OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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/logging.h" | 9 #include "base/logging.h" |
10 #include "ppapi/c/pp_completion_callback.h" | 10 #include "ppapi/c/pp_completion_callback.h" |
11 #include "ppapi/c/pp_errors.h" | 11 #include "ppapi/c/pp_errors.h" |
12 #include "ppapi/c/pp_resource.h" | 12 #include "ppapi/c/pp_resource.h" |
13 #include "ppapi/c/ppb_graphics_2d.h" | 13 #include "ppapi/c/ppb_graphics_2d.h" |
14 #include "ppapi/proxy/plugin_dispatcher.h" | 14 #include "ppapi/proxy/plugin_dispatcher.h" |
15 #include "ppapi/proxy/plugin_resource.h" | 15 #include "ppapi/proxy/plugin_resource.h" |
16 #include "ppapi/proxy/ppapi_messages.h" | 16 #include "ppapi/proxy/ppapi_messages.h" |
17 | 17 |
18 namespace pp { | 18 namespace pp { |
19 namespace proxy { | 19 namespace proxy { |
20 | 20 |
21 class Graphics2D : public PluginResource { | 21 class Graphics2D : public PluginResource { |
22 public: | 22 public: |
23 Graphics2D(const PP_Size& size, bool is_always_opaque) | 23 Graphics2D(const PP_Size& size, PP_Bool is_always_opaque) |
24 : size_(size), is_always_opaque_(is_always_opaque) { | 24 : size_(size), is_always_opaque_(is_always_opaque) { |
25 } | 25 } |
26 | 26 |
27 // Resource overrides. | 27 // Resource overrides. |
28 virtual Graphics2D* AsGraphics2D() { return this; } | 28 virtual Graphics2D* AsGraphics2D() { return this; } |
29 | 29 |
30 const PP_Size& size() const { return size_; } | 30 const PP_Size& size() const { return size_; } |
31 bool is_always_opaque() const { return is_always_opaque_; } | 31 PP_Bool is_always_opaque() const { return is_always_opaque_; } |
32 | 32 |
33 private: | 33 private: |
34 PP_Size size_; | 34 PP_Size size_; |
35 bool is_always_opaque_; | 35 PP_Bool is_always_opaque_; |
36 | 36 |
37 DISALLOW_COPY_AND_ASSIGN(Graphics2D); | 37 DISALLOW_COPY_AND_ASSIGN(Graphics2D); |
38 }; | 38 }; |
39 | 39 |
40 namespace { | 40 namespace { |
41 | 41 |
42 PP_Resource Create(PP_Module module_id, | 42 PP_Resource Create(PP_Module module_id, |
43 const PP_Size* size, | 43 const PP_Size* size, |
44 bool is_always_opaque) { | 44 PP_Bool is_always_opaque) { |
45 PluginDispatcher* dispatcher = PluginDispatcher::Get(); | 45 PluginDispatcher* dispatcher = PluginDispatcher::Get(); |
46 PP_Resource result = 0; | 46 PP_Resource result = 0; |
47 dispatcher->Send(new PpapiHostMsg_PPBGraphics2D_Create( | 47 dispatcher->Send(new PpapiHostMsg_PPBGraphics2D_Create( |
48 INTERFACE_ID_PPB_GRAPHICS_2D, module_id, *size, is_always_opaque, | 48 INTERFACE_ID_PPB_GRAPHICS_2D, module_id, *size, is_always_opaque, |
49 &result)); | 49 &result)); |
50 if (result) { | 50 if (result) { |
51 linked_ptr<Graphics2D> graphics_2d(new Graphics2D(*size, is_always_opaque)); | 51 linked_ptr<Graphics2D> graphics_2d(new Graphics2D(*size, is_always_opaque)); |
52 dispatcher->plugin_resource_tracker()->AddResource(result, graphics_2d); | 52 dispatcher->plugin_resource_tracker()->AddResource(result, graphics_2d); |
53 } | 53 } |
54 return result; | 54 return result; |
55 } | 55 } |
56 | 56 |
57 bool IsGraphics2D(PP_Resource resource) { | 57 PP_Bool IsGraphics2D(PP_Resource resource) { |
58 Graphics2D* object = PluginResource::GetAs<Graphics2D>(resource); | 58 Graphics2D* object = PluginResource::GetAs<Graphics2D>(resource); |
59 return !!object; | 59 return BoolToPPBool(!!object); |
60 } | 60 } |
61 | 61 |
62 bool Describe(PP_Resource graphics_2d, | 62 PP_Bool Describe(PP_Resource graphics_2d, |
63 PP_Size* size, | 63 PP_Size* size, |
64 bool* is_always_opaque) { | 64 PP_Bool* is_always_opaque) { |
65 Graphics2D* object = PluginResource::GetAs<Graphics2D>(graphics_2d); | 65 Graphics2D* object = PluginResource::GetAs<Graphics2D>(graphics_2d); |
66 if (!object) { | 66 if (!object) { |
67 size->width = 0; | 67 size->width = 0; |
68 size->height = 0; | 68 size->height = 0; |
69 *is_always_opaque = false; | 69 *is_always_opaque = PP_FALSE; |
70 return false; | 70 return PP_FALSE; |
71 } | 71 } |
72 | 72 |
73 *size = object->size(); | 73 *size = object->size(); |
74 *is_always_opaque = object->is_always_opaque(); | 74 *is_always_opaque = object->is_always_opaque(); |
75 return true; | 75 return PP_TRUE; |
76 } | 76 } |
77 | 77 |
78 void PaintImageData(PP_Resource graphics_2d, | 78 void PaintImageData(PP_Resource graphics_2d, |
79 PP_Resource image_data, | 79 PP_Resource image_data, |
80 const PP_Point* top_left, | 80 const PP_Point* top_left, |
81 const PP_Rect* src_rect) { | 81 const PP_Rect* src_rect) { |
82 PP_Rect dummy; | 82 PP_Rect dummy; |
83 memset(&dummy, 0, sizeof(PP_Rect)); | 83 memset(&dummy, 0, sizeof(PP_Rect)); |
84 PluginDispatcher::Get()->Send(new PpapiHostMsg_PPBGraphics2D_PaintImageData( | 84 PluginDispatcher::Get()->Send(new PpapiHostMsg_PPBGraphics2D_PaintImageData( |
85 INTERFACE_ID_PPB_GRAPHICS_2D, graphics_2d, image_data, *top_left, | 85 INTERFACE_ID_PPB_GRAPHICS_2D, graphics_2d, image_data, *top_left, |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
151 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBGraphics2D_ReplaceContents, | 151 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBGraphics2D_ReplaceContents, |
152 OnMsgReplaceContents) | 152 OnMsgReplaceContents) |
153 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBGraphics2D_Flush, | 153 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBGraphics2D_Flush, |
154 OnMsgFlush) | 154 OnMsgFlush) |
155 IPC_END_MESSAGE_MAP() | 155 IPC_END_MESSAGE_MAP() |
156 // FIXME(brettw) handle bad messages! | 156 // FIXME(brettw) handle bad messages! |
157 } | 157 } |
158 | 158 |
159 void PPB_Graphics2D_Proxy::OnMsgCreate(PP_Module module, | 159 void PPB_Graphics2D_Proxy::OnMsgCreate(PP_Module module, |
160 const PP_Size& size, | 160 const PP_Size& size, |
161 bool is_always_opaque, | 161 PP_Bool is_always_opaque, |
162 PP_Resource* result) { | 162 PP_Resource* result) { |
163 *result = ppb_graphics_2d_target()->Create( | 163 *result = ppb_graphics_2d_target()->Create( |
164 module, &size, is_always_opaque); | 164 module, &size, is_always_opaque); |
165 } | 165 } |
166 | 166 |
167 void PPB_Graphics2D_Proxy::OnMsgPaintImageData(PP_Resource graphics_2d, | 167 void PPB_Graphics2D_Proxy::OnMsgPaintImageData(PP_Resource graphics_2d, |
168 PP_Resource image_data, | 168 PP_Resource image_data, |
169 const PP_Point& top_left, | 169 const PP_Point& top_left, |
170 bool src_rect_specified, | 170 bool src_rect_specified, |
171 const PP_Rect& src_rect) { | 171 const PP_Rect& src_rect) { |
(...skipping 21 matching lines...) Expand all Loading... |
193 int32_t* result) { | 193 int32_t* result) { |
194 // TODO(brettw) this should be a non-sync function. Ideally it would call | 194 // TODO(brettw) this should be a non-sync function. Ideally it would call |
195 // the callback with a failure code from here if you weren't allowed to | 195 // the callback with a failure code from here if you weren't allowed to |
196 // call Flush there. | 196 // call Flush there. |
197 *result = ppb_graphics_2d_target()->Flush( | 197 *result = ppb_graphics_2d_target()->Flush( |
198 graphics_2d, ReceiveCallback(serialized_callback)); | 198 graphics_2d, ReceiveCallback(serialized_callback)); |
199 } | 199 } |
200 | 200 |
201 } // namespace proxy | 201 } // namespace proxy |
202 } // namespace pp | 202 } // namespace pp |
OLD | NEW |