@@ -60,10 +60,10 @@ class RenderPassGLESWithDiscardFrameBufferExtTest
6060
6161namespace {
6262std::shared_ptr<ContextGLES> CreateFakeGLESContext (
63- ProcTableGLES::Resolver resolver = kMockResolverGLES ) {
63+ ProcTableGLES::Resolver resolver = kMockResolverGLES ,
64+ Flags flags = Flags{}) {
6465 auto dummy_gl_procs = std::make_unique<ProcTableGLES>(std::move (resolver));
6566 auto dummy_shader_library = std::vector<std::shared_ptr<fml::Mapping>>{};
66- auto flags = Flags{};
6767 return ContextGLES::Create (flags, std::move (dummy_gl_procs),
6868 dummy_shader_library, false );
6969}
@@ -238,14 +238,15 @@ class RenderPassGLESCommandTest : public ::testing::Test {
238238 // see, which is how a caller selects the hardware or emulated instancing
239239 // path.
240240 static RenderPassGLESContext CreateRenderPassGLESContext (
241- ProcTableGLES::Resolver resolver = kMockResolverGLES ) {
241+ ProcTableGLES::Resolver resolver = kMockResolverGLES ,
242+ Flags flags = Flags{}) {
242243 std::unique_ptr<NiceMock<MockGLESImpl>> mock_gl_impl =
243244 std::make_unique<NiceMock<MockGLESImpl>>();
244245 testing::NiceMock<MockGLESImpl>& mock_gl_impl_ref = *mock_gl_impl;
245246 std::shared_ptr<MockGLES> mock_gl = MockGLES::Init (std::move (mock_gl_impl));
246247
247248 std::shared_ptr<ContextGLES> context =
248- CreateFakeGLESContext (std::move (resolver));
249+ CreateFakeGLESContext (std::move (resolver), flags );
249250 std::shared_ptr<MockWorker> dummy_worker = std::make_shared<MockWorker>();
250251 context->AddReactorWorker (dummy_worker);
251252 std::shared_ptr<ReactorGLES> reactor = context->GetReactor ();
@@ -563,6 +564,57 @@ TEST_F(RenderPassGLESCommandTest, ZeroInstanceCountIssuesNoDraw) {
563564 EXPECT_TRUE (reactor->React ());
564565}
565566
567+ namespace {
568+ // Builds a render pass targeting a wrapped (embedder supplied) framebuffer,
569+ // which is the case whose orientation depends on the default framebuffer's
570+ // origin.
571+ std::shared_ptr<RenderPass> CreateWrappedFBORenderPass (
572+ const std::shared_ptr<ContextGLES>& context,
573+ const std::shared_ptr<ReactorGLES>& reactor,
574+ const std::shared_ptr<CommandBuffer>& command_buffer) {
575+ TextureDescriptor tex_desc;
576+ tex_desc.size = {100 , 100 };
577+ tex_desc.format = PixelFormat::kR8G8B8A8UNormInt ;
578+ // A framebuffer that gets presented is never transient, and attaching a
579+ // transient texture with a kStore store action fails validation.
580+ tex_desc.storage_mode = StorageMode::kDevicePrivate ;
581+
582+ RenderTarget target;
583+ ColorAttachment color0;
584+ color0.texture = TextureGLES::WrapFBO (reactor, tex_desc, /* fbo=*/ 1u );
585+ color0.store_action = StoreAction::kStore ;
586+ color0.load_action = LoadAction::kClear ;
587+ target.SetColorAttachment (color0, 0 );
588+
589+ return command_buffer->CreateRenderPass (target);
590+ }
591+ } // namespace
592+
593+ // By default the default framebuffer uses OpenGL's bottom-left origin, so a
594+ // wrapped FBO keeps the top-down to bottom-up viewport conversion.
595+ TEST_F (RenderPassGLESCommandTest, WrappedFBOConvertsViewportByDefault) {
596+ auto ctx = CreateRenderPassGLESContext ();
597+ testing::NiceMock<MockGLESImpl>& mock_gl_impl_ref = ctx.mock_gl_impl_ref ;
598+ std::shared_ptr<PipelineGLES>& pipeline = ctx.pipeline ;
599+ std::shared_ptr<ReactorGLES>& reactor = ctx.reactor ;
600+
601+ std::shared_ptr<RenderPass> render_pass =
602+ CreateWrappedFBORenderPass (ctx.context , reactor, ctx.command_buffer );
603+
604+ render_pass->SetPipeline (PipelineRef (pipeline));
605+ render_pass->SetElementCount (1 );
606+ render_pass->SetIndexBuffer ({}, IndexType::kNone );
607+ render_pass->SetViewport (
608+ Viewport{Rect::MakeXYWH (0 , 0 , 50 , 50 ), DepthRange{0 .0f , 1 .0f }});
609+ EXPECT_TRUE (render_pass->Draw ().ok ());
610+
611+ // flip_y = false, so y is converted: 100 - 0 - 50 == 50.
612+ EXPECT_CALL (mock_gl_impl_ref, Viewport (0 , 50 , 50 , 50 )).Times (1 );
613+
614+ EXPECT_TRUE (render_pass->EncodeCommands ());
615+ EXPECT_TRUE (reactor->React ());
616+ }
617+
566618TEST_F (RenderPassGLESCommandTest,
567619 DeduplicatesPipelineAndScissorStateAcrossCommands) {
568620 auto ctx = CreateRenderPassGLESContext ();
@@ -619,6 +671,35 @@ TEST_F(RenderPassGLESCommandTest,
619671 EXPECT_TRUE (reactor->React ());
620672}
621673
674+ // When the embedder's default framebuffer has a top-left origin the whole
675+ // pipeline is stored top-down, so a wrapped FBO flips in the vertex shader and
676+ // passes the viewport through unconverted.
677+ TEST_F (RenderPassGLESCommandTest, WrappedFBOPassesViewportThroughWhenTopLeft) {
678+ Flags flags;
679+ flags.top_left_default_framebuffer_origin = true ;
680+
681+ auto ctx = CreateRenderPassGLESContext (kMockResolverGLES , flags);
682+ testing::NiceMock<MockGLESImpl>& mock_gl_impl_ref = ctx.mock_gl_impl_ref ;
683+ std::shared_ptr<PipelineGLES>& pipeline = ctx.pipeline ;
684+ std::shared_ptr<ReactorGLES>& reactor = ctx.reactor ;
685+
686+ std::shared_ptr<RenderPass> render_pass =
687+ CreateWrappedFBORenderPass (ctx.context , reactor, ctx.command_buffer );
688+
689+ render_pass->SetPipeline (PipelineRef (pipeline));
690+ render_pass->SetElementCount (1 );
691+ render_pass->SetIndexBuffer ({}, IndexType::kNone );
692+ render_pass->SetViewport (
693+ Viewport{Rect::MakeXYWH (0 , 0 , 50 , 50 ), DepthRange{0 .0f , 1 .0f }});
694+ EXPECT_TRUE (render_pass->Draw ().ok ());
695+
696+ // flip_y = true, so y is used as-is.
697+ EXPECT_CALL (mock_gl_impl_ref, Viewport (0 , 0 , 50 , 50 )).Times (1 );
698+
699+ EXPECT_TRUE (render_pass->EncodeCommands ());
700+ EXPECT_TRUE (reactor->React ());
701+ }
702+
622703TEST_F (RenderPassGLESCommandTest,
623704 DeduplicatesEnabledBlendStencilDepthAndSharedProgramAcrossVariants) {
624705 auto ctx = CreateRenderPassGLESContext ();
0 commit comments