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 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
55 kImageRepCocoa, | 55 kImageRepCocoa, |
56 kImageRepCairoCache, | 56 kImageRepCairoCache, |
57 kImageRepSkia, | 57 kImageRepSkia, |
58 }; | 58 }; |
59 | 59 |
60 typedef std::map<RepresentationType, internal::ImageRep*> RepresentationMap; | 60 typedef std::map<RepresentationType, internal::ImageRep*> RepresentationMap; |
61 | 61 |
62 // Creates an empty image with no representations. | 62 // Creates an empty image with no representations. |
63 Image(); | 63 Image(); |
64 | 64 |
| 65 // Creates a new image by copying the ImageSkia for use as the default |
| 66 // representation. |
| 67 explicit Image(const ImageSkia& image); |
| 68 |
65 // Creates a new image by copying the bitmap for use as the default | 69 // Creates a new image by copying the bitmap for use as the default |
66 // representation. | 70 // representation. |
67 explicit Image(const SkBitmap& bitmap); | 71 explicit Image(const SkBitmap& bitmap); |
68 | 72 |
69 // To create an Image that supports multiple resolutions pass a vector | |
70 // of bitmaps, one for each resolution. | |
71 explicit Image(const std::vector<const SkBitmap*>& bitmaps); | |
72 | |
73 #if defined(TOOLKIT_GTK) | 73 #if defined(TOOLKIT_GTK) |
74 // Does not increase |pixbuf|'s reference count; expects to take ownership. | 74 // Does not increase |pixbuf|'s reference count; expects to take ownership. |
75 explicit Image(GdkPixbuf* pixbuf); | 75 explicit Image(GdkPixbuf* pixbuf); |
76 #elif defined(OS_MACOSX) | 76 #elif defined(OS_MACOSX) |
77 // Does not retain |image|; expects to take ownership. | 77 // Does not retain |image|; expects to take ownership. |
78 // A single NSImage object can contain multiple bitmaps so there's no reason | 78 // A single NSImage object can contain multiple bitmaps so there's no reason |
79 // to pass a vector of these. | 79 // to pass a vector of these. |
80 explicit Image(NSImage* image); | 80 explicit Image(NSImage* image); |
81 #endif | 81 #endif |
82 | 82 |
(...skipping 18 matching lines...) Expand all Loading... |
101 #elif defined(OS_MACOSX) | 101 #elif defined(OS_MACOSX) |
102 NSImage* ToNSImage() const; | 102 NSImage* ToNSImage() const; |
103 #endif | 103 #endif |
104 | 104 |
105 // Performs a conversion, like above, but returns a copy of the result rather | 105 // Performs a conversion, like above, but returns a copy of the result rather |
106 // than a weak pointer. The caller is responsible for deleting the result. | 106 // than a weak pointer. The caller is responsible for deleting the result. |
107 // Note that the result is only a copy in terms of memory management; the | 107 // Note that the result is only a copy in terms of memory management; the |
108 // backing pixels are shared amongst all copies (a fact of each of the | 108 // backing pixels are shared amongst all copies (a fact of each of the |
109 // converted representations, rather than a limitation imposed by Image) and | 109 // converted representations, rather than a limitation imposed by Image) and |
110 // so the result should be considered immutable. | 110 // so the result should be considered immutable. |
| 111 ImageSkia* CopyImageSkia() const; |
111 SkBitmap* CopySkBitmap() const; | 112 SkBitmap* CopySkBitmap() const; |
112 #if defined(TOOLKIT_GTK) | 113 #if defined(TOOLKIT_GTK) |
113 GdkPixbuf* CopyGdkPixbuf() const; | 114 GdkPixbuf* CopyGdkPixbuf() const; |
114 #elif defined(OS_MACOSX) | 115 #elif defined(OS_MACOSX) |
115 NSImage* CopyNSImage() const; | 116 NSImage* CopyNSImage() const; |
116 #endif | 117 #endif |
117 | 118 |
118 // DEPRECATED ---------------------------------------------------------------- | 119 // DEPRECATED ---------------------------------------------------------------- |
119 // Conversion handlers. These wrap the ToType() variants. | 120 // Conversion handlers. These wrap the ToType() variants. |
120 #if defined(OS_MACOSX) | 121 #if defined(OS_MACOSX) |
(...skipping 28 matching lines...) Expand all Loading... |
149 // be cheaply copied. | 150 // be cheaply copied. |
150 scoped_refptr<internal::ImageStorage> storage_; | 151 scoped_refptr<internal::ImageStorage> storage_; |
151 | 152 |
152 friend class ::ImageTest; | 153 friend class ::ImageTest; |
153 friend class ::ImageMacTest; | 154 friend class ::ImageMacTest; |
154 }; | 155 }; |
155 | 156 |
156 } // namespace gfx | 157 } // namespace gfx |
157 | 158 |
158 #endif // UI_GFX_IMAGE_IMAGE_H_ | 159 #endif // UI_GFX_IMAGE_IMAGE_H_ |
OLD | NEW |