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 #ifndef UI_GFX_IMAGE_IMAGE_SKIA_H_ | 5 #ifndef UI_GFX_IMAGE_IMAGE_SKIA_H_ |
6 #define UI_GFX_IMAGE_IMAGE_SKIA_H_ | 6 #define UI_GFX_IMAGE_IMAGE_SKIA_H_ |
7 | 7 |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
(...skipping 29 matching lines...) Expand all Loading... |
40 | 40 |
41 // Creates an instance with no bitmaps. | 41 // Creates an instance with no bitmaps. |
42 ImageSkia(); | 42 ImageSkia(); |
43 | 43 |
44 // Creates an instance that will use the |source| to get the image | 44 // Creates an instance that will use the |source| to get the image |
45 // for scale factors. |size| specifes the size of the image in DIP. | 45 // for scale factors. |size| specifes the size of the image in DIP. |
46 // ImageSkia owns |source|. | 46 // ImageSkia owns |source|. |
47 ImageSkia(ImageSkiaSource* source, const gfx::Size& size); | 47 ImageSkia(ImageSkiaSource* source, const gfx::Size& size); |
48 | 48 |
49 // Creates an instance that uses the |source|. The constructor loads the image | 49 // Creates an instance that uses the |source|. The constructor loads the image |
50 // at |scale_factor| and uses its dimensions to calculate the size in DIP. | 50 // at |scale| and uses its dimensions to calculate the size in DIP. ImageSkia |
51 // ImageSkia owns |source|. | 51 // owns |source|. |
52 ImageSkia(ImageSkiaSource* source, ui::ScaleFactor scale_factor); | 52 ImageSkia(ImageSkiaSource* source, float scale); |
53 | 53 |
54 explicit ImageSkia(const gfx::ImageSkiaRep& image_rep); | 54 explicit ImageSkia(const gfx::ImageSkiaRep& image_rep); |
55 | 55 |
56 // Copies a reference to |other|'s storage. | 56 // Copies a reference to |other|'s storage. |
57 ImageSkia(const ImageSkia& other); | 57 ImageSkia(const ImageSkia& other); |
58 | 58 |
59 // Copies a reference to |other|'s storage. | 59 // Copies a reference to |other|'s storage. |
60 ImageSkia& operator=(const ImageSkia& other); | 60 ImageSkia& operator=(const ImageSkia& other); |
61 | 61 |
62 ~ImageSkia(); | 62 ~ImageSkia(); |
63 | 63 |
| 64 // Changes the value of GetSupportedScales() to |scales|. |
| 65 static void SetSupportedScales(const std::vector<float>& scales); |
| 66 |
| 67 // Returns a vector with the scale factors which are supported by this |
| 68 // platform, in ascending order. |
| 69 static const std::vector<float>& GetSupportedScales(); |
| 70 |
| 71 // Returns the maximum scale supported by this platform. |
| 72 static float GetMaxSupportedScale(); |
| 73 |
64 // Creates an image from the passed in bitmap. | 74 // Creates an image from the passed in bitmap. |
65 // DIP width and height are based on scale factor of 1x. | 75 // DIP width and height are based on scale factor of 1x. |
66 // Adds ref to passed in bitmap. | 76 // Adds ref to passed in bitmap. |
67 // WARNING: The resulting image will be pixelated when painted on a high | 77 // WARNING: The resulting image will be pixelated when painted on a high |
68 // density display. | 78 // density display. |
69 static ImageSkia CreateFrom1xBitmap(const SkBitmap& bitmap); | 79 static ImageSkia CreateFrom1xBitmap(const SkBitmap& bitmap); |
70 | 80 |
71 // Returns a deep copy of this ImageSkia which has its own storage with | 81 // Returns a deep copy of this ImageSkia which has its own storage with |
72 // the ImageSkiaRep instances that this ImageSkia currently has. | 82 // the ImageSkiaRep instances that this ImageSkia currently has. |
73 // This can be safely passed to and manipulated by another thread. | 83 // This can be safely passed to and manipulated by another thread. |
74 // Note that this does NOT generate ImageSkiaReps from its source. | 84 // Note that this does NOT generate ImageSkiaReps from its source. |
75 // If you want to create a deep copy with ImageSkiaReps for supported | 85 // If you want to create a deep copy with ImageSkiaReps for supported |
76 // scale factors, you need to explicitly call | 86 // scale factors, you need to explicitly call |
77 // |EnsureRepsForSupportedScaleFactors()| first. | 87 // |EnsureRepsForSupportedScales()| first. |
78 scoped_ptr<ImageSkia> DeepCopy() const; | 88 scoped_ptr<ImageSkia> DeepCopy() const; |
79 | 89 |
80 // Returns true if this object is backed by the same ImageSkiaStorage as | 90 // Returns true if this object is backed by the same ImageSkiaStorage as |
81 // |other|. Will also return true if both images are isNull(). | 91 // |other|. Will also return true if both images are isNull(). |
82 bool BackedBySameObjectAs(const gfx::ImageSkia& other) const; | 92 bool BackedBySameObjectAs(const gfx::ImageSkia& other) const; |
83 | 93 |
84 // Adds |image_rep| to the image reps contained by this object. | 94 // Adds |image_rep| to the image reps contained by this object. |
85 void AddRepresentation(const gfx::ImageSkiaRep& image_rep); | 95 void AddRepresentation(const gfx::ImageSkiaRep& image_rep); |
86 | 96 |
87 // Removes the image rep of |scale_factor| if present. | 97 // Removes the image rep of |scale| if present. |
88 void RemoveRepresentation(ui::ScaleFactor scale_factor); | 98 void RemoveRepresentation(float scale); |
89 | 99 |
90 // Returns true if the object owns an image rep whose density matches | 100 // Returns true if the object owns an image rep whose density matches |
91 // |scale_factor| exactly. | 101 // |scale| exactly. |
92 bool HasRepresentation(ui::ScaleFactor scale_factor) const; | 102 bool HasRepresentation(float scale) const; |
93 | 103 |
94 // Returns the image rep whose density best matches | 104 // Returns the image rep whose density best matches |scale|. |
95 // |scale_factor|. | |
96 // Returns a null image rep if the object contains no image reps. | 105 // Returns a null image rep if the object contains no image reps. |
97 const gfx::ImageSkiaRep& GetRepresentation( | 106 const gfx::ImageSkiaRep& GetRepresentation(float scale) const; |
98 ui::ScaleFactor scale_factor) const; | |
99 | 107 |
100 // Make the ImageSkia instance read-only. Note that this only prevent | 108 // Make the ImageSkia instance read-only. Note that this only prevent |
101 // modification from client code, and the storage may still be | 109 // modification from client code, and the storage may still be |
102 // modified by the source if any (thus, it's not thread safe). This | 110 // modified by the source if any (thus, it's not thread safe). This |
103 // detaches the storage from currently accessing thread, so its safe | 111 // detaches the storage from currently accessing thread, so its safe |
104 // to pass it to other thread as long as it is accessed only by that | 112 // to pass it to other thread as long as it is accessed only by that |
105 // thread. If this ImageSkia's storage will be accessed by multiple | 113 // thread. If this ImageSkia's storage will be accessed by multiple |
106 // threads, use |MakeThreadSafe()| method. | 114 // threads, use |MakeThreadSafe()| method. |
107 void SetReadOnly(); | 115 void SetReadOnly(); |
108 | 116 |
(...skipping 20 matching lines...) Expand all Loading... |
129 const SkBitmap* bitmap() const { return &GetBitmap(); } | 137 const SkBitmap* bitmap() const { return &GetBitmap(); } |
130 | 138 |
131 // Returns a vector with the image reps contained in this object. | 139 // Returns a vector with the image reps contained in this object. |
132 // There is no guarantee that this will return all images rep for | 140 // There is no guarantee that this will return all images rep for |
133 // supported scale factors. | 141 // supported scale factors. |
134 std::vector<gfx::ImageSkiaRep> image_reps() const; | 142 std::vector<gfx::ImageSkiaRep> image_reps() const; |
135 | 143 |
136 // When the source is available, generates all ImageReps for | 144 // When the source is available, generates all ImageReps for |
137 // supported scale factors. This method is defined as const as | 145 // supported scale factors. This method is defined as const as |
138 // the state change in the storage is agnostic to the caller. | 146 // the state change in the storage is agnostic to the caller. |
139 void EnsureRepsForSupportedScaleFactors() const; | 147 void EnsureRepsForSupportedScales() const; |
140 | 148 |
141 private: | 149 private: |
142 friend class test::TestOnThread; | 150 friend class test::TestOnThread; |
143 FRIEND_TEST_ALL_PREFIXES(ImageSkiaTest, EmptyOnThreadTest); | 151 FRIEND_TEST_ALL_PREFIXES(ImageSkiaTest, EmptyOnThreadTest); |
144 FRIEND_TEST_ALL_PREFIXES(ImageSkiaTest, StaticOnThreadTest); | 152 FRIEND_TEST_ALL_PREFIXES(ImageSkiaTest, StaticOnThreadTest); |
145 FRIEND_TEST_ALL_PREFIXES(ImageSkiaTest, SourceOnThreadTest); | 153 FRIEND_TEST_ALL_PREFIXES(ImageSkiaTest, SourceOnThreadTest); |
146 | 154 |
147 // Initialize ImageSkiaStorage with passed in parameters. | 155 // Initialize ImageSkiaStorage with passed in parameters. |
148 // If the image rep's bitmap is empty, ImageStorage is set to NULL. | 156 // If the image rep's bitmap is empty, ImageStorage is set to NULL. |
149 void Init(const gfx::ImageSkiaRep& image_rep); | 157 void Init(const gfx::ImageSkiaRep& image_rep); |
150 | 158 |
151 SkBitmap& GetBitmap() const; | 159 SkBitmap& GetBitmap() const; |
152 | 160 |
153 // Checks if the current thread can read/modify the ImageSkia. | 161 // Checks if the current thread can read/modify the ImageSkia. |
154 bool CanRead() const; | 162 bool CanRead() const; |
155 bool CanModify() const; | 163 bool CanModify() const; |
156 | 164 |
157 // Detach the storage from the currently assinged thread | 165 // Detach the storage from the currently assinged thread |
158 // so that other thread can access the storage. | 166 // so that other thread can access the storage. |
159 void DetachStorageFromThread(); | 167 void DetachStorageFromThread(); |
160 | 168 |
161 // A refptr so that ImageRepSkia can be copied cheaply. | 169 // A refptr so that ImageRepSkia can be copied cheaply. |
162 scoped_refptr<internal::ImageSkiaStorage> storage_; | 170 scoped_refptr<internal::ImageSkiaStorage> storage_; |
163 }; | 171 }; |
164 | 172 |
165 } // namespace gfx | 173 } // namespace gfx |
166 | 174 |
167 #endif // UI_GFX_IMAGE_IMAGE_SKIA_H_ | 175 #endif // UI_GFX_IMAGE_IMAGE_SKIA_H_ |
OLD | NEW |