|
9 | 9 |
|
10 | 10 | import android.annotation.TargetApi; |
11 | 11 | import android.content.Context; |
| 12 | +import android.graphics.PixelFormat; |
| 13 | +import android.hardware.HardwareBuffer; |
| 14 | +import android.media.ImageReader; |
12 | 15 | import android.os.Build; |
13 | 16 | import android.util.DisplayMetrics; |
14 | 17 | import android.util.Log; |
| 18 | +import android.util.LongSparseArray; |
15 | 19 | import android.view.MotionEvent; |
16 | 20 | import android.view.View; |
17 | 21 | import androidx.annotation.NonNull; |
18 | 22 | import androidx.annotation.UiThread; |
19 | 23 | import androidx.annotation.VisibleForTesting; |
| 24 | +import io.flutter.embedding.android.FlutterImageView; |
20 | 25 | import io.flutter.embedding.engine.FlutterOverlaySurface; |
21 | 26 | import io.flutter.embedding.engine.dart.DartExecutor; |
22 | 27 | import io.flutter.embedding.engine.systemchannels.PlatformViewsChannel; |
@@ -71,6 +76,12 @@ public class PlatformViewsController implements PlatformViewsAccessibilityDelega |
71 | 76 | // it is associated with(e.g if a platform view creates other views in the same virtual display. |
72 | 77 | private final HashMap<Context, View> contextToPlatformView; |
73 | 78 |
|
| 79 | + // Map of unique IDs to views that render overlay layers. |
| 80 | + private final LongSparseArray<FlutterImageView> overlayLayerViews; |
| 81 | + |
| 82 | + // Next available unique ID for use in overlayLayerViews; |
| 83 | + private long nextOverlayLayerId = 0; |
| 84 | + |
74 | 85 | private final PlatformViewsChannel.PlatformViewsHandler channelHandler = |
75 | 86 | new PlatformViewsChannel.PlatformViewsHandler() { |
76 | 87 | @TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1) |
@@ -283,6 +294,7 @@ public PlatformViewsController() { |
283 | 294 | vdControllers = new HashMap<>(); |
284 | 295 | accessibilityEventsDelegate = new AccessibilityEventsDelegate(); |
285 | 296 | contextToPlatformView = new HashMap<>(); |
| 297 | + overlayLayerViews = new LongSparseArray<>(); |
286 | 298 | } |
287 | 299 |
|
288 | 300 | /** |
@@ -551,8 +563,27 @@ public void onEndFrame() { |
551 | 563 | // TODO: Implement this method. https://github.com/flutter/flutter/issues/58288 |
552 | 564 | } |
553 | 565 |
|
| 566 | + @TargetApi(19) |
554 | 567 | public FlutterOverlaySurface createOverlaySurface() { |
555 | | - // TODO: Implement this method. https://github.com/flutter/flutter/issues/58288 |
556 | | - return null; |
| 568 | + ImageReader imageReader; |
| 569 | + if (android.os.Build.VERSION.SDK_INT >= 29) { |
| 570 | + imageReader = |
| 571 | + ImageReader.newInstance( |
| 572 | + flutterView.getWidth(), |
| 573 | + flutterView.getHeight(), |
| 574 | + PixelFormat.RGBA_8888, |
| 575 | + 2, |
| 576 | + HardwareBuffer.USAGE_GPU_SAMPLED_IMAGE | HardwareBuffer.USAGE_GPU_COLOR_OUTPUT); |
| 577 | + } else { |
| 578 | + imageReader = |
| 579 | + ImageReader.newInstance( |
| 580 | + flutterView.getWidth(), flutterView.getHeight(), PixelFormat.RGBA_8888, 2); |
| 581 | + } |
| 582 | + |
| 583 | + FlutterImageView imageView = new FlutterImageView(flutterView.getContext(), imageReader); |
| 584 | + long id = nextOverlayLayerId++; |
| 585 | + overlayLayerViews.put(id, imageView); |
| 586 | + |
| 587 | + return new FlutterOverlaySurface(id, imageReader.getSurface()); |
557 | 588 | } |
558 | 589 | } |
0 commit comments