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-01-27 20:40:39 +0000
committerbrettw@chromium.org <brettw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-01-27 20:40:39 +0000
commitf24448db9f893c5dde10ed1ae4cead436e18f64f (patch)
treec224a27ed5949a761ed2f62b75cedae0fa2014e2 /ppapi/proxy/ppb_graphics_2d_proxy.cc
parente9319bf33e2b7e6bdd2fa005b212f2fcf0896883 (diff)
downloadchromium_src-f24448db9f893c5dde10ed1ae4cead436e18f64f.zip
chromium_src-f24448db9f893c5dde10ed1ae4cead436e18f64f.tar.gz
chromium_src-f24448db9f893c5dde10ed1ae4cead436e18f64f.tar.bz2
Refactor PPAPI proxy resource handling to maintain which host they came from,
and to map back to that host when calling functions on them. Adds a mapping between resources generated by the hosts to a new list inside the plugin so there can't be overlaps. This means there are now two meanings for a PP_Resource, one in the plugin process and one in the host process. This is potentially very confusing. I introduced a new object called a HostResource that always represents a "host" PP_Resource to try to prevent errors. In the plugin side of the proxy, it only deals with PP_Resources valid in the plugin, and SerializedResources valid in the host. It also encapsulates the associated instance, which simplifies some code. Each PluginResource object maintains its SerializedResource which the proxy uses to send to the host for requests. This requires getting the PluginResource object in more proxy calls. This fixes a bug in var sending introduced in my previous patch. The var releasing from EndSendPassRef used the host var rather than the plugin var. I had to add more plumbing to get the dispatcher at this location and convert to a plugin var. I removed the separate file for ImageData and put it in ppb_image_data_proxy like for the other resource types. TEST=some unit tests included BUG=none Review URL: http://codereview.chromium.org/6334016 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@72879 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ppapi/proxy/ppb_graphics_2d_proxy.cc')
-rw-r--r--ppapi/proxy/ppb_graphics_2d_proxy.cc114
1 files changed, 70 insertions, 44 deletions
diff --git a/ppapi/proxy/ppb_graphics_2d_proxy.cc b/ppapi/proxy/ppb_graphics_2d_proxy.cc
index 143ec44..be98e1d 100644
--- a/ppapi/proxy/ppb_graphics_2d_proxy.cc
+++ b/ppapi/proxy/ppb_graphics_2d_proxy.cc
@@ -1,4 +1,4 @@
-// Copyright (c) 2010 The Chromium Authors. All rights reserved.
+// Copyright (c) 2011 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.
@@ -21,14 +21,16 @@ namespace proxy {
class Graphics2D : public PluginResource {
public:
- Graphics2D(PP_Instance instance,
+ Graphics2D(const HostResource& host_resource,
const PP_Size& size,
PP_Bool is_always_opaque)
- : PluginResource(instance),
+ : PluginResource(host_resource),
size_(size),
is_always_opaque_(is_always_opaque),
current_flush_callback_(PP_BlockUntilComplete()) {
}
+ virtual ~Graphics2D() {
+ }
// Resource overrides.
virtual Graphics2D* AsGraphics2D() { return this; }
@@ -65,16 +67,15 @@ PP_Resource Create(PP_Instance instance,
if (!dispatcher)
return PP_ERROR_BADARGUMENT;
- PP_Resource result = 0;
+ HostResource result;
dispatcher->Send(new PpapiHostMsg_PPBGraphics2D_Create(
INTERFACE_ID_PPB_GRAPHICS_2D, instance, *size, is_always_opaque,
&result));
- if (result) {
- linked_ptr<Graphics2D> graphics_2d(new Graphics2D(instance, *size,
- is_always_opaque));
- PluginResourceTracker::GetInstance()->AddResource(result, graphics_2d);
- }
- return 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);
}
PP_Bool IsGraphics2D(PP_Resource resource) {
@@ -102,19 +103,27 @@ void PaintImageData(PP_Resource graphics_2d,
PP_Resource image_data,
const PP_Point* top_left,
const PP_Rect* src_rect) {
- Graphics2D* object = PluginResource::GetAs<Graphics2D>(graphics_2d);
- if (!object)
+ Graphics2D* graphics_object = PluginResource::GetAs<Graphics2D>(graphics_2d);
+ if (!graphics_object)
+ return;
+ PluginResource* image_object = PluginResourceTracker::GetInstance()->
+ GetResourceObject(image_data);
+ if (!image_object)
return;
+ if (graphics_object->instance() != image_object->instance())
+ return;
+
PluginDispatcher* dispatcher = PluginDispatcher::GetForInstance(
- object->instance());
+ graphics_object->instance());
if (!dispatcher)
return;
PP_Rect dummy;
memset(&dummy, 0, sizeof(PP_Rect));
dispatcher->Send(new PpapiHostMsg_PPBGraphics2D_PaintImageData(
- INTERFACE_ID_PPB_GRAPHICS_2D, graphics_2d, image_data, *top_left,
- !!src_rect, src_rect ? *src_rect : dummy));
+ INTERFACE_ID_PPB_GRAPHICS_2D, graphics_object->host_resource(),
+ image_object->host_resource(), *top_left, !!src_rect,
+ src_rect ? *src_rect : dummy));
}
void Scroll(PP_Resource graphics_2d,
@@ -131,21 +140,29 @@ void Scroll(PP_Resource graphics_2d,
PP_Rect dummy;
memset(&dummy, 0, sizeof(PP_Rect));
dispatcher->Send(new PpapiHostMsg_PPBGraphics2D_Scroll(
- INTERFACE_ID_PPB_GRAPHICS_2D, graphics_2d, !!clip_rect,
- clip_rect ? *clip_rect : dummy, *amount));
+ INTERFACE_ID_PPB_GRAPHICS_2D, object->host_resource(),
+ !!clip_rect, clip_rect ? *clip_rect : dummy, *amount));
}
void ReplaceContents(PP_Resource graphics_2d, PP_Resource image_data) {
- Graphics2D* object = PluginResource::GetAs<Graphics2D>(graphics_2d);
- if (!object)
+ Graphics2D* graphics_object = PluginResource::GetAs<Graphics2D>(graphics_2d);
+ if (!graphics_object)
+ return;
+ PluginResource* image_object = PluginResourceTracker::GetInstance()->
+ GetResourceObject(image_data);
+ if (!image_object)
return;
+ if (graphics_object->instance() != image_object->instance())
+ return;
+
PluginDispatcher* dispatcher = PluginDispatcher::GetForInstance(
- object->instance());
+ graphics_object->instance());
if (!dispatcher)
return;
dispatcher->Send(new PpapiHostMsg_PPBGraphics2D_ReplaceContents(
- INTERFACE_ID_PPB_GRAPHICS_2D, graphics_2d, image_data));
+ INTERFACE_ID_PPB_GRAPHICS_2D, graphics_object->host_resource(),
+ image_object->host_resource()));
}
int32_t Flush(PP_Resource graphics_2d,
@@ -168,7 +185,7 @@ int32_t Flush(PP_Resource graphics_2d,
object->set_current_flush_callback(callback);
dispatcher->Send(new PpapiHostMsg_PPBGraphics2D_Flush(
- INTERFACE_ID_PPB_GRAPHICS_2D, graphics_2d));
+ INTERFACE_ID_PPB_GRAPHICS_2D, object->host_resource()));
return PP_ERROR_WOULDBLOCK;
}
@@ -226,40 +243,42 @@ bool PPB_Graphics2D_Proxy::OnMessageReceived(const IPC::Message& msg) {
void PPB_Graphics2D_Proxy::OnMsgCreate(PP_Instance instance,
const PP_Size& size,
PP_Bool is_always_opaque,
- PP_Resource* result) {
- *result = ppb_graphics_2d_target()->Create(
- instance, &size, is_always_opaque);
+ HostResource* result) {
+ result->SetHostResource(instance, ppb_graphics_2d_target()->Create(
+ instance, &size, is_always_opaque));
}
-void PPB_Graphics2D_Proxy::OnMsgPaintImageData(PP_Resource graphics_2d,
- PP_Resource image_data,
- const PP_Point& top_left,
- bool src_rect_specified,
- const PP_Rect& src_rect) {
+void PPB_Graphics2D_Proxy::OnMsgPaintImageData(
+ const HostResource& graphics_2d,
+ const HostResource& image_data,
+ const PP_Point& top_left,
+ bool src_rect_specified,
+ const PP_Rect& src_rect) {
ppb_graphics_2d_target()->PaintImageData(
- graphics_2d, image_data, &top_left,
+ graphics_2d.host_resource(), image_data.host_resource(), &top_left,
src_rect_specified ? &src_rect : NULL);
}
-void PPB_Graphics2D_Proxy::OnMsgScroll(PP_Resource graphics_2d,
+void PPB_Graphics2D_Proxy::OnMsgScroll(const HostResource& graphics_2d,
bool clip_specified,
const PP_Rect& clip,
const PP_Point& amount) {
- ppb_graphics_2d_target()->Scroll(
- graphics_2d,
- clip_specified ? &clip : NULL, &amount);
+ ppb_graphics_2d_target()->Scroll(graphics_2d.host_resource(),
+ clip_specified ? &clip : NULL, &amount);
}
-void PPB_Graphics2D_Proxy::OnMsgReplaceContents(PP_Resource graphics_2d,
- PP_Resource image_data) {
- ppb_graphics_2d_target()->ReplaceContents(graphics_2d, image_data);
+void PPB_Graphics2D_Proxy::OnMsgReplaceContents(
+ const HostResource& graphics_2d,
+ const HostResource& image_data) {
+ ppb_graphics_2d_target()->ReplaceContents(graphics_2d.host_resource(),
+ image_data.host_resource());
}
-void PPB_Graphics2D_Proxy::OnMsgFlush(PP_Resource graphics_2d) {
+void PPB_Graphics2D_Proxy::OnMsgFlush(const HostResource& graphics_2d) {
CompletionCallback callback = callback_factory_.NewCallback(
&PPB_Graphics2D_Proxy::SendFlushACKToPlugin, graphics_2d);
int32_t result = ppb_graphics_2d_target()->Flush(
- graphics_2d, callback.pp_completion_callback());
+ graphics_2d.host_resource(), callback.pp_completion_callback());
if (result != PP_ERROR_WOULDBLOCK) {
// There was some error, so we won't get a flush callback. We need to now
// issue the ACK to the plugin hears about the error. This will also clean
@@ -268,9 +287,15 @@ void PPB_Graphics2D_Proxy::OnMsgFlush(PP_Resource graphics_2d) {
}
}
-void PPB_Graphics2D_Proxy::OnMsgFlushACK(PP_Resource resource,
+void PPB_Graphics2D_Proxy::OnMsgFlushACK(const HostResource& host_resource,
int32_t pp_error) {
- Graphics2D* object = PluginResource::GetAs<Graphics2D>(resource);
+ 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.
@@ -284,8 +309,9 @@ void PPB_Graphics2D_Proxy::OnMsgFlushACK(PP_Resource resource,
PP_RunCompletionCallback(&callback, pp_error);
}
-void PPB_Graphics2D_Proxy::SendFlushACKToPlugin(int32_t result,
- PP_Resource graphics_2d) {
+void PPB_Graphics2D_Proxy::SendFlushACKToPlugin(
+ int32_t result,
+ const HostResource& graphics_2d) {
dispatcher()->Send(new PpapiMsg_PPBGraphics2D_FlushACK(
INTERFACE_ID_PPB_GRAPHICS_2D, graphics_2d, result));
}