Index: webkit/plugins/ppapi/ppb_graphics_2d_impl.cc |
=================================================================== |
--- webkit/plugins/ppapi/ppb_graphics_2d_impl.cc (revision 0) |
+++ webkit/plugins/ppapi/ppb_graphics_2d_impl.cc (working copy) |
@@ -2,7 +2,7 @@ |
// Use of this source code is governed by a BSD-style license that can be |
// found in the LICENSE file. |
-#include "webkit/glue/plugins/pepper_graphics_2d.h" |
+#include "webkit/plugins/ppapi/ppb_graphics_2d_impl.h" |
#include <iterator> |
@@ -19,17 +19,18 @@ |
#include "ppapi/c/pp_resource.h" |
#include "ppapi/c/ppb_graphics_2d.h" |
#include "third_party/skia/include/core/SkBitmap.h" |
-#include "webkit/glue/plugins/pepper_common.h" |
-#include "webkit/glue/plugins/pepper_image_data.h" |
-#include "webkit/glue/plugins/pepper_plugin_instance.h" |
-#include "webkit/glue/plugins/pepper_plugin_module.h" |
+#include "webkit/plugins/ppapi/common.h" |
+#include "webkit/plugins/ppapi/plugin_instance.h" |
+#include "webkit/plugins/ppapi/plugin_module.h" |
+#include "webkit/plugins/ppapi/ppb_image_data_impl.h" |
#if defined(OS_MACOSX) |
#include "base/mac_util.h" |
#include "base/mac/scoped_cftyperef.h" |
#endif |
-namespace pepper { |
+namespace webkit { |
+namespace ppapi { |
namespace { |
@@ -81,11 +82,11 @@ |
// Converts ImageData from PP_IMAGEDATAFORMAT_BGRA_PREMUL to |
// PP_IMAGEDATAFORMAT_RGBA_PREMUL, or reverse. |
-void ConvertImageData(ImageData* src_image, const SkIRect& src_rect, |
- ImageData* dest_image, const SkRect& dest_rect) { |
+void ConvertImageData(PPB_ImageData_Impl* src_image, const SkIRect& src_rect, |
+ PPB_ImageData_Impl* dest_image, const SkRect& dest_rect) { |
DCHECK(src_image->format() != dest_image->format()); |
- DCHECK(ImageData::IsImageDataFormatSupported(src_image->format())); |
- DCHECK(ImageData::IsImageDataFormatSupported(dest_image->format())); |
+ DCHECK(PPB_ImageData_Impl::IsImageDataFormatSupported(src_image->format())); |
+ DCHECK(PPB_ImageData_Impl::IsImageDataFormatSupported(dest_image->format())); |
const SkBitmap* src_bitmap = src_image->GetMappedBitmap(); |
const SkBitmap* dest_bitmap = dest_image->GetMappedBitmap(); |
@@ -118,21 +119,21 @@ |
if (!module) |
return 0; |
- scoped_refptr<Graphics2D> context(new Graphics2D(module)); |
+ scoped_refptr<PPB_Graphics2D_Impl> context(new PPB_Graphics2D_Impl(module)); |
if (!context->Init(size->width, size->height, PPBoolToBool(is_always_opaque))) |
return 0; |
return context->GetReference(); |
} |
PP_Bool IsGraphics2D(PP_Resource resource) { |
- return BoolToPPBool(!!Resource::GetAs<Graphics2D>(resource)); |
+ return BoolToPPBool(!!Resource::GetAs<PPB_Graphics2D_Impl>(resource)); |
} |
PP_Bool Describe(PP_Resource graphics_2d, |
PP_Size* size, |
PP_Bool* is_always_opaque) { |
- scoped_refptr<Graphics2D> context( |
- Resource::GetAs<Graphics2D>(graphics_2d)); |
+ scoped_refptr<PPB_Graphics2D_Impl> context( |
+ Resource::GetAs<PPB_Graphics2D_Impl>(graphics_2d)); |
if (!context) |
return PP_FALSE; |
return context->Describe(size, is_always_opaque); |
@@ -142,8 +143,8 @@ |
PP_Resource image_data, |
const PP_Point* top_left, |
const PP_Rect* src_rect) { |
- scoped_refptr<Graphics2D> context( |
- Resource::GetAs<Graphics2D>(graphics_2d)); |
+ scoped_refptr<PPB_Graphics2D_Impl> context( |
+ Resource::GetAs<PPB_Graphics2D_Impl>(graphics_2d)); |
if (context) |
context->PaintImageData(image_data, top_left, src_rect); |
} |
@@ -151,23 +152,23 @@ |
void Scroll(PP_Resource graphics_2d, |
const PP_Rect* clip_rect, |
const PP_Point* amount) { |
- scoped_refptr<Graphics2D> context( |
- Resource::GetAs<Graphics2D>(graphics_2d)); |
+ scoped_refptr<PPB_Graphics2D_Impl> context( |
+ Resource::GetAs<PPB_Graphics2D_Impl>(graphics_2d)); |
if (context) |
context->Scroll(clip_rect, amount); |
} |
void ReplaceContents(PP_Resource graphics_2d, PP_Resource image_data) { |
- scoped_refptr<Graphics2D> context( |
- Resource::GetAs<Graphics2D>(graphics_2d)); |
+ scoped_refptr<PPB_Graphics2D_Impl> context( |
+ Resource::GetAs<PPB_Graphics2D_Impl>(graphics_2d)); |
if (context) |
context->ReplaceContents(image_data); |
} |
int32_t Flush(PP_Resource graphics_2d, |
PP_CompletionCallback callback) { |
- scoped_refptr<Graphics2D> context( |
- Resource::GetAs<Graphics2D>(graphics_2d)); |
+ scoped_refptr<PPB_Graphics2D_Impl> context( |
+ Resource::GetAs<PPB_Graphics2D_Impl>(graphics_2d)); |
if (!context) |
return PP_ERROR_BADRESOURCE; |
return context->Flush(callback); |
@@ -185,7 +186,7 @@ |
} // namespace |
-struct Graphics2D::QueuedOperation { |
+struct PPB_Graphics2D_Impl::QueuedOperation { |
enum Type { |
PAINT, |
SCROLL, |
@@ -203,7 +204,7 @@ |
Type type; |
// Valid when type == PAINT. |
- scoped_refptr<ImageData> paint_image; |
+ scoped_refptr<PPB_ImageData_Impl> paint_image; |
int paint_x, paint_y; |
gfx::Rect paint_src_rect; |
@@ -212,10 +213,10 @@ |
int scroll_dx, scroll_dy; |
// Valid when type == REPLACE. |
- scoped_refptr<ImageData> replace_image; |
+ scoped_refptr<PPB_ImageData_Impl> replace_image; |
}; |
-Graphics2D::Graphics2D(PluginModule* module) |
+PPB_Graphics2D_Impl::PPB_Graphics2D_Impl(PluginModule* module) |
: Resource(module), |
bound_instance_(NULL), |
flushed_any_data_(false), |
@@ -223,19 +224,20 @@ |
is_always_opaque_(false) { |
} |
-Graphics2D::~Graphics2D() { |
+PPB_Graphics2D_Impl::~PPB_Graphics2D_Impl() { |
} |
// static |
-const PPB_Graphics2D* Graphics2D::GetInterface() { |
+const PPB_Graphics2D* PPB_Graphics2D_Impl::GetInterface() { |
return &ppb_graphics_2d; |
} |
-bool Graphics2D::Init(int width, int height, bool is_always_opaque) { |
- // The underlying ImageData will validate the dimensions. |
- image_data_ = new ImageData(module()); |
- if (!image_data_->Init(ImageData::GetNativeImageDataFormat(), width, height, |
- true) || !image_data_->Map()) { |
+bool PPB_Graphics2D_Impl::Init(int width, int height, bool is_always_opaque) { |
+ // The underlying PPB_ImageData_Impl will validate the dimensions. |
+ image_data_ = new PPB_ImageData_Impl(module()); |
+ if (!image_data_->Init(PPB_ImageData_Impl::GetNativeImageDataFormat(), |
+ width, height, true) || |
+ !image_data_->Map()) { |
image_data_ = NULL; |
return false; |
} |
@@ -243,21 +245,25 @@ |
return true; |
} |
-PP_Bool Graphics2D::Describe(PP_Size* size, PP_Bool* is_always_opaque) { |
+PPB_Graphics2D_Impl* PPB_Graphics2D_Impl::AsPPB_Graphics2D_Impl() { |
+ return this; |
+} |
+ |
+PP_Bool PPB_Graphics2D_Impl::Describe(PP_Size* size, PP_Bool* is_always_opaque) { |
size->width = image_data_->width(); |
size->height = image_data_->height(); |
*is_always_opaque = PP_FALSE; // TODO(brettw) implement this. |
return PP_TRUE; |
} |
-void Graphics2D::PaintImageData(PP_Resource image_data, |
- const PP_Point* top_left, |
- const PP_Rect* src_rect) { |
+void PPB_Graphics2D_Impl::PaintImageData(PP_Resource image_data, |
+ const PP_Point* top_left, |
+ const PP_Rect* src_rect) { |
if (!top_left) |
return; |
- scoped_refptr<ImageData> image_resource( |
- Resource::GetAs<ImageData>(image_data)); |
+ scoped_refptr<PPB_ImageData_Impl> image_resource( |
+ Resource::GetAs<PPB_ImageData_Impl>(image_data)); |
if (!image_resource) |
return; |
@@ -286,7 +292,8 @@ |
queued_operations_.push_back(operation); |
} |
-void Graphics2D::Scroll(const PP_Rect* clip_rect, const PP_Point* amount) { |
+void PPB_Graphics2D_Impl::Scroll(const PP_Rect* clip_rect, |
+ const PP_Point* amount) { |
QueuedOperation operation(QueuedOperation::SCROLL); |
if (!ValidateAndConvertRect(clip_rect, |
image_data_->width(), |
@@ -308,12 +315,13 @@ |
queued_operations_.push_back(operation); |
} |
-void Graphics2D::ReplaceContents(PP_Resource image_data) { |
- scoped_refptr<ImageData> image_resource( |
- Resource::GetAs<ImageData>(image_data)); |
+void PPB_Graphics2D_Impl::ReplaceContents(PP_Resource image_data) { |
+ scoped_refptr<PPB_ImageData_Impl> image_resource( |
+ Resource::GetAs<PPB_ImageData_Impl>(image_data)); |
if (!image_resource) |
return; |
- if (!ImageData::IsImageDataFormatSupported(image_resource->format())) |
+ if (!PPB_ImageData_Impl::IsImageDataFormatSupported( |
+ image_resource->format())) |
return; |
if (image_resource->width() != image_data_->width() || |
@@ -325,7 +333,7 @@ |
queued_operations_.push_back(operation); |
} |
-int32_t Graphics2D::Flush(const PP_CompletionCallback& callback) { |
+int32_t PPB_Graphics2D_Impl::Flush(const PP_CompletionCallback& callback) { |
// Don't allow more than one pending flush at a time. |
if (HasPendingFlush()) |
return PP_ERROR_INPROGRESS; |
@@ -387,13 +395,15 @@ |
return PP_ERROR_WOULDBLOCK; |
} |
-bool Graphics2D::ReadImageData(PP_Resource image, |
- const PP_Point* top_left) { |
+bool PPB_Graphics2D_Impl::ReadImageData(PP_Resource image, |
+ const PP_Point* top_left) { |
// Get and validate the image object to paint into. |
- scoped_refptr<ImageData> image_resource(Resource::GetAs<ImageData>(image)); |
+ scoped_refptr<PPB_ImageData_Impl> image_resource( |
+ Resource::GetAs<PPB_ImageData_Impl>(image)); |
if (!image_resource) |
return false; |
- if (!ImageData::IsImageDataFormatSupported(image_resource->format())) |
+ if (!PPB_ImageData_Impl::IsImageDataFormatSupported( |
+ image_resource->format())) |
return false; // Must be in the right format. |
// Validate the bitmap position. |
@@ -436,7 +446,7 @@ |
return true; |
} |
-bool Graphics2D::BindToInstance(PluginInstance* new_instance) { |
+bool PPB_Graphics2D_Impl::BindToInstance(PluginInstance* new_instance) { |
if (bound_instance_ == new_instance) |
return true; // Rebinding the same device, nothing to do. |
if (bound_instance_ && new_instance) |
@@ -470,9 +480,9 @@ |
return true; |
} |
-void Graphics2D::Paint(WebKit::WebCanvas* canvas, |
- const gfx::Rect& plugin_rect, |
- const gfx::Rect& paint_rect) { |
+void PPB_Graphics2D_Impl::Paint(WebKit::WebCanvas* canvas, |
+ const gfx::Rect& plugin_rect, |
+ const gfx::Rect& paint_rect) { |
ImageDataAutoMapper auto_mapper(image_data_); |
const SkBitmap& backing_bitmap = *image_data_->GetMappedBitmap(); |
@@ -525,7 +535,7 @@ |
#endif |
} |
-void Graphics2D::ViewInitiatedPaint() { |
+void PPB_Graphics2D_Impl::ViewInitiatedPaint() { |
// Move any "unpainted" callback to the painted state. See |
// |unpainted_flush_callback_| in the header for more. |
if (!unpainted_flush_callback_.is_null()) { |
@@ -534,7 +544,7 @@ |
} |
} |
-void Graphics2D::ViewFlushedPaint() { |
+void PPB_Graphics2D_Impl::ViewFlushedPaint() { |
// Notify any "painted" callback. See |unpainted_flush_callback_| in the |
// header for more. |
if (!painted_flush_callback_.is_null()) { |
@@ -547,10 +557,10 @@ |
} |
} |
-void Graphics2D::ExecutePaintImageData(ImageData* image, |
- int x, int y, |
- const gfx::Rect& src_rect, |
- gfx::Rect* invalidated_rect) { |
+void PPB_Graphics2D_Impl::ExecutePaintImageData(PPB_ImageData_Impl* image, |
+ int x, int y, |
+ const gfx::Rect& src_rect, |
+ gfx::Rect* invalidated_rect) { |
// Ensure the source image is mapped to read from it. |
ImageDataAutoMapper auto_mapper(image); |
if (!auto_mapper.is_valid()) |
@@ -583,15 +593,16 @@ |
} |
} |
-void Graphics2D::ExecuteScroll(const gfx::Rect& clip, int dx, int dy, |
- gfx::Rect* invalidated_rect) { |
+void PPB_Graphics2D_Impl::ExecuteScroll(const gfx::Rect& clip, |
+ int dx, int dy, |
+ gfx::Rect* invalidated_rect) { |
gfx::ScrollCanvas(image_data_->mapped_canvas(), |
clip, gfx::Point(dx, dy)); |
*invalidated_rect = clip; |
} |
-void Graphics2D::ExecuteReplaceContents(ImageData* image, |
- gfx::Rect* invalidated_rect) { |
+void PPB_Graphics2D_Impl::ExecuteReplaceContents(PPB_ImageData_Impl* image, |
+ gfx::Rect* invalidated_rect) { |
if (image->format() != image_data_->format()) { |
DCHECK(image->width() == image_data_->width() && |
image->height() == image_data_->height()); |
@@ -609,17 +620,18 @@ |
image_data_->width(), image_data_->height()); |
} |
-void Graphics2D::ScheduleOffscreenCallback(const FlushCallbackData& callback) { |
+void PPB_Graphics2D_Impl::ScheduleOffscreenCallback( |
+ const FlushCallbackData& callback) { |
DCHECK(!HasPendingFlush()); |
offscreen_flush_pending_ = true; |
MessageLoop::current()->PostTask( |
FROM_HERE, |
NewRunnableMethod(this, |
- &Graphics2D::ExecuteOffscreenCallback, |
+ &PPB_Graphics2D_Impl::ExecuteOffscreenCallback, |
callback)); |
} |
-void Graphics2D::ExecuteOffscreenCallback(FlushCallbackData data) { |
+void PPB_Graphics2D_Impl::ExecuteOffscreenCallback(FlushCallbackData data) { |
DCHECK(offscreen_flush_pending_); |
// We must clear this flag before issuing the callback. It will be |
@@ -629,10 +641,12 @@ |
data.Execute(PP_OK); |
} |
-bool Graphics2D::HasPendingFlush() const { |
+bool PPB_Graphics2D_Impl::HasPendingFlush() const { |
return !unpainted_flush_callback_.is_null() || |
!painted_flush_callback_.is_null() || |
offscreen_flush_pending_; |
} |
-} // namespace pepper |
+} // namespace ppapi |
+} // namespace webkit |
+ |