Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[PDFX] Migrate to SurfaceProducer #543

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 5 additions & 6 deletions packages/pdfx/android/src/main/kotlin/io/scer/pdfx/Messages.kt
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class Messages(private val binding : FlutterPlugin.FlutterPluginBinding,
private val documents: DocumentRepository,
private val pages: PageRepository) : Pigeon.PdfxApi {

private val textures: SparseArray<TextureRegistry.SurfaceTextureEntry> = SparseArray()
private val textures: SparseArray<TextureRegistry.SurfaceProducer> = SparseArray()

override fun openDocumentData(
message: Pigeon.OpenDataMessage,
Expand Down Expand Up @@ -207,7 +207,7 @@ class Messages(private val binding : FlutterPlugin.FlutterPluginBinding,
}

override fun registerTexture(): Pigeon.RegisterTextureReply {
val surfaceTexture = binding.textureRegistry.createSurfaceTexture()
val surfaceTexture = binding.textureRegistry.createSurfaceProducer()
val id = surfaceTexture.id().toInt()
textures.put(id, surfaceTexture)
val result = Pigeon.RegisterTextureReply()
Expand Down Expand Up @@ -253,10 +253,9 @@ class Messages(private val binding : FlutterPlugin.FlutterPluginBinding,
val texWidth = message.textureWidth!!.toInt()
val texHeight = message.textureHeight!!.toInt()
if (texWidth != 0 && texHeight != 0) {
tex.surfaceTexture().setDefaultBufferSize(texWidth, texHeight)
tex.setSize(texWidth, texHeight)
}

Surface(tex.surfaceTexture()).use {
tex.surface.use {
val canvas = it.lockCanvas(Rect(destX, destY, width, height))

canvas.drawBitmap(bmp, destX.toFloat(), destY.toFloat(), null)
Expand All @@ -280,7 +279,7 @@ class Messages(private val binding : FlutterPlugin.FlutterPluginBinding,
val width = message.width!!.toInt()
val height = message.height!!.toInt()
val tex = textures[texId]
tex?.surfaceTexture()?.setDefaultBufferSize(width, height)
tex?.setSize(width, height)
result.success(null)
}

Expand Down
2 changes: 1 addition & 1 deletion packages/pdfx/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ version: 2.8.0

environment:
sdk: '>=3.3.0 <4.0.0'
flutter: '>=3.19.0'
flutter: '>=3.24.0'

dependencies:
flutter:
Expand Down