| Index: webkit/plugins/ppapi/ppb_image_data_impl.h | 
| diff --git a/webkit/plugins/ppapi/ppb_image_data_impl.h b/webkit/plugins/ppapi/ppb_image_data_impl.h | 
| index 817b238fcca0b38ff0869b22e0c9a4bfc4c768e6..e4601dbc3d6fe629b4eea873a995b6da2775fb92 100644 | 
| --- a/webkit/plugins/ppapi/ppb_image_data_impl.h | 
| +++ b/webkit/plugins/ppapi/ppb_image_data_impl.h | 
| @@ -11,6 +11,7 @@ | 
| #include "ppapi/shared_impl/ppb_image_data_shared.h" | 
| #include "ppapi/shared_impl/resource.h" | 
| #include "ppapi/thunk/ppb_image_data_api.h" | 
| +#include "third_party/skia/include/core/SkCanvas.h" | 
| #include "webkit/plugins/ppapi/plugin_delegate.h" | 
| #include "webkit/plugins/webkit_plugins_export.h" | 
|  | 
| @@ -23,24 +24,54 @@ class SkBitmap; | 
| namespace webkit { | 
| namespace ppapi { | 
|  | 
| -class PPB_ImageData_Impl : public ::ppapi::Resource, | 
| -                           public ::ppapi::PPB_ImageData_Shared, | 
| -                           public ::ppapi::thunk::PPB_ImageData_API { | 
| +WEBKIT_PLUGINS_EXPORT class PPB_ImageData_Impl | 
| +    : public ::ppapi::Resource, | 
| +      public ::ppapi::PPB_ImageData_Shared, | 
| +      public ::ppapi::thunk::PPB_ImageData_API { | 
| public: | 
| +  // We delegate most of our implementation to a back-end class that either uses | 
| +  // a PlatformCanvas (for most trusted stuff) or bare shared memory (for use by | 
| +  // NaCl). This makes it cheap & easy to implement Swap. | 
| +  class Backend { | 
| +   public: | 
| +    virtual ~Backend() {}; | 
| +    virtual bool Init(PPB_ImageData_Impl* impl, PP_ImageDataFormat format, | 
| +                      int width, int height, bool init_to_zero) = 0; | 
| +    virtual bool IsMapped() const = 0; | 
| +    virtual PluginDelegate::PlatformImage2D* PlatformImage() const = 0; | 
| +    virtual void* Map() = 0; | 
| +    virtual void Unmap() = 0; | 
| +    virtual int32_t GetSharedMemory(int* handle, uint32_t* byte_count) = 0; | 
| +    virtual skia::PlatformCanvas* GetPlatformCanvas() = 0; | 
| +    virtual SkCanvas* GetCanvas() = 0; | 
| +    virtual const SkBitmap* GetMappedBitmap() const = 0; | 
| +  }; | 
| + | 
| // If you call this constructor, you must also call Init before use. Normally | 
| // you should use the static Create function, but this constructor is needed | 
| // for some internal uses of ImageData (like Graphics2D). | 
| -  WEBKIT_PLUGINS_EXPORT explicit PPB_ImageData_Impl(PP_Instance instance); | 
| +  enum ImageDataType { PLATFORM, NACL }; | 
| +  PPB_ImageData_Impl(PP_Instance instance, ImageDataType type); | 
| virtual ~PPB_ImageData_Impl(); | 
|  | 
| -  static PP_Resource Create(PP_Instance pp_instance, | 
| -                            PP_ImageDataFormat format, | 
| -                            const PP_Size& size, | 
| -                            PP_Bool init_to_zero); | 
| - | 
| -  WEBKIT_PLUGINS_EXPORT bool Init(PP_ImageDataFormat format, | 
| -                                  int width, int height, | 
| -                                  bool init_to_zero); | 
| +  bool Init(PP_ImageDataFormat format, | 
| +            int width, int height, | 
| +            bool init_to_zero); | 
| + | 
| +  // Create an ImageData backed by a PlatformCanvas. You must use this if you | 
| +  // intend the ImageData to be usable in platform-specific APIs (like font | 
| +  // rendering or rendering widgets like scrollbars). | 
| +  static PP_Resource CreatePlatform(PP_Instance pp_instance, | 
| +                                    PP_ImageDataFormat format, | 
| +                                    const PP_Size& size, | 
| +                                    PP_Bool init_to_zero); | 
| + | 
| +  // Use this to create an ImageData for use with NaCl. This is backed by a | 
| +  // simple shared memory buffer. | 
| +  static PP_Resource CreateNaCl(PP_Instance pp_instance, | 
| +                                PP_ImageDataFormat format, | 
| +                                const PP_Size& size, | 
| +                                PP_Bool init_to_zero); | 
|  | 
| int width() const { return width_; } | 
| int height() const { return height_; } | 
| @@ -50,12 +81,10 @@ class PPB_ImageData_Impl : public ::ppapi::Resource, | 
|  | 
| // Returns true if this image is mapped. False means that the image is either | 
| // invalid or not mapped. See ImageDataAutoMapper below. | 
| -  bool is_mapped() const { return !!mapped_canvas_.get(); } | 
| - | 
| -  PluginDelegate::PlatformImage2D* platform_image() const { | 
| -    return platform_image_.get(); | 
| -  } | 
| +  bool IsMapped() const; | 
| +  PluginDelegate::PlatformImage2D* PlatformImage() const; | 
|  | 
| +  // Resource override. | 
| virtual ::ppapi::thunk::PPB_ImageData_API* AsPPB_ImageData_API() OVERRIDE; | 
|  | 
| // PPB_ImageData_API implementation. | 
| @@ -64,6 +93,7 @@ class PPB_ImageData_Impl : public ::ppapi::Resource, | 
| virtual void Unmap() OVERRIDE; | 
| virtual int32_t GetSharedMemory(int* handle, uint32_t* byte_count) OVERRIDE; | 
| virtual skia::PlatformCanvas* GetPlatformCanvas() OVERRIDE; | 
| +  virtual SkCanvas* GetCanvas() OVERRIDE; | 
|  | 
| const SkBitmap* GetMappedBitmap() const; | 
|  | 
| @@ -71,6 +101,32 @@ class PPB_ImageData_Impl : public ::ppapi::Resource, | 
| void Swap(PPB_ImageData_Impl* other); | 
|  | 
| private: | 
| +  PP_ImageDataFormat format_; | 
| +  int width_; | 
| +  int height_; | 
| +  scoped_ptr<Backend> backend_; | 
| + | 
| +  DISALLOW_COPY_AND_ASSIGN(PPB_ImageData_Impl); | 
| +}; | 
| + | 
| +class ImageDataPlatformBackend : public PPB_ImageData_Impl::Backend { | 
| + public: | 
| +  ImageDataPlatformBackend(); | 
| +  virtual ~ImageDataPlatformBackend(); | 
| + | 
| +  // PPB_ImageData_Impl::Backend implementation. | 
| +  virtual bool Init(PPB_ImageData_Impl* impl, PP_ImageDataFormat format, | 
| +                    int width, int height, bool init_to_zero) OVERRIDE; | 
| +  virtual bool IsMapped() const OVERRIDE; | 
| +  virtual PluginDelegate::PlatformImage2D* PlatformImage() const OVERRIDE; | 
| +  virtual void* Map() OVERRIDE; | 
| +  virtual void Unmap() OVERRIDE; | 
| +  virtual int32_t GetSharedMemory(int* handle, uint32_t* byte_count) OVERRIDE; | 
| +  virtual skia::PlatformCanvas* GetPlatformCanvas() OVERRIDE; | 
| +  virtual SkCanvas* GetCanvas() OVERRIDE; | 
| +  virtual const SkBitmap* GetMappedBitmap() const OVERRIDE; | 
| + | 
| + private: | 
| // This will be NULL before initialization, and if this PPB_ImageData_Impl is | 
| // swapped with another. | 
| scoped_ptr<PluginDelegate::PlatformImage2D> platform_image_; | 
| @@ -78,11 +134,34 @@ class PPB_ImageData_Impl : public ::ppapi::Resource, | 
| // When the device is mapped, this is the image. Null when umapped. | 
| scoped_ptr<skia::PlatformCanvas> mapped_canvas_; | 
|  | 
| -  PP_ImageDataFormat format_; | 
| -  int width_; | 
| -  int height_; | 
| +  DISALLOW_COPY_AND_ASSIGN(ImageDataPlatformBackend); | 
| +}; | 
|  | 
| -  DISALLOW_COPY_AND_ASSIGN(PPB_ImageData_Impl); | 
| +class ImageDataNaClBackend : public PPB_ImageData_Impl::Backend { | 
| + public: | 
| +  ImageDataNaClBackend(); | 
| +  virtual ~ImageDataNaClBackend(); | 
| + | 
| +  // PPB_ImageData_Impl::Backend implementation. | 
| +  bool Init(PPB_ImageData_Impl* impl, PP_ImageDataFormat format, | 
| +            int width, int height, bool init_to_zero) OVERRIDE; | 
| +  virtual bool IsMapped() const OVERRIDE; | 
| +  PluginDelegate::PlatformImage2D* PlatformImage() const OVERRIDE; | 
| +  virtual void* Map() OVERRIDE; | 
| +  virtual void Unmap() OVERRIDE; | 
| +  virtual int32_t GetSharedMemory(int* handle, uint32_t* byte_count) OVERRIDE; | 
| +  virtual skia::PlatformCanvas* GetPlatformCanvas() OVERRIDE; | 
| +  virtual SkCanvas* GetCanvas() OVERRIDE; | 
| +  virtual const SkBitmap* GetMappedBitmap() const OVERRIDE; | 
| + | 
| + private: | 
| +  scoped_ptr<base::SharedMemory> shared_memory_; | 
| +  // skia_bitmap_ is backed by shared_memory_. | 
| +  SkBitmap skia_bitmap_; | 
| +  SkCanvas skia_canvas_; | 
| +  uint32 map_count_; | 
| + | 
| +  DISALLOW_COPY_AND_ASSIGN(ImageDataNaClBackend); | 
| }; | 
|  | 
| // Manages mapping an image resource if necessary. Use this to ensure the | 
| @@ -99,7 +178,7 @@ class ImageDataAutoMapper { | 
| public: | 
| explicit ImageDataAutoMapper(PPB_ImageData_Impl* image_data) | 
| : image_data_(image_data) { | 
| -    if (image_data_->is_mapped()) { | 
| +    if (image_data_->IsMapped()) { | 
| is_valid_ = true; | 
| needs_unmap_ = false; | 
| } else { | 
|  |