-
Notifications
You must be signed in to change notification settings - Fork 6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Windows] Move to FlutterCompositor
for rendering
#48849
Conversation
b589838
to
9b70e4b
Compare
CompositorOpenGL::CompositorOpenGL(FlutterWindowsEngine* engine, | ||
impeller::ProcTableGLES::Resolver resolver) | ||
: engine_(engine), resolver_(resolver) {} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The CompositorOpenGL
mirrors Linux's backing store provider:
engine/shell/platform/linux/fl_backing_store_provider.cc
Lines 19 to 102 in 101396f
static void fl_backing_store_provider_dispose(GObject* object) { | |
FlBackingStoreProvider* self = FL_BACKING_STORE_PROVIDER(object); | |
glDeleteFramebuffers(1, &self->framebuffer_id); | |
glDeleteTextures(1, &self->texture_id); | |
G_OBJECT_CLASS(fl_backing_store_provider_parent_class)->dispose(object); | |
} | |
static void fl_backing_store_provider_class_init( | |
FlBackingStoreProviderClass* klass) { | |
G_OBJECT_CLASS(klass)->dispose = fl_backing_store_provider_dispose; | |
} | |
static void fl_backing_store_provider_init(FlBackingStoreProvider* self) {} | |
FlBackingStoreProvider* fl_backing_store_provider_new(int width, int height) { | |
FlBackingStoreProvider* provider = FL_BACKING_STORE_PROVIDER( | |
g_object_new(fl_backing_store_provider_get_type(), nullptr)); | |
provider->geometry = { | |
.x = 0, | |
.y = 0, | |
.width = width, | |
.height = height, | |
}; | |
glGenTextures(1, &provider->texture_id); | |
glGenFramebuffers(1, &provider->framebuffer_id); | |
glBindFramebuffer(GL_FRAMEBUFFER, provider->framebuffer_id); | |
glBindTexture(GL_TEXTURE_2D, provider->texture_id); | |
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); | |
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); | |
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); | |
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); | |
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, width, height, 0, GL_RGBA, | |
GL_UNSIGNED_BYTE, NULL); | |
glBindTexture(GL_TEXTURE_2D, 0); | |
glFramebufferTexture2D(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, | |
GL_TEXTURE_2D, provider->texture_id, 0); | |
return provider; | |
} | |
uint32_t fl_backing_store_provider_get_gl_framebuffer_id( | |
FlBackingStoreProvider* self) { | |
return self->framebuffer_id; | |
} | |
uint32_t fl_backing_store_provider_get_gl_texture_id( | |
FlBackingStoreProvider* self) { | |
return self->texture_id; | |
} | |
uint32_t fl_backing_store_provider_get_gl_target(FlBackingStoreProvider* self) { | |
return GL_TEXTURE_2D; | |
} | |
uint32_t fl_backing_store_provider_get_gl_format(FlBackingStoreProvider* self) { | |
// Flutter defines SK_R32_SHIFT=16, so SK_PMCOLOR_BYTE_ORDER should be BGRA. | |
// In Linux kN32_SkColorType is assumed to be kBGRA_8888_SkColorType. | |
// So we must choose a valid gl format to be compatible with surface format | |
// BGRA8. | |
// Following logics are copied from Skia GrGLCaps.cpp. | |
if (epoxy_is_desktop_gl()) { | |
// For OpenGL. | |
if (epoxy_gl_version() >= 12 || epoxy_has_gl_extension("GL_EXT_bgra")) { | |
return GL_RGBA8; | |
} | |
} else { | |
// For OpenGL ES. | |
if (epoxy_has_gl_extension("GL_EXT_texture_format_BGRA8888") || | |
(epoxy_has_gl_extension("GL_APPLE_texture_format_BGRA8888") && | |
epoxy_gl_version() >= 30)) { | |
return GL_BGRA8_EXT; | |
} | |
} | |
g_critical("Failed to determine valid GL format for Flutter rendering"); | |
return GL_RGBA8; | |
} |
@@ -134,6 +139,7 @@ source_set("flutter_windows_source") { | |||
deps = [ | |||
":flutter_windows_headers", | |||
"//flutter/fml:fml", | |||
"//flutter/impeller/renderer/backend/gles", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The Windows embedder uses Impeller's ProcTableGLES
and DescriptionGLES
to resolve OpenGLES functions and determine the GL version and extensions. This was the approach recommended by Impeller folks: https://discord.com/channels/608014603317936148/1173336353187041380/1182110838849536040
Also note that Windows has a GlProcTable
which is a worse version of Impeller's ProcTableGLES
. I was hoping to converge everything to ProcTableGLES
, however, ProcTableGLES
's initialization requires that the GL context is current. This prevents us from using ProcTableGLES
on the platform thread as it ideally shouldn't make the context current. We'll want to clean this up somehow in the future...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why does impeller require the context to be current - do we combine creation of the proc table with looking up gl state? Could we split that functionality out of proc table so you could use it exclusively?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
do we combine creation of the proc table with looking up gl state?
Yes. The proc table uses the DescriptionGLES
to determine capabilities and determine supported extension functions, and the DescriptionGLES
constructor fails if the context isn't current.
Could we split that functionality out of proc table so you could use it exclusively?
I think so. We could have a "raw" proc table that can be initialized without a GL context, does not have the description/capabilities, and includes potentially unsupported extension functions. The "safe" proc table would load the description/capabilities and remove unsupported functions. This might require a little experimentation to get the API right.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM as long as we're going with the C stdlib memory management
|
||
bool CompositorSoftware::Present(const FlutterLayer** layers, | ||
size_t layers_count) { | ||
FML_DCHECK(layers_count == 1); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This reminds me:
This wouldn't be in this PR, but how about iterating through however many backing store layers there are and blending them per-pixel-alpha so we can composite an arbitrary number of layers? I'm doing something similar on my local branch working with platform views. If that sounds good, I can start a PR once this lands to add that here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That sounds reasonable but before that PR we'd first want a design doc shared and reviewed by everyone :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Overall looks great -- just a few nits!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Usage looks fine to me. But if we can make an adjustment to proc table to make it more useful we should do that.
4bea4a5
to
aea1725
Compare
…140108) flutter/engine@9f7004e...45b95f2 2023-12-13 737941+loic-sharma@users.noreply.github.com [Windows] Move to `FlutterCompositor` for rendering (flutter/engine#48849) If this roll has caused a breakage, revert this CL and stop the roller using the controls here: https://autoroll.skia.org/r/flutter-engine-flutter-autoroll Please CC jsimmons@google.com,rmistry@google.com,zra@google.com on the revert to ensure that a human is aware of the problem. To file a bug in Flutter: https://github.com/flutter/flutter/issues/new/choose To report a problem with the AutoRoller itself, please file a bug: https://issues.skia.org/issues/new?component=1389291&template=1850622 Documentation for the AutoRoller is here: https://skia.googlesource.com/buildbot/+doc/main/autoroll/README.md
Reverting. The framework tree became red on Example failure: https://ci.chromium.org/ui/p/flutter/builders/prod/Windows%20run_debug_test_windows/5826/overview |
This reverts commit 45b95f2.
Reverts #48849 Initiated by: loic-sharma This change reverts the following previous change: Original Description: This migrates the Windows embedder to `FlutterCompositor` so that the engine renders off-screen to a framebuffer instead of directly onto the window's surface. This will allow us to support platform views and multiple views on Windows. <details> <summary>Tests...</summary> * Verify OpenGL compositor's raster time isn't regressed and memory increase is reasonable * Software compositor's raster time and memory isn't regressed Test device configurations * [x] Windows 11 (hardware acceleration enabled/disabled) * [x] Windows Arm64 (hardware acceleration enabled/disabled) * [x] Windows 7 (hardware acceleration enabled/disabled, DWM enabled/disabled) </details> Addresses flutter/flutter#128904 [C++, Objective-C, Java style guides]: https://github.com/flutter/engine/blob/main/CONTRIBUTING.md#style
…ision)" (#140123) Reverts #140108 Initiated by: loic-sharma This change reverts the following previous change: Original Description: flutter/engine@9f7004e...45b95f2 2023-12-13 737941+loic-sharma@users.noreply.github.com [Windows] Move to `FlutterCompositor` for rendering (flutter/engine#48849) If this roll has caused a breakage, revert this CL and stop the roller using the controls here: https://autoroll.skia.org/r/flutter-engine-flutter-autoroll Please CC jsimmons@google.com,rmistry@google.com,zra@google.com on the revert to ensure that a human is aware of the problem. To file a bug in Flutter: https://github.com/flutter/flutter/issues/new/choose To report a problem with the AutoRoller itself, please file a bug: https://issues.skia.org/issues/new?component=1389291&template=1850622 Documentation for the AutoRoller is here: https://skia.googlesource.com/buildbot/+doc/main/autoroll/README.md
…140130) flutter/engine@9f7004e...923f9e2 2023-12-14 98614782+auto-submit[bot]@users.noreply.github.com Reverts "[Windows] Move to `FlutterCompositor` for rendering" (flutter/engine#49015) 2023-12-14 magder@google.com Add xcprivacy privacy manifest to iOS framework (flutter/engine#48951) 2023-12-14 30870216+gaaclarke@users.noreply.github.com [Impeller] Made the new blur support 1D blurs (flutter/engine#49001) 2023-12-14 skia-flutter-autoroll@skia.org Roll Skia from 69c02c9d56b2 to 188515347032 (1 revision) (flutter/engine#49005) 2023-12-14 bdero@google.com [Impeller] Add golden for clipped+transformed blur. (flutter/engine#48886) 2023-12-14 bdero@google.com [Flutter GPU] Runtime shader import. (flutter/engine#48875) 2023-12-13 737941+loic-sharma@users.noreply.github.com [Windows] Move to `FlutterCompositor` for rendering (flutter/engine#48849) If this roll has caused a breakage, revert this CL and stop the roller using the controls here: https://autoroll.skia.org/r/flutter-engine-flutter-autoroll Please CC jsimmons@google.com,rmistry@google.com,zra@google.com on the revert to ensure that a human is aware of the problem. To file a bug in Flutter: https://github.com/flutter/flutter/issues/new/choose To report a problem with the AutoRoller itself, please file a bug: https://issues.skia.org/issues/new?component=1389291&template=1850622 Documentation for the AutoRoller is here: https://skia.googlesource.com/buildbot/+doc/main/autoroll/README.md
why it is reverted? |
## Reland #48849 was reverted as it incorrectly expected to receive always 1 layer. However, the engine will present 0 layers on an ["empty" app](https://github.com/flutter/flutter/blob/6981fe6fd3aacb95bfc4a6c427ee5d493f43c5dc/dev/integration_tests/ui/lib/empty.dart#L8-L19). This pull request is split into two commits: 1. df604a1 is the original pull request, unchanged 2. c30b369 adds the ability to "clear" the view if the engine presents 0 layers ## Original pull request description This migrates the Windows embedder to `FlutterCompositor` so that the engine renders off-screen to a framebuffer instead of directly onto the window's surface. This will allow us to support platform views and multiple views on Windows. Addresses flutter/flutter#128904 [C++, Objective-C, Java style guides]: https://github.com/flutter/engine/blob/main/CONTRIBUTING.md#style
This migrates the Windows embedder to
FlutterCompositor
so that the engine renders off-screen to a framebuffer instead of directly onto the window's surface. This will allow us to support platform views and multiple views on Windows.Tests...
Test device configurations
Addresses flutter/flutter#128904
Pre-launch Checklist
///
).If you need help, consider asking for advice on the #hackers-new channel on Discord.