[Android] HC++ plumbing. (#162407)

We'll need the JNI fascade to create the surface transaction for HC++
mode. Split into a separate PR so that the "real" HC++ PR isn't 5000
lines long.
This commit is contained in:
Jonah Williams 2025-01-30 10:04:40 -08:00 committed by GitHub
parent fffbf663ff
commit 1eecbf1256
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
15 changed files with 45 additions and 28 deletions

View File

@ -170,7 +170,7 @@ TEST(AndroidSurfaceGL, CreateSnapshopSurfaceWhenOnscreenSurfaceIsNotNull) {
std::make_unique<AndroidSurfaceGLSkia>(android_context);
auto window = fml::MakeRefCounted<AndroidNativeWindow>(
nullptr, /*is_fake_window=*/true);
android_surface->SetNativeWindow(window);
android_surface->SetNativeWindow(window, nullptr);
auto onscreen_surface = android_surface->GetOnscreenSurface();
EXPECT_NE(onscreen_surface, nullptr);
android_surface->CreateSnapshotSurface();

View File

@ -74,7 +74,8 @@ bool AndroidSurfaceGLImpeller::ResourceContextClearCurrent() {
// |AndroidSurface|
bool AndroidSurfaceGLImpeller::SetNativeWindow(
fml::RefPtr<AndroidNativeWindow> window) {
fml::RefPtr<AndroidNativeWindow> window,
const std::shared_ptr<PlatformViewAndroidJNI>& jni_facade) {
native_window_ = std::move(window);
return RecreateOnscreenSurfaceAndMakeOnscreenContextCurrent();
}

View File

@ -43,7 +43,9 @@ class AndroidSurfaceGLImpeller final : public GPUSurfaceGLDelegate,
bool ResourceContextClearCurrent() override;
// |AndroidSurface|
bool SetNativeWindow(fml::RefPtr<AndroidNativeWindow> window) override;
bool SetNativeWindow(
fml::RefPtr<AndroidNativeWindow> window,
const std::shared_ptr<PlatformViewAndroidJNI>& jni_facade) override;
// |AndroidSurface|
std::unique_ptr<Surface> CreateSnapshotSurface() override;

View File

@ -100,7 +100,8 @@ bool AndroidSurfaceGLSkia::ResourceContextClearCurrent() {
}
bool AndroidSurfaceGLSkia::SetNativeWindow(
fml::RefPtr<AndroidNativeWindow> window) {
fml::RefPtr<AndroidNativeWindow> window,
const std::shared_ptr<PlatformViewAndroidJNI>& jni_facade) {
FML_DCHECK(IsValid());
FML_DCHECK(window);
native_window_ = window;

View File

@ -46,7 +46,9 @@ class AndroidSurfaceGLSkia final : public GPUSurfaceGLDelegate,
bool ResourceContextClearCurrent() override;
// |AndroidSurface|
bool SetNativeWindow(fml::RefPtr<AndroidNativeWindow> window) override;
bool SetNativeWindow(
fml::RefPtr<AndroidNativeWindow> window,
const std::shared_ptr<PlatformViewAndroidJNI>& jni_facade) override;
// |AndroidSurface|
virtual std::unique_ptr<Surface> CreateSnapshotSurface() override;

View File

@ -150,7 +150,8 @@ bool AndroidSurfaceSoftware::OnScreenSurfaceResize(const SkISize& size) {
}
bool AndroidSurfaceSoftware::SetNativeWindow(
fml::RefPtr<AndroidNativeWindow> window) {
fml::RefPtr<AndroidNativeWindow> window,
const std::shared_ptr<PlatformViewAndroidJNI>& jni_facade) {
native_window_ = std::move(window);
if (!(native_window_ && native_window_->IsValid())) {
return false;

View File

@ -43,7 +43,9 @@ class AndroidSurfaceSoftware final : public AndroidSurface,
bool OnScreenSurfaceResize(const SkISize& size) override;
// |AndroidSurface|
bool SetNativeWindow(fml::RefPtr<AndroidNativeWindow> window) override;
bool SetNativeWindow(
fml::RefPtr<AndroidNativeWindow> window,
const std::shared_ptr<PlatformViewAndroidJNI>& jni_facade) override;
// |GPUSurfaceSoftwareDelegate|
sk_sp<SkSurface> AcquireBackingStore(const SkISize& size) override;

View File

@ -81,7 +81,8 @@ bool AndroidSurfaceVKImpeller::ResourceContextClearCurrent() {
}
bool AndroidSurfaceVKImpeller::SetNativeWindow(
fml::RefPtr<AndroidNativeWindow> window) {
fml::RefPtr<AndroidNativeWindow> window,
const std::shared_ptr<PlatformViewAndroidJNI>& jni_facade) {
if (window && (native_window_ == window)) {
return OnScreenSurfaceResize(window->GetSize());
}

View File

@ -45,7 +45,9 @@ class AndroidSurfaceVKImpeller : public AndroidSurface {
std::shared_ptr<impeller::Context> GetImpellerContext() override;
// |AndroidSurface|
bool SetNativeWindow(fml::RefPtr<AndroidNativeWindow> window) override;
bool SetNativeWindow(
fml::RefPtr<AndroidNativeWindow> window,
const std::shared_ptr<PlatformViewAndroidJNI>& jni_facade) override;
private:
std::shared_ptr<impeller::SurfaceContextVK> surface_context_vk_;

View File

@ -24,6 +24,7 @@
namespace flutter {
namespace testing {
using ::testing::_;
using ::testing::ByMove;
using ::testing::Return;
@ -295,7 +296,7 @@ TEST(AndroidExternalViewEmbedder, SubmitFlutterView) {
EXPECT_CALL(*android_surface_mock, CreateGPUSurface(gr_context.get()))
.WillOnce(Return(ByMove(std::move(surface_mock))));
EXPECT_CALL(*android_surface_mock, SetNativeWindow(window));
EXPECT_CALL(*android_surface_mock, SetNativeWindow(window, _));
return android_surface_mock;
});
@ -504,7 +505,7 @@ TEST(AndroidExternalViewEmbedder, OverlayCoverTwoPlatformViews) {
EXPECT_CALL(*android_surface_mock, CreateGPUSurface(gr_context.get()))
.WillOnce(Return(ByMove(std::move(surface_mock))));
EXPECT_CALL(*android_surface_mock, SetNativeWindow(window));
EXPECT_CALL(*android_surface_mock, SetNativeWindow(window, _));
return android_surface_mock;
});
auto embedder = std::make_unique<AndroidExternalViewEmbedder>(
@ -606,7 +607,7 @@ TEST(AndroidExternalViewEmbedder, SubmitFrameOverlayComposition) {
EXPECT_CALL(*android_surface_mock, CreateGPUSurface(gr_context.get()))
.WillOnce(Return(ByMove(std::move(surface_mock))));
EXPECT_CALL(*android_surface_mock, SetNativeWindow(window));
EXPECT_CALL(*android_surface_mock, SetNativeWindow(window, _));
return android_surface_mock;
});
auto embedder = std::make_unique<AndroidExternalViewEmbedder>(
@ -713,7 +714,7 @@ TEST(AndroidExternalViewEmbedder, SubmitFramePlatformViewWithoutAnyOverlay) {
EXPECT_CALL(*android_surface_mock, CreateGPUSurface(gr_context.get()))
.WillOnce(Return(ByMove(std::move(surface_mock))));
EXPECT_CALL(*android_surface_mock, SetNativeWindow(window));
EXPECT_CALL(*android_surface_mock, SetNativeWindow(window, _));
return android_surface_mock;
});
auto embedder = std::make_unique<AndroidExternalViewEmbedder>(
@ -804,7 +805,7 @@ TEST(AndroidExternalViewEmbedder, DestroyOverlayLayersOnSizeChange) {
EXPECT_CALL(*android_surface_mock, CreateGPUSurface(gr_context.get()))
.WillOnce(Return(ByMove(std::move(surface_mock))));
EXPECT_CALL(*android_surface_mock, SetNativeWindow(window));
EXPECT_CALL(*android_surface_mock, SetNativeWindow(window, _));
return android_surface_mock;
});
@ -896,7 +897,7 @@ TEST(AndroidExternalViewEmbedder, DoesNotDestroyOverlayLayersOnSizeChange) {
EXPECT_CALL(*android_surface_mock, CreateGPUSurface(gr_context.get()))
.WillOnce(Return(ByMove(std::move(surface_mock))));
EXPECT_CALL(*android_surface_mock, SetNativeWindow(window));
EXPECT_CALL(*android_surface_mock, SetNativeWindow(window, _));
return android_surface_mock;
});

View File

@ -45,7 +45,7 @@ std::shared_ptr<OverlayLayer> SurfacePool::GetLayer(
jni_facade->FlutterViewCreateOverlaySurface();
FML_CHECK(java_metadata->window);
android_surface->SetNativeWindow(java_metadata->window);
android_surface->SetNativeWindow(java_metadata->window, jni_facade);
std::unique_ptr<Surface> surface =
android_surface->CreateGPUSurface(gr_context);

View File

@ -15,6 +15,7 @@
namespace flutter {
namespace testing {
using ::testing::_;
using ::testing::ByMove;
using ::testing::Return;
@ -54,7 +55,7 @@ TEST(SurfacePool, GetLayerAllocateOneLayer) {
std::make_shared<TestAndroidSurfaceFactory>([gr_context, window]() {
auto android_surface_mock = std::make_unique<AndroidSurfaceMock>();
EXPECT_CALL(*android_surface_mock, CreateGPUSurface(gr_context.get()));
EXPECT_CALL(*android_surface_mock, SetNativeWindow(window));
EXPECT_CALL(*android_surface_mock, SetNativeWindow(window, _));
EXPECT_CALL(*android_surface_mock, IsValid()).WillOnce(Return(true));
return android_surface_mock;
});
@ -85,7 +86,7 @@ TEST(SurfacePool, GetUnusedLayers) {
std::make_shared<TestAndroidSurfaceFactory>([gr_context, window]() {
auto android_surface_mock = std::make_unique<AndroidSurfaceMock>();
EXPECT_CALL(*android_surface_mock, CreateGPUSurface(gr_context.get()));
EXPECT_CALL(*android_surface_mock, SetNativeWindow(window));
EXPECT_CALL(*android_surface_mock, SetNativeWindow(window, _));
EXPECT_CALL(*android_surface_mock, IsValid()).WillOnce(Return(true));
return android_surface_mock;
});
@ -124,7 +125,7 @@ TEST(SurfacePool, GetLayerRecycle) {
EXPECT_CALL(*android_surface_mock,
CreateGPUSurface(gr_context_2.get()));
// Set the native window once.
EXPECT_CALL(*android_surface_mock, SetNativeWindow(window));
EXPECT_CALL(*android_surface_mock, SetNativeWindow(window, _));
EXPECT_CALL(*android_surface_mock, IsValid()).WillOnce(Return(true));
return android_surface_mock;
});
@ -167,7 +168,7 @@ TEST(SurfacePool, GetLayerAllocateTwoLayers) {
std::make_shared<TestAndroidSurfaceFactory>([gr_context, window]() {
auto android_surface_mock = std::make_unique<AndroidSurfaceMock>();
EXPECT_CALL(*android_surface_mock, CreateGPUSurface(gr_context.get()));
EXPECT_CALL(*android_surface_mock, SetNativeWindow(window));
EXPECT_CALL(*android_surface_mock, SetNativeWindow(window, _));
EXPECT_CALL(*android_surface_mock, IsValid()).WillOnce(Return(true));
return android_surface_mock;
});
@ -206,7 +207,7 @@ TEST(SurfacePool, DestroyLayers) {
std::make_shared<TestAndroidSurfaceFactory>([gr_context, window]() {
auto android_surface_mock = std::make_unique<AndroidSurfaceMock>();
EXPECT_CALL(*android_surface_mock, CreateGPUSurface(gr_context.get()));
EXPECT_CALL(*android_surface_mock, SetNativeWindow(window));
EXPECT_CALL(*android_surface_mock, SetNativeWindow(window, _));
EXPECT_CALL(*android_surface_mock, IsValid()).WillOnce(Return(true));
return android_surface_mock;
});
@ -235,7 +236,7 @@ TEST(SurfacePool, DestroyLayersFrameSizeChanged) {
std::make_shared<TestAndroidSurfaceFactory>([gr_context, window]() {
auto android_surface_mock = std::make_unique<AndroidSurfaceMock>();
EXPECT_CALL(*android_surface_mock, CreateGPUSurface(gr_context.get()));
EXPECT_CALL(*android_surface_mock, SetNativeWindow(window));
EXPECT_CALL(*android_surface_mock, SetNativeWindow(window, _));
EXPECT_CALL(*android_surface_mock, IsValid()).WillOnce(Return(true));
return android_surface_mock;
});

View File

@ -148,8 +148,8 @@ void PlatformViewAndroid::NotifyCreated(
fml::TaskRunner::RunNowOrPostTask(
task_runners_.GetRasterTaskRunner(),
[&latch, surface = android_surface_.get(),
native_window = std::move(native_window)]() {
surface->SetNativeWindow(native_window);
native_window = std::move(native_window), jni_facade = jni_facade_]() {
surface->SetNativeWindow(native_window, jni_facade);
latch.Signal();
});
latch.Wait();
@ -165,9 +165,9 @@ void PlatformViewAndroid::NotifySurfaceWindowChanged(
fml::TaskRunner::RunNowOrPostTask(
task_runners_.GetRasterTaskRunner(),
[&latch, surface = android_surface_.get(),
native_window = std::move(native_window)]() {
native_window = std::move(native_window), jni_facade = jni_facade_]() {
surface->TeardownOnScreenContext();
surface->SetNativeWindow(native_window);
surface->SetNativeWindow(native_window, jni_facade);
latch.Signal();
});
latch.Wait();

View File

@ -39,7 +39,9 @@ class AndroidSurface {
virtual bool ResourceContextClearCurrent() = 0;
virtual bool SetNativeWindow(fml::RefPtr<AndroidNativeWindow> window) = 0;
virtual bool SetNativeWindow(
fml::RefPtr<AndroidNativeWindow> window,
const std::shared_ptr<PlatformViewAndroidJNI>& jni_facade) = 0;
virtual std::unique_ptr<Surface> CreateSnapshotSurface();

View File

@ -35,7 +35,8 @@ class AndroidSurfaceMock final : public GPUSurfaceGLDelegate,
MOCK_METHOD(bool,
SetNativeWindow,
(fml::RefPtr<AndroidNativeWindow> window),
(fml::RefPtr<AndroidNativeWindow> window,
const std::shared_ptr<PlatformViewAndroidJNI>& jni_facade),
(override));
// |GPUSurfaceGLDelegate|