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 // An Image wraps an image any flavor, be it platform-native GdkBitmap/NSImage, | 5 // An Image wraps an image any flavor, be it platform-native GdkBitmap/NSImage, |
6 // or a SkBitmap. This also provides easy conversion to other image types | 6 // or a SkBitmap. This also provides easy conversion to other image types |
7 // through operator overloading. It will cache the converted representations | 7 // through operator overloading. It will cache the converted representations |
8 // internally to prevent double-conversion. | 8 // internally to prevent double-conversion. |
9 // | 9 // |
10 // The lifetime of both the initial representation and any converted ones are | 10 // The lifetime of both the initial representation and any converted ones are |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
90 | 90 |
91 // Copies a reference to |other|'s storage. | 91 // Copies a reference to |other|'s storage. |
92 Image& operator=(const Image& other); | 92 Image& operator=(const Image& other); |
93 | 93 |
94 // Deletes the image and, if the only owner of the storage, all of its cached | 94 // Deletes the image and, if the only owner of the storage, all of its cached |
95 // representations. | 95 // representations. |
96 ~Image(); | 96 ~Image(); |
97 | 97 |
98 // Converts the Image to the desired representation and stores it internally. | 98 // Converts the Image to the desired representation and stores it internally. |
99 // The returned result is a weak pointer owned by and scoped to the life of | 99 // The returned result is a weak pointer owned by and scoped to the life of |
100 // the Image. | 100 // the Image. Must only be called if IsEmpty() is false. |
101 const SkBitmap* ToSkBitmap() const; | 101 const SkBitmap* ToSkBitmap() const; |
102 const ImageSkia* ToImageSkia() const; | 102 const ImageSkia* ToImageSkia() const; |
103 #if defined(TOOLKIT_GTK) | 103 #if defined(TOOLKIT_GTK) |
104 GdkPixbuf* ToGdkPixbuf() const; | 104 GdkPixbuf* ToGdkPixbuf() const; |
105 CairoCachedSurface* const ToCairo() const; | 105 CairoCachedSurface* const ToCairo() const; |
106 #elif defined(OS_MACOSX) | 106 #elif defined(OS_MACOSX) |
107 NSImage* ToNSImage() const; | 107 NSImage* ToNSImage() const; |
108 #endif | 108 #endif |
109 | 109 |
110 // Same as ToSkBitmap(), but returns a null SkBitmap if this image is empty. | 110 // Same as ToSkBitmap(), but returns a null SkBitmap if this image is empty. |
111 SkBitmap AsBitmap() const; | 111 SkBitmap AsBitmap() const; |
112 | 112 |
113 // Same as ToSkBitmap(), but returns a ImageSkia with a null SkBitmap if this | 113 // Same as ToImageSkia(), but returns an empty ImageSkia if this |
114 // image is empty. | 114 // image is empty. |
115 ImageSkia AsImageSkia() const; | 115 ImageSkia AsImageSkia() const; |
116 | 116 |
| 117 #if defined(OS_MACOSX) |
| 118 // Same as ToSkBitmap(), but returns nil if this image is empty. |
| 119 NSImage* AsNSImage() const; |
| 120 #endif |
| 121 |
117 // Performs a conversion, like above, but returns a copy of the result rather | 122 // Performs a conversion, like above, but returns a copy of the result rather |
118 // than a weak pointer. The caller is responsible for deleting the result. | 123 // than a weak pointer. The caller is responsible for deleting the result. |
119 // Note that the result is only a copy in terms of memory management; the | 124 // Note that the result is only a copy in terms of memory management; the |
120 // backing pixels are shared amongst all copies (a fact of each of the | 125 // backing pixels are shared amongst all copies (a fact of each of the |
121 // converted representations, rather than a limitation imposed by Image) and | 126 // converted representations, rather than a limitation imposed by Image) and |
122 // so the result should be considered immutable. | 127 // so the result should be considered immutable. |
123 ImageSkia* CopyImageSkia() const; | 128 ImageSkia* CopyImageSkia() const; |
124 SkBitmap* CopySkBitmap() const; | 129 SkBitmap* CopySkBitmap() const; |
125 #if defined(TOOLKIT_GTK) | 130 #if defined(TOOLKIT_GTK) |
126 GdkPixbuf* CopyGdkPixbuf() const; | 131 GdkPixbuf* CopyGdkPixbuf() const; |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
163 // be cheaply copied. | 168 // be cheaply copied. |
164 scoped_refptr<internal::ImageStorage> storage_; | 169 scoped_refptr<internal::ImageStorage> storage_; |
165 | 170 |
166 friend class ::ImageTest; | 171 friend class ::ImageTest; |
167 friend class ::ImageMacTest; | 172 friend class ::ImageMacTest; |
168 }; | 173 }; |
169 | 174 |
170 } // namespace gfx | 175 } // namespace gfx |
171 | 176 |
172 #endif // UI_GFX_IMAGE_IMAGE_H_ | 177 #endif // UI_GFX_IMAGE_IMAGE_H_ |
OLD | NEW |