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, | |
58 }; | 59 }; |
59 | 60 |
60 typedef std::map<RepresentationType, internal::ImageRep*> RepresentationMap; | 61 typedef std::map<RepresentationType, internal::ImageRep*> RepresentationMap; |
61 | 62 |
62 // Creates an empty image with no representations. | 63 // Creates an empty image with no representations. |
63 Image(); | 64 Image(); |
64 | 65 |
66 // Creates a new image by copying the png-encoded input for use as the default | |
Robert Sesek
2012/07/24 18:59:17
nit: PNG
Also add a note about how to create this
cjhopman
2012/07/25 21:13:29
Done.
| |
67 // representation. | |
68 Image(const unsigned char* png, size_t input_size); | |
69 | |
65 // Creates a new image by copying the ImageSkia for use as the default | 70 // Creates a new image by copying the ImageSkia for use as the default |
66 // representation. | 71 // representation. |
67 explicit Image(const ImageSkia& image); | 72 explicit Image(const ImageSkia& image); |
68 | 73 |
69 // Creates a new image by copying the image rep for use as the default | 74 // Creates a new image by copying the image rep for use as the default |
70 // representation. | 75 // representation. |
71 explicit Image(const ImageSkiaRep& image_rep); | 76 explicit Image(const ImageSkiaRep& image_rep); |
72 | 77 |
73 // Creates a new image by copying the bitmap for use as the default | 78 // Creates a new image by copying the bitmap for use as the default |
74 // representation. | 79 // representation. |
(...skipping 16 matching lines...) Expand all Loading... | |
91 // Copies a reference to |other|'s storage. | 96 // Copies a reference to |other|'s storage. |
92 Image& operator=(const Image& other); | 97 Image& operator=(const Image& other); |
93 | 98 |
94 // Deletes the image and, if the only owner of the storage, all of its cached | 99 // Deletes the image and, if the only owner of the storage, all of its cached |
95 // representations. | 100 // representations. |
96 ~Image(); | 101 ~Image(); |
97 | 102 |
98 // Converts the Image to the desired representation and stores it internally. | 103 // 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 | 104 // The returned result is a weak pointer owned by and scoped to the life of |
100 // the Image. | 105 // the Image. |
106 const std::vector<unsigned char>* ToImagePNG() const; | |
101 const SkBitmap* ToSkBitmap() const; | 107 const SkBitmap* ToSkBitmap() const; |
102 const ImageSkia* ToImageSkia() const; | 108 const ImageSkia* ToImageSkia() const; |
103 #if defined(TOOLKIT_GTK) | 109 #if defined(TOOLKIT_GTK) |
104 GdkPixbuf* ToGdkPixbuf() const; | 110 GdkPixbuf* ToGdkPixbuf() const; |
105 CairoCachedSurface* const ToCairo() const; | 111 CairoCachedSurface* const ToCairo() const; |
106 #elif defined(OS_MACOSX) | 112 #elif defined(OS_MACOSX) |
107 NSImage* ToNSImage() const; | 113 NSImage* ToNSImage() const; |
108 #endif | 114 #endif |
109 | 115 |
110 // Performs a conversion, like above, but returns a copy of the result rather | 116 // Performs a conversion, like above, but returns a copy of the result rather |
111 // than a weak pointer. The caller is responsible for deleting the result. | 117 // than a weak pointer. The caller is responsible for deleting the result. |
112 // Note that the result is only a copy in terms of memory management; the | 118 // Note that the result is only a copy in terms of memory management; the |
113 // backing pixels are shared amongst all copies (a fact of each of the | 119 // backing pixels are shared amongst all copies (a fact of each of the |
114 // converted representations, rather than a limitation imposed by Image) and | 120 // converted representations, rather than a limitation imposed by Image) and |
115 // so the result should be considered immutable. | 121 // so the result should be considered immutable. |
122 std::vector<unsigned char>* CopyImagePNG() const; | |
116 ImageSkia* CopyImageSkia() const; | 123 ImageSkia* CopyImageSkia() const; |
117 SkBitmap* CopySkBitmap() const; | 124 SkBitmap* CopySkBitmap() const; |
118 #if defined(TOOLKIT_GTK) | 125 #if defined(TOOLKIT_GTK) |
119 GdkPixbuf* CopyGdkPixbuf() const; | 126 GdkPixbuf* CopyGdkPixbuf() const; |
120 #elif defined(OS_MACOSX) | 127 #elif defined(OS_MACOSX) |
121 NSImage* CopyNSImage() const; | 128 NSImage* CopyNSImage() const; |
122 #endif | 129 #endif |
123 | 130 |
124 // DEPRECATED ---------------------------------------------------------------- | 131 // DEPRECATED ---------------------------------------------------------------- |
125 // Conversion handlers. These wrap the ToType() variants. | 132 // Conversion handlers. These wrap the ToType() variants. |
(...skipping 30 matching lines...) Expand all Loading... | |
156 // be cheaply copied. | 163 // be cheaply copied. |
157 scoped_refptr<internal::ImageStorage> storage_; | 164 scoped_refptr<internal::ImageStorage> storage_; |
158 | 165 |
159 friend class ::ImageTest; | 166 friend class ::ImageTest; |
160 friend class ::ImageMacTest; | 167 friend class ::ImageMacTest; |
161 }; | 168 }; |
162 | 169 |
163 } // namespace gfx | 170 } // namespace gfx |
164 | 171 |
165 #endif // UI_GFX_IMAGE_IMAGE_H_ | 172 #endif // UI_GFX_IMAGE_IMAGE_H_ |
OLD | NEW |