diff options
Diffstat (limited to 'webkit/glue/plugins/pepper_image_data.cc')
-rw-r--r-- | webkit/glue/plugins/pepper_image_data.cc | 28 |
1 files changed, 24 insertions, 4 deletions
diff --git a/webkit/glue/plugins/pepper_image_data.cc b/webkit/glue/plugins/pepper_image_data.cc index 8c9bc08..2ee8b21 100644 --- a/webkit/glue/plugins/pepper_image_data.cc +++ b/webkit/glue/plugins/pepper_image_data.cc @@ -15,6 +15,7 @@ #include "third_party/ppapi/c/pp_resource.h" #include "third_party/ppapi/c/ppb_image_data.h" #include "third_party/ppapi/c/trusted/ppb_image_data_trusted.h" +#include "third_party/skia/include/core/SkColorPriv.h" #include "webkit/glue/plugins/pepper_plugin_instance.h" #include "webkit/glue/plugins/pepper_plugin_module.h" @@ -23,11 +24,11 @@ namespace pepper { namespace { PP_ImageDataFormat GetNativeImageDataFormat() { - return PP_IMAGEDATAFORMAT_BGRA_PREMUL; + return ImageData::GetNativeImageDataFormat(); } bool IsImageDataFormatSupported(PP_ImageDataFormat format) { - return format == PP_IMAGEDATAFORMAT_BGRA_PREMUL; + return ImageData::IsImageDataFormatSupported(format); } PP_Resource Create(PP_Module module_id, @@ -98,6 +99,7 @@ const PPB_ImageDataTrusted ppb_imagedata_trusted = { ImageData::ImageData(PluginModule* module) : Resource(module), + format_(PP_IMAGEDATAFORMAT_BGRA_PREMUL), width_(0), height_(0) { } @@ -115,12 +117,28 @@ const PPB_ImageDataTrusted* ImageData::GetTrustedInterface() { return &ppb_imagedata_trusted; } +// static +PP_ImageDataFormat ImageData::GetNativeImageDataFormat() { + if (SK_B32_SHIFT == 0) + return PP_IMAGEDATAFORMAT_BGRA_PREMUL; + else if (SK_R32_SHIFT == 0) + return PP_IMAGEDATAFORMAT_RGBA_PREMUL; + else + return PP_IMAGEDATAFORMAT_BGRA_PREMUL; // Default to something on failure. +} + +// static +bool ImageData::IsImageDataFormatSupported(PP_ImageDataFormat format) { + return format == PP_IMAGEDATAFORMAT_BGRA_PREMUL || + format == PP_IMAGEDATAFORMAT_RGBA_PREMUL; +} + bool ImageData::Init(PP_ImageDataFormat format, int width, int height, bool init_to_zero) { // TODO(brettw) this should be called only on the main thread! // TODO(brettw) use init_to_zero when we implement caching. - if (format != PP_IMAGEDATAFORMAT_BGRA_PREMUL) + if (!IsImageDataFormatSupported(format)) return false; // Only support this one format for now. if (width <= 0 || height <= 0) return false; @@ -130,13 +148,14 @@ bool ImageData::Init(PP_ImageDataFormat format, platform_image_.reset( module()->GetSomeInstance()->delegate()->CreateImage2D(width, height)); + format_ = format; width_ = width; height_ = height; return !!platform_image_.get(); } void ImageData::Describe(PP_ImageDataDesc* desc) const { - desc->format = PP_IMAGEDATAFORMAT_BGRA_PREMUL; + desc->format = format_; desc->size.width = width_; desc->size.height = height_; desc->stride = width_ * 4; @@ -178,6 +197,7 @@ const SkBitmap* ImageData::GetMappedBitmap() const { void ImageData::Swap(ImageData* other) { swap(other->platform_image_, platform_image_); swap(other->mapped_canvas_, mapped_canvas_); + std::swap(other->format_, format_); std::swap(other->width_, width_); std::swap(other->height_, height_); } |