Commit 5e7b4d97 authored by aelias's avatar aelias Committed by Commit bot

Re-hook up surfaceRedrawNeededAsync callback.

This method was accidentally left unimplemented after
CompositorSurfaceManager was made the canonical SurfaceHolder.Callback2
implementation, leaving the CompositorView one dangling with no
callsites.  Because https://codereview.chromium.org/2201483002 also
changed it so that SurfaceViews are created later, at native library
load time, and always visible, bringing this back does not bring back
the black flicker associated with implementing this method on an
invisible View.  So we can safely reimplement it.

I changed CompositorView to inherit from a new interface because
surfaceRedrawNeededAsync is still not exposed in the SDK.

(In the future, we can also look into attaching the opaque SurfaceView
as early as possible -- instead of when the native library is loaded --
in order to avoid a flicker of View system content, given that this
callback should block the system from drawing until it's ready.)

BUG=512636

Review-Url: https://codereview.chromium.org/2893833005
Cr-Commit-Position: refs/heads/master@{#473414}
parent b3b711c9
...@@ -13,6 +13,8 @@ import android.view.View; ...@@ -13,6 +13,8 @@ import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
import android.widget.FrameLayout; import android.widget.FrameLayout;
import org.chromium.base.annotations.UsedByReflection;
/** /**
* Manage multiple SurfaceViews for the compositor, so that transitions between * Manage multiple SurfaceViews for the compositor, so that transitions between
* surfaces with and without an alpha channel can be visually smooth. * surfaces with and without an alpha channel can be visually smooth.
...@@ -33,7 +35,14 @@ import android.widget.FrameLayout; ...@@ -33,7 +35,14 @@ import android.widget.FrameLayout;
* *
* The full design doc is at https://goo.gl/aAmQzR . * The full design doc is at https://goo.gl/aAmQzR .
*/ */
class CompositorSurfaceManager implements SurfaceHolder.Callback { class CompositorSurfaceManager implements SurfaceHolder.Callback2 {
public interface SurfaceHolderCallbackTarget {
public void surfaceRedrawNeededAsync(SurfaceHolder holder, Runnable drawingFinished);
public void surfaceChanged(SurfaceHolder holder, int format, int width, int height);
public void surfaceCreated(SurfaceHolder holder);
public void surfaceDestroyed(SurfaceHolder holder);
}
private static class SurfaceState { private static class SurfaceState {
public SurfaceView surfaceView; public SurfaceView surfaceView;
...@@ -53,7 +62,7 @@ class CompositorSurfaceManager implements SurfaceHolder.Callback { ...@@ -53,7 +62,7 @@ class CompositorSurfaceManager implements SurfaceHolder.Callback {
// Parent ViewGroup, or null. // Parent ViewGroup, or null.
private ViewGroup mParent; private ViewGroup mParent;
public SurfaceState(Context context, int format, SurfaceHolder.Callback callback) { public SurfaceState(Context context, int format, SurfaceHolder.Callback2 callback) {
surfaceView = new SurfaceView(context); surfaceView = new SurfaceView(context);
surfaceView.setZOrderMediaOverlay(true); surfaceView.setZOrderMediaOverlay(true);
surfaceView.setVisibility(View.VISIBLE); surfaceView.setVisibility(View.VISIBLE);
...@@ -109,12 +118,12 @@ class CompositorSurfaceManager implements SurfaceHolder.Callback { ...@@ -109,12 +118,12 @@ class CompositorSurfaceManager implements SurfaceHolder.Callback {
private SurfaceState mRequestedByClient; private SurfaceState mRequestedByClient;
// Client that we notify about surface change events. // Client that we notify about surface change events.
private SurfaceHolder.Callback mClient; private SurfaceHolderCallbackTarget mClient;
// View to which we'll attach the SurfaceView. // View to which we'll attach the SurfaceView.
private final ViewGroup mParentView; private final ViewGroup mParentView;
public CompositorSurfaceManager(ViewGroup parentView, SurfaceHolder.Callback client) { public CompositorSurfaceManager(ViewGroup parentView, SurfaceHolderCallbackTarget client) {
mParentView = parentView; mParentView = parentView;
mClient = client; mClient = client;
...@@ -253,6 +262,17 @@ class CompositorSurfaceManager implements SurfaceHolder.Callback { ...@@ -253,6 +262,17 @@ class CompositorSurfaceManager implements SurfaceHolder.Callback {
} }
} }
@Override
public void surfaceRedrawNeeded(SurfaceHolder holder) {
// Intentionally not implemented.
}
// TODO(boliu): Mark this override instead.
@UsedByReflection("Android")
public void surfaceRedrawNeededAsync(SurfaceHolder holder, Runnable drawingFinished) {
mClient.surfaceRedrawNeededAsync(holder, drawingFinished);
}
@Override @Override
public void surfaceCreated(SurfaceHolder holder) { public void surfaceCreated(SurfaceHolder holder) {
SurfaceState state = getStateForHolder(holder); SurfaceState state = getStateForHolder(holder);
......
...@@ -23,7 +23,6 @@ import android.widget.FrameLayout; ...@@ -23,7 +23,6 @@ import android.widget.FrameLayout;
import org.chromium.base.TraceEvent; import org.chromium.base.TraceEvent;
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.base.annotations.UsedByReflection;
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;
import org.chromium.chrome.browser.compositor.layouts.LayoutRenderHost; import org.chromium.chrome.browser.compositor.layouts.LayoutRenderHost;
...@@ -46,7 +45,8 @@ import java.util.List; ...@@ -46,7 +45,8 @@ import java.util.List;
* The is the {@link View} displaying the ui compositor results; including webpages and tabswitcher. * The is the {@link View} displaying the ui compositor results; including webpages and tabswitcher.
*/ */
@JNINamespace("android") @JNINamespace("android")
public class CompositorView extends FrameLayout implements SurfaceHolder.Callback2 { public class CompositorView
extends FrameLayout implements CompositorSurfaceManager.SurfaceHolderCallbackTarget {
private static final String TAG = "CompositorView"; private static final String TAG = "CompositorView";
private static final long NANOSECONDS_PER_MILLISECOND = 1000000; private static final long NANOSECONDS_PER_MILLISECOND = 1000000;
...@@ -251,12 +251,6 @@ public class CompositorView extends FrameLayout implements SurfaceHolder.Callbac ...@@ -251,12 +251,6 @@ public class CompositorView extends FrameLayout implements SurfaceHolder.Callbac
} }
@Override @Override
public void surfaceRedrawNeeded(SurfaceHolder holder) {
// Intentionally not implemented.
}
// TODO(boliu): Mark this override instead.
@UsedByReflection("Android")
public void surfaceRedrawNeededAsync(SurfaceHolder holder, Runnable drawingFinished) { public void surfaceRedrawNeededAsync(SurfaceHolder holder, Runnable drawingFinished) {
if (mDrawingFinishedCallbacks == null) mDrawingFinishedCallbacks = new ArrayList<>(); if (mDrawingFinishedCallbacks == null) mDrawingFinishedCallbacks = new ArrayList<>();
mDrawingFinishedCallbacks.add(drawingFinished); mDrawingFinishedCallbacks.add(drawingFinished);
......
...@@ -47,7 +47,7 @@ import java.util.Set; ...@@ -47,7 +47,7 @@ import java.util.Set;
@Config(manifest = Config.NONE) @Config(manifest = Config.NONE)
public class CompositorSurfaceManagerTest { public class CompositorSurfaceManagerTest {
@Mock @Mock
private SurfaceHolder.Callback mCallback; private CompositorSurfaceManager.SurfaceHolderCallbackTarget mCallback;
private CompositorSurfaceManager mManager; private CompositorSurfaceManager mManager;
......
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