Flutter Engine
The Flutter Engine
SurfaceTextureSurfaceProducer.java
Go to the documentation of this file.
1package io.flutter.embedding.engine.renderer;
2
3import android.graphics.SurfaceTexture;
4import android.os.Handler;
5import android.view.Surface;
6import androidx.annotation.NonNull;
7import androidx.annotation.Nullable;
8import io.flutter.embedding.engine.FlutterJNI;
9import io.flutter.view.TextureRegistry;
10
11/** Uses a {@link android.graphics.SurfaceTexture} to populate the texture registry. */
13 implements TextureRegistry.SurfaceProducer, TextureRegistry.GLTextureConsumer {
14 private final long id;
15 private int requestBufferWidth;
16 private int requestedBufferHeight;
17 private boolean released;
18 @Nullable private Surface surface;
19 @NonNull private final TextureRegistry.SurfaceTextureEntry texture;
20 @NonNull private final Handler handler;
21 @NonNull private final FlutterJNI flutterJNI;
22
24 long id,
25 @NonNull Handler handler,
26 @NonNull FlutterJNI flutterJNI,
27 @NonNull TextureRegistry.SurfaceTextureEntry texture) {
28 this.id = id;
29 this.handler = handler;
30 this.flutterJNI = flutterJNI;
31 this.texture = texture;
32 }
33
34 @Override
35 protected void finalize() throws Throwable {
36 try {
37 if (released) {
38 return;
39 }
40 release();
41 handler.post(new FlutterRenderer.TextureFinalizerRunnable(id, flutterJNI));
42 } finally {
43 super.finalize();
44 }
45 }
46
47 @Override
48 public long id() {
49 return id;
50 }
51
52 @Override
53 public void release() {
54 texture.release();
55 released = true;
56 }
57
58 @Override
59 @NonNull
60 public SurfaceTexture getSurfaceTexture() {
61 return texture.surfaceTexture();
62 }
63
64 @Override
65 public void setSize(int width, int height) {
66 requestBufferWidth = width;
67 requestedBufferHeight = height;
68 getSurfaceTexture().setDefaultBufferSize(width, height);
69 }
70
71 @Override
72 public int getWidth() {
73 return requestBufferWidth;
74 }
75
76 @Override
77 public int getHeight() {
78 return requestedBufferHeight;
79 }
80
81 @Override
82 public Surface getSurface() {
83 if (surface == null) {
84 surface = new Surface(texture.surfaceTexture());
85 }
86 return surface;
87 }
88
89 @Override
90 public void scheduleFrame() {
91 flutterJNI.markTextureFrameAvailable(id);
92 }
93}
SurfaceTextureSurfaceProducer(long id, @NonNull Handler handler, @NonNull FlutterJNI flutterJNI, @NonNull TextureRegistry.SurfaceTextureEntry texture)
VkSurfaceKHR surface
Definition: main.cc:49
FlTexture * texture
int32_t height
int32_t width
const uintptr_t id