Skip to content

Commit

Permalink
test
Browse files Browse the repository at this point in the history
  • Loading branch information
Nayuta403 committed Dec 26, 2022
1 parent ebca48f commit d876848
Showing 1 changed file with 102 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -516,6 +516,108 @@ TEST(AndroidExternalViewEmbedder, SubmitFrame) {
}
}

TEST(AndroidExternalViewEmbedder, OverlayCoverTwoPlatformViews) {
// In this test we will simulate two Android views appearing on the screen
// with a rect intersecting both of them

auto jni_mock = std::make_shared<JNIMock>();
auto android_context =
std::make_shared<AndroidContext>(AndroidRenderingAPI::kSoftware);

auto window = fml::MakeRefCounted<AndroidNativeWindow>(nullptr);
auto gr_context = GrDirectContext::MakeMock(nullptr);
auto frame_size = SkISize::Make(1000, 1000);
SurfaceFrame::FramebufferInfo framebuffer_info;
auto surface_factory = std::make_shared<TestAndroidSurfaceFactory>(
[&android_context, gr_context, window, frame_size, framebuffer_info]() {
auto surface_frame_1 = std::make_unique<SurfaceFrame>(
SkSurface::MakeNull(1000, 1000), framebuffer_info,
[](const SurfaceFrame& surface_frame, SkCanvas* canvas) {
return true;
},
/*frame_size=*/SkISize::Make(800, 600));

auto surface_mock = std::make_unique<SurfaceMock>();
EXPECT_CALL(*surface_mock, AcquireFrame(frame_size))
.Times(1 /* frames */)
.WillOnce(Return(ByMove(std::move(surface_frame_1))));

auto android_surface_mock =
std::make_unique<AndroidSurfaceMock>(android_context);
EXPECT_CALL(*android_surface_mock, IsValid()).WillOnce(Return(true));

EXPECT_CALL(*android_surface_mock, CreateGPUSurface(gr_context.get()))
.WillOnce(Return(ByMove(std::move(surface_mock))));

EXPECT_CALL(*android_surface_mock, SetNativeWindow(window));
return android_surface_mock;
});
auto embedder = std::make_unique<AndroidExternalViewEmbedder>(
*android_context, jni_mock, surface_factory, GetTaskRunnersForFixture());

auto raster_thread_merger = GetThreadMergerFromPlatformThread();

EXPECT_CALL(*jni_mock, FlutterViewBeginFrame());
embedder->BeginFrame(frame_size, nullptr, 1.5, raster_thread_merger);

{
// Add first Android view.
SkMatrix matrix = SkMatrix::Translate(100, 100);
MutatorsStack stack;
embedder->PrerollCompositeEmbeddedView(
0, std::make_unique<EmbeddedViewParams>(matrix, SkSize::Make(100, 100),
stack));
// The JNI call to display the Android view.
EXPECT_CALL(*jni_mock, FlutterViewOnDisplayPlatformView(
0, 100, 100, 100, 100, 150, 150, stack));
}

{
// Add second Android view.
SkMatrix matrix = SkMatrix::Translate(300, 100);
MutatorsStack stack;
embedder->PrerollCompositeEmbeddedView(
1, std::make_unique<EmbeddedViewParams>(matrix, SkSize::Make(100, 100),
stack));
// The JNI call to display the Android view.
EXPECT_CALL(*jni_mock, FlutterViewOnDisplayPlatformView(
1, 300, 100, 100, 100, 150, 150, stack));
}
auto rect_paint = SkPaint();
rect_paint.setColor(SkColors::kCyan);
rect_paint.setStyle(SkPaint::Style::kFill_Style);

// This simulates Flutter UI that intersects with the two Android views.
// Since we will compute the intersection for each android view in turn, and
// finally merge The final size of the overlay will be smaller than the
// width and height of the rect.
embedder->CompositeEmbeddedView(1).canvas->drawRect(
SkRect::MakeXYWH(150, 50, 200, 200), rect_paint);

EXPECT_CALL(*jni_mock, FlutterViewCreateOverlaySurface())
.WillRepeatedly([&]() {
return std::make_unique<PlatformViewAndroidJNI::OverlayMetadata>(
1, window);
});

// The JNI call to display the overlay surface.
EXPECT_CALL(*jni_mock,
FlutterViewDisplayOverlaySurface(1, 150, 100, 200, 100))
.Times(1);

auto surface_frame = std::make_unique<SurfaceFrame>(
SkSurface::MakeNull(1000, 1000), framebuffer_info,
[](const SurfaceFrame& surface_frame, SkCanvas* canvas) mutable {
return true;
},
/*frame_size=*/SkISize::Make(800, 600));

embedder->SubmitFrame(gr_context.get(), std::move(surface_frame));

EXPECT_CALL(*jni_mock, FlutterViewEndFrame());
embedder->EndFrame(/*should_resubmit_frame=*/false, raster_thread_merger);
}

TEST(AndroidExternalViewEmbedder, SubmitFrameOverlayComposition) {
auto jni_mock = std::make_shared<JNIMock>();
auto android_context =
Expand Down

0 comments on commit d876848

Please sign in to comment.