Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(25)

Side by Side Diff: ppapi/proxy/ppb_graphics_2d_proxy.cc

Issue 7629017: Add a unified resource tracker shared between the proxy and the impl. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Address review comments Created 9 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "ppapi/proxy/ppb_graphics_2d_proxy.h" 5 #include "ppapi/proxy/ppb_graphics_2d_proxy.h"
6 6
7 #include <string.h> // For memset. 7 #include <string.h> // For memset.
8 8
9 #include "base/compiler_specific.h" 9 #include "base/compiler_specific.h"
10 #include "base/logging.h" 10 #include "base/logging.h"
11 #include "ppapi/c/pp_completion_callback.h" 11 #include "ppapi/c/pp_completion_callback.h"
12 #include "ppapi/c/pp_errors.h" 12 #include "ppapi/c/pp_errors.h"
13 #include "ppapi/c/pp_resource.h" 13 #include "ppapi/c/pp_resource.h"
14 #include "ppapi/c/ppb_graphics_2d.h" 14 #include "ppapi/c/ppb_graphics_2d.h"
15 #include "ppapi/proxy/enter_proxy.h" 15 #include "ppapi/proxy/enter_proxy.h"
16 #include "ppapi/proxy/plugin_dispatcher.h" 16 #include "ppapi/proxy/plugin_dispatcher.h"
17 #include "ppapi/proxy/plugin_resource.h"
18 #include "ppapi/proxy/ppapi_messages.h" 17 #include "ppapi/proxy/ppapi_messages.h"
19 #include "ppapi/thunk/enter.h" 18 #include "ppapi/thunk/enter.h"
20 #include "ppapi/thunk/ppb_graphics_2d_api.h" 19 #include "ppapi/thunk/ppb_graphics_2d_api.h"
21 #include "ppapi/thunk/thunk.h" 20 #include "ppapi/thunk/thunk.h"
22 21
23 using ppapi::HostResource; 22 using ppapi::HostResource;
23 using ppapi::Resource;
24 using ppapi::thunk::PPB_Graphics2D_API; 24 using ppapi::thunk::PPB_Graphics2D_API;
25 25
26 namespace pp { 26 namespace pp {
27 namespace proxy { 27 namespace proxy {
28 28
29 namespace { 29 namespace {
30 30
31 InterfaceProxy* CreateGraphics2DProxy(Dispatcher* dispatcher, 31 InterfaceProxy* CreateGraphics2DProxy(Dispatcher* dispatcher,
32 const void* target_interface) { 32 const void* target_interface) {
33 return new PPB_Graphics2D_Proxy(dispatcher, target_interface); 33 return new PPB_Graphics2D_Proxy(dispatcher, target_interface);
34 } 34 }
35 35
36 } // namespace 36 } // namespace
37 37
38 class Graphics2D : public PluginResource, 38 class Graphics2D : public ppapi::Resource,
39 public ::ppapi::thunk::PPB_Graphics2D_API { 39 public ppapi::thunk::PPB_Graphics2D_API {
40 public: 40 public:
41 Graphics2D(const HostResource& host_resource, 41 Graphics2D(const HostResource& host_resource,
42 const PP_Size& size, 42 const PP_Size& size,
43 PP_Bool is_always_opaque); 43 PP_Bool is_always_opaque);
44 virtual ~Graphics2D(); 44 virtual ~Graphics2D();
45 45
46 // ResourceObjectBase. 46 // Resource.
47 virtual PPB_Graphics2D_API* AsPPB_Graphics2D_API(); 47 virtual PPB_Graphics2D_API* AsPPB_Graphics2D_API();
48 48
49 // PPB_Graphics_2D_API. 49 // PPB_Graphics_2D_API.
50 PP_Bool Describe(PP_Size* size, PP_Bool* is_always_opaque); 50 PP_Bool Describe(PP_Size* size, PP_Bool* is_always_opaque);
51 void PaintImageData(PP_Resource image_data, 51 void PaintImageData(PP_Resource image_data,
52 const PP_Point* top_left, 52 const PP_Point* top_left,
53 const PP_Rect* src_rect); 53 const PP_Rect* src_rect);
54 void Scroll(const PP_Rect* clip_rect, 54 void Scroll(const PP_Rect* clip_rect,
55 const PP_Point* amount); 55 const PP_Point* amount);
56 void ReplaceContents(PP_Resource image_data); 56 void ReplaceContents(PP_Resource image_data);
57 int32_t Flush(PP_CompletionCallback callback); 57 int32_t Flush(PP_CompletionCallback callback);
58 58
59 // Notification that the host has sent an ACK for a pending Flush. 59 // Notification that the host has sent an ACK for a pending Flush.
60 void FlushACK(int32_t result_code); 60 void FlushACK(int32_t result_code);
61 61
62 private: 62 private:
63 PluginDispatcher* GetDispatcher() const {
64 return PluginDispatcher::GetForResource(this);
65 }
66
63 PP_Size size_; 67 PP_Size size_;
64 PP_Bool is_always_opaque_; 68 PP_Bool is_always_opaque_;
65 69
66 // In the plugin, this is the current callback set for Flushes. When the 70 // In the plugin, this is the current callback set for Flushes. When the
67 // callback function pointer is non-NULL, we're waiting for a flush ACK. 71 // callback function pointer is non-NULL, we're waiting for a flush ACK.
68 PP_CompletionCallback current_flush_callback_; 72 PP_CompletionCallback current_flush_callback_;
69 73
70 DISALLOW_COPY_AND_ASSIGN(Graphics2D); 74 DISALLOW_COPY_AND_ASSIGN(Graphics2D);
71 }; 75 };
72 76
73 Graphics2D::Graphics2D(const HostResource& host_resource, 77 Graphics2D::Graphics2D(const HostResource& host_resource,
74 const PP_Size& size, 78 const PP_Size& size,
75 PP_Bool is_always_opaque) 79 PP_Bool is_always_opaque)
76 : PluginResource(host_resource), 80 : Resource(host_resource),
77 size_(size), 81 size_(size),
78 is_always_opaque_(is_always_opaque), 82 is_always_opaque_(is_always_opaque),
79 current_flush_callback_(PP_BlockUntilComplete()) { 83 current_flush_callback_(PP_BlockUntilComplete()) {
80 } 84 }
81 85
82 Graphics2D::~Graphics2D() { 86 Graphics2D::~Graphics2D() {
83 } 87 }
84 88
85 PPB_Graphics2D_API* Graphics2D::AsPPB_Graphics2D_API() { 89 PPB_Graphics2D_API* Graphics2D::AsPPB_Graphics2D_API() {
86 return this; 90 return this;
87 } 91 }
88 92
89 PP_Bool Graphics2D::Describe(PP_Size* size, PP_Bool* is_always_opaque) { 93 PP_Bool Graphics2D::Describe(PP_Size* size, PP_Bool* is_always_opaque) {
90 *size = size_; 94 *size = size_;
91 *is_always_opaque = is_always_opaque_; 95 *is_always_opaque = is_always_opaque_;
92 return PP_TRUE; 96 return PP_TRUE;
93 } 97 }
94 98
95 void Graphics2D::PaintImageData(PP_Resource image_data, 99 void Graphics2D::PaintImageData(PP_Resource image_data,
96 const PP_Point* top_left, 100 const PP_Point* top_left,
97 const PP_Rect* src_rect) { 101 const PP_Rect* src_rect) {
98 PluginResource* image_object = PluginResourceTracker::GetInstance()-> 102 Resource* image_object = PluginResourceTracker::GetInstance()->
99 GetResourceObject(image_data); 103 GetResource(image_data);
100 //if (!image_object || instance() != image_object->instance()) 104 if (!image_object || pp_instance() != image_object->pp_instance())
101 // return; 105 return;
102 106
103 PP_Rect dummy; 107 PP_Rect dummy;
104 memset(&dummy, 0, sizeof(PP_Rect)); 108 memset(&dummy, 0, sizeof(PP_Rect));
105 GetDispatcher()->Send(new PpapiHostMsg_PPBGraphics2D_PaintImageData( 109 GetDispatcher()->Send(new PpapiHostMsg_PPBGraphics2D_PaintImageData(
106 INTERFACE_ID_PPB_GRAPHICS_2D, host_resource(), 110 INTERFACE_ID_PPB_GRAPHICS_2D, host_resource(),
107 image_object->host_resource(), *top_left, !!src_rect, 111 image_object->host_resource(), *top_left, !!src_rect,
108 src_rect ? *src_rect : dummy)); 112 src_rect ? *src_rect : dummy));
109 } 113 }
110 114
111 void Graphics2D::Scroll(const PP_Rect* clip_rect, 115 void Graphics2D::Scroll(const PP_Rect* clip_rect,
112 const PP_Point* amount) { 116 const PP_Point* amount) {
113 PP_Rect dummy; 117 PP_Rect dummy;
114 memset(&dummy, 0, sizeof(PP_Rect)); 118 memset(&dummy, 0, sizeof(PP_Rect));
115 GetDispatcher()->Send(new PpapiHostMsg_PPBGraphics2D_Scroll( 119 GetDispatcher()->Send(new PpapiHostMsg_PPBGraphics2D_Scroll(
116 INTERFACE_ID_PPB_GRAPHICS_2D, host_resource(), 120 INTERFACE_ID_PPB_GRAPHICS_2D, host_resource(),
117 !!clip_rect, clip_rect ? *clip_rect : dummy, *amount)); 121 !!clip_rect, clip_rect ? *clip_rect : dummy, *amount));
118 } 122 }
119 123
120 void Graphics2D::ReplaceContents(PP_Resource image_data) { 124 void Graphics2D::ReplaceContents(PP_Resource image_data) {
121 PluginResource* image_object = PluginResourceTracker::GetInstance()-> 125 Resource* image_object = PluginResourceTracker::GetInstance()->
122 GetResourceObject(image_data); 126 GetResource(image_data);
123 if (!image_object || instance() != image_object->instance()) 127 if (!image_object || pp_instance() != image_object->pp_instance())
124 return; 128 return;
125 129
126 GetDispatcher()->Send(new PpapiHostMsg_PPBGraphics2D_ReplaceContents( 130 GetDispatcher()->Send(new PpapiHostMsg_PPBGraphics2D_ReplaceContents(
127 INTERFACE_ID_PPB_GRAPHICS_2D, host_resource(), 131 INTERFACE_ID_PPB_GRAPHICS_2D, host_resource(),
128 image_object->host_resource())); 132 image_object->host_resource()));
129 } 133 }
130 134
131 int32_t Graphics2D::Flush(PP_CompletionCallback callback) { 135 int32_t Graphics2D::Flush(PP_CompletionCallback callback) {
132 // For now, disallow blocking calls. We'll need to add support for other 136 // For now, disallow blocking calls. We'll need to add support for other
133 // threads to this later. 137 // threads to this later.
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
176 PluginDispatcher* dispatcher = PluginDispatcher::GetForInstance(instance); 180 PluginDispatcher* dispatcher = PluginDispatcher::GetForInstance(instance);
177 if (!dispatcher) 181 if (!dispatcher)
178 return 0; 182 return 0;
179 183
180 HostResource result; 184 HostResource result;
181 dispatcher->Send(new PpapiHostMsg_ResourceCreation_Graphics2D( 185 dispatcher->Send(new PpapiHostMsg_ResourceCreation_Graphics2D(
182 INTERFACE_ID_RESOURCE_CREATION, instance, size, is_always_opaque, 186 INTERFACE_ID_RESOURCE_CREATION, instance, size, is_always_opaque,
183 &result)); 187 &result));
184 if (result.is_null()) 188 if (result.is_null())
185 return 0; 189 return 0;
186 return PluginResourceTracker::GetInstance()->AddResource( 190 return (new Graphics2D(result, size, is_always_opaque))->GetReference();
187 new Graphics2D(result, size, is_always_opaque));
188 } 191 }
189 192
190 bool PPB_Graphics2D_Proxy::OnMessageReceived(const IPC::Message& msg) { 193 bool PPB_Graphics2D_Proxy::OnMessageReceived(const IPC::Message& msg) {
191 bool handled = true; 194 bool handled = true;
192 IPC_BEGIN_MESSAGE_MAP(PPB_Graphics2D_Proxy, msg) 195 IPC_BEGIN_MESSAGE_MAP(PPB_Graphics2D_Proxy, msg)
193 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBGraphics2D_PaintImageData, 196 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBGraphics2D_PaintImageData,
194 OnMsgPaintImageData) 197 OnMsgPaintImageData)
195 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBGraphics2D_Scroll, 198 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBGraphics2D_Scroll,
196 OnMsgScroll) 199 OnMsgScroll)
197 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBGraphics2D_ReplaceContents, 200 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBGraphics2D_ReplaceContents,
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
257 260
258 void PPB_Graphics2D_Proxy::SendFlushACKToPlugin( 261 void PPB_Graphics2D_Proxy::SendFlushACKToPlugin(
259 int32_t result, 262 int32_t result,
260 const HostResource& graphics_2d) { 263 const HostResource& graphics_2d) {
261 dispatcher()->Send(new PpapiMsg_PPBGraphics2D_FlushACK( 264 dispatcher()->Send(new PpapiMsg_PPBGraphics2D_FlushACK(
262 INTERFACE_ID_PPB_GRAPHICS_2D, graphics_2d, result)); 265 INTERFACE_ID_PPB_GRAPHICS_2D, graphics_2d, result));
263 } 266 }
264 267
265 } // namespace proxy 268 } // namespace proxy
266 } // namespace pp 269 } // namespace pp
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698