Commit 090cf2ce authored by yusufo@chromium.org's avatar yusufo@chromium.org

Get rid of delayed runnable and change visibility instead for ContentViewRenderView

A better fix to not missing any callbacks during Java initialization is setting
the SurfaceView visibility to VISIBLE only after libraries has loaded. This
change removes the delayedRunnable setup and adds an assert to make sure we dont
have a valid surface before native load.

BUG=401581

Review URL: https://codereview.chromium.org/462783002

Cr-Commit-Position: refs/heads/master@{#288901}
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@288901 0039d316-1c4b-4281-b951-d872f2087c98
parent d61c2474
...@@ -16,9 +16,6 @@ import org.chromium.base.CalledByNative; ...@@ -16,9 +16,6 @@ import org.chromium.base.CalledByNative;
import org.chromium.base.JNINamespace; import org.chromium.base.JNINamespace;
import org.chromium.ui.base.WindowAndroid; import org.chromium.ui.base.WindowAndroid;
import java.util.ArrayList;
import java.util.List;
/*** /***
* This view is used by a ContentView to render its content. * This view is used by a ContentView to render its content.
* Call {@link #setCurrentContentViewCore(ContentViewCore)} with the contentViewCore that should be * Call {@link #setCurrentContentViewCore(ContentViewCore)} with the contentViewCore that should be
...@@ -30,46 +27,12 @@ public class ContentViewRenderView extends FrameLayout { ...@@ -30,46 +27,12 @@ public class ContentViewRenderView extends FrameLayout {
// The native side of this object. // The native side of this object.
private long mNativeContentViewRenderView; private long mNativeContentViewRenderView;
private SurfaceHolder.Callback mSurfaceCallback; private SurfaceHolder.Callback mSurfaceCallback;
private List<DelayedSurfaceRunnable> mDelayedSurfaceRunnableList;
private final SurfaceView mSurfaceView; private final SurfaceView mSurfaceView;
protected ContentViewCore mContentViewCore; protected ContentViewCore mContentViewCore;
private ContentReadbackHandler mContentReadbackHandler; private ContentReadbackHandler mContentReadbackHandler;
/**
* Constructing the SurfaceView early sends surface created notifications
* before the native library is loaded. This runnable sends the same signals after
* the library is loaded.
*/
private class DelayedSurfaceRunnable implements Runnable {
private final SurfaceHolder mHolder;
private final int mFormat;
private final int mWidth;
private final int mHeight;
/**
* see https://developer.android.com/reference/android/view/SurfaceHolder.Callback.html#
* surfaceChanged(android.view.SurfaceHolder, int, int, int)
*/
public DelayedSurfaceRunnable(SurfaceHolder holder, int format, int width, int height) {
mHolder = holder;
mFormat = format;
mWidth = width;
mHeight = height;
}
@Override
public void run() {
assert mNativeContentViewRenderView != 0;
nativeSurfaceChanged(mNativeContentViewRenderView, mFormat, mWidth, mHeight,
mHolder.getSurface());
if (mContentViewCore != null) {
mContentViewCore.onPhysicalBackingSizeChanged(mWidth, mHeight);
}
}
}
/** /**
* Constructs a new ContentViewRenderView. * Constructs a new ContentViewRenderView.
* This should be called and the {@link ContentViewRenderView} should be added to the view * This should be called and the {@link ContentViewRenderView} should be added to the view
...@@ -84,34 +47,11 @@ public class ContentViewRenderView extends FrameLayout { ...@@ -84,34 +47,11 @@ public class ContentViewRenderView extends FrameLayout {
mSurfaceView.setZOrderMediaOverlay(true); mSurfaceView.setZOrderMediaOverlay(true);
setSurfaceViewBackgroundColor(Color.WHITE); setSurfaceViewBackgroundColor(Color.WHITE);
// Add a placeholder callback which will keep track of the last surfaceChanged call if we
// get any until the native libraries have been loaded.
mSurfaceCallback = new SurfaceHolder.Callback() {
@Override
public void surfaceDestroyed(SurfaceHolder holder) {
mDelayedSurfaceRunnableList = null;
}
@Override
public void surfaceCreated(SurfaceHolder holder) {
mDelayedSurfaceRunnableList =
new ArrayList<ContentViewRenderView.DelayedSurfaceRunnable>();
}
@Override
public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) {
mDelayedSurfaceRunnableList.add(
new DelayedSurfaceRunnable(holder, format, width, height));
return;
}
};
mSurfaceView.getHolder().addCallback(mSurfaceCallback);
addView(mSurfaceView, addView(mSurfaceView,
new FrameLayout.LayoutParams( new FrameLayout.LayoutParams(
FrameLayout.LayoutParams.MATCH_PARENT, FrameLayout.LayoutParams.MATCH_PARENT,
FrameLayout.LayoutParams.MATCH_PARENT)); FrameLayout.LayoutParams.MATCH_PARENT));
mSurfaceView.setVisibility(GONE);
} }
/** /**
...@@ -120,10 +60,11 @@ public class ContentViewRenderView extends FrameLayout { ...@@ -120,10 +60,11 @@ public class ContentViewRenderView extends FrameLayout {
* @param rootWindow The {@link WindowAndroid} this render view should be linked to. * @param rootWindow The {@link WindowAndroid} this render view should be linked to.
*/ */
public void onNativeLibraryLoaded(WindowAndroid rootWindow) { public void onNativeLibraryLoaded(WindowAndroid rootWindow) {
assert !mSurfaceView.getHolder().getSurface().isValid() :
"Surface created before native library loaded.";
assert rootWindow != null; assert rootWindow != null;
mNativeContentViewRenderView = nativeInit(rootWindow.getNativePointer()); mNativeContentViewRenderView = nativeInit(rootWindow.getNativePointer());
assert mNativeContentViewRenderView != 0; assert mNativeContentViewRenderView != 0;
mSurfaceView.getHolder().removeCallback(mSurfaceCallback);
mSurfaceCallback = new SurfaceHolder.Callback() { mSurfaceCallback = new SurfaceHolder.Callback() {
@Override @Override
public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) { public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) {
...@@ -151,6 +92,7 @@ public class ContentViewRenderView extends FrameLayout { ...@@ -151,6 +92,7 @@ public class ContentViewRenderView extends FrameLayout {
} }
}; };
mSurfaceView.getHolder().addCallback(mSurfaceCallback); mSurfaceView.getHolder().addCallback(mSurfaceCallback);
mSurfaceView.setVisibility(VISIBLE);
mContentReadbackHandler = new ContentReadbackHandler() { mContentReadbackHandler = new ContentReadbackHandler() {
@Override @Override
...@@ -159,13 +101,6 @@ public class ContentViewRenderView extends FrameLayout { ...@@ -159,13 +101,6 @@ public class ContentViewRenderView extends FrameLayout {
} }
}; };
mContentReadbackHandler.initNativeContentReadbackHandler(); mContentReadbackHandler.initNativeContentReadbackHandler();
if (mDelayedSurfaceRunnableList != null) {
nativeSurfaceCreated(mNativeContentViewRenderView);
for (int i = 0; i < mDelayedSurfaceRunnableList.size(); i++) {
mDelayedSurfaceRunnableList.get(i).run();
}
mDelayedSurfaceRunnableList = null;
}
} }
/** /**
......
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