| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 25 matching lines...) Expand all Loading... |
| 36 virtual PPB_Graphics2D_API* AsPPB_Graphics2D_API(); | 36 virtual PPB_Graphics2D_API* AsPPB_Graphics2D_API(); |
| 37 | 37 |
| 38 // PPB_Graphics_2D_API. | 38 // PPB_Graphics_2D_API. |
| 39 PP_Bool Describe(PP_Size* size, PP_Bool* is_always_opaque); | 39 PP_Bool Describe(PP_Size* size, PP_Bool* is_always_opaque); |
| 40 void PaintImageData(PP_Resource image_data, | 40 void PaintImageData(PP_Resource image_data, |
| 41 const PP_Point* top_left, | 41 const PP_Point* top_left, |
| 42 const PP_Rect* src_rect); | 42 const PP_Rect* src_rect); |
| 43 void Scroll(const PP_Rect* clip_rect, | 43 void Scroll(const PP_Rect* clip_rect, |
| 44 const PP_Point* amount); | 44 const PP_Point* amount); |
| 45 void ReplaceContents(PP_Resource image_data); | 45 void ReplaceContents(PP_Resource image_data); |
| 46 bool SetScale(float scale); |
| 47 float GetScale(); |
| 46 int32_t Flush(scoped_refptr<TrackedCallback> callback); | 48 int32_t Flush(scoped_refptr<TrackedCallback> callback); |
| 47 | 49 |
| 48 // Notification that the host has sent an ACK for a pending Flush. | 50 // Notification that the host has sent an ACK for a pending Flush. |
| 49 void FlushACK(int32_t result_code); | 51 void FlushACK(int32_t result_code); |
| 50 | 52 |
| 51 private: | 53 private: |
| 52 PluginDispatcher* GetDispatcher() const { | 54 PluginDispatcher* GetDispatcher() const { |
| 53 return PluginDispatcher::GetForResource(this); | 55 return PluginDispatcher::GetForResource(this); |
| 54 } | 56 } |
| 55 | 57 |
| 56 static const ApiID kApiID = API_ID_PPB_GRAPHICS_2D; | 58 static const ApiID kApiID = API_ID_PPB_GRAPHICS_2D; |
| 57 | 59 |
| 58 PP_Size size_; | 60 PP_Size size_; |
| 59 PP_Bool is_always_opaque_; | 61 PP_Bool is_always_opaque_; |
| 62 float scale_; |
| 60 | 63 |
| 61 // In the plugin, this is the current callback set for Flushes. When the | 64 // In the plugin, this is the current callback set for Flushes. When the |
| 62 // pointer is non-NULL, we're waiting for a flush ACK. | 65 // pointer is non-NULL, we're waiting for a flush ACK. |
| 63 scoped_refptr<TrackedCallback> current_flush_callback_; | 66 scoped_refptr<TrackedCallback> current_flush_callback_; |
| 64 | 67 |
| 65 DISALLOW_COPY_AND_ASSIGN(Graphics2D); | 68 DISALLOW_COPY_AND_ASSIGN(Graphics2D); |
| 66 }; | 69 }; |
| 67 | 70 |
| 68 Graphics2D::Graphics2D(const HostResource& host_resource, | 71 Graphics2D::Graphics2D(const HostResource& host_resource, |
| 69 const PP_Size& size, | 72 const PP_Size& size, |
| 70 PP_Bool is_always_opaque) | 73 PP_Bool is_always_opaque) |
| 71 : Resource(OBJECT_IS_PROXY, host_resource), | 74 : Resource(OBJECT_IS_PROXY, host_resource), |
| 72 size_(size), | 75 size_(size), |
| 73 is_always_opaque_(is_always_opaque) { | 76 is_always_opaque_(is_always_opaque), |
| 77 scale_(1.0f) { |
| 74 } | 78 } |
| 75 | 79 |
| 76 Graphics2D::~Graphics2D() { | 80 Graphics2D::~Graphics2D() { |
| 77 } | 81 } |
| 78 | 82 |
| 79 PPB_Graphics2D_API* Graphics2D::AsPPB_Graphics2D_API() { | 83 PPB_Graphics2D_API* Graphics2D::AsPPB_Graphics2D_API() { |
| 80 return this; | 84 return this; |
| 81 } | 85 } |
| 82 | 86 |
| 83 PP_Bool Graphics2D::Describe(PP_Size* size, PP_Bool* is_always_opaque) { | 87 PP_Bool Graphics2D::Describe(PP_Size* size, PP_Bool* is_always_opaque) { |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 119 if (!image_object || pp_instance() != image_object->pp_instance()) { | 123 if (!image_object || pp_instance() != image_object->pp_instance()) { |
| 120 Log(PP_LOGLEVEL_ERROR, | 124 Log(PP_LOGLEVEL_ERROR, |
| 121 "PPB_Graphics2D.PaintImageData: Bad image resource."); | 125 "PPB_Graphics2D.PaintImageData: Bad image resource."); |
| 122 return; | 126 return; |
| 123 } | 127 } |
| 124 | 128 |
| 125 GetDispatcher()->Send(new PpapiHostMsg_PPBGraphics2D_ReplaceContents( | 129 GetDispatcher()->Send(new PpapiHostMsg_PPBGraphics2D_ReplaceContents( |
| 126 kApiID, host_resource(), image_object->host_resource())); | 130 kApiID, host_resource(), image_object->host_resource())); |
| 127 } | 131 } |
| 128 | 132 |
| 133 bool Graphics2D::SetScale(float scale) { |
| 134 if (scale <= 0.0f) |
| 135 return false; |
| 136 GetDispatcher()->Send(new PpapiHostMsg_PPBGraphics2D_Dev_SetScale( |
| 137 kApiID, host_resource(), scale)); |
| 138 scale_ = scale; |
| 139 return true; |
| 140 } |
| 141 |
| 142 float Graphics2D::GetScale() { |
| 143 return scale_; |
| 144 } |
| 145 |
| 129 int32_t Graphics2D::Flush(scoped_refptr<TrackedCallback> callback) { | 146 int32_t Graphics2D::Flush(scoped_refptr<TrackedCallback> callback) { |
| 130 if (TrackedCallback::IsPending(current_flush_callback_)) | 147 if (TrackedCallback::IsPending(current_flush_callback_)) |
| 131 return PP_ERROR_INPROGRESS; // Can't have >1 flush pending. | 148 return PP_ERROR_INPROGRESS; // Can't have >1 flush pending. |
| 132 current_flush_callback_ = callback; | 149 current_flush_callback_ = callback; |
| 133 | 150 |
| 134 GetDispatcher()->Send(new PpapiHostMsg_PPBGraphics2D_Flush(kApiID, | 151 GetDispatcher()->Send(new PpapiHostMsg_PPBGraphics2D_Flush(kApiID, |
| 135 host_resource())); | 152 host_resource())); |
| 136 return PP_OK_COMPLETIONPENDING; | 153 return PP_OK_COMPLETIONPENDING; |
| 137 } | 154 } |
| 138 | 155 |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 171 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBGraphics2D_Create, | 188 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBGraphics2D_Create, |
| 172 OnHostMsgCreate) | 189 OnHostMsgCreate) |
| 173 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBGraphics2D_PaintImageData, | 190 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBGraphics2D_PaintImageData, |
| 174 OnHostMsgPaintImageData) | 191 OnHostMsgPaintImageData) |
| 175 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBGraphics2D_Scroll, | 192 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBGraphics2D_Scroll, |
| 176 OnHostMsgScroll) | 193 OnHostMsgScroll) |
| 177 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBGraphics2D_ReplaceContents, | 194 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBGraphics2D_ReplaceContents, |
| 178 OnHostMsgReplaceContents) | 195 OnHostMsgReplaceContents) |
| 179 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBGraphics2D_Flush, | 196 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBGraphics2D_Flush, |
| 180 OnHostMsgFlush) | 197 OnHostMsgFlush) |
| 198 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBGraphics2D_Dev_SetScale, |
| 199 OnHostMsgSetScale) |
| 181 | 200 |
| 182 IPC_MESSAGE_HANDLER(PpapiMsg_PPBGraphics2D_FlushACK, | 201 IPC_MESSAGE_HANDLER(PpapiMsg_PPBGraphics2D_FlushACK, |
| 183 OnPluginMsgFlushACK) | 202 OnPluginMsgFlushACK) |
| 184 IPC_MESSAGE_UNHANDLED(handled = false) | 203 IPC_MESSAGE_UNHANDLED(handled = false) |
| 185 IPC_END_MESSAGE_MAP() | 204 IPC_END_MESSAGE_MAP() |
| 186 // FIXME(brettw) handle bad messages! | 205 // FIXME(brettw) handle bad messages! |
| 187 return handled; | 206 return handled; |
| 188 } | 207 } |
| 189 | 208 |
| 190 void PPB_Graphics2D_Proxy::OnHostMsgCreate(PP_Instance instance, | 209 void PPB_Graphics2D_Proxy::OnHostMsgCreate(PP_Instance instance, |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 232 | 251 |
| 233 void PPB_Graphics2D_Proxy::OnHostMsgFlush(const HostResource& graphics_2d) { | 252 void PPB_Graphics2D_Proxy::OnHostMsgFlush(const HostResource& graphics_2d) { |
| 234 EnterHostFromHostResourceForceCallback<PPB_Graphics2D_API> enter( | 253 EnterHostFromHostResourceForceCallback<PPB_Graphics2D_API> enter( |
| 235 graphics_2d, callback_factory_, | 254 graphics_2d, callback_factory_, |
| 236 &PPB_Graphics2D_Proxy::SendFlushACKToPlugin, graphics_2d); | 255 &PPB_Graphics2D_Proxy::SendFlushACKToPlugin, graphics_2d); |
| 237 if (enter.failed()) | 256 if (enter.failed()) |
| 238 return; | 257 return; |
| 239 enter.SetResult(enter.object()->Flush(enter.callback())); | 258 enter.SetResult(enter.object()->Flush(enter.callback())); |
| 240 } | 259 } |
| 241 | 260 |
| 261 void PPB_Graphics2D_Proxy::OnHostMsgSetScale(const HostResource& graphics_2d, |
| 262 float scale) { |
| 263 EnterHostFromHostResource<PPB_Graphics2D_API> enter(graphics_2d); |
| 264 if (enter.failed()) |
| 265 return; |
| 266 enter.object()->SetScale(scale); |
| 267 } |
| 268 |
| 242 void PPB_Graphics2D_Proxy::OnPluginMsgFlushACK( | 269 void PPB_Graphics2D_Proxy::OnPluginMsgFlushACK( |
| 243 const HostResource& host_resource, | 270 const HostResource& host_resource, |
| 244 int32_t pp_error) { | 271 int32_t pp_error) { |
| 245 EnterPluginFromHostResource<PPB_Graphics2D_API> enter(host_resource); | 272 EnterPluginFromHostResource<PPB_Graphics2D_API> enter(host_resource); |
| 246 if (enter.succeeded()) | 273 if (enter.succeeded()) |
| 247 static_cast<Graphics2D*>(enter.object())->FlushACK(pp_error); | 274 static_cast<Graphics2D*>(enter.object())->FlushACK(pp_error); |
| 248 } | 275 } |
| 249 | 276 |
| 250 void PPB_Graphics2D_Proxy::SendFlushACKToPlugin( | 277 void PPB_Graphics2D_Proxy::SendFlushACKToPlugin( |
| 251 int32_t result, | 278 int32_t result, |
| 252 const HostResource& graphics_2d) { | 279 const HostResource& graphics_2d) { |
| 253 dispatcher()->Send(new PpapiMsg_PPBGraphics2D_FlushACK(kApiID, graphics_2d, | 280 dispatcher()->Send(new PpapiMsg_PPBGraphics2D_FlushACK(kApiID, graphics_2d, |
| 254 result)); | 281 result)); |
| 255 } | 282 } |
| 256 | 283 |
| 257 } // namespace proxy | 284 } // namespace proxy |
| 258 } // namespace ppapi | 285 } // namespace ppapi |
| OLD | NEW |