[Android WebView] Update SW rendering to use SkPicture and fix scrolling cases.

The new capturePicture API will now provide SkPicture objects rather than cc::PicturePileImpl. Update the code to reflect that.

Also, when rendering into separate layers in HW mode we're applying a translation to undo the Android Framework scrolling and let Chrome's compositor take care of it. This is not applicable to the layer case, however, as we only render ourselves out of our provided sufrace.

SW rendering doesn't need scroll correction after using SkPicture directly. Before, cc::PicturePileImpl translated the canvas as part of the content rect rasterization.

BUG=161409

Review URL: https://chromiumcodereview.appspot.com/11732002

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@175781 0039d316-1c4b-4281-b951-d872f2087c98
parent 72bf5ac2
...@@ -13,6 +13,8 @@ include_rules = [ ...@@ -13,6 +13,8 @@ include_rules = [
"+content/public/common", "+content/public/common",
"+jni", "+jni",
"+net", "+net",
"+skia",
"+third_party/skia/include",
"+ui/android", "+ui/android",
"+ui/base", "+ui/base",
"+webkit", "+webkit",
......
...@@ -4,6 +4,8 @@ ...@@ -4,6 +4,8 @@
#include "android_webview/common/renderer_picture_map.h" #include "android_webview/common/renderer_picture_map.h"
#include "base/logging.h"
using base::AutoLock; using base::AutoLock;
namespace android_webview { namespace android_webview {
...@@ -28,14 +30,13 @@ RendererPictureMap::RendererPictureMap() { ...@@ -28,14 +30,13 @@ RendererPictureMap::RendererPictureMap() {
RendererPictureMap::~RendererPictureMap() { RendererPictureMap::~RendererPictureMap() {
} }
scoped_refptr<cc::PicturePileImpl> RendererPictureMap::GetRendererPicture( skia::RefPtr<SkPicture> RendererPictureMap::GetRendererPicture(int id) {
int id) {
AutoLock lock(lock_); AutoLock lock(lock_);
return picture_map_[id]; return picture_map_[id];
} }
void RendererPictureMap::SetRendererPicture(int id, void RendererPictureMap::SetRendererPicture(int id,
scoped_refptr<cc::PicturePileImpl> picture) { skia::RefPtr<SkPicture> picture) {
AutoLock lock(lock_); AutoLock lock(lock_);
picture_map_[id] = picture; picture_map_[id] = picture;
} }
......
...@@ -7,28 +7,28 @@ ...@@ -7,28 +7,28 @@
#include <map> #include <map>
#include "base/memory/ref_counted.h"
#include "base/synchronization/lock.h" #include "base/synchronization/lock.h"
#include "cc/picture_pile_impl.h" #include "skia/ext/refptr.h"
#include "third_party/skia/include/core/SkPicture.h"
namespace android_webview { namespace android_webview {
// Stores picture piles received from diferent renderers and associates them by // Stores pictures received from diferent renderers and associates them by
// renderer id. Will only work in single process mode. // renderer id. Will only work in single process mode.
class RendererPictureMap { class RendererPictureMap {
public: public:
static void CreateInstance(); static void CreateInstance();
static RendererPictureMap* GetInstance(); static RendererPictureMap* GetInstance();
scoped_refptr<cc::PicturePileImpl> GetRendererPicture(int id); skia::RefPtr<SkPicture> GetRendererPicture(int id);
void SetRendererPicture(int id, scoped_refptr<cc::PicturePileImpl> picture); void SetRendererPicture(int id, skia::RefPtr<SkPicture> picture);
void ClearRendererPicture(int id); void ClearRendererPicture(int id);
private: private:
RendererPictureMap(); RendererPictureMap();
~RendererPictureMap(); ~RendererPictureMap();
typedef std::map<int, scoped_refptr<cc::PicturePileImpl> > PictureMap; typedef std::map<int, skia::RefPtr<SkPicture> > PictureMap;
PictureMap picture_map_; PictureMap picture_map_;
base::Lock lock_; base::Lock lock_;
}; };
......
...@@ -27,8 +27,6 @@ ...@@ -27,8 +27,6 @@
#include "base/pickle.h" #include "base/pickle.h"
#include "base/supports_user_data.h" #include "base/supports_user_data.h"
#include "cc/layer.h" #include "cc/layer.h"
#include "cc/picture_pile_impl.h"
#include "cc/rendering_stats.h"
#include "content/components/navigation_interception/intercept_navigation_delegate.h" #include "content/components/navigation_interception/intercept_navigation_delegate.h"
#include "content/public/browser/android/content_view_core.h" #include "content/public/browser/android/content_view_core.h"
#include "content/public/browser/browser_thread.h" #include "content/public/browser/browser_thread.h"
...@@ -39,9 +37,11 @@ ...@@ -39,9 +37,11 @@
#include "content/public/common/ssl_status.h" #include "content/public/common/ssl_status.h"
#include "jni/AwContents_jni.h" #include "jni/AwContents_jni.h"
#include "net/base/x509_certificate.h" #include "net/base/x509_certificate.h"
#include "skia/ext/refptr.h"
#include "third_party/skia/include/core/SkBitmap.h" #include "third_party/skia/include/core/SkBitmap.h"
#include "third_party/skia/include/core/SkCanvas.h" #include "third_party/skia/include/core/SkCanvas.h"
#include "third_party/skia/include/core/SkDevice.h" #include "third_party/skia/include/core/SkDevice.h"
#include "third_party/skia/include/core/SkPicture.h"
#include "ui/gfx/transform.h" #include "ui/gfx/transform.h"
#include "ui/gl/gl_bindings.h" #include "ui/gl/gl_bindings.h"
...@@ -122,7 +122,6 @@ AwContents::AwContents(JNIEnv* env, ...@@ -122,7 +122,6 @@ AwContents::AwContents(JNIEnv* env,
view_visible_(false), view_visible_(false),
compositor_visible_(false), compositor_visible_(false),
is_composite_pending_(false), is_composite_pending_(false),
last_scroll_x_(0), last_scroll_y_(0),
last_frame_context_(NULL) { last_frame_context_(NULL) {
RendererPictureMap::CreateInstance(); RendererPictureMap::CreateInstance();
android_webview::AwBrowserDependencyFactory* dependency_factory = android_webview::AwBrowserDependencyFactory* dependency_factory =
...@@ -270,7 +269,6 @@ void AwContents::DrawGL(AwDrawGLInfo* draw_info) { ...@@ -270,7 +269,6 @@ void AwContents::DrawGL(AwDrawGLInfo* draw_info) {
last_frame_context_ = current_context; last_frame_context_ = current_context;
} }
gfx::Transform transform;
compositor_->SetWindowBounds(gfx::Size(draw_info->width, draw_info->height)); compositor_->SetWindowBounds(gfx::Size(draw_info->width, draw_info->height));
if (draw_info->is_layer) { if (draw_info->is_layer) {
...@@ -279,6 +277,7 @@ void AwContents::DrawGL(AwDrawGLInfo* draw_info) { ...@@ -279,6 +277,7 @@ void AwContents::DrawGL(AwDrawGLInfo* draw_info) {
// The Android framework will composite us afterwards. // The Android framework will composite us afterwards.
compositor_->SetHasTransparentBackground(false); compositor_->SetHasTransparentBackground(false);
view_clip_layer_->setMasksToBounds(false); view_clip_layer_->setMasksToBounds(false);
transform_layer_->setTransform(gfx::Transform());
scissor_clip_layer_->setMasksToBounds(false); scissor_clip_layer_->setMasksToBounds(false);
scissor_clip_layer_->setPosition(gfx::PointF()); scissor_clip_layer_->setPosition(gfx::PointF());
scissor_clip_layer_->setBounds(gfx::Size()); scissor_clip_layer_->setBounds(gfx::Size());
...@@ -303,15 +302,17 @@ void AwContents::DrawGL(AwDrawGLInfo* draw_info) { ...@@ -303,15 +302,17 @@ void AwContents::DrawGL(AwDrawGLInfo* draw_info) {
undo_clip_position.Translate(-clip_rect.x(), -clip_rect.y()); undo_clip_position.Translate(-clip_rect.x(), -clip_rect.y());
scissor_clip_layer_->setSublayerTransform(undo_clip_position); scissor_clip_layer_->setSublayerTransform(undo_clip_position);
gfx::Transform transform;
transform.matrix().setColMajorf(draw_info->transform); transform.matrix().setColMajorf(draw_info->transform);
view_clip_layer_->setMasksToBounds(true);
}
// The scrolling values of the Android Framework affect the transformation // The scrolling values of the Android Framework affect the transformation
// matrix. This needs to be undone to let the compositor handle scrolling. // matrix. This needs to be undone to let the compositor handle scrolling.
transform.Translate(last_scroll_x_, last_scroll_y_); transform.Translate(hw_rendering_scroll_.x(), hw_rendering_scroll_.y());
transform_layer_->setTransform(transform); transform_layer_->setTransform(transform);
view_clip_layer_->setMasksToBounds(true);
}
compositor_->Composite(); compositor_->Composite();
is_composite_pending_ = false; is_composite_pending_ = false;
...@@ -379,7 +380,7 @@ void AwContents::DrawGL(AwDrawGLInfo* draw_info) { ...@@ -379,7 +380,7 @@ void AwContents::DrawGL(AwDrawGLInfo* draw_info) {
} }
bool AwContents::DrawSW(JNIEnv* env, jobject obj, jobject java_canvas) { bool AwContents::DrawSW(JNIEnv* env, jobject obj, jobject java_canvas) {
scoped_refptr<cc::PicturePileImpl> picture = skia::RefPtr<SkPicture> picture =
RendererPictureMap::GetInstance()->GetRendererPicture( RendererPictureMap::GetInstance()->GetRendererPicture(
web_contents_->GetRoutingID()); web_contents_->GetRoutingID());
if (!picture) if (!picture)
...@@ -402,9 +403,8 @@ bool AwContents::DrawSW(JNIEnv* env, jobject obj, jobject java_canvas) { ...@@ -402,9 +403,8 @@ bool AwContents::DrawSW(JNIEnv* env, jobject obj, jobject java_canvas) {
SkDevice device(bitmap); SkDevice device(bitmap);
SkCanvas canvas(&device); SkCanvas canvas(&device);
SkMatrix matrix; SkMatrix matrix;
for (int i = 0; i < 9; i++) { for (int i = 0; i < 9; i++)
matrix.set(i, pixels->matrix[i]); matrix.set(i, pixels->matrix[i]);
}
canvas.setMatrix(matrix); canvas.setMatrix(matrix);
SkRegion clip; SkRegion clip;
...@@ -416,12 +416,7 @@ bool AwContents::DrawSW(JNIEnv* env, jobject obj, jobject java_canvas) { ...@@ -416,12 +416,7 @@ bool AwContents::DrawSW(JNIEnv* env, jobject obj, jobject java_canvas) {
clip.setRect(SkIRect::MakeWH(pixels->width, pixels->height)); clip.setRect(SkIRect::MakeWH(pixels->width, pixels->height));
} }
SkIRect sk_clip_rect = clip.getBounds(); picture->draw(&canvas);
gfx::Rect clip_rect(sk_clip_rect.x(), sk_clip_rect.y(),
sk_clip_rect.width(), sk_clip_rect.height());
cc::RenderingStats stats;
picture->Raster(&canvas, clip_rect, 1.0, &stats);
} }
g_draw_sw_functions->release_pixels(pixels); g_draw_sw_functions->release_pixels(pixels);
...@@ -817,8 +812,7 @@ jboolean AwContents::RestoreFromOpaqueState( ...@@ -817,8 +812,7 @@ jboolean AwContents::RestoreFromOpaqueState(
void AwContents::SetScrollForHWFrame(JNIEnv* env, jobject obj, void AwContents::SetScrollForHWFrame(JNIEnv* env, jobject obj,
int scroll_x, int scroll_y) { int scroll_x, int scroll_y) {
last_scroll_x_ = scroll_x; hw_rendering_scroll_ = gfx::Point(scroll_x, scroll_y);
last_scroll_y_ = scroll_y;
} }
void AwContents::SetPendingWebContentsForPopup( void AwContents::SetPendingWebContentsForPopup(
...@@ -846,6 +840,8 @@ void AwContents::OnPictureUpdated(int process_id, int render_view_id) { ...@@ -846,6 +840,8 @@ void AwContents::OnPictureUpdated(int process_id, int render_view_id) {
if (render_view_id != web_contents_->GetRoutingID()) if (render_view_id != web_contents_->GetRoutingID())
return; return;
// TODO(leandrogracia): delete when sw rendering uses Ubercompositor.
// Invalidation should be provided by the compositor only.
Invalidate(); Invalidate();
} }
......
...@@ -146,11 +146,11 @@ class AwContents : public FindHelper::Listener, ...@@ -146,11 +146,11 @@ class AwContents : public FindHelper::Listener,
scoped_refptr<cc::Layer> scissor_clip_layer_; scoped_refptr<cc::Layer> scissor_clip_layer_;
scoped_refptr<cc::Layer> transform_layer_; scoped_refptr<cc::Layer> transform_layer_;
scoped_refptr<cc::Layer> view_clip_layer_; scoped_refptr<cc::Layer> view_clip_layer_;
gfx::Point hw_rendering_scroll_;
gfx::Size view_size_; gfx::Size view_size_;
bool view_visible_; bool view_visible_;
bool compositor_visible_; bool compositor_visible_;
bool is_composite_pending_; bool is_composite_pending_;
int last_scroll_x_, last_scroll_y_;
// Used only for detecting Android View System context changes. // Used only for detecting Android View System context changes.
// Not to be used between draw calls. // Not to be used between draw calls.
......
...@@ -200,8 +200,7 @@ void AwRenderViewExt::OnEnableCapturePictureCallback(bool enable) { ...@@ -200,8 +200,7 @@ void AwRenderViewExt::OnEnableCapturePictureCallback(bool enable) {
// content::RenderView::CapturePictureCallback()); // content::RenderView::CapturePictureCallback());
} }
void AwRenderViewExt::OnPictureUpdate( void AwRenderViewExt::OnPictureUpdate(skia::RefPtr<SkPicture> picture) {
scoped_refptr<cc::PicturePileImpl> picture) {
RendererPictureMap::GetInstance()->SetRendererPicture(routing_id(), picture); RendererPictureMap::GetInstance()->SetRendererPicture(routing_id(), picture);
Send(new AwViewHostMsg_PictureUpdated(routing_id())); Send(new AwViewHostMsg_PictureUpdated(routing_id()));
} }
......
...@@ -7,10 +7,11 @@ ...@@ -7,10 +7,11 @@
#include "base/basictypes.h" #include "base/basictypes.h"
#include "base/compiler_specific.h" #include "base/compiler_specific.h"
#include "base/memory/ref_counted.h" #include "base/memory/weak_ptr.h"
#include "cc/picture_pile_impl.h"
#include "content/public/renderer/render_view_observer.h" #include "content/public/renderer/render_view_observer.h"
#include "skia/ext/refptr.h"
#include "third_party/WebKit/Source/WebKit/chromium/public/WebPermissionClient.h" #include "third_party/WebKit/Source/WebKit/chromium/public/WebPermissionClient.h"
#include "third_party/skia/include/core/SkPicture.h"
namespace WebKit { namespace WebKit {
...@@ -45,7 +46,7 @@ class AwRenderViewExt : public content::RenderViewObserver, ...@@ -45,7 +46,7 @@ class AwRenderViewExt : public content::RenderViewObserver,
void OnEnableCapturePictureCallback(bool enable); void OnEnableCapturePictureCallback(bool enable);
void OnPictureUpdate(scoped_refptr<cc::PicturePileImpl> picture); void OnPictureUpdate(skia::RefPtr<SkPicture> picture);
// WebKit::WebPermissionClient implementation. // WebKit::WebPermissionClient implementation.
virtual bool allowImage(WebKit::WebFrame* frame, virtual bool allowImage(WebKit::WebFrame* frame,
......
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