1package io.flutter.plugin.platform;
3import static android.content.ComponentCallbacks2.TRIM_MEMORY_COMPLETE;
4import static io.flutter.Build.API_LEVELS;
6import android.annotation.TargetApi;
7import android.graphics.SurfaceTexture;
10import io.flutter.view.TextureRegistry;
11import io.flutter.view.TextureRegistry.SurfaceTextureEntry;
13@TargetApi(API_LEVELS.API_26)
15 private static final String
TAG =
"SurfaceTexturePlatformViewRenderTarget";
19 private SurfaceTexture surfaceTexture;
21 private int bufferWidth = 0;
22 private int bufferHeight = 0;
24 private boolean shouldRecreateSurfaceForLowMemory =
false;
25 private final TextureRegistry.OnTrimMemoryListener trimMemoryListener =
28 public void onTrimMemory(
int level) {
37 shouldRecreateSurfaceForLowMemory =
true;
42 private void recreateSurfaceIfNeeded() {
43 if (
surface !=
null && !shouldRecreateSurfaceForLowMemory) {
52 shouldRecreateSurfaceForLowMemory =
false;
56 return new Surface(surfaceTexture);
62 throw new UnsupportedOperationException(
63 "Platform views cannot be displayed below API level 23"
64 +
"You can prevent this issue by setting `minSdkVersion: 23` in build.gradle.");
66 this.surfaceTextureEntry = surfaceTextureEntry;
74 if (surfaceTexture !=
null) {
75 surfaceTexture.setDefaultBufferSize(bufferWidth, bufferHeight);
88 return this.surfaceTextureEntry.
id();
92 return surfaceTexture ==
null;
97 surfaceTexture =
null;
105 recreateSurfaceIfNeeded();
106 if (surfaceTexture ==
null || surfaceTexture.isReleased()) {
void resize(int width, int height)
SurfaceTexturePlatformViewRenderTarget(SurfaceTextureEntry surfaceTextureEntry)
SurfaceTexture surfaceTexture()
default void setOnTrimMemoryListener(@Nullable OnTrimMemoryListener listener)
def Build(configs, env, options)