-
Notifications
You must be signed in to change notification settings - Fork 28.8k
[Android] Add a way to request new Surface
s from SurfaceProducer
and avoid SurfaceProducer
returning invalid Surface
#169899
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
Conversation
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
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as outdated.
This comment was marked as outdated.
Surface
from SurfaceProducer
and avoid SurfaceProducer
returning invalid Surface
Surface
s from SurfaceProducer
and avoid SurfaceProducer
returning invalid Surface
} | ||
|
||
@Override | ||
public Surface getSurface(boolean forceNewSurface) { |
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 do you think of this API, versus possible alternatives?
void invalidateSurface()
(surface = null
), which is called beforegetSurface
to force a new surface.Surface getForceNewSurface()
, identical this one, but without using a boolean parameter.
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.
To clarify, you suggesting we provide two different ways to force getting a new surface, i.e. a user could call invalidateSurface
then getSurface
or just call getForceNewSurface
?
void invalidateSurface()
(surface = null
), which is called before getSurface to force a new surface.
Also, as an aside, I think we should avoid the invalidateSurface
name because we aren't actually invalidating the Surface
. Maybe requestNewSurface
or something?
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.
Yeah I just know if getSurface(true)
really ... screams anything, like I wouldn't notice it in a code review.
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.
Hahaha no that's such a good point. I'm thinking we do Surface getForceNewSurface()
then so it's clearer.
Edit: Chose getForcedNewSurface
so "forced new" is kinda like a descriptor for the surface.
Gonna go ahead and land this! I'll monitor the dashboard too in case I need to revert in case folks aren't around. |
…Producer` and avoid `SurfaceProducer` returning invalid `Surface` (flutter/flutter#169899)
flutter/flutter@85a9b4f...c7362b4 2025-06-20 43054281+camsim99@users.noreply.github.com [Android] Add a way to request new `Surface`s from `SurfaceProducer` and avoid `SurfaceProducer` returning invalid `Surface` (flutter/flutter#169899) 2025-06-20 engine-flutter-autoroll@skia.org Roll Dart SDK from cc2f604acb05 to a554bdd0a2cc (1 revision) (flutter/flutter#170912) 2025-06-20 robert.ancell@canonical.com Set the background in the Linux template (flutter/flutter#170841) 2025-06-20 engine-flutter-autoroll@skia.org Roll Skia from 2fc58cffe69b to f1e68950ea7b (2 revisions) (flutter/flutter#170914) 2025-06-20 engine-flutter-autoroll@skia.org Roll Skia from 8a710de2a1d3 to 2fc58cffe69b (2 revisions) (flutter/flutter#170906) 2025-06-20 137456488+flutter-pub-roller-bot@users.noreply.github.com Roll pub packages (flutter/flutter#170907) 2025-06-20 engine-flutter-autoroll@skia.org Roll Skia from 2ac2476b0bcb to 8a710de2a1d3 (2 revisions) (flutter/flutter#170900) 2025-06-20 fluttergithubbot@gmail.com Marks Linux_pixel_7pro dynamic_path_stroke_tessellation_perf__timeline_summary to be flaky (flutter/flutter#170785) 2025-06-20 engine-flutter-autoroll@skia.org Roll Dart SDK from 6a4b11760906 to cc2f604acb05 (1 revision) (flutter/flutter#170895) 2025-06-19 engine-flutter-autoroll@skia.org Roll Skia from 61c89daa3888 to 2ac2476b0bcb (4 revisions) (flutter/flutter#170890) 2025-06-19 engine-flutter-autoroll@skia.org Roll Dart SDK from bce9abe03175 to 6a4b11760906 (1 revision) (flutter/flutter#170884) 2025-06-19 bkonyi@google.com [ Tool ] Roll DDS 5.0.3 (flutter/flutter#170880) 2025-06-19 engine-flutter-autoroll@skia.org Roll Packages from 715a0a5 to 0ec4053 (8 revisions) (flutter/flutter#170879) 2025-06-19 engine-flutter-autoroll@skia.org Roll Skia from 794936b23812 to 61c89daa3888 (7 revisions) (flutter/flutter#170878) If this roll has caused a breakage, revert this CL and stop the roller using the controls here: https://autoroll.skia.org/r/flutter-packages Please CC stuartmorgan@google.com on the revert to ensure that a human is aware of the problem. To file a bug in Packages: 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
flutter/flutter@85a9b4f...c7362b4 2025-06-20 43054281+camsim99@users.noreply.github.com [Android] Add a way to request new `Surface`s from `SurfaceProducer` and avoid `SurfaceProducer` returning invalid `Surface` (flutter/flutter#169899) 2025-06-20 engine-flutter-autoroll@skia.org Roll Dart SDK from cc2f604acb05 to a554bdd0a2cc (1 revision) (flutter/flutter#170912) 2025-06-20 robert.ancell@canonical.com Set the background in the Linux template (flutter/flutter#170841) 2025-06-20 engine-flutter-autoroll@skia.org Roll Skia from 2fc58cffe69b to f1e68950ea7b (2 revisions) (flutter/flutter#170914) 2025-06-20 engine-flutter-autoroll@skia.org Roll Skia from 8a710de2a1d3 to 2fc58cffe69b (2 revisions) (flutter/flutter#170906) 2025-06-20 137456488+flutter-pub-roller-bot@users.noreply.github.com Roll pub packages (flutter/flutter#170907) 2025-06-20 engine-flutter-autoroll@skia.org Roll Skia from 2ac2476b0bcb to 8a710de2a1d3 (2 revisions) (flutter/flutter#170900) 2025-06-20 fluttergithubbot@gmail.com Marks Linux_pixel_7pro dynamic_path_stroke_tessellation_perf__timeline_summary to be flaky (flutter/flutter#170785) 2025-06-20 engine-flutter-autoroll@skia.org Roll Dart SDK from 6a4b11760906 to cc2f604acb05 (1 revision) (flutter/flutter#170895) 2025-06-19 engine-flutter-autoroll@skia.org Roll Skia from 61c89daa3888 to 2ac2476b0bcb (4 revisions) (flutter/flutter#170890) 2025-06-19 engine-flutter-autoroll@skia.org Roll Dart SDK from bce9abe03175 to 6a4b11760906 (1 revision) (flutter/flutter#170884) 2025-06-19 bkonyi@google.com [ Tool ] Roll DDS 5.0.3 (flutter/flutter#170880) 2025-06-19 engine-flutter-autoroll@skia.org Roll Packages from 715a0a5c4fdd to e3b2898 (8 revisions) (flutter/flutter#170879) 2025-06-19 engine-flutter-autoroll@skia.org Roll Skia from 794936b23812 to 61c89daa3888 (7 revisions) (flutter/flutter#170878) If this roll has caused a breakage, revert this CL and stop the roller using the controls here: https://autoroll.skia.org/r/flutter-packages Please CC stuartmorgan@google.com on the revert to ensure that a human is aware of the problem. To file a bug in Packages: 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
Note
For anyone reviewing this PR, see flutter/packages#9360 for how I'd use the
getSurface(boolean forceNewSurface)
method.Note
For anyone coming across this PR post-landing, in the code review process, I renamed
getSurface(boolean forceNewSurface)
togetForcedNewSurface()
.What this does
(1) Adds method
getSurface(boolean forceNewSurface)
toSurfaceProducer
that will force the creation of a newSurface
whenSurfaceProducer.getSurface()
is called.(2) Fixes
SurfaceProducer
to avoid returning invalidSurface
s whenSurfaceProducer.getSurface()
/getSurface(boolean forceNewSurface)
is called.Why we should...
(1) Add
getSurface(boolean forceNewSurface)
My motivation for adding this is directly tied to #155294. The
camera_android_camerax
plugin supports a camera preview use case that requires providing aSurface
to in order to render the preview. It does so viaSurfaceProducer
; we provide aSurface
retrieved fromSurfaceProducer.getSurface()
to the CameraX library to render a camera preview, and when the camera preview is done, a callback that we provide is called, reporting thatSurface
as used and that it now should be released/invalidated (seeSurfaceRequest
,SurfaceRequest.Result
). However, the CameraX library makes no guarantees about when requests for newSurface
s are made, so the following race condition can happen:Surface
Surface
A fromSurfaceProducer.getSurface()
Surface
Surface
A fromSurfaceProducer.getSurface()
because it is still technically validSurface
A is released/invalidI believe
SurfaceProducer
currently has no way to handle the level of complexity ofSurface
handling required for use cases like thecamera_android_camerax
camera preview, where aSurface
may be invalidated between calls toSurfaceProducer.getSurface()
. So,getSurface(boolean forceNewSurface)
can support these use cases.*getSurface(boolean forceNewSurface)
simply will forceSurfaceProducer
to return a newSurface
whenSurfaceProducer.getSurface
is called versus potentially returning the sameSurface
as the previous invocation.For
camera_android_camerax
, see flutter/packages#9360 for an example of how it would be used.*I'd like to note that I also played around with creating new
SurfaceProducer
s to solve the camera problem, which was successful and probably could be generally for that use case, but I think it's cleaner to support this functionality from within the sameSurfaceProducer
since we can 🤷♀️ It also helps avoid the user from needing to create/manage multiple FlutterTexture
s, from my understanding.(2) Fix
SurfaceProducer.getSurface()
/getSurface(boolean forceNewSurface)
to never return an invalidSurface
sI noticed that
SurfaceProducer.getSurface()
/getSurface(boolean forceNewSurface)
does not check forSurface
validity before returning them while I was working on (1). Honestly, this just feels right? We should ensure that aSurface
is valid and can be used before returning it and potentially confusing the user.Pre-launch Checklist
///
).If you need help, consider asking for advice on the #hackers-new channel on Discord.