From b53670aecf2699022dffbf9400267ccf147eba64 Mon Sep 17 00:00:00 2001 From: Robert Carr Date: Thu, 25 May 2017 18:20:49 -0700 Subject: [PATCH] SurfaceView: Avoid over-reporting DRAW_FINISHED. To some extent we rely on the app to call the draw callback if they want the app to work properly, but this case is fairly easy to detect, so why not prevent it and provide a helpful log. Bug: 62051758 Test: Warm start camera a few times. go/wm-smoke. Change-Id: I39f4e015bfa15a1e0c37dba70b4a700803a6a274 --- core/java/android/view/SurfaceView.java | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/core/java/android/view/SurfaceView.java b/core/java/android/view/SurfaceView.java index 435675ba01e57..b57ac66e10cc1 100644 --- a/core/java/android/view/SurfaceView.java +++ b/core/java/android/view/SurfaceView.java @@ -264,6 +264,22 @@ public class SurfaceView extends View implements ViewRootImpl.WindowStoppedCallb updateSurface(); } + private void performDrawFinished() { + if (mPendingReportDraws > 0) { + mDrawFinished = true; + if (mAttachedToWindow) { + mParent.requestTransparentRegion(SurfaceView.this); + + notifyDrawFinished(); + invalidate(); + } + } else { + Log.e(TAG, System.identityHashCode(this) + "finished drawing" + + " but no pending report draw (extra call" + + " to draw completion runnable?)"); + } + } + void notifyDrawFinished() { ViewRootImpl viewRoot = getViewRootImpl(); if (viewRoot != null) { @@ -729,12 +745,7 @@ public class SurfaceView extends View implements ViewRootImpl.WindowStoppedCallb } runOnUiThread(() -> { - mDrawFinished = true; - if (mAttachedToWindow) { - mParent.requestTransparentRegion(SurfaceView.this); - notifyDrawFinished(); - invalidate(); - } + performDrawFinished(); }); }