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

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

Issue 7082036: Convert more interfaces to the new thunk system. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 9 years, 6 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/plugin_dispatcher.h" 16 #include "ppapi/proxy/plugin_dispatcher.h"
16 #include "ppapi/proxy/plugin_resource.h" 17 #include "ppapi/proxy/plugin_resource.h"
17 #include "ppapi/proxy/ppapi_messages.h" 18 #include "ppapi/proxy/ppapi_messages.h"
18 #include "ppapi/thunk/enter.h" 19 #include "ppapi/thunk/enter.h"
20 #include "ppapi/thunk/ppb_graphics_2d_api.h"
19 #include "ppapi/thunk/thunk.h" 21 #include "ppapi/thunk/thunk.h"
20 22
21 using ::ppapi::thunk::PPB_Graphics2D_API; 23 using ::ppapi::thunk::PPB_Graphics2D_API;
22 using ::ppapi::thunk::EnterResource;
23 24
24 namespace pp { 25 namespace pp {
25 namespace proxy { 26 namespace proxy {
26 27
27 namespace { 28 namespace {
28 29
29 InterfaceProxy* CreateGraphics2DProxy(Dispatcher* dispatcher, 30 InterfaceProxy* CreateGraphics2DProxy(Dispatcher* dispatcher,
30 const void* target_interface) { 31 const void* target_interface) {
31 return new PPB_Graphics2D_Proxy(dispatcher, target_interface); 32 return new PPB_Graphics2D_Proxy(dispatcher, target_interface);
32 } 33 }
33 34
34 } // namespace 35 } // namespace
35 36
36 PPB_Graphics2D_API* Graphics2D::AsGraphics2D_API() { 37 class Graphics2D : public PluginResource,
38 public ::ppapi::thunk::PPB_Graphics2D_API {
39 public:
40 Graphics2D(const HostResource& host_resource,
41 const PP_Size& size,
42 PP_Bool is_always_opaque);
43 virtual ~Graphics2D();
44
45 // ResourceObjectBase.
46 virtual PPB_Graphics2D_API* AsPPB_Graphics2D_API();
47
48 // PPB_Graphics_2D_API.
49 PP_Bool Describe(PP_Size* size, PP_Bool* is_always_opaque);
50 void PaintImageData(PP_Resource image_data,
51 const PP_Point* top_left,
52 const PP_Rect* src_rect);
53 void Scroll(const PP_Rect* clip_rect,
54 const PP_Point* amount);
55 void ReplaceContents(PP_Resource image_data);
56 int32_t Flush(PP_CompletionCallback callback);
57
58 // Notification that the host has sent an ACK for a pending Flush.
59 void FlushACK(int32_t result_code);
60
61 private:
62 PP_Size size_;
63 PP_Bool is_always_opaque_;
64
65 // In the plugin, this is the current callback set for Flushes. When the
66 // callback function pointer is non-NULL, we're waiting for a flush ACK.
67 PP_CompletionCallback current_flush_callback_;
68
69 DISALLOW_COPY_AND_ASSIGN(Graphics2D);
70 };
71
72 Graphics2D::Graphics2D(const HostResource& host_resource,
73 const PP_Size& size,
74 PP_Bool is_always_opaque)
75 : PluginResource(host_resource),
76 size_(size),
77 is_always_opaque_(is_always_opaque),
78 current_flush_callback_(PP_BlockUntilComplete()) {
79 }
80
81 Graphics2D::~Graphics2D() {
82 }
83
84 PPB_Graphics2D_API* Graphics2D::AsPPB_Graphics2D_API() {
37 return this; 85 return this;
38 } 86 }
39 87
40 PP_Bool Graphics2D::Describe(PP_Size* size, PP_Bool* is_always_opaque) { 88 PP_Bool Graphics2D::Describe(PP_Size* size, PP_Bool* is_always_opaque) {
41 *size = size_; 89 *size = size_;
42 *is_always_opaque = is_always_opaque_; 90 *is_always_opaque = is_always_opaque_;
43 return PP_TRUE; 91 return PP_TRUE;
44 } 92 }
45 93
46 void Graphics2D::PaintImageData(PP_Resource image_data, 94 void Graphics2D::PaintImageData(PP_Resource image_data,
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
78 INTERFACE_ID_PPB_GRAPHICS_2D, host_resource(), 126 INTERFACE_ID_PPB_GRAPHICS_2D, host_resource(),
79 image_object->host_resource())); 127 image_object->host_resource()));
80 } 128 }
81 129
82 int32_t Graphics2D::Flush(PP_CompletionCallback callback) { 130 int32_t Graphics2D::Flush(PP_CompletionCallback callback) {
83 // For now, disallow blocking calls. We'll need to add support for other 131 // For now, disallow blocking calls. We'll need to add support for other
84 // threads to this later. 132 // threads to this later.
85 if (!callback.func) 133 if (!callback.func)
86 return PP_ERROR_BADARGUMENT; 134 return PP_ERROR_BADARGUMENT;
87 135
88 if (is_flush_pending()) 136 if (current_flush_callback_.func)
89 return PP_ERROR_INPROGRESS; // Can't have >1 flush pending. 137 return PP_ERROR_INPROGRESS; // Can't have >1 flush pending.
90 set_current_flush_callback(callback); 138 current_flush_callback_ = callback;
91 139
92 GetDispatcher()->Send(new PpapiHostMsg_PPBGraphics2D_Flush( 140 GetDispatcher()->Send(new PpapiHostMsg_PPBGraphics2D_Flush(
93 INTERFACE_ID_PPB_GRAPHICS_2D, host_resource())); 141 INTERFACE_ID_PPB_GRAPHICS_2D, host_resource()));
94 return PP_OK_COMPLETIONPENDING; 142 return PP_OK_COMPLETIONPENDING;
95 } 143 }
96 144
145 void Graphics2D::FlushACK(int32_t result_code) {
146 PP_RunAndClearCompletionCallback(&current_flush_callback_, result_code);
147 }
148
97 PPB_Graphics2D_Proxy::PPB_Graphics2D_Proxy(Dispatcher* dispatcher, 149 PPB_Graphics2D_Proxy::PPB_Graphics2D_Proxy(Dispatcher* dispatcher,
98 const void* target_interface) 150 const void* target_interface)
99 : InterfaceProxy(dispatcher, target_interface), 151 : InterfaceProxy(dispatcher, target_interface),
100 callback_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) { 152 callback_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) {
101 } 153 }
102 154
103 PPB_Graphics2D_Proxy::~PPB_Graphics2D_Proxy() { 155 PPB_Graphics2D_Proxy::~PPB_Graphics2D_Proxy() {
104 } 156 }
105 157
106 // static 158 // static
107 const InterfaceProxy::Info* PPB_Graphics2D_Proxy::GetInfo() { 159 const InterfaceProxy::Info* PPB_Graphics2D_Proxy::GetInfo() {
108 static const Info info = { 160 static const Info info = {
109 ::ppapi::thunk::GetPPB_Graphics2D_Thunk(), 161 ::ppapi::thunk::GetPPB_Graphics2D_Thunk(),
110 PPB_GRAPHICS_2D_INTERFACE, 162 PPB_GRAPHICS_2D_INTERFACE,
111 INTERFACE_ID_PPB_GRAPHICS_2D, 163 INTERFACE_ID_PPB_GRAPHICS_2D,
112 false, 164 false,
113 &CreateGraphics2DProxy, 165 &CreateGraphics2DProxy,
114 }; 166 };
115 return &info; 167 return &info;
116 } 168 }
117 169
170 // static
171 PP_Resource PPB_Graphics2D_Proxy::CreateProxyResource(
172 PP_Instance instance,
173 const PP_Size& size,
174 PP_Bool is_always_opaque) {
175 PluginDispatcher* dispatcher = PluginDispatcher::GetForInstance(instance);
176 if (!dispatcher)
177 return 0;
178
179 HostResource result;
180 dispatcher->Send(new PpapiHostMsg_ResourceCreation_Graphics2D(
181 INTERFACE_ID_RESOURCE_CREATION, instance, size, is_always_opaque,
182 &result));
183 if (result.is_null())
184 return 0;
185 linked_ptr<Graphics2D> graphics_2d(new Graphics2D(result, size,
186 is_always_opaque));
187 return PluginResourceTracker::GetInstance()->AddResource(graphics_2d);
188 }
189
118 bool PPB_Graphics2D_Proxy::OnMessageReceived(const IPC::Message& msg) { 190 bool PPB_Graphics2D_Proxy::OnMessageReceived(const IPC::Message& msg) {
119 bool handled = true; 191 bool handled = true;
120 IPC_BEGIN_MESSAGE_MAP(PPB_Graphics2D_Proxy, msg) 192 IPC_BEGIN_MESSAGE_MAP(PPB_Graphics2D_Proxy, msg)
121 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBGraphics2D_PaintImageData, 193 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBGraphics2D_PaintImageData,
122 OnMsgPaintImageData) 194 OnMsgPaintImageData)
123 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBGraphics2D_Scroll, 195 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBGraphics2D_Scroll,
124 OnMsgScroll) 196 OnMsgScroll)
125 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBGraphics2D_ReplaceContents, 197 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBGraphics2D_ReplaceContents,
126 OnMsgReplaceContents) 198 OnMsgReplaceContents)
127 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBGraphics2D_Flush, 199 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBGraphics2D_Flush,
128 OnMsgFlush) 200 OnMsgFlush)
129 201
130 IPC_MESSAGE_HANDLER(PpapiMsg_PPBGraphics2D_FlushACK, 202 IPC_MESSAGE_HANDLER(PpapiMsg_PPBGraphics2D_FlushACK,
131 OnMsgFlushACK) 203 OnMsgFlushACK)
132 IPC_MESSAGE_UNHANDLED(handled = false) 204 IPC_MESSAGE_UNHANDLED(handled = false)
133 IPC_END_MESSAGE_MAP() 205 IPC_END_MESSAGE_MAP()
134 // FIXME(brettw) handle bad messages! 206 // FIXME(brettw) handle bad messages!
135 return handled; 207 return handled;
136 } 208 }
137 209
138 void PPB_Graphics2D_Proxy::OnMsgPaintImageData( 210 void PPB_Graphics2D_Proxy::OnMsgPaintImageData(
139 const HostResource& graphics_2d, 211 const HostResource& graphics_2d,
140 const HostResource& image_data, 212 const HostResource& image_data,
141 const PP_Point& top_left, 213 const PP_Point& top_left,
142 bool src_rect_specified, 214 bool src_rect_specified,
143 const PP_Rect& src_rect) { 215 const PP_Rect& src_rect) {
144 EnterResource<PPB_Graphics2D_API> enter(graphics_2d.host_resource(), false); 216 EnterHostFromHostResource<PPB_Graphics2D_API> enter(graphics_2d);
145 if (enter.failed()) 217 if (enter.failed())
146 return; 218 return;
147 enter.object()->PaintImageData(image_data.host_resource(), &top_left, 219 enter.object()->PaintImageData(image_data.host_resource(), &top_left,
148 src_rect_specified ? &src_rect : NULL); 220 src_rect_specified ? &src_rect : NULL);
149 } 221 }
150 222
151 void PPB_Graphics2D_Proxy::OnMsgScroll(const HostResource& graphics_2d, 223 void PPB_Graphics2D_Proxy::OnMsgScroll(const HostResource& graphics_2d,
152 bool clip_specified, 224 bool clip_specified,
153 const PP_Rect& clip, 225 const PP_Rect& clip,
154 const PP_Point& amount) { 226 const PP_Point& amount) {
155 EnterResource<PPB_Graphics2D_API> enter(graphics_2d.host_resource(), false); 227 EnterHostFromHostResource<PPB_Graphics2D_API> enter(graphics_2d);
156 if (enter.failed()) 228 if (enter.failed())
157 return; 229 return;
158 enter.object()->Scroll(clip_specified ? &clip : NULL, &amount); 230 enter.object()->Scroll(clip_specified ? &clip : NULL, &amount);
159 } 231 }
160 232
161 void PPB_Graphics2D_Proxy::OnMsgReplaceContents( 233 void PPB_Graphics2D_Proxy::OnMsgReplaceContents(
162 const HostResource& graphics_2d, 234 const HostResource& graphics_2d,
163 const HostResource& image_data) { 235 const HostResource& image_data) {
164 EnterResource<PPB_Graphics2D_API> enter(graphics_2d.host_resource(), false); 236 EnterHostFromHostResource<PPB_Graphics2D_API> enter(graphics_2d);
165 if (enter.failed()) 237 if (enter.failed())
166 return; 238 return;
167 enter.object()->ReplaceContents(image_data.host_resource()); 239 enter.object()->ReplaceContents(image_data.host_resource());
168 } 240 }
169 241
170 void PPB_Graphics2D_Proxy::OnMsgFlush(const HostResource& graphics_2d) { 242 void PPB_Graphics2D_Proxy::OnMsgFlush(const HostResource& graphics_2d) {
171 CompletionCallback callback = callback_factory_.NewCallback( 243 CompletionCallback callback = callback_factory_.NewCallback(
172 &PPB_Graphics2D_Proxy::SendFlushACKToPlugin, graphics_2d); 244 &PPB_Graphics2D_Proxy::SendFlushACKToPlugin, graphics_2d);
173 int32_t result = ppb_graphics_2d_target()->Flush( 245 int32_t result = ppb_graphics_2d_target()->Flush(
174 graphics_2d.host_resource(), callback.pp_completion_callback()); 246 graphics_2d.host_resource(), callback.pp_completion_callback());
175 if (result != PP_OK_COMPLETIONPENDING) { 247 if (result != PP_OK_COMPLETIONPENDING) {
176 // There was some error, so we won't get a flush callback. We need to now 248 // There was some error, so we won't get a flush callback. We need to now
177 // issue the ACK to the plugin hears about the error. This will also clean 249 // issue the ACK to the plugin hears about the error. This will also clean
178 // up the data associated with the callback. 250 // up the data associated with the callback.
179 callback.Run(result); 251 callback.Run(result);
180 } 252 }
181 } 253 }
182 254
183 void PPB_Graphics2D_Proxy::OnMsgFlushACK(const HostResource& host_resource, 255 void PPB_Graphics2D_Proxy::OnMsgFlushACK(const HostResource& host_resource,
184 int32_t pp_error) { 256 int32_t pp_error) {
185 PP_Resource plugin_resource = 257 EnterPluginFromHostResource<PPB_Graphics2D_API> enter(host_resource);
186 PluginResourceTracker::GetInstance()->PluginResourceForHostResource( 258 if (enter.succeeded())
187 host_resource); 259 static_cast<Graphics2D*>(enter.object())->FlushACK(pp_error);
188 if (!plugin_resource)
189 return;
190
191 Graphics2D* object = PluginResource::GetAs<Graphics2D>(plugin_resource);
192 if (!object) {
193 // The plugin has released the graphics 2D object so don't issue the
194 // callback.
195 return;
196 }
197
198 // Be careful to make the callback NULL again before issuing the callback
199 // since the plugin might want to flush from within the callback.
200 PP_CompletionCallback callback = object->current_flush_callback();
201 object->set_current_flush_callback(PP_BlockUntilComplete());
202 PP_RunCompletionCallback(&callback, pp_error);
203 } 260 }
204 261
205 void PPB_Graphics2D_Proxy::SendFlushACKToPlugin( 262 void PPB_Graphics2D_Proxy::SendFlushACKToPlugin(
206 int32_t result, 263 int32_t result,
207 const HostResource& graphics_2d) { 264 const HostResource& graphics_2d) {
208 dispatcher()->Send(new PpapiMsg_PPBGraphics2D_FlushACK( 265 dispatcher()->Send(new PpapiMsg_PPBGraphics2D_FlushACK(
209 INTERFACE_ID_PPB_GRAPHICS_2D, graphics_2d, result)); 266 INTERFACE_ID_PPB_GRAPHICS_2D, graphics_2d, result));
210 } 267 }
211 268
212 } // namespace proxy 269 } // namespace proxy
213 } // namespace pp 270 } // namespace pp
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698