Skip to content

Commit 0e62d43

Browse files
authored
Starts flipping content on windows to avoid full screen renders (flutter#193133)
This is glue code to hook us up to the optimization we've created in ANGLE at https://chromium-review.git.corp.google.com/c/angle/angle/+/8436859 This removes a temporary full screen texture and a full screen render pass, allowing us to MSAA resolve directly into the swapchain. fixes: flutter#192496 ## screenshot of afterwards capture Notice the last thing is a resolve. <img width="1674" height="903" alt="Screenshot 2026-09-25 133558" src="https://github.com/user-attachments/assets/599449e8-57be-40c2-9cc9-fd1fc1c9217e" /> ## Pre-launch Checklist - [x] I read the [Contributor Guide] and followed the process outlined there for submitting PRs. - [x] I read the [AI contribution guidelines] and understand my responsibilities, or I am not using AI tools. - [x] I read the [Tree Hygiene] wiki page, which explains my responsibilities. - [x] I read and followed the [Flutter Style Guide], including [Features we expect every widget to implement]. - [x] I signed the [CLA]. - [x] I listed at least one issue that this PR fixes in the description above. - [x] I updated/added relevant in-code documentation (doc comments with `///`). - [x] If this PR introduces a new feature or capability, I created and linked a website documentation issue or PR in [flutter/website] (or verified none is needed). - [x] I added new tests to check the change I am making, or this PR is [test-exempt]. - [x] I followed the [breaking change policy] and added [Data Driven Fixes] where supported. - [x] All existing and new tests are passing. If you need help, consider asking for advice on the #hackers-new channel on [Discord]. If this change needs to override an active code freeze, provide a comment explaining why. The code freeze workflow can be overridden by code reviewers. See pinned issues for any active code freezes with guidance. **Note**: The Flutter team is currently trialing the use of [Gemini Code Assist for GitHub](https://developers.google.com/gemini-code-assist/docs/review-github-code). Comments from the `gemini-code-assist` bot should not be taken as authoritative feedback from the Flutter team. If you find its comments useful you can update your code accordingly, but if you are unsure or disagree with the feedback, please feel free to wait for a Flutter team member's review for guidance on which automated comments should be addressed. <!-- Links --> [Contributor Guide]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#overview [AI contribution guidelines]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#ai-contribution-guidelines [Tree Hygiene]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md [test-exempt]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#tests [Flutter Style Guide]: https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md [Features we expect every widget to implement]: https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md#features-we-expect-every-widget-to-implement [CLA]: https://cla.developers.google.com/ [flutter/tests]: https://github.com/flutter/tests [flutter/website]: https://github.com/flutter/website [breaking change policy]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#handling-breaking-changes [Discord]: https://github.com/flutter/flutter/blob/main/docs/contributing/Chat.md [Data Driven Fixes]: https://github.com/flutter/flutter/blob/main/docs/contributing/Data-driven-Fixes.md
1 parent f1a0549 commit 0e62d43

17 files changed

Lines changed: 381 additions & 69 deletions

File tree

‎DEPS‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -541,7 +541,7 @@ deps = {
541541
Var('flutter_git') + '/third_party/swiftshader.git' + '@' + '1be9f83618f8ba258431c0c13d7a083eb193df11',
542542

543543
'engine/src/flutter/third_party/angle':
544-
Var('flutter_git') + '/third_party/angle' + '@' + 'cc08479fbcc181697fa837069ce1103c58c15528',
544+
Var('flutter_git') + '/third_party/angle' + '@' + 'a8d74ca3e5e9e4ffa241330ceedcbe302443e472',
545545

546546
'engine/src/flutter/third_party/vulkan_memory_allocator':
547547
Var('chromium_git') + '/external/github.com/GPUOpen-LibrariesAndSDKs/VulkanMemoryAllocator' + '@' + 'c788c52156f3ef7bc7ab769cb03c110a53ac8fcb',

‎engine/src/flutter/common/settings.h‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,14 @@ struct Settings {
243243
// Whether to use SDFs for rendering in Impeller.
244244
bool impeller_use_sdfs = false;
245245

246+
// Whether the origin of the default framebuffer (framebuffer 0) is the
247+
// top-left of the window rather than OpenGL's usual bottom-left.
248+
//
249+
// Set by embedders whose window surface is created with an inverted Y axis,
250+
// such as ANGLE's EGL_SURFACE_ORIENTATION_INVERT_Y_ANGLE. Only meaningful
251+
// for OpenGL ES backends.
252+
bool impeller_top_left_default_framebuffer_origin = false;
253+
246254
// Log a warning during shell initialization if Impeller is not enabled.
247255
bool warn_on_impeller_opt_out = false;
248256

‎engine/src/flutter/impeller/base/flags.h‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,14 @@ struct Flags {
1010
/// Use SDFs for rendering.
1111
bool use_sdfs = false;
1212

13+
/// Whether the origin of the default framebuffer (framebuffer 0) is the
14+
/// top-left of the window rather than OpenGL's usual bottom-left.
15+
///
16+
/// Set by embedders whose window surface is created with an inverted Y
17+
/// axis, such as ANGLE's EGL_SURFACE_ORIENTATION_INVERT_Y_ANGLE. Only
18+
/// meaningful for the OpenGL ES backend.
19+
bool top_left_default_framebuffer_origin = false;
20+
1321
bool operator==(const Flags&) const = default;
1422
};
1523
} // namespace impeller

‎engine/src/flutter/impeller/renderer/backend/gles/context_gles.cc‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,9 @@ ContextGLES::ContextGLES(
3535
const std::vector<std::shared_ptr<fml::Mapping>>& shader_libraries_mappings,
3636
bool enable_gpu_tracing,
3737
std::shared_ptr<fml::BasicTaskRunner> io_task_runner)
38-
: Context(flags) {
38+
: Context(flags),
39+
top_left_default_framebuffer_origin_(
40+
flags.top_left_default_framebuffer_origin) {
3941
reactor_ = std::make_shared<ReactorGLES>(std::move(gl));
4042
if (!reactor_->IsValid()) {
4143
VALIDATION_LOG << "Could not create valid reactor.";

‎engine/src/flutter/impeller/renderer/backend/gles/context_gles.h‎

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,22 @@ class ContextGLES final : public Context,
5050
const std::shared_ptr<GpuSubmissionTracker>& GetMutableSubmissionTracker()
5151
const;
5252

53+
//----------------------------------------------------------------------------
54+
/// @brief Whether the origin of the default framebuffer (framebuffer 0)
55+
/// is the top-left of the window rather than OpenGL's usual
56+
/// bottom-left.
57+
///
58+
/// This is true for embedders whose window surface is created
59+
/// with an inverted Y axis, such as ANGLE's
60+
/// EGL_SURFACE_ORIENTATION_INVERT_Y_ANGLE. When true, render
61+
/// passes targeting wrapped framebuffers store their contents
62+
/// top-down so that a 1:1 blit into the default framebuffer
63+
/// needs no vertical flip.
64+
///
65+
bool HasTopLeftDefaultFramebufferOrigin() const {
66+
return top_left_default_framebuffer_origin_;
67+
}
68+
5369
private:
5470
std::shared_ptr<ReactorGLES> reactor_;
5571
std::shared_ptr<GpuSubmissionTracker> submission_tracker_ =
@@ -65,6 +81,7 @@ class ContextGLES final : public Context,
6581
// in order to satisfy the Context::GetCapabilities signature which returns
6682
// a reference.
6783
std::shared_ptr<const Capabilities> device_capabilities_;
84+
bool top_left_default_framebuffer_origin_ = false;
6885
bool is_valid_ = false;
6986

7087
ContextGLES(

‎engine/src/flutter/impeller/renderer/backend/gles/render_pass_gles.cc‎

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -567,9 +567,21 @@ void RenderPassGLES::ResetGLState(const ProcTableGLES& gl) {
567567
// is bottom left origin, so we convert the coordinates here.
568568
ISize target_size = pass_data.color_attachment->GetSize();
569569

570-
// Offscreen FBO passes flip in the vertex shader (the swapchain is
571-
// left alone); see https://github.com/flutter/flutter/issues/186554.
572-
const bool flip_y = !is_wrapped_fbo;
570+
// Offscreen (non-wrapped) FBOs always flip in the vertex shader so they are
571+
// stored with a top-left origin, matching Impeller's coordinate system. See
572+
// https://github.com/flutter/flutter/issues/186554.
573+
//
574+
// Wrapped FBOs match the embedder's default framebuffer origin:
575+
// - Bottom-left (the OpenGL default): no flip.
576+
// - Top-left (currently only the Windows embedder, via ANGLE's
577+
// EGL_SURFACE_ORIENTATION_INVERT_Y_ANGLE): flip, like offscreen FBOs.
578+
// The whole pipeline is then in one orientation, so the blit that
579+
// presents a wrapped framebuffer to the swapchain is a straight 1:1 copy,
580+
// which lets the driver resolve or DMA it instead of running a
581+
// full-screen shader pass to flip it.
582+
const bool top_left_default_framebuffer_origin =
583+
ContextGLES::Cast(*impeller_context).HasTopLeftDefaultFramebufferOrigin();
584+
const bool flip_y = !is_wrapped_fbo || top_left_default_framebuffer_origin;
573585
const float y_flip_value = flip_y ? -1.0f : 1.0f;
574586

575587
RenderPassStateCache state_cache;

‎engine/src/flutter/impeller/renderer/backend/gles/render_pass_gles_unittests.cc‎

Lines changed: 85 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,10 +60,10 @@ class RenderPassGLESWithDiscardFrameBufferExtTest
6060

6161
namespace {
6262
std::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+
566618
TEST_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+
622703
TEST_F(RenderPassGLESCommandTest,
623704
DeduplicatesEnabledBlendStencilDepthAndSharedProgramAcrossVariants) {
624705
auto ctx = CreateRenderPassGLESContext();

‎engine/src/flutter/shell/common/switch_defs.h‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -295,6 +295,13 @@ DEF_SWITCH(kImpellerLazyShaderMode,
295295
DEF_SWITCH(kImpellerUseSdFs,
296296
"impeller-use-sdfs",
297297
"Whether to use SDFs for rendering in Impeller.")
298+
DEF_SWITCH(kImpellerTopLeftDefaultFramebufferOrigin,
299+
"impeller-top-left-default-framebuffer-origin",
300+
"Whether the origin of the default framebuffer (framebuffer 0) is "
301+
"the top-left of the window rather than OpenGL's usual "
302+
"bottom-left. Set by embedders whose window surface is created "
303+
"with an inverted Y axis, such as ANGLE's "
304+
"EGL_SURFACE_ORIENTATION_INVERT_Y_ANGLE. Defaults to false.")
298305
DEF_SWITCHES_END
299306

300307
} // namespace flutter

‎engine/src/flutter/shell/common/switches.cc‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -566,6 +566,9 @@ Settings SettingsFromCommandLine(const fml::CommandLine& command_line,
566566
command_line.HasOption(FlagForSwitch(Switch::kImpellerLazyShaderMode));
567567
settings.impeller_use_sdfs =
568568
command_line.HasOption(FlagForSwitch(Switch::kImpellerUseSdFs));
569+
settings.impeller_top_left_default_framebuffer_origin =
570+
command_line.HasOption(
571+
FlagForSwitch(Switch::kImpellerTopLeftDefaultFramebufferOrigin));
569572

570573
return settings;
571574
}

‎engine/src/flutter/shell/platform/embedder/embedder.cc‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2319,6 +2319,8 @@ FlutterEngineResult FlutterEngineInitialize(size_t version,
23192319

23202320
impeller::Flags impeller_flags;
23212321
impeller_flags.use_sdfs = settings.impeller_use_sdfs;
2322+
impeller_flags.top_left_default_framebuffer_origin =
2323+
settings.impeller_top_left_default_framebuffer_origin;
23222324

23232325
auto on_create_platform_view = InferPlatformViewCreationCallback(
23242326
config, user_data, platform_dispatch_table,

0 commit comments

Comments
 (0)