| 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 |
| 11 // tied to the lifetime of the Image's internal storage. To allow Images to be | 11 // tied to the lifetime of the Image's internal storage. To allow Images to be |
| 12 // cheaply passed around by value, the actual image data is stored in a ref- | 12 // cheaply passed around by value, the actual image data is stored in a ref- |
| 13 // counted member. When all Images referencing this storage are deleted, the | 13 // counted member. When all Images referencing this storage are deleted, the |
| 14 // actual representations are deleted, too. | 14 // actual representations are deleted, too. |
| 15 // | 15 // |
| 16 // Images can be empty, in which case they have no backing representation. | 16 // Images can be empty, in which case they have no backing representation. |
| 17 // Attempting to use an empty Image will result in a crash. | 17 // Attempting to use an empty Image will result in a crash. |
| 18 | 18 |
| 19 #ifndef UI_GFX_IMAGE_IMAGE_H_ | 19 #ifndef UI_GFX_IMAGE_IMAGE_H_ |
| 20 #define UI_GFX_IMAGE_IMAGE_H_ | 20 #define UI_GFX_IMAGE_IMAGE_H_ |
| 21 | 21 |
| 22 #include <stddef.h> | 22 #include <stddef.h> |
| 23 | 23 |
| 24 #include <map> | 24 #include <map> |
| 25 #include <memory> | 25 #include <memory> |
| 26 #include <vector> | 26 #include <vector> |
| 27 | 27 |
| 28 #include "base/memory/ref_counted_memory.h" | 28 #include "base/memory/ref_counted_memory.h" |
| 29 #include "base/memory/scoped_policy.h" |
| 29 #include "build/build_config.h" | 30 #include "build/build_config.h" |
| 30 #include "ui/gfx/gfx_export.h" | 31 #include "ui/gfx/gfx_export.h" |
| 31 #include "ui/gfx/native_widget_types.h" | 32 #include "ui/gfx/native_widget_types.h" |
| 32 | 33 |
| 33 #if defined(OS_MACOSX) && !defined(OS_IOS) | 34 #if defined(OS_MACOSX) && !defined(OS_IOS) |
| 34 typedef struct CGColorSpace* CGColorSpaceRef; | 35 typedef struct CGColorSpace* CGColorSpaceRef; |
| 35 #endif | 36 #endif |
| 36 | 37 |
| 37 class SkBitmap; | 38 class SkBitmap; |
| 38 | 39 |
| (...skipping 26 matching lines...) Expand all Loading... |
| 65 // default representation. | 66 // default representation. |
| 66 explicit Image(const std::vector<ImagePNGRep>& image_reps); | 67 explicit Image(const std::vector<ImagePNGRep>& image_reps); |
| 67 | 68 |
| 68 // Creates a new image by copying the ImageSkia for use as the default | 69 // Creates a new image by copying the ImageSkia for use as the default |
| 69 // representation. | 70 // representation. |
| 70 explicit Image(const ImageSkia& image); | 71 explicit Image(const ImageSkia& image); |
| 71 | 72 |
| 72 #if defined(OS_IOS) | 73 #if defined(OS_IOS) |
| 73 // Does not retain |image|; expects to take ownership. | 74 // Does not retain |image|; expects to take ownership. |
| 74 explicit Image(UIImage* image); | 75 explicit Image(UIImage* image); |
| 76 |
| 77 // Retains argument according to |policy|. |
| 78 Image(UIImage* image, base::scoped_policy::OwnershipPolicy policy); |
| 79 |
| 75 #elif defined(OS_MACOSX) | 80 #elif defined(OS_MACOSX) |
| 76 // Does not retain |image|; expects to take ownership. | 81 // Does not retain |image|; expects to take ownership. |
| 77 // 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 |
| 78 // to pass a vector of these. | 83 // to pass a vector of these. |
| 79 explicit Image(NSImage* image); | 84 explicit Image(NSImage* image); |
| 80 #endif | 85 #endif |
| 81 | 86 |
| 82 // Initializes a new Image by AddRef()ing |other|'s internal storage. | 87 // Initializes a new Image by AddRef()ing |other|'s internal storage. |
| 83 Image(const Image& other); | 88 Image(const Image& other); |
| 84 | 89 |
| (...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 190 std::unique_ptr<internal::ImageRep> rep) const; | 195 std::unique_ptr<internal::ImageRep> rep) const; |
| 191 | 196 |
| 192 // Internal class that holds all the representations. This allows the Image to | 197 // Internal class that holds all the representations. This allows the Image to |
| 193 // be cheaply copied. | 198 // be cheaply copied. |
| 194 scoped_refptr<internal::ImageStorage> storage_; | 199 scoped_refptr<internal::ImageStorage> storage_; |
| 195 }; | 200 }; |
| 196 | 201 |
| 197 } // namespace gfx | 202 } // namespace gfx |
| 198 | 203 |
| 199 #endif // UI_GFX_IMAGE_IMAGE_H_ | 204 #endif // UI_GFX_IMAGE_IMAGE_H_ |
| OLD | NEW |