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 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
88 const PP_Point* top_left, | 88 const PP_Point* top_left, |
89 const PP_Rect* src_rect) { | 89 const PP_Rect* src_rect) { |
90 Resource* image_object = | 90 Resource* image_object = |
91 PpapiGlobals::Get()->GetResourceTracker()->GetResource(image_data); | 91 PpapiGlobals::Get()->GetResourceTracker()->GetResource(image_data); |
92 if (!image_object || pp_instance() != image_object->pp_instance()) | 92 if (!image_object || pp_instance() != image_object->pp_instance()) |
93 return; | 93 return; |
94 | 94 |
95 PP_Rect dummy; | 95 PP_Rect dummy; |
96 memset(&dummy, 0, sizeof(PP_Rect)); | 96 memset(&dummy, 0, sizeof(PP_Rect)); |
97 GetDispatcher()->Send(new PpapiHostMsg_PPBGraphics2D_PaintImageData( | 97 GetDispatcher()->Send(new PpapiHostMsg_PPBGraphics2D_PaintImageData( |
98 INTERFACE_ID_PPB_GRAPHICS_2D, host_resource(), | 98 API_ID_PPB_GRAPHICS_2D, host_resource(), |
99 image_object->host_resource(), *top_left, !!src_rect, | 99 image_object->host_resource(), *top_left, !!src_rect, |
100 src_rect ? *src_rect : dummy)); | 100 src_rect ? *src_rect : dummy)); |
101 } | 101 } |
102 | 102 |
103 void Graphics2D::Scroll(const PP_Rect* clip_rect, | 103 void Graphics2D::Scroll(const PP_Rect* clip_rect, |
104 const PP_Point* amount) { | 104 const PP_Point* amount) { |
105 PP_Rect dummy; | 105 PP_Rect dummy; |
106 memset(&dummy, 0, sizeof(PP_Rect)); | 106 memset(&dummy, 0, sizeof(PP_Rect)); |
107 GetDispatcher()->Send(new PpapiHostMsg_PPBGraphics2D_Scroll( | 107 GetDispatcher()->Send(new PpapiHostMsg_PPBGraphics2D_Scroll( |
108 INTERFACE_ID_PPB_GRAPHICS_2D, host_resource(), | 108 API_ID_PPB_GRAPHICS_2D, host_resource(), |
109 !!clip_rect, clip_rect ? *clip_rect : dummy, *amount)); | 109 !!clip_rect, clip_rect ? *clip_rect : dummy, *amount)); |
110 } | 110 } |
111 | 111 |
112 void Graphics2D::ReplaceContents(PP_Resource image_data) { | 112 void Graphics2D::ReplaceContents(PP_Resource image_data) { |
113 Resource* image_object = | 113 Resource* image_object = |
114 PpapiGlobals::Get()->GetResourceTracker()->GetResource(image_data); | 114 PpapiGlobals::Get()->GetResourceTracker()->GetResource(image_data); |
115 if (!image_object || pp_instance() != image_object->pp_instance()) | 115 if (!image_object || pp_instance() != image_object->pp_instance()) |
116 return; | 116 return; |
117 | 117 |
118 GetDispatcher()->Send(new PpapiHostMsg_PPBGraphics2D_ReplaceContents( | 118 GetDispatcher()->Send(new PpapiHostMsg_PPBGraphics2D_ReplaceContents( |
119 INTERFACE_ID_PPB_GRAPHICS_2D, host_resource(), | 119 API_ID_PPB_GRAPHICS_2D, host_resource(), |
120 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( |
134 INTERFACE_ID_PPB_GRAPHICS_2D, host_resource())); | 134 API_ID_PPB_GRAPHICS_2D, 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_ResourceCreation_Graphics2D( |
161 INTERFACE_ID_RESOURCE_CREATION, instance, size, is_always_opaque, | 161 API_ID_RESOURCE_CREATION, instance, size, is_always_opaque, |
162 &result)); | 162 &result)); |
163 if (result.is_null()) | 163 if (result.is_null()) |
164 return 0; | 164 return 0; |
165 return (new Graphics2D(result, size, is_always_opaque))->GetReference(); | 165 return (new Graphics2D(result, size, is_always_opaque))->GetReference(); |
166 } | 166 } |
167 | 167 |
168 bool PPB_Graphics2D_Proxy::OnMessageReceived(const IPC::Message& msg) { | 168 bool PPB_Graphics2D_Proxy::OnMessageReceived(const IPC::Message& msg) { |
169 bool handled = true; | 169 bool handled = true; |
170 IPC_BEGIN_MESSAGE_MAP(PPB_Graphics2D_Proxy, msg) | 170 IPC_BEGIN_MESSAGE_MAP(PPB_Graphics2D_Proxy, msg) |
171 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBGraphics2D_PaintImageData, | 171 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBGraphics2D_PaintImageData, |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
230 int32_t pp_error) { | 230 int32_t pp_error) { |
231 EnterPluginFromHostResource<PPB_Graphics2D_API> enter(host_resource); | 231 EnterPluginFromHostResource<PPB_Graphics2D_API> enter(host_resource); |
232 if (enter.succeeded()) | 232 if (enter.succeeded()) |
233 static_cast<Graphics2D*>(enter.object())->FlushACK(pp_error); | 233 static_cast<Graphics2D*>(enter.object())->FlushACK(pp_error); |
234 } | 234 } |
235 | 235 |
236 void PPB_Graphics2D_Proxy::SendFlushACKToPlugin( | 236 void PPB_Graphics2D_Proxy::SendFlushACKToPlugin( |
237 int32_t result, | 237 int32_t result, |
238 const HostResource& graphics_2d) { | 238 const HostResource& graphics_2d) { |
239 dispatcher()->Send(new PpapiMsg_PPBGraphics2D_FlushACK( | 239 dispatcher()->Send(new PpapiMsg_PPBGraphics2D_FlushACK( |
240 INTERFACE_ID_PPB_GRAPHICS_2D, graphics_2d, result)); | 240 API_ID_PPB_GRAPHICS_2D, graphics_2d, result)); |
241 } | 241 } |
242 | 242 |
243 } // namespace proxy | 243 } // namespace proxy |
244 } // namespace ppapi | 244 } // namespace ppapi |
OLD | NEW |