| 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 CONTENT_RENDERER_PEPPER_PPB_IMAGE_DATA_IMPL_H_ | 5 #ifndef CONTENT_RENDERER_PEPPER_PPB_IMAGE_DATA_IMPL_H_ |
| 6 #define CONTENT_RENDERER_PEPPER_PPB_IMAGE_DATA_IMPL_H_ | 6 #define CONTENT_RENDERER_PEPPER_PPB_IMAGE_DATA_IMPL_H_ |
| 7 | 7 |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 | 9 |
| 10 #include <memory> | 10 #include <memory> |
| 11 | 11 |
| 12 #include "base/macros.h" | 12 #include "base/macros.h" |
| 13 #include "base/memory/shared_memory.h" | 13 #include "base/memory/shared_memory.h" |
| 14 #include "content/common/content_export.h" | 14 #include "content/common/content_export.h" |
| 15 #include "ppapi/c/ppb_image_data.h" | 15 #include "ppapi/c/ppb_image_data.h" |
| 16 #include "ppapi/shared_impl/ppb_image_data_shared.h" | 16 #include "ppapi/shared_impl/ppb_image_data_shared.h" |
| 17 #include "ppapi/shared_impl/resource.h" | 17 #include "ppapi/shared_impl/resource.h" |
| 18 #include "ppapi/thunk/ppb_image_data_api.h" | 18 #include "ppapi/thunk/ppb_image_data_api.h" |
| 19 #include "third_party/skia/include/core/SkCanvas.h" | 19 #include "skia/ext/cdl_common.h" |
| 20 #include "third_party/skia/include/core/SkBitmap.h" |
| 20 | 21 |
| 21 class SkBitmap; | 22 class SkBitmap; |
| 22 class SkCanvas; | |
| 23 class TransportDIB; | 23 class TransportDIB; |
| 24 | 24 |
| 25 namespace base { | 25 namespace base { |
| 26 class SharedMemory; | 26 class SharedMemory; |
| 27 } | 27 } |
| 28 | 28 |
| 29 namespace content { | 29 namespace content { |
| 30 | 30 |
| 31 class CONTENT_EXPORT PPB_ImageData_Impl | 31 class CONTENT_EXPORT PPB_ImageData_Impl |
| 32 : public ppapi::Resource, | 32 : public ppapi::Resource, |
| (...skipping 11 matching lines...) Expand all Loading... |
| 44 PP_ImageDataFormat format, | 44 PP_ImageDataFormat format, |
| 45 int width, | 45 int width, |
| 46 int height, | 46 int height, |
| 47 bool init_to_zero) = 0; | 47 bool init_to_zero) = 0; |
| 48 virtual bool IsMapped() const = 0; | 48 virtual bool IsMapped() const = 0; |
| 49 virtual TransportDIB* GetTransportDIB() const = 0; | 49 virtual TransportDIB* GetTransportDIB() const = 0; |
| 50 virtual void* Map() = 0; | 50 virtual void* Map() = 0; |
| 51 virtual void Unmap() = 0; | 51 virtual void Unmap() = 0; |
| 52 virtual int32_t GetSharedMemory(base::SharedMemory** shm, | 52 virtual int32_t GetSharedMemory(base::SharedMemory** shm, |
| 53 uint32_t* byte_count) = 0; | 53 uint32_t* byte_count) = 0; |
| 54 virtual SkCanvas* GetPlatformCanvas() = 0; | 54 virtual CdlCanvas* GetPlatformCanvas() = 0; |
| 55 virtual SkCanvas* GetCanvas() = 0; | 55 virtual CdlCanvas* GetCanvas() = 0; |
| 56 virtual SkBitmap GetMappedBitmap() const = 0; | 56 virtual SkBitmap GetMappedBitmap() const = 0; |
| 57 }; | 57 }; |
| 58 | 58 |
| 59 // If you call this constructor, you must also call Init before use. Normally | 59 // If you call this constructor, you must also call Init before use. Normally |
| 60 // you should use the static Create function, but this constructor is needed | 60 // you should use the static Create function, but this constructor is needed |
| 61 // for some internal uses of ImageData (like Graphics2D). | 61 // for some internal uses of ImageData (like Graphics2D). |
| 62 PPB_ImageData_Impl(PP_Instance instance, | 62 PPB_ImageData_Impl(PP_Instance instance, |
| 63 PPB_ImageData_Shared::ImageDataType type); | 63 PPB_ImageData_Shared::ImageDataType type); |
| 64 | 64 |
| 65 // Constructor used for unittests. The ImageData is always allocated locally. | 65 // Constructor used for unittests. The ImageData is always allocated locally. |
| (...skipping 24 matching lines...) Expand all Loading... |
| 90 | 90 |
| 91 // Resource override. | 91 // Resource override. |
| 92 ppapi::thunk::PPB_ImageData_API* AsPPB_ImageData_API() override; | 92 ppapi::thunk::PPB_ImageData_API* AsPPB_ImageData_API() override; |
| 93 | 93 |
| 94 // PPB_ImageData_API implementation. | 94 // PPB_ImageData_API implementation. |
| 95 PP_Bool Describe(PP_ImageDataDesc* desc) override; | 95 PP_Bool Describe(PP_ImageDataDesc* desc) override; |
| 96 void* Map() override; | 96 void* Map() override; |
| 97 void Unmap() override; | 97 void Unmap() override; |
| 98 int32_t GetSharedMemory(base::SharedMemory** shm, | 98 int32_t GetSharedMemory(base::SharedMemory** shm, |
| 99 uint32_t* byte_count) override; | 99 uint32_t* byte_count) override; |
| 100 SkCanvas* GetPlatformCanvas() override; | 100 CdlCanvas* GetPlatformCanvas() override; |
| 101 SkCanvas* GetCanvas() override; | 101 CdlCanvas* GetCanvas() override; |
| 102 void SetIsCandidateForReuse() override; | 102 void SetIsCandidateForReuse() override; |
| 103 | 103 |
| 104 // Returns an *empty* bitmap on error. | 104 // Returns an *empty* bitmap on error. |
| 105 // Users must call SkBitmap::lockPixels() before SkBitmap::getPixels(); | 105 // Users must call SkBitmap::lockPixels() before SkBitmap::getPixels(); |
| 106 // unlockPixels() will be automatically invoked if necessary when the | 106 // unlockPixels() will be automatically invoked if necessary when the |
| 107 // bitmap goes out of scope. | 107 // bitmap goes out of scope. |
| 108 SkBitmap GetMappedBitmap() const; | 108 SkBitmap GetMappedBitmap() const; |
| 109 | 109 |
| 110 private: | 110 private: |
| 111 ~PPB_ImageData_Impl() override; | 111 ~PPB_ImageData_Impl() override; |
| (...skipping 18 matching lines...) Expand all Loading... |
| 130 PP_ImageDataFormat format, | 130 PP_ImageDataFormat format, |
| 131 int width, | 131 int width, |
| 132 int height, | 132 int height, |
| 133 bool init_to_zero) override; | 133 bool init_to_zero) override; |
| 134 bool IsMapped() const override; | 134 bool IsMapped() const override; |
| 135 TransportDIB* GetTransportDIB() const override; | 135 TransportDIB* GetTransportDIB() const override; |
| 136 void* Map() override; | 136 void* Map() override; |
| 137 void Unmap() override; | 137 void Unmap() override; |
| 138 int32_t GetSharedMemory(base::SharedMemory** shm, | 138 int32_t GetSharedMemory(base::SharedMemory** shm, |
| 139 uint32_t* byte_count) override; | 139 uint32_t* byte_count) override; |
| 140 SkCanvas* GetPlatformCanvas() override; | 140 CdlCanvas* GetPlatformCanvas() override; |
| 141 SkCanvas* GetCanvas() override; | 141 CdlCanvas* GetCanvas() override; |
| 142 SkBitmap GetMappedBitmap() const override; | 142 SkBitmap GetMappedBitmap() const override; |
| 143 | 143 |
| 144 private: | 144 private: |
| 145 // This will be NULL before initialization, and if this PPB_ImageData_Impl is | 145 // This will be NULL before initialization, and if this PPB_ImageData_Impl is |
| 146 // swapped with another. | 146 // swapped with another. |
| 147 int width_; | 147 int width_; |
| 148 int height_; | 148 int height_; |
| 149 std::unique_ptr<TransportDIB> dib_; | 149 std::unique_ptr<TransportDIB> dib_; |
| 150 | 150 |
| 151 // When the device is mapped, this is the image. Null when umapped. | 151 // When the device is mapped, this is the image. Null when umapped. |
| 152 std::unique_ptr<SkCanvas> mapped_canvas_; | 152 std::unique_ptr<CdlCanvas> mapped_canvas_; |
| 153 | 153 |
| 154 DISALLOW_COPY_AND_ASSIGN(ImageDataPlatformBackend); | 154 DISALLOW_COPY_AND_ASSIGN(ImageDataPlatformBackend); |
| 155 }; | 155 }; |
| 156 | 156 |
| 157 class ImageDataSimpleBackend : public PPB_ImageData_Impl::Backend { | 157 class ImageDataSimpleBackend : public PPB_ImageData_Impl::Backend { |
| 158 public: | 158 public: |
| 159 ImageDataSimpleBackend(); | 159 ImageDataSimpleBackend(); |
| 160 ~ImageDataSimpleBackend() override; | 160 ~ImageDataSimpleBackend() override; |
| 161 | 161 |
| 162 // PPB_ImageData_Impl::Backend implementation. | 162 // PPB_ImageData_Impl::Backend implementation. |
| 163 bool Init(PPB_ImageData_Impl* impl, | 163 bool Init(PPB_ImageData_Impl* impl, |
| 164 PP_ImageDataFormat format, | 164 PP_ImageDataFormat format, |
| 165 int width, | 165 int width, |
| 166 int height, | 166 int height, |
| 167 bool init_to_zero) override; | 167 bool init_to_zero) override; |
| 168 bool IsMapped() const override; | 168 bool IsMapped() const override; |
| 169 TransportDIB* GetTransportDIB() const override; | 169 TransportDIB* GetTransportDIB() const override; |
| 170 void* Map() override; | 170 void* Map() override; |
| 171 void Unmap() override; | 171 void Unmap() override; |
| 172 int32_t GetSharedMemory(base::SharedMemory** shm, | 172 int32_t GetSharedMemory(base::SharedMemory** shm, |
| 173 uint32_t* byte_count) override; | 173 uint32_t* byte_count) override; |
| 174 SkCanvas* GetPlatformCanvas() override; | 174 CdlCanvas* GetPlatformCanvas() override; |
| 175 SkCanvas* GetCanvas() override; | 175 CdlCanvas* GetCanvas() override; |
| 176 SkBitmap GetMappedBitmap() const override; | 176 SkBitmap GetMappedBitmap() const override; |
| 177 | 177 |
| 178 private: | 178 private: |
| 179 std::unique_ptr<base::SharedMemory> shared_memory_; | 179 std::unique_ptr<base::SharedMemory> shared_memory_; |
| 180 // skia_bitmap_ is backed by shared_memory_. | 180 // skia_bitmap_ is backed by shared_memory_. |
| 181 SkBitmap skia_bitmap_; | 181 SkBitmap skia_bitmap_; |
| 182 std::unique_ptr<SkCanvas> skia_canvas_; | 182 std::unique_ptr<CdlCanvas> skia_canvas_; |
| 183 uint32_t map_count_; | 183 uint32_t map_count_; |
| 184 | 184 |
| 185 DISALLOW_COPY_AND_ASSIGN(ImageDataSimpleBackend); | 185 DISALLOW_COPY_AND_ASSIGN(ImageDataSimpleBackend); |
| 186 }; | 186 }; |
| 187 | 187 |
| 188 // Manages mapping an image resource if necessary. Use this to ensure the | 188 // Manages mapping an image resource if necessary. Use this to ensure the |
| 189 // image is mapped. The destructor will put the image back into the previous | 189 // image is mapped. The destructor will put the image back into the previous |
| 190 // state. You must check is_valid() to make sure the image was successfully | 190 // state. You must check is_valid() to make sure the image was successfully |
| 191 // mapped before using it. | 191 // mapped before using it. |
| 192 // | 192 // |
| (...skipping 27 matching lines...) Expand all Loading... |
| 220 PPB_ImageData_Impl* image_data_; | 220 PPB_ImageData_Impl* image_data_; |
| 221 bool is_valid_; | 221 bool is_valid_; |
| 222 bool needs_unmap_; | 222 bool needs_unmap_; |
| 223 | 223 |
| 224 DISALLOW_COPY_AND_ASSIGN(ImageDataAutoMapper); | 224 DISALLOW_COPY_AND_ASSIGN(ImageDataAutoMapper); |
| 225 }; | 225 }; |
| 226 | 226 |
| 227 } // namespace content | 227 } // namespace content |
| 228 | 228 |
| 229 #endif // CONTENT_RENDERER_PEPPER_PPB_IMAGE_DATA_IMPL_H_ | 229 #endif // CONTENT_RENDERER_PEPPER_PPB_IMAGE_DATA_IMPL_H_ |
| OLD | NEW |