| 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 11 matching lines...) Expand all Loading... |
| 22 | 22 |
| 23 using ppapi::thunk::PPB_Graphics2D_API; | 23 using ppapi::thunk::PPB_Graphics2D_API; |
| 24 | 24 |
| 25 namespace ppapi { | 25 namespace ppapi { |
| 26 namespace proxy { | 26 namespace proxy { |
| 27 | 27 |
| 28 class Graphics2D : public Resource, public thunk::PPB_Graphics2D_API { | 28 class Graphics2D : public Resource, public thunk::PPB_Graphics2D_API { |
| 29 public: | 29 public: |
| 30 Graphics2D(const HostResource& host_resource, | 30 Graphics2D(const HostResource& host_resource, |
| 31 const PP_Size& size, | 31 const PP_Size& size, |
| 32 PP_Bool is_always_opaque); | 32 PP_Bool is_always_opaque, |
| 33 float scale); |
| 33 virtual ~Graphics2D(); | 34 virtual ~Graphics2D(); |
| 34 | 35 |
| 35 // Resource. | 36 // Resource. |
| 36 virtual PPB_Graphics2D_API* AsPPB_Graphics2D_API(); | 37 virtual PPB_Graphics2D_API* AsPPB_Graphics2D_API(); |
| 37 | 38 |
| 38 // PPB_Graphics_2D_API. | 39 // PPB_Graphics_2D_API. |
| 39 PP_Bool Describe(PP_Size* size, PP_Bool* is_always_opaque); | 40 PP_Bool Describe(PP_Size* size, PP_Bool* is_always_opaque); |
| 40 void PaintImageData(PP_Resource image_data, | 41 void PaintImageData(PP_Resource image_data, |
| 41 const PP_Point* top_left, | 42 const PP_Point* top_left, |
| 42 const PP_Rect* src_rect); | 43 const PP_Rect* src_rect); |
| 43 void Scroll(const PP_Rect* clip_rect, | 44 void Scroll(const PP_Rect* clip_rect, |
| 44 const PP_Point* amount); | 45 const PP_Point* amount); |
| 45 void ReplaceContents(PP_Resource image_data); | 46 void ReplaceContents(PP_Resource image_data); |
| 46 int32_t Flush(PP_CompletionCallback callback); | 47 int32_t Flush(PP_CompletionCallback callback); |
| 47 | 48 |
| 48 // Notification that the host has sent an ACK for a pending Flush. | 49 // Notification that the host has sent an ACK for a pending Flush. |
| 49 void FlushACK(int32_t result_code); | 50 void FlushACK(int32_t result_code); |
| 50 | 51 |
| 51 private: | 52 private: |
| 52 PluginDispatcher* GetDispatcher() const { | 53 PluginDispatcher* GetDispatcher() const { |
| 53 return PluginDispatcher::GetForResource(this); | 54 return PluginDispatcher::GetForResource(this); |
| 54 } | 55 } |
| 55 | 56 |
| 56 static const ApiID kApiID = API_ID_PPB_GRAPHICS_2D; | 57 static const ApiID kApiID = API_ID_PPB_GRAPHICS_2D; |
| 57 | 58 |
| 58 PP_Size size_; | 59 PP_Size size_; |
| 59 PP_Bool is_always_opaque_; | 60 PP_Bool is_always_opaque_; |
| 61 float scale_; |
| 60 | 62 |
| 61 // In the plugin, this is the current callback set for Flushes. When the | 63 // 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. | 64 // pointer is non-NULL, we're waiting for a flush ACK. |
| 63 scoped_refptr<TrackedCallback> current_flush_callback_; | 65 scoped_refptr<TrackedCallback> current_flush_callback_; |
| 64 | 66 |
| 65 DISALLOW_COPY_AND_ASSIGN(Graphics2D); | 67 DISALLOW_COPY_AND_ASSIGN(Graphics2D); |
| 66 }; | 68 }; |
| 67 | 69 |
| 68 Graphics2D::Graphics2D(const HostResource& host_resource, | 70 Graphics2D::Graphics2D(const HostResource& host_resource, |
| 69 const PP_Size& size, | 71 const PP_Size& size, |
| 70 PP_Bool is_always_opaque) | 72 PP_Bool is_always_opaque, |
| 73 float scale) |
| 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_(scale) { |
| 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 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 150 callback_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) { | 154 callback_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) { |
| 151 } | 155 } |
| 152 | 156 |
| 153 PPB_Graphics2D_Proxy::~PPB_Graphics2D_Proxy() { | 157 PPB_Graphics2D_Proxy::~PPB_Graphics2D_Proxy() { |
| 154 } | 158 } |
| 155 | 159 |
| 156 // static | 160 // static |
| 157 PP_Resource PPB_Graphics2D_Proxy::CreateProxyResource( | 161 PP_Resource PPB_Graphics2D_Proxy::CreateProxyResource( |
| 158 PP_Instance instance, | 162 PP_Instance instance, |
| 159 const PP_Size& size, | 163 const PP_Size& size, |
| 160 PP_Bool is_always_opaque) { | 164 PP_Bool is_always_opaque, |
| 165 float scale) { |
| 161 PluginDispatcher* dispatcher = PluginDispatcher::GetForInstance(instance); | 166 PluginDispatcher* dispatcher = PluginDispatcher::GetForInstance(instance); |
| 162 if (!dispatcher) | 167 if (!dispatcher) |
| 163 return 0; | 168 return 0; |
| 164 | 169 |
| 165 HostResource result; | 170 HostResource result; |
| 166 dispatcher->Send(new PpapiHostMsg_PPBGraphics2D_Create( | 171 dispatcher->Send(new PpapiHostMsg_PPBGraphics2D_Create( |
| 167 kApiID, instance, size, is_always_opaque, &result)); | 172 kApiID, instance, size, is_always_opaque, scale, &result)); |
| 168 if (result.is_null()) | 173 if (result.is_null()) |
| 169 return 0; | 174 return 0; |
| 170 return (new Graphics2D(result, size, is_always_opaque))->GetReference(); | 175 return (new Graphics2D(result, size, is_always_opaque, scale)) |
| 176 ->GetReference(); |
| 171 } | 177 } |
| 172 | 178 |
| 173 bool PPB_Graphics2D_Proxy::OnMessageReceived(const IPC::Message& msg) { | 179 bool PPB_Graphics2D_Proxy::OnMessageReceived(const IPC::Message& msg) { |
| 174 bool handled = true; | 180 bool handled = true; |
| 175 IPC_BEGIN_MESSAGE_MAP(PPB_Graphics2D_Proxy, msg) | 181 IPC_BEGIN_MESSAGE_MAP(PPB_Graphics2D_Proxy, msg) |
| 176 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBGraphics2D_Create, | 182 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBGraphics2D_Create, |
| 177 OnHostMsgCreate) | 183 OnHostMsgCreate) |
| 178 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBGraphics2D_PaintImageData, | 184 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBGraphics2D_PaintImageData, |
| 179 OnHostMsgPaintImageData) | 185 OnHostMsgPaintImageData) |
| 180 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBGraphics2D_Scroll, | 186 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBGraphics2D_Scroll, |
| 181 OnHostMsgScroll) | 187 OnHostMsgScroll) |
| 182 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBGraphics2D_ReplaceContents, | 188 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBGraphics2D_ReplaceContents, |
| 183 OnHostMsgReplaceContents) | 189 OnHostMsgReplaceContents) |
| 184 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBGraphics2D_Flush, | 190 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBGraphics2D_Flush, |
| 185 OnHostMsgFlush) | 191 OnHostMsgFlush) |
| 186 | 192 |
| 187 IPC_MESSAGE_HANDLER(PpapiMsg_PPBGraphics2D_FlushACK, | 193 IPC_MESSAGE_HANDLER(PpapiMsg_PPBGraphics2D_FlushACK, |
| 188 OnPluginMsgFlushACK) | 194 OnPluginMsgFlushACK) |
| 189 IPC_MESSAGE_UNHANDLED(handled = false) | 195 IPC_MESSAGE_UNHANDLED(handled = false) |
| 190 IPC_END_MESSAGE_MAP() | 196 IPC_END_MESSAGE_MAP() |
| 191 // FIXME(brettw) handle bad messages! | 197 // FIXME(brettw) handle bad messages! |
| 192 return handled; | 198 return handled; |
| 193 } | 199 } |
| 194 | 200 |
| 195 void PPB_Graphics2D_Proxy::OnHostMsgCreate(PP_Instance instance, | 201 void PPB_Graphics2D_Proxy::OnHostMsgCreate(PP_Instance instance, |
| 196 const PP_Size& size, | 202 const PP_Size& size, |
| 197 PP_Bool is_always_opaque, | 203 PP_Bool is_always_opaque, |
| 204 float scale, |
| 198 HostResource* result) { | 205 HostResource* result) { |
| 199 thunk::EnterResourceCreation enter(instance); | 206 thunk::EnterResourceCreation enter(instance); |
| 200 if (enter.succeeded()) { | 207 if (enter.succeeded()) { |
| 201 result->SetHostResource(instance, enter.functions()->CreateGraphics2D( | 208 result->SetHostResource(instance, enter.functions()->CreateGraphics2D( |
| 202 instance, size, is_always_opaque)); | 209 instance, size, is_always_opaque, scale)); |
| 203 } | 210 } |
| 204 } | 211 } |
| 205 | 212 |
| 206 void PPB_Graphics2D_Proxy::OnHostMsgPaintImageData( | 213 void PPB_Graphics2D_Proxy::OnHostMsgPaintImageData( |
| 207 const HostResource& graphics_2d, | 214 const HostResource& graphics_2d, |
| 208 const HostResource& image_data, | 215 const HostResource& image_data, |
| 209 const PP_Point& top_left, | 216 const PP_Point& top_left, |
| 210 bool src_rect_specified, | 217 bool src_rect_specified, |
| 211 const PP_Rect& src_rect) { | 218 const PP_Rect& src_rect) { |
| 212 EnterHostFromHostResource<PPB_Graphics2D_API> enter(graphics_2d); | 219 EnterHostFromHostResource<PPB_Graphics2D_API> enter(graphics_2d); |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 254 | 261 |
| 255 void PPB_Graphics2D_Proxy::SendFlushACKToPlugin( | 262 void PPB_Graphics2D_Proxy::SendFlushACKToPlugin( |
| 256 int32_t result, | 263 int32_t result, |
| 257 const HostResource& graphics_2d) { | 264 const HostResource& graphics_2d) { |
| 258 dispatcher()->Send(new PpapiMsg_PPBGraphics2D_FlushACK(kApiID, graphics_2d, | 265 dispatcher()->Send(new PpapiMsg_PPBGraphics2D_FlushACK(kApiID, graphics_2d, |
| 259 result)); | 266 result)); |
| 260 } | 267 } |
| 261 | 268 |
| 262 } // namespace proxy | 269 } // namespace proxy |
| 263 } // namespace ppapi | 270 } // namespace ppapi |
| OLD | NEW |