| 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 |
| 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 |
| 65 // 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 |
| 66 // representation. | 73 // representation. |
| 67 explicit Image(const ImageSkia& image); | 74 explicit Image(const ImageSkia& image); |
| 68 | 75 |
| 69 // Creates a new image by copying the image rep for use as the default | 76 // Creates a new image by copying the image rep for use as the default |
| 70 // representation. | 77 // representation. |
| 71 explicit Image(const ImageSkiaRep& image_rep); | 78 explicit Image(const ImageSkiaRep& image_rep); |
| 72 | 79 |
| 73 // Creates a new image by copying the bitmap for use as the default | 80 // Creates a new image by copying the bitmap for use as the default |
| 74 // representation. | 81 // representation. |
| (...skipping 16 matching lines...) Expand all Loading... |
| 91 // Copies a reference to |other|'s storage. | 98 // Copies a reference to |other|'s storage. |
| 92 Image& operator=(const Image& other); | 99 Image& operator=(const Image& other); |
| 93 | 100 |
| 94 // Deletes the image and, if the only owner of the storage, all of its cached | 101 // Deletes the image and, if the only owner of the storage, all of its cached |
| 95 // representations. | 102 // representations. |
| 96 ~Image(); | 103 ~Image(); |
| 97 | 104 |
| 98 // Converts the Image to the desired representation and stores it internally. | 105 // 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 | 106 // The returned result is a weak pointer owned by and scoped to the life of |
| 100 // the Image. | 107 // the Image. |
| 108 const std::vector<unsigned char>* ToImagePNG() const; |
| 101 const SkBitmap* ToSkBitmap() const; | 109 const SkBitmap* ToSkBitmap() const; |
| 102 const ImageSkia* ToImageSkia() const; | 110 const ImageSkia* ToImageSkia() const; |
| 103 #if defined(TOOLKIT_GTK) | 111 #if defined(TOOLKIT_GTK) |
| 104 GdkPixbuf* ToGdkPixbuf() const; | 112 GdkPixbuf* ToGdkPixbuf() const; |
| 105 CairoCachedSurface* const ToCairo() const; | 113 CairoCachedSurface* const ToCairo() const; |
| 106 #elif defined(OS_MACOSX) | 114 #elif defined(OS_MACOSX) |
| 107 NSImage* ToNSImage() const; | 115 NSImage* ToNSImage() const; |
| 108 #endif | 116 #endif |
| 109 | 117 |
| 110 // Same as ToSkBitmap(), but returns a null SkBitmap if this image is empty. | 118 // Same as ToSkBitmap(), but returns a null SkBitmap if this image is empty. |
| 111 SkBitmap AsBitmap() const; | 119 SkBitmap AsBitmap() const; |
| 112 | 120 |
| 113 // Same as ToSkBitmap(), but returns a ImageSkia with a null SkBitmap if this | 121 // Same as ToSkBitmap(), but returns a ImageSkia with a null SkBitmap if this |
| 114 // image is empty. | 122 // image is empty. |
| 115 ImageSkia AsImageSkia() const; | 123 ImageSkia AsImageSkia() const; |
| 116 | 124 |
| 117 // Performs a conversion, like above, but returns a copy of the result rather | 125 // Performs a conversion, like above, but returns a copy of the result rather |
| 118 // than a weak pointer. The caller is responsible for deleting the result. | 126 // than a weak pointer. The caller is responsible for deleting the result. |
| 119 // Note that the result is only a copy in terms of memory management; the | 127 // Note that the result is only a copy in terms of memory management; the |
| 120 // backing pixels are shared amongst all copies (a fact of each of the | 128 // backing pixels are shared amongst all copies (a fact of each of the |
| 121 // converted representations, rather than a limitation imposed by Image) and | 129 // converted representations, rather than a limitation imposed by Image) and |
| 122 // so the result should be considered immutable. | 130 // so the result should be considered immutable. |
| 131 std::vector<unsigned char>* CopyImagePNG() const; |
| 123 ImageSkia* CopyImageSkia() const; | 132 ImageSkia* CopyImageSkia() const; |
| 124 SkBitmap* CopySkBitmap() const; | 133 SkBitmap* CopySkBitmap() const; |
| 125 #if defined(TOOLKIT_GTK) | 134 #if defined(TOOLKIT_GTK) |
| 126 GdkPixbuf* CopyGdkPixbuf() const; | 135 GdkPixbuf* CopyGdkPixbuf() const; |
| 127 #elif defined(OS_MACOSX) | 136 #elif defined(OS_MACOSX) |
| 128 NSImage* CopyNSImage() const; | 137 NSImage* CopyNSImage() const; |
| 129 #endif | 138 #endif |
| 130 | 139 |
| 131 // DEPRECATED ---------------------------------------------------------------- | 140 // DEPRECATED ---------------------------------------------------------------- |
| 132 // Conversion handlers. These wrap the ToType() variants. | 141 // Conversion handlers. These wrap the ToType() variants. |
| (...skipping 30 matching lines...) Expand all Loading... |
| 163 // be cheaply copied. | 172 // be cheaply copied. |
| 164 scoped_refptr<internal::ImageStorage> storage_; | 173 scoped_refptr<internal::ImageStorage> storage_; |
| 165 | 174 |
| 166 friend class ::ImageTest; | 175 friend class ::ImageTest; |
| 167 friend class ::ImageMacTest; | 176 friend class ::ImageMacTest; |
| 168 }; | 177 }; |
| 169 | 178 |
| 170 } // namespace gfx | 179 } // namespace gfx |
| 171 | 180 |
| 172 #endif // UI_GFX_IMAGE_IMAGE_H_ | 181 #endif // UI_GFX_IMAGE_IMAGE_H_ |
| OLD | NEW |