Expose the capturePicture feature in RenderView for Android WebView legacy API support.

These methods are required to implement WebView.capturePicture and WebView.PictureListener.onNewPicture.
- http://developer.android.com/reference/android/webkit/WebView.html#capturePicture()
- http://developer.android.com/reference/android/webkit/WebView.PictureListener.html

BUG=167908,167913

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

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@182106 0039d316-1c4b-4281-b951-d872f2087c98
parent 768c8ac2
...@@ -31,15 +31,6 @@ bool AwMainDelegate::BasicStartupComplete(int* exit_code) { ...@@ -31,15 +31,6 @@ bool AwMainDelegate::BasicStartupComplete(int* exit_code) {
// Set the command line to enable synchronous API compatibility. // Set the command line to enable synchronous API compatibility.
command_line->AppendSwitch(switches::kEnableWebViewSynchronousAPIs); command_line->AppendSwitch(switches::kEnableWebViewSynchronousAPIs);
// TODO(leandrogracia): enable with the CapturePicture API support.
if (false) {
// Enable impl-side painting in the compositor.
command_line->AppendSwitch(switches::kForceCompositingMode);
command_line->AppendSwitch(switches::kEnableThreadedCompositing);
command_line->AppendSwitch(switches::kEnableDeferredImageDecoding);
command_line->AppendSwitch(cc::switches::kEnableImplSidePainting);
}
return false; return false;
} }
......
...@@ -554,9 +554,8 @@ void AwContents::Destroy(JNIEnv* env, jobject obj) { ...@@ -554,9 +554,8 @@ void AwContents::Destroy(JNIEnv* env, jobject obj) {
void SetAwDrawSWFunctionTable(JNIEnv* env, jclass, jint function_table) { void SetAwDrawSWFunctionTable(JNIEnv* env, jclass, jint function_table) {
g_draw_sw_functions = g_draw_sw_functions =
reinterpret_cast<AwDrawSWFunctionTable*>(function_table); reinterpret_cast<AwDrawSWFunctionTable*>(function_table);
// TODO(leandrogracia): uncomment once the glue layer implements this method. g_is_skia_version_compatible =
//g_is_skia_version_compatible = g_draw_sw_functions->is_skia_version_compatible(&SkGraphics::GetVersion);
// g_draw_sw_functions->is_skia_version_compatible(&SkGraphics::GetVersion);
LOG_IF(WARNING, !g_is_skia_version_compatible) << LOG_IF(WARNING, !g_is_skia_version_compatible) <<
"Skia native versions are not compatible."; "Skia native versions are not compatible.";
} }
......
...@@ -15,6 +15,7 @@ ...@@ -15,6 +15,7 @@
#include "content/public/renderer/android_content_detection_prefixes.h" #include "content/public/renderer/android_content_detection_prefixes.h"
#include "content/public/renderer/document_state.h" #include "content/public/renderer/document_state.h"
#include "content/public/renderer/render_view.h" #include "content/public/renderer/render_view.h"
#include "skia/ext/refptr.h"
#include "third_party/WebKit/Source/Platform/chromium/public/WebSize.h" #include "third_party/WebKit/Source/Platform/chromium/public/WebSize.h"
#include "third_party/WebKit/Source/Platform/chromium/public/WebURL.h" #include "third_party/WebKit/Source/Platform/chromium/public/WebURL.h"
#include "third_party/WebKit/Source/Platform/chromium/public/WebVector.h" #include "third_party/WebKit/Source/Platform/chromium/public/WebVector.h"
...@@ -27,6 +28,7 @@ ...@@ -27,6 +28,7 @@
#include "third_party/WebKit/Source/WebKit/chromium/public/WebNodeList.h" #include "third_party/WebKit/Source/WebKit/chromium/public/WebNodeList.h"
#include "third_party/WebKit/Source/WebKit/chromium/public/WebSecurityOrigin.h" #include "third_party/WebKit/Source/WebKit/chromium/public/WebSecurityOrigin.h"
#include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h" #include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h"
#include "third_party/skia/include/core/SkPicture.h"
namespace android_webview { namespace android_webview {
...@@ -127,18 +129,13 @@ void PopulateHitTestData(const GURL& absolute_link_url, ...@@ -127,18 +129,13 @@ void PopulateHitTestData(const GURL& absolute_link_url,
AwRenderViewExt::AwRenderViewExt(content::RenderView* render_view) AwRenderViewExt::AwRenderViewExt(content::RenderView* render_view)
: content::RenderViewObserver(render_view) { : content::RenderViewObserver(render_view) {
render_view->GetWebView()->setPermissionClient(this); render_view->GetWebView()->setPermissionClient(this);
// TODO(leandrogracia): enable once the feature is available in RenderView.
// TODO(leandrogracia): remove when SW rendering uses Ubercompositor. // TODO(leandrogracia): remove when SW rendering uses Ubercompositor.
// Until then we need the callback enabled for SW mode invalidation. // Until then we need the callback enabled for SW mode invalidation.
// http://crbug.com/170086. // http://crbug.com/170086.
//render_view->SetCapturePictureCallback( capture_picture_enabled_ = true;
// base::Bind(&AwRenderViewExt::OnPictureUpdate, AsWeakPtr()));
} }
AwRenderViewExt::~AwRenderViewExt() { AwRenderViewExt::~AwRenderViewExt() {
// TODO(leandrogracia): enable once the feature is available in RenderView.
//render_view()->SetCapturePictureCallback(
// content::RenderView::CapturePictureCallback());
RendererPictureMap::GetInstance()->ClearRendererPicture(routing_id()); RendererPictureMap::GetInstance()->ClearRendererPicture(routing_id());
} }
...@@ -229,6 +226,15 @@ void AwRenderViewExt::FocusedNodeChanged(const WebKit::WebNode& node) { ...@@ -229,6 +226,15 @@ void AwRenderViewExt::FocusedNodeChanged(const WebKit::WebNode& node) {
Send(new AwViewHostMsg_UpdateHitTestData(routing_id(), data)); Send(new AwViewHostMsg_UpdateHitTestData(routing_id(), data));
} }
void AwRenderViewExt::DidCommitCompositorFrame() {
if (!capture_picture_enabled_)
return;
skia::RefPtr<SkPicture> picture = render_view()->CapturePicture();
RendererPictureMap::GetInstance()->SetRendererPicture(routing_id(), picture);
Send(new AwViewHostMsg_PictureUpdated(routing_id()));
}
void AwRenderViewExt::OnDoHitTest(int view_x, int view_y) { void AwRenderViewExt::OnDoHitTest(int view_x, int view_y) {
if (!render_view() || !render_view()->GetWebView()) if (!render_view() || !render_view()->GetWebView())
return; return;
...@@ -251,21 +257,12 @@ void AwRenderViewExt::OnDoHitTest(int view_x, int view_y) { ...@@ -251,21 +257,12 @@ void AwRenderViewExt::OnDoHitTest(int view_x, int view_y) {
} }
void AwRenderViewExt::OnEnableCapturePictureCallback(bool enable) { void AwRenderViewExt::OnEnableCapturePictureCallback(bool enable) {
// TODO(leandrogracia): enable once the feature is available in RenderView. capture_picture_enabled_ = enable;
//render_view()->SetCapturePictureCallback(enable ?
// base::Bind(&AwRenderViewExt::OnPictureUpdate, AsWeakPtr()) :
// content::RenderView::CapturePictureCallback());
}
void AwRenderViewExt::OnPictureUpdate(skia::RefPtr<SkPicture> picture) {
RendererPictureMap::GetInstance()->SetRendererPicture(routing_id(), picture);
Send(new AwViewHostMsg_PictureUpdated(routing_id()));
} }
void AwRenderViewExt::OnCapturePictureSync() { void AwRenderViewExt::OnCapturePictureSync() {
// TODO(leandrogracia): enable once the feature is available in RenderView. RendererPictureMap::GetInstance()->SetRendererPicture(
//RendererPictureMap::GetInstance()->SetRendererPicture( routing_id(), render_view()->CapturePicture());
// routing_id(), render_view()->CapturePicture());
} }
} // namespace android_webview } // namespace android_webview
...@@ -9,9 +9,7 @@ ...@@ -9,9 +9,7 @@
#include "base/compiler_specific.h" #include "base/compiler_specific.h"
#include "base/memory/weak_ptr.h" #include "base/memory/weak_ptr.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 {
...@@ -42,6 +40,7 @@ class AwRenderViewExt : public content::RenderViewObserver, ...@@ -42,6 +40,7 @@ class AwRenderViewExt : public content::RenderViewObserver,
virtual void DidCommitProvisionalLoad(WebKit::WebFrame* frame, virtual void DidCommitProvisionalLoad(WebKit::WebFrame* frame,
bool is_new_navigation) OVERRIDE; bool is_new_navigation) OVERRIDE;
virtual void FocusedNodeChanged(const WebKit::WebNode& node) OVERRIDE; virtual void FocusedNodeChanged(const WebKit::WebNode& node) OVERRIDE;
virtual void DidCommitCompositorFrame() OVERRIDE;
void OnDocumentHasImagesRequest(int id); void OnDocumentHasImagesRequest(int id);
...@@ -49,8 +48,6 @@ class AwRenderViewExt : public content::RenderViewObserver, ...@@ -49,8 +48,6 @@ class AwRenderViewExt : public content::RenderViewObserver,
void OnEnableCapturePictureCallback(bool enable); void OnEnableCapturePictureCallback(bool enable);
void OnPictureUpdate(skia::RefPtr<SkPicture> picture);
void OnCapturePictureSync(); void OnCapturePictureSync();
// WebKit::WebPermissionClient implementation. // WebKit::WebPermissionClient implementation.
...@@ -58,6 +55,8 @@ class AwRenderViewExt : public content::RenderViewObserver, ...@@ -58,6 +55,8 @@ class AwRenderViewExt : public content::RenderViewObserver,
bool enabledPerSettings, bool enabledPerSettings,
const WebKit::WebURL& imageURL) OVERRIDE; const WebKit::WebURL& imageURL) OVERRIDE;
bool capture_picture_enabled_;
DISALLOW_COPY_AND_ASSIGN(AwRenderViewExt); DISALLOW_COPY_AND_ASSIGN(AwRenderViewExt);
}; };
......
...@@ -9,10 +9,13 @@ ...@@ -9,10 +9,13 @@
#include "base/string16.h" #include "base/string16.h"
#include "content/common/content_export.h" #include "content/common/content_export.h"
#include "ipc/ipc_sender.h" #include "ipc/ipc_sender.h"
#include "skia/ext/refptr.h"
#include "third_party/WebKit/Source/WebKit/chromium/public/WebNavigationPolicy.h" #include "third_party/WebKit/Source/WebKit/chromium/public/WebNavigationPolicy.h"
#include "third_party/WebKit/Source/WebKit/chromium/public/WebPageVisibilityState.h" #include "third_party/WebKit/Source/WebKit/chromium/public/WebPageVisibilityState.h"
#include "ui/gfx/native_widget_types.h" #include "ui/gfx/native_widget_types.h"
class SkPicture;
namespace webkit_glue { namespace webkit_glue {
struct WebPreferences; struct WebPreferences;
} }
...@@ -163,6 +166,15 @@ class CONTENT_EXPORT RenderView : public IPC::Sender { ...@@ -163,6 +166,15 @@ class CONTENT_EXPORT RenderView : public IPC::Sender {
// Returns a collection of security info about |frame|. // Returns a collection of security info about |frame|.
virtual SSLStatus GetSSLStatusOfFrame(WebKit::WebFrame* frame) const = 0; virtual SSLStatus GetSSLStatusOfFrame(WebKit::WebFrame* frame) const = 0;
#if defined(OS_ANDROID)
// Returns a SkPicture with the full contents of the current frame as part of
// the legacy Android WebView capture picture API. As it involves playing back
// all the drawing commands of the current frame it can have an important
// performance impact and should not be used for other purposes.
// Requires enabling the impl-side painting feature in the compositor.
virtual skia::RefPtr<SkPicture> CapturePicture() = 0;
#endif
protected: protected:
virtual ~RenderView() {} virtual ~RenderView() {}
}; };
......
...@@ -85,6 +85,7 @@ class CONTENT_EXPORT RenderViewObserver : public IPC::Listener, ...@@ -85,6 +85,7 @@ class CONTENT_EXPORT RenderViewObserver : public IPC::Listener,
virtual void DidRequestShowContextMenu( virtual void DidRequestShowContextMenu(
WebKit::WebFrame* frame, WebKit::WebFrame* frame,
const WebKit::WebContextMenuData& data) {} const WebKit::WebContextMenuData& data) {}
virtual void DidCommitCompositorFrame() {}
// These match the RenderView methods. // These match the RenderView methods.
virtual void DidHandleMouseEvent(const WebKit::WebMouseEvent& event) {} virtual void DidHandleMouseEvent(const WebKit::WebMouseEvent& event) {}
......
...@@ -359,9 +359,7 @@ void RenderWidgetCompositor::willCommit() { ...@@ -359,9 +359,7 @@ void RenderWidgetCompositor::willCommit() {
} }
void RenderWidgetCompositor::didCommit() { void RenderWidgetCompositor::didCommit() {
// TODO(jamesr): There is no chromium-side implementation of this first call, widget_->DidCommitCompositorFrame();
// remove if it's not needed.
widget_->didCommitCompositorFrame();
widget_->didBecomeReadyForAdditionalInput(); widget_->didBecomeReadyForAdditionalInput();
} }
......
...@@ -27,6 +27,7 @@ ...@@ -27,6 +27,7 @@
#include "base/sys_string_conversions.h" #include "base/sys_string_conversions.h"
#include "base/time.h" #include "base/time.h"
#include "base/utf_string_conversions.h" #include "base/utf_string_conversions.h"
#include "cc/layer_tree_host.h"
#include "cc/output_surface.h" #include "cc/output_surface.h"
#include "cc/switches.h" #include "cc/switches.h"
#include "content/common/appcache/appcache_dispatcher.h" #include "content/common/appcache/appcache_dispatcher.h"
...@@ -181,6 +182,7 @@ ...@@ -181,6 +182,7 @@
#include "third_party/WebKit/Source/WebKit/chromium/public/WebWindowFeatures.h" #include "third_party/WebKit/Source/WebKit/chromium/public/WebWindowFeatures.h"
#include "third_party/WebKit/Source/WebKit/chromium/public/default/WebRenderTheme.h" #include "third_party/WebKit/Source/WebKit/chromium/public/default/WebRenderTheme.h"
#include "third_party/skia/include/core/SkBitmap.h" #include "third_party/skia/include/core/SkBitmap.h"
#include "third_party/skia/include/core/SkPicture.h"
#include "ui/base/ui_base_switches.h" #include "ui/base/ui_base_switches.h"
#include "ui/gfx/native_widget_types.h" #include "ui/gfx/native_widget_types.h"
#include "ui/gfx/point.h" #include "ui/gfx/point.h"
...@@ -6616,6 +6618,11 @@ bool RenderViewImpl::didTapMultipleTargets( ...@@ -6616,6 +6618,11 @@ bool RenderViewImpl::didTapMultipleTargets(
return true; return true;
} }
skia::RefPtr<SkPicture> RenderViewImpl::CapturePicture() {
return compositor_ ? compositor_->layer_tree_host()->capturePicture() :
skia::RefPtr<SkPicture>();
}
#endif #endif
void RenderViewImpl::OnReleaseDisambiguationPopupDIB( void RenderViewImpl::OnReleaseDisambiguationPopupDIB(
...@@ -6624,4 +6631,9 @@ void RenderViewImpl::OnReleaseDisambiguationPopupDIB( ...@@ -6624,4 +6631,9 @@ void RenderViewImpl::OnReleaseDisambiguationPopupDIB(
RenderProcess::current()->ReleaseTransportDIB(dib); RenderProcess::current()->ReleaseTransportDIB(dib);
} }
void RenderViewImpl::DidCommitCompositorFrame() {
RenderWidget::DidCommitCompositorFrame();
FOR_EACH_OBSERVER(RenderViewObserver, observers_, DidCommitCompositorFrame());
}
} // namespace content } // namespace content
...@@ -728,6 +728,9 @@ class CONTENT_EXPORT RenderViewImpl ...@@ -728,6 +728,9 @@ class CONTENT_EXPORT RenderViewImpl
const std::string& value) OVERRIDE; const std::string& value) OVERRIDE;
virtual void ClearEditCommands() OVERRIDE; virtual void ClearEditCommands() OVERRIDE;
virtual SSLStatus GetSSLStatusOfFrame(WebKit::WebFrame* frame) const OVERRIDE; virtual SSLStatus GetSSLStatusOfFrame(WebKit::WebFrame* frame) const OVERRIDE;
#if defined(OS_ANDROID)
virtual skia::RefPtr<SkPicture> CapturePicture() OVERRIDE;
#endif
// webkit_glue::WebPluginPageDelegate implementation ------------------------- // webkit_glue::WebPluginPageDelegate implementation -------------------------
...@@ -802,6 +805,7 @@ class CONTENT_EXPORT RenderViewImpl ...@@ -802,6 +805,7 @@ class CONTENT_EXPORT RenderViewImpl
virtual void GetCompositionCharacterBounds( virtual void GetCompositionCharacterBounds(
std::vector<gfx::Rect>* character_bounds) OVERRIDE; std::vector<gfx::Rect>* character_bounds) OVERRIDE;
virtual bool CanComposeInline() OVERRIDE; virtual bool CanComposeInline() OVERRIDE;
virtual void DidCommitCompositorFrame() OVERRIDE;
protected: protected:
explicit RenderViewImpl(RenderViewImplParams* params); explicit RenderViewImpl(RenderViewImplParams* params);
......
...@@ -1371,6 +1371,9 @@ void RenderWidget::didBecomeReadyForAdditionalInput() { ...@@ -1371,6 +1371,9 @@ void RenderWidget::didBecomeReadyForAdditionalInput() {
Send(pending_input_event_ack_.release()); Send(pending_input_event_ack_.release());
} }
void RenderWidget::DidCommitCompositorFrame() {
}
void RenderWidget::didCommitAndDrawCompositorFrame() { void RenderWidget::didCommitAndDrawCompositorFrame() {
TRACE_EVENT0("gpu", "RenderWidget::didCommitAndDrawCompositorFrame"); TRACE_EVENT0("gpu", "RenderWidget::didCommitAndDrawCompositorFrame");
// Accelerated FPS tick for performance tests. See throughput_tests.cc. // Accelerated FPS tick for performance tests. See throughput_tests.cc.
......
...@@ -190,6 +190,9 @@ class CONTENT_EXPORT RenderWidget ...@@ -190,6 +190,9 @@ class CONTENT_EXPORT RenderWidget
// Close the underlying WebWidget. // Close the underlying WebWidget.
virtual void Close(); virtual void Close();
// Notifies about a compositor frame commit operation having finished.
virtual void DidCommitCompositorFrame();
float filtered_time_per_frame() const { float filtered_time_per_frame() const {
return filtered_time_per_frame_; return filtered_time_per_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