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

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

Issue 6282007: First pass at making the proxy handle multiple renderers. This associates the... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 9 years, 11 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
« no previous file with comments | « ppapi/proxy/ppb_fullscreen_proxy.cc ('k') | ppapi/proxy/ppb_image_data_proxy.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/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/plugin_dispatcher.h" 15 #include "ppapi/proxy/plugin_dispatcher.h"
16 #include "ppapi/proxy/plugin_resource.h" 16 #include "ppapi/proxy/plugin_resource.h"
17 #include "ppapi/proxy/ppapi_messages.h" 17 #include "ppapi/proxy/ppapi_messages.h"
18 18
19 namespace pp { 19 namespace pp {
20 namespace proxy { 20 namespace proxy {
21 21
22 class Graphics2D : public PluginResource { 22 class Graphics2D : public PluginResource {
23 public: 23 public:
24 Graphics2D(const PP_Size& size, PP_Bool is_always_opaque) 24 Graphics2D(PP_Instance instance,
25 : size_(size), 25 const PP_Size& size,
26 PP_Bool is_always_opaque)
27 : PluginResource(instance),
28 size_(size),
26 is_always_opaque_(is_always_opaque), 29 is_always_opaque_(is_always_opaque),
27 current_flush_callback_(PP_BlockUntilComplete()) { 30 current_flush_callback_(PP_BlockUntilComplete()) {
28 } 31 }
29 32
30 // Resource overrides. 33 // Resource overrides.
31 virtual Graphics2D* AsGraphics2D() { return this; } 34 virtual Graphics2D* AsGraphics2D() { return this; }
32 35
33 const PP_Size& size() const { return size_; } 36 const PP_Size& size() const { return size_; }
34 PP_Bool is_always_opaque() const { return is_always_opaque_; } 37 PP_Bool is_always_opaque() const { return is_always_opaque_; }
35 38
(...skipping 15 matching lines...) Expand all
51 PP_CompletionCallback current_flush_callback_; 54 PP_CompletionCallback current_flush_callback_;
52 55
53 DISALLOW_COPY_AND_ASSIGN(Graphics2D); 56 DISALLOW_COPY_AND_ASSIGN(Graphics2D);
54 }; 57 };
55 58
56 namespace { 59 namespace {
57 60
58 PP_Resource Create(PP_Instance instance, 61 PP_Resource Create(PP_Instance instance,
59 const PP_Size* size, 62 const PP_Size* size,
60 PP_Bool is_always_opaque) { 63 PP_Bool is_always_opaque) {
61 PluginDispatcher* dispatcher = PluginDispatcher::Get(); 64 PluginDispatcher* dispatcher = PluginDispatcher::GetForInstance(instance);
65 if (!dispatcher)
66 return PP_ERROR_BADARGUMENT;
67
62 PP_Resource result = 0; 68 PP_Resource result = 0;
63 dispatcher->Send(new PpapiHostMsg_PPBGraphics2D_Create( 69 dispatcher->Send(new PpapiHostMsg_PPBGraphics2D_Create(
64 INTERFACE_ID_PPB_GRAPHICS_2D, instance, *size, is_always_opaque, 70 INTERFACE_ID_PPB_GRAPHICS_2D, instance, *size, is_always_opaque,
65 &result)); 71 &result));
66 if (result) { 72 if (result) {
67 linked_ptr<Graphics2D> graphics_2d(new Graphics2D(*size, is_always_opaque)); 73 linked_ptr<Graphics2D> graphics_2d(new Graphics2D(instance, *size,
68 dispatcher->plugin_resource_tracker()->AddResource(result, graphics_2d); 74 is_always_opaque));
75 PluginResourceTracker::GetInstance()->AddResource(result, graphics_2d);
69 } 76 }
70 return result; 77 return result;
71 } 78 }
72 79
73 PP_Bool IsGraphics2D(PP_Resource resource) { 80 PP_Bool IsGraphics2D(PP_Resource resource) {
74 Graphics2D* object = PluginResource::GetAs<Graphics2D>(resource); 81 Graphics2D* object = PluginResource::GetAs<Graphics2D>(resource);
75 return BoolToPPBool(!!object); 82 return BoolToPPBool(!!object);
76 } 83 }
77 84
78 PP_Bool Describe(PP_Resource graphics_2d, 85 PP_Bool Describe(PP_Resource graphics_2d,
79 PP_Size* size, 86 PP_Size* size,
80 PP_Bool* is_always_opaque) { 87 PP_Bool* is_always_opaque) {
81 Graphics2D* object = PluginResource::GetAs<Graphics2D>(graphics_2d); 88 Graphics2D* object = PluginResource::GetAs<Graphics2D>(graphics_2d);
82 if (!object) { 89 if (!object) {
83 size->width = 0; 90 size->width = 0;
84 size->height = 0; 91 size->height = 0;
85 *is_always_opaque = PP_FALSE; 92 *is_always_opaque = PP_FALSE;
86 return PP_FALSE; 93 return PP_FALSE;
87 } 94 }
88 95
89 *size = object->size(); 96 *size = object->size();
90 *is_always_opaque = object->is_always_opaque(); 97 *is_always_opaque = object->is_always_opaque();
91 return PP_TRUE; 98 return PP_TRUE;
92 } 99 }
93 100
94 void PaintImageData(PP_Resource graphics_2d, 101 void PaintImageData(PP_Resource graphics_2d,
95 PP_Resource image_data, 102 PP_Resource image_data,
96 const PP_Point* top_left, 103 const PP_Point* top_left,
97 const PP_Rect* src_rect) { 104 const PP_Rect* src_rect) {
105 Graphics2D* object = PluginResource::GetAs<Graphics2D>(graphics_2d);
106 if (!object)
107 return;
108 PluginDispatcher* dispatcher = PluginDispatcher::GetForInstance(
109 object->instance());
110 if (!dispatcher)
111 return;
112
98 PP_Rect dummy; 113 PP_Rect dummy;
99 memset(&dummy, 0, sizeof(PP_Rect)); 114 memset(&dummy, 0, sizeof(PP_Rect));
100 PluginDispatcher::Get()->Send(new PpapiHostMsg_PPBGraphics2D_PaintImageData( 115 dispatcher->Send(new PpapiHostMsg_PPBGraphics2D_PaintImageData(
101 INTERFACE_ID_PPB_GRAPHICS_2D, graphics_2d, image_data, *top_left, 116 INTERFACE_ID_PPB_GRAPHICS_2D, graphics_2d, image_data, *top_left,
102 !!src_rect, src_rect ? *src_rect : dummy)); 117 !!src_rect, src_rect ? *src_rect : dummy));
103 } 118 }
104 119
105 void Scroll(PP_Resource graphics_2d, 120 void Scroll(PP_Resource graphics_2d,
106 const PP_Rect* clip_rect, 121 const PP_Rect* clip_rect,
107 const PP_Point* amount) { 122 const PP_Point* amount) {
123 Graphics2D* object = PluginResource::GetAs<Graphics2D>(graphics_2d);
124 if (!object)
125 return;
126 PluginDispatcher* dispatcher = PluginDispatcher::GetForInstance(
127 object->instance());
128 if (!dispatcher)
129 return;
130
108 PP_Rect dummy; 131 PP_Rect dummy;
109 memset(&dummy, 0, sizeof(PP_Rect)); 132 memset(&dummy, 0, sizeof(PP_Rect));
110 PluginDispatcher::Get()->Send(new PpapiHostMsg_PPBGraphics2D_Scroll( 133 dispatcher->Send(new PpapiHostMsg_PPBGraphics2D_Scroll(
111 INTERFACE_ID_PPB_GRAPHICS_2D, graphics_2d, !!clip_rect, 134 INTERFACE_ID_PPB_GRAPHICS_2D, graphics_2d, !!clip_rect,
112 clip_rect ? *clip_rect : dummy, *amount)); 135 clip_rect ? *clip_rect : dummy, *amount));
113 } 136 }
114 137
115 void ReplaceContents(PP_Resource graphics_2d, PP_Resource image_data) { 138 void ReplaceContents(PP_Resource graphics_2d, PP_Resource image_data) {
116 PluginDispatcher::Get()->Send(new PpapiHostMsg_PPBGraphics2D_ReplaceContents( 139 Graphics2D* object = PluginResource::GetAs<Graphics2D>(graphics_2d);
140 if (!object)
141 return;
142 PluginDispatcher* dispatcher = PluginDispatcher::GetForInstance(
143 object->instance());
144 if (!dispatcher)
145 return;
146
147 dispatcher->Send(new PpapiHostMsg_PPBGraphics2D_ReplaceContents(
117 INTERFACE_ID_PPB_GRAPHICS_2D, graphics_2d, image_data)); 148 INTERFACE_ID_PPB_GRAPHICS_2D, graphics_2d, image_data));
118 } 149 }
119 150
120 int32_t Flush(PP_Resource graphics_2d, 151 int32_t Flush(PP_Resource graphics_2d,
121 PP_CompletionCallback callback) { 152 PP_CompletionCallback callback) {
122 Graphics2D* object = PluginResource::GetAs<Graphics2D>(graphics_2d); 153 Graphics2D* object = PluginResource::GetAs<Graphics2D>(graphics_2d);
123 if (!object) 154 if (!object)
124 return PP_ERROR_BADRESOURCE; 155 return PP_ERROR_BADRESOURCE;
156 PluginDispatcher* dispatcher = PluginDispatcher::GetForInstance(
157 object->instance());
158 if (!dispatcher)
159 return PP_ERROR_FAILED;
125 160
126 // For now, disallow blocking calls. We'll need to add support for other 161 // For now, disallow blocking calls. We'll need to add support for other
127 // threads to this later. 162 // threads to this later.
128 if (!callback.func) 163 if (!callback.func)
129 return PP_ERROR_BADARGUMENT; 164 return PP_ERROR_BADARGUMENT;
130 165
131 if (object->is_flush_pending()) 166 if (object->is_flush_pending())
132 return PP_ERROR_INPROGRESS; // Can't have >1 flush pending. 167 return PP_ERROR_INPROGRESS; // Can't have >1 flush pending.
133 object->set_current_flush_callback(callback); 168 object->set_current_flush_callback(callback);
134 169
135 PluginDispatcher::Get()->Send(new PpapiHostMsg_PPBGraphics2D_Flush( 170 dispatcher->Send(new PpapiHostMsg_PPBGraphics2D_Flush(
136 INTERFACE_ID_PPB_GRAPHICS_2D, graphics_2d)); 171 INTERFACE_ID_PPB_GRAPHICS_2D, graphics_2d));
137 return PP_ERROR_WOULDBLOCK; 172 return PP_ERROR_WOULDBLOCK;
138 } 173 }
139 174
140 const PPB_Graphics2D ppb_graphics_2d = { 175 const PPB_Graphics2D ppb_graphics_2d = {
141 &Create, 176 &Create,
142 &IsGraphics2D, 177 &IsGraphics2D,
143 &Describe, 178 &Describe,
144 &PaintImageData, 179 &PaintImageData,
145 &Scroll, 180 &Scroll,
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after
250 } 285 }
251 286
252 void PPB_Graphics2D_Proxy::SendFlushACKToPlugin(int32_t result, 287 void PPB_Graphics2D_Proxy::SendFlushACKToPlugin(int32_t result,
253 PP_Resource graphics_2d) { 288 PP_Resource graphics_2d) {
254 dispatcher()->Send(new PpapiMsg_PPBGraphics2D_FlushACK( 289 dispatcher()->Send(new PpapiMsg_PPBGraphics2D_FlushACK(
255 INTERFACE_ID_PPB_GRAPHICS_2D, graphics_2d, result)); 290 INTERFACE_ID_PPB_GRAPHICS_2D, graphics_2d, result));
256 } 291 }
257 292
258 } // namespace proxy 293 } // namespace proxy
259 } // namespace pp 294 } // namespace pp
OLDNEW
« no previous file with comments | « ppapi/proxy/ppb_fullscreen_proxy.cc ('k') | ppapi/proxy/ppb_image_data_proxy.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698