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

Optimizing performance by avoiding multiple GC operations caused by multiple surface destruction notifications #43587

Merged
merged 1 commit into from
Jul 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -370,19 +370,20 @@ public void surfaceChanged(int width, int height) {
* android.view.TextureView.SurfaceTextureListener}
*/
public void stopRenderingToSurface() {
flutterJNI.onSurfaceDestroyed();

surface = null;
if (surface != null) {
flutterJNI.onSurfaceDestroyed();

// TODO(mattcarroll): the source of truth for this call should be FlutterJNI, which is where
// the call to onFlutterUiDisplayed() comes from. However, no such native callback exists yet,
// so until the engine and FlutterJNI are configured to call us back when rendering stops,
// we will manually monitor that change here.
if (isDisplayingFlutterUi) {
flutterUiDisplayListener.onFlutterUiNoLongerDisplayed();
}

// TODO(mattcarroll): the source of truth for this call should be FlutterJNI, which is where
// the call to onFlutterUiDisplayed() comes from. However, no such native callback exists yet,
// so until the engine and FlutterJNI are configured to call us back when rendering stops,
// we will manually monitor that change here.
if (isDisplayingFlutterUi) {
flutterUiDisplayListener.onFlutterUiNoLongerDisplayed();
isDisplayingFlutterUi = false;
surface = null;
}

isDisplayingFlutterUi = false;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -393,4 +393,20 @@ public void onTrimMemory(int level) {
// Verify behavior under test.
assertEquals(1, invocationCount.get());
}

@Test
public void itDoesDispatchSurfaceDestructionNotificationOnlyOnce() {
// Setup the test.
FlutterRenderer flutterRenderer = new FlutterRenderer(fakeFlutterJNI);

flutterRenderer.startRenderingToSurface(fakeSurface, /*keepCurrentSurface=*/ false);

// Execute the behavior under test.
// Simulate calling |FlutterRenderer#stopRenderingToSurface| twice with different code paths.
flutterRenderer.stopRenderingToSurface();
flutterRenderer.stopRenderingToSurface();

// Verify behavior under test.
verify(fakeFlutterJNI, times(1)).onSurfaceDestroyed();
}
}