Chromium Code Reviews| 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 19 matching lines...) Expand all Loading... | |
| 30 #include "ui/gfx/native_widget_types.h" | 30 #include "ui/gfx/native_widget_types.h" |
| 31 | 31 |
| 32 class SkBitmap; | 32 class SkBitmap; |
| 33 | 33 |
| 34 namespace { | 34 namespace { |
| 35 class ImageTest; | 35 class ImageTest; |
| 36 class ImageMacTest; | 36 class ImageMacTest; |
| 37 } | 37 } |
| 38 | 38 |
| 39 namespace gfx { | 39 namespace gfx { |
| 40 class ImageSkia; | |
| 40 | 41 |
| 41 #if defined(TOOLKIT_GTK) | 42 #if defined(TOOLKIT_GTK) |
| 42 class CairoCachedSurface; | 43 class CairoCachedSurface; |
| 43 #endif | 44 #endif |
| 44 | 45 |
| 45 namespace internal { | 46 namespace internal { |
| 46 class ImageRep; | 47 class ImageRep; |
| 47 class ImageStorage; | 48 class ImageStorage; |
| 48 } | 49 } |
| 49 | 50 |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 61 // Creates an empty image with no representations. | 62 // Creates an empty image with no representations. |
| 62 Image(); | 63 Image(); |
| 63 | 64 |
| 64 // Creates a new image with the default representation. The object will take | 65 // Creates a new image with the default representation. The object will take |
| 65 // ownership of the image. | 66 // ownership of the image. |
| 66 explicit Image(const SkBitmap* bitmap); | 67 explicit Image(const SkBitmap* bitmap); |
| 67 | 68 |
| 68 // Creates a new image by copying the bitmap for use as the default | 69 // Creates a new image by copying the bitmap for use as the default |
| 69 // representation. | 70 // representation. |
| 70 explicit Image(const SkBitmap& bitmap); | 71 explicit Image(const SkBitmap& bitmap); |
| 71 | 72 |
|
Robert Sesek
2012/04/16 16:06:01
Should you be able to construct an Image with a Im
| |
| 72 // To create an Image that supports multiple resolutions pass a vector | 73 // To create an Image that supports multiple resolutions pass a vector |
| 73 // of bitmaps, one for each resolution. | 74 // of bitmaps, one for each resolution. |
| 74 explicit Image(const std::vector<const SkBitmap*>& bitmaps); | 75 explicit Image(const std::vector<const SkBitmap*>& bitmaps); |
| 75 | 76 |
| 76 #if defined(TOOLKIT_GTK) | 77 #if defined(TOOLKIT_GTK) |
| 77 // Does not increase |pixbuf|'s reference count; expects to take ownership. | 78 // Does not increase |pixbuf|'s reference count; expects to take ownership. |
| 78 explicit Image(GdkPixbuf* pixbuf); | 79 explicit Image(GdkPixbuf* pixbuf); |
| 79 #elif defined(OS_MACOSX) | 80 #elif defined(OS_MACOSX) |
| 80 // Does not retain |image|; expects to take ownership. | 81 // Does not retain |image|; expects to take ownership. |
| 81 // A single NSImage object can contain multiple bitmaps so there's no reason | 82 // A single NSImage object can contain multiple bitmaps so there's no reason |
| 82 // to pass a vector of these. | 83 // to pass a vector of these. |
| 83 explicit Image(NSImage* image); | 84 explicit Image(NSImage* image); |
| 84 #endif | 85 #endif |
| 85 | 86 |
| 86 // Initializes a new Image by AddRef()ing |other|'s internal storage. | 87 // Initializes a new Image by AddRef()ing |other|'s internal storage. |
| 87 Image(const Image& other); | 88 Image(const Image& other); |
| 88 | 89 |
| 89 // Copies a reference to |other|'s storage. | 90 // Copies a reference to |other|'s storage. |
| 90 Image& operator=(const Image& other); | 91 Image& operator=(const Image& other); |
| 91 | 92 |
| 92 // Deletes the image and, if the only owner of the storage, all of its cached | 93 // Deletes the image and, if the only owner of the storage, all of its cached |
| 93 // representations. | 94 // representations. |
| 94 ~Image(); | 95 ~Image(); |
| 95 | 96 |
| 96 // Converts the Image to the desired representation and stores it internally. | 97 // Converts the Image to the desired representation and stores it internally. |
| 97 // The returned result is a weak pointer owned by and scoped to the life of | 98 // The returned result is a weak pointer owned by and scoped to the life of |
| 98 // the Image. | 99 // the Image. |
| 99 const SkBitmap* ToSkBitmap() const; | 100 const SkBitmap* ToSkBitmap() const; |
| 101 | |
|
Robert Sesek
2012/04/16 16:06:01
nit: no blank line
| |
| 102 const ImageSkia* ToImageSkia() const; | |
|
sky
2012/04/16 14:35:27
Document ownership.
pkotwicz
2012/04/19 03:15:05
Ownership is documented in unmodified comment abov
| |
| 100 #if defined(TOOLKIT_GTK) | 103 #if defined(TOOLKIT_GTK) |
| 101 GdkPixbuf* ToGdkPixbuf() const; | 104 GdkPixbuf* ToGdkPixbuf() const; |
| 102 CairoCachedSurface* const ToCairo() const; | 105 CairoCachedSurface* const ToCairo() const; |
| 103 #elif defined(OS_MACOSX) | 106 #elif defined(OS_MACOSX) |
| 104 NSImage* ToNSImage() const; | 107 NSImage* ToNSImage() const; |
| 105 #endif | 108 #endif |
| 106 | 109 |
| 107 // Performs a conversion, like above, but returns a copy of the result rather | 110 // Performs a conversion, like above, but returns a copy of the result rather |
| 108 // than a weak pointer. The caller is responsible for deleting the result. | 111 // than a weak pointer. The caller is responsible for deleting the result. |
| 109 // Note that the result is only a copy in terms of memory management; the | 112 // Note that the result is only a copy in terms of memory management; the |
| 110 // backing pixels are shared amongst all copies (a fact of each of the | 113 // backing pixels are shared amongst all copies (a fact of each of the |
| 111 // converted representations, rather than a limitation imposed by Image) and | 114 // converted representations, rather than a limitation imposed by Image) and |
| 112 // so the result should be considered immutable. | 115 // so the result should be considered immutable. |
| 113 SkBitmap* CopySkBitmap() const; | 116 SkBitmap* CopySkBitmap() const; |
| 114 #if defined(TOOLKIT_GTK) | 117 #if defined(TOOLKIT_GTK) |
| 115 GdkPixbuf* CopyGdkPixbuf() const; | 118 GdkPixbuf* CopyGdkPixbuf() const; |
| 116 #elif defined(OS_MACOSX) | 119 #elif defined(OS_MACOSX) |
| 117 NSImage* CopyNSImage() const; | 120 NSImage* CopyNSImage() const; |
| 118 #endif | 121 #endif |
| 119 | 122 |
| 120 // DEPRECATED ---------------------------------------------------------------- | 123 // DEPRECATED ---------------------------------------------------------------- |
| 121 // Conversion handlers. These wrap the ToType() variants. | 124 // Conversion handlers. These wrap the ToType() variants. |
| 122 #if defined(OS_MACOSX) | 125 #if defined(OS_MACOSX) |
| 123 operator NSImage*() const; | 126 operator NSImage*() const; |
| 124 #endif | 127 #endif |
| 125 // --------------------------------------------------------------------------- | 128 // --------------------------------------------------------------------------- |
| 126 | 129 |
| 127 // Gets the number of bitmaps in this image. This may cause a conversion | |
| 128 // to a bitmap representation. Note, this function and GetSkBitmapAtIndex() | |
| 129 // are primarily meant to be used by the theme provider. | |
| 130 size_t GetNumberOfSkBitmaps() const; | |
| 131 | |
| 132 // Gets the bitmap at the given index. This may cause a conversion | |
| 133 // to a bitmap representation. Note, the internal ordering of bitmaps is not | |
| 134 // guaranteed. | |
| 135 const SkBitmap* GetSkBitmapAtIndex(size_t index) const; | |
| 136 | |
| 137 // Inspects the representations map to see if the given type exists. | 130 // Inspects the representations map to see if the given type exists. |
| 138 bool HasRepresentation(RepresentationType type) const; | 131 bool HasRepresentation(RepresentationType type) const; |
| 139 | 132 |
| 140 // Returns the number of representations. | 133 // Returns the number of representations. |
| 141 size_t RepresentationCount() const; | 134 size_t RepresentationCount() const; |
| 142 | 135 |
| 143 // Returns true if this Image has no representations. | 136 // Returns true if this Image has no representations. |
| 144 bool IsEmpty() const; | 137 bool IsEmpty() const; |
| 145 | 138 |
| 146 // Swaps this image's internal representations with |other|. | 139 // Swaps this image's internal representations with |other|. |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 161 // be cheaply copied. | 154 // be cheaply copied. |
| 162 scoped_refptr<internal::ImageStorage> storage_; | 155 scoped_refptr<internal::ImageStorage> storage_; |
| 163 | 156 |
| 164 friend class ::ImageTest; | 157 friend class ::ImageTest; |
| 165 friend class ::ImageMacTest; | 158 friend class ::ImageMacTest; |
| 166 }; | 159 }; |
| 167 | 160 |
| 168 } // namespace gfx | 161 } // namespace gfx |
| 169 | 162 |
| 170 #endif // UI_GFX_IMAGE_IMAGE_H_ | 163 #endif // UI_GFX_IMAGE_IMAGE_H_ |
| OLD | NEW |