-
Notifications
You must be signed in to change notification settings - Fork 6k
Refactor FlRenderer to platform-independent implementation #24011
Conversation
|
@robert-ancell This is the first part of pr to implement platform views on Linux. I have tried to minimize modifications.. But implementing compositor requires all of these changes. |
b66a9de to
4e0c564
Compare
914d01f to
e8e01b9
Compare
All tests are passed now. |
| * | ||
| * Returns %TRUE if successful. | ||
| */ | ||
| gboolean (*collect_backing_store)(FlRenderer* renderer, |
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.
Is "collect" used elsewhere in Flutter to mean release? If not I think the meaning of this name is unintuitive.
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 function implements
engine/shell/platform/embedder/embedder.h
Line 1050 in 0bf71f6
| FlutterBackingStoreCollectCallback collect_backing_store_callback; |
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.
Cool, in that case sounds good
| glGenTextures(1, &provider->texture_id); | ||
| glGenFramebuffers(1, &provider->framebuffer_id); | ||
|
|
||
| glBindFramebuffer(GL_FRAMEBUFFER, provider->framebuffer_id); |
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.
I notice you unbind the texture at the end of the function, but don't unbind the framebuffer. It doesn't seem to be documented that this leaves the framebuffer bound. Is this intentional?
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.
Binding framebuffer 0 does not mean 'unbinding' framebuffer, but binding to the system default framebuffer. Flutter/Skia will always bind a specific framebuffer (provided by FlBackingStoreProvider) before rendering. So we have no need to bind to framebuffer 0 here. Restoring framebuffer binding requires a call to glGetIntegerv(GL_FRAMEBUFFER_BINDING, &old_fbo);.
macOS implementation has the same behavior, and because framebuffer 0 is not the default framebuffer.
engine/shell/platform/darwin/macos/framework/Source/FlutterFrameBufferProvider.mm
Lines 31 to 37 in 0bf71f6
| glBindFramebuffer(GL_FRAMEBUFFER, _frameBufferId); | |
| glBindTexture(GL_TEXTURE_RECTANGLE_ARB, _backingTexture); | |
| glTexParameterf(GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_MIN_FILTER, GL_NEAREST); | |
| glTexParameterf(GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_MAG_FILTER, GL_NEAREST); | |
| glTexParameteri(GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); | |
| glTexParameteri(GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); | |
| glBindTexture(GL_TEXTURE_RECTANGLE_ARB, 0); |
|
|
||
| uint32_t framebuffer_id; | ||
| uint32_t texture_id; | ||
| GdkRectangle geometry; |
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.
Does geometry get set anywhere? I see it's used, but I don't see it being set.
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.
Now geometry is used in FlGLArea for resolving drawing texture repeatedly.
| GdkWindow* window = gtk_widget_get_parent_window(widget); | ||
|
|
||
| *visible = gdk_window_create_gl_context(window, error); | ||
| *resource = gdk_window_create_gl_context(window, error); |
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.
Looks sus to use error twice without checking it. probably best to check error after each call.
In practice I don't think this is unsafe or a memory leak, but if the 1st call results in an error the 2nd call will fail a non-fatal assertion inside GTK (which prints an error message to console). Might leak an error if assertions are turned off.
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.
Added error check right after line 24.
|
Tested and Wayland works on Sway and Mir. One oddity is that the GL view seems to be in tiled mode, so when you're resizing the app to be bigger (which is still al little janky) instead of being black, white or whatever was there before, the top and/or right edge is a copy of the other edge side of the window. |
e8e01b9 to
f1310d0
Compare
Now resizing the app to be bigger, area not covered will be white. |
wmww
left a comment
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
robert-ancell
left a comment
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, thanks @huanghongxun!
|
Maybe we need your approval? @stuartmorgan @cbracken |
|
@robert-ancell is a committer, so his review is sufficient unless there's a reason someone else needs to review it. |
…4011) Refactor FlRenderer to platform-independent implementation
This pull request is part of #23985.
This pull request refactors
FlRendererto a platform-independent implementation.FlGLAreato represent a Flutter content layer from compositor.Code changes:
egl_utils.h/ccsince I'm usinglibepoxyinstead, which is also used by GTK.mock_egl.ccis refactored intomock_epoxy.ccfor mockinglibepoxy.wayland-clientandx11requirement. Now we usegtk_cairoto draw OpenGL textures.FlBackingStoreProviderfor framebuffer and texture creation. Just likeFlutterFrameBufferProviderin macOS implementation.FlEnginenow enables compositor capability of embedder.FlGLAreafor framebuffer and texture drawing. everyFlGLAreahas aGdkWindow, because we may embed some widgets provided by plugins, which have ownGdkWindows.FlRendereris now responsible for compositing. Creates backing store byFlBackingStoreProvider, and present layers by puttingFlGLAreas with given textures intoFlView.FlRendererGLfor OpenGL renderer, createsGdkGLContextas OpenGL context.FlViewnow isGtkContainerto support multiple layers ofFlGLArea, maintaining a cachedgl_area_list, andchildren_list. Every frameFlRendererwill reset children ofFlView, but if every time we unparent and parent these child widgets, GtkInspector will crash. So calculates diff ofchildren_listis necessary.GtkEventBoxon top ofFlView, instead of directly capturing events inFlView, becauseFlGLAreas have their ownGdkWindows, which can capture pointer events, we must cover aGdkWindowfor event capturing on the top.This pr is part of platform view implementation on Linux, related issue: flutter/flutter#41724.
Pre-launch Checklist
writing and running engine tests.
///).If you need help, consider asking for advice on the #hackers-new channel on [Discord].