-
Notifications
You must be signed in to change notification settings - Fork 6k
Share Android surface GrDirectContext #23798
Share Android surface GrDirectContext #23798
Conversation
It looks like this pull request may not have tests. Please make sure to add tests before merging. If you need an exemption to this rule, contact Hixie on the #hackers channel in Chat. Reviewers: Read the Tree Hygiene page and make sure this patch meets those guidelines before LGTMing. |
Writing tests now. Please take a look to see if the ownership scheme makes sense. |
b4e821b
to
7d79434
Compare
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.
Reading guide: most of this PR is just plumbing. There are just 2 spots that actually do real work.
} | ||
|
||
std::unique_ptr<Surface> AndroidSurfaceGL::CreateGPUSurface( | ||
GrDirectContext* gr_context) { | ||
if (gr_context) { | ||
return std::make_unique<GPUSurfaceGL>(sk_ref_sp(gr_context), this, true); | ||
} else { | ||
sk_sp<GrDirectContext> main_skia_context = |
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 is more or less 1 of 2 of the actual interesting parts of this PR. When AndroidSurfaceGL needs to make a GPUSurfaceGL (which would then make a GrDirectContext implicitly), the AndroidSurfaceGL makes one explicitly, then stores it in the AndroidContext for reuse if more AndroidSurfaceGLs are made with the same AndroidContext.
@@ -317,7 +317,8 @@ std::unique_ptr<Surface> PlatformViewAndroid::CreateRenderingSurface() { | |||
if (!android_surface_) { | |||
return nullptr; | |||
} | |||
return android_surface_->CreateGPUSurface(); | |||
return android_surface_->CreateGPUSurface( | |||
android_context_->GetMainSkiaContext().get()); |
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 is the 2/2 of the actual active parts of this PR. If more GPUSurfaces are made with other AndroidSurfaces, re-use the same GrDirectContext from the AndroidContext.
Since no one looked yet, I added Vulkan support to this one too. Unfortunately there are a lot of impediments to testing. For OpenGL, the main challenge is that the AndroidSurfaceGL needs a AndroidEGLSurface. It also needs an AndroidContextGL, where half of the cc code is interactions with <EGL/eglext.h>. This needs to pull in the Android ndk which we wouldn't want to do into host_debug_unopt where the unittests will be. Possible approaches:
Then for AndroidSurfaceVulkan, the challenge is only engine builds with Possible approaches:
Maybe you guys have some ideas. Otherwise, I'd say this becomes a Q1/Q2 task of doing the long term solution of breaking all these classes up by composition as much as possible and only let the injectable bottom of indirections import Android (a bit like the JNI in java) so we can test the rest. And break up the big flutter_shell_native target. |
74a66c2
to
60222a8
Compare
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!
shell/gpu/gpu_surface_vulkan.cc
Outdated
@@ -12,7 +12,20 @@ GPUSurfaceVulkan::GPUSurfaceVulkan( | |||
GPUSurfaceVulkanDelegate* delegate, | |||
std::unique_ptr<vulkan::VulkanNativeSurface> native_surface, | |||
bool render_to_surface) | |||
: window_(delegate->vk(), std::move(native_surface), render_to_surface), | |||
: GPUSurfaceVulkan(nullptr, |
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.
nit: parameter comment would be nice for nullptr
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.
thanks. Done here and in vulkan_window
Heads up, my work on opengl had to be reverted. I'm investigating now (flutter/flutter#74502) You probably don't want to land this until I remedy this problem. |
I'm actually guessing this PR fixes that issue :D. Since your PR changed GPUSurfaceGL for both platforms but might not have accounted for how Android uses it and this PR accounts for it. Let me run that test on this commit. |
shell/gpu/gpu_surface_vulkan.cc
Outdated
@@ -12,7 +12,7 @@ GPUSurfaceVulkan::GPUSurfaceVulkan( | |||
GPUSurfaceVulkanDelegate* delegate, | |||
std::unique_ptr<vulkan::VulkanNativeSurface> native_surface, | |||
bool render_to_surface) | |||
: GPUSurfaceVulkan(nullptr, | |||
: GPUSurfaceVulkan(nullptr /* GrDirectContext */, |
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 proper way to comment these is with /*foobar=*/
, where foobar is the name of the parameter according to the declaration.
https://google.github.io/styleguide/cppguide.html#Function_Argument_Comments
Unfortunately my last testing path didn't quite go the way I wanted. I was thinking of just actually using the NDK and build 2 targets for Android. A normal jar for feeding into gradle and a separate executable for the unit test with the same deps upstream as the cpp files used to build the libflutter.so. It works and builds, except it's built with the NDK compiler for elf 64 rather than mach-o 64 to be able to run locally. A further slice might be pretty complicated to use mac's clang but import standard libraries from Android's NDK. I think the proper modular, long term solution is to continue slicing and mocking the c++ classes like Emmanuel started in flutter/flutter#59031 for the rest of the dependencies. |
Spot checked a number of Android devicelab tests |
* 004d8ad Roll Skia from cc6961b9ac5e to 6a272434c2b2 (3 revisions) (flutter/engine#23864) * 7c2da3b reland of flutter/engine#23634 (flutter/engine#23865) * a4f02b7 Share Android surface GrDirectContext (flutter/engine#23798) * 31ef1dd Roll Skia from 6a272434c2b2 to bfc9be0f773f (2 revisions) (flutter/engine#23867) * 6dec57f Remove workarounds now that type promotion accounts for local boolean variables. (flutter/engine#23862) * a787229 Roll Skia from bfc9be0f773f to 3193ff271628 (5 revisions) (flutter/engine#23872) * a242dd8 [web] Fix shadows for arbitrary paths on PhysicalShape (flutter/engine#23830) * 05b4bec Started using Dart_CreateInGroup when using spawn on a release build (flutter/engine#23782)
Does half of flutter/flutter#73597.
The Android side of #23634.
Manual tested and via the new Scenario App spawn test so far.
Pre-launch Checklist
writing and running engine tests.
///
).If you need help, consider asking for advice on the #hackers-new channel on Discord.