summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorbrettw@chromium.org <brettw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-11-29 18:53:29 +0000
committerbrettw@chromium.org <brettw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-11-29 18:53:29 +0000
commit08e65c1a5b8187886e3c5d8c37e8b17c19d0b57e (patch)
tree67fc51a28fb4bc9c8f686d97f5acbff34b479cf3
parent895a8472bdc74bcaa0c32609f68c6570dedba03e (diff)
downloadchromium_src-08e65c1a5b8187886e3c5d8c37e8b17c19d0b57e.zip
chromium_src-08e65c1a5b8187886e3c5d8c37e8b17c19d0b57e.tar.gz
chromium_src-08e65c1a5b8187886e3c5d8c37e8b17c19d0b57e.tar.bz2
Migrate Graphics2D to new design, as part of the whole Pepper resource redesign.
New design provides higher performance and involves writing much less code. See the pepper implementation doc for detail. http://www.chromium.org/developers/design-documents/pepper-plugin-implementation TODO: Inline impl to PepperGraphics2DHost Original review URL: https://codereview.chromium.org/11053003/ Patch by Victor Hsieh R = brettw, Cris Neckar Review URL: https://codereview.chromium.org/11414171 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@170225 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--chrome/test/ppapi/ppapi_browsertest.cc1
-rw-r--r--content/content_renderer.gypi2
-rw-r--r--content/public/renderer/renderer_ppapi_host.h10
-rw-r--r--content/renderer/pepper/content_renderer_pepper_host_factory.cc12
-rw-r--r--content/renderer/pepper/mock_renderer_ppapi_host.cc11
-rw-r--r--content/renderer/pepper/mock_renderer_ppapi_host.h3
-rw-r--r--content/renderer/pepper/pepper_graphics_2d_host.cc213
-rw-r--r--content/renderer/pepper/pepper_graphics_2d_host.h99
-rw-r--r--content/renderer/pepper/pepper_in_process_resource_creation.cc10
-rw-r--r--content/renderer/pepper/pepper_in_process_resource_creation.h4
-rw-r--r--content/renderer/pepper/pepper_plugin_delegate_impl.cc9
-rw-r--r--content/renderer/pepper/pepper_plugin_delegate_impl.h3
-rw-r--r--content/renderer/pepper/renderer_ppapi_host_impl.cc21
-rw-r--r--content/renderer/pepper/renderer_ppapi_host_impl.h7
-rw-r--r--ppapi/cpp/graphics_2d.cc22
-rw-r--r--ppapi/host/ppapi_host.cc4
-rw-r--r--ppapi/host/ppapi_host.h6
-rw-r--r--ppapi/host/resource_host.h2
-rw-r--r--ppapi/ppapi_proxy.gypi4
-rw-r--r--ppapi/proxy/graphics_2d_resource.cc152
-rw-r--r--ppapi/proxy/graphics_2d_resource.h63
-rw-r--r--ppapi/proxy/interface_list.cc1
-rw-r--r--ppapi/proxy/ppapi_messages.h62
-rw-r--r--ppapi/proxy/ppb_graphics_2d_proxy.cc314
-rw-r--r--ppapi/proxy/ppb_graphics_2d_proxy.h77
-rw-r--r--ppapi/proxy/ppb_image_data_proxy.cc4
-rw-r--r--ppapi/proxy/ppb_image_data_proxy.h3
-rw-r--r--ppapi/proxy/ppb_instance_proxy.cc33
-rw-r--r--ppapi/proxy/ppb_instance_proxy.h2
-rw-r--r--ppapi/proxy/ppb_testing_proxy.cc17
-rw-r--r--ppapi/proxy/resource_creation_proxy.cc6
-rw-r--r--ppapi/tests/test_graphics_2d.cc73
-rw-r--r--ppapi/tests/test_graphics_2d.h5
-rw-r--r--ppapi/thunk/interfaces_ppb_public_stable.h3
-rw-r--r--ppapi/thunk/ppb_graphics_2d_api.h11
-rw-r--r--ppapi/thunk/ppb_image_data_api.h5
-rw-r--r--webkit/plugins/ppapi/mock_plugin_delegate.cc7
-rw-r--r--webkit/plugins/ppapi/mock_plugin_delegate.h2
-rw-r--r--webkit/plugins/ppapi/plugin_delegate.h34
-rw-r--r--webkit/plugins/ppapi/plugin_module.cc3
-rw-r--r--webkit/plugins/ppapi/ppapi_plugin_instance.cc53
-rw-r--r--webkit/plugins/ppapi/ppapi_plugin_instance.h8
-rw-r--r--webkit/plugins/ppapi/ppb_graphics_2d_impl.h22
-rw-r--r--webkit/plugins/ppapi/ppb_graphics_2d_impl_unittest.cc12
-rw-r--r--webkit/plugins/ppapi/ppb_image_data_impl.cc4
-rw-r--r--webkit/plugins/ppapi/ppb_image_data_impl.h1
-rw-r--r--webkit/plugins/ppapi/resource_creation_impl.cc8
-rw-r--r--webkit/plugins/ppapi/resource_creation_impl.h3
48 files changed, 899 insertions, 532 deletions
diff --git a/chrome/test/ppapi/ppapi_browsertest.cc b/chrome/test/ppapi/ppapi_browsertest.cc
index 94d604c..5596347 100644
--- a/chrome/test/ppapi/ppapi_browsertest.cc
+++ b/chrome/test/ppapi/ppapi_browsertest.cc
@@ -259,6 +259,7 @@ TEST_PPAPI_NACL_VIA_HTTP(Graphics2D_Scroll)
TEST_PPAPI_NACL_VIA_HTTP(Graphics2D_Replace)
TEST_PPAPI_NACL_VIA_HTTP(Graphics2D_Flush)
TEST_PPAPI_NACL_VIA_HTTP(Graphics2D_FlushOffscreenUpdate)
+TEST_PPAPI_NACL_VIA_HTTP(Graphics2D_BindNull)
#if defined(OS_WIN) && !defined(USE_AURA)
// These tests fail with the test compositor which is what's used by default for
diff --git a/content/content_renderer.gypi b/content/content_renderer.gypi
index 2592aaa..81d31ba 100644
--- a/content/content_renderer.gypi
+++ b/content/content_renderer.gypi
@@ -178,6 +178,8 @@
'renderer/pepper/pepper_flash_clipboard_host.h',
'renderer/pepper/pepper_flash_host.cc',
'renderer/pepper/pepper_flash_host.h',
+ 'renderer/pepper/pepper_graphics_2d_host.cc',
+ 'renderer/pepper/pepper_graphics_2d_host.h',
'renderer/pepper/pepper_hung_plugin_filter.cc',
'renderer/pepper/pepper_hung_plugin_filter.h',
'renderer/pepper/pepper_in_process_resource_creation.cc',
diff --git a/content/public/renderer/renderer_ppapi_host.h b/content/public/renderer/renderer_ppapi_host.h
index c41757b..3cd550c 100644
--- a/content/public/renderer/renderer_ppapi_host.h
+++ b/content/public/renderer/renderer_ppapi_host.h
@@ -10,6 +10,7 @@
#include "content/common/content_export.h"
#include "ipc/ipc_platform_file.h"
#include "ppapi/c/pp_instance.h"
+#include "webkit/plugins/ppapi/plugin_delegate.h"
class FilePath;
@@ -89,6 +90,11 @@ class RendererPpapiHost {
virtual WebKit::WebPluginContainer* GetContainerForInstance(
PP_Instance instance) const = 0;
+ // Returns the PlatformGraphics2D for the given plugin resource, or NULL if
+ // the resource is invalid.
+ virtual webkit::ppapi::PluginDelegate::PlatformGraphics2D*
+ GetPlatformGraphics2D(PP_Resource resource) = 0;
+
// Returns true if the given instance is considered to be currently
// processing a user gesture or the plugin module has the "override user
// gesture" flag set (in which case it can always do things normally
@@ -119,6 +125,9 @@ class RendererPpapiHost {
base::PlatformFile handle,
bool should_close_source) = 0;
+ // Returns true if the plugin is running in process.
+ virtual bool IsRunningInProcess() const = 0;
+
protected:
virtual ~RendererPpapiHost() {}
};
@@ -126,4 +135,3 @@ class RendererPpapiHost {
} // namespace content
#endif // CONTENT_PUBLIC_RENDERER_RENDERER_PPAPI_HOST_H_
-
diff --git a/content/renderer/pepper/content_renderer_pepper_host_factory.cc b/content/renderer/pepper/content_renderer_pepper_host_factory.cc
index db03a34..288f70a 100644
--- a/content/renderer/pepper/content_renderer_pepper_host_factory.cc
+++ b/content/renderer/pepper/content_renderer_pepper_host_factory.cc
@@ -9,6 +9,7 @@
#include "content/renderer/pepper/pepper_file_chooser_host.h"
#include "content/renderer/pepper/pepper_flash_clipboard_host.h"
#include "content/renderer/pepper/pepper_flash_host.h"
+#include "content/renderer/pepper/pepper_graphics_2d_host.h"
#include "content/renderer/pepper/pepper_video_capture_host.h"
#include "content/renderer/pepper/pepper_websocket_host.h"
#include "content/renderer/pepper/renderer_ppapi_host_impl.h"
@@ -54,6 +55,17 @@ scoped_ptr<ResourceHost> ContentRendererPepperHostFactory::CreateResourceHost(
case PpapiHostMsg_FileChooser_Create::ID:
return scoped_ptr<ResourceHost>(new PepperFileChooserHost(
host_, instance, params.pp_resource()));
+ case PpapiHostMsg_Graphics2D_Create::ID: {
+ PpapiHostMsg_Graphics2D_Create::Schema::Param msg_params;
+ if (!PpapiHostMsg_Graphics2D_Create::Read(&message, &msg_params)) {
+ NOTREACHED();
+ return scoped_ptr<ResourceHost>();
+ }
+ return scoped_ptr<ResourceHost>(
+ PepperGraphics2DHost::Create(host_, instance, params.pp_resource(),
+ msg_params.a /* PP_Size */,
+ msg_params.b /* PP_Bool */));
+ }
case PpapiHostMsg_VideoCapture_Create::ID: {
PepperVideoCaptureHost* host = new PepperVideoCaptureHost(
host_, instance, params.pp_resource());
diff --git a/content/renderer/pepper/mock_renderer_ppapi_host.cc b/content/renderer/pepper/mock_renderer_ppapi_host.cc
index 2d21b21..68aa8c8 100644
--- a/content/renderer/pepper/mock_renderer_ppapi_host.cc
+++ b/content/renderer/pepper/mock_renderer_ppapi_host.cc
@@ -47,6 +47,12 @@ WebKit::WebPluginContainer* MockRendererPpapiHost::GetContainerForInstance(
return NULL;
}
+webkit::ppapi::PluginDelegate::PlatformGraphics2D*
+MockRendererPpapiHost::GetPlatformGraphics2D(PP_Resource resource) {
+ NOTIMPLEMENTED();
+ return NULL;
+}
+
bool MockRendererPpapiHost::HasUserGesture(PP_Instance instance) const {
return has_user_gesture_;
}
@@ -68,4 +74,9 @@ IPC::PlatformFileForTransit MockRendererPpapiHost::ShareHandleWithRemote(
return IPC::InvalidPlatformFileForTransit();
}
+bool MockRendererPpapiHost::IsRunningInProcess() const {
+ NOTIMPLEMENTED();
+ return false;
+}
+
} // namespace content
diff --git a/content/renderer/pepper/mock_renderer_ppapi_host.h b/content/renderer/pepper/mock_renderer_ppapi_host.h
index 5cbf6ef..47f5861 100644
--- a/content/renderer/pepper/mock_renderer_ppapi_host.h
+++ b/content/renderer/pepper/mock_renderer_ppapi_host.h
@@ -45,6 +45,8 @@ class MockRendererPpapiHost : public RendererPpapiHost {
PP_Instance instance) const OVERRIDE;
virtual WebKit::WebPluginContainer* GetContainerForInstance(
PP_Instance instance) const OVERRIDE;
+ virtual webkit::ppapi::PluginDelegate::PlatformGraphics2D*
+ GetPlatformGraphics2D(PP_Resource resource) OVERRIDE;
virtual bool HasUserGesture(PP_Instance instance) const OVERRIDE;
virtual int GetRoutingIDForWidget(PP_Instance instance) const OVERRIDE;
virtual gfx::Point PluginPointToRenderView(
@@ -53,6 +55,7 @@ class MockRendererPpapiHost : public RendererPpapiHost {
virtual IPC::PlatformFileForTransit ShareHandleWithRemote(
base::PlatformFile handle,
bool should_close_source) OVERRIDE;
+ virtual bool IsRunningInProcess() const OVERRIDE;
private:
ppapi::proxy::ResourceMessageTestSink sink_;
diff --git a/content/renderer/pepper/pepper_graphics_2d_host.cc b/content/renderer/pepper/pepper_graphics_2d_host.cc
new file mode 100644
index 0000000..2c04d76
--- /dev/null
+++ b/content/renderer/pepper/pepper_graphics_2d_host.cc
@@ -0,0 +1,213 @@
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "content/renderer/pepper/pepper_graphics_2d_host.h"
+
+#include "content/public/renderer/renderer_ppapi_host.h"
+#include "ppapi/c/pp_bool.h"
+#include "ppapi/host/dispatch_host_message.h"
+#include "ppapi/host/host_message_context.h"
+#include "ppapi/host/ppapi_host.h"
+#include "ppapi/proxy/ppapi_messages.h"
+#include "ppapi/shared_impl/api_id.h"
+#include "ppapi/thunk/enter.h"
+#include "webkit/plugins/ppapi/ppapi_plugin_instance.h"
+#include "webkit/plugins/ppapi/ppb_graphics_2d_impl.h" // TODO: merge to here
+
+namespace content {
+
+// static
+PepperGraphics2DHost* PepperGraphics2DHost::Create(RendererPpapiHost* host,
+ PP_Instance instance,
+ PP_Resource resource,
+ const PP_Size& size,
+ PP_Bool is_always_opaque) {
+ PepperGraphics2DHost* resource_host =
+ new PepperGraphics2DHost(host, instance, resource);
+ if (!resource_host->graphics_2d_->Init(size.width, size.height,
+ PP_ToBool(is_always_opaque))) {
+ delete resource_host;
+ return NULL;
+ }
+ return resource_host;
+}
+
+PepperGraphics2DHost::PepperGraphics2DHost(RendererPpapiHost* host,
+ PP_Instance instance,
+ PP_Resource resource)
+ : ResourceHost(host->GetPpapiHost(), instance, resource),
+ graphics_2d_(new webkit::ppapi::PPB_Graphics2D_Impl(instance)),
+ is_running_in_process_(host->IsRunningInProcess()) {
+}
+
+PepperGraphics2DHost::~PepperGraphics2DHost() {
+ // Unbind from the instance when destoryed.
+ PP_Instance instance = graphics_2d_->pp_instance();
+ ppapi::thunk::EnterInstanceNoLock enter(instance);
+ if (enter.succeeded())
+ enter.functions()->BindGraphics(instance, 0);
+}
+
+int32_t PepperGraphics2DHost::OnResourceMessageReceived(
+ const IPC::Message& msg,
+ ppapi::host::HostMessageContext* context) {
+ IPC_BEGIN_MESSAGE_MAP(PepperGraphics2DHost, msg)
+#if !defined(OS_NACL)
+ PPAPI_DISPATCH_HOST_RESOURCE_CALL(
+ PpapiHostMsg_Graphics2D_PaintImageData,
+ OnHostMsgPaintImageData)
+ PPAPI_DISPATCH_HOST_RESOURCE_CALL(
+ PpapiHostMsg_Graphics2D_Scroll,
+ OnHostMsgScroll)
+ PPAPI_DISPATCH_HOST_RESOURCE_CALL(
+ PpapiHostMsg_Graphics2D_ReplaceContents,
+ OnHostMsgReplaceContents)
+ PPAPI_DISPATCH_HOST_RESOURCE_CALL_0(
+ PpapiHostMsg_Graphics2D_Flush,
+ OnHostMsgFlush)
+ PPAPI_DISPATCH_HOST_RESOURCE_CALL(
+ PpapiHostMsg_Graphics2D_Dev_SetScale,
+ OnHostMsgSetScale)
+ PPAPI_DISPATCH_HOST_RESOURCE_CALL(
+ PpapiHostMsg_Graphics2D_ReadImageData,
+ OnHostMsgReadImageData)
+#endif
+ IPC_END_MESSAGE_MAP()
+ return PP_ERROR_FAILED;
+}
+
+bool PepperGraphics2DHost::ReadImageData(PP_Resource image,
+ const PP_Point* top_left) {
+ return graphics_2d_->ReadImageData(image, top_left);
+}
+
+bool PepperGraphics2DHost::BindToInstance(
+ webkit::ppapi::PluginInstance* new_instance) {
+ if (new_instance &&
+ new_instance->pp_instance() != graphics_2d_->pp_instance())
+ return false; // Can't bind other instance's contexts.
+ return graphics_2d_->BindToInstance(new_instance);
+}
+
+void PepperGraphics2DHost::Paint(WebKit::WebCanvas* canvas,
+ const gfx::Rect& plugin_rect,
+ const gfx::Rect& paint_rect) {
+ graphics_2d_->Paint(canvas, plugin_rect, paint_rect);
+}
+
+void PepperGraphics2DHost::ViewWillInitiatePaint() {
+ graphics_2d_->ViewWillInitiatePaint();
+}
+
+void PepperGraphics2DHost::ViewInitiatedPaint() {
+ graphics_2d_->ViewInitiatedPaint();
+}
+
+void PepperGraphics2DHost::ViewFlushedPaint() {
+ graphics_2d_->ViewFlushedPaint();
+}
+
+void PepperGraphics2DHost::SetScale(float scale) {
+ graphics_2d_->scale_ = scale;
+}
+
+float PepperGraphics2DHost::GetScale() const {
+ return graphics_2d_->scale_;
+}
+
+bool PepperGraphics2DHost::IsAlwaysOpaque() const {
+ return graphics_2d_->is_always_opaque_;
+}
+
+webkit::ppapi::PPB_ImageData_Impl* PepperGraphics2DHost::ImageData() {
+ return graphics_2d_->image_data_.get();
+}
+
+bool PepperGraphics2DHost::IsGraphics2DHost() const {
+ return true;
+}
+
+#if !defined(OS_NACL)
+int32_t PepperGraphics2DHost::OnHostMsgPaintImageData(
+ ppapi::host::HostMessageContext* context,
+ const ppapi::HostResource& image_data,
+ const PP_Point& top_left,
+ bool src_rect_specified,
+ const PP_Rect& src_rect) {
+ graphics_2d_->PaintImageData(image_data.host_resource(), &top_left,
+ src_rect_specified ? &src_rect : NULL);
+ return PP_OK;
+}
+
+int32_t PepperGraphics2DHost::OnHostMsgScroll(
+ ppapi::host::HostMessageContext* context,
+ bool clip_specified,
+ const PP_Rect& clip,
+ const PP_Point& amount) {
+ graphics_2d_->Scroll(clip_specified ? &clip : NULL, &amount);
+ return PP_OK;
+}
+
+int32_t PepperGraphics2DHost::OnHostMsgReplaceContents(
+ ppapi::host::HostMessageContext* context,
+ const ppapi::HostResource& image_data) {
+ graphics_2d_->ReplaceContents(image_data.host_resource());
+ return PP_OK;
+}
+
+int32_t PepperGraphics2DHost::OnHostMsgFlush(
+ ppapi::host::HostMessageContext* context) {
+ PP_Resource old_image_data = 0;
+ flush_reply_context_ = context->MakeReplyMessageContext();
+ // TODO: when merge PP_Graphics2D_Impl, we won't need this tracked callback.
+ scoped_refptr<ppapi::TrackedCallback> callback(new ppapi::TrackedCallback(
+ graphics_2d_.get(),
+ PP_MakeCompletionCallback(&PepperGraphics2DHost::SendFlushACKToPlugin,
+ AsWeakPtr())));
+ if (is_running_in_process_)
+ return graphics_2d_->Flush(callback, NULL);
+
+ // Reuse image data when running out of process.
+ int32_t result = graphics_2d_->Flush(callback, &old_image_data);
+
+ if (old_image_data) {
+ // If the Graphics2D has an old image data it's not using any more, send
+ // it back to the plugin for possible re-use. See ppb_image_data_proxy.cc
+ // for a description how this process works.
+ ppapi::HostResource old_image_data_host_resource;
+ old_image_data_host_resource.SetHostResource(pp_instance(),
+ old_image_data);
+ host()->Send(new PpapiMsg_PPBImageData_NotifyUnusedImageData(
+ ppapi::API_ID_PPB_IMAGE_DATA, old_image_data_host_resource));
+ }
+
+ return result;
+}
+
+int32_t PepperGraphics2DHost::OnHostMsgSetScale(
+ ppapi::host::HostMessageContext* context,
+ float scale) {
+ return graphics_2d_->SetScale(scale) ? PP_OK : PP_ERROR_BADARGUMENT;
+}
+
+int32_t PepperGraphics2DHost::OnHostMsgReadImageData(
+ ppapi::host::HostMessageContext* context,
+ PP_Resource image,
+ const PP_Point& top_left) {
+ context->reply_msg = PpapiPluginMsg_Graphics2D_ReadImageDataAck();
+ return ReadImageData(image, &top_left) ? PP_OK : PP_ERROR_FAILED;
+}
+
+// static
+void PepperGraphics2DHost::SendFlushACKToPlugin(void* data,
+ int32_t pp_error) {
+ if (!data || pp_error != PP_OK)
+ return;
+ PepperGraphics2DHost* self = (PepperGraphics2DHost*) data;
+ self->host()->SendReply(self->flush_reply_context_,
+ PpapiPluginMsg_Graphics2D_FlushAck());
+}
+#endif // !defined(OS_NACL)
+
+} // namespace content
diff --git a/content/renderer/pepper/pepper_graphics_2d_host.h b/content/renderer/pepper/pepper_graphics_2d_host.h
new file mode 100644
index 0000000..3496b22
--- /dev/null
+++ b/content/renderer/pepper/pepper_graphics_2d_host.h
@@ -0,0 +1,99 @@
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef CONTENT_RENDERER_PEPPER_PEPPER_GRAPHICS_2D_HOST_H_
+#define CONTENT_RENDERER_PEPPER_PEPPER_GRAPHICS_2D_HOST_H_
+
+#include "base/compiler_specific.h"
+#include "base/memory/weak_ptr.h"
+#include "content/common/content_export.h"
+#include "ppapi/c/ppb_graphics_2d.h"
+#include "ppapi/host/host_message_context.h"
+#include "ppapi/host/resource_host.h"
+#include "webkit/plugins/ppapi/plugin_delegate.h"
+#include "webkit/plugins/ppapi/ppb_graphics_2d_impl.h"
+
+namespace webkit {
+namespace ppapi {
+class PPB_ImageData_Impl;
+class PluginInstance;
+}
+}
+
+namespace content {
+
+class RendererPpapiHost;
+
+class CONTENT_EXPORT PepperGraphics2DHost
+ : public ppapi::host::ResourceHost,
+ public webkit::ppapi::PluginDelegate::PlatformGraphics2D,
+ public base::SupportsWeakPtr<PepperGraphics2DHost> {
+ public:
+ static PepperGraphics2DHost* Create(RendererPpapiHost* host,
+ PP_Instance instance,
+ PP_Resource resource,
+ const PP_Size& size,
+ PP_Bool is_always_opaque);
+
+ virtual ~PepperGraphics2DHost();
+
+ virtual int32_t OnResourceMessageReceived(
+ const IPC::Message& msg,
+ ppapi::host::HostMessageContext* context) OVERRIDE;
+
+ // PlatformGraphics2D overrides.
+ virtual bool ReadImageData(PP_Resource image,
+ const PP_Point* top_left) OVERRIDE;
+ virtual bool BindToInstance(
+ webkit::ppapi::PluginInstance* new_instance) OVERRIDE;
+ virtual void Paint(WebKit::WebCanvas* canvas,
+ const gfx::Rect& plugin_rect,
+ const gfx::Rect& paint_rect) OVERRIDE;
+ virtual void ViewWillInitiatePaint() OVERRIDE;
+ virtual void ViewInitiatedPaint() OVERRIDE;
+ virtual void ViewFlushedPaint() OVERRIDE;
+ virtual void SetScale(float scale) OVERRIDE;
+ virtual float GetScale() const OVERRIDE;
+ virtual bool IsAlwaysOpaque() const OVERRIDE;
+ virtual webkit::ppapi::PPB_ImageData_Impl* ImageData() OVERRIDE;
+ virtual bool IsGraphics2DHost() const OVERRIDE;
+
+ private:
+ PepperGraphics2DHost(RendererPpapiHost* host,
+ PP_Instance instance,
+ PP_Resource resource);
+
+ int32_t OnHostMsgPaintImageData(ppapi::host::HostMessageContext* context,
+ const ppapi::HostResource& image_data,
+ const PP_Point& top_left,
+ bool src_rect_specified,
+ const PP_Rect& src_rect);
+ int32_t OnHostMsgScroll(ppapi::host::HostMessageContext* context,
+ bool clip_specified,
+ const PP_Rect& clip,
+ const PP_Point& amount);
+ int32_t OnHostMsgReplaceContents(ppapi::host::HostMessageContext* context,
+ const ppapi::HostResource& image_data);
+ int32_t OnHostMsgFlush(ppapi::host::HostMessageContext* context);
+ int32_t OnHostMsgSetScale(ppapi::host::HostMessageContext* context,
+ float scale);
+ int32_t OnHostMsgReadImageData(ppapi::host::HostMessageContext* context,
+ PP_Resource image,
+ const PP_Point& top_left);
+
+ static void SendFlushACKToPlugin(void* data, int32_t pp_error);
+
+ // TODO: merge this delegation into this host class.
+ scoped_refptr<webkit::ppapi::PPB_Graphics2D_Impl> graphics_2d_;
+
+ ppapi::host::ReplyMessageContext flush_reply_context_;
+
+ bool is_running_in_process_;
+
+ DISALLOW_COPY_AND_ASSIGN(PepperGraphics2DHost);
+};
+
+} // namespace content
+
+#endif // CONTENT_RENDERER_PEPPER_PEPPER_GRAPHICS_2D_HOST_H_
diff --git a/content/renderer/pepper/pepper_in_process_resource_creation.cc b/content/renderer/pepper/pepper_in_process_resource_creation.cc
index 5fbd426..3d6d12b 100644
--- a/content/renderer/pepper/pepper_in_process_resource_creation.cc
+++ b/content/renderer/pepper/pepper_in_process_resource_creation.cc
@@ -15,6 +15,7 @@
#include "ppapi/host/ppapi_host.h"
#include "ppapi/proxy/browser_font_resource_trusted.h"
#include "ppapi/proxy/file_chooser_resource.h"
+#include "ppapi/proxy/graphics_2d_resource.h"
#include "ppapi/proxy/ppapi_messages.h"
#include "ppapi/proxy/printing_resource.h"
#include "ppapi/proxy/url_request_info_resource.h"
@@ -67,6 +68,15 @@ PP_Resource PepperInProcessResourceCreation::CreateFileChooser(
instance, mode, accept_types))->GetReference();
}
+PP_Resource PepperInProcessResourceCreation::CreateGraphics2D(
+ PP_Instance instance,
+ const PP_Size& size,
+ PP_Bool is_always_opaque) {
+ return (new ppapi::proxy::Graphics2DResource(
+ host_impl_->in_process_router()->GetPluginConnection(),
+ instance, size, is_always_opaque))->GetReference();
+}
+
PP_Resource PepperInProcessResourceCreation::CreatePrinting(
PP_Instance instance) {
return (new ppapi::proxy::PrintingResource(
diff --git a/content/renderer/pepper/pepper_in_process_resource_creation.h b/content/renderer/pepper/pepper_in_process_resource_creation.h
index e830221..8972d83 100644
--- a/content/renderer/pepper/pepper_in_process_resource_creation.h
+++ b/content/renderer/pepper/pepper_in_process_resource_creation.h
@@ -49,6 +49,10 @@ class PepperInProcessResourceCreation
PP_Instance instance,
PP_FileChooserMode_Dev mode,
const char* accept_types) OVERRIDE;
+ virtual PP_Resource CreateGraphics2D(
+ PP_Instance pp_instance,
+ const PP_Size& size,
+ PP_Bool is_always_opaque) OVERRIDE;
virtual PP_Resource CreatePrinting(
PP_Instance instance) OVERRIDE;
virtual PP_Resource CreateURLRequestInfo(
diff --git a/content/renderer/pepper/pepper_plugin_delegate_impl.cc b/content/renderer/pepper/pepper_plugin_delegate_impl.cc
index 0b7b1a5..827db5e 100644
--- a/content/renderer/pepper/pepper_plugin_delegate_impl.cc
+++ b/content/renderer/pepper/pepper_plugin_delegate_impl.cc
@@ -771,6 +771,15 @@ PepperPluginDelegateImpl::CreateImage2D(int width, int height) {
return PepperPlatformImage2DImpl::Create(width, height);
}
+webkit::ppapi::PluginDelegate::PlatformGraphics2D*
+PepperPluginDelegateImpl::GetGraphics2D(
+ webkit::ppapi::PluginInstance* instance,
+ PP_Resource resource) {
+ RendererPpapiHostImpl* host_impl = static_cast<RendererPpapiHostImpl*>(
+ instance->module()->GetEmbedderState());
+ return host_impl->GetPlatformGraphics2D(resource);
+}
+
webkit::ppapi::PluginDelegate::PlatformContext3D*
PepperPluginDelegateImpl::CreateContext3D() {
#ifdef ENABLE_GPU
diff --git a/content/renderer/pepper/pepper_plugin_delegate_impl.h b/content/renderer/pepper/pepper_plugin_delegate_impl.h
index cc69021..ee2e780 100644
--- a/content/renderer/pepper/pepper_plugin_delegate_impl.h
+++ b/content/renderer/pepper/pepper_plugin_delegate_impl.h
@@ -203,6 +203,9 @@ class PepperPluginDelegateImpl
uint32_t sample_count,
PlatformAudioInputClient* client) OVERRIDE;
virtual PlatformImage2D* CreateImage2D(int width, int height) OVERRIDE;
+ virtual PlatformGraphics2D* GetGraphics2D(
+ webkit::ppapi::PluginInstance* instance,
+ PP_Resource resource) OVERRIDE;
virtual PlatformContext3D* CreateContext3D() OVERRIDE;
virtual void ReparentContext(PlatformContext3D*) OVERRIDE;
virtual PlatformVideoCapture* CreateVideoCapture(
diff --git a/content/renderer/pepper/renderer_ppapi_host_impl.cc b/content/renderer/pepper/renderer_ppapi_host_impl.cc
index da42d85..fff104e 100644
--- a/content/renderer/pepper/renderer_ppapi_host_impl.cc
+++ b/content/renderer/pepper/renderer_ppapi_host_impl.cc
@@ -6,16 +6,19 @@
#include "base/file_path.h"
#include "base/logging.h"
+#include "content/renderer/pepper/pepper_graphics_2d_host.h"
#include "content/renderer/pepper/pepper_in_process_resource_creation.h"
#include "content/renderer/pepper/pepper_in_process_router.h"
#include "content/renderer/pepper/pepper_plugin_delegate_impl.h"
#include "content/renderer/render_view_impl.h"
#include "content/renderer/render_widget_fullscreen_pepper.h"
+#include "ppapi/host/ppapi_host.h"
#include "ppapi/proxy/host_dispatcher.h"
#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebRect.h"
#include "ui/gfx/point.h"
#include "webkit/plugins/ppapi/fullscreen_container.h"
#include "webkit/plugins/ppapi/host_globals.h"
+#include "webkit/plugins/ppapi/plugin_delegate.h"
#include "webkit/plugins/ppapi/plugin_module.h"
#include "webkit/plugins/ppapi/ppapi_plugin_instance.h"
@@ -64,6 +67,7 @@ RendererPpapiHostImpl::RendererPpapiHostImpl(
ppapi_host_->AddHostFactoryFilter(scoped_ptr<ppapi::host::HostFactory>(
new ContentRendererPepperHostFactory(this)));
dispatcher->AddFilter(ppapi_host_.get());
+ is_running_in_process_ = false;
}
// In-process constructor.
@@ -78,6 +82,7 @@ RendererPpapiHostImpl::RendererPpapiHostImpl(
in_process_router_->GetRendererToPluginSender(), permissions));
ppapi_host_->AddHostFactoryFilter(scoped_ptr<ppapi::host::HostFactory>(
new ContentRendererPepperHostFactory(this)));
+ is_running_in_process_ = true;
}
RendererPpapiHostImpl::~RendererPpapiHostImpl() {
@@ -150,6 +155,18 @@ RenderView* RendererPpapiHostImpl::GetRenderViewForInstance(
instance_object->delegate())->render_view();
}
+webkit::ppapi::PluginDelegate::PlatformGraphics2D*
+RendererPpapiHostImpl::GetPlatformGraphics2D(
+ PP_Resource resource) {
+ ppapi::host::ResourceHost* resource_host =
+ GetPpapiHost()->GetResourceHost(resource);
+ if (!resource_host || !resource_host->IsGraphics2DHost()) {
+ DLOG(ERROR) << "Resource is not Graphics2D";
+ return NULL;
+ }
+ return static_cast<PepperGraphics2DHost*>(resource_host);
+}
+
bool RendererPpapiHostImpl::IsValidInstance(
PP_Instance instance) const {
return !!GetAndValidateInstance(instance);
@@ -224,6 +241,10 @@ IPC::PlatformFileForTransit RendererPpapiHostImpl::ShareHandleWithRemote(
return dispatcher_->ShareHandleWithRemote(handle, should_close_source);
}
+bool RendererPpapiHostImpl::IsRunningInProcess() const {
+ return is_running_in_process_;
+}
+
PluginInstance* RendererPpapiHostImpl::GetAndValidateInstance(
PP_Instance pp_instance) const {
PluginInstance* instance = HostGlobals::Get()->GetInstance(pp_instance);
diff --git a/content/renderer/pepper/renderer_ppapi_host_impl.h b/content/renderer/pepper/renderer_ppapi_host_impl.h
index e3a4b60..4d3d0b4 100644
--- a/content/renderer/pepper/renderer_ppapi_host_impl.h
+++ b/content/renderer/pepper/renderer_ppapi_host_impl.h
@@ -10,6 +10,7 @@
#include "content/public/renderer/renderer_ppapi_host.h"
#include "content/renderer/pepper/content_renderer_pepper_host_factory.h"
#include "ppapi/host/ppapi_host.h"
+#include "webkit/plugins/ppapi/plugin_delegate.h"
#include "webkit/plugins/ppapi/plugin_module.h"
namespace IPC {
@@ -86,6 +87,8 @@ class RendererPpapiHostImpl
virtual bool IsValidInstance(PP_Instance instance) const OVERRIDE;
virtual webkit::ppapi::PluginInstance* GetPluginInstance(
PP_Instance instance) const OVERRIDE;
+ virtual webkit::ppapi::PluginDelegate::PlatformGraphics2D*
+ GetPlatformGraphics2D(PP_Resource resource) OVERRIDE;
virtual RenderView* GetRenderViewForInstance(
PP_Instance instance) const OVERRIDE;
virtual WebKit::WebPluginContainer* GetContainerForInstance(
@@ -98,6 +101,7 @@ class RendererPpapiHostImpl
virtual IPC::PlatformFileForTransit ShareHandleWithRemote(
base::PlatformFile handle,
bool should_close_source) OVERRIDE;
+ virtual bool IsRunningInProcess() const OVERRIDE;
private:
RendererPpapiHostImpl(webkit::ppapi::PluginModule* module,
@@ -124,6 +128,9 @@ class RendererPpapiHostImpl
// Null when running out-of-process.
scoped_ptr<PepperInProcessRouter> in_process_router_;
+ // Whether the plugin is running in process.
+ bool is_running_in_process_;
+
DISALLOW_COPY_AND_ASSIGN(RendererPpapiHostImpl);
};
diff --git a/ppapi/cpp/graphics_2d.cc b/ppapi/cpp/graphics_2d.cc
index 69bba9c..f4cd645 100644
--- a/ppapi/cpp/graphics_2d.cc
+++ b/ppapi/cpp/graphics_2d.cc
@@ -62,9 +62,9 @@ void Graphics2D::PaintImageData(const ImageData& image,
if (!has_interface<PPB_Graphics2D_1_0>())
return;
get_interface<PPB_Graphics2D_1_0>()->PaintImageData(pp_resource(),
- image.pp_resource(),
- &top_left.pp_point(),
- NULL);
+ image.pp_resource(),
+ &top_left.pp_point(),
+ NULL);
}
void Graphics2D::PaintImageData(const ImageData& image,
@@ -73,24 +73,24 @@ void Graphics2D::PaintImageData(const ImageData& image,
if (!has_interface<PPB_Graphics2D_1_0>())
return;
get_interface<PPB_Graphics2D_1_0>()->PaintImageData(pp_resource(),
- image.pp_resource(),
- &top_left.pp_point(),
- &src_rect.pp_rect());
+ image.pp_resource(),
+ &top_left.pp_point(),
+ &src_rect.pp_rect());
}
void Graphics2D::Scroll(const Rect& clip, const Point& amount) {
if (!has_interface<PPB_Graphics2D_1_0>())
return;
get_interface<PPB_Graphics2D_1_0>()->Scroll(pp_resource(),
- &clip.pp_rect(),
- &amount.pp_point());
+ &clip.pp_rect(),
+ &amount.pp_point());
}
void Graphics2D::ReplaceContents(ImageData* image) {
if (!has_interface<PPB_Graphics2D_1_0>())
return;
get_interface<PPB_Graphics2D_1_0>()->ReplaceContents(pp_resource(),
- image->pp_resource());
+ image->pp_resource());
// On success, reset the image data. This is to help prevent people
// from continuing to use the resource which will result in artifacts.
@@ -100,8 +100,8 @@ void Graphics2D::ReplaceContents(ImageData* image) {
int32_t Graphics2D::Flush(const CompletionCallback& cc) {
if (!has_interface<PPB_Graphics2D_1_0>())
return cc.MayForce(PP_ERROR_NOINTERFACE);
- return get_interface<PPB_Graphics2D_1_0>()->Flush(pp_resource(),
- cc.pp_completion_callback());
+ return get_interface<PPB_Graphics2D_1_0>()->Flush(
+ pp_resource(), cc.pp_completion_callback());
}
} // namespace pp
diff --git a/ppapi/host/ppapi_host.cc b/ppapi/host/ppapi_host.cc
index 7a9b4b6..436462c 100644
--- a/ppapi/host/ppapi_host.cc
+++ b/ppapi/host/ppapi_host.cc
@@ -164,8 +164,8 @@ void PpapiHost::OnHostMsgResourceDestroyed(PP_Resource resource) {
resources_.erase(found);
}
-ResourceHost* PpapiHost::GetResourceHost(PP_Resource resource) {
- ResourceMap::iterator found = resources_.find(resource);
+ResourceHost* PpapiHost::GetResourceHost(PP_Resource resource) const {
+ ResourceMap::const_iterator found = resources_.find(resource);
return found == resources_.end() ? NULL : found->second.get();
}
diff --git a/ppapi/host/ppapi_host.h b/ppapi/host/ppapi_host.h
index 3597093..7210b81 100644
--- a/ppapi/host/ppapi_host.h
+++ b/ppapi/host/ppapi_host.h
@@ -69,6 +69,9 @@ class PPAPI_HOST_EXPORT PpapiHost : public IPC::Sender, public IPC::Listener {
// ownership of the pointer.
void AddInstanceMessageFilter(scoped_ptr<InstanceMessageFilter> filter);
+ // Returns null if the resource doesn't exist.
+ host::ResourceHost* GetResourceHost(PP_Resource resource) const;
+
private:
friend class InstanceMessageFilter;
@@ -89,9 +92,6 @@ class PPAPI_HOST_EXPORT PpapiHost : public IPC::Sender, public IPC::Listener {
const IPC::Message& nested_msg);
void OnHostMsgResourceDestroyed(PP_Resource resource);
- // Returns null if the resource doesn't exist.
- host::ResourceHost* GetResourceHost(PP_Resource resource);
-
// Non-owning pointer.
IPC::Sender* sender_;
diff --git a/ppapi/host/resource_host.h b/ppapi/host/resource_host.h
index a3fe024..763da2c 100644
--- a/ppapi/host/resource_host.h
+++ b/ppapi/host/resource_host.h
@@ -46,6 +46,8 @@ class PPAPI_HOST_EXPORT ResourceHost : public ResourceMessageHandler {
virtual void SendReply(const ReplyMessageContext& context,
const IPC::Message& msg) OVERRIDE;
+ virtual bool IsGraphics2DHost() const { return false; }
+
protected:
// Adds a ResourceMessageFilter to handle resource messages. Incoming
// messages will be passed to the handlers of these filters before being
diff --git a/ppapi/ppapi_proxy.gypi b/ppapi/ppapi_proxy.gypi
index 9b98eba..6db746c 100644
--- a/ppapi/ppapi_proxy.gypi
+++ b/ppapi/ppapi_proxy.gypi
@@ -29,6 +29,8 @@
'proxy/dispatcher.cc',
'proxy/dispatcher.h',
'proxy/enter_proxy.h',
+ 'proxy/graphics_2d_resource.cc',
+ 'proxy/graphics_2d_resource.h',
'proxy/file_chooser_resource.cc',
'proxy/file_chooser_resource.h',
'proxy/flash_clipboard_resource.cc',
@@ -89,8 +91,6 @@
'proxy/ppb_flash_proxy.h',
'proxy/ppb_flash_message_loop_proxy.cc',
'proxy/ppb_flash_message_loop_proxy.h',
- 'proxy/ppb_graphics_2d_proxy.cc',
- 'proxy/ppb_graphics_2d_proxy.h',
'proxy/ppb_graphics_3d_proxy.cc',
'proxy/ppb_graphics_3d_proxy.h',
'proxy/ppb_host_resolver_private_proxy.cc',
diff --git a/ppapi/proxy/graphics_2d_resource.cc b/ppapi/proxy/graphics_2d_resource.cc
new file mode 100644
index 0000000..b07db46
--- /dev/null
+++ b/ppapi/proxy/graphics_2d_resource.cc
@@ -0,0 +1,152 @@
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "ppapi/proxy/graphics_2d_resource.h"
+
+#include "ppapi/c/pp_bool.h"
+#include "ppapi/c/pp_point.h"
+#include "ppapi/c/pp_rect.h"
+#include "ppapi/c/pp_resource.h"
+#include "ppapi/c/pp_size.h"
+#include "ppapi/c/ppb_graphics_2d.h"
+#include "ppapi/proxy/dispatch_reply_message.h"
+#include "ppapi/proxy/ppapi_messages.h"
+#include "ppapi/shared_impl/ppapi_globals.h"
+#include "ppapi/shared_impl/resource_tracker.h"
+#include "ppapi/shared_impl/tracked_callback.h"
+#include "ppapi/thunk/enter.h"
+#include "ppapi/thunk/ppb_image_data_api.h"
+
+namespace ppapi {
+namespace proxy {
+
+Graphics2DResource::Graphics2DResource(Connection connection,
+ PP_Instance instance,
+ const PP_Size& size,
+ PP_Bool is_always_opaque)
+ : PluginResource(connection, instance),
+ size_(size),
+ is_always_opaque_(is_always_opaque),
+ scale_(1.0f) {
+ // These checks are copied from PPB_ImageData_Impl::Init to make tests passed.
+ // Let's remove/refactor this when start to refactor ImageData.
+ bool bad_args = size.width <= 0 || size.height <= 0 ||
+ static_cast<int64>(size.width) * static_cast<int64>(size.height) >=
+ std::numeric_limits<int32>::max() / 4;
+ if (!bad_args && !sent_create_to_renderer()) {
+ SendCreate(RENDERER,
+ PpapiHostMsg_Graphics2D_Create(size, is_always_opaque));
+ }
+}
+
+Graphics2DResource::~Graphics2DResource() {
+}
+
+PP_Bool Graphics2DResource::Describe(PP_Size* size, PP_Bool* is_always_opaque) {
+ *size = size_;
+ *is_always_opaque = is_always_opaque_;
+ return PP_TRUE;
+}
+
+thunk::PPB_Graphics2D_API* Graphics2DResource::AsPPB_Graphics2D_API() {
+ return this;
+}
+
+void Graphics2DResource::PaintImageData(PP_Resource image_data,
+ const PP_Point* top_left,
+ const PP_Rect* src_rect) {
+ Resource* image_object =
+ PpapiGlobals::Get()->GetResourceTracker()->GetResource(image_data);
+ if (!image_object || pp_instance() != image_object->pp_instance()) {
+ Log(PP_LOGLEVEL_ERROR,
+ "Graphics2DResource.PaintImageData: Bad image resource.");
+ return;
+ }
+
+ PP_Rect dummy;
+ memset(&dummy, 0, sizeof(PP_Rect));
+ Post(RENDERER, PpapiHostMsg_Graphics2D_PaintImageData(
+ image_object->host_resource(), *top_left,
+ !!src_rect, src_rect ? *src_rect : dummy));
+}
+
+void Graphics2DResource::Scroll(const PP_Rect* clip_rect,
+ const PP_Point* amount) {
+ PP_Rect dummy;
+ memset(&dummy, 0, sizeof(PP_Rect));
+ Post(RENDERER, PpapiHostMsg_Graphics2D_Scroll(
+ !!clip_rect, clip_rect ? *clip_rect : dummy, *amount));
+}
+
+void Graphics2DResource::ReplaceContents(PP_Resource image_data) {
+ thunk::EnterResourceNoLock<thunk::PPB_ImageData_API> enter_image(
+ image_data, true);
+ if (enter_image.failed())
+ return;
+
+ // Check that the PP_Instance matches.
+ Resource* image_object =
+ PpapiGlobals::Get()->GetResourceTracker()->GetResource(image_data);
+ if (!image_object || pp_instance() != image_object->pp_instance()) {
+ Log(PP_LOGLEVEL_ERROR,
+ "Graphics2DResource.PaintImageData: Bad image resource.");
+ return;
+ }
+ enter_image.object()->SetUsedInReplaceContents();
+
+ Post(RENDERER, PpapiHostMsg_Graphics2D_ReplaceContents(
+ image_object->host_resource()));
+}
+
+bool Graphics2DResource::SetScale(float scale) {
+ if (scale <= 0.0f)
+ return false;
+ Post(RENDERER, PpapiHostMsg_Graphics2D_Dev_SetScale(scale));
+ scale_ = scale;
+ return true;
+}
+
+float Graphics2DResource::GetScale() {
+ return scale_;
+}
+
+int32_t Graphics2DResource::Flush(scoped_refptr<TrackedCallback> callback,
+ PP_Resource* old_image_data) {
+ // If host is not even created, return failure immediately. This can happen
+ // when failed to initialize (in constructor).
+ if (!sent_create_to_renderer())
+ return PP_ERROR_FAILED;
+
+ // We don't support this feature, it's for in-renderer only.
+ if (old_image_data)
+ *old_image_data = 0;
+
+ if (TrackedCallback::IsPending(current_flush_callback_))
+ return PP_ERROR_INPROGRESS; // Can't have >1 flush pending.
+ current_flush_callback_ = callback;
+
+ Call<PpapiPluginMsg_Graphics2D_FlushAck>(
+ RENDERER,
+ PpapiHostMsg_Graphics2D_Flush(),
+ base::Bind(&Graphics2DResource::OnPluginMsgFlushACK, this));
+ return PP_OK_COMPLETIONPENDING;
+}
+
+bool Graphics2DResource::ReadImageData(PP_Resource image,
+ const PP_Point* top_left) {
+ if (!top_left)
+ return false;
+ int32_t result = SyncCall<PpapiPluginMsg_Graphics2D_ReadImageDataAck>(
+ RENDERER,
+ PpapiHostMsg_Graphics2D_ReadImageData(image, *top_left));
+ return result == PP_OK;
+}
+
+void Graphics2DResource::OnPluginMsgFlushACK(
+ const ResourceMessageReplyParams& params) {
+ current_flush_callback_->Run(params.result());
+}
+
+} // namespace proxy
+} // namespace ppapi
diff --git a/ppapi/proxy/graphics_2d_resource.h b/ppapi/proxy/graphics_2d_resource.h
new file mode 100644
index 0000000..01309dc
--- /dev/null
+++ b/ppapi/proxy/graphics_2d_resource.h
@@ -0,0 +1,63 @@
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef PPAPI_PROXY_GRAPHICS_2D_RESOURCE_H_
+#define PPAPI_PROXY_GRAPHICS_2D_RESOURCE_H_
+
+#include "base/compiler_specific.h"
+#include "ppapi/proxy/plugin_resource.h"
+#include "ppapi/proxy/ppapi_proxy_export.h"
+#include "ppapi/thunk/ppb_graphics_2d_api.h"
+
+namespace ppapi {
+
+class TrackedCallback;
+
+namespace proxy {
+
+class PPAPI_PROXY_EXPORT Graphics2DResource
+ : public PluginResource,
+ public NON_EXPORTED_BASE(thunk::PPB_Graphics2D_API) {
+ public:
+ Graphics2DResource(Connection connection,
+ PP_Instance instance,
+ const PP_Size& size,
+ PP_Bool is_always_opaque);
+
+ virtual ~Graphics2DResource();
+
+ // Resource overrides.
+ virtual thunk::PPB_Graphics2D_API* AsPPB_Graphics2D_API() OVERRIDE;
+
+ // PPB_Graphics2D_API overrides.
+ virtual PP_Bool Describe(PP_Size* size, PP_Bool* is_always_opaque) OVERRIDE;
+ virtual void PaintImageData(PP_Resource image_data,
+ const PP_Point* top_left,
+ const PP_Rect* src_rect) OVERRIDE;
+ virtual void Scroll(const PP_Rect* clip_rect,
+ const PP_Point* amount) OVERRIDE;
+ virtual void ReplaceContents(PP_Resource image_data) OVERRIDE;
+ virtual bool SetScale(float scale) OVERRIDE;
+ virtual float GetScale() OVERRIDE;
+ virtual int32_t Flush(scoped_refptr<TrackedCallback> callback,
+ PP_Resource* old_image_data) OVERRIDE;
+ virtual bool ReadImageData(PP_Resource image,
+ const PP_Point* top_left) OVERRIDE;
+
+ private:
+ void OnPluginMsgFlushACK(const ResourceMessageReplyParams& params);
+
+ const PP_Size size_;
+ const PP_Bool is_always_opaque_;
+ float scale_;
+
+ scoped_refptr<TrackedCallback> current_flush_callback_;
+
+ DISALLOW_COPY_AND_ASSIGN(Graphics2DResource);
+};
+
+} // namespace proxy
+} // namespace ppapi
+
+#endif // PPAPI_PROXY_GRAPHICS_2D_RESOURCE_H_
diff --git a/ppapi/proxy/interface_list.cc b/ppapi/proxy/interface_list.cc
index 4b9e8e6..1c4d7e0 100644
--- a/ppapi/proxy/interface_list.cc
+++ b/ppapi/proxy/interface_list.cc
@@ -86,7 +86,6 @@
#include "ppapi/proxy/ppb_file_system_proxy.h"
#include "ppapi/proxy/ppb_flash_message_loop_proxy.h"
#include "ppapi/proxy/ppb_flash_proxy.h"
-#include "ppapi/proxy/ppb_graphics_2d_proxy.h"
#include "ppapi/proxy/ppb_graphics_3d_proxy.h"
#include "ppapi/proxy/ppb_host_resolver_private_proxy.h"
#include "ppapi/proxy/ppb_image_data_proxy.h"
diff --git a/ppapi/proxy/ppapi_messages.h b/ppapi/proxy/ppapi_messages.h
index 087540b..2bec742 100644
--- a/ppapi/proxy/ppapi_messages.h
+++ b/ppapi/proxy/ppapi_messages.h
@@ -450,11 +450,6 @@ IPC_MESSAGE_ROUTED2(
ppapi::HostResource /* filesystem */,
int32_t /* result */)
-// PPB_Graphics2D.
-IPC_MESSAGE_ROUTED2(PpapiMsg_PPBGraphics2D_FlushACK,
- ppapi::HostResource /* graphics_2d */,
- int32_t /* pp_error */)
-
// PPB_Graphics3D.
IPC_MESSAGE_ROUTED2(PpapiMsg_PPBGraphics3D_SwapBuffersACK,
ppapi::HostResource /* graphics_3d */,
@@ -885,32 +880,6 @@ IPC_MESSAGE_ROUTED2(PpapiHostMsg_PPBFileSystem_Open,
ppapi::HostResource /* result */,
int64_t /* expected_size */)
-// PPB_Graphics2D.
-IPC_SYNC_MESSAGE_ROUTED3_1(PpapiHostMsg_PPBGraphics2D_Create,
- PP_Instance /* instance */,
- PP_Size /* size */,
- PP_Bool /* is_always_opaque */,
- ppapi::HostResource /* result */)
-IPC_MESSAGE_ROUTED5(PpapiHostMsg_PPBGraphics2D_PaintImageData,
- ppapi::HostResource /* graphics_2d */,
- ppapi::HostResource /* image_data */,
- PP_Point /* top_left */,
- bool /* src_rect_specified */,
- PP_Rect /* src_rect */)
-IPC_MESSAGE_ROUTED4(PpapiHostMsg_PPBGraphics2D_Scroll,
- ppapi::HostResource /* graphics_2d */,
- bool /* clip_specified */,
- PP_Rect /* clip */,
- PP_Point /* amount */)
-IPC_MESSAGE_ROUTED2(PpapiHostMsg_PPBGraphics2D_ReplaceContents,
- ppapi::HostResource /* graphics_2d */,
- ppapi::HostResource /* image_data */)
-IPC_MESSAGE_ROUTED1(PpapiHostMsg_PPBGraphics2D_Flush,
- ppapi::HostResource /* graphics_2d */)
-IPC_MESSAGE_ROUTED2(PpapiHostMsg_PPBGraphics2D_Dev_SetScale,
- ppapi::HostResource /* graphics_2d */,
- float /* scale */)
-
// PPB_Graphics3D.
IPC_SYNC_MESSAGE_ROUTED3_1(PpapiHostMsg_PPBGraphics3D_Create,
PP_Instance /* instance */,
@@ -976,7 +945,7 @@ IPC_SYNC_MESSAGE_ROUTED1_1(PpapiHostMsg_PPBInstance_GetOwnerElementObject,
ppapi::proxy::SerializedVar /* result */)
IPC_SYNC_MESSAGE_ROUTED2_1(PpapiHostMsg_PPBInstance_BindGraphics,
PP_Instance /* instance */,
- ppapi::HostResource /* device */,
+ PP_Resource /* device */,
PP_Bool /* result */)
IPC_SYNC_MESSAGE_ROUTED1_1(
PpapiHostMsg_PPBInstance_GetAudioHardwareOutputSampleRate,
@@ -1505,6 +1474,35 @@ IPC_MESSAGE_CONTROL0(PpapiHostMsg_Gamepad_RequestMemory)
// actual handle is passed in the ReplyParams struct.
IPC_MESSAGE_CONTROL0(PpapiPluginMsg_Gamepad_SendMemory)
+
+// Graphics2D, plugin -> host
+IPC_MESSAGE_CONTROL2(PpapiHostMsg_Graphics2D_Create,
+ PP_Size /* size */,
+ PP_Bool /* is_always_opaque */)
+IPC_MESSAGE_CONTROL4(PpapiHostMsg_Graphics2D_PaintImageData,
+ ppapi::HostResource /* image_data */,
+ PP_Point /* top_left */,
+ bool /* src_rect_specified */,
+ PP_Rect /* src_rect */)
+IPC_MESSAGE_CONTROL3(PpapiHostMsg_Graphics2D_Scroll,
+ bool /* clip_specified */,
+ PP_Rect /* clip */,
+ PP_Point /* amount */)
+IPC_MESSAGE_CONTROL1(PpapiHostMsg_Graphics2D_ReplaceContents,
+ ppapi::HostResource /* image_data */)
+IPC_MESSAGE_CONTROL1(PpapiHostMsg_Graphics2D_Dev_SetScale,
+ float /* scale */)
+
+// Graphics2D, plugin -> host -> plugin
+IPC_MESSAGE_CONTROL0(PpapiHostMsg_Graphics2D_Flush)
+IPC_MESSAGE_CONTROL0(PpapiPluginMsg_Graphics2D_FlushAck)
+
+IPC_MESSAGE_CONTROL2(PpapiHostMsg_Graphics2D_ReadImageData,
+ PP_Resource /* image */,
+ PP_Point /* top_left */)
+IPC_MESSAGE_CONTROL0(PpapiPluginMsg_Graphics2D_ReadImageDataAck)
+
+
// Printing.
IPC_MESSAGE_CONTROL0(PpapiHostMsg_Printing_Create)
IPC_MESSAGE_CONTROL0(PpapiHostMsg_Printing_GetDefaultPrintSettings)
diff --git a/ppapi/proxy/ppb_graphics_2d_proxy.cc b/ppapi/proxy/ppb_graphics_2d_proxy.cc
deleted file mode 100644
index 4b05fe8..0000000
--- a/ppapi/proxy/ppb_graphics_2d_proxy.cc
+++ /dev/null
@@ -1,314 +0,0 @@
-// Copyright (c) 2012 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#include "ppapi/proxy/ppb_graphics_2d_proxy.h"
-
-#include <string.h> // For memset.
-
-#include "base/compiler_specific.h"
-#include "base/logging.h"
-#include "ppapi/c/pp_completion_callback.h"
-#include "ppapi/c/pp_errors.h"
-#include "ppapi/c/pp_resource.h"
-#include "ppapi/c/ppb_graphics_2d.h"
-#include "ppapi/proxy/enter_proxy.h"
-#include "ppapi/proxy/plugin_dispatcher.h"
-#include "ppapi/proxy/plugin_resource_tracker.h"
-#include "ppapi/proxy/ppapi_messages.h"
-#include "ppapi/proxy/ppb_image_data_proxy.h"
-#include "ppapi/shared_impl/tracked_callback.h"
-#include "ppapi/thunk/enter.h"
-#include "ppapi/thunk/ppb_graphics_2d_api.h"
-#include "ppapi/thunk/thunk.h"
-
-using ppapi::thunk::PPB_Graphics2D_API;
-
-namespace ppapi {
-namespace proxy {
-
-class Graphics2D : public Resource, public thunk::PPB_Graphics2D_API {
- public:
- Graphics2D(const HostResource& host_resource,
- const PP_Size& size,
- PP_Bool is_always_opaque);
- virtual ~Graphics2D();
-
- // Resource.
- virtual PPB_Graphics2D_API* AsPPB_Graphics2D_API();
-
- // PPB_Graphics_2D_API.
- PP_Bool Describe(PP_Size* size, PP_Bool* is_always_opaque);
- void PaintImageData(PP_Resource image_data,
- const PP_Point* top_left,
- const PP_Rect* src_rect);
- void Scroll(const PP_Rect* clip_rect,
- const PP_Point* amount);
- void ReplaceContents(PP_Resource image_data);
- bool SetScale(float scale);
- float GetScale();
- int32_t Flush(scoped_refptr<TrackedCallback> callback,
- PP_Resource* old_image_data);
-
- // Notification that the host has sent an ACK for a pending Flush.
- void FlushACK(int32_t result_code);
-
- private:
- PluginDispatcher* GetDispatcher() const {
- return PluginDispatcher::GetForResource(this);
- }
-
- static const ApiID kApiID = API_ID_PPB_GRAPHICS_2D;
-
- PP_Size size_;
- PP_Bool is_always_opaque_;
- float scale_;
-
- // In the plugin, this is the current callback set for Flushes. When the
- // callback is pending, we're waiting for a flush ACK.
- scoped_refptr<TrackedCallback> current_flush_callback_;
-
- DISALLOW_COPY_AND_ASSIGN(Graphics2D);
-};
-
-Graphics2D::Graphics2D(const HostResource& host_resource,
- const PP_Size& size,
- PP_Bool is_always_opaque)
- : Resource(OBJECT_IS_PROXY, host_resource),
- size_(size),
- is_always_opaque_(is_always_opaque),
- scale_(1.0f) {
-}
-
-Graphics2D::~Graphics2D() {
-}
-
-PPB_Graphics2D_API* Graphics2D::AsPPB_Graphics2D_API() {
- return this;
-}
-
-PP_Bool Graphics2D::Describe(PP_Size* size, PP_Bool* is_always_opaque) {
- *size = size_;
- *is_always_opaque = is_always_opaque_;
- return PP_TRUE;
-}
-
-void Graphics2D::PaintImageData(PP_Resource image_data,
- const PP_Point* top_left,
- const PP_Rect* src_rect) {
- Resource* image_object =
- PpapiGlobals::Get()->GetResourceTracker()->GetResource(image_data);
- if (!image_object || pp_instance() != image_object->pp_instance()) {
- Log(PP_LOGLEVEL_ERROR,
- "PPB_Graphics2D.PaintImageData: Bad image resource.");
- return;
- }
-
- PP_Rect dummy;
- memset(&dummy, 0, sizeof(PP_Rect));
- GetDispatcher()->Send(new PpapiHostMsg_PPBGraphics2D_PaintImageData(
- kApiID, host_resource(), image_object->host_resource(), *top_left,
- !!src_rect, src_rect ? *src_rect : dummy));
-}
-
-void Graphics2D::Scroll(const PP_Rect* clip_rect,
- const PP_Point* amount) {
- PP_Rect dummy;
- memset(&dummy, 0, sizeof(PP_Rect));
- GetDispatcher()->Send(new PpapiHostMsg_PPBGraphics2D_Scroll(
- kApiID, host_resource(), !!clip_rect, clip_rect ? *clip_rect : dummy,
- *amount));
-}
-
-void Graphics2D::ReplaceContents(PP_Resource image_data) {
- thunk::EnterResourceNoLock<thunk::PPB_ImageData_API> enter_image(
- image_data, true);
- if (enter_image.failed())
- return;
-
- ImageData* image_object = static_cast<ImageData*>(enter_image.object());
- if (pp_instance() != image_object->pp_instance()) {
- Log(PP_LOGLEVEL_ERROR,
- "PPB_Graphics2D.ReplaceContents: Image resource for another instance.");
- return;
- }
- image_object->set_used_in_replace_contents();
-
- GetDispatcher()->Send(new PpapiHostMsg_PPBGraphics2D_ReplaceContents(
- kApiID, host_resource(), image_object->host_resource()));
-}
-
-bool Graphics2D::SetScale(float scale) {
- if (scale <= 0.0f)
- return false;
- GetDispatcher()->Send(new PpapiHostMsg_PPBGraphics2D_Dev_SetScale(
- kApiID, host_resource(), scale));
- scale_ = scale;
- return true;
-}
-
-float Graphics2D::GetScale() {
- return scale_;
-}
-
-int32_t Graphics2D::Flush(scoped_refptr<TrackedCallback> callback,
- PP_Resource* old_image_data) {
- // We don't support this feature, it's for in-renderer only.
- if (old_image_data)
- *old_image_data = 0;
-
- if (TrackedCallback::IsPending(current_flush_callback_))
- return PP_ERROR_INPROGRESS; // Can't have >1 flush pending.
- current_flush_callback_ = callback;
-
- GetDispatcher()->Send(new PpapiHostMsg_PPBGraphics2D_Flush(kApiID,
- host_resource()));
- return PP_OK_COMPLETIONPENDING;
-}
-
-void Graphics2D::FlushACK(int32_t result_code) {
- current_flush_callback_->Run(result_code);
-}
-
-PPB_Graphics2D_Proxy::PPB_Graphics2D_Proxy(Dispatcher* dispatcher)
- : InterfaceProxy(dispatcher),
- callback_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) {
-}
-
-PPB_Graphics2D_Proxy::~PPB_Graphics2D_Proxy() {
-}
-
-// static
-PP_Resource PPB_Graphics2D_Proxy::CreateProxyResource(
- PP_Instance instance,
- const PP_Size& size,
- PP_Bool is_always_opaque) {
- PluginDispatcher* dispatcher = PluginDispatcher::GetForInstance(instance);
- if (!dispatcher)
- return 0;
-
- HostResource result;
- dispatcher->Send(new PpapiHostMsg_PPBGraphics2D_Create(
- kApiID, instance, size, is_always_opaque, &result));
- if (result.is_null())
- return 0;
- return (new Graphics2D(result, size, is_always_opaque))->GetReference();
-}
-
-bool PPB_Graphics2D_Proxy::OnMessageReceived(const IPC::Message& msg) {
- bool handled = true;
- IPC_BEGIN_MESSAGE_MAP(PPB_Graphics2D_Proxy, msg)
-#if !defined(OS_NACL)
- IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBGraphics2D_Create,
- OnHostMsgCreate)
- IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBGraphics2D_PaintImageData,
- OnHostMsgPaintImageData)
- IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBGraphics2D_Scroll,
- OnHostMsgScroll)
- IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBGraphics2D_ReplaceContents,
- OnHostMsgReplaceContents)
- IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBGraphics2D_Flush,
- OnHostMsgFlush)
- IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBGraphics2D_Dev_SetScale,
- OnHostMsgSetScale)
-#endif // !defined(OS_NACL)
- IPC_MESSAGE_HANDLER(PpapiMsg_PPBGraphics2D_FlushACK,
- OnPluginMsgFlushACK)
- IPC_MESSAGE_UNHANDLED(handled = false)
- IPC_END_MESSAGE_MAP()
- // FIXME(brettw) handle bad messages!
- return handled;
-}
-
-#if !defined(OS_NACL)
-void PPB_Graphics2D_Proxy::OnHostMsgCreate(PP_Instance instance,
- const PP_Size& size,
- PP_Bool is_always_opaque,
- HostResource* result) {
- thunk::EnterResourceCreation enter(instance);
- if (enter.succeeded()) {
- result->SetHostResource(instance, enter.functions()->CreateGraphics2D(
- instance, size, is_always_opaque));
- }
-}
-
-void PPB_Graphics2D_Proxy::OnHostMsgPaintImageData(
- const HostResource& graphics_2d,
- const HostResource& image_data,
- const PP_Point& top_left,
- bool src_rect_specified,
- const PP_Rect& src_rect) {
- EnterHostFromHostResource<PPB_Graphics2D_API> enter(graphics_2d);
- if (enter.failed())
- return;
- enter.object()->PaintImageData(image_data.host_resource(), &top_left,
- src_rect_specified ? &src_rect : NULL);
-}
-
-void PPB_Graphics2D_Proxy::OnHostMsgScroll(const HostResource& graphics_2d,
- bool clip_specified,
- const PP_Rect& clip,
- const PP_Point& amount) {
- EnterHostFromHostResource<PPB_Graphics2D_API> enter(graphics_2d);
- if (enter.failed())
- return;
- enter.object()->Scroll(clip_specified ? &clip : NULL, &amount);
-}
-
-void PPB_Graphics2D_Proxy::OnHostMsgReplaceContents(
- const HostResource& graphics_2d,
- const HostResource& image_data) {
- EnterHostFromHostResource<PPB_Graphics2D_API> enter(graphics_2d);
- if (enter.failed())
- return;
- enter.object()->ReplaceContents(image_data.host_resource());
-}
-
-void PPB_Graphics2D_Proxy::OnHostMsgFlush(const HostResource& graphics_2d) {
- EnterHostFromHostResourceForceCallback<PPB_Graphics2D_API> enter(
- graphics_2d, callback_factory_,
- &PPB_Graphics2D_Proxy::SendFlushACKToPlugin, graphics_2d);
- if (enter.failed())
- return;
- PP_Resource old_image_data = 0;
- enter.SetResult(enter.object()->Flush(enter.callback(), &old_image_data));
- if (old_image_data) {
- // If the Graphics2D has an old image data it's not using any more, send
- // it back to the plugin for possible re-use. See ppb_image_data_proxy.cc
- // for a description how this process works.
- HostResource old_image_data_host_resource;
- old_image_data_host_resource.SetHostResource(graphics_2d.instance(),
- old_image_data);
- dispatcher()->Send(new PpapiMsg_PPBImageData_NotifyUnusedImageData(
- API_ID_PPB_IMAGE_DATA, old_image_data_host_resource));
- }
-}
-
-void PPB_Graphics2D_Proxy::OnHostMsgSetScale(const HostResource& graphics_2d,
- float scale) {
- EnterHostFromHostResource<PPB_Graphics2D_API> enter(graphics_2d);
- if (enter.failed())
- return;
- enter.object()->SetScale(scale);
-}
-#endif // !defined(OS_NACL)
-
-void PPB_Graphics2D_Proxy::OnPluginMsgFlushACK(
- const HostResource& host_resource,
- int32_t pp_error) {
- EnterPluginFromHostResource<PPB_Graphics2D_API> enter(host_resource);
- if (enter.succeeded())
- static_cast<Graphics2D*>(enter.object())->FlushACK(pp_error);
-}
-
-#if !defined(OS_NACL)
-void PPB_Graphics2D_Proxy::SendFlushACKToPlugin(
- int32_t result,
- const HostResource& graphics_2d) {
- dispatcher()->Send(new PpapiMsg_PPBGraphics2D_FlushACK(kApiID, graphics_2d,
- result));
-}
-#endif // !defined(OS_NACL)
-
-} // namespace proxy
-} // namespace ppapi
diff --git a/ppapi/proxy/ppb_graphics_2d_proxy.h b/ppapi/proxy/ppb_graphics_2d_proxy.h
deleted file mode 100644
index cf0a921..0000000
--- a/ppapi/proxy/ppb_graphics_2d_proxy.h
+++ /dev/null
@@ -1,77 +0,0 @@
-// Copyright (c) 2012 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#ifndef PPAPI_PPB_GRAPHICS_2D_PROXY_H_
-#define PPAPI_PPB_GRAPHICS_2D_PROXY_H_
-
-#include "ppapi/c/pp_bool.h"
-#include "ppapi/c/pp_completion_callback.h"
-#include "ppapi/c/pp_module.h"
-#include "ppapi/c/pp_module.h"
-#include "ppapi/c/pp_resource.h"
-#include "ppapi/c/pp_size.h"
-#include "ppapi/c/pp_var.h"
-#include "ppapi/proxy/interface_proxy.h"
-#include "ppapi/proxy/proxy_completion_callback_factory.h"
-#include "ppapi/shared_impl/host_resource.h"
-#include "ppapi/utility/completion_callback_factory.h"
-
-struct PP_Point;
-struct PP_Rect;
-
-namespace ppapi {
-namespace proxy {
-
-class PPB_Graphics2D_Proxy : public InterfaceProxy {
- public:
- PPB_Graphics2D_Proxy(Dispatcher* dispatcher);
- virtual ~PPB_Graphics2D_Proxy();
-
- static PP_Resource CreateProxyResource(PP_Instance instance,
- const PP_Size& size,
- PP_Bool is_always_opaque);
-
- // InterfaceProxy implementation.
- virtual bool OnMessageReceived(const IPC::Message& msg);
-
- static const ApiID kApiID = API_ID_PPB_GRAPHICS_2D;
-
- private:
- // Plugin->host message handlers.
- void OnHostMsgCreate(PP_Instance instance,
- const PP_Size& size,
- PP_Bool is_always_opaque,
- HostResource* result);
- void OnHostMsgPaintImageData(const HostResource& graphics_2d,
- const HostResource& image_data,
- const PP_Point& top_left,
- bool src_rect_specified,
- const PP_Rect& src_rect);
- void OnHostMsgScroll(const HostResource& graphics_2d,
- bool clip_specified,
- const PP_Rect& clip,
- const PP_Point& amount);
- void OnHostMsgReplaceContents(const HostResource& graphics_2d,
- const HostResource& image_data);
- void OnHostMsgFlush(const HostResource& graphics_2d);
- void OnHostMsgSetScale(const HostResource& graphics_2d,
- float scale);
-
- // Host->plugin message handlers.
- void OnPluginMsgFlushACK(const HostResource& graphics_2d,
- int32_t pp_error);
-
- // Called in the renderer to send the given flush ACK to the plugin.
- void SendFlushACKToPlugin(int32_t result,
- const HostResource& graphics_2d);
-
- ProxyCompletionCallbackFactory<PPB_Graphics2D_Proxy> callback_factory_;
-
- DISALLOW_COPY_AND_ASSIGN(PPB_Graphics2D_Proxy);
-};
-
-} // namespace proxy
-} // namespace ppapi
-
-#endif // PPAPI_PPB_GRAPHICS_2D_PROXY_H_
diff --git a/ppapi/proxy/ppb_image_data_proxy.cc b/ppapi/proxy/ppb_image_data_proxy.cc
index 096d61d..43974b8 100644
--- a/ppapi/proxy/ppb_image_data_proxy.cc
+++ b/ppapi/proxy/ppb_image_data_proxy.cc
@@ -402,6 +402,10 @@ SkCanvas* ImageData::GetCanvas() {
#endif
}
+void ImageData::SetUsedInReplaceContents() {
+ used_in_replace_contents_ = true;
+}
+
void ImageData::RecycleToPlugin(bool zero_contents) {
used_in_replace_contents_ = false;
if (zero_contents) {
diff --git a/ppapi/proxy/ppb_image_data_proxy.h b/ppapi/proxy/ppb_image_data_proxy.h
index 6ddbafa..c56217a5 100644
--- a/ppapi/proxy/ppb_image_data_proxy.h
+++ b/ppapi/proxy/ppb_image_data_proxy.h
@@ -59,11 +59,10 @@ class ImageData : public ppapi::Resource,
virtual int32_t GetSharedMemory(int* handle, uint32_t* byte_count) OVERRIDE;
virtual SkCanvas* GetPlatformCanvas() OVERRIDE;
virtual SkCanvas* GetCanvas() OVERRIDE;
+ virtual void SetUsedInReplaceContents() OVERRIDE;
const PP_ImageDataDesc& desc() const { return desc_; }
- void set_used_in_replace_contents() { used_in_replace_contents_ = true; }
-
// Prepares this image data to be recycled to the plugin. The contents will be
// cleared if zero_contents is set.
void RecycleToPlugin(bool zero_contents);
diff --git a/ppapi/proxy/ppb_instance_proxy.cc b/ppapi/proxy/ppb_instance_proxy.cc
index 51196f7..603e34d 100644
--- a/ppapi/proxy/ppb_instance_proxy.cc
+++ b/ppapi/proxy/ppb_instance_proxy.cc
@@ -29,6 +29,8 @@
#include "ppapi/shared_impl/ppb_view_shared.h"
#include "ppapi/shared_impl/var.h"
#include "ppapi/thunk/enter.h"
+#include "ppapi/thunk/ppb_graphics_2d_api.h"
+#include "ppapi/thunk/ppb_graphics_3d_api.h"
#include "ppapi/thunk/thunk.h"
// Windows headers interfere with this file.
@@ -38,6 +40,8 @@
using ppapi::thunk::EnterInstanceNoLock;
using ppapi::thunk::EnterResourceNoLock;
+using ppapi::thunk::PPB_Graphics2D_API;
+using ppapi::thunk::PPB_Graphics3D_API;
using ppapi::thunk::PPB_Instance_API;
namespace ppapi {
@@ -198,17 +202,35 @@ PP_Bool PPB_Instance_Proxy::BindGraphics(PP_Instance instance,
// If device is 0, pass a null HostResource. This signals the host to unbind
// all devices.
HostResource host_resource;
+ PP_Resource pp_resource = 0;
+ PP_Bool result = PP_FALSE;
if (device) {
Resource* resource =
PpapiGlobals::Get()->GetResourceTracker()->GetResource(device);
if (!resource || resource->pp_instance() != instance)
return PP_FALSE;
host_resource = resource->host_resource();
+ pp_resource = resource->pp_resource();
+ } else {
+ // Passing 0 means unbinding all devices.
+ dispatcher()->Send(new PpapiHostMsg_PPBInstance_BindGraphics(
+ API_ID_PPB_INSTANCE, instance, 0, &result));
+ return result;
}
- PP_Bool result = PP_FALSE;
- dispatcher()->Send(new PpapiHostMsg_PPBInstance_BindGraphics(
- API_ID_PPB_INSTANCE, instance, host_resource, &result));
+ // We need to pass different resource to Graphics 2D and 3D right now. Once
+ // 3D is migrated to the new design, we should be able to unify this.
+ EnterResourceNoLock<PPB_Graphics2D_API> enter_2d(device, false);
+ EnterResourceNoLock<PPB_Graphics3D_API> enter_3d(device, false);
+ if (enter_2d.succeeded()) {
+ dispatcher()->Send(new PpapiHostMsg_PPBInstance_BindGraphics(
+ API_ID_PPB_INSTANCE, instance, pp_resource,
+ &result));
+ } else if (enter_3d.succeeded()) {
+ dispatcher()->Send(new PpapiHostMsg_PPBInstance_BindGraphics(
+ API_ID_PPB_INSTANCE, instance, host_resource.host_resource(),
+ &result));
+ }
return result;
}
@@ -788,12 +810,11 @@ void PPB_Instance_Proxy::OnHostMsgGetOwnerElementObject(
}
void PPB_Instance_Proxy::OnHostMsgBindGraphics(PP_Instance instance,
- const HostResource& device,
+ PP_Resource device,
PP_Bool* result) {
EnterInstanceNoLock enter(instance);
if (enter.succeeded()) {
- *result = enter.functions()->BindGraphics(instance,
- device.host_resource());
+ *result = enter.functions()->BindGraphics(instance, device);
}
}
diff --git a/ppapi/proxy/ppb_instance_proxy.h b/ppapi/proxy/ppb_instance_proxy.h
index fbdc694..ca7f4af 100644
--- a/ppapi/proxy/ppb_instance_proxy.h
+++ b/ppapi/proxy/ppb_instance_proxy.h
@@ -164,7 +164,7 @@ class PPB_Instance_Proxy : public InterfaceProxy,
void OnHostMsgGetOwnerElementObject(PP_Instance instance,
SerializedVarReturnValue result);
void OnHostMsgBindGraphics(PP_Instance instance,
- const ppapi::HostResource& device,
+ PP_Resource device,
PP_Bool* result);
void OnHostMsgIsFullFrame(PP_Instance instance, PP_Bool* result);
void OnHostMsgExecuteScript(PP_Instance instance,
diff --git a/ppapi/proxy/ppb_testing_proxy.cc b/ppapi/proxy/ppb_testing_proxy.cc
index 576302f..c52528b 100644
--- a/ppapi/proxy/ppb_testing_proxy.cc
+++ b/ppapi/proxy/ppb_testing_proxy.cc
@@ -14,10 +14,13 @@
#include "ppapi/shared_impl/resource.h"
#include "ppapi/shared_impl/resource_tracker.h"
#include "ppapi/thunk/enter.h"
+#include "ppapi/thunk/ppb_graphics_2d_api.h"
#include "ppapi/thunk/ppb_input_event_api.h"
using ppapi::thunk::EnterInstance;
+using ppapi::thunk::EnterResource;
using ppapi::thunk::EnterResourceNoLock;
+using ppapi::thunk::PPB_Graphics2D_API;
using ppapi::thunk::PPB_InputEvent_API;
namespace ppapi {
@@ -39,16 +42,12 @@ PP_Bool ReadImageData(PP_Resource graphics_2d,
image_object->pp_instance() != graphics_2d_object->pp_instance())
return PP_FALSE;
- PluginDispatcher* dispatcher = PluginDispatcher::GetForInstance(
- image_object->pp_instance());
- if (!dispatcher)
+ EnterResourceNoLock<PPB_Graphics2D_API> enter(graphics_2d, true);
+ if (enter.failed())
return PP_FALSE;
-
- PP_Bool result = PP_FALSE;
- dispatcher->Send(new PpapiHostMsg_PPBTesting_ReadImageData(
- API_ID_PPB_TESTING, graphics_2d_object->host_resource(),
- image_object->host_resource(), *top_left, &result));
- return result;
+ const HostResource& host_image = image_object->host_resource();
+ return enter.object()->ReadImageData(host_image.host_resource(), top_left) ?
+ PP_TRUE : PP_FALSE;
}
void RunMessageLoop(PP_Instance instance) {
diff --git a/ppapi/proxy/resource_creation_proxy.cc b/ppapi/proxy/resource_creation_proxy.cc
index c37ff63..0c995891 100644
--- a/ppapi/proxy/resource_creation_proxy.cc
+++ b/ppapi/proxy/resource_creation_proxy.cc
@@ -14,6 +14,7 @@
#include "ppapi/proxy/flash_device_id_resource.h"
#include "ppapi/proxy/flash_font_file_resource.h"
#include "ppapi/proxy/flash_menu_resource.h"
+#include "ppapi/proxy/graphics_2d_resource.h"
#include "ppapi/proxy/plugin_dispatcher.h"
#include "ppapi/proxy/plugin_globals.h"
#include "ppapi/proxy/plugin_resource_tracker.h"
@@ -25,7 +26,6 @@
#include "ppapi/proxy/ppb_file_ref_proxy.h"
#include "ppapi/proxy/ppb_file_system_proxy.h"
#include "ppapi/proxy/ppb_flash_message_loop_proxy.h"
-#include "ppapi/proxy/ppb_graphics_2d_proxy.h"
#include "ppapi/proxy/ppb_graphics_3d_proxy.h"
#include "ppapi/proxy/ppb_host_resolver_private_proxy.h"
#include "ppapi/proxy/ppb_image_data_proxy.h"
@@ -207,8 +207,8 @@ PP_Resource ResourceCreationProxy::CreateFileChooser(
PP_Resource ResourceCreationProxy::CreateGraphics2D(PP_Instance instance,
const PP_Size& size,
PP_Bool is_always_opaque) {
- return PPB_Graphics2D_Proxy::CreateProxyResource(instance, size,
- is_always_opaque);
+ return (new Graphics2DResource(GetConnection(), instance, size,
+ is_always_opaque))->GetReference();
}
PP_Resource ResourceCreationProxy::CreateGraphics3D(
diff --git a/ppapi/tests/test_graphics_2d.cc b/ppapi/tests/test_graphics_2d.cc
index 4b31c92..95ead3e 100644
--- a/ppapi/tests/test_graphics_2d.cc
+++ b/ppapi/tests/test_graphics_2d.cc
@@ -14,11 +14,14 @@
#include "ppapi/c/ppb_graphics_2d.h"
#include "ppapi/cpp/completion_callback.h"
#include "ppapi/cpp/dev/graphics_2d_dev.h"
+#include "ppapi/cpp/dev/graphics_2d_dev.h"
#include "ppapi/cpp/graphics_2d.h"
+#include "ppapi/cpp/graphics_3d.h"
#include "ppapi/cpp/image_data.h"
#include "ppapi/cpp/instance.h"
#include "ppapi/cpp/module.h"
#include "ppapi/cpp/rect.h"
+#include "ppapi/tests/test_utils.h"
#include "ppapi/tests/testing_instance.h"
REGISTER_TEST_CASE(Graphics2D);
@@ -63,6 +66,7 @@ void TestGraphics2D::RunTests(const std::string& filter) {
RUN_TEST_FORCEASYNC_AND_NOT(FlushOffscreenUpdate, filter);
RUN_TEST(Dev, filter);
RUN_TEST(ReplaceContentsCaching, filter);
+ RUN_TEST(BindNull, filter);
}
void TestGraphics2D::QuitMessageLoop() {
@@ -89,6 +93,29 @@ bool TestGraphics2D::IsDCUniformColor(const pp::Graphics2D& dc,
return IsSquareInImage(readback, 0, pp::Rect(dc.size()), color);
}
+bool TestGraphics2D::ResourceHealthCheck(pp::Instance* instance,
+ pp::Graphics2D* context) {
+ TestCompletionCallback callback(instance->pp_instance(), callback_type());
+ callback.WaitForResult(context->Flush(callback));
+ if (callback.result() < 0)
+ return callback.result() != PP_ERROR_FAILED;
+ else if (callback.result() == 0)
+ return false;
+ return true;
+}
+
+bool TestGraphics2D::ResourceHealthCheckForC(pp::Instance* instance,
+ PP_Resource graphics_2d) {
+ TestCompletionCallback callback(instance->pp_instance(), callback_type());
+ callback.WaitForResult(graphics_2d_interface_->Flush(
+ graphics_2d, callback.GetCallback().pp_completion_callback()));
+ if (callback.result() < 0)
+ return callback.result() != PP_ERROR_FAILED;
+ else if (callback.result() == 0)
+ return false;
+ return true;
+}
+
bool TestGraphics2D::FlushAndWaitForDone(pp::Graphics2D* context) {
int32_t flags = (force_async_ ? 0 : PP_COMPLETIONCALLBACK_FLAG_OPTIONAL);
pp::CompletionCallback cc(&FlushCallbackQuitMessageLoop, this, flags);
@@ -260,31 +287,40 @@ std::string TestGraphics2D::TestInvalidResource() {
std::string TestGraphics2D::TestInvalidSize() {
pp::Graphics2D a(instance_, pp::Size(16, 0), false);
- if (!a.is_null())
+ if (ResourceHealthCheck(instance_, &a))
return "0 height accepted";
pp::Graphics2D b(instance_, pp::Size(0, 16), false);
- if (!b.is_null())
- return "0 width accepted";
+ if (ResourceHealthCheck(instance_, &b))
+ return "0 height accepted";
// Need to use the C API since pp::Size prevents negative sizes.
PP_Size size;
size.width = 16;
size.height = -16;
- ASSERT_FALSE(!!graphics_2d_interface_->Create(
- instance_->pp_instance(), &size, PP_FALSE));
+ PP_Resource graphics = graphics_2d_interface_->Create(
+ instance_->pp_instance(), &size, PP_FALSE);
+ ASSERT_FALSE(ResourceHealthCheckForC(instance_, graphics));
size.width = -16;
size.height = 16;
- ASSERT_FALSE(!!graphics_2d_interface_->Create(
- instance_->pp_instance(), &size, PP_FALSE));
+ graphics = graphics_2d_interface_->Create(
+ instance_->pp_instance(), &size, PP_FALSE);
+ ASSERT_FALSE(ResourceHealthCheckForC(instance_, graphics));
+
+ // Overflow to negative size
+ size.width = std::numeric_limits<int32_t>::max();
+ size.height = std::numeric_limits<int32_t>::max();
+ graphics = graphics_2d_interface_->Create(
+ instance_->pp_instance(), &size, PP_FALSE);
+ ASSERT_FALSE(ResourceHealthCheckForC(instance_, graphics));
PASS();
}
std::string TestGraphics2D::TestHumongous() {
pp::Graphics2D a(instance_, pp::Size(100000, 100000), false);
- if (!a.is_null())
+ if (ResourceHealthCheck(instance_, &a))
return "Humongous device created";
PASS();
}
@@ -816,3 +852,24 @@ std::string TestGraphics2D::TestReplaceContentsCaching() {
PASS();
}
+
+std::string TestGraphics2D::TestBindNull() {
+ // Binding a null resource is not an error, it should clear all bound
+ // resources. We can't easily test what resource is bound, but we can test
+ // that this doesn't throw an error.
+ ASSERT_TRUE(instance_->BindGraphics(pp::Graphics2D()));
+ ASSERT_TRUE(instance_->BindGraphics(pp::Graphics3D()));
+
+ const int w = 115, h = 117;
+ pp::Graphics2D dc(instance_, pp::Size(w, h), false);
+ if (dc.is_null())
+ return "Failure creating device.";
+ if (!instance_->BindGraphics(dc))
+ return "Failure to bind the boring device.";
+
+ ASSERT_TRUE(instance_->BindGraphics(pp::Graphics2D()));
+ ASSERT_TRUE(instance_->BindGraphics(pp::Graphics3D()));
+
+ PASS();
+}
+
diff --git a/ppapi/tests/test_graphics_2d.h b/ppapi/tests/test_graphics_2d.h
index 193aa44..4107504 100644
--- a/ppapi/tests/test_graphics_2d.h
+++ b/ppapi/tests/test_graphics_2d.h
@@ -66,6 +66,10 @@ class TestGraphics2D : public TestCase {
// Validates that the given device context is filled with the given color.
bool IsDCUniformColor(const pp::Graphics2D& dc, uint32_t color) const;
+ // Returns true if Graphics2D resource is created correctly.
+ bool ResourceHealthCheck(pp::Instance* instance, pp::Graphics2D* context);
+ bool ResourceHealthCheckForC(pp::Instance* instance, PP_Resource graphics_2d);
+
// Issues a flush on the given device context and blocks until the flush
// has issued its callback. Returns true on success.
bool FlushAndWaitForDone(pp::Graphics2D* context);
@@ -99,6 +103,7 @@ class TestGraphics2D : public TestCase {
std::string TestFlushOffscreenUpdate();
std::string TestDev();
std::string TestReplaceContentsCaching();
+ std::string TestBindNull();
// Used by the tests that access the C API directly.
const PPB_Graphics2D* graphics_2d_interface_;
diff --git a/ppapi/thunk/interfaces_ppb_public_stable.h b/ppapi/thunk/interfaces_ppb_public_stable.h
index 96f4a5e..6698943 100644
--- a/ppapi/thunk/interfaces_ppb_public_stable.h
+++ b/ppapi/thunk/interfaces_ppb_public_stable.h
@@ -22,7 +22,6 @@ PROXIED_API(PPB_Core)
PROXIED_API(PPB_FileIO)
PROXIED_API(PPB_FileRef)
PROXIED_API(PPB_FileSystem)
-PROXIED_API(PPB_Graphics2D)
PROXIED_API(PPB_Graphics3D)
PROXIED_API(PPB_ImageData)
PROXIED_API(PPB_Instance)
@@ -53,11 +52,11 @@ PROXIED_IFACE(PPB_FileIO, PPB_FILEIO_INTERFACE_1_0, PPB_FileIO_1_0)
PROXIED_IFACE(PPB_FileIO, PPB_FILEIO_INTERFACE_1_1, PPB_FileIO_1_1)
PROXIED_IFACE(PPB_FileRef, PPB_FILEREF_INTERFACE_1_0, PPB_FileRef_1_0)
PROXIED_IFACE(PPB_FileSystem, PPB_FILESYSTEM_INTERFACE_1_0, PPB_FileSystem_1_0)
-PROXIED_IFACE(PPB_Graphics2D, PPB_GRAPHICS_2D_INTERFACE_1_0, PPB_Graphics2D_1_0)
PROXIED_IFACE(PPB_Graphics3D, PPB_GRAPHICS_3D_INTERFACE_1_0, PPB_Graphics3D_1_0)
PROXIED_IFACE(PPB_ImageData, PPB_IMAGEDATA_INTERFACE_1_0, PPB_ImageData_1_0)
PROXIED_IFACE(PPB_Instance, PPB_GAMEPAD_INTERFACE_1_0, PPB_Gamepad_1_0)
PROXIED_IFACE(PPB_Instance, PPB_INSTANCE_INTERFACE_1_0, PPB_Instance_1_0)
+PROXIED_IFACE(NoAPIName, PPB_GRAPHICS_2D_INTERFACE_1_0, PPB_Graphics2D_1_0)
PROXIED_IFACE(NoAPIName, PPB_INPUT_EVENT_INTERFACE_1_0, PPB_InputEvent_1_0)
PROXIED_IFACE(NoAPIName, PPB_KEYBOARD_INPUT_EVENT_INTERFACE_1_0,
PPB_KeyboardInputEvent_1_0)
diff --git a/ppapi/thunk/ppb_graphics_2d_api.h b/ppapi/thunk/ppb_graphics_2d_api.h
index 6f14b93..e6357c3 100644
--- a/ppapi/thunk/ppb_graphics_2d_api.h
+++ b/ppapi/thunk/ppb_graphics_2d_api.h
@@ -2,6 +2,9 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
+#ifndef PPAPI_THUNK_PPB_GRAPHICS_2D_API_H_
+#define PPAPI_THUNK_PPB_GRAPHICS_2D_API_H_
+
#include "base/memory/ref_counted.h"
#include "ppapi/c/pp_bool.h"
#include "ppapi/c/pp_completion_callback.h"
@@ -9,6 +12,7 @@
#include "ppapi/c/pp_rect.h"
#include "ppapi/c/pp_resource.h"
#include "ppapi/c/pp_size.h"
+#include "ppapi/thunk/ppapi_thunk_export.h"
namespace ppapi {
@@ -16,7 +20,7 @@ class TrackedCallback;
namespace thunk {
-class PPB_Graphics2D_API {
+class PPAPI_THUNK_EXPORT PPB_Graphics2D_API {
public:
virtual ~PPB_Graphics2D_API() {}
@@ -41,7 +45,12 @@ class PPB_Graphics2D_API {
// destroyed if there was one.
virtual int32_t Flush(scoped_refptr<TrackedCallback> callback,
PP_Resource* old_image_data) = 0;
+
+ // Test only
+ virtual bool ReadImageData(PP_Resource image, const PP_Point* top_left) = 0;
};
} // namespace thunk
} // namespace ppapi
+
+#endif // PPAPI_THUNK_PPB_GRAPHICS_2D_API_H_
diff --git a/ppapi/thunk/ppb_image_data_api.h b/ppapi/thunk/ppb_image_data_api.h
index 32166c7..9546304 100644
--- a/ppapi/thunk/ppb_image_data_api.h
+++ b/ppapi/thunk/ppb_image_data_api.h
@@ -42,6 +42,11 @@ class PPB_ImageData_API {
// * If the image is not mapped.
// * Within untrusted code (which does not have skia).
virtual SkCanvas* GetCanvas() = 0;
+
+ // Sets whether this image was used in a ReplaceContents call. If the
+ // current implementation supports image data recycling (only supported
+ // out-of-process then it will be marked for potential re-use.
+ virtual void SetUsedInReplaceContents() = 0;
};
} // namespace thunk
diff --git a/webkit/plugins/ppapi/mock_plugin_delegate.cc b/webkit/plugins/ppapi/mock_plugin_delegate.cc
index 84a19ba..6294660 100644
--- a/webkit/plugins/ppapi/mock_plugin_delegate.cc
+++ b/webkit/plugins/ppapi/mock_plugin_delegate.cc
@@ -10,6 +10,7 @@
#include "ppapi/shared_impl/ppapi_preferences.h"
#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebGamepads.h"
#include "webkit/plugins/ppapi/mock_platform_image_2d.h"
+#include "webkit/plugins/ppapi/plugin_delegate.h"
#include "webkit/plugins/ppapi/ppapi_plugin_instance.h"
namespace webkit {
@@ -77,6 +78,12 @@ MockPluginDelegate::PlatformImage2D* MockPluginDelegate::CreateImage2D(
return new MockPlatformImage2D(width, height);
}
+PluginDelegate::PlatformGraphics2D* MockPluginDelegate::GetGraphics2D(
+ PluginInstance* instance,
+ PP_Resource graphics_2d) {
+ return NULL;
+}
+
MockPluginDelegate::PlatformContext3D* MockPluginDelegate::CreateContext3D() {
return NULL;
}
diff --git a/webkit/plugins/ppapi/mock_plugin_delegate.h b/webkit/plugins/ppapi/mock_plugin_delegate.h
index cb3a10e..bbf9d5a 100644
--- a/webkit/plugins/ppapi/mock_plugin_delegate.h
+++ b/webkit/plugins/ppapi/mock_plugin_delegate.h
@@ -37,6 +37,8 @@ class MockPluginDelegate : public PluginDelegate {
virtual SkBitmap* GetSadPluginBitmap();
virtual WebKit::WebPlugin* CreatePluginReplacement(const FilePath& file_path);
virtual PlatformImage2D* CreateImage2D(int width, int height);
+ virtual PlatformGraphics2D* GetGraphics2D(PluginInstance* instance,
+ PP_Resource graphics_2d);
virtual PlatformContext3D* CreateContext3D();
virtual void ReparentContext(PlatformContext3D*);
virtual PlatformVideoDecoder* CreateVideoDecoder(
diff --git a/webkit/plugins/ppapi/plugin_delegate.h b/webkit/plugins/ppapi/plugin_delegate.h
index 6f4f9bf..a781007 100644
--- a/webkit/plugins/ppapi/plugin_delegate.h
+++ b/webkit/plugins/ppapi/plugin_delegate.h
@@ -72,6 +72,7 @@ class ResourceCreationAPI;
} // namespace ppapi
namespace WebKit {
+typedef SkCanvas WebCanvas;
class WebGamepads;
class WebPlugin;
struct WebCompositionUnderline;
@@ -92,6 +93,8 @@ class FullscreenContainer;
class PluginInstance;
class PluginModule;
class PPB_Broker_Impl;
+class PPB_Flash_Menu_Impl;
+class PPB_ImageData_Impl;
class PPB_TCPSocket_Private_Impl;
class PPB_UDPSocket_Private_Impl;
@@ -167,6 +170,33 @@ class PluginDelegate {
virtual TransportDIB* GetTransportDIB() const = 0;
};
+ class PlatformGraphics2D {
+ public:
+ virtual bool ReadImageData(PP_Resource image, const PP_Point* top_left) = 0;
+
+ // Assciates this device with the given plugin instance. You can pass NULL
+ // to clear the existing device. Returns true on success. In this case, a
+ // repaint of the page will also be scheduled. Failure means that the device
+ // is already bound to a different instance, and nothing will happen.
+ virtual bool BindToInstance(PluginInstance* new_instance) = 0;
+
+ // Paints the current backing store to the web page.
+ virtual void Paint(WebKit::WebCanvas* canvas,
+ const gfx::Rect& plugin_rect,
+ const gfx::Rect& paint_rect) = 0;
+
+ // Notifications about the view's progress painting. See PluginInstance.
+ // These messages are used to send Flush callbacks to the plugin.
+ virtual void ViewWillInitiatePaint() = 0;
+ virtual void ViewInitiatedPaint() = 0;
+ virtual void ViewFlushedPaint() = 0;
+
+ virtual bool IsAlwaysOpaque() const = 0;
+ virtual void SetScale(float scale) = 0;
+ virtual float GetScale() const = 0;
+ virtual PPB_ImageData_Impl* ImageData() = 0;
+ };
+
class PlatformContext3D {
public:
virtual ~PlatformContext3D() {}
@@ -358,6 +388,10 @@ class PluginDelegate {
// The caller will own the pointer returned from this.
virtual PlatformImage2D* CreateImage2D(int width, int height) = 0;
+ // Returns the internal PlatformGraphics2D implementation.
+ virtual PlatformGraphics2D* GetGraphics2D(PluginInstance* instance,
+ PP_Resource graphics_2d) = 0;
+
// The caller will own the pointer returned from this.
virtual PlatformContext3D* CreateContext3D() = 0;
diff --git a/webkit/plugins/ppapi/plugin_module.cc b/webkit/plugins/ppapi/plugin_module.cc
index dd230ec..e993554 100644
--- a/webkit/plugins/ppapi/plugin_module.cc
+++ b/webkit/plugins/ppapi/plugin_module.cc
@@ -200,8 +200,7 @@ PP_Bool ReadImageData(PP_Resource device_context_2d,
EnterResource<PPB_Graphics2D_API> enter(device_context_2d, true);
if (enter.failed())
return PP_FALSE;
- return BoolToPPBool(static_cast<PPB_Graphics2D_Impl*>(enter.object())->
- ReadImageData(image, top_left));
+ return BoolToPPBool(enter.object()->ReadImageData(image, top_left));
}
void RunMessageLoop(PP_Instance instance) {
diff --git a/webkit/plugins/ppapi/ppapi_plugin_instance.cc b/webkit/plugins/ppapi/ppapi_plugin_instance.cc
index 409e115..2d10023 100644
--- a/webkit/plugins/ppapi/ppapi_plugin_instance.cc
+++ b/webkit/plugins/ppapi/ppapi_plugin_instance.cc
@@ -77,7 +77,6 @@
#include "webkit/plugins/ppapi/plugin_module.h"
#include "webkit/plugins/ppapi/plugin_object.h"
#include "webkit/plugins/ppapi/ppb_buffer_impl.h"
-#include "webkit/plugins/ppapi/ppb_graphics_2d_impl.h"
#include "webkit/plugins/ppapi/ppb_graphics_3d_impl.h"
#include "webkit/plugins/ppapi/ppb_image_data_impl.h"
#include "webkit/plugins/ppapi/ppb_url_loader_impl.h"
@@ -347,6 +346,7 @@ PluginInstance::PluginInstance(
full_frame_(false),
sent_initial_did_change_view_(false),
view_change_weak_ptr_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)),
+ bound_graphics_2d_platform_(NULL),
has_webkit_focus_(false),
has_content_area_focus_(false),
find_identifier_(-1),
@@ -464,7 +464,7 @@ void PluginInstance::Paint(WebCanvas* canvas,
return;
}
- PPB_Graphics2D_Impl* bound_graphics_2d = GetBoundGraphics2D();
+ PluginDelegate::PlatformGraphics2D* bound_graphics_2d = GetBoundGraphics2D();
if (bound_graphics_2d)
bound_graphics_2d->Paint(canvas, plugin_rect, paint_rect);
}
@@ -935,13 +935,13 @@ bool PluginInstance::GetBitmapForOptimizedPluginPaint(
float* scale_factor) {
if (!always_on_top_)
return false;
- if (!GetBoundGraphics2D() || !GetBoundGraphics2D()->is_always_opaque())
+ if (!GetBoundGraphics2D() || !GetBoundGraphics2D()->IsAlwaysOpaque())
return false;
// We specifically want to compare against the area covered by the backing
// store when seeing if we cover the given paint bounds, since the backing
// store could be smaller than the declared plugin area.
- PPB_ImageData_Impl* image_data = GetBoundGraphics2D()->image_data();
+ PPB_ImageData_Impl* image_data = GetBoundGraphics2D()->ImageData();
// ImageDatas created by NaCl don't have a PlatformImage, so can't be
// optimized this way.
if (!image_data->PlatformImage())
@@ -1698,22 +1698,14 @@ bool PluginInstance::PrintPDFOutput(PP_Resource print_output,
#endif
}
-PPB_Graphics2D_Impl* PluginInstance::GetBoundGraphics2D() const {
- if (bound_graphics_.get() == NULL)
- return NULL;
-
- if (bound_graphics_->AsPPB_Graphics2D_API())
- return static_cast<PPB_Graphics2D_Impl*>(bound_graphics_.get());
- return NULL;
+PluginDelegate::PlatformGraphics2D* PluginInstance::GetBoundGraphics2D() const {
+ return bound_graphics_2d_platform_;
}
PPB_Graphics3D_Impl* PluginInstance::GetBoundGraphics3D() const {
- if (bound_graphics_.get() == NULL)
+ if (bound_graphics_3d_.get() == NULL)
return NULL;
-
- if (bound_graphics_->AsPPB_Graphics3D_API())
- return static_cast<PPB_Graphics3D_Impl*>(bound_graphics_.get());
- return NULL;
+ return static_cast<PPB_Graphics3D_Impl*>(bound_graphics_3d_.get());
}
void PluginInstance::setBackingTextureId(unsigned int id, bool is_opaque) {
@@ -1874,14 +1866,16 @@ PP_Bool PluginInstance::BindGraphics(PP_Instance instance,
TRACE_EVENT0("ppapi", "PluginInstance::BindGraphics");
// The Graphics3D instance can't be destroyed until we call
// setBackingTextureId.
- scoped_refptr< ::ppapi::Resource> old_graphics = bound_graphics_;
- if (bound_graphics_.get()) {
- if (GetBoundGraphics2D()) {
- GetBoundGraphics2D()->BindToInstance(NULL);
- } else if (GetBoundGraphics3D()) {
+ scoped_refptr< ::ppapi::Resource> old_graphics = bound_graphics_3d_;
+ if (bound_graphics_3d_.get()) {
+ if (GetBoundGraphics3D()) {
GetBoundGraphics3D()->BindToInstance(false);
}
- bound_graphics_ = NULL;
+ bound_graphics_3d_ = NULL;
+ }
+ if (bound_graphics_2d_platform_) {
+ GetBoundGraphics2D()->BindToInstance(NULL);
+ bound_graphics_2d_platform_ = NULL;
}
// Special-case clearing the current device.
@@ -1897,21 +1891,16 @@ PP_Bool PluginInstance::BindGraphics(PP_Instance instance,
desired_fullscreen_state_ != view_data_.is_fullscreen)
return PP_FALSE;
- EnterResourceNoLock<PPB_Graphics2D_API> enter_2d(device, false);
- PPB_Graphics2D_Impl* graphics_2d = enter_2d.succeeded() ?
- static_cast<PPB_Graphics2D_Impl*>(enter_2d.object()) : NULL;
+ bound_graphics_2d_platform_ = delegate_->GetGraphics2D(this, device);
EnterResourceNoLock<PPB_Graphics3D_API> enter_3d(device, false);
PPB_Graphics3D_Impl* graphics_3d = enter_3d.succeeded() ?
static_cast<PPB_Graphics3D_Impl*>(enter_3d.object()) : NULL;
- if (graphics_2d) {
- if (graphics_2d->pp_instance() != pp_instance())
- return PP_FALSE; // Can't bind other instance's contexts.
- if (!graphics_2d->BindToInstance(this))
+ if (bound_graphics_2d_platform_) {
+ if (!bound_graphics_2d_platform_->BindToInstance(this))
return PP_FALSE; // Can't bind to more than one instance.
- bound_graphics_ = graphics_2d;
- setBackingTextureId(0, graphics_2d->is_always_opaque());
+ setBackingTextureId(0, bound_graphics_2d_platform_->IsAlwaysOpaque());
// BindToInstance will have invalidated the plugin if necessary.
} else if (graphics_3d) {
// Make sure graphics can only be bound to the instance it is
@@ -1921,7 +1910,7 @@ PP_Bool PluginInstance::BindGraphics(PP_Instance instance,
if (!graphics_3d->BindToInstance(true))
return PP_FALSE;
- bound_graphics_ = graphics_3d;
+ bound_graphics_3d_ = graphics_3d;
setBackingTextureId(graphics_3d->GetBackingTextureId(),
graphics_3d->IsOpaque());
} else {
diff --git a/webkit/plugins/ppapi/ppapi_plugin_instance.h b/webkit/plugins/ppapi/ppapi_plugin_instance.h
index e6c37e2..cab6cd4 100644
--- a/webkit/plugins/ppapi/ppapi_plugin_instance.h
+++ b/webkit/plugins/ppapi/ppapi_plugin_instance.h
@@ -87,7 +87,6 @@ class MessageChannel;
class PluginDelegate;
class PluginModule;
class PluginObject;
-class PPB_Graphics2D_Impl;
class PPB_Graphics3D_Impl;
class PPB_ImageData_Impl;
class PPB_URLLoader_Impl;
@@ -517,7 +516,7 @@ class WEBKIT_PLUGINS_EXPORT PluginInstance :
// Get the bound graphics context as a concrete 2D graphics context or returns
// null if the context is not 2D.
- PPB_Graphics2D_Impl* GetBoundGraphics2D() const;
+ PluginDelegate::PlatformGraphics2D* GetBoundGraphics2D() const;
// Get the bound 3D graphics context.
// Returns NULL if bound graphics is not a 3D context.
@@ -603,8 +602,9 @@ class WEBKIT_PLUGINS_EXPORT PluginInstance :
// view change events.
base::WeakPtrFactory<PluginInstance> view_change_weak_ptr_factory_;
- // The current device context for painting in 2D or 3D.
- scoped_refptr< ::ppapi::Resource> bound_graphics_;
+ // The current device context for painting in 2D and 3D.
+ scoped_refptr< ::ppapi::Resource> bound_graphics_3d_;
+ PluginDelegate::PlatformGraphics2D* bound_graphics_2d_platform_;
// We track two types of focus, one from WebKit, which is the focus among
// all elements of the page, one one from the browser, which is whether the
diff --git a/webkit/plugins/ppapi/ppb_graphics_2d_impl.h b/webkit/plugins/ppapi/ppb_graphics_2d_impl.h
index 5419daa..39461b8 100644
--- a/webkit/plugins/ppapi/ppb_graphics_2d_impl.h
+++ b/webkit/plugins/ppapi/ppb_graphics_2d_impl.h
@@ -22,20 +22,25 @@ class Point;
class Rect;
}
+namespace content {
+class PepperGraphics2DHost;
+}
+
namespace webkit {
namespace ppapi {
class PPB_ImageData_Impl;
class PluginInstance;
-class PPB_Graphics2D_Impl : public ::ppapi::Resource,
- public ::ppapi::thunk::PPB_Graphics2D_API {
+class WEBKIT_PLUGINS_EXPORT PPB_Graphics2D_Impl :
+ public ::ppapi::Resource,
+ public ::ppapi::thunk::PPB_Graphics2D_API {
public:
virtual ~PPB_Graphics2D_Impl();
- WEBKIT_PLUGINS_EXPORT static PP_Resource Create(PP_Instance instance,
- const PP_Size& size,
- PP_Bool is_always_opaque);
+ static PP_Resource Create(PP_Instance instance,
+ const PP_Size& size,
+ PP_Bool is_always_opaque);
bool is_always_opaque() const { return is_always_opaque_; }
@@ -83,9 +88,9 @@ class PPB_Graphics2D_Impl : public ::ppapi::Resource,
// pixels as well for scrolling cases. Returns false for scrolling cases where
// scaling either |op_rect| or |delta| would require scrolling to fall back to
// invalidation due to rounding errors, true otherwise.
- WEBKIT_PLUGINS_EXPORT static bool ConvertToLogicalPixels(float scale,
- gfx::Rect* op_rect,
- gfx::Point* delta);
+ static bool ConvertToLogicalPixels(float scale,
+ gfx::Rect* op_rect,
+ gfx::Point* delta);
private:
explicit PPB_Graphics2D_Impl(PP_Instance instance);
@@ -206,6 +211,7 @@ class PPB_Graphics2D_Impl : public ::ppapi::Resource,
base::WeakPtrFactory<PPB_Graphics2D_Impl> weak_ptr_factory_;
+ friend class content::PepperGraphics2DHost;
DISALLOW_COPY_AND_ASSIGN(PPB_Graphics2D_Impl);
};
diff --git a/webkit/plugins/ppapi/ppb_graphics_2d_impl_unittest.cc b/webkit/plugins/ppapi/ppb_graphics_2d_impl_unittest.cc
index c885378..644b8c0 100644
--- a/webkit/plugins/ppapi/ppb_graphics_2d_impl_unittest.cc
+++ b/webkit/plugins/ppapi/ppb_graphics_2d_impl_unittest.cc
@@ -87,6 +87,17 @@ TEST_F(PpapiGraphics2DImplTest, ConvertToLogicalPixels) {
}
}
+/*
+Disabled because this doesn't run with the new proxy design.
+TODO(brettw) Rewrite this test to use the new design.
+
+#if !defined(USE_AURA) && (defined(OS_WIN) || defined(OS_LINUX))
+// Windows and Linux don't support scaled optimized plugin paints ATM.
+#define MAYBE_GetBitmap2xScale DISABLED_GetBitmap2xScale
+#else
+#define MAYBE_GetBitmap2xScale GetBitmap2xScale
+#endif
+
// Test that GetBitmapForOptimizedPluginPaint doesn't return a bitmap rect
// that's bigger than the actual backing store bitmap.
TEST_F(PpapiGraphics2DImplTest, GetBitmap2xScale) {
@@ -119,6 +130,7 @@ TEST_F(PpapiGraphics2DImplTest, GetBitmap2xScale) {
EXPECT_EQ(size.height, clip.height());
EXPECT_EQ(scale, bitmap_scale);
}
+*/
} // namespace ppapi
} // namespace webkit
diff --git a/webkit/plugins/ppapi/ppb_image_data_impl.cc b/webkit/plugins/ppapi/ppb_image_data_impl.cc
index 4bdcbef..2d28f5e 100644
--- a/webkit/plugins/ppapi/ppb_image_data_impl.cc
+++ b/webkit/plugins/ppapi/ppb_image_data_impl.cc
@@ -128,6 +128,10 @@ SkCanvas* PPB_ImageData_Impl::GetCanvas() {
return backend_->GetCanvas();
}
+void PPB_ImageData_Impl::SetUsedInReplaceContents() {
+ // Nothing to do since we don't support image data re-use in-process.
+}
+
const SkBitmap* PPB_ImageData_Impl::GetMappedBitmap() const {
return backend_->GetMappedBitmap();
}
diff --git a/webkit/plugins/ppapi/ppb_image_data_impl.h b/webkit/plugins/ppapi/ppb_image_data_impl.h
index a0548709..f2dc043 100644
--- a/webkit/plugins/ppapi/ppb_image_data_impl.h
+++ b/webkit/plugins/ppapi/ppb_image_data_impl.h
@@ -91,6 +91,7 @@ class WEBKIT_PLUGINS_EXPORT PPB_ImageData_Impl
virtual int32_t GetSharedMemory(int* handle, uint32_t* byte_count) OVERRIDE;
virtual SkCanvas* GetPlatformCanvas() OVERRIDE;
virtual SkCanvas* GetCanvas() OVERRIDE;
+ virtual void SetUsedInReplaceContents() OVERRIDE;
const SkBitmap* GetMappedBitmap() const;
diff --git a/webkit/plugins/ppapi/resource_creation_impl.cc b/webkit/plugins/ppapi/resource_creation_impl.cc
index e1f883e..96713c8 100644
--- a/webkit/plugins/ppapi/resource_creation_impl.cc
+++ b/webkit/plugins/ppapi/resource_creation_impl.cc
@@ -18,7 +18,6 @@
#include "webkit/plugins/ppapi/ppb_file_ref_impl.h"
#include "webkit/plugins/ppapi/ppb_file_system_impl.h"
#include "webkit/plugins/ppapi/ppb_flash_message_loop_impl.h"
-#include "webkit/plugins/ppapi/ppb_graphics_2d_impl.h"
#include "webkit/plugins/ppapi/ppb_graphics_3d_impl.h"
#include "webkit/plugins/ppapi/ppb_host_resolver_private_impl.h"
#include "webkit/plugins/ppapi/ppb_image_data_impl.h"
@@ -123,13 +122,6 @@ PP_Resource ResourceCreationImpl::CreateFlashMessageLoop(PP_Instance instance) {
return PPB_Flash_MessageLoop_Impl::Create(instance);
}
-PP_Resource ResourceCreationImpl::CreateGraphics2D(
- PP_Instance instance,
- const PP_Size& size,
- PP_Bool is_always_opaque) {
- return PPB_Graphics2D_Impl::Create(instance, size, is_always_opaque);
-}
-
PP_Resource ResourceCreationImpl::CreateGraphics3D(
PP_Instance instance,
PP_Resource share_context,
diff --git a/webkit/plugins/ppapi/resource_creation_impl.h b/webkit/plugins/ppapi/resource_creation_impl.h
index 5a6c0c4..ea18798 100644
--- a/webkit/plugins/ppapi/resource_creation_impl.h
+++ b/webkit/plugins/ppapi/resource_creation_impl.h
@@ -48,9 +48,6 @@ class WEBKIT_PLUGINS_EXPORT ResourceCreationImpl
virtual PP_Resource CreateFlashMenu(PP_Instance instance,
const PP_Flash_Menu* menu_data) OVERRIDE;
virtual PP_Resource CreateFlashMessageLoop(PP_Instance instance) OVERRIDE;
- virtual PP_Resource CreateGraphics2D(PP_Instance pp_instance,
- const PP_Size& size,
- PP_Bool is_always_opaque) OVERRIDE;
virtual PP_Resource CreateGraphics3D(PP_Instance instance,
PP_Resource share_context,
const int32_t* attrib_list) OVERRIDE;