-
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
Fix compatibility issues with SurfaceTexture on Android Q. #31698
Conversation
025e773
to
451e49c
Compare
public SurfaceTextureWrapper( | ||
@NonNull SurfaceTexture surfaceTexture, @Nullable Runnable onFrameConsumed) { |
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.
java doc for this constructor as well as the previous one to document when to use which
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.
done.
surfaceCanvas.drawColor(Color.TRANSPARENT, BlendMode.CLEAR); | ||
} else { | ||
surfaceCanvas.drawColor(Color.TRANSPARENT); | ||
// We've observed on Android Q that we have to wait for the consumer of {@link SurfaceTexture} |
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.
did you test with versions below Q?
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.
cc @jreck
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.
did you test with versions below Q?
Yes, I did. They work fine.
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.
Just to clarify, which versions did you test on? I'm getting reports that it may be several versions. See googleads/googleads-mobile-flutter#269 (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.
Just to clarify, which versions did you test on? I'm getting reports that it may be several versions. See googleads/googleads-mobile-flutter#269 (comment)
I have tested on real devices from Android9 to Android12.
/** Listener invoked when a new image frame becomes available and has been consumed. */ | ||
interface ImageFrameListener { | ||
/** This method will to be invoked when a new image frame becomes available. */ | ||
void onFrameAvailable(); |
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 this method used?
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.
done.
@@ -195,6 +209,11 @@ protected void finalize() throws Throwable { | |||
super.finalize(); | |||
} | |||
} | |||
|
|||
@Override | |||
public void setImageFrameListener(@Nullable ImageFrameListener listener) { |
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 don't think this is used or related to bug. If this is indeed the case, please remove.
@@ -109,6 +141,10 @@ public void setTexture(@Nullable SurfaceTexture newTx) { | |||
} else { | |||
canvas.drawColor(Color.TRANSPARENT); | |||
} | |||
|
|||
if (Build.VERSION.SDK_INT == Build.VERSION_CODES.Q) { |
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: we decided that it's more readable to use a number than the constant. e.g.
consider: Build.VERSION_CODES.Q
vs 29
. Fewer characters, and also more clear to someone reading this 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.
done.
Thank you for looking at this @0xZOne! This is a very useful finding |
It is my pleasure to contribute code to Flutter. : ) |
64d75b2
to
d19e052
Compare
d19e052
to
4d3a607
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 - This is pretty awesome! Thank you
We've observed on Android Q that we have to wait for the consumer of
SurfaceTexture
to consume the last image before continuing to draw, otherwise, subsequent calls todequeueBuffer
to request a free buffer from theBufferQueue
will fail./cc @blasten @dnfield
Fixes: flutter/flutter#98722
Pre-launch Checklist
writing and running engine tests.
///
).If you need help, consider asking for advice on the #hackers-new channel on Discord.