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 19 matching lines...) Expand all Loading... |
30 #include "ui/gfx/native_widget_types.h" | 30 #include "ui/gfx/native_widget_types.h" |
31 | 31 |
32 class SkBitmap; | 32 class SkBitmap; |
33 | 33 |
34 namespace { | 34 namespace { |
35 class ImageTest; | 35 class ImageTest; |
36 class ImageMacTest; | 36 class ImageMacTest; |
37 } | 37 } |
38 | 38 |
39 namespace gfx { | 39 namespace gfx { |
| 40 class ImageSkia; |
40 | 41 |
41 #if defined(TOOLKIT_GTK) | 42 #if defined(TOOLKIT_GTK) |
42 class CairoCachedSurface; | 43 class CairoCachedSurface; |
43 #endif | 44 #endif |
44 | 45 |
45 namespace internal { | 46 namespace internal { |
46 class ImageRep; | 47 class ImageRep; |
47 class ImageStorage; | 48 class ImageStorage; |
48 } | 49 } |
49 | 50 |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
90 Image& operator=(const Image& other); | 91 Image& operator=(const Image& other); |
91 | 92 |
92 // Deletes the image and, if the only owner of the storage, all of its cached | 93 // Deletes the image and, if the only owner of the storage, all of its cached |
93 // representations. | 94 // representations. |
94 ~Image(); | 95 ~Image(); |
95 | 96 |
96 // Converts the Image to the desired representation and stores it internally. | 97 // Converts the Image to the desired representation and stores it internally. |
97 // The returned result is a weak pointer owned by and scoped to the life of | 98 // The returned result is a weak pointer owned by and scoped to the life of |
98 // the Image. | 99 // the Image. |
99 const SkBitmap* ToSkBitmap() const; | 100 const SkBitmap* ToSkBitmap() const; |
| 101 const ImageSkia* ToImageSkia() const; |
100 #if defined(TOOLKIT_GTK) | 102 #if defined(TOOLKIT_GTK) |
101 GdkPixbuf* ToGdkPixbuf() const; | 103 GdkPixbuf* ToGdkPixbuf() const; |
102 CairoCachedSurface* const ToCairo() const; | 104 CairoCachedSurface* const ToCairo() const; |
103 #elif defined(OS_MACOSX) | 105 #elif defined(OS_MACOSX) |
104 NSImage* ToNSImage() const; | 106 NSImage* ToNSImage() const; |
105 #endif | 107 #endif |
106 | 108 |
107 // Performs a conversion, like above, but returns a copy of the result rather | 109 // Performs a conversion, like above, but returns a copy of the result rather |
108 // than a weak pointer. The caller is responsible for deleting the result. | 110 // than a weak pointer. The caller is responsible for deleting the result. |
109 // Note that the result is only a copy in terms of memory management; the | 111 // Note that the result is only a copy in terms of memory management; the |
110 // backing pixels are shared amongst all copies (a fact of each of the | 112 // backing pixels are shared amongst all copies (a fact of each of the |
111 // converted representations, rather than a limitation imposed by Image) and | 113 // converted representations, rather than a limitation imposed by Image) and |
112 // so the result should be considered immutable. | 114 // so the result should be considered immutable. |
113 SkBitmap* CopySkBitmap() const; | 115 SkBitmap* CopySkBitmap() const; |
114 #if defined(TOOLKIT_GTK) | 116 #if defined(TOOLKIT_GTK) |
115 GdkPixbuf* CopyGdkPixbuf() const; | 117 GdkPixbuf* CopyGdkPixbuf() const; |
116 #elif defined(OS_MACOSX) | 118 #elif defined(OS_MACOSX) |
117 NSImage* CopyNSImage() const; | 119 NSImage* CopyNSImage() const; |
118 #endif | 120 #endif |
119 | 121 |
120 // DEPRECATED ---------------------------------------------------------------- | 122 // DEPRECATED ---------------------------------------------------------------- |
121 // Conversion handlers. These wrap the ToType() variants. | 123 // Conversion handlers. These wrap the ToType() variants. |
122 #if defined(OS_MACOSX) | 124 #if defined(OS_MACOSX) |
123 operator NSImage*() const; | 125 operator NSImage*() const; |
124 #endif | 126 #endif |
125 // --------------------------------------------------------------------------- | 127 // --------------------------------------------------------------------------- |
126 | 128 |
127 // Gets the number of bitmaps in this image. This may cause a conversion | |
128 // to a bitmap representation. Note, this function and GetSkBitmapAtIndex() | |
129 // are primarily meant to be used by the theme provider. | |
130 size_t GetNumberOfSkBitmaps() const; | |
131 | |
132 // Gets the bitmap at the given index. This may cause a conversion | |
133 // to a bitmap representation. Note, the internal ordering of bitmaps is not | |
134 // guaranteed. | |
135 const SkBitmap* GetSkBitmapAtIndex(size_t index) const; | |
136 | |
137 // Inspects the representations map to see if the given type exists. | 129 // Inspects the representations map to see if the given type exists. |
138 bool HasRepresentation(RepresentationType type) const; | 130 bool HasRepresentation(RepresentationType type) const; |
139 | 131 |
140 // Returns the number of representations. | 132 // Returns the number of representations. |
141 size_t RepresentationCount() const; | 133 size_t RepresentationCount() const; |
142 | 134 |
143 // Returns true if this Image has no representations. | 135 // Returns true if this Image has no representations. |
144 bool IsEmpty() const; | 136 bool IsEmpty() const; |
145 | 137 |
146 // Swaps this image's internal representations with |other|. | 138 // Swaps this image's internal representations with |other|. |
(...skipping 14 matching lines...) Expand all Loading... |
161 // be cheaply copied. | 153 // be cheaply copied. |
162 scoped_refptr<internal::ImageStorage> storage_; | 154 scoped_refptr<internal::ImageStorage> storage_; |
163 | 155 |
164 friend class ::ImageTest; | 156 friend class ::ImageTest; |
165 friend class ::ImageMacTest; | 157 friend class ::ImageMacTest; |
166 }; | 158 }; |
167 | 159 |
168 } // namespace gfx | 160 } // namespace gfx |
169 | 161 |
170 #endif // UI_GFX_IMAGE_IMAGE_H_ | 162 #endif // UI_GFX_IMAGE_IMAGE_H_ |
OLD | NEW |