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

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

Issue 10823378: Cache image data objects. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 4 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"
11 #include "ppapi/c/pp_completion_callback.h" 11 #include "ppapi/c/pp_completion_callback.h"
12 #include "ppapi/c/pp_errors.h" 12 #include "ppapi/c/pp_errors.h"
13 #include "ppapi/c/pp_resource.h" 13 #include "ppapi/c/pp_resource.h"
14 #include "ppapi/c/ppb_graphics_2d.h" 14 #include "ppapi/c/ppb_graphics_2d.h"
15 #include "ppapi/proxy/enter_proxy.h" 15 #include "ppapi/proxy/enter_proxy.h"
16 #include "ppapi/proxy/plugin_dispatcher.h" 16 #include "ppapi/proxy/plugin_dispatcher.h"
17 #include "ppapi/proxy/plugin_resource_tracker.h"
17 #include "ppapi/proxy/ppapi_messages.h" 18 #include "ppapi/proxy/ppapi_messages.h"
18 #include "ppapi/shared_impl/tracked_callback.h" 19 #include "ppapi/shared_impl/tracked_callback.h"
19 #include "ppapi/thunk/enter.h" 20 #include "ppapi/thunk/enter.h"
20 #include "ppapi/thunk/ppb_graphics_2d_api.h" 21 #include "ppapi/thunk/ppb_graphics_2d_api.h"
21 #include "ppapi/thunk/thunk.h" 22 #include "ppapi/thunk/thunk.h"
22 23
23 using ppapi::thunk::PPB_Graphics2D_API; 24 using ppapi::thunk::PPB_Graphics2D_API;
24 25
25 namespace ppapi { 26 namespace ppapi {
26 namespace proxy { 27 namespace proxy {
(...skipping 11 matching lines...) Expand all
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 bool SetScale(float scale); 47 bool SetScale(float scale);
47 float GetScale(); 48 float GetScale();
48 int32_t Flush(scoped_refptr<TrackedCallback> callback); 49 int32_t Flush(scoped_refptr<TrackedCallback> callback,
50 PP_Resource* old_image_data);
49 51
50 // Notification that the host has sent an ACK for a pending Flush. 52 // Notification that the host has sent an ACK for a pending Flush.
51 void FlushACK(int32_t result_code); 53 void FlushACK(int32_t result_code);
52 54
53 private: 55 private:
54 PluginDispatcher* GetDispatcher() const { 56 PluginDispatcher* GetDispatcher() const {
55 return PluginDispatcher::GetForResource(this); 57 return PluginDispatcher::GetForResource(this);
56 } 58 }
57 59
58 static const ApiID kApiID = API_ID_PPB_GRAPHICS_2D; 60 static const ApiID kApiID = API_ID_PPB_GRAPHICS_2D;
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
136 GetDispatcher()->Send(new PpapiHostMsg_PPBGraphics2D_Dev_SetScale( 138 GetDispatcher()->Send(new PpapiHostMsg_PPBGraphics2D_Dev_SetScale(
137 kApiID, host_resource(), scale)); 139 kApiID, host_resource(), scale));
138 scale_ = scale; 140 scale_ = scale;
139 return true; 141 return true;
140 } 142 }
141 143
142 float Graphics2D::GetScale() { 144 float Graphics2D::GetScale() {
143 return scale_; 145 return scale_;
144 } 146 }
145 147
146 int32_t Graphics2D::Flush(scoped_refptr<TrackedCallback> callback) { 148 int32_t Graphics2D::Flush(scoped_refptr<TrackedCallback> callback,
149 PP_Resource* old_image_data) {
150 // We don't support this feature, it's for in-renderer only.
151 if (old_image_data)
152 *old_image_data = 0;
153
147 if (TrackedCallback::IsPending(current_flush_callback_)) 154 if (TrackedCallback::IsPending(current_flush_callback_))
148 return PP_ERROR_INPROGRESS; // Can't have >1 flush pending. 155 return PP_ERROR_INPROGRESS; // Can't have >1 flush pending.
149 current_flush_callback_ = callback; 156 current_flush_callback_ = callback;
150 157
151 GetDispatcher()->Send(new PpapiHostMsg_PPBGraphics2D_Flush(kApiID, 158 GetDispatcher()->Send(new PpapiHostMsg_PPBGraphics2D_Flush(kApiID,
152 host_resource())); 159 host_resource()));
153 return PP_OK_COMPLETIONPENDING; 160 return PP_OK_COMPLETIONPENDING;
154 } 161 }
155 162
156 void Graphics2D::FlushACK(int32_t result_code) { 163 void Graphics2D::FlushACK(int32_t result_code) {
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
248 return; 255 return;
249 enter.object()->ReplaceContents(image_data.host_resource()); 256 enter.object()->ReplaceContents(image_data.host_resource());
250 } 257 }
251 258
252 void PPB_Graphics2D_Proxy::OnHostMsgFlush(const HostResource& graphics_2d) { 259 void PPB_Graphics2D_Proxy::OnHostMsgFlush(const HostResource& graphics_2d) {
253 EnterHostFromHostResourceForceCallback<PPB_Graphics2D_API> enter( 260 EnterHostFromHostResourceForceCallback<PPB_Graphics2D_API> enter(
254 graphics_2d, callback_factory_, 261 graphics_2d, callback_factory_,
255 &PPB_Graphics2D_Proxy::SendFlushACKToPlugin, graphics_2d); 262 &PPB_Graphics2D_Proxy::SendFlushACKToPlugin, graphics_2d);
256 if (enter.failed()) 263 if (enter.failed())
257 return; 264 return;
258 enter.SetResult(enter.object()->Flush(enter.callback())); 265 PP_Resource old_image_data = 0;
266 enter.SetResult(enter.object()->Flush(enter.callback(), &old_image_data));
267 if (old_image_data) {
268 // If the Graphics2D has an old image data it's not using any more, send
269 // it back to the plugin for possible re-use. See ppb_image_data_proxy.cc
270 // for a description how this process works.
271 HostResource old_image_data_host_resource;
272 old_image_data_host_resource.SetHostResource(graphics_2d.instance(),
273 old_image_data);
274 dispatcher()->Send(new PpapiPluginMsg_PPBImageData_NotifyUnusedImageData(
275 API_ID_PPB_IMAGE_DATA, old_image_data_host_resource));
276 }
259 } 277 }
260 278
261 void PPB_Graphics2D_Proxy::OnHostMsgSetScale(const HostResource& graphics_2d, 279 void PPB_Graphics2D_Proxy::OnHostMsgSetScale(const HostResource& graphics_2d,
262 float scale) { 280 float scale) {
263 EnterHostFromHostResource<PPB_Graphics2D_API> enter(graphics_2d); 281 EnterHostFromHostResource<PPB_Graphics2D_API> enter(graphics_2d);
264 if (enter.failed()) 282 if (enter.failed())
265 return; 283 return;
266 enter.object()->SetScale(scale); 284 enter.object()->SetScale(scale);
267 } 285 }
268 286
269 void PPB_Graphics2D_Proxy::OnPluginMsgFlushACK( 287 void PPB_Graphics2D_Proxy::OnPluginMsgFlushACK(
270 const HostResource& host_resource, 288 const HostResource& host_resource,
271 int32_t pp_error) { 289 int32_t pp_error) {
272 EnterPluginFromHostResource<PPB_Graphics2D_API> enter(host_resource); 290 EnterPluginFromHostResource<PPB_Graphics2D_API> enter(host_resource);
273 if (enter.succeeded()) 291 if (enter.succeeded())
274 static_cast<Graphics2D*>(enter.object())->FlushACK(pp_error); 292 static_cast<Graphics2D*>(enter.object())->FlushACK(pp_error);
275 } 293 }
276 294
277 void PPB_Graphics2D_Proxy::SendFlushACKToPlugin( 295 void PPB_Graphics2D_Proxy::SendFlushACKToPlugin(
278 int32_t result, 296 int32_t result,
279 const HostResource& graphics_2d) { 297 const HostResource& graphics_2d) {
280 dispatcher()->Send(new PpapiMsg_PPBGraphics2D_FlushACK(kApiID, graphics_2d, 298 dispatcher()->Send(new PpapiMsg_PPBGraphics2D_FlushACK(kApiID, graphics_2d,
281 result)); 299 result));
282 } 300 }
283 301
284 } // namespace proxy 302 } // namespace proxy
285 } // namespace ppapi 303 } // namespace ppapi
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698