Commit 98da165e authored by yusufo's avatar yusufo Committed by Commit bot

Delay setting the compositor view background to null on N

We set compositor view background to white while there are no
frames and onSwapBufferCompleted swap it back to null. On N
this creates a black flash on some cold starts where there is
still a frame that is drawn before the frame is actually completed.

BUG=640758

Review-Url: https://codereview.chromium.org/2271393003
Cr-Commit-Position: refs/heads/master@{#414292}
parent 0cfb5283
...@@ -9,11 +9,14 @@ import android.content.Context; ...@@ -9,11 +9,14 @@ import android.content.Context;
import android.graphics.Color; import android.graphics.Color;
import android.graphics.PixelFormat; import android.graphics.PixelFormat;
import android.graphics.Rect; import android.graphics.Rect;
import android.os.Build;
import android.view.Display;
import android.view.MotionEvent; import android.view.MotionEvent;
import android.view.Surface; import android.view.Surface;
import android.view.SurfaceHolder; import android.view.SurfaceHolder;
import android.view.SurfaceView; import android.view.SurfaceView;
import android.view.View; import android.view.View;
import android.view.WindowManager;
import org.chromium.base.CommandLine; import org.chromium.base.CommandLine;
import org.chromium.base.Log; import org.chromium.base.Log;
...@@ -21,7 +24,6 @@ import org.chromium.base.TraceEvent; ...@@ -21,7 +24,6 @@ import org.chromium.base.TraceEvent;
import org.chromium.base.VisibleForTesting; import org.chromium.base.VisibleForTesting;
import org.chromium.base.annotations.CalledByNative; import org.chromium.base.annotations.CalledByNative;
import org.chromium.base.annotations.JNINamespace; import org.chromium.base.annotations.JNINamespace;
import org.chromium.chrome.R;
import org.chromium.chrome.browser.ChromeSwitches; import org.chromium.chrome.browser.ChromeSwitches;
import org.chromium.chrome.browser.compositor.layouts.Layout; import org.chromium.chrome.browser.compositor.layouts.Layout;
import org.chromium.chrome.browser.compositor.layouts.LayoutProvider; import org.chromium.chrome.browser.compositor.layouts.LayoutProvider;
...@@ -47,6 +49,7 @@ import org.chromium.ui.resources.ResourceManager; ...@@ -47,6 +49,7 @@ import org.chromium.ui.resources.ResourceManager;
public class CompositorView public class CompositorView
extends SurfaceView implements ContentOffsetProvider, SurfaceHolder.Callback { extends SurfaceView implements ContentOffsetProvider, SurfaceHolder.Callback {
private static final String TAG = "CompositorView"; private static final String TAG = "CompositorView";
private static final long NANOSECONDS_PER_MILLISECOND = 1000000;
// Cache objects that should not be created every frame // Cache objects that should not be created every frame
private final Rect mCacheViewport = new Rect(); private final Rect mCacheViewport = new Rect();
...@@ -61,6 +64,9 @@ public class CompositorView ...@@ -61,6 +64,9 @@ public class CompositorView
private int mLastLayerCount; private int mLastLayerCount;
// A conservative estimate of when a frame is guaranteed to be presented after being submitted.
private long mFramePresentationDelay;
// Resource Management // Resource Management
private ResourceManager mResourceManager; private ResourceManager mResourceManager;
...@@ -187,6 +193,18 @@ public class CompositorView ...@@ -187,6 +193,18 @@ public class CompositorView
setBackgroundColor(Color.WHITE); setBackgroundColor(Color.WHITE);
setVisibility(View.VISIBLE); setVisibility(View.VISIBLE);
mFramePresentationDelay = 0;
if (Build.VERSION.SDK_INT > Build.VERSION_CODES.M) {
Display display =
((WindowManager) getContext().getSystemService(Context.WINDOW_SERVICE))
.getDefaultDisplay();
long presentationDeadline = display.getPresentationDeadlineNanos()
/ NANOSECONDS_PER_MILLISECOND;
long vsyncPeriod = mWindowAndroid.getVsyncPeriodInMillis();
mFramePresentationDelay = Math.min(3 * vsyncPeriod,
((presentationDeadline + vsyncPeriod - 1) / vsyncPeriod) * vsyncPeriod);
}
// Grab the Resource Manager // Grab the Resource Manager
mResourceManager = nativeGetResourceManager(mNativeCompositorView); mResourceManager = nativeGetResourceManager(mNativeCompositorView);
} }
...@@ -289,12 +307,12 @@ public class CompositorView ...@@ -289,12 +307,12 @@ public class CompositorView
private void onSwapBuffersCompleted(int pendingSwapBuffersCount) { private void onSwapBuffersCompleted(int pendingSwapBuffersCount) {
// Clear the color used to cover the uninitialized surface. // Clear the color used to cover the uninitialized surface.
if (getBackground() != null) { if (getBackground() != null) {
post(new Runnable() { postDelayed(new Runnable() {
@Override @Override
public void run() { public void run() {
setBackgroundResource(0); setBackgroundResource(0);
} }
}); }, mFramePresentationDelay);
} }
mRenderHost.onSwapBuffersCompleted(pendingSwapBuffersCount); mRenderHost.onSwapBuffersCompleted(pendingSwapBuffersCount);
......
...@@ -154,6 +154,13 @@ public class WindowAndroid { ...@@ -154,6 +154,13 @@ public class WindowAndroid {
return mVSyncMonitor.isInsideVSync(); return mVSyncMonitor.isInsideVSync();
} }
/**
* @return The time interval between two consecutive vsync pulses in milliseconds.
*/
public long getVsyncPeriodInMillis() {
return mVSyncMonitor.getVSyncPeriodInMicroseconds() * 1000;
}
/** /**
* @param context The application context. * @param context The application context.
*/ */
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment