15 private static final String
TAG =
"SurfaceTexturePlatformViewRenderTarget";
17 private final SurfaceTextureEntry surfaceTextureEntry;
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 =
26 new TextureRegistry.OnTrimMemoryListener() {
28 public void onTrimMemory(
int level) {
36 if (level == TRIM_MEMORY_COMPLETE &&
Build.VERSION.SDK_INT >= API_LEVELS.API_29) {
37 shouldRecreateSurfaceForLowMemory =
true;
42 private void recreateSurfaceIfNeeded() {
43 if (
surface !=
null && !shouldRecreateSurfaceForLowMemory) {
52 shouldRecreateSurfaceForLowMemory =
false;
56 return new Surface(surfaceTexture);
61 if (
Build.VERSION.SDK_INT < API_LEVELS.API_23) {
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;
67 this.surfaceTexture = surfaceTextureEntry.surfaceTexture();
68 surfaceTextureEntry.setOnTrimMemoryListener(trimMemoryListener);
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()) {