Optimizing performance by avoiding multiple GC operations caused by multiple surface destruction notifications (flutter/engine#43587)
Fixes: https://github.com/flutter/flutter/issues/130379 [C++, Objective-C, Java style guides]: https://github.com/flutter/engine/blob/main/CONTRIBUTING.md#style
This commit is contained in:
@@ -370,19 +370,20 @@ public class FlutterRenderer implements TextureRegistry {
|
||||
* android.view.TextureView.SurfaceTextureListener}
|
||||
*/
|
||||
public void stopRenderingToSurface() {
|
||||
flutterJNI.onSurfaceDestroyed();
|
||||
if (surface != null) {
|
||||
flutterJNI.onSurfaceDestroyed();
|
||||
|
||||
surface = null;
|
||||
// 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;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -393,4 +393,20 @@ public class FlutterRendererTest {
|
||||
// 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();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user