| OLD | NEW |
| 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" |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 45 int32_t Flush(PP_CompletionCallback callback); | 45 int32_t Flush(PP_CompletionCallback callback); |
| 46 | 46 |
| 47 // Notification that the host has sent an ACK for a pending Flush. | 47 // Notification that the host has sent an ACK for a pending Flush. |
| 48 void FlushACK(int32_t result_code); | 48 void FlushACK(int32_t result_code); |
| 49 | 49 |
| 50 private: | 50 private: |
| 51 PluginDispatcher* GetDispatcher() const { | 51 PluginDispatcher* GetDispatcher() const { |
| 52 return PluginDispatcher::GetForResource(this); | 52 return PluginDispatcher::GetForResource(this); |
| 53 } | 53 } |
| 54 | 54 |
| 55 static const ApiID kApiID = API_ID_PPB_GRAPHICS_2D; |
| 56 |
| 55 PP_Size size_; | 57 PP_Size size_; |
| 56 PP_Bool is_always_opaque_; | 58 PP_Bool is_always_opaque_; |
| 57 | 59 |
| 58 // In the plugin, this is the current callback set for Flushes. When the | 60 // In the plugin, this is the current callback set for Flushes. When the |
| 59 // callback function pointer is non-NULL, we're waiting for a flush ACK. | 61 // callback function pointer is non-NULL, we're waiting for a flush ACK. |
| 60 PP_CompletionCallback current_flush_callback_; | 62 PP_CompletionCallback current_flush_callback_; |
| 61 | 63 |
| 62 DISALLOW_COPY_AND_ASSIGN(Graphics2D); | 64 DISALLOW_COPY_AND_ASSIGN(Graphics2D); |
| 63 }; | 65 }; |
| 64 | 66 |
| (...skipping 23 matching lines...) Expand all Loading... |
| 88 const PP_Point* top_left, | 90 const PP_Point* top_left, |
| 89 const PP_Rect* src_rect) { | 91 const PP_Rect* src_rect) { |
| 90 Resource* image_object = | 92 Resource* image_object = |
| 91 PpapiGlobals::Get()->GetResourceTracker()->GetResource(image_data); | 93 PpapiGlobals::Get()->GetResourceTracker()->GetResource(image_data); |
| 92 if (!image_object || pp_instance() != image_object->pp_instance()) | 94 if (!image_object || pp_instance() != image_object->pp_instance()) |
| 93 return; | 95 return; |
| 94 | 96 |
| 95 PP_Rect dummy; | 97 PP_Rect dummy; |
| 96 memset(&dummy, 0, sizeof(PP_Rect)); | 98 memset(&dummy, 0, sizeof(PP_Rect)); |
| 97 GetDispatcher()->Send(new PpapiHostMsg_PPBGraphics2D_PaintImageData( | 99 GetDispatcher()->Send(new PpapiHostMsg_PPBGraphics2D_PaintImageData( |
| 98 API_ID_PPB_GRAPHICS_2D, host_resource(), | 100 kApiID, host_resource(), image_object->host_resource(), *top_left, |
| 99 image_object->host_resource(), *top_left, !!src_rect, | 101 !!src_rect, src_rect ? *src_rect : dummy)); |
| 100 src_rect ? *src_rect : dummy)); | |
| 101 } | 102 } |
| 102 | 103 |
| 103 void Graphics2D::Scroll(const PP_Rect* clip_rect, | 104 void Graphics2D::Scroll(const PP_Rect* clip_rect, |
| 104 const PP_Point* amount) { | 105 const PP_Point* amount) { |
| 105 PP_Rect dummy; | 106 PP_Rect dummy; |
| 106 memset(&dummy, 0, sizeof(PP_Rect)); | 107 memset(&dummy, 0, sizeof(PP_Rect)); |
| 107 GetDispatcher()->Send(new PpapiHostMsg_PPBGraphics2D_Scroll( | 108 GetDispatcher()->Send(new PpapiHostMsg_PPBGraphics2D_Scroll( |
| 108 API_ID_PPB_GRAPHICS_2D, host_resource(), | 109 kApiID, host_resource(), !!clip_rect, clip_rect ? *clip_rect : dummy, |
| 109 !!clip_rect, clip_rect ? *clip_rect : dummy, *amount)); | 110 *amount)); |
| 110 } | 111 } |
| 111 | 112 |
| 112 void Graphics2D::ReplaceContents(PP_Resource image_data) { | 113 void Graphics2D::ReplaceContents(PP_Resource image_data) { |
| 113 Resource* image_object = | 114 Resource* image_object = |
| 114 PpapiGlobals::Get()->GetResourceTracker()->GetResource(image_data); | 115 PpapiGlobals::Get()->GetResourceTracker()->GetResource(image_data); |
| 115 if (!image_object || pp_instance() != image_object->pp_instance()) | 116 if (!image_object || pp_instance() != image_object->pp_instance()) |
| 116 return; | 117 return; |
| 117 | 118 |
| 118 GetDispatcher()->Send(new PpapiHostMsg_PPBGraphics2D_ReplaceContents( | 119 GetDispatcher()->Send(new PpapiHostMsg_PPBGraphics2D_ReplaceContents( |
| 119 API_ID_PPB_GRAPHICS_2D, host_resource(), | 120 kApiID, host_resource(), image_object->host_resource())); |
| 120 image_object->host_resource())); | |
| 121 } | 121 } |
| 122 | 122 |
| 123 int32_t Graphics2D::Flush(PP_CompletionCallback callback) { | 123 int32_t Graphics2D::Flush(PP_CompletionCallback callback) { |
| 124 // For now, disallow blocking calls. We'll need to add support for other | 124 // For now, disallow blocking calls. We'll need to add support for other |
| 125 // threads to this later. | 125 // threads to this later. |
| 126 if (!callback.func) | 126 if (!callback.func) |
| 127 return PP_ERROR_BLOCKS_MAIN_THREAD; | 127 return PP_ERROR_BLOCKS_MAIN_THREAD; |
| 128 | 128 |
| 129 if (current_flush_callback_.func) | 129 if (current_flush_callback_.func) |
| 130 return PP_ERROR_INPROGRESS; // Can't have >1 flush pending. | 130 return PP_ERROR_INPROGRESS; // Can't have >1 flush pending. |
| 131 current_flush_callback_ = callback; | 131 current_flush_callback_ = callback; |
| 132 | 132 |
| 133 GetDispatcher()->Send(new PpapiHostMsg_PPBGraphics2D_Flush( | 133 GetDispatcher()->Send(new PpapiHostMsg_PPBGraphics2D_Flush(kApiID, |
| 134 API_ID_PPB_GRAPHICS_2D, host_resource())); | 134 host_resource())); |
| 135 return PP_OK_COMPLETIONPENDING; | 135 return PP_OK_COMPLETIONPENDING; |
| 136 } | 136 } |
| 137 | 137 |
| 138 void Graphics2D::FlushACK(int32_t result_code) { | 138 void Graphics2D::FlushACK(int32_t result_code) { |
| 139 PP_RunAndClearCompletionCallback(¤t_flush_callback_, result_code); | 139 PP_RunAndClearCompletionCallback(¤t_flush_callback_, result_code); |
| 140 } | 140 } |
| 141 | 141 |
| 142 PPB_Graphics2D_Proxy::PPB_Graphics2D_Proxy(Dispatcher* dispatcher) | 142 PPB_Graphics2D_Proxy::PPB_Graphics2D_Proxy(Dispatcher* dispatcher) |
| 143 : InterfaceProxy(dispatcher), | 143 : InterfaceProxy(dispatcher), |
| 144 callback_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) { | 144 callback_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) { |
| 145 } | 145 } |
| 146 | 146 |
| 147 PPB_Graphics2D_Proxy::~PPB_Graphics2D_Proxy() { | 147 PPB_Graphics2D_Proxy::~PPB_Graphics2D_Proxy() { |
| 148 } | 148 } |
| 149 | 149 |
| 150 // static | 150 // static |
| 151 PP_Resource PPB_Graphics2D_Proxy::CreateProxyResource( | 151 PP_Resource PPB_Graphics2D_Proxy::CreateProxyResource( |
| 152 PP_Instance instance, | 152 PP_Instance instance, |
| 153 const PP_Size& size, | 153 const PP_Size& size, |
| 154 PP_Bool is_always_opaque) { | 154 PP_Bool is_always_opaque) { |
| 155 PluginDispatcher* dispatcher = PluginDispatcher::GetForInstance(instance); | 155 PluginDispatcher* dispatcher = PluginDispatcher::GetForInstance(instance); |
| 156 if (!dispatcher) | 156 if (!dispatcher) |
| 157 return 0; | 157 return 0; |
| 158 | 158 |
| 159 HostResource result; | 159 HostResource result; |
| 160 dispatcher->Send(new PpapiHostMsg_ResourceCreation_Graphics2D( | 160 dispatcher->Send(new PpapiHostMsg_PPBGraphics2D_Create( |
| 161 API_ID_RESOURCE_CREATION, instance, size, is_always_opaque, | 161 kApiID, instance, size, is_always_opaque, &result)); |
| 162 &result)); | |
| 163 if (result.is_null()) | 162 if (result.is_null()) |
| 164 return 0; | 163 return 0; |
| 165 return (new Graphics2D(result, size, is_always_opaque))->GetReference(); | 164 return (new Graphics2D(result, size, is_always_opaque))->GetReference(); |
| 166 } | 165 } |
| 167 | 166 |
| 168 bool PPB_Graphics2D_Proxy::OnMessageReceived(const IPC::Message& msg) { | 167 bool PPB_Graphics2D_Proxy::OnMessageReceived(const IPC::Message& msg) { |
| 169 bool handled = true; | 168 bool handled = true; |
| 170 IPC_BEGIN_MESSAGE_MAP(PPB_Graphics2D_Proxy, msg) | 169 IPC_BEGIN_MESSAGE_MAP(PPB_Graphics2D_Proxy, msg) |
| 170 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBGraphics2D_Create, |
| 171 OnHostMsgCreate) |
| 171 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBGraphics2D_PaintImageData, | 172 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBGraphics2D_PaintImageData, |
| 172 OnMsgPaintImageData) | 173 OnHostMsgPaintImageData) |
| 173 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBGraphics2D_Scroll, | 174 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBGraphics2D_Scroll, |
| 174 OnMsgScroll) | 175 OnHostMsgScroll) |
| 175 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBGraphics2D_ReplaceContents, | 176 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBGraphics2D_ReplaceContents, |
| 176 OnMsgReplaceContents) | 177 OnHostMsgReplaceContents) |
| 177 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBGraphics2D_Flush, | 178 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBGraphics2D_Flush, |
| 178 OnMsgFlush) | 179 OnHostMsgFlush) |
| 179 | 180 |
| 180 IPC_MESSAGE_HANDLER(PpapiMsg_PPBGraphics2D_FlushACK, | 181 IPC_MESSAGE_HANDLER(PpapiMsg_PPBGraphics2D_FlushACK, |
| 181 OnMsgFlushACK) | 182 OnPluginMsgFlushACK) |
| 182 IPC_MESSAGE_UNHANDLED(handled = false) | 183 IPC_MESSAGE_UNHANDLED(handled = false) |
| 183 IPC_END_MESSAGE_MAP() | 184 IPC_END_MESSAGE_MAP() |
| 184 // FIXME(brettw) handle bad messages! | 185 // FIXME(brettw) handle bad messages! |
| 185 return handled; | 186 return handled; |
| 186 } | 187 } |
| 187 | 188 |
| 188 void PPB_Graphics2D_Proxy::OnMsgPaintImageData( | 189 void PPB_Graphics2D_Proxy::OnHostMsgCreate(PP_Instance instance, |
| 190 const PP_Size& size, |
| 191 PP_Bool is_always_opaque, |
| 192 HostResource* result) { |
| 193 thunk::EnterResourceCreation enter(instance); |
| 194 if (enter.succeeded()) { |
| 195 result->SetHostResource(instance, enter.functions()->CreateGraphics2D( |
| 196 instance, size, is_always_opaque)); |
| 197 } |
| 198 } |
| 199 |
| 200 void PPB_Graphics2D_Proxy::OnHostMsgPaintImageData( |
| 189 const HostResource& graphics_2d, | 201 const HostResource& graphics_2d, |
| 190 const HostResource& image_data, | 202 const HostResource& image_data, |
| 191 const PP_Point& top_left, | 203 const PP_Point& top_left, |
| 192 bool src_rect_specified, | 204 bool src_rect_specified, |
| 193 const PP_Rect& src_rect) { | 205 const PP_Rect& src_rect) { |
| 194 EnterHostFromHostResource<PPB_Graphics2D_API> enter(graphics_2d); | 206 EnterHostFromHostResource<PPB_Graphics2D_API> enter(graphics_2d); |
| 195 if (enter.failed()) | 207 if (enter.failed()) |
| 196 return; | 208 return; |
| 197 enter.object()->PaintImageData(image_data.host_resource(), &top_left, | 209 enter.object()->PaintImageData(image_data.host_resource(), &top_left, |
| 198 src_rect_specified ? &src_rect : NULL); | 210 src_rect_specified ? &src_rect : NULL); |
| 199 } | 211 } |
| 200 | 212 |
| 201 void PPB_Graphics2D_Proxy::OnMsgScroll(const HostResource& graphics_2d, | 213 void PPB_Graphics2D_Proxy::OnHostMsgScroll(const HostResource& graphics_2d, |
| 202 bool clip_specified, | 214 bool clip_specified, |
| 203 const PP_Rect& clip, | 215 const PP_Rect& clip, |
| 204 const PP_Point& amount) { | 216 const PP_Point& amount) { |
| 205 EnterHostFromHostResource<PPB_Graphics2D_API> enter(graphics_2d); | 217 EnterHostFromHostResource<PPB_Graphics2D_API> enter(graphics_2d); |
| 206 if (enter.failed()) | 218 if (enter.failed()) |
| 207 return; | 219 return; |
| 208 enter.object()->Scroll(clip_specified ? &clip : NULL, &amount); | 220 enter.object()->Scroll(clip_specified ? &clip : NULL, &amount); |
| 209 } | 221 } |
| 210 | 222 |
| 211 void PPB_Graphics2D_Proxy::OnMsgReplaceContents( | 223 void PPB_Graphics2D_Proxy::OnHostMsgReplaceContents( |
| 212 const HostResource& graphics_2d, | 224 const HostResource& graphics_2d, |
| 213 const HostResource& image_data) { | 225 const HostResource& image_data) { |
| 214 EnterHostFromHostResource<PPB_Graphics2D_API> enter(graphics_2d); | 226 EnterHostFromHostResource<PPB_Graphics2D_API> enter(graphics_2d); |
| 215 if (enter.failed()) | 227 if (enter.failed()) |
| 216 return; | 228 return; |
| 217 enter.object()->ReplaceContents(image_data.host_resource()); | 229 enter.object()->ReplaceContents(image_data.host_resource()); |
| 218 } | 230 } |
| 219 | 231 |
| 220 void PPB_Graphics2D_Proxy::OnMsgFlush(const HostResource& graphics_2d) { | 232 void PPB_Graphics2D_Proxy::OnHostMsgFlush(const HostResource& graphics_2d) { |
| 221 EnterHostFromHostResourceForceCallback<PPB_Graphics2D_API> enter( | 233 EnterHostFromHostResourceForceCallback<PPB_Graphics2D_API> enter( |
| 222 graphics_2d, callback_factory_, | 234 graphics_2d, callback_factory_, |
| 223 &PPB_Graphics2D_Proxy::SendFlushACKToPlugin, graphics_2d); | 235 &PPB_Graphics2D_Proxy::SendFlushACKToPlugin, graphics_2d); |
| 224 if (enter.failed()) | 236 if (enter.failed()) |
| 225 return; | 237 return; |
| 226 enter.SetResult(enter.object()->Flush(enter.callback())); | 238 enter.SetResult(enter.object()->Flush(enter.callback())); |
| 227 } | 239 } |
| 228 | 240 |
| 229 void PPB_Graphics2D_Proxy::OnMsgFlushACK(const HostResource& host_resource, | 241 void PPB_Graphics2D_Proxy::OnPluginMsgFlushACK( |
| 230 int32_t pp_error) { | 242 const HostResource& host_resource, |
| 243 int32_t pp_error) { |
| 231 EnterPluginFromHostResource<PPB_Graphics2D_API> enter(host_resource); | 244 EnterPluginFromHostResource<PPB_Graphics2D_API> enter(host_resource); |
| 232 if (enter.succeeded()) | 245 if (enter.succeeded()) |
| 233 static_cast<Graphics2D*>(enter.object())->FlushACK(pp_error); | 246 static_cast<Graphics2D*>(enter.object())->FlushACK(pp_error); |
| 234 } | 247 } |
| 235 | 248 |
| 236 void PPB_Graphics2D_Proxy::SendFlushACKToPlugin( | 249 void PPB_Graphics2D_Proxy::SendFlushACKToPlugin( |
| 237 int32_t result, | 250 int32_t result, |
| 238 const HostResource& graphics_2d) { | 251 const HostResource& graphics_2d) { |
| 239 dispatcher()->Send(new PpapiMsg_PPBGraphics2D_FlushACK( | 252 dispatcher()->Send(new PpapiMsg_PPBGraphics2D_FlushACK(kApiID, graphics_2d, |
| 240 API_ID_PPB_GRAPHICS_2D, graphics_2d, result)); | 253 result)); |
| 241 } | 254 } |
| 242 | 255 |
| 243 } // namespace proxy | 256 } // namespace proxy |
| 244 } // namespace ppapi | 257 } // namespace ppapi |
| OLD | NEW |