1package io.flutter.plugin.platform;
3import static io.flutter.Build.API_LEVELS;
5import android.annotation.TargetApi;
6import android.graphics.ImageFormat;
7import android.hardware.HardwareBuffer;
14import io.flutter.view.TextureRegistry.ImageTextureEntry;
16@TargetApi(API_LEVELS.API_29)
19 private ImageReader reader;
20 private int bufferWidth = 0;
21 private int bufferHeight = 0;
22 private static final String
TAG =
"ImageReaderPlatformViewRenderTarget";
23 private static final int MAX_IMAGES = 4;
25 private void closeReader() {
26 if (this.reader !=
null) {
35 private final Handler onImageAvailableHandler =
new Handler();
36 private final ImageReader.OnImageAvailableListener onImageAvailableListener =
37 new ImageReader.OnImageAvailableListener() {
39 public void onImageAvailable(ImageReader reader) {
42 image = reader.acquireLatestImage();
43 }
catch (IllegalStateException
e) {
44 Log.
e(
TAG,
"onImageAvailable acquireLatestImage failed: " +
e.toString());
54 protected ImageReader createImageReader33() {
55 final ImageReader.Builder
builder =
new ImageReader.Builder(bufferWidth, bufferHeight);
57 builder.setMaxImages(MAX_IMAGES);
64 builder.setImageFormat(ImageFormat.PRIVATE);
66 builder.setUsage(HardwareBuffer.USAGE_GPU_SAMPLED_IMAGE);
67 final ImageReader reader =
builder.build();
68 reader.setOnImageAvailableListener(this.onImageAvailableListener, onImageAvailableHandler);
73 protected ImageReader createImageReader29() {
74 final ImageReader reader =
75 ImageReader.newInstance(
80 HardwareBuffer.USAGE_GPU_SAMPLED_IMAGE);
81 reader.setOnImageAvailableListener(this.onImageAvailableListener, onImageAvailableHandler);
87 return createImageReader33();
89 return createImageReader29();
91 throw new UnsupportedOperationException(
92 "ImageReaderPlatformViewRenderTarget requires API version 29+");
97 throw new UnsupportedOperationException(
98 "ImageReaderPlatformViewRenderTarget requires API version 29+");
100 this.textureEntry = textureEntry;
104 if (this.reader !=
null && bufferWidth ==
width && bufferHeight ==
height) {
111 this.reader = createImageReader();
115 return this.bufferWidth;
119 return this.bufferHeight;
123 return this.textureEntry.id();
133 return this.textureEntry ==
null;
137 return this.reader.getSurface();
static void e(@NonNull String tag, @NonNull String message)
void pushImage(Image image)
sk_sp< const SkImage > image
def Build(configs, env, options)