diff options
author | joth@chromium.org <joth@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-07-19 05:17:18 +0000 |
---|---|---|
committer | joth@chromium.org <joth@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-07-19 05:17:18 +0000 |
commit | 5f07afcd9dc529b87cfa860ba8cbb526af214dec (patch) | |
tree | 5ae9ed998300679338518998b64b8972ab951350 /android_webview | |
parent | d12ffd8adf17f6442ed60900d14eaa84d0b4f027 (diff) | |
download | chromium_src-5f07afcd9dc529b87cfa860ba8cbb526af214dec.zip chromium_src-5f07afcd9dc529b87cfa860ba8cbb526af214dec.tar.gz chromium_src-5f07afcd9dc529b87cfa860ba8cbb526af214dec.tar.bz2 |
Adds a new callback as this signal is required to pass up to the application
independent of whether the compositor is generating frames
BUG=232944
Review URL: https://chromiumcodereview.appspot.com/16958012
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@212526 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'android_webview')
4 files changed, 46 insertions, 4 deletions
diff --git a/android_webview/browser/in_process_view_renderer.cc b/android_webview/browser/in_process_view_renderer.cc index 53d4a20..2b60bea 100644 --- a/android_webview/browser/in_process_view_renderer.cc +++ b/android_webview/browser/in_process_view_renderer.cc @@ -158,6 +158,7 @@ InProcessViewRenderer::InProcessViewRenderer( visible_(false), dip_scale_(0.0), page_scale_factor_(1.0), + on_new_picture_enable_(false), continuous_invalidate_(false), block_invalidates_(false), width_(0), @@ -411,6 +412,7 @@ InProcessViewRenderer::CapturePicture() { } void InProcessViewRenderer::EnableOnNewPicture(bool enabled) { + on_new_picture_enable_ = enabled; } void InProcessViewRenderer::OnVisibilityChanged(bool visible) { @@ -540,6 +542,11 @@ void InProcessViewRenderer::ScrollTo(gfx::Vector2d new_value) { compositor_->DidChangeRootLayerScrollOffset(); } +void InProcessViewRenderer::DidUpdateContent() { + if (on_new_picture_enable_) + client_->OnNewPicture(); +} + void InProcessViewRenderer::SetTotalRootLayerScrollOffset( gfx::Vector2dF new_value_css) { // TOOD(mkosiba): Add a DCHECK to say that this does _not_ get called during diff --git a/android_webview/browser/in_process_view_renderer.h b/android_webview/browser/in_process_view_renderer.h index 354dc1e..c949bde 100644 --- a/android_webview/browser/in_process_view_renderer.h +++ b/android_webview/browser/in_process_view_renderer.h @@ -63,6 +63,7 @@ class InProcessViewRenderer : public BrowserViewRenderer, virtual void SetContinuousInvalidate(bool invalidate) OVERRIDE; virtual void SetTotalRootLayerScrollOffset( gfx::Vector2dF new_value_css) OVERRIDE; + virtual void DidUpdateContent() OVERRIDE; virtual gfx::Vector2dF GetTotalRootLayerScrollOffset() OVERRIDE; virtual void DidOverscroll(gfx::Vector2dF latest_overscroll_delta, gfx::Vector2dF current_fling_velocity) OVERRIDE; @@ -91,6 +92,7 @@ class InProcessViewRenderer : public BrowserViewRenderer, bool visible_; float dip_scale_; float page_scale_factor_; + bool on_new_picture_enable_; // When true, we should continuously invalidate and keep drawing, for example // to drive animation. diff --git a/android_webview/java/src/org/chromium/android_webview/AwContents.java b/android_webview/java/src/org/chromium/android_webview/AwContents.java index d425f4d..40075d7 100644 --- a/android_webview/java/src/org/chromium/android_webview/AwContents.java +++ b/android_webview/java/src/org/chromium/android_webview/AwContents.java @@ -55,6 +55,7 @@ import java.io.File; import java.lang.annotation.Annotation; import java.net.MalformedURLException; import java.net.URL; +import java.util.concurrent.Callable; /** * Exposes the native AwContents class, and together these classes wrap the ContentViewCore @@ -160,7 +161,9 @@ public class AwContents { private DefaultVideoPosterRequestHandler mDefaultVideoPosterRequestHandler; - private boolean mNewPictureInvalidationOnly; + // Bound method for suppling Picture instances to the AwContentClient. Will be null if the + // picture listener API has not yet been enabled, or if it is using invalidation-only mode. + private Callable<Picture> mPictureListenerContentProvider; private int mLastGlobalVisibleWidth; private int mLastGlobalVisibleHeight; @@ -687,12 +690,21 @@ public class AwContents { } /** - * Enable the OnNewPicture callback. + * Enable the onNewPicture callback. * @param enabled Flag to enable the callback. * @param invalidationOnly Flag to call back only on invalidation without providing a picture. */ public void enableOnNewPicture(boolean enabled, boolean invalidationOnly) { - mNewPictureInvalidationOnly = invalidationOnly; + if (invalidationOnly) { + mPictureListenerContentProvider = null; + } else if (enabled && mPictureListenerContentProvider == null) { + mPictureListenerContentProvider = new Callable<Picture>() { + @Override + public Picture call() { + return capturePicture(); + } + }; + } nativeEnableOnNewPicture(mNativeAwContents, enabled); } @@ -1535,7 +1547,10 @@ public class AwContents { @CalledByNative public void onNewPicture() { - mContentsClient.onNewPicture(mNewPictureInvalidationOnly ? null : capturePicture()); + // Don't call capturePicture() here but instead defer it until the posted task runs within + // the callback helper, to avoid doubling back into the renderer compositor in the middle + // of the notification it is sending up to here. + mContentsClient.getCallbackHelper().postOnNewPicture(mPictureListenerContentProvider); } // Called as a result of nativeUpdateLastHitTestData. diff --git a/android_webview/java/src/org/chromium/android_webview/AwContentsClientCallbackHelper.java b/android_webview/java/src/org/chromium/android_webview/AwContentsClientCallbackHelper.java index 8dbd571..8b00a34 100644 --- a/android_webview/java/src/org/chromium/android_webview/AwContentsClientCallbackHelper.java +++ b/android_webview/java/src/org/chromium/android_webview/AwContentsClientCallbackHelper.java @@ -4,12 +4,15 @@ package org.chromium.android_webview; +import android.graphics.Picture; import android.os.Handler; import android.os.Looper; import android.os.Message; import org.chromium.content.browser.ContentViewCore; +import java.util.concurrent.Callable; + /** * This class is responsible for calling certain client callbacks on the UI thread. * @@ -70,6 +73,7 @@ class AwContentsClientCallbackHelper { private final static int MSG_ON_DOWNLOAD_START = 3; private final static int MSG_ON_RECEIVED_LOGIN_REQUEST = 4; private final static int MSG_ON_RECEIVED_ERROR = 5; + private final static int MSG_ON_NEW_PICTURE = 6; private final AwContentsClient mContentsClient; @@ -104,6 +108,16 @@ class AwContentsClientCallbackHelper { info.mFailingUrl); break; } + case MSG_ON_NEW_PICTURE: { + Picture picture = null; + try { + if (msg.obj != null) picture = ((Callable<Picture>) msg.obj).call(); + } catch (Exception e) { + throw new RuntimeException("Error getting picture", e); + } + mContentsClient.onNewPicture(picture); + break; + } default: throw new IllegalStateException( "AwContentsClientCallbackHelper: unhandled message " + msg.what); @@ -139,4 +153,8 @@ class AwContentsClientCallbackHelper { OnReceivedErrorInfo info = new OnReceivedErrorInfo(errorCode, description, failingUrl); mHandler.sendMessage(mHandler.obtainMessage(MSG_ON_RECEIVED_ERROR, info)); } + + public void postOnNewPicture(Callable<Picture> pictureProvider) { + mHandler.sendMessage(mHandler.obtainMessage(MSG_ON_NEW_PICTURE, pictureProvider)); + } } |