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 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
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 namespace internal { | 47 namespace internal { |
48 class ImageRep; | 48 class ImageRep; |
49 class ImageStorage; | 49 class ImageStorage; |
50 } | 50 } |
51 | 51 |
52 // An image, backed by zero or more equivalent representations. When a specific | |
Robert Sesek
2014/04/17 16:56:58
The comment for this class is at the top of the fi
| |
53 // representation is requested, the image data is converted to the desired | |
54 // representation and cached, if it is not already. | |
55 // | |
56 // Image objects are copyable and thread safe. However, there are no thread | |
57 // safety guarantees about the individual representations. | |
52 class GFX_EXPORT Image { | 58 class GFX_EXPORT Image { |
53 public: | 59 public: |
54 enum RepresentationType { | 60 enum RepresentationType { |
55 kImageRepGdk, | 61 kImageRepGdk, |
56 kImageRepCocoa, | 62 kImageRepCocoa, |
57 kImageRepCocoaTouch, | 63 kImageRepCocoaTouch, |
58 kImageRepCairo, | 64 kImageRepCairo, |
59 kImageRepSkia, | 65 kImageRepSkia, |
60 kImageRepPNG, | 66 kImageRepPNG, |
61 }; | 67 }; |
62 | 68 |
63 typedef std::map<RepresentationType, internal::ImageRep*> RepresentationMap; | |
64 | |
65 // Creates an empty image with no representations. | 69 // Creates an empty image with no representations. |
66 Image(); | 70 Image(); |
67 | 71 |
68 // Creates a new image by copying the raw PNG-encoded input for use as the | 72 // Creates a new image by copying the raw PNG-encoded input for use as the |
69 // default representation. | 73 // default representation. |
70 explicit Image(const std::vector<ImagePNGRep>& image_reps); | 74 explicit Image(const std::vector<ImagePNGRep>& image_reps); |
71 | 75 |
72 // Creates a new image by copying the ImageSkia for use as the default | 76 // Creates a new image by copying the ImageSkia for use as the default |
73 // representation. | 77 // representation. |
74 explicit Image(const ImageSkia& image); | 78 explicit Image(const ImageSkia& image); |
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
181 private: | 185 private: |
182 // Returns the type of the default representation. | 186 // Returns the type of the default representation. |
183 RepresentationType DefaultRepresentationType() const; | 187 RepresentationType DefaultRepresentationType() const; |
184 | 188 |
185 // Returns the ImageRep of the appropriate type or NULL if there is no | 189 // Returns the ImageRep of the appropriate type or NULL if there is no |
186 // representation of that type (and must_exist is false). | 190 // representation of that type (and must_exist is false). |
187 internal::ImageRep* GetRepresentation( | 191 internal::ImageRep* GetRepresentation( |
188 RepresentationType rep_type, bool must_exist) const; | 192 RepresentationType rep_type, bool must_exist) const; |
189 | 193 |
190 // Stores a representation into the map. | 194 // Stores a representation into the map. |
195 // NOTE: This is const, despite modifying the object's internal storage. It | |
196 // should only be used to add representations that are equivalent to an | |
197 // existing representation (i.e., it should not affect the externally visible | |
198 // state of the object). | |
191 void AddRepresentation(internal::ImageRep* rep) const; | 199 void AddRepresentation(internal::ImageRep* rep) const; |
192 | 200 |
193 // Internal class that holds all the representations. This allows the Image to | 201 // Internal class that holds all the representations. This allows the Image to |
194 // be cheaply copied. | 202 // be cheaply copied. |
195 scoped_refptr<internal::ImageStorage> storage_; | 203 scoped_refptr<internal::ImageStorage> storage_; |
196 | 204 |
197 friend class ::ImageTest; | 205 friend class ::ImageTest; |
198 friend class ::ImageMacTest; | 206 friend class ::ImageMacTest; |
199 }; | 207 }; |
200 | 208 |
201 } // namespace gfx | 209 } // namespace gfx |
202 | 210 |
203 #endif // UI_GFX_IMAGE_IMAGE_H_ | 211 #endif // UI_GFX_IMAGE_IMAGE_H_ |
OLD | NEW |