| 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 18 matching lines...) Expand all Loading... |
| 29 #include "ui/gfx/native_widget_types.h" | 29 #include "ui/gfx/native_widget_types.h" |
| 30 | 30 |
| 31 class SkBitmap; | 31 class SkBitmap; |
| 32 | 32 |
| 33 namespace { | 33 namespace { |
| 34 class ImageTest; | 34 class ImageTest; |
| 35 class ImageMacTest; | 35 class ImageMacTest; |
| 36 } | 36 } |
| 37 | 37 |
| 38 namespace gfx { | 38 namespace gfx { |
| 39 class ImagePNG; |
| 39 class ImageSkia; | 40 class ImageSkia; |
| 40 class ImageSkiaRep; | 41 class ImageSkiaRep; |
| 41 | 42 |
| 42 #if defined(TOOLKIT_GTK) | 43 #if defined(TOOLKIT_GTK) |
| 43 class CairoCachedSurface; | 44 class CairoCachedSurface; |
| 44 #endif | 45 #endif |
| 45 | 46 |
| 46 namespace internal { | 47 namespace internal { |
| 47 class ImageRep; | 48 class ImageRep; |
| 48 class ImageStorage; | 49 class ImageStorage; |
| 49 } | 50 } |
| 50 | 51 |
| 51 class UI_EXPORT Image { | 52 class UI_EXPORT Image { |
| 52 public: | 53 public: |
| 53 enum RepresentationType { | 54 enum RepresentationType { |
| 54 kImageRepGdk, | 55 kImageRepGdk, |
| 55 kImageRepCocoa, | 56 kImageRepCocoa, |
| 56 kImageRepCairo, | 57 kImageRepCairo, |
| 57 kImageRepSkia, | 58 kImageRepSkia, |
| 59 kImageRepPNG, |
| 58 }; | 60 }; |
| 59 | 61 |
| 60 typedef std::map<RepresentationType, internal::ImageRep*> RepresentationMap; | 62 typedef std::map<RepresentationType, internal::ImageRep*> RepresentationMap; |
| 61 | 63 |
| 62 // Creates an empty image with no representations. | 64 // Creates an empty image with no representations. |
| 63 Image(); | 65 Image(); |
| 64 | 66 |
| 67 // Creates a new image by copying the ImagePNG for use as the default |
| 68 // representation. |
| 69 explicit Image(const ImagePNG& png); |
| 70 |
| 65 // Creates a new image by copying the ImageSkia for use as the default | 71 // Creates a new image by copying the ImageSkia for use as the default |
| 66 // representation. | 72 // representation. |
| 67 explicit Image(const ImageSkia& image); | 73 explicit Image(const ImageSkia& image); |
| 68 | 74 |
| 69 // Creates a new image by copying the image rep for use as the default | 75 // Creates a new image by copying the image rep for use as the default |
| 70 // representation. | 76 // representation. |
| 71 explicit Image(const ImageSkiaRep& image_rep); | 77 explicit Image(const ImageSkiaRep& image_rep); |
| 72 | 78 |
| 73 // Creates a new image by copying the bitmap for use as the default | 79 // Creates a new image by copying the bitmap for use as the default |
| 74 // representation. | 80 // representation. |
| (...skipping 16 matching lines...) Expand all Loading... |
| 91 // Copies a reference to |other|'s storage. | 97 // Copies a reference to |other|'s storage. |
| 92 Image& operator=(const Image& other); | 98 Image& operator=(const Image& other); |
| 93 | 99 |
| 94 // Deletes the image and, if the only owner of the storage, all of its cached | 100 // Deletes the image and, if the only owner of the storage, all of its cached |
| 95 // representations. | 101 // representations. |
| 96 ~Image(); | 102 ~Image(); |
| 97 | 103 |
| 98 // Converts the Image to the desired representation and stores it internally. | 104 // 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 | 105 // The returned result is a weak pointer owned by and scoped to the life of |
| 100 // the Image. | 106 // the Image. |
| 107 const ImagePNG* ToImagePNG() const; |
| 101 const SkBitmap* ToSkBitmap() const; | 108 const SkBitmap* ToSkBitmap() const; |
| 102 const ImageSkia* ToImageSkia() const; | 109 const ImageSkia* ToImageSkia() const; |
| 103 #if defined(TOOLKIT_GTK) | 110 #if defined(TOOLKIT_GTK) |
| 104 GdkPixbuf* ToGdkPixbuf() const; | 111 GdkPixbuf* ToGdkPixbuf() const; |
| 105 CairoCachedSurface* const ToCairo() const; | 112 CairoCachedSurface* const ToCairo() const; |
| 106 #elif defined(OS_MACOSX) | 113 #elif defined(OS_MACOSX) |
| 107 NSImage* ToNSImage() const; | 114 NSImage* ToNSImage() const; |
| 108 #endif | 115 #endif |
| 109 | 116 |
| 110 // Performs a conversion, like above, but returns a copy of the result rather | 117 // 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. | 118 // 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 | 119 // 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 | 120 // backing pixels are shared amongst all copies (a fact of each of the |
| 114 // converted representations, rather than a limitation imposed by Image) and | 121 // converted representations, rather than a limitation imposed by Image) and |
| 115 // so the result should be considered immutable. | 122 // so the result should be considered immutable. |
| 123 ImagePNG* CopyImagePNG() const; |
| 116 ImageSkia* CopyImageSkia() const; | 124 ImageSkia* CopyImageSkia() const; |
| 117 SkBitmap* CopySkBitmap() const; | 125 SkBitmap* CopySkBitmap() const; |
| 118 #if defined(TOOLKIT_GTK) | 126 #if defined(TOOLKIT_GTK) |
| 119 GdkPixbuf* CopyGdkPixbuf() const; | 127 GdkPixbuf* CopyGdkPixbuf() const; |
| 120 #elif defined(OS_MACOSX) | 128 #elif defined(OS_MACOSX) |
| 121 NSImage* CopyNSImage() const; | 129 NSImage* CopyNSImage() const; |
| 122 #endif | 130 #endif |
| 123 | 131 |
| 124 // DEPRECATED ---------------------------------------------------------------- | 132 // DEPRECATED ---------------------------------------------------------------- |
| 125 // Conversion handlers. These wrap the ToType() variants. | 133 // Conversion handlers. These wrap the ToType() variants. |
| (...skipping 30 matching lines...) Expand all Loading... |
| 156 // be cheaply copied. | 164 // be cheaply copied. |
| 157 scoped_refptr<internal::ImageStorage> storage_; | 165 scoped_refptr<internal::ImageStorage> storage_; |
| 158 | 166 |
| 159 friend class ::ImageTest; | 167 friend class ::ImageTest; |
| 160 friend class ::ImageMacTest; | 168 friend class ::ImageMacTest; |
| 161 }; | 169 }; |
| 162 | 170 |
| 163 } // namespace gfx | 171 } // namespace gfx |
| 164 | 172 |
| 165 #endif // UI_GFX_IMAGE_IMAGE_H_ | 173 #endif // UI_GFX_IMAGE_IMAGE_H_ |
| OLD | NEW |