summaryrefslogtreecommitdiffstats
path: root/ppapi/proxy/ppb_graphics_2d_proxy.cc
diff options
context:
space:
mode:
authorbrettw@chromium.org <brettw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-06-01 07:19:31 +0000
committerbrettw@chromium.org <brettw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-06-01 07:19:31 +0000
commitcd910b93160f754297e51b27bdbc5f98cf52a743 (patch)
tree098dd0816260568abeae1662fa7de759e8372c49 /ppapi/proxy/ppb_graphics_2d_proxy.cc
parent20da3817eb403599ec87537bf2bc862446a13abf (diff)
downloadchromium_src-cd910b93160f754297e51b27bdbc5f98cf52a743.zip
chromium_src-cd910b93160f754297e51b27bdbc5f98cf52a743.tar.gz
chromium_src-cd910b93160f754297e51b27bdbc5f98cf52a743.tar.bz2
Convert more interfaces to the new thunk system. This goes up to and including
the ones starting with "F". Since this adds a lot more interfaces, I added the macro stuff we used for the old system to generate the various template specializations. This involded a lot of renaming since the As* needs to match the name (I was previously leaving off the "PPB_" part). I did other misc cleanup to the infrastructure. Review URL: http://codereview.chromium.org/7082036 Reland 87415 Review URL: http://codereview.chromium.org/7105013 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@87444 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ppapi/proxy/ppb_graphics_2d_proxy.cc')
-rw-r--r--ppapi/proxy/ppb_graphics_2d_proxy.cc107
1 files changed, 82 insertions, 25 deletions
diff --git a/ppapi/proxy/ppb_graphics_2d_proxy.cc b/ppapi/proxy/ppb_graphics_2d_proxy.cc
index 38777b7..8027956 100644
--- a/ppapi/proxy/ppb_graphics_2d_proxy.cc
+++ b/ppapi/proxy/ppb_graphics_2d_proxy.cc
@@ -12,14 +12,15 @@
#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.h"
#include "ppapi/proxy/ppapi_messages.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;
-using ::ppapi::thunk::EnterResource;
namespace pp {
namespace proxy {
@@ -33,7 +34,54 @@ InterfaceProxy* CreateGraphics2DProxy(Dispatcher* dispatcher,
} // namespace
-PPB_Graphics2D_API* Graphics2D::AsGraphics2D_API() {
+class Graphics2D : public PluginResource,
+ public ::ppapi::thunk::PPB_Graphics2D_API {
+ public:
+ Graphics2D(const HostResource& host_resource,
+ const PP_Size& size,
+ PP_Bool is_always_opaque);
+ virtual ~Graphics2D();
+
+ // ResourceObjectBase.
+ 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);
+ int32_t Flush(PP_CompletionCallback callback);
+
+ // Notification that the host has sent an ACK for a pending Flush.
+ void FlushACK(int32_t result_code);
+
+ private:
+ PP_Size size_;
+ PP_Bool is_always_opaque_;
+
+ // In the plugin, this is the current callback set for Flushes. When the
+ // callback function pointer is non-NULL, we're waiting for a flush ACK.
+ PP_CompletionCallback current_flush_callback_;
+
+ DISALLOW_COPY_AND_ASSIGN(Graphics2D);
+};
+
+Graphics2D::Graphics2D(const HostResource& host_resource,
+ const PP_Size& size,
+ PP_Bool is_always_opaque)
+ : PluginResource(host_resource),
+ size_(size),
+ is_always_opaque_(is_always_opaque),
+ current_flush_callback_(PP_BlockUntilComplete()) {
+}
+
+Graphics2D::~Graphics2D() {
+}
+
+PPB_Graphics2D_API* Graphics2D::AsPPB_Graphics2D_API() {
return this;
}
@@ -85,15 +133,19 @@ int32_t Graphics2D::Flush(PP_CompletionCallback callback) {
if (!callback.func)
return PP_ERROR_BADARGUMENT;
- if (is_flush_pending())
+ if (current_flush_callback_.func)
return PP_ERROR_INPROGRESS; // Can't have >1 flush pending.
- set_current_flush_callback(callback);
+ current_flush_callback_ = callback;
GetDispatcher()->Send(new PpapiHostMsg_PPBGraphics2D_Flush(
INTERFACE_ID_PPB_GRAPHICS_2D, host_resource()));
return PP_OK_COMPLETIONPENDING;
}
+void Graphics2D::FlushACK(int32_t result_code) {
+ PP_RunAndClearCompletionCallback(&current_flush_callback_, result_code);
+}
+
PPB_Graphics2D_Proxy::PPB_Graphics2D_Proxy(Dispatcher* dispatcher,
const void* target_interface)
: InterfaceProxy(dispatcher, target_interface),
@@ -115,6 +167,26 @@ const InterfaceProxy::Info* PPB_Graphics2D_Proxy::GetInfo() {
return &info;
}
+// 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_ResourceCreation_Graphics2D(
+ INTERFACE_ID_RESOURCE_CREATION, instance, size, is_always_opaque,
+ &result));
+ if (result.is_null())
+ return 0;
+ linked_ptr<Graphics2D> graphics_2d(new Graphics2D(result, size,
+ is_always_opaque));
+ return PluginResourceTracker::GetInstance()->AddResource(graphics_2d);
+}
+
bool PPB_Graphics2D_Proxy::OnMessageReceived(const IPC::Message& msg) {
bool handled = true;
IPC_BEGIN_MESSAGE_MAP(PPB_Graphics2D_Proxy, msg)
@@ -141,7 +213,7 @@ void PPB_Graphics2D_Proxy::OnMsgPaintImageData(
const PP_Point& top_left,
bool src_rect_specified,
const PP_Rect& src_rect) {
- EnterResource<PPB_Graphics2D_API> enter(graphics_2d.host_resource(), false);
+ EnterHostFromHostResource<PPB_Graphics2D_API> enter(graphics_2d);
if (enter.failed())
return;
enter.object()->PaintImageData(image_data.host_resource(), &top_left,
@@ -152,7 +224,7 @@ void PPB_Graphics2D_Proxy::OnMsgScroll(const HostResource& graphics_2d,
bool clip_specified,
const PP_Rect& clip,
const PP_Point& amount) {
- EnterResource<PPB_Graphics2D_API> enter(graphics_2d.host_resource(), false);
+ EnterHostFromHostResource<PPB_Graphics2D_API> enter(graphics_2d);
if (enter.failed())
return;
enter.object()->Scroll(clip_specified ? &clip : NULL, &amount);
@@ -161,7 +233,7 @@ void PPB_Graphics2D_Proxy::OnMsgScroll(const HostResource& graphics_2d,
void PPB_Graphics2D_Proxy::OnMsgReplaceContents(
const HostResource& graphics_2d,
const HostResource& image_data) {
- EnterResource<PPB_Graphics2D_API> enter(graphics_2d.host_resource(), false);
+ EnterHostFromHostResource<PPB_Graphics2D_API> enter(graphics_2d);
if (enter.failed())
return;
enter.object()->ReplaceContents(image_data.host_resource());
@@ -182,24 +254,9 @@ void PPB_Graphics2D_Proxy::OnMsgFlush(const HostResource& graphics_2d) {
void PPB_Graphics2D_Proxy::OnMsgFlushACK(const HostResource& host_resource,
int32_t pp_error) {
- PP_Resource plugin_resource =
- PluginResourceTracker::GetInstance()->PluginResourceForHostResource(
- host_resource);
- if (!plugin_resource)
- return;
-
- Graphics2D* object = PluginResource::GetAs<Graphics2D>(plugin_resource);
- if (!object) {
- // The plugin has released the graphics 2D object so don't issue the
- // callback.
- return;
- }
-
- // Be careful to make the callback NULL again before issuing the callback
- // since the plugin might want to flush from within the callback.
- PP_CompletionCallback callback = object->current_flush_callback();
- object->set_current_flush_callback(PP_BlockUntilComplete());
- PP_RunCompletionCallback(&callback, pp_error);
+ EnterPluginFromHostResource<PPB_Graphics2D_API> enter(host_resource);
+ if (enter.succeeded())
+ static_cast<Graphics2D*>(enter.object())->FlushACK(pp_error);
}
void PPB_Graphics2D_Proxy::SendFlushACKToPlugin(