| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 #ifndef WEBKIT_PLUGINS_PPAPI_PPB_IMAGE_DATA_IMPL_H_ | 5 #ifndef WEBKIT_PLUGINS_PPAPI_PPB_IMAGE_DATA_IMPL_H_ |
| 6 #define WEBKIT_PLUGINS_PPAPI_PPB_IMAGE_DATA_IMPL_H_ | 6 #define WEBKIT_PLUGINS_PPAPI_PPB_IMAGE_DATA_IMPL_H_ |
| 7 | 7 |
| 8 #include "base/basictypes.h" | 8 #include "base/basictypes.h" |
| 9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
| 10 #include "ppapi/c/ppb_image_data.h" | 10 #include "ppapi/c/ppb_image_data.h" |
| (...skipping 10 matching lines...) Expand all Loading... |
| 21 namespace webkit { | 21 namespace webkit { |
| 22 namespace ppapi { | 22 namespace ppapi { |
| 23 | 23 |
| 24 class WEBKIT_PLUGINS_EXPORT PPB_ImageData_Impl | 24 class WEBKIT_PLUGINS_EXPORT PPB_ImageData_Impl |
| 25 : public ::ppapi::Resource, | 25 : public ::ppapi::Resource, |
| 26 public ::ppapi::PPB_ImageData_Shared, | 26 public ::ppapi::PPB_ImageData_Shared, |
| 27 public NON_EXPORTED_BASE(::ppapi::thunk::PPB_ImageData_API) { | 27 public NON_EXPORTED_BASE(::ppapi::thunk::PPB_ImageData_API) { |
| 28 public: | 28 public: |
| 29 // We delegate most of our implementation to a back-end class that either uses | 29 // We delegate most of our implementation to a back-end class that either uses |
| 30 // a PlatformCanvas (for most trusted stuff) or bare shared memory (for use by | 30 // a PlatformCanvas (for most trusted stuff) or bare shared memory (for use by |
| 31 // NaCl). This makes it cheap & easy to implement Swap. | 31 // NaCl, or trusted plugins when the PlatformCanvas isn't needed). This makes |
| 32 // it cheap & easy to implement Swap. |
| 32 class Backend { | 33 class Backend { |
| 33 public: | 34 public: |
| 34 virtual ~Backend() {}; | 35 virtual ~Backend() {}; |
| 35 virtual bool Init(PPB_ImageData_Impl* impl, PP_ImageDataFormat format, | 36 virtual bool Init(PPB_ImageData_Impl* impl, PP_ImageDataFormat format, |
| 36 int width, int height, bool init_to_zero) = 0; | 37 int width, int height, bool init_to_zero) = 0; |
| 37 virtual bool IsMapped() const = 0; | 38 virtual bool IsMapped() const = 0; |
| 38 virtual PluginDelegate::PlatformImage2D* PlatformImage() const = 0; | 39 virtual PluginDelegate::PlatformImage2D* PlatformImage() const = 0; |
| 39 virtual void* Map() = 0; | 40 virtual void* Map() = 0; |
| 40 virtual void Unmap() = 0; | 41 virtual void Unmap() = 0; |
| 41 virtual int32_t GetSharedMemory(int* handle, uint32_t* byte_count) = 0; | 42 virtual int32_t GetSharedMemory(int* handle, uint32_t* byte_count) = 0; |
| 42 virtual SkCanvas* GetPlatformCanvas() = 0; | 43 virtual SkCanvas* GetPlatformCanvas() = 0; |
| 43 virtual SkCanvas* GetCanvas() = 0; | 44 virtual SkCanvas* GetCanvas() = 0; |
| 44 virtual const SkBitmap* GetMappedBitmap() const = 0; | 45 virtual const SkBitmap* GetMappedBitmap() const = 0; |
| 45 }; | 46 }; |
| 46 | 47 |
| 47 // If you call this constructor, you must also call Init before use. Normally | 48 // If you call this constructor, you must also call Init before use. Normally |
| 48 // you should use the static Create function, but this constructor is needed | 49 // you should use the static Create function, but this constructor is needed |
| 49 // for some internal uses of ImageData (like Graphics2D). | 50 // for some internal uses of ImageData (like Graphics2D). |
| 50 enum ImageDataType { PLATFORM, NACL }; | 51 PPB_ImageData_Impl(PP_Instance instance, |
| 51 PPB_ImageData_Impl(PP_Instance instance, ImageDataType type); | 52 PPB_ImageData_Shared::ImageDataType type); |
| 52 virtual ~PPB_ImageData_Impl(); | 53 virtual ~PPB_ImageData_Impl(); |
| 53 | 54 |
| 54 bool Init(PP_ImageDataFormat format, | 55 bool Init(PP_ImageDataFormat format, |
| 55 int width, int height, | 56 int width, int height, |
| 56 bool init_to_zero); | 57 bool init_to_zero); |
| 57 | 58 |
| 58 // Create an ImageData backed by a PlatformCanvas. You must use this if you | 59 static PP_Resource Create(PP_Instance pp_instance, |
| 59 // intend the ImageData to be usable in platform-specific APIs (like font | 60 PPB_ImageData_Shared::ImageDataType type, |
| 60 // rendering or rendering widgets like scrollbars). | 61 PP_ImageDataFormat format, |
| 61 static PP_Resource CreatePlatform(PP_Instance pp_instance, | 62 const PP_Size& size, |
| 62 PP_ImageDataFormat format, | 63 PP_Bool init_to_zero); |
| 63 const PP_Size& size, | |
| 64 PP_Bool init_to_zero); | |
| 65 | |
| 66 // Use this to create an ImageData for use with NaCl. This is backed by a | |
| 67 // simple shared memory buffer. | |
| 68 static PP_Resource CreateNaCl(PP_Instance pp_instance, | |
| 69 PP_ImageDataFormat format, | |
| 70 const PP_Size& size, | |
| 71 PP_Bool init_to_zero); | |
| 72 | 64 |
| 73 int width() const { return width_; } | 65 int width() const { return width_; } |
| 74 int height() const { return height_; } | 66 int height() const { return height_; } |
| 75 | 67 |
| 76 // Returns the image format. | 68 // Returns the image format. |
| 77 PP_ImageDataFormat format() const { return format_; } | 69 PP_ImageDataFormat format() const { return format_; } |
| 78 | 70 |
| 79 // Returns true if this image is mapped. False means that the image is either | 71 // Returns true if this image is mapped. False means that the image is either |
| 80 // invalid or not mapped. See ImageDataAutoMapper below. | 72 // invalid or not mapped. See ImageDataAutoMapper below. |
| 81 bool IsMapped() const; | 73 bool IsMapped() const; |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 125 // This will be NULL before initialization, and if this PPB_ImageData_Impl is | 117 // This will be NULL before initialization, and if this PPB_ImageData_Impl is |
| 126 // swapped with another. | 118 // swapped with another. |
| 127 scoped_ptr<PluginDelegate::PlatformImage2D> platform_image_; | 119 scoped_ptr<PluginDelegate::PlatformImage2D> platform_image_; |
| 128 | 120 |
| 129 // When the device is mapped, this is the image. Null when umapped. | 121 // When the device is mapped, this is the image. Null when umapped. |
| 130 scoped_ptr<SkCanvas> mapped_canvas_; | 122 scoped_ptr<SkCanvas> mapped_canvas_; |
| 131 | 123 |
| 132 DISALLOW_COPY_AND_ASSIGN(ImageDataPlatformBackend); | 124 DISALLOW_COPY_AND_ASSIGN(ImageDataPlatformBackend); |
| 133 }; | 125 }; |
| 134 | 126 |
| 135 class ImageDataNaClBackend : public PPB_ImageData_Impl::Backend { | 127 class ImageDataSimpleBackend : public PPB_ImageData_Impl::Backend { |
| 136 public: | 128 public: |
| 137 ImageDataNaClBackend(); | 129 ImageDataSimpleBackend(); |
| 138 virtual ~ImageDataNaClBackend(); | 130 virtual ~ImageDataSimpleBackend(); |
| 139 | 131 |
| 140 // PPB_ImageData_Impl::Backend implementation. | 132 // PPB_ImageData_Impl::Backend implementation. |
| 141 bool Init(PPB_ImageData_Impl* impl, PP_ImageDataFormat format, | 133 bool Init(PPB_ImageData_Impl* impl, PP_ImageDataFormat format, |
| 142 int width, int height, bool init_to_zero) OVERRIDE; | 134 int width, int height, bool init_to_zero) OVERRIDE; |
| 143 virtual bool IsMapped() const OVERRIDE; | 135 virtual bool IsMapped() const OVERRIDE; |
| 144 PluginDelegate::PlatformImage2D* PlatformImage() const OVERRIDE; | 136 PluginDelegate::PlatformImage2D* PlatformImage() const OVERRIDE; |
| 145 virtual void* Map() OVERRIDE; | 137 virtual void* Map() OVERRIDE; |
| 146 virtual void Unmap() OVERRIDE; | 138 virtual void Unmap() OVERRIDE; |
| 147 virtual int32_t GetSharedMemory(int* handle, uint32_t* byte_count) OVERRIDE; | 139 virtual int32_t GetSharedMemory(int* handle, uint32_t* byte_count) OVERRIDE; |
| 148 virtual SkCanvas* GetPlatformCanvas() OVERRIDE; | 140 virtual SkCanvas* GetPlatformCanvas() OVERRIDE; |
| 149 virtual SkCanvas* GetCanvas() OVERRIDE; | 141 virtual SkCanvas* GetCanvas() OVERRIDE; |
| 150 virtual const SkBitmap* GetMappedBitmap() const OVERRIDE; | 142 virtual const SkBitmap* GetMappedBitmap() const OVERRIDE; |
| 151 | 143 |
| 152 private: | 144 private: |
| 153 scoped_ptr<base::SharedMemory> shared_memory_; | 145 scoped_ptr<base::SharedMemory> shared_memory_; |
| 154 // skia_bitmap_ is backed by shared_memory_. | 146 // skia_bitmap_ is backed by shared_memory_. |
| 155 SkBitmap skia_bitmap_; | 147 SkBitmap skia_bitmap_; |
| 156 scoped_ptr<SkCanvas> skia_canvas_; | 148 scoped_ptr<SkCanvas> skia_canvas_; |
| 157 uint32 map_count_; | 149 uint32 map_count_; |
| 158 | 150 |
| 159 DISALLOW_COPY_AND_ASSIGN(ImageDataNaClBackend); | 151 DISALLOW_COPY_AND_ASSIGN(ImageDataSimpleBackend); |
| 160 }; | 152 }; |
| 161 | 153 |
| 162 // Manages mapping an image resource if necessary. Use this to ensure the | 154 // Manages mapping an image resource if necessary. Use this to ensure the |
| 163 // image is mapped. The destructor will put the image back into the previous | 155 // image is mapped. The destructor will put the image back into the previous |
| 164 // state. You must check is_valid() to make sure the image was successfully | 156 // state. You must check is_valid() to make sure the image was successfully |
| 165 // mapped before using it. | 157 // mapped before using it. |
| 166 // | 158 // |
| 167 // Example: | 159 // Example: |
| 168 // ImageDataAutoMapper mapper(image_data); | 160 // ImageDataAutoMapper mapper(image_data); |
| 169 // if (!mapper.is_valid()) | 161 // if (!mapper.is_valid()) |
| (...skipping 25 matching lines...) Expand all Loading... |
| 195 bool is_valid_; | 187 bool is_valid_; |
| 196 bool needs_unmap_; | 188 bool needs_unmap_; |
| 197 | 189 |
| 198 DISALLOW_COPY_AND_ASSIGN(ImageDataAutoMapper); | 190 DISALLOW_COPY_AND_ASSIGN(ImageDataAutoMapper); |
| 199 }; | 191 }; |
| 200 | 192 |
| 201 } // namespace ppapi | 193 } // namespace ppapi |
| 202 } // namespace webkit | 194 } // namespace webkit |
| 203 | 195 |
| 204 #endif // WEBKIT_PLUGINS_PPAPI_PPB_IMAGE_DATA_IMPL_H_ | 196 #endif // WEBKIT_PLUGINS_PPAPI_PPB_IMAGE_DATA_IMPL_H_ |
| OLD | NEW |