From 2b6c71c4d3ab9f94fa6d6260f2b302891dd0132c Mon Sep 17 00:00:00 2001 From: Jason Simmons Date: Tue, 23 Jun 2020 12:03:02 -0700 Subject: [PATCH] Reland "Implement PlatformViewsController.createOverlaySurface" (#19245) --- .../platform/PlatformViewsController.java | 35 +++++++++++++++++-- 1 file changed, 33 insertions(+), 2 deletions(-) diff --git a/shell/platform/android/io/flutter/plugin/platform/PlatformViewsController.java b/shell/platform/android/io/flutter/plugin/platform/PlatformViewsController.java index 706b31228..6b70ebd57 100644 --- a/shell/platform/android/io/flutter/plugin/platform/PlatformViewsController.java +++ b/shell/platform/android/io/flutter/plugin/platform/PlatformViewsController.java @@ -9,14 +9,19 @@ import static android.view.MotionEvent.PointerProperties; import android.annotation.TargetApi; import android.content.Context; +import android.graphics.PixelFormat; +import android.hardware.HardwareBuffer; +import android.media.ImageReader; import android.os.Build; import android.util.DisplayMetrics; import android.util.Log; +import android.util.LongSparseArray; import android.view.MotionEvent; import android.view.View; import androidx.annotation.NonNull; import androidx.annotation.UiThread; import androidx.annotation.VisibleForTesting; +import io.flutter.embedding.android.FlutterImageView; import io.flutter.embedding.engine.FlutterOverlaySurface; import io.flutter.embedding.engine.dart.DartExecutor; import io.flutter.embedding.engine.systemchannels.PlatformViewsChannel; @@ -71,6 +76,12 @@ public class PlatformViewsController implements PlatformViewsAccessibilityDelega // it is associated with(e.g if a platform view creates other views in the same virtual display. private final HashMap contextToPlatformView; + // Map of unique IDs to views that render overlay layers. + private final LongSparseArray overlayLayerViews; + + // Next available unique ID for use in overlayLayerViews; + private long nextOverlayLayerId = 0; + private final PlatformViewsChannel.PlatformViewsHandler channelHandler = new PlatformViewsChannel.PlatformViewsHandler() { @TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1) @@ -283,6 +294,7 @@ public class PlatformViewsController implements PlatformViewsAccessibilityDelega vdControllers = new HashMap<>(); accessibilityEventsDelegate = new AccessibilityEventsDelegate(); contextToPlatformView = new HashMap<>(); + overlayLayerViews = new LongSparseArray<>(); } /** @@ -551,8 +563,27 @@ public class PlatformViewsController implements PlatformViewsAccessibilityDelega // TODO: Implement this method. https://github.com/flutter/flutter/issues/58288 } + @TargetApi(19) public FlutterOverlaySurface createOverlaySurface() { - // TODO: Implement this method. https://github.com/flutter/flutter/issues/58288 - return null; + ImageReader imageReader; + if (android.os.Build.VERSION.SDK_INT >= 29) { + imageReader = + ImageReader.newInstance( + flutterView.getWidth(), + flutterView.getHeight(), + PixelFormat.RGBA_8888, + 2, + HardwareBuffer.USAGE_GPU_SAMPLED_IMAGE | HardwareBuffer.USAGE_GPU_COLOR_OUTPUT); + } else { + imageReader = + ImageReader.newInstance( + flutterView.getWidth(), flutterView.getHeight(), PixelFormat.RGBA_8888, 2); + } + + FlutterImageView imageView = new FlutterImageView(flutterView.getContext(), imageReader); + long id = nextOverlayLayerId++; + overlayLayerViews.put(id, imageView); + + return new FlutterOverlaySurface(id, imageReader.getSurface()); } } -- GitLab