| 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" |
| 11 #include "ppapi/shared_impl/ppb_image_data_shared.h" | 11 #include "ppapi/shared_impl/ppb_image_data_shared.h" |
| 12 #include "ppapi/shared_impl/resource.h" | 12 #include "ppapi/shared_impl/resource.h" |
| 13 #include "ppapi/thunk/ppb_image_data_api.h" | 13 #include "ppapi/thunk/ppb_image_data_api.h" |
| 14 #include "third_party/skia/include/core/SkCanvas.h" | 14 #include "third_party/skia/include/core/SkCanvas.h" |
| 15 #include "webkit/plugins/ppapi/plugin_delegate.h" | 15 #include "webkit/plugins/ppapi/plugin_delegate.h" |
| 16 #include "webkit/plugins/webkit_plugins_export.h" | 16 #include "webkit/plugins/webkit_plugins_export.h" |
| 17 | 17 |
| 18 namespace skia { | |
| 19 class PlatformCanvas; | |
| 20 } | |
| 21 | |
| 22 class SkBitmap; | 18 class SkBitmap; |
| 19 class SkCanvas; |
| 23 | 20 |
| 24 namespace webkit { | 21 namespace webkit { |
| 25 namespace ppapi { | 22 namespace ppapi { |
| 26 | 23 |
| 27 class WEBKIT_PLUGINS_EXPORT PPB_ImageData_Impl | 24 class WEBKIT_PLUGINS_EXPORT PPB_ImageData_Impl |
| 28 : public ::ppapi::Resource, | 25 : public ::ppapi::Resource, |
| 29 public ::ppapi::PPB_ImageData_Shared, | 26 public ::ppapi::PPB_ImageData_Shared, |
| 30 public NON_EXPORTED_BASE(::ppapi::thunk::PPB_ImageData_API) { | 27 public NON_EXPORTED_BASE(::ppapi::thunk::PPB_ImageData_API) { |
| 31 public: | 28 public: |
| 32 // 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 |
| 33 // 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 |
| 34 // NaCl). This makes it cheap & easy to implement Swap. | 31 // NaCl). This makes it cheap & easy to implement Swap. |
| 35 class Backend { | 32 class Backend { |
| 36 public: | 33 public: |
| 37 virtual ~Backend() {}; | 34 virtual ~Backend() {}; |
| 38 virtual bool Init(PPB_ImageData_Impl* impl, PP_ImageDataFormat format, | 35 virtual bool Init(PPB_ImageData_Impl* impl, PP_ImageDataFormat format, |
| 39 int width, int height, bool init_to_zero) = 0; | 36 int width, int height, bool init_to_zero) = 0; |
| 40 virtual bool IsMapped() const = 0; | 37 virtual bool IsMapped() const = 0; |
| 41 virtual PluginDelegate::PlatformImage2D* PlatformImage() const = 0; | 38 virtual PluginDelegate::PlatformImage2D* PlatformImage() const = 0; |
| 42 virtual void* Map() = 0; | 39 virtual void* Map() = 0; |
| 43 virtual void Unmap() = 0; | 40 virtual void Unmap() = 0; |
| 44 virtual int32_t GetSharedMemory(int* handle, uint32_t* byte_count) = 0; | 41 virtual int32_t GetSharedMemory(int* handle, uint32_t* byte_count) = 0; |
| 45 virtual skia::PlatformCanvas* GetPlatformCanvas() = 0; | 42 virtual SkCanvas* GetPlatformCanvas() = 0; |
| 46 virtual SkCanvas* GetCanvas() = 0; | 43 virtual SkCanvas* GetCanvas() = 0; |
| 47 virtual const SkBitmap* GetMappedBitmap() const = 0; | 44 virtual const SkBitmap* GetMappedBitmap() const = 0; |
| 48 }; | 45 }; |
| 49 | 46 |
| 50 // If you call this constructor, you must also call Init before use. Normally | 47 // If you call this constructor, you must also call Init before use. Normally |
| 51 // you should use the static Create function, but this constructor is needed | 48 // you should use the static Create function, but this constructor is needed |
| 52 // for some internal uses of ImageData (like Graphics2D). | 49 // for some internal uses of ImageData (like Graphics2D). |
| 53 enum ImageDataType { PLATFORM, NACL }; | 50 enum ImageDataType { PLATFORM, NACL }; |
| 54 PPB_ImageData_Impl(PP_Instance instance, ImageDataType type); | 51 PPB_ImageData_Impl(PP_Instance instance, ImageDataType type); |
| 55 virtual ~PPB_ImageData_Impl(); | 52 virtual ~PPB_ImageData_Impl(); |
| (...skipping 29 matching lines...) Expand all Loading... |
| 85 PluginDelegate::PlatformImage2D* PlatformImage() const; | 82 PluginDelegate::PlatformImage2D* PlatformImage() const; |
| 86 | 83 |
| 87 // Resource override. | 84 // Resource override. |
| 88 virtual ::ppapi::thunk::PPB_ImageData_API* AsPPB_ImageData_API() OVERRIDE; | 85 virtual ::ppapi::thunk::PPB_ImageData_API* AsPPB_ImageData_API() OVERRIDE; |
| 89 | 86 |
| 90 // PPB_ImageData_API implementation. | 87 // PPB_ImageData_API implementation. |
| 91 virtual PP_Bool Describe(PP_ImageDataDesc* desc) OVERRIDE; | 88 virtual PP_Bool Describe(PP_ImageDataDesc* desc) OVERRIDE; |
| 92 virtual void* Map() OVERRIDE; | 89 virtual void* Map() OVERRIDE; |
| 93 virtual void Unmap() OVERRIDE; | 90 virtual void Unmap() OVERRIDE; |
| 94 virtual int32_t GetSharedMemory(int* handle, uint32_t* byte_count) OVERRIDE; | 91 virtual int32_t GetSharedMemory(int* handle, uint32_t* byte_count) OVERRIDE; |
| 95 virtual skia::PlatformCanvas* GetPlatformCanvas() OVERRIDE; | 92 virtual SkCanvas* GetPlatformCanvas() OVERRIDE; |
| 96 virtual SkCanvas* GetCanvas() OVERRIDE; | 93 virtual SkCanvas* GetCanvas() OVERRIDE; |
| 97 | 94 |
| 98 const SkBitmap* GetMappedBitmap() const; | 95 const SkBitmap* GetMappedBitmap() const; |
| 99 | 96 |
| 100 private: | 97 private: |
| 101 PP_ImageDataFormat format_; | 98 PP_ImageDataFormat format_; |
| 102 int width_; | 99 int width_; |
| 103 int height_; | 100 int height_; |
| 104 scoped_ptr<Backend> backend_; | 101 scoped_ptr<Backend> backend_; |
| 105 | 102 |
| 106 DISALLOW_COPY_AND_ASSIGN(PPB_ImageData_Impl); | 103 DISALLOW_COPY_AND_ASSIGN(PPB_ImageData_Impl); |
| 107 }; | 104 }; |
| 108 | 105 |
| 109 class ImageDataPlatformBackend : public PPB_ImageData_Impl::Backend { | 106 class ImageDataPlatformBackend : public PPB_ImageData_Impl::Backend { |
| 110 public: | 107 public: |
| 111 ImageDataPlatformBackend(); | 108 ImageDataPlatformBackend(); |
| 112 virtual ~ImageDataPlatformBackend(); | 109 virtual ~ImageDataPlatformBackend(); |
| 113 | 110 |
| 114 // PPB_ImageData_Impl::Backend implementation. | 111 // PPB_ImageData_Impl::Backend implementation. |
| 115 virtual bool Init(PPB_ImageData_Impl* impl, PP_ImageDataFormat format, | 112 virtual bool Init(PPB_ImageData_Impl* impl, PP_ImageDataFormat format, |
| 116 int width, int height, bool init_to_zero) OVERRIDE; | 113 int width, int height, bool init_to_zero) OVERRIDE; |
| 117 virtual bool IsMapped() const OVERRIDE; | 114 virtual bool IsMapped() const OVERRIDE; |
| 118 virtual PluginDelegate::PlatformImage2D* PlatformImage() const OVERRIDE; | 115 virtual PluginDelegate::PlatformImage2D* PlatformImage() const OVERRIDE; |
| 119 virtual void* Map() OVERRIDE; | 116 virtual void* Map() OVERRIDE; |
| 120 virtual void Unmap() OVERRIDE; | 117 virtual void Unmap() OVERRIDE; |
| 121 virtual int32_t GetSharedMemory(int* handle, uint32_t* byte_count) OVERRIDE; | 118 virtual int32_t GetSharedMemory(int* handle, uint32_t* byte_count) OVERRIDE; |
| 122 virtual skia::PlatformCanvas* GetPlatformCanvas() OVERRIDE; | 119 virtual SkCanvas* GetPlatformCanvas() OVERRIDE; |
| 123 virtual SkCanvas* GetCanvas() OVERRIDE; | 120 virtual SkCanvas* GetCanvas() OVERRIDE; |
| 124 virtual const SkBitmap* GetMappedBitmap() const OVERRIDE; | 121 virtual const SkBitmap* GetMappedBitmap() const OVERRIDE; |
| 125 | 122 |
| 126 private: | 123 private: |
| 127 // This will be NULL before initialization, and if this PPB_ImageData_Impl is | 124 // This will be NULL before initialization, and if this PPB_ImageData_Impl is |
| 128 // swapped with another. | 125 // swapped with another. |
| 129 scoped_ptr<PluginDelegate::PlatformImage2D> platform_image_; | 126 scoped_ptr<PluginDelegate::PlatformImage2D> platform_image_; |
| 130 | 127 |
| 131 // When the device is mapped, this is the image. Null when umapped. | 128 // When the device is mapped, this is the image. Null when umapped. |
| 132 scoped_ptr<skia::PlatformCanvas> mapped_canvas_; | 129 scoped_ptr<SkCanvas> mapped_canvas_; |
| 133 | 130 |
| 134 DISALLOW_COPY_AND_ASSIGN(ImageDataPlatformBackend); | 131 DISALLOW_COPY_AND_ASSIGN(ImageDataPlatformBackend); |
| 135 }; | 132 }; |
| 136 | 133 |
| 137 class ImageDataNaClBackend : public PPB_ImageData_Impl::Backend { | 134 class ImageDataNaClBackend : public PPB_ImageData_Impl::Backend { |
| 138 public: | 135 public: |
| 139 ImageDataNaClBackend(); | 136 ImageDataNaClBackend(); |
| 140 virtual ~ImageDataNaClBackend(); | 137 virtual ~ImageDataNaClBackend(); |
| 141 | 138 |
| 142 // PPB_ImageData_Impl::Backend implementation. | 139 // PPB_ImageData_Impl::Backend implementation. |
| 143 bool Init(PPB_ImageData_Impl* impl, PP_ImageDataFormat format, | 140 bool Init(PPB_ImageData_Impl* impl, PP_ImageDataFormat format, |
| 144 int width, int height, bool init_to_zero) OVERRIDE; | 141 int width, int height, bool init_to_zero) OVERRIDE; |
| 145 virtual bool IsMapped() const OVERRIDE; | 142 virtual bool IsMapped() const OVERRIDE; |
| 146 PluginDelegate::PlatformImage2D* PlatformImage() const OVERRIDE; | 143 PluginDelegate::PlatformImage2D* PlatformImage() const OVERRIDE; |
| 147 virtual void* Map() OVERRIDE; | 144 virtual void* Map() OVERRIDE; |
| 148 virtual void Unmap() OVERRIDE; | 145 virtual void Unmap() OVERRIDE; |
| 149 virtual int32_t GetSharedMemory(int* handle, uint32_t* byte_count) OVERRIDE; | 146 virtual int32_t GetSharedMemory(int* handle, uint32_t* byte_count) OVERRIDE; |
| 150 virtual skia::PlatformCanvas* GetPlatformCanvas() OVERRIDE; | 147 virtual SkCanvas* GetPlatformCanvas() OVERRIDE; |
| 151 virtual SkCanvas* GetCanvas() OVERRIDE; | 148 virtual SkCanvas* GetCanvas() OVERRIDE; |
| 152 virtual const SkBitmap* GetMappedBitmap() const OVERRIDE; | 149 virtual const SkBitmap* GetMappedBitmap() const OVERRIDE; |
| 153 | 150 |
| 154 private: | 151 private: |
| 155 scoped_ptr<base::SharedMemory> shared_memory_; | 152 scoped_ptr<base::SharedMemory> shared_memory_; |
| 156 // skia_bitmap_ is backed by shared_memory_. | 153 // skia_bitmap_ is backed by shared_memory_. |
| 157 SkBitmap skia_bitmap_; | 154 SkBitmap skia_bitmap_; |
| 158 scoped_ptr<SkCanvas> skia_canvas_; | 155 scoped_ptr<SkCanvas> skia_canvas_; |
| 159 uint32 map_count_; | 156 uint32 map_count_; |
| 160 | 157 |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 197 bool is_valid_; | 194 bool is_valid_; |
| 198 bool needs_unmap_; | 195 bool needs_unmap_; |
| 199 | 196 |
| 200 DISALLOW_COPY_AND_ASSIGN(ImageDataAutoMapper); | 197 DISALLOW_COPY_AND_ASSIGN(ImageDataAutoMapper); |
| 201 }; | 198 }; |
| 202 | 199 |
| 203 } // namespace ppapi | 200 } // namespace ppapi |
| 204 } // namespace webkit | 201 } // namespace webkit |
| 205 | 202 |
| 206 #endif // WEBKIT_PLUGINS_PPAPI_PPB_IMAGE_DATA_IMPL_H_ | 203 #endif // WEBKIT_PLUGINS_PPAPI_PPB_IMAGE_DATA_IMPL_H_ |
| OLD | NEW |