OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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_GLUE_PLUGINS_PEPPER_IMAGE_DATA_H_ | 5 #ifndef WEBKIT_PLUGINS_PPAPI_PPB_IMAGE_DATA_IMPL_H_ |
6 #define WEBKIT_GLUE_PLUGINS_PEPPER_IMAGE_DATA_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/scoped_ptr.h" | 9 #include "base/scoped_ptr.h" |
10 #include "ppapi/c/ppb_image_data.h" | 10 #include "ppapi/c/ppb_image_data.h" |
11 #include "webkit/glue/plugins/pepper_plugin_delegate.h" | 11 #include "webkit/plugins/ppapi/plugin_delegate.h" |
12 #include "webkit/glue/plugins/pepper_resource.h" | 12 #include "webkit/plugins/ppapi/resource.h" |
13 | 13 |
14 namespace skia { | 14 namespace skia { |
15 class PlatformCanvas; | 15 class PlatformCanvas; |
16 } | 16 } |
17 | 17 |
18 struct PPB_ImageDataTrusted; | 18 struct PPB_ImageDataTrusted; |
19 class SkBitmap; | 19 class SkBitmap; |
20 | 20 |
21 namespace pepper { | 21 namespace webkit { |
| 22 namespace ppapi { |
22 | 23 |
23 class ImageData : public Resource { | 24 class PPB_ImageData_Impl : public Resource { |
24 public: | 25 public: |
25 explicit ImageData(PluginModule* module); | 26 explicit PPB_ImageData_Impl(PluginModule* module); |
26 virtual ~ImageData(); | 27 virtual ~PPB_ImageData_Impl(); |
27 | 28 |
28 int width() const { return width_; } | 29 int width() const { return width_; } |
29 int height() const { return height_; } | 30 int height() const { return height_; } |
30 | 31 |
31 // Returns the image format. | 32 // Returns the image format. |
32 PP_ImageDataFormat format() const { return format_; } | 33 PP_ImageDataFormat format() const { return format_; } |
33 | 34 |
34 // Returns true if this image is mapped. False means that the image is either | 35 // Returns true if this image is mapped. False means that the image is either |
35 // invalid or not mapped. See ImageDataAutoMapper below. | 36 // invalid or not mapped. See ImageDataAutoMapper below. |
36 bool is_mapped() const { return !!mapped_canvas_.get(); } | 37 bool is_mapped() const { return !!mapped_canvas_.get(); } |
37 | 38 |
38 PluginDelegate::PlatformImage2D* platform_image() const { | 39 PluginDelegate::PlatformImage2D* platform_image() const { |
39 return platform_image_.get(); | 40 return platform_image_.get(); |
40 } | 41 } |
41 | 42 |
42 // Returns a pointer to the interface implementing PPB_ImageData that is | 43 // Returns a pointer to the interface implementing PPB_ImageData that is |
43 // exposed to the plugin. | 44 // exposed to the plugin. |
44 static const PPB_ImageData* GetInterface(); | 45 static const PPB_ImageData* GetInterface(); |
45 static const PPB_ImageDataTrusted* GetTrustedInterface(); | 46 static const PPB_ImageDataTrusted* GetTrustedInterface(); |
46 | 47 |
47 // Returns the image data format used by the browser. If the plugin uses the | 48 // Returns the image data format used by the browser. If the plugin uses the |
48 // same format, there is no conversion. Otherwise the browser will be in | 49 // same format, there is no conversion. Otherwise the browser will be in |
49 // charge of converting from a supported format to its native format. | 50 // charge of converting from a supported format to its native format. |
50 static PP_ImageDataFormat GetNativeImageDataFormat(); | 51 static PP_ImageDataFormat GetNativeImageDataFormat(); |
51 | 52 |
52 // Returns true if the format is supported by the browser. | 53 // Returns true if the format is supported by the browser. |
53 static bool IsImageDataFormatSupported(PP_ImageDataFormat format); | 54 static bool IsImageDataFormatSupported(PP_ImageDataFormat format); |
54 | 55 |
55 // Resource overrides. | 56 // Resource overrides. |
56 virtual ImageData* AsImageData() { return this; } | 57 virtual PPB_ImageData_Impl* AsPPB_ImageData_Impl(); |
57 | 58 |
58 // PPB_ImageData implementation. | 59 // PPB_ImageData implementation. |
59 bool Init(PP_ImageDataFormat format, | 60 bool Init(PP_ImageDataFormat format, |
60 int width, int height, | 61 int width, int height, |
61 bool init_to_zero); | 62 bool init_to_zero); |
62 void Describe(PP_ImageDataDesc* desc) const; | 63 void Describe(PP_ImageDataDesc* desc) const; |
63 void* Map(); | 64 void* Map(); |
64 void Unmap(); | 65 void Unmap(); |
65 | 66 |
66 // PPB_ImageDataTrusted implementation. | 67 // PPB_ImageDataTrusted implementation. |
67 int GetSharedMemoryHandle(uint32* byte_count) const; | 68 int GetSharedMemoryHandle(uint32* byte_count) const; |
68 | 69 |
69 // The mapped bitmap and canvas will be NULL if the image is not mapped. | 70 // The mapped bitmap and canvas will be NULL if the image is not mapped. |
70 skia::PlatformCanvas* mapped_canvas() const { return mapped_canvas_.get(); } | 71 skia::PlatformCanvas* mapped_canvas() const { return mapped_canvas_.get(); } |
71 const SkBitmap* GetMappedBitmap() const; | 72 const SkBitmap* GetMappedBitmap() const; |
72 | 73 |
73 // Swaps the guts of this image data with another. | 74 // Swaps the guts of this image data with another. |
74 void Swap(ImageData* other); | 75 void Swap(PPB_ImageData_Impl* other); |
75 | 76 |
76 private: | 77 private: |
77 // This will be NULL before initialization, and if this ImageData is | 78 // This will be NULL before initialization, and if this PPB_ImageData_Impl is |
78 // swapped with another. | 79 // swapped with another. |
79 scoped_ptr<PluginDelegate::PlatformImage2D> platform_image_; | 80 scoped_ptr<PluginDelegate::PlatformImage2D> platform_image_; |
80 | 81 |
81 // When the device is mapped, this is the image. Null when umapped. | 82 // When the device is mapped, this is the image. Null when umapped. |
82 scoped_ptr<skia::PlatformCanvas> mapped_canvas_; | 83 scoped_ptr<skia::PlatformCanvas> mapped_canvas_; |
83 | 84 |
84 PP_ImageDataFormat format_; | 85 PP_ImageDataFormat format_; |
85 int width_; | 86 int width_; |
86 int height_; | 87 int height_; |
87 | 88 |
88 DISALLOW_COPY_AND_ASSIGN(ImageData); | 89 DISALLOW_COPY_AND_ASSIGN(PPB_ImageData_Impl); |
89 }; | 90 }; |
90 | 91 |
91 // Manages mapping an image resource if necessary. Use this to ensure the | 92 // Manages mapping an image resource if necessary. Use this to ensure the |
92 // image is mapped. The destructor will put the image back into the previous | 93 // image is mapped. The destructor will put the image back into the previous |
93 // state. You must check is_valid() to make sure the image was successfully | 94 // state. You must check is_valid() to make sure the image was successfully |
94 // mapped before using it. | 95 // mapped before using it. |
95 // | 96 // |
96 // Example: | 97 // Example: |
97 // ImageDataAutoMapper mapper(image_data); | 98 // ImageDataAutoMapper mapper(image_data); |
98 // if (!mapper.is_valid()) | 99 // if (!mapper.is_valid()) |
99 // return utter_failure; | 100 // return utter_failure; |
100 // image_data->mapped_canvas()->blah(); // Guaranteed valid. | 101 // image_data->mapped_canvas()->blah(); // Guaranteed valid. |
101 class ImageDataAutoMapper { | 102 class ImageDataAutoMapper { |
102 public: | 103 public: |
103 ImageDataAutoMapper(ImageData* image_data) : image_data_(image_data) { | 104 ImageDataAutoMapper(PPB_ImageData_Impl* image_data) |
| 105 : image_data_(image_data) { |
104 if (image_data_->is_mapped()) { | 106 if (image_data_->is_mapped()) { |
105 is_valid_ = true; | 107 is_valid_ = true; |
106 needs_unmap_ = false; | 108 needs_unmap_ = false; |
107 } else { | 109 } else { |
108 is_valid_ = needs_unmap_ = !!image_data_->Map(); | 110 is_valid_ = needs_unmap_ = !!image_data_->Map(); |
109 } | 111 } |
110 } | 112 } |
111 | 113 |
112 ~ImageDataAutoMapper() { | 114 ~ImageDataAutoMapper() { |
113 if (needs_unmap_) | 115 if (needs_unmap_) |
114 image_data_->Unmap(); | 116 image_data_->Unmap(); |
115 } | 117 } |
116 | 118 |
117 // Check this to see if the image was successfully mapped. If this is false, | 119 // Check this to see if the image was successfully mapped. If this is false, |
118 // the image could not be mapped and is unusable. | 120 // the image could not be mapped and is unusable. |
119 bool is_valid() const { return is_valid_; } | 121 bool is_valid() const { return is_valid_; } |
120 | 122 |
121 private: | 123 private: |
122 ImageData* image_data_; | 124 PPB_ImageData_Impl* image_data_; |
123 bool is_valid_; | 125 bool is_valid_; |
124 bool needs_unmap_; | 126 bool needs_unmap_; |
125 | 127 |
126 DISALLOW_COPY_AND_ASSIGN(ImageDataAutoMapper); | 128 DISALLOW_COPY_AND_ASSIGN(ImageDataAutoMapper); |
127 }; | 129 }; |
128 | 130 |
129 } // namespace pepper | 131 } // namespace ppapi |
| 132 } // namespace webkit |
130 | 133 |
131 #endif // WEBKIT_GLUE_PLUGINS_PEPPER_IMAGE_DATA_H_ | 134 #endif // WEBKIT_PLUGINS_PPAPI_PPB_IMAGE_DATA_IMPL_H_ |
OLD | NEW |