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

Side by Side Diff: webkit/plugins/ppapi/ppb_graphics_2d_impl.cc

Issue 6905088: New thunk system for Pepper proxy and implementation (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 9 years, 7 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) 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 "webkit/plugins/ppapi/ppb_graphics_2d_impl.h" 5 #include "webkit/plugins/ppapi/ppb_graphics_2d_impl.h"
6 6
7 #include <iterator> 7 #include <iterator>
8 8
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/message_loop.h" 10 #include "base/message_loop.h"
11 #include "base/task.h" 11 #include "base/task.h"
12 #include "skia/ext/platform_canvas.h" 12 #include "skia/ext/platform_canvas.h"
13 #include "ppapi/c/pp_errors.h" 13 #include "ppapi/c/pp_errors.h"
14 #include "ppapi/c/pp_rect.h" 14 #include "ppapi/c/pp_rect.h"
15 #include "ppapi/c/pp_resource.h" 15 #include "ppapi/c/pp_resource.h"
16 #include "ppapi/c/ppb_graphics_2d.h" 16 #include "ppapi/c/ppb_graphics_2d.h"
17 #include "ppapi/cpp/common.h" 17 #include "ppapi/cpp/common.h"
18 #include "ppapi/thunk/thunk.h"
18 #include "third_party/skia/include/core/SkBitmap.h" 19 #include "third_party/skia/include/core/SkBitmap.h"
19 #include "ui/gfx/blit.h" 20 #include "ui/gfx/blit.h"
20 #include "ui/gfx/point.h" 21 #include "ui/gfx/point.h"
21 #include "ui/gfx/rect.h" 22 #include "ui/gfx/rect.h"
22 #include "webkit/plugins/ppapi/common.h" 23 #include "webkit/plugins/ppapi/common.h"
23 #include "webkit/plugins/ppapi/ppapi_plugin_instance.h" 24 #include "webkit/plugins/ppapi/ppapi_plugin_instance.h"
24 #include "webkit/plugins/ppapi/ppb_image_data_impl.h" 25 #include "webkit/plugins/ppapi/ppb_image_data_impl.h"
25 26
26 #if defined(OS_MACOSX) 27 #if defined(OS_MACOSX)
27 #include "base/mac/mac_util.h" 28 #include "base/mac/mac_util.h"
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
107 ConvertBetweenBGRAandRGBA( 108 ConvertBetweenBGRAandRGBA(
108 src_bitmap->getAddr32(static_cast<int>(src_rect.fLeft), 109 src_bitmap->getAddr32(static_cast<int>(src_rect.fLeft),
109 static_cast<int>(src_rect.fTop + y)), 110 static_cast<int>(src_rect.fTop + y)),
110 src_rect.width(), 111 src_rect.width(),
111 dest_bitmap->getAddr32(static_cast<int>(dest_rect.fLeft), 112 dest_bitmap->getAddr32(static_cast<int>(dest_rect.fLeft),
112 static_cast<int>(dest_rect.fTop + y))); 113 static_cast<int>(dest_rect.fTop + y)));
113 } 114 }
114 } 115 }
115 } 116 }
116 117
117 PP_Resource Create(PP_Instance instance_id,
118 const PP_Size* size,
119 PP_Bool is_always_opaque) {
120 PluginInstance* instance = ResourceTracker::Get()->GetInstance(instance_id);
121 if (!instance)
122 return 0;
123
124 scoped_refptr<PPB_Graphics2D_Impl> context(
125 new PPB_Graphics2D_Impl(instance));
126 if (!context->Init(size->width, size->height, PPBoolToBool(is_always_opaque)))
127 return 0;
128 return context->GetReference();
129 }
130
131 PP_Bool IsGraphics2D(PP_Resource resource) {
132 return BoolToPPBool(!!Resource::GetAs<PPB_Graphics2D_Impl>(resource));
133 }
134
135 PP_Bool Describe(PP_Resource graphics_2d,
136 PP_Size* size,
137 PP_Bool* is_always_opaque) {
138 scoped_refptr<PPB_Graphics2D_Impl> context(
139 Resource::GetAs<PPB_Graphics2D_Impl>(graphics_2d));
140 if (!context) {
141 *size = PP_MakeSize(0, 0);
142 *is_always_opaque = PP_FALSE;
143 return PP_FALSE;
144 }
145 return context->Describe(size, is_always_opaque);
146 }
147
148 void PaintImageData(PP_Resource graphics_2d,
149 PP_Resource image_data,
150 const PP_Point* top_left,
151 const PP_Rect* src_rect) {
152 scoped_refptr<PPB_Graphics2D_Impl> context(
153 Resource::GetAs<PPB_Graphics2D_Impl>(graphics_2d));
154 if (context)
155 context->PaintImageData(image_data, top_left, src_rect);
156 }
157
158 void Scroll(PP_Resource graphics_2d,
159 const PP_Rect* clip_rect,
160 const PP_Point* amount) {
161 scoped_refptr<PPB_Graphics2D_Impl> context(
162 Resource::GetAs<PPB_Graphics2D_Impl>(graphics_2d));
163 if (context)
164 context->Scroll(clip_rect, amount);
165 }
166
167 void ReplaceContents(PP_Resource graphics_2d, PP_Resource image_data) {
168 scoped_refptr<PPB_Graphics2D_Impl> context(
169 Resource::GetAs<PPB_Graphics2D_Impl>(graphics_2d));
170 if (context)
171 context->ReplaceContents(image_data);
172 }
173
174 int32_t Flush(PP_Resource graphics_2d,
175 PP_CompletionCallback callback) {
176 scoped_refptr<PPB_Graphics2D_Impl> context(
177 Resource::GetAs<PPB_Graphics2D_Impl>(graphics_2d));
178 if (!context)
179 return PP_ERROR_BADRESOURCE;
180 return context->Flush(callback);
181 }
182
183 const PPB_Graphics2D ppb_graphics_2d = {
184 &Create,
185 &IsGraphics2D,
186 &Describe,
187 &PaintImageData,
188 &Scroll,
189 &ReplaceContents,
190 &Flush
191 };
192
193 } // namespace 118 } // namespace
194 119
195 struct PPB_Graphics2D_Impl::QueuedOperation { 120 struct PPB_Graphics2D_Impl::QueuedOperation {
196 enum Type { 121 enum Type {
197 PAINT, 122 PAINT,
198 SCROLL, 123 SCROLL,
199 REPLACE 124 REPLACE
200 }; 125 };
201 126
202 QueuedOperation(Type t) 127 QueuedOperation(Type t)
(...skipping 25 matching lines...) Expand all
228 flushed_any_data_(false), 153 flushed_any_data_(false),
229 offscreen_flush_pending_(false), 154 offscreen_flush_pending_(false),
230 is_always_opaque_(false) { 155 is_always_opaque_(false) {
231 } 156 }
232 157
233 PPB_Graphics2D_Impl::~PPB_Graphics2D_Impl() { 158 PPB_Graphics2D_Impl::~PPB_Graphics2D_Impl() {
234 } 159 }
235 160
236 // static 161 // static
237 const PPB_Graphics2D* PPB_Graphics2D_Impl::GetInterface() { 162 const PPB_Graphics2D* PPB_Graphics2D_Impl::GetInterface() {
238 return &ppb_graphics_2d; 163 return ::ppapi::thunk::GetPPB_Graphics2D_Thunk();
239 } 164 }
240 165
241 bool PPB_Graphics2D_Impl::Init(int width, int height, bool is_always_opaque) { 166 bool PPB_Graphics2D_Impl::Init(int width, int height, bool is_always_opaque) {
242 // The underlying PPB_ImageData_Impl will validate the dimensions. 167 // The underlying PPB_ImageData_Impl will validate the dimensions.
243 image_data_ = new PPB_ImageData_Impl(instance()); 168 image_data_ = new PPB_ImageData_Impl(instance());
244 if (!image_data_->Init(PPB_ImageData_Impl::GetNativeImageDataFormat(), 169 if (!image_data_->Init(PPB_ImageData_Impl::GetNativeImageDataFormat(),
245 width, height, true) || 170 width, height, true) ||
246 !image_data_->Map()) { 171 !image_data_->Map()) {
247 image_data_ = NULL; 172 image_data_ = NULL;
248 return false; 173 return false;
249 } 174 }
250 is_always_opaque_ = is_always_opaque; 175 is_always_opaque_ = is_always_opaque;
251 return true; 176 return true;
252 } 177 }
253 178
179 ::ppapi::thunk::PPB_Graphics2D_API* PPB_Graphics2D_Impl::AsGraphics2D_API() {
180 return this;
181 }
182
254 PPB_Graphics2D_Impl* PPB_Graphics2D_Impl::AsPPB_Graphics2D_Impl() { 183 PPB_Graphics2D_Impl* PPB_Graphics2D_Impl::AsPPB_Graphics2D_Impl() {
255 return this; 184 return this;
256 } 185 }
257 186
258 PP_Bool PPB_Graphics2D_Impl::Describe(PP_Size* size, 187 PP_Bool PPB_Graphics2D_Impl::Describe(PP_Size* size,
259 PP_Bool* is_always_opaque) { 188 PP_Bool* is_always_opaque) {
260 size->width = image_data_->width(); 189 size->width = image_data_->width();
261 size->height = image_data_->height(); 190 size->height = image_data_->height();
262 *is_always_opaque = pp::BoolToPPBool(is_always_opaque_); 191 *is_always_opaque = pp::BoolToPPBool(is_always_opaque_);
263 return PP_TRUE; 192 return PP_TRUE;
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
333 262
334 if (image_resource->width() != image_data_->width() || 263 if (image_resource->width() != image_data_->width() ||
335 image_resource->height() != image_data_->height()) 264 image_resource->height() != image_data_->height())
336 return; 265 return;
337 266
338 QueuedOperation operation(QueuedOperation::REPLACE); 267 QueuedOperation operation(QueuedOperation::REPLACE);
339 operation.replace_image = image_resource; 268 operation.replace_image = image_resource;
340 queued_operations_.push_back(operation); 269 queued_operations_.push_back(operation);
341 } 270 }
342 271
343 int32_t PPB_Graphics2D_Impl::Flush(const PP_CompletionCallback& callback) { 272 int32_t PPB_Graphics2D_Impl::Flush(PP_CompletionCallback callback) {
344 // Don't allow more than one pending flush at a time. 273 // Don't allow more than one pending flush at a time.
345 if (HasPendingFlush()) 274 if (HasPendingFlush())
346 return PP_ERROR_INPROGRESS; 275 return PP_ERROR_INPROGRESS;
347 276
348 // TODO(brettw) check that the current thread is not the main one and 277 // TODO(brettw) check that the current thread is not the main one and
349 // implement blocking flushes in this case. 278 // implement blocking flushes in this case.
350 if (!callback.func) 279 if (!callback.func)
351 return PP_ERROR_BADARGUMENT; 280 return PP_ERROR_BADARGUMENT;
352 281
353 bool nothing_visible = true; 282 bool nothing_visible = true;
(...skipping 323 matching lines...) Expand 10 before | Expand all | Expand 10 after
677 } 606 }
678 607
679 bool PPB_Graphics2D_Impl::HasPendingFlush() const { 608 bool PPB_Graphics2D_Impl::HasPendingFlush() const {
680 return !unpainted_flush_callback_.is_null() || 609 return !unpainted_flush_callback_.is_null() ||
681 !painted_flush_callback_.is_null() || 610 !painted_flush_callback_.is_null() ||
682 offscreen_flush_pending_; 611 offscreen_flush_pending_;
683 } 612 }
684 613
685 } // namespace ppapi 614 } // namespace ppapi
686 } // namespace webkit 615 } // namespace webkit
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698