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

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

Issue 4265002: Add proxies for ImageData and Graphics2D. These don't build by themselves, th... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 10 years, 1 month 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
Property Changes:
Added: svn:eol-style
+ LF
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "ppapi/proxy/ppb_graphics_2d_proxy.h"
6
7 #include <string.h> // For memcpy
piman 2010/11/03 22:53:49 // For memset ?
8
9 #include "base/logging.h"
10 #include "ppapi/c/pp_completion_callback.h"
11 #include "ppapi/c/pp_errors.h"
12 #include "ppapi/c/pp_resource.h"
13 #include "ppapi/c/ppb_graphics_2d.h"
14 #include "ppapi/proxy/plugin_dispatcher.h"
15 #include "ppapi/proxy/plugin_resource.h"
16 #include "ppapi/proxy/ppapi_messages.h"
17
18 namespace pp {
19 namespace proxy {
20
21 class Graphics2D : public PluginResource {
22 public:
23 Graphics2D(const PP_Size& size, bool is_always_opaque)
24 : size_(size), is_always_opaque_(is_always_opaque) {
25 }
26
27 // Resource overrides.
28 virtual Graphics2D* AsGraphics2D() { return this; }
29
30 const PP_Size& size() const { return size_; }
31 bool is_always_opaque() const { return is_always_opaque_; }
32
33 private:
34 PP_Size size_;
35 bool is_always_opaque_;
36
37 DISALLOW_COPY_AND_ASSIGN(Graphics2D);
38 };
39
40 namespace {
41
42 PP_Resource Create(PP_Module module_id,
43 const PP_Size* size,
44 bool is_always_opaque) {
45 PluginDispatcher* dispatcher = PluginDispatcher::Get();
46 PP_Resource result = 0;
47 dispatcher->Send(new PpapiHostMsg_PPBGraphics2D_Create(
48 INTERFACE_ID_PPB_GRAPHICS_2D, module_id, *size, is_always_opaque,
49 &result));
50 if (result) {
51 linked_ptr<Graphics2D> graphics_2d(new Graphics2D(*size, is_always_opaque));
52 dispatcher->plugin_resource_tracker()->AddResource(result, graphics_2d);
53 }
54 return result;
55 }
56
57 bool IsGraphics2D(PP_Resource resource) {
58 Graphics2D* object = PluginResource::GetAs<Graphics2D>(resource);
59 return !!object;
60 }
61
62 bool Describe(PP_Resource graphics_2d,
63 PP_Size* size,
64 bool* is_always_opaque) {
65 Graphics2D* object = PluginResource::GetAs<Graphics2D>(graphics_2d);
66 if (!object) {
67 size->width = 0;
68 size->height = 0;
69 *is_always_opaque = false;
70 return false;
71 }
72
73 *size = object->size();
74 *is_always_opaque = object->is_always_opaque();
75 return true;
76 }
77
78 void PaintImageData(PP_Resource graphics_2d,
79 PP_Resource image_data,
80 const PP_Point* top_left,
81 const PP_Rect* src_rect) {
82 PP_Rect dummy;
83 memset(&dummy, 0, sizeof(PP_Rect));
84 PluginDispatcher::Get()->Send(new PpapiHostMsg_PPBGraphics2D_PaintImageData(
85 INTERFACE_ID_PPB_GRAPHICS_2D, graphics_2d, image_data, *top_left,
86 !!src_rect, src_rect ? *src_rect : dummy));
87 }
88
89 void Scroll(PP_Resource graphics_2d,
90 const PP_Rect* clip_rect,
91 const PP_Point* amount) {
92 PP_Rect dummy;
93 memset(&dummy, 0, sizeof(PP_Rect));
94 PluginDispatcher::Get()->Send(new PpapiHostMsg_PPBGraphics2D_Scroll(
95 INTERFACE_ID_PPB_GRAPHICS_2D, graphics_2d, !!clip_rect,
96 clip_rect ? *clip_rect : dummy, *amount));
97 }
98
99 void ReplaceContents(PP_Resource graphics_2d, PP_Resource image_data) {
100 PluginDispatcher::Get()->Send(new PpapiHostMsg_PPBGraphics2D_ReplaceContents(
101 INTERFACE_ID_PPB_GRAPHICS_2D, graphics_2d, image_data));
102 }
103
104 int32_t Flush(PP_Resource graphics_2d,
105 PP_CompletionCallback callback) {
106 PluginDispatcher* dispatcher = PluginDispatcher::Get();
107 int32_t result = PP_ERROR_FAILED;
108 dispatcher->Send(new PpapiHostMsg_PPBGraphics2D_Flush(
109 INTERFACE_ID_PPB_GRAPHICS_2D, graphics_2d,
110 dispatcher->callback_tracker().SendCallback(callback),
111 &result));
112 return result;
113 }
114
115 const PPB_Graphics2D ppb_graphics_2d = {
116 &Create,
117 &IsGraphics2D,
118 &Describe,
119 &PaintImageData,
120 &Scroll,
121 &ReplaceContents,
122 &Flush
123 };
124
125 } // namespace
126
127 PPB_Graphics2D_Proxy::PPB_Graphics2D_Proxy(Dispatcher* dispatcher,
128 const void* target_interface)
129 : InterfaceProxy(dispatcher, target_interface) {
130 }
131
132 PPB_Graphics2D_Proxy::~PPB_Graphics2D_Proxy() {
133 }
134
135 const void* PPB_Graphics2D_Proxy::GetSourceInterface() const {
136 return &ppb_graphics_2d;
137 }
138
139 InterfaceID PPB_Graphics2D_Proxy::GetInterfaceId() const {
140 return INTERFACE_ID_PPB_GRAPHICS_2D;
141 }
142
143 void PPB_Graphics2D_Proxy::OnMessageReceived(const IPC::Message& msg) {
144 IPC_BEGIN_MESSAGE_MAP(PPB_Graphics2D_Proxy, msg)
145 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBGraphics2D_Create,
146 OnMsgCreate)
147 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBGraphics2D_PaintImageData,
148 OnMsgPaintImageData)
149 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBGraphics2D_Scroll,
150 OnMsgScroll)
151 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBGraphics2D_ReplaceContents,
152 OnMsgReplaceContents)
153 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBGraphics2D_Flush,
154 OnMsgFlush)
155 IPC_END_MESSAGE_MAP()
156 // FIXME(brettw) handle bad messages!
157 }
158
159 void PPB_Graphics2D_Proxy::OnMsgCreate(PP_Module module,
160 const PP_Size& size,
161 bool is_always_opaque,
162 PP_Resource* result) {
163 *result = ppb_graphics_2d_target()->Create(
164 module, &size, is_always_opaque);
165 }
166
167 void PPB_Graphics2D_Proxy::OnMsgPaintImageData(PP_Resource graphics_2d,
168 PP_Resource image_data,
169 const PP_Point& top_left,
170 bool src_rect_specified,
171 const PP_Rect& src_rect) {
172 ppb_graphics_2d_target()->PaintImageData(
173 graphics_2d, image_data, &top_left,
174 src_rect_specified ? &src_rect : NULL);
175 }
176
177 void PPB_Graphics2D_Proxy::OnMsgScroll(PP_Resource graphics_2d,
178 bool clip_specified,
179 const PP_Rect& clip,
180 const PP_Point& amount) {
181 ppb_graphics_2d_target()->Scroll(
182 graphics_2d,
183 clip_specified ? &clip : NULL, &amount);
184 }
185
186 void PPB_Graphics2D_Proxy::OnMsgReplaceContents(PP_Resource graphics_2d,
187 PP_Resource image_data) {
188 ppb_graphics_2d_target()->ReplaceContents(graphics_2d, image_data);
189 }
190
191 void PPB_Graphics2D_Proxy::OnMsgFlush(PP_Resource graphics_2d,
192 uint32_t serialized_callback,
193 int32_t* result) {
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
196 // call Flush there.
197 *result = ppb_graphics_2d_target()->Flush(
198 graphics_2d, ReceiveCallback(serialized_callback));
199 }
200
201 } // namespace proxy
202 } // namespace pp
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698