| 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 26 matching lines...) Expand all Loading... |
| 37 namespace { | 37 namespace { |
| 38 class ImageTest; | 38 class ImageTest; |
| 39 class ImageMacTest; | 39 class ImageMacTest; |
| 40 } | 40 } |
| 41 | 41 |
| 42 namespace gfx { | 42 namespace gfx { |
| 43 struct ImagePNGRep; | 43 struct ImagePNGRep; |
| 44 class ImageSkia; | 44 class ImageSkia; |
| 45 class Size; | 45 class Size; |
| 46 | 46 |
| 47 #if defined(TOOLKIT_GTK) | |
| 48 class CairoCachedSurface; | |
| 49 #endif | |
| 50 | |
| 51 namespace internal { | 47 namespace internal { |
| 52 class ImageRep; | 48 class ImageRep; |
| 53 class ImageStorage; | 49 class ImageStorage; |
| 54 } | 50 } |
| 55 | 51 |
| 56 class GFX_EXPORT Image { | 52 class GFX_EXPORT Image { |
| 57 public: | 53 public: |
| 58 enum RepresentationType { | 54 enum RepresentationType { |
| 59 kImageRepGdk, | 55 kImageRepGdk, |
| 60 kImageRepCocoa, | 56 kImageRepCocoa, |
| 61 kImageRepCocoaTouch, | 57 kImageRepCocoaTouch, |
| 62 kImageRepCairo, | 58 kImageRepCairo, |
| 63 kImageRepSkia, | 59 kImageRepSkia, |
| 64 kImageRepPNG, | 60 kImageRepPNG, |
| 65 }; | 61 }; |
| 66 | 62 |
| 67 typedef std::map<RepresentationType, internal::ImageRep*> RepresentationMap; | 63 typedef std::map<RepresentationType, internal::ImageRep*> RepresentationMap; |
| 68 | 64 |
| 69 // Creates an empty image with no representations. | 65 // Creates an empty image with no representations. |
| 70 Image(); | 66 Image(); |
| 71 | 67 |
| 72 // Creates a new image by copying the raw PNG-encoded input for use as the | 68 // Creates a new image by copying the raw PNG-encoded input for use as the |
| 73 // default representation. | 69 // default representation. |
| 74 explicit Image(const std::vector<ImagePNGRep>& image_reps); | 70 explicit Image(const std::vector<ImagePNGRep>& image_reps); |
| 75 | 71 |
| 76 // Creates a new image by copying the ImageSkia for use as the default | 72 // Creates a new image by copying the ImageSkia for use as the default |
| 77 // representation. | 73 // representation. |
| 78 explicit Image(const ImageSkia& image); | 74 explicit Image(const ImageSkia& image); |
| 79 | 75 |
| 80 #if defined(TOOLKIT_GTK) | 76 #if defined(OS_IOS) |
| 81 // Does not increase |pixbuf|'s reference count; expects to take ownership. | |
| 82 explicit Image(GdkPixbuf* pixbuf); | |
| 83 #elif defined(OS_IOS) | |
| 84 // Does not retain |image|; expects to take ownership. | 77 // Does not retain |image|; expects to take ownership. |
| 85 explicit Image(UIImage* image); | 78 explicit Image(UIImage* image); |
| 86 #elif defined(OS_MACOSX) | 79 #elif defined(OS_MACOSX) |
| 87 // Does not retain |image|; expects to take ownership. | 80 // Does not retain |image|; expects to take ownership. |
| 88 // A single NSImage object can contain multiple bitmaps so there's no reason | 81 // A single NSImage object can contain multiple bitmaps so there's no reason |
| 89 // to pass a vector of these. | 82 // to pass a vector of these. |
| 90 explicit Image(NSImage* image); | 83 explicit Image(NSImage* image); |
| 91 #endif | 84 #endif |
| 92 | 85 |
| 93 // Initializes a new Image by AddRef()ing |other|'s internal storage. | 86 // Initializes a new Image by AddRef()ing |other|'s internal storage. |
| (...skipping 21 matching lines...) Expand all Loading... |
| 115 | 108 |
| 116 // Creates an image from the PNG encoded input. | 109 // Creates an image from the PNG encoded input. |
| 117 static Image CreateFrom1xPNGBytes( | 110 static Image CreateFrom1xPNGBytes( |
| 118 const scoped_refptr<base::RefCountedMemory>& input); | 111 const scoped_refptr<base::RefCountedMemory>& input); |
| 119 | 112 |
| 120 // Converts the Image to the desired representation and stores it internally. | 113 // Converts the Image to the desired representation and stores it internally. |
| 121 // The returned result is a weak pointer owned by and scoped to the life of | 114 // The returned result is a weak pointer owned by and scoped to the life of |
| 122 // the Image. Must only be called if IsEmpty() is false. | 115 // the Image. Must only be called if IsEmpty() is false. |
| 123 const SkBitmap* ToSkBitmap() const; | 116 const SkBitmap* ToSkBitmap() const; |
| 124 const ImageSkia* ToImageSkia() const; | 117 const ImageSkia* ToImageSkia() const; |
| 125 #if defined(TOOLKIT_GTK) | 118 #if defined(OS_IOS) |
| 126 GdkPixbuf* ToGdkPixbuf() const; | |
| 127 CairoCachedSurface* const ToCairo() const; | |
| 128 #elif defined(OS_IOS) | |
| 129 UIImage* ToUIImage() const; | 119 UIImage* ToUIImage() const; |
| 130 #elif defined(OS_MACOSX) | 120 #elif defined(OS_MACOSX) |
| 131 NSImage* ToNSImage() const; | 121 NSImage* ToNSImage() const; |
| 132 #endif | 122 #endif |
| 133 | 123 |
| 134 // Returns the raw PNG-encoded data for the bitmap at 1x. If the data is | 124 // Returns the raw PNG-encoded data for the bitmap at 1x. If the data is |
| 135 // unavailable, either because the image has no data for 1x or because it is | 125 // unavailable, either because the image has no data for 1x or because it is |
| 136 // empty, an empty RefCountedBytes object is returned. NULL is never | 126 // empty, an empty RefCountedBytes object is returned. NULL is never |
| 137 // returned. | 127 // returned. |
| 138 scoped_refptr<base::RefCountedMemory> As1xPNGBytes() const; | 128 scoped_refptr<base::RefCountedMemory> As1xPNGBytes() const; |
| (...skipping 12 matching lines...) Expand all Loading... |
| 151 | 141 |
| 152 // Performs a conversion, like above, but returns a copy of the result rather | 142 // Performs a conversion, like above, but returns a copy of the result rather |
| 153 // than a weak pointer. The caller is responsible for deleting the result. | 143 // than a weak pointer. The caller is responsible for deleting the result. |
| 154 // Note that the result is only a copy in terms of memory management; the | 144 // Note that the result is only a copy in terms of memory management; the |
| 155 // backing pixels are shared amongst all copies (a fact of each of the | 145 // backing pixels are shared amongst all copies (a fact of each of the |
| 156 // converted representations, rather than a limitation imposed by Image) and | 146 // converted representations, rather than a limitation imposed by Image) and |
| 157 // so the result should be considered immutable. | 147 // so the result should be considered immutable. |
| 158 scoped_refptr<base::RefCountedMemory> Copy1xPNGBytes() const; | 148 scoped_refptr<base::RefCountedMemory> Copy1xPNGBytes() const; |
| 159 ImageSkia* CopyImageSkia() const; | 149 ImageSkia* CopyImageSkia() const; |
| 160 SkBitmap* CopySkBitmap() const; | 150 SkBitmap* CopySkBitmap() const; |
| 161 #if defined(TOOLKIT_GTK) | 151 #if defined(OS_IOS) |
| 162 GdkPixbuf* CopyGdkPixbuf() const; | |
| 163 #elif defined(OS_IOS) | |
| 164 UIImage* CopyUIImage() const; | 152 UIImage* CopyUIImage() const; |
| 165 #elif defined(OS_MACOSX) | 153 #elif defined(OS_MACOSX) |
| 166 NSImage* CopyNSImage() const; | 154 NSImage* CopyNSImage() const; |
| 167 #endif | 155 #endif |
| 168 | 156 |
| 169 // Inspects the representations map to see if the given type exists. | 157 // Inspects the representations map to see if the given type exists. |
| 170 bool HasRepresentation(RepresentationType type) const; | 158 bool HasRepresentation(RepresentationType type) const; |
| 171 | 159 |
| 172 // Returns the number of representations. | 160 // Returns the number of representations. |
| 173 size_t RepresentationCount() const; | 161 size_t RepresentationCount() const; |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 206 // be cheaply copied. | 194 // be cheaply copied. |
| 207 scoped_refptr<internal::ImageStorage> storage_; | 195 scoped_refptr<internal::ImageStorage> storage_; |
| 208 | 196 |
| 209 friend class ::ImageTest; | 197 friend class ::ImageTest; |
| 210 friend class ::ImageMacTest; | 198 friend class ::ImageMacTest; |
| 211 }; | 199 }; |
| 212 | 200 |
| 213 } // namespace gfx | 201 } // namespace gfx |
| 214 | 202 |
| 215 #endif // UI_GFX_IMAGE_IMAGE_H_ | 203 #endif // UI_GFX_IMAGE_IMAGE_H_ |
| OLD | NEW |