Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(466)

Side by Side Diff: ppapi/proxy/ppb_graphics_2d_proxy.cc

Issue 10544168: Implement HiDPI support in Pepper dev interface (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Add comments to Graphics2DDev C++ header Created 8 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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
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() { return scale_; }
brettw 2012/06/19 20:21:27 Can you make this non-inline? It makes it difficul
Josh Horwich 2012/06/19 23:56:15 Done.
46 int32_t Flush(PP_CompletionCallback callback); 48 int32_t Flush(PP_CompletionCallback 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
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 bool result;
135 GetDispatcher()->Send(new PpapiHostMsg_PPBGraphics2D_Dev_SetScale(
136 kApiID, host_resource(), scale, &result));
137 if (result)
138 scale_ = scale;
139 return result;
140 }
141
129 int32_t Graphics2D::Flush(PP_CompletionCallback callback) { 142 int32_t Graphics2D::Flush(PP_CompletionCallback callback) {
130 // For now, disallow blocking calls. We'll need to add support for other 143 // For now, disallow blocking calls. We'll need to add support for other
131 // threads to this later. 144 // threads to this later.
132 if (!callback.func) 145 if (!callback.func)
133 return PP_ERROR_BLOCKS_MAIN_THREAD; 146 return PP_ERROR_BLOCKS_MAIN_THREAD;
134 147
135 if (TrackedCallback::IsPending(current_flush_callback_)) 148 if (TrackedCallback::IsPending(current_flush_callback_))
136 return PP_ERROR_INPROGRESS; // Can't have >1 flush pending. 149 return PP_ERROR_INPROGRESS; // Can't have >1 flush pending.
137 current_flush_callback_ = new TrackedCallback(this, callback); 150 current_flush_callback_ = new TrackedCallback(this, callback);
138 151
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
176 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBGraphics2D_Create, 189 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBGraphics2D_Create,
177 OnHostMsgCreate) 190 OnHostMsgCreate)
178 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBGraphics2D_PaintImageData, 191 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBGraphics2D_PaintImageData,
179 OnHostMsgPaintImageData) 192 OnHostMsgPaintImageData)
180 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBGraphics2D_Scroll, 193 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBGraphics2D_Scroll,
181 OnHostMsgScroll) 194 OnHostMsgScroll)
182 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBGraphics2D_ReplaceContents, 195 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBGraphics2D_ReplaceContents,
183 OnHostMsgReplaceContents) 196 OnHostMsgReplaceContents)
184 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBGraphics2D_Flush, 197 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBGraphics2D_Flush,
185 OnHostMsgFlush) 198 OnHostMsgFlush)
199 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBGraphics2D_Dev_SetScale,
200 OnHostMsgSetScale)
186 201
187 IPC_MESSAGE_HANDLER(PpapiMsg_PPBGraphics2D_FlushACK, 202 IPC_MESSAGE_HANDLER(PpapiMsg_PPBGraphics2D_FlushACK,
188 OnPluginMsgFlushACK) 203 OnPluginMsgFlushACK)
189 IPC_MESSAGE_UNHANDLED(handled = false) 204 IPC_MESSAGE_UNHANDLED(handled = false)
190 IPC_END_MESSAGE_MAP() 205 IPC_END_MESSAGE_MAP()
191 // FIXME(brettw) handle bad messages! 206 // FIXME(brettw) handle bad messages!
192 return handled; 207 return handled;
193 } 208 }
194 209
195 void PPB_Graphics2D_Proxy::OnHostMsgCreate(PP_Instance instance, 210 void PPB_Graphics2D_Proxy::OnHostMsgCreate(PP_Instance instance,
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
237 252
238 void PPB_Graphics2D_Proxy::OnHostMsgFlush(const HostResource& graphics_2d) { 253 void PPB_Graphics2D_Proxy::OnHostMsgFlush(const HostResource& graphics_2d) {
239 EnterHostFromHostResourceForceCallback<PPB_Graphics2D_API> enter( 254 EnterHostFromHostResourceForceCallback<PPB_Graphics2D_API> enter(
240 graphics_2d, callback_factory_, 255 graphics_2d, callback_factory_,
241 &PPB_Graphics2D_Proxy::SendFlushACKToPlugin, graphics_2d); 256 &PPB_Graphics2D_Proxy::SendFlushACKToPlugin, graphics_2d);
242 if (enter.failed()) 257 if (enter.failed())
243 return; 258 return;
244 enter.SetResult(enter.object()->Flush(enter.callback())); 259 enter.SetResult(enter.object()->Flush(enter.callback()));
245 } 260 }
246 261
262 void PPB_Graphics2D_Proxy::OnHostMsgSetScale(const HostResource& graphics_2d,
263 float scale,
264 bool* result) {
265 EnterHostFromHostResource<PPB_Graphics2D_API> enter(graphics_2d);
266 if (enter.succeeded())
267 *result = enter.object()->SetScale(scale);
268 else
269 *result = false;
270 }
271
247 void PPB_Graphics2D_Proxy::OnPluginMsgFlushACK( 272 void PPB_Graphics2D_Proxy::OnPluginMsgFlushACK(
248 const HostResource& host_resource, 273 const HostResource& host_resource,
249 int32_t pp_error) { 274 int32_t pp_error) {
250 EnterPluginFromHostResource<PPB_Graphics2D_API> enter(host_resource); 275 EnterPluginFromHostResource<PPB_Graphics2D_API> enter(host_resource);
251 if (enter.succeeded()) 276 if (enter.succeeded())
252 static_cast<Graphics2D*>(enter.object())->FlushACK(pp_error); 277 static_cast<Graphics2D*>(enter.object())->FlushACK(pp_error);
253 } 278 }
254 279
255 void PPB_Graphics2D_Proxy::SendFlushACKToPlugin( 280 void PPB_Graphics2D_Proxy::SendFlushACKToPlugin(
256 int32_t result, 281 int32_t result,
257 const HostResource& graphics_2d) { 282 const HostResource& graphics_2d) {
258 dispatcher()->Send(new PpapiMsg_PPBGraphics2D_FlushACK(kApiID, graphics_2d, 283 dispatcher()->Send(new PpapiMsg_PPBGraphics2D_FlushACK(kApiID, graphics_2d,
259 result)); 284 result));
260 } 285 }
261 286
262 } // namespace proxy 287 } // namespace proxy
263 } // namespace ppapi 288 } // namespace ppapi
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698