diff options
author | joth@chromium.org <joth@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-06-13 22:42:55 +0000 |
---|---|---|
committer | joth@chromium.org <joth@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-06-13 22:42:55 +0000 |
commit | bc66e38566dacd301b44d3b4f6ee44913f7cedb7 (patch) | |
tree | 1939819f3e771666ff1190b7f176dcd6e4494209 /android_webview | |
parent | 13914c9dae337943e348df3f63bed3bb1375bb3c (diff) | |
download | chromium_src-bc66e38566dacd301b44d3b4f6ee44913f7cedb7.zip chromium_src-bc66e38566dacd301b44d3b4f6ee44913f7cedb7.tar.gz chromium_src-bc66e38566dacd301b44d3b4f6ee44913f7cedb7.tar.bz2 |
Consolidate the SW and HW draw methods in InProcessViewRenderer
As the view renderer already requests DrawGL invocation for the GL init
path, it's simpler to have it always request GL callback than sometimes
have AwContents.java perform that duty.
Review URL: https://chromiumcodereview.appspot.com/16034017
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@206180 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'android_webview')
-rw-r--r-- | android_webview/browser/browser_view_renderer.h | 25 | ||||
-rw-r--r-- | android_webview/browser/in_process_view_renderer.cc | 30 | ||||
-rw-r--r-- | android_webview/browser/in_process_view_renderer.h | 7 | ||||
-rw-r--r-- | android_webview/java/src/org/chromium/android_webview/AwContents.java | 43 | ||||
-rw-r--r-- | android_webview/native/aw_contents.cc | 34 | ||||
-rw-r--r-- | android_webview/native/aw_contents.h | 17 |
6 files changed, 87 insertions, 69 deletions
diff --git a/android_webview/browser/browser_view_renderer.h b/android_webview/browser/browser_view_renderer.h index 86c1ea9..ded115a 100644 --- a/android_webview/browser/browser_view_renderer.h +++ b/android_webview/browser/browser_view_renderer.h @@ -28,9 +28,10 @@ class BrowserViewRenderer { public: class Client { public: - // Request DrawGL be called with AwDrawGLInfo::kModeProcess. The callback + // Request DrawGL be called. Passing null canvas implies the request + // will be of AwDrawGLInfo::kModeProcess type. The callback // may never be made, and the mode may be promoted to kModeDraw. - virtual void RequestProcessMode() = 0; + virtual bool RequestDrawGL(jobject canvas) = 0; // Called when a new Picture is available. Needs to be enabled // via the EnableOnNewPicture method. @@ -73,6 +74,7 @@ class BrowserViewRenderer { virtual ~JavaHelper() {} }; + // Global hookup methods. static void SetAwDrawSWFunctionTable(AwDrawSWFunctionTable* table); static AwDrawSWFunctionTable* GetAwDrawSWFunctionTable(); static bool IsSkiaVersionCompatible(); @@ -80,13 +82,22 @@ class BrowserViewRenderer { // Content control methods. virtual void SetContents(content::ContentViewCore* content_view_core) = 0; - // Hardware rendering methods. - virtual bool PrepareDrawGL(int x, int y) = 0; + // Rendering methods. + + // Main handler for view drawing: performs a SW draw immediately, or sets up + // a subsequent GL Draw (via Client::RequestDrawGL) and returns true. A false + // return value indicates nothing was or will be drawn. + // |java_canvas| is the target of the draw. |is_hardware_canvas| indicates + // a GL Draw maybe possible on this canvas. |scroll| if the view's current + // scroll offset. |clip| is the canvas's clip bounds. + virtual bool OnDraw(jobject java_canvas, + bool is_hardware_canvas, + const gfx::Point& scroll, + const gfx::Rect& clip) = 0; + // Called in response to a prior Client::RequestDrawGL() call. See + // AwDrawGLInfo documentation for more details of the contract. virtual void DrawGL(AwDrawGLInfo* draw_info) = 0; - // Software rendering methods. - virtual bool DrawSW(jobject java_canvas, const gfx::Rect& clip_bounds) = 0; - // CapturePicture API methods. virtual base::android::ScopedJavaLocalRef<jobject> CapturePicture() = 0; virtual void EnableOnNewPicture(bool enabled) = 0; diff --git a/android_webview/browser/in_process_view_renderer.cc b/android_webview/browser/in_process_view_renderer.cc index 6122172..556b7c5 100644 --- a/android_webview/browser/in_process_view_renderer.cc +++ b/android_webview/browser/in_process_view_renderer.cc @@ -352,11 +352,20 @@ void InProcessViewRenderer::WebContentsGone() { compositor_ = NULL; } -bool InProcessViewRenderer::PrepareDrawGL(int x, int y) { - // No harm in updating |scroll_at_start_of_frame_| even if we return false. - scroll_at_start_of_frame_ = gfx::Point(x, y); - return attached_to_window_ && compositor_ && !hardware_failed_ && - HardwareEnabled(); +bool InProcessViewRenderer::OnDraw(jobject java_canvas, + bool is_hardware_canvas, + const gfx::Point& scroll, + const gfx::Rect& clip) { + scroll_at_start_of_frame_ = scroll; + if (is_hardware_canvas && attached_to_window_ && compositor_ && + HardwareEnabled() && client_->RequestDrawGL(java_canvas)) { + // All set: we'll get a call on DrawGL when the time comes. + return true; + } + // Perform a software draw + bool result = DrawSWInternal(java_canvas, clip); + EnsureContinuousInvalidation(); + return result; } void InProcessViewRenderer::DrawGL(AwDrawGLInfo* draw_info) { @@ -412,13 +421,6 @@ void InProcessViewRenderer::DrawGL(AwDrawGLInfo* draw_info) { EnsureContinuousInvalidation(); } -bool InProcessViewRenderer::DrawSW(jobject java_canvas, - const gfx::Rect& clip) { - bool result = DrawSWInternal(java_canvas, clip); - EnsureContinuousInvalidation(); - return result; -} - bool InProcessViewRenderer::DrawSWInternal(jobject java_canvas, const gfx::Rect& clip) { TRACE_EVENT0("android_webview", "InProcessViewRenderer::DrawSW"); @@ -561,7 +563,7 @@ void InProcessViewRenderer::OnAttachedToWindow(int width, int height) { width_ = width; height_ = height; if (compositor_ && !hardware_initialized_) - client_->RequestProcessMode(); + client_->RequestDrawGL(NULL); } void InProcessViewRenderer::OnDetachedFromWindow() { @@ -589,7 +591,7 @@ void InProcessViewRenderer::DidInitializeCompositor( hardware_failed_ = false; if (attached_to_window_) - client_->RequestProcessMode(); + client_->RequestDrawGL(NULL); } void InProcessViewRenderer::DidDestroyCompositor( diff --git a/android_webview/browser/in_process_view_renderer.h b/android_webview/browser/in_process_view_renderer.h index 3a05209..55d5415b 100644 --- a/android_webview/browser/in_process_view_renderer.h +++ b/android_webview/browser/in_process_view_renderer.h @@ -35,10 +35,11 @@ class InProcessViewRenderer : public BrowserViewRenderer, // BrowserViewRenderer overrides virtual void SetContents( content::ContentViewCore* content_view_core) OVERRIDE; - virtual bool PrepareDrawGL(int x, int y) OVERRIDE; + virtual bool OnDraw(jobject java_canvas, + bool is_hardware_canvas, + const gfx::Point& scroll, + const gfx::Rect& clip) OVERRIDE; virtual void DrawGL(AwDrawGLInfo* draw_info) OVERRIDE; - virtual bool DrawSW(jobject java_canvas, - const gfx::Rect& clip_bounds) OVERRIDE; virtual base::android::ScopedJavaLocalRef<jobject> CapturePicture() OVERRIDE; virtual void EnableOnNewPicture(bool enabled) OVERRIDE; virtual void OnVisibilityChanged( 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 2f30c92..4730d24 100644 --- a/android_webview/java/src/org/chromium/android_webview/AwContents.java +++ b/android_webview/java/src/org/chromium/android_webview/AwContents.java @@ -133,7 +133,6 @@ public class AwContents { private boolean mNewPictureInvalidationOnly; - private Rect mGlobalVisibleBounds; private int mLastGlobalVisibleWidth; private int mLastGlobalVisibleHeight; @@ -388,18 +387,20 @@ public class AwContents { mDefaultVideoPosterRequestHandler = new DefaultVideoPosterRequestHandler(mContentsClient); mSettings.setDefaultVideoPosterURL( mDefaultVideoPosterRequestHandler.getDefaultVideoPosterURL()); - mGlobalVisibleBounds = new Rect(); } + // Only valid within updatePhysicalBackingSizeIfNeeded(). + private final Rect mGlobalVisibleBoundsTemporary = new Rect(); + private void updatePhysicalBackingSizeIfNeeded() { // We musn't let the physical backing size get too big, otherwise we // will try to allocate a SurfaceTexture beyond what the GL driver can // cope with. In most cases, limiting the SurfaceTexture size to that // of the visible bounds of the WebView will be good enough i.e. the maximum // SurfaceTexture dimensions will match the screen dimensions). - mContainerView.getGlobalVisibleRect(mGlobalVisibleBounds); - int width = mGlobalVisibleBounds.width(); - int height = mGlobalVisibleBounds.height(); + mContainerView.getGlobalVisibleRect(mGlobalVisibleBoundsTemporary); + int width = mGlobalVisibleBoundsTemporary.width(); + int height = mGlobalVisibleBoundsTemporary.height(); if (width != mLastGlobalVisibleWidth || height != mLastGlobalVisibleHeight) { mLastGlobalVisibleWidth = width; mLastGlobalVisibleHeight = height; @@ -457,19 +458,18 @@ public class AwContents { return nativeGetAwDrawGLViewContext(mNativeAwContents); } + // Only valid within onDraw(). + private final Rect mClipBoundsTemporary = new Rect(); + public void onDraw(Canvas canvas) { if (mNativeAwContents == 0) return; - // TODO(joth): Consolidate most of this logic into nativePrepareDrawGL(), and - // rename it to nativeOnDraw(). - if (nativePrepareDrawGL(mNativeAwContents, - mContainerView.getScrollX(), mContainerView.getScrollY()) && - canvas.isHardwareAccelerated() && mInternalAccessAdapter.requestDrawGL(canvas)) { - return; - } - Rect clip = canvas.getClipBounds(); - if (!nativeDrawSW(mNativeAwContents, canvas, clip.left, clip.top, - clip.right - clip.left, clip.bottom - clip.top)) { - Log.w(TAG, "Native DrawSW failed; clearing to background color."); + + canvas.getClipBounds(mClipBoundsTemporary); + if (!nativeOnDraw(mNativeAwContents, canvas, canvas.isHardwareAccelerated(), + mContainerView.getScrollX(), mContainerView.getScrollY(), + mClipBoundsTemporary.left, mClipBoundsTemporary.top, + mClipBoundsTemporary.right, mClipBoundsTemporary.bottom )) { + Log.w(TAG, "nativeOnDraw failed; clearing to background color."); int c = mContentViewCore.getBackgroundColor(); canvas.drawRGB(Color.red(c), Color.green(c), Color.blue(c)); } @@ -1343,8 +1343,8 @@ public class AwContents { } @CalledByNative - private void requestProcessMode() { - mInternalAccessAdapter.requestDrawGL(null); + private boolean requestDrawGL(Canvas canvas) { + return mInternalAccessAdapter.requestDrawGL(canvas); } @CalledByNative @@ -1446,8 +1446,9 @@ public class AwContents { InterceptNavigationDelegate navigationInterceptionDelegate); private native void nativeAddVisitedLinks(int nativeAwContents, String[] visitedLinks); - - private native boolean nativePrepareDrawGL(int nativeAwContents, int scrollX, int scrollY); + private native boolean nativeOnDraw(int nativeAwContents, Canvas canvas, + boolean isHardwareAccelerated, int scrollX, int ScrollY, + int clipLeft, int clipTop, int clipRight, int clipBottom); private native void nativeFindAllAsync(int nativeAwContents, String searchString); private native void nativeFindNext(int nativeAwContents, boolean forward); private native void nativeClearMatches(int nativeAwContents); @@ -1474,8 +1475,6 @@ public class AwContents { private native void nativeSetWebContents(int nativeAwContents, int nativeNewWebContents); private native void nativeFocusFirstNode(int nativeAwContents); - private native boolean nativeDrawSW(int nativeAwContents, Canvas canvas, int clipX, int clipY, - int clipW, int clipH); private native int nativeGetAwDrawGLViewContext(int nativeAwContents); private native Picture nativeCapturePicture(int nativeAwContents); private native void nativeEnableOnNewPicture(int nativeAwContents, boolean enabled); diff --git a/android_webview/native/aw_contents.cc b/android_webview/native/aw_contents.cc index 79eceeb..8d726da 100644 --- a/android_webview/native/aw_contents.cc +++ b/android_webview/native/aw_contents.cc @@ -515,11 +515,12 @@ void AwContents::OnReceivedTouchIconUrl(const std::string& url, env, obj.obj(), ConvertUTF8ToJavaString(env, url).obj(), precomposed); } -void AwContents::RequestProcessMode() { +bool AwContents::RequestDrawGL(jobject canvas) { JNIEnv* env = AttachCurrentThread(); ScopedJavaLocalRef<jobject> obj = java_ref_.get(env); - if (!obj.is_null()) - Java_AwContents_requestProcessMode(env, obj.obj()); + if (obj.is_null()) + return false; + return Java_AwContents_requestDrawGL(env, obj.obj(), canvas); } void AwContents::Invalidate() { @@ -644,20 +645,23 @@ jboolean AwContents::RestoreFromOpaqueState( return RestoreFromPickle(&iterator, web_contents_.get()); } -bool AwContents::DrawSW(JNIEnv* env, +bool AwContents::OnDraw(JNIEnv* env, jobject obj, jobject canvas, - jint clip_x, - jint clip_y, - jint clip_w, - jint clip_h) { - return browser_view_renderer_->DrawSW( - canvas, gfx::Rect(clip_x, clip_y, clip_w, clip_h)); -} - -bool AwContents::PrepareDrawGL(JNIEnv* env, jobject obj, - int scroll_x, int scroll_y) { - return browser_view_renderer_->PrepareDrawGL(scroll_x, scroll_y); + jboolean is_hardware_accelerated, + jint scroll_x, + jint scroll_y, + jint clip_left, + jint clip_top, + jint clip_right, + jint clip_bottom) { + return browser_view_renderer_->OnDraw(canvas, + is_hardware_accelerated, + gfx::Point(scroll_x, scroll_y), + gfx::Rect(clip_left, + clip_top, + clip_right - clip_left, + clip_bottom - clip_top)); } void AwContents::SetPendingWebContentsForPopup( diff --git a/android_webview/native/aw_contents.h b/android_webview/native/aw_contents.h index 0465ae2..170e9b7 100644 --- a/android_webview/native/aw_contents.h +++ b/android_webview/native/aw_contents.h @@ -94,15 +94,16 @@ class AwContents : public FindHelper::Listener, JNIEnv* env, jobject obj); jboolean RestoreFromOpaqueState(JNIEnv* env, jobject obj, jbyteArray state); void FocusFirstNode(JNIEnv* env, jobject obj); - bool DrawSW(JNIEnv* env, + bool OnDraw(JNIEnv* env, jobject obj, jobject canvas, - jint clip_x, - jint clip_y, - jint clip_w, - jint clip_h); - bool PrepareDrawGL(JNIEnv* env, jobject obj, - int scroll_x, int scroll_y); + jboolean is_hardware_accelerated, + jint scroll_x, + jint scroll_y, + jint clip_left, + jint clip_top, + jint clip_right, + jint clip_bottom); jint GetAwDrawGLViewContext(JNIEnv* env, jobject obj); base::android::ScopedJavaLocalRef<jobject> CapturePicture(JNIEnv* env, jobject obj); @@ -137,7 +138,7 @@ class AwContents : public FindHelper::Listener, virtual void OnPageScaleFactorChanged(float page_scale_factor) OVERRIDE; // BrowserViewRenderer::Client implementation. - virtual void RequestProcessMode() OVERRIDE; + virtual bool RequestDrawGL(jobject canvas) OVERRIDE; virtual void Invalidate() OVERRIDE; virtual void OnNewPicture() OVERRIDE; virtual gfx::Point GetLocationOnScreen() OVERRIDE; |