Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit d876848

Browse files
committed
test
1 parent ebca48f commit d876848

File tree

1 file changed

+102
-0
lines changed

1 file changed

+102
-0
lines changed

shell/platform/android/external_view_embedder/external_view_embedder_unittests.cc

Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -516,6 +516,108 @@ TEST(AndroidExternalViewEmbedder, SubmitFrame) {
516516
}
517517
}
518518

519+
TEST(AndroidExternalViewEmbedder, OverlayCoverTwoPlatformViews) {
520+
// In this test we will simulate two Android views appearing on the screen
521+
// with a rect intersecting both of them
522+
523+
auto jni_mock = std::make_shared<JNIMock>();
524+
auto android_context =
525+
std::make_shared<AndroidContext>(AndroidRenderingAPI::kSoftware);
526+
527+
auto window = fml::MakeRefCounted<AndroidNativeWindow>(nullptr);
528+
auto gr_context = GrDirectContext::MakeMock(nullptr);
529+
auto frame_size = SkISize::Make(1000, 1000);
530+
SurfaceFrame::FramebufferInfo framebuffer_info;
531+
auto surface_factory = std::make_shared<TestAndroidSurfaceFactory>(
532+
[&android_context, gr_context, window, frame_size, framebuffer_info]() {
533+
auto surface_frame_1 = std::make_unique<SurfaceFrame>(
534+
SkSurface::MakeNull(1000, 1000), framebuffer_info,
535+
[](const SurfaceFrame& surface_frame, SkCanvas* canvas) {
536+
return true;
537+
},
538+
/*frame_size=*/SkISize::Make(800, 600));
539+
540+
auto surface_mock = std::make_unique<SurfaceMock>();
541+
EXPECT_CALL(*surface_mock, AcquireFrame(frame_size))
542+
.Times(1 /* frames */)
543+
.WillOnce(Return(ByMove(std::move(surface_frame_1))));
544+
545+
auto android_surface_mock =
546+
std::make_unique<AndroidSurfaceMock>(android_context);
547+
EXPECT_CALL(*android_surface_mock, IsValid()).WillOnce(Return(true));
548+
549+
EXPECT_CALL(*android_surface_mock, CreateGPUSurface(gr_context.get()))
550+
.WillOnce(Return(ByMove(std::move(surface_mock))));
551+
552+
EXPECT_CALL(*android_surface_mock, SetNativeWindow(window));
553+
return android_surface_mock;
554+
});
555+
auto embedder = std::make_unique<AndroidExternalViewEmbedder>(
556+
*android_context, jni_mock, surface_factory, GetTaskRunnersForFixture());
557+
558+
auto raster_thread_merger = GetThreadMergerFromPlatformThread();
559+
560+
EXPECT_CALL(*jni_mock, FlutterViewBeginFrame());
561+
embedder->BeginFrame(frame_size, nullptr, 1.5, raster_thread_merger);
562+
563+
{
564+
// Add first Android view.
565+
SkMatrix matrix = SkMatrix::Translate(100, 100);
566+
MutatorsStack stack;
567+
embedder->PrerollCompositeEmbeddedView(
568+
0, std::make_unique<EmbeddedViewParams>(matrix, SkSize::Make(100, 100),
569+
stack));
570+
// The JNI call to display the Android view.
571+
EXPECT_CALL(*jni_mock, FlutterViewOnDisplayPlatformView(
572+
0, 100, 100, 100, 100, 150, 150, stack));
573+
}
574+
575+
{
576+
// Add second Android view.
577+
SkMatrix matrix = SkMatrix::Translate(300, 100);
578+
MutatorsStack stack;
579+
embedder->PrerollCompositeEmbeddedView(
580+
1, std::make_unique<EmbeddedViewParams>(matrix, SkSize::Make(100, 100),
581+
stack));
582+
// The JNI call to display the Android view.
583+
EXPECT_CALL(*jni_mock, FlutterViewOnDisplayPlatformView(
584+
1, 300, 100, 100, 100, 150, 150, stack));
585+
}
586+
auto rect_paint = SkPaint();
587+
rect_paint.setColor(SkColors::kCyan);
588+
rect_paint.setStyle(SkPaint::Style::kFill_Style);
589+
590+
// This simulates Flutter UI that intersects with the two Android views.
591+
// Since we will compute the intersection for each android view in turn, and
592+
// finally merge The final size of the overlay will be smaller than the
593+
// width and height of the rect.
594+
embedder->CompositeEmbeddedView(1).canvas->drawRect(
595+
SkRect::MakeXYWH(150, 50, 200, 200), rect_paint);
596+
597+
EXPECT_CALL(*jni_mock, FlutterViewCreateOverlaySurface())
598+
.WillRepeatedly([&]() {
599+
return std::make_unique<PlatformViewAndroidJNI::OverlayMetadata>(
600+
1, window);
601+
});
602+
603+
// The JNI call to display the overlay surface.
604+
EXPECT_CALL(*jni_mock,
605+
FlutterViewDisplayOverlaySurface(1, 150, 100, 200, 100))
606+
.Times(1);
607+
608+
auto surface_frame = std::make_unique<SurfaceFrame>(
609+
SkSurface::MakeNull(1000, 1000), framebuffer_info,
610+
[](const SurfaceFrame& surface_frame, SkCanvas* canvas) mutable {
611+
return true;
612+
},
613+
/*frame_size=*/SkISize::Make(800, 600));
614+
615+
embedder->SubmitFrame(gr_context.get(), std::move(surface_frame));
616+
617+
EXPECT_CALL(*jni_mock, FlutterViewEndFrame());
618+
embedder->EndFrame(/*should_resubmit_frame=*/false, raster_thread_merger);
619+
}
620+
519621
TEST(AndroidExternalViewEmbedder, SubmitFrameOverlayComposition) {
520622
auto jni_mock = std::make_shared<JNIMock>();
521623
auto android_context =

0 commit comments

Comments
 (0)