This repository was archived by the owner on Feb 25, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6k
Only creates 'onscreen_surface_' when it's not available in 'AndroidSurfaceGL::CreateSnapshotSurface' #30590
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -49,7 +49,7 @@ class AndroidSurfaceGL final : public GPUSurfaceGLDelegate, | |
| bool SetNativeWindow(fml::RefPtr<AndroidNativeWindow> window) override; | ||
|
|
||
| // |AndroidSurface| | ||
| virtual std::unique_ptr<Surface> CreatePbufferSurface() override; | ||
| virtual std::unique_ptr<Surface> CreateSnapshotSurface() override; | ||
|
|
||
| // |GPUSurfaceGLDelegate| | ||
| std::unique_ptr<GLContextResult> GLContextMakeCurrent() override; | ||
|
|
@@ -66,6 +66,14 @@ class AndroidSurfaceGL final : public GPUSurfaceGLDelegate, | |
| // |GPUSurfaceGLDelegate| | ||
| sk_sp<const GrGLInterface> GetGLInterface() const override; | ||
|
|
||
| // Obtain a raw pointer to the on-screen AndroidEGLSurface. | ||
| // | ||
| // This method is intended for use in tests. Callers must not | ||
| // delete the returned pointer. | ||
| AndroidEGLSurface* GetOnscreenSurface() const { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please add a doc comment, probably explaining that this is only intended for tests. e.g.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. (I went ahead and made this change so we can just get this landed, rather than wait for another time zone cycle :) |
||
| return onscreen_surface_.get(); | ||
| } | ||
|
|
||
| private: | ||
| fml::RefPtr<AndroidNativeWindow> native_window_; | ||
| std::unique_ptr<AndroidEGLSurface> onscreen_surface_; | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Maybe just an early return instead? This needs a test too.
Uh oh!
There was an error while loading. Please reload this page.
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.
If we early return, then
Rasterizer::DoMakeRasterSnapshotwill execute the following logic, which will change from hardware rasterization to software rasterization. The performance will be a little bit worse, but the logic should be correct. If you think an early return is more reasonable, I'm happy to tweak the code.engine/shell/common/rasterizer.cc
Lines 292 to 297 in 30f048d
And about test, I'm not sure how to test this, would you mind giving me some suggestions ? Thank you :) .
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 thought about it again, the early return will introduce a new problem. If
Rasterizer::DoMakeRasterSnapshotis executed multiple times when the app is in the background. The first time there is no problem, andAndroidSurfaceGL::on_screen_surface_which size is 1x1 is created, but the second time, becauseAndroidSurfaceGL::on_screen_surface_already exists, it is returned early. As a result,Rasterizer::DoMakeRasterSnapshothas changed from hardware rasterization to software rasterization.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 think the part I'm not clear on is how we'd get 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.
Although I can't provide a reproducible sample, it appeared many times in my application, and I finally found the reason for the problem by printing the Log, and the problem was triggered by this line of code.
https://github.com/flutter/flutter/blob/019f03374c5b106c3fde05c8eee930cd26b8ffff/packages/flutter/lib/src/painting/shader_warm_up.dart#L95
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 think this is a combination of a few things:
Shell::NotifyCreatedThere 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.
So what I think should happen here is the following:
AndroidSurfaceGL::CreatePbufferSurfaceto something likeAndroidSurfaceGL::GetOrCreateSnapshotSurface.onscreen_surface_is null/invalid. Otherwise, returnonscreen_surface_.NotifyCreatedis called, run some Dart code that calls and completestoImage, unlatch the raster task runner, make sure the rasterizer surface is the right one.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.
What happens if the buffer isn't a Pbuffer at this time? Does it make sense to destroy the existing surface and then create the actual Pbuffer?
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.
No. We just want to make sure that we have a GPU backed surface and don't end up in the software backend code.
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.
@dnfield
We can't return
onscreen_surface_because the type of the return value isstd::unique_ptr<Surface>, but the type ofonscreen_surface_isstd::unique_ptr<AndroidEGLSurface>. So in either case we have to create a newstd::unique_ptr<Surface>. so I renamed it toAndroidSurfaceGL::CreateSnapshotSurface. I also added test cases as you said in discord.