Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit 57099ca

Browse files
Optimizations for TLHC frame rate and jank (#50033)
- ImageReaderSurfaceProducer no longer drops frames when the producer and the consumers are up to two frames out of sync. - Have the native C++ side of the Android external textures check if a new frame has been pushed and that the texture needs to be updated. This avoids having to schedule a task on the raster thread for each updated texture. - Notify the engine earlier that a frame is needed when updating a TLHC texture.
1 parent 2bdba6b commit 57099ca

19 files changed

+427
-195
lines changed

shell/platform/android/android_shell_holder_unittests.cc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,10 @@ class MockPlatformViewAndroidJNI : public PlatformViewAndroidJNI {
3535
SurfaceTextureAttachToGLContext,
3636
(JavaLocalRef surface_texture, int textureId),
3737
(override));
38+
MOCK_METHOD(bool,
39+
SurfaceTextureShouldUpdate,
40+
(JavaLocalRef surface_texture),
41+
(override));
3842
MOCK_METHOD(void,
3943
SurfaceTextureUpdateTexImage,
4044
(JavaLocalRef surface_texture),

shell/platform/android/image_external_texture.cc

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,9 @@ void ImageExternalTexture::Paint(PaintContext& context,
2626
return;
2727
}
2828
Attach(context);
29-
const bool should_process_frame =
30-
(!freeze && new_frame_ready_) || dl_image_ == nullptr;
29+
const bool should_process_frame = !freeze;
3130
if (should_process_frame) {
3231
ProcessFrame(context, bounds);
33-
new_frame_ready_ = false;
3432
}
3533
if (dl_image_) {
3634
context.canvas->DrawImageRect(
@@ -48,7 +46,7 @@ void ImageExternalTexture::Paint(PaintContext& context,
4846

4947
// Implementing flutter::Texture.
5048
void ImageExternalTexture::MarkNewFrameAvailable() {
51-
new_frame_ready_ = true;
49+
// NOOP.
5250
}
5351

5452
// Implementing flutter::Texture.

shell/platform/android/image_external_texture.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,6 @@ class ImageExternalTexture : public flutter::Texture {
6161

6262
enum class AttachmentState { kUninitialized, kAttached, kDetached };
6363
AttachmentState state_ = AttachmentState::kUninitialized;
64-
bool new_frame_ready_ = false;
6564

6665
sk_sp<flutter::DlImage> dl_image_;
6766

shell/platform/android/io/flutter/embedding/engine/FlutterJNI.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -951,6 +951,16 @@ public void markTextureFrameAvailable(long textureId) {
951951

952952
private native void nativeMarkTextureFrameAvailable(long nativeShellHolderId, long textureId);
953953

954+
/** Schedule the engine to draw a frame but does not invalidate the layout tree. */
955+
@UiThread
956+
public void scheduleFrame() {
957+
ensureRunningOnMainThread();
958+
ensureAttachedToNative();
959+
nativeScheduleFrame(nativeShellHolderId);
960+
}
961+
962+
private native void nativeScheduleFrame(long nativeShellHolderId);
963+
954964
/**
955965
* Unregisters a texture that was registered with {@link #registerTexture(long,
956966
* SurfaceTextureWrapper)}.

0 commit comments

Comments
 (0)