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

Side by Side Diff: webkit/glue/plugins/pepper_device_context_2d.cc

Issue 2800028: Simplfy Pepepr2 bolierplate code. (Closed) Base URL: http://src.chromium.org/git/chromium.git
Patch Set: Updated. Created 10 years, 5 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
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 "webkit/glue/plugins/pepper_device_context_2d.h" 5 #include "webkit/glue/plugins/pepper_device_context_2d.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 "gfx/point.h" 12 #include "gfx/point.h"
13 #include "gfx/rect.h" 13 #include "gfx/rect.h"
14 #include "skia/ext/platform_canvas.h" 14 #include "skia/ext/platform_canvas.h"
15 #include "third_party/ppapi/c/pp_errors.h" 15 #include "third_party/ppapi/c/pp_errors.h"
16 #include "third_party/ppapi/c/pp_module.h" 16 #include "third_party/ppapi/c/pp_module.h"
17 #include "third_party/ppapi/c/pp_rect.h" 17 #include "third_party/ppapi/c/pp_rect.h"
18 #include "third_party/ppapi/c/pp_resource.h" 18 #include "third_party/ppapi/c/pp_resource.h"
19 #include "third_party/ppapi/c/ppb_device_context_2d.h" 19 #include "third_party/ppapi/c/ppb_device_context_2d.h"
20 #include "third_party/skia/include/core/SkBitmap.h" 20 #include "third_party/skia/include/core/SkBitmap.h"
21 #include "webkit/glue/plugins/pepper_image_data.h" 21 #include "webkit/glue/plugins/pepper_image_data.h"
22 #include "webkit/glue/plugins/pepper_plugin_instance.h" 22 #include "webkit/glue/plugins/pepper_plugin_instance.h"
23 #include "webkit/glue/plugins/pepper_plugin_module.h" 23 #include "webkit/glue/plugins/pepper_plugin_module.h"
24 #include "webkit/glue/plugins/pepper_resource_tracker.h"
25 24
26 #if defined(OS_MACOSX) 25 #if defined(OS_MACOSX)
27 #include "base/mac_util.h" 26 #include "base/mac_util.h"
28 #include "base/scoped_cftyperef.h" 27 #include "base/scoped_cftyperef.h"
29 #endif 28 #endif
30 29
31 namespace pepper { 30 namespace pepper {
32 31
33 namespace { 32 namespace {
34 33
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
71 70
72 scoped_refptr<DeviceContext2D> context(new DeviceContext2D(module)); 71 scoped_refptr<DeviceContext2D> context(new DeviceContext2D(module));
73 if (!context->Init(width, height, is_always_opaque)) 72 if (!context->Init(width, height, is_always_opaque))
74 return NULL; 73 return NULL;
75 context->AddRef(); // AddRef for the caller. 74 context->AddRef(); // AddRef for the caller.
76 return context->GetResource(); 75 return context->GetResource();
77 } 76 }
78 77
79 bool IsDeviceContext2D(PP_Resource resource) { 78 bool IsDeviceContext2D(PP_Resource resource) {
80 scoped_refptr<DeviceContext2D> context( 79 scoped_refptr<DeviceContext2D> context(
81 ResourceTracker::Get()->GetAsDeviceContext2D(resource)); 80 Resource::GetAs<DeviceContext2D>(resource));
82 return !!context.get(); 81 return !!context.get();
83 } 82 }
84 83
85 bool Describe(PP_Resource device_context, 84 bool Describe(PP_Resource device_context,
86 int32_t* width, int32_t* height, bool* is_always_opaque) { 85 int32_t* width, int32_t* height, bool* is_always_opaque) {
87 scoped_refptr<DeviceContext2D> context( 86 scoped_refptr<DeviceContext2D> context(
88 ResourceTracker::Get()->GetAsDeviceContext2D(device_context)); 87 Resource::GetAs<DeviceContext2D>(device_context));
89 if (!context.get()) 88 if (!context.get())
90 return false; 89 return false;
91 return context->Describe(width, height, is_always_opaque); 90 return context->Describe(width, height, is_always_opaque);
92 } 91 }
93 92
94 bool PaintImageData(PP_Resource device_context, 93 bool PaintImageData(PP_Resource device_context,
95 PP_Resource image, 94 PP_Resource image,
96 int32_t x, int32_t y, 95 int32_t x, int32_t y,
97 const PP_Rect* src_rect) { 96 const PP_Rect* src_rect) {
98 scoped_refptr<DeviceContext2D> context( 97 scoped_refptr<DeviceContext2D> context(
99 ResourceTracker::Get()->GetAsDeviceContext2D(device_context)); 98 Resource::GetAs<DeviceContext2D>(device_context));
100 if (!context.get()) 99 if (!context.get())
101 return false; 100 return false;
102 return context->PaintImageData(image, x, y, src_rect); 101 return context->PaintImageData(image, x, y, src_rect);
103 } 102 }
104 103
105 bool Scroll(PP_Resource device_context, 104 bool Scroll(PP_Resource device_context,
106 const PP_Rect* clip_rect, 105 const PP_Rect* clip_rect,
107 int32_t dx, int32_t dy) { 106 int32_t dx, int32_t dy) {
108 scoped_refptr<DeviceContext2D> context( 107 scoped_refptr<DeviceContext2D> context(
109 ResourceTracker::Get()->GetAsDeviceContext2D(device_context)); 108 Resource::GetAs<DeviceContext2D>(device_context));
110 if (!context.get()) 109 if (!context.get())
111 return false; 110 return false;
112 return context->Scroll(clip_rect, dx, dy); 111 return context->Scroll(clip_rect, dx, dy);
113 } 112 }
114 113
115 bool ReplaceContents(PP_Resource device_context, PP_Resource image) { 114 bool ReplaceContents(PP_Resource device_context, PP_Resource image) {
116 scoped_refptr<DeviceContext2D> context( 115 scoped_refptr<DeviceContext2D> context(
117 ResourceTracker::Get()->GetAsDeviceContext2D(device_context)); 116 Resource::GetAs<DeviceContext2D>(device_context));
118 if (!context.get()) 117 if (!context.get())
119 return false; 118 return false;
120 return context->ReplaceContents(image); 119 return context->ReplaceContents(image);
121 } 120 }
122 121
123 int32_t Flush(PP_Resource device_context, 122 int32_t Flush(PP_Resource device_context,
124 PP_CompletionCallback callback) { 123 PP_CompletionCallback callback) {
125 scoped_refptr<DeviceContext2D> context( 124 scoped_refptr<DeviceContext2D> context(
126 ResourceTracker::Get()->GetAsDeviceContext2D(device_context)); 125 Resource::GetAs<DeviceContext2D>(device_context));
127 if (!context.get()) 126 if (!context.get())
128 return PP_Error_BadResource; 127 return PP_Error_BadResource;
129 return context->Flush(callback); 128 return context->Flush(callback);
130 } 129 }
131 130
132 const PPB_DeviceContext2D ppb_devicecontext2d = { 131 const PPB_DeviceContext2D ppb_devicecontext2d = {
133 &Create, 132 &Create,
134 &IsDeviceContext2D, 133 &IsDeviceContext2D,
135 &Describe, 134 &Describe,
136 &PaintImageData, 135 &PaintImageData,
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
202 bool* is_always_opaque) { 201 bool* is_always_opaque) {
203 *width = image_data_->width(); 202 *width = image_data_->width();
204 *height = image_data_->height(); 203 *height = image_data_->height();
205 *is_always_opaque = false; // TODO(brettw) implement this. 204 *is_always_opaque = false; // TODO(brettw) implement this.
206 return true; 205 return true;
207 } 206 }
208 207
209 bool DeviceContext2D::PaintImageData(PP_Resource image, 208 bool DeviceContext2D::PaintImageData(PP_Resource image,
210 int32_t x, int32_t y, 209 int32_t x, int32_t y,
211 const PP_Rect* src_rect) { 210 const PP_Rect* src_rect) {
212 scoped_refptr<ImageData> image_resource( 211 scoped_refptr<ImageData> image_resource(Resource::GetAs<ImageData>(image));
213 ResourceTracker::Get()->GetAsImageData(image));
214 if (!image_resource.get()) 212 if (!image_resource.get())
215 return false; 213 return false;
216 214
217 QueuedOperation operation(QueuedOperation::PAINT); 215 QueuedOperation operation(QueuedOperation::PAINT);
218 operation.paint_image = image_resource; 216 operation.paint_image = image_resource;
219 if (!ValidateAndConvertRect(src_rect, image_resource->width(), 217 if (!ValidateAndConvertRect(src_rect, image_resource->width(),
220 image_resource->height(), 218 image_resource->height(),
221 &operation.paint_src_rect)) 219 &operation.paint_src_rect))
222 return false; 220 return false;
223 221
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
255 return true; 253 return true;
256 254
257 operation.scroll_dx = dx; 255 operation.scroll_dx = dx;
258 operation.scroll_dy = dy; 256 operation.scroll_dy = dy;
259 257
260 queued_operations_.push_back(operation); 258 queued_operations_.push_back(operation);
261 return false; 259 return false;
262 } 260 }
263 261
264 bool DeviceContext2D::ReplaceContents(PP_Resource image) { 262 bool DeviceContext2D::ReplaceContents(PP_Resource image) {
265 scoped_refptr<ImageData> image_resource( 263 scoped_refptr<ImageData> image_resource(Resource::GetAs<ImageData>(image));
266 ResourceTracker::Get()->GetAsImageData(image));
267 if (!image_resource.get()) 264 if (!image_resource.get())
268 return false; 265 return false;
269 if (image_resource->format() != PP_IMAGEDATAFORMAT_BGRA_PREMUL) 266 if (image_resource->format() != PP_IMAGEDATAFORMAT_BGRA_PREMUL)
270 return false; 267 return false;
271 268
272 if (image_resource->width() != image_data_->width() || 269 if (image_resource->width() != image_data_->width() ||
273 image_resource->height() != image_data_->height()) 270 image_resource->height() != image_data_->height())
274 return false; 271 return false;
275 272
276 QueuedOperation operation(QueuedOperation::REPLACE); 273 QueuedOperation operation(QueuedOperation::REPLACE);
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
329 } else { 326 } else {
330 // There's nothing visible to invalidate so just schedule the callback to 327 // There's nothing visible to invalidate so just schedule the callback to
331 // execute in the next round of the message loop. 328 // execute in the next round of the message loop.
332 ScheduleOffscreenCallback(FlushCallbackData(callback)); 329 ScheduleOffscreenCallback(FlushCallbackData(callback));
333 } 330 }
334 return PP_Error_WouldBlock; 331 return PP_Error_WouldBlock;
335 } 332 }
336 333
337 bool DeviceContext2D::ReadImageData(PP_Resource image, int32_t x, int32_t y) { 334 bool DeviceContext2D::ReadImageData(PP_Resource image, int32_t x, int32_t y) {
338 // Get and validate the image object to paint into. 335 // Get and validate the image object to paint into.
339 scoped_refptr<ImageData> image_resource( 336 scoped_refptr<ImageData> image_resource(Resource::GetAs<ImageData>(image));
340 ResourceTracker::Get()->GetAsImageData(image));
341 if (!image_resource.get()) 337 if (!image_resource.get())
342 return false; 338 return false;
343 if (image_resource->format() != PP_IMAGEDATAFORMAT_BGRA_PREMUL) 339 if (image_resource->format() != PP_IMAGEDATAFORMAT_BGRA_PREMUL)
344 return false; // Must be in the right format. 340 return false; // Must be in the right format.
345 341
346 // Validate the bitmap position. 342 // Validate the bitmap position.
347 if (x < 0 || 343 if (x < 0 ||
348 static_cast<int64>(x) + static_cast<int64>(image_resource->width()) > 344 static_cast<int64>(x) + static_cast<int64>(image_resource->width()) >
349 image_data_->width()) 345 image_data_->width())
350 return false; 346 return false;
(...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after
538 data.Execute(PP_OK); 534 data.Execute(PP_OK);
539 } 535 }
540 536
541 bool DeviceContext2D::HasPendingFlush() const { 537 bool DeviceContext2D::HasPendingFlush() const {
542 return !unpainted_flush_callback_.is_null() || 538 return !unpainted_flush_callback_.is_null() ||
543 !painted_flush_callback_.is_null() || 539 !painted_flush_callback_.is_null() ||
544 offscreen_flush_pending_; 540 offscreen_flush_pending_;
545 } 541 }
546 542
547 } // namespace pepper 543 } // namespace pepper
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698