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 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
48 class ImageStorage; | 48 class ImageStorage; |
49 } | 49 } |
50 | 50 |
51 class UI_EXPORT Image { | 51 class UI_EXPORT Image { |
52 public: | 52 public: |
53 enum RepresentationType { | 53 enum RepresentationType { |
54 kImageRepGdk, | 54 kImageRepGdk, |
55 kImageRepCocoa, | 55 kImageRepCocoa, |
56 kImageRepCairo, | 56 kImageRepCairo, |
57 kImageRepSkia, | 57 kImageRepSkia, |
58 kImageRepPNG, | |
59 }; | 58 }; |
60 | 59 |
61 typedef std::map<RepresentationType, internal::ImageRep*> RepresentationMap; | 60 typedef std::map<RepresentationType, internal::ImageRep*> RepresentationMap; |
62 | 61 |
63 // Creates an empty image with no representations. | 62 // Creates an empty image with no representations. |
64 Image(); | 63 Image(); |
65 | 64 |
66 // Creates a new image by copying the PNG-encoded input for use as the default | |
67 // representation. For example (from an std::vector): | |
68 // std::vector<unsigned char> png = ...; | |
69 // gfx::Image image(&png.front(), png.size()); | |
70 Image(const unsigned char* png, size_t input_size); | |
71 | |
72 // Creates a new image by copying the ImageSkia for use as the default | 65 // Creates a new image by copying the ImageSkia for use as the default |
73 // representation. | 66 // representation. |
74 explicit Image(const ImageSkia& image); | 67 explicit Image(const ImageSkia& image); |
75 | 68 |
76 // Creates a new image by copying the image rep for use as the default | 69 // Creates a new image by copying the image rep for use as the default |
77 // representation. | 70 // representation. |
78 explicit Image(const ImageSkiaRep& image_rep); | 71 explicit Image(const ImageSkiaRep& image_rep); |
79 | 72 |
80 // Creates a new image by copying the bitmap for use as the default | 73 // Creates a new image by copying the bitmap for use as the default |
81 // representation. | 74 // representation. |
(...skipping 16 matching lines...) Expand all Loading... |
98 // Copies a reference to |other|'s storage. | 91 // Copies a reference to |other|'s storage. |
99 Image& operator=(const Image& other); | 92 Image& operator=(const Image& other); |
100 | 93 |
101 // 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 |
102 // representations. | 95 // representations. |
103 ~Image(); | 96 ~Image(); |
104 | 97 |
105 // Converts the Image to the desired representation and stores it internally. | 98 // Converts the Image to the desired representation and stores it internally. |
106 // 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 |
107 // the Image. Must only be called if IsEmpty() is false. | 100 // the Image. Must only be called if IsEmpty() is false. |
108 const std::vector<unsigned char>* ToImagePNG() const; | |
109 const SkBitmap* ToSkBitmap() const; | 101 const SkBitmap* ToSkBitmap() const; |
110 const ImageSkia* ToImageSkia() const; | 102 const ImageSkia* ToImageSkia() const; |
111 #if defined(TOOLKIT_GTK) | 103 #if defined(TOOLKIT_GTK) |
112 GdkPixbuf* ToGdkPixbuf() const; | 104 GdkPixbuf* ToGdkPixbuf() const; |
113 CairoCachedSurface* const ToCairo() const; | 105 CairoCachedSurface* const ToCairo() const; |
114 #elif defined(OS_MACOSX) | 106 #elif defined(OS_MACOSX) |
115 NSImage* ToNSImage() const; | 107 NSImage* ToNSImage() const; |
116 #endif | 108 #endif |
117 | 109 |
118 // 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. |
119 SkBitmap AsBitmap() const; | 111 SkBitmap AsBitmap() const; |
120 | 112 |
121 // Same as ToImageSkia(), but returns an empty ImageSkia if this | 113 // Same as ToImageSkia(), but returns an empty ImageSkia if this |
122 // image is empty. | 114 // image is empty. |
123 ImageSkia AsImageSkia() const; | 115 ImageSkia AsImageSkia() const; |
124 | 116 |
125 #if defined(OS_MACOSX) | 117 #if defined(OS_MACOSX) |
126 // Same as ToSkBitmap(), but returns nil if this image is empty. | 118 // Same as ToSkBitmap(), but returns nil if this image is empty. |
127 NSImage* AsNSImage() const; | 119 NSImage* AsNSImage() const; |
128 #endif | 120 #endif |
129 | 121 |
130 // 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 |
131 // 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. |
132 // 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 |
133 // 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 |
134 // converted representations, rather than a limitation imposed by Image) and | 126 // converted representations, rather than a limitation imposed by Image) and |
135 // so the result should be considered immutable. | 127 // so the result should be considered immutable. |
136 std::vector<unsigned char>* CopyImagePNG() const; | |
137 ImageSkia* CopyImageSkia() const; | 128 ImageSkia* CopyImageSkia() const; |
138 SkBitmap* CopySkBitmap() const; | 129 SkBitmap* CopySkBitmap() const; |
139 #if defined(TOOLKIT_GTK) | 130 #if defined(TOOLKIT_GTK) |
140 GdkPixbuf* CopyGdkPixbuf() const; | 131 GdkPixbuf* CopyGdkPixbuf() const; |
141 #elif defined(OS_MACOSX) | 132 #elif defined(OS_MACOSX) |
142 NSImage* CopyNSImage() const; | 133 NSImage* CopyNSImage() const; |
143 #endif | 134 #endif |
144 | 135 |
145 // DEPRECATED ---------------------------------------------------------------- | 136 // DEPRECATED ---------------------------------------------------------------- |
146 // Conversion handlers. These wrap the ToType() variants. | 137 // Conversion handlers. These wrap the ToType() variants. |
(...skipping 30 matching lines...) Expand all Loading... |
177 // be cheaply copied. | 168 // be cheaply copied. |
178 scoped_refptr<internal::ImageStorage> storage_; | 169 scoped_refptr<internal::ImageStorage> storage_; |
179 | 170 |
180 friend class ::ImageTest; | 171 friend class ::ImageTest; |
181 friend class ::ImageMacTest; | 172 friend class ::ImageMacTest; |
182 }; | 173 }; |
183 | 174 |
184 } // namespace gfx | 175 } // namespace gfx |
185 | 176 |
186 #endif // UI_GFX_IMAGE_IMAGE_H_ | 177 #endif // UI_GFX_IMAGE_IMAGE_H_ |
OLD | NEW |