Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@

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;
Expand All @@ -17,6 +20,7 @@
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;
Expand Down Expand Up @@ -71,6 +75,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<Context, View> contextToPlatformView;

// Map of unique IDs to views that render overlay layers.
private HashMap<Long, FlutterImageView> 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)
Expand Down Expand Up @@ -283,6 +293,7 @@ public PlatformViewsController() {
vdControllers = new HashMap<>();
accessibilityEventsDelegate = new AccessibilityEventsDelegate();
contextToPlatformView = new HashMap<>();
overlayLayerViews = new HashMap<>();
}

/**
Expand Down Expand Up @@ -552,7 +563,25 @@ public void onEndFrame() {
}

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());
}
}