OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/ref_counted.h" |
9 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
10 #include "ppapi/c/ppb_image_data.h" | 11 #include "ppapi/c/ppb_image_data.h" |
11 #include "ppapi/shared_impl/ppb_image_data_shared.h" | 12 #include "ppapi/shared_impl/ppb_image_data_shared.h" |
12 #include "ppapi/shared_impl/resource.h" | 13 #include "ppapi/shared_impl/resource.h" |
13 #include "ppapi/thunk/ppb_image_data_api.h" | 14 #include "ppapi/thunk/ppb_image_data_api.h" |
14 #include "webkit/plugins/ppapi/plugin_delegate.h" | 15 #include "webkit/plugins/ppapi/plugin_delegate.h" |
15 #include "webkit/plugins/webkit_plugins_export.h" | 16 #include "webkit/plugins/webkit_plugins_export.h" |
16 | 17 |
17 namespace skia { | 18 namespace skia { |
18 class PlatformCanvas; | 19 class PlatformCanvas; |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
90 // state. You must check is_valid() to make sure the image was successfully | 91 // state. You must check is_valid() to make sure the image was successfully |
91 // mapped before using it. | 92 // mapped before using it. |
92 // | 93 // |
93 // Example: | 94 // Example: |
94 // ImageDataAutoMapper mapper(image_data); | 95 // ImageDataAutoMapper mapper(image_data); |
95 // if (!mapper.is_valid()) | 96 // if (!mapper.is_valid()) |
96 // return utter_failure; | 97 // return utter_failure; |
97 // image_data->mapped_canvas()->blah(); // Guaranteed valid. | 98 // image_data->mapped_canvas()->blah(); // Guaranteed valid. |
98 class ImageDataAutoMapper { | 99 class ImageDataAutoMapper { |
99 public: | 100 public: |
100 explicit ImageDataAutoMapper(PPB_ImageData_Impl* image_data) | 101 explicit ImageDataAutoMapper(scoped_refptr<PPB_ImageData_Impl> image_data) |
101 : image_data_(image_data) { | 102 : image_data_(image_data) { |
102 if (image_data_->is_mapped()) { | 103 if (image_data_->is_mapped()) { |
103 is_valid_ = true; | 104 is_valid_ = true; |
104 needs_unmap_ = false; | 105 needs_unmap_ = false; |
105 } else { | 106 } else { |
106 is_valid_ = needs_unmap_ = !!image_data_->Map(); | 107 is_valid_ = needs_unmap_ = !!image_data_->Map(); |
107 } | 108 } |
108 } | 109 } |
109 | 110 |
110 ~ImageDataAutoMapper() { | 111 ~ImageDataAutoMapper() { |
111 if (needs_unmap_) | 112 if (needs_unmap_) |
112 image_data_->Unmap(); | 113 image_data_->Unmap(); |
113 } | 114 } |
114 | 115 |
115 // Check this to see if the image was successfully mapped. If this is false, | 116 // Check this to see if the image was successfully mapped. If this is false, |
116 // the image could not be mapped and is unusable. | 117 // the image could not be mapped and is unusable. |
117 bool is_valid() const { return is_valid_; } | 118 bool is_valid() const { return is_valid_; } |
118 | 119 |
119 private: | 120 private: |
120 PPB_ImageData_Impl* image_data_; | 121 scoped_refptr<PPB_ImageData_Impl> image_data_; |
121 bool is_valid_; | 122 bool is_valid_; |
122 bool needs_unmap_; | 123 bool needs_unmap_; |
123 | 124 |
124 DISALLOW_COPY_AND_ASSIGN(ImageDataAutoMapper); | 125 DISALLOW_COPY_AND_ASSIGN(ImageDataAutoMapper); |
125 }; | 126 }; |
126 | 127 |
127 } // namespace ppapi | 128 } // namespace ppapi |
128 } // namespace webkit | 129 } // namespace webkit |
129 | 130 |
130 #endif // WEBKIT_PLUGINS_PPAPI_PPB_IMAGE_DATA_IMPL_H_ | 131 #endif // WEBKIT_PLUGINS_PPAPI_PPB_IMAGE_DATA_IMPL_H_ |
OLD | NEW |