| Index: content/public/android/java/src/org/chromium/content/browser/ContentViewRenderView.java
|
| diff --git a/content/public/android/java/src/org/chromium/content/browser/ContentViewRenderView.java b/content/public/android/java/src/org/chromium/content/browser/ContentViewRenderView.java
|
| index c3f6c26e144aca71bab32dc5a43425d30e78bd0a..6c5971b1b88e5ae0d449ec679369218d76a6a7a7 100644
|
| --- a/content/public/android/java/src/org/chromium/content/browser/ContentViewRenderView.java
|
| +++ b/content/public/android/java/src/org/chromium/content/browser/ContentViewRenderView.java
|
| @@ -25,17 +25,10 @@ public class ContentViewRenderView extends FrameLayout {
|
| private int mNativeContentViewRenderView = 0;
|
|
|
| private SurfaceView mSurfaceView;
|
| + private VSyncAdapter mVSyncAdapter;
|
|
|
| private ContentView mCurrentContentView;
|
|
|
| - private final VSyncMonitor mVSyncMonitor;
|
| -
|
| - // The VSyncMonitor gives the timebase for the actual vsync, but we don't want render until
|
| - // we have had a chance for input events to propagate to the compositor thread. This takes
|
| - // 3 ms typically, so we adjust the vsync timestamps forward by a bit to give input events a
|
| - // chance to arrive.
|
| - private static final long INPUT_EVENT_LAG_FROM_VSYNC_MICROSECONDS = 3200;
|
| -
|
| /**
|
| * Constructs a new ContentViewRenderView that should be can to a view hierarchy.
|
| * Native code should add/remove the layers to be rendered through the ContentViewLayerRenderer.
|
| @@ -70,24 +63,55 @@ public class ContentViewRenderView extends FrameLayout {
|
| }
|
| });
|
|
|
| - mVSyncMonitor = new VSyncMonitor(getContext(), new VSyncMonitor.Listener() {
|
| - @Override
|
| - public void onVSync(VSyncMonitor monitor, long vsyncTimeMicros) {
|
| - if (mCurrentContentView == null) return;
|
| + mVSyncAdapter = new VSyncAdapter(getContext());
|
| + addView(mSurfaceView,
|
| + new FrameLayout.LayoutParams(
|
| + FrameLayout.LayoutParams.MATCH_PARENT,
|
| + FrameLayout.LayoutParams.MATCH_PARENT));
|
| + }
|
| +
|
| + private static class VSyncAdapter implements VSyncManager.Provider, VSyncMonitor.Listener {
|
| + private final VSyncMonitor mVSyncMonitor;
|
| + private boolean mVSyncNotificationEnabled;
|
| + private VSyncManager.Listener mVSyncListener;
|
| +
|
| + // The VSyncMonitor gives the timebase for the actual vsync, but we don't want render until
|
| + // we have had a chance for input events to propagate to the compositor thread. This takes
|
| + // 3 ms typically, so we adjust the vsync timestamps forward by a bit to give input events a
|
| + // chance to arrive.
|
| + private static final long INPUT_EVENT_LAG_FROM_VSYNC_MICROSECONDS = 3200;
|
| +
|
| + VSyncAdapter(Context context) {
|
| + mVSyncMonitor = new VSyncMonitor(context, this);
|
| + }
|
| +
|
| + @Override
|
| + public void onVSync(VSyncMonitor monitor, long vsyncTimeMicros) {
|
| + if (mVSyncListener == null) return;
|
| + if (mVSyncNotificationEnabled) {
|
| + mVSyncListener.onVSync(vsyncTimeMicros);
|
| + mVSyncMonitor.requestUpdate();
|
| + } else {
|
| // Compensate for input event lag. Input events are delivered immediately on
|
| // pre-JB releases, so this adjustment is only done for later versions.
|
| if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
|
| vsyncTimeMicros += INPUT_EVENT_LAG_FROM_VSYNC_MICROSECONDS;
|
| }
|
| - mCurrentContentView.getContentViewCore().updateVSync(vsyncTimeMicros,
|
| + mVSyncListener.updateVSync(vsyncTimeMicros,
|
| mVSyncMonitor.getVSyncPeriodInMicroseconds());
|
| }
|
| - });
|
| -
|
| - addView(mSurfaceView,
|
| - new FrameLayout.LayoutParams(
|
| - FrameLayout.LayoutParams.MATCH_PARENT,
|
| - FrameLayout.LayoutParams.MATCH_PARENT));
|
| + }
|
| +
|
| + @Override
|
| + public void setVSyncNotificationEnabled(VSyncManager.Listener listener, boolean enabled) {
|
| + if (enabled && !mVSyncNotificationEnabled) mVSyncMonitor.requestUpdate();
|
| + mVSyncNotificationEnabled = enabled;
|
| + }
|
| +
|
| + void setVSyncListener(VSyncManager.Listener listener) {
|
| + mVSyncListener = listener;
|
| + if (mVSyncListener != null) mVSyncMonitor.requestUpdate();
|
| + }
|
| }
|
|
|
| /**
|
| @@ -102,13 +126,13 @@ public class ContentViewRenderView extends FrameLayout {
|
| * Makes the passed ContentView the one displayed by this ContentViewRenderView.
|
| */
|
| public void setCurrentContentView(ContentView contentView) {
|
| + ContentViewCore contentViewCore = contentView.getContentViewCore();
|
| nativeSetCurrentContentView(mNativeContentViewRenderView,
|
| - contentView.getContentViewCore().getNativeContentViewCore());
|
| + contentViewCore.getNativeContentViewCore());
|
|
|
| mCurrentContentView = contentView;
|
| - mCurrentContentView.getContentViewCore().onPhysicalBackingSizeChanged(
|
| - getWidth(), getHeight());
|
| - mVSyncMonitor.requestUpdate();
|
| + contentViewCore.onPhysicalBackingSizeChanged(getWidth(), getHeight());
|
| + mVSyncAdapter.setVSyncListener(contentViewCore.getVSyncListener(mVSyncAdapter));
|
| }
|
|
|
| /**
|
|
|