Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(15)

Side by Side Diff: ui/gfx/image/image_skia.h

Issue 10820049: Load 2x resources on demand (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: For preview Created 8 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 19 matching lines...) Expand all
30 // ImageSkia is cheap to copy and intentionally supports copy semantics. 30 // ImageSkia is cheap to copy and intentionally supports copy semantics.
31 class UI_EXPORT ImageSkia { 31 class UI_EXPORT ImageSkia {
32 public: 32 public:
33 typedef std::vector<ImageSkiaRep> ImageSkiaReps; 33 typedef std::vector<ImageSkiaRep> ImageSkiaReps;
34 34
35 // Creates an instance with no bitmaps. 35 // Creates an instance with no bitmaps.
36 ImageSkia(); 36 ImageSkia();
37 37
38 // Creates an instance that will use the |source| to get the image 38 // Creates an instance that will use the |source| to get the image
39 // for scale factors. |size| specifes the size of the image in DIP. 39 // for scale factors. |size| specifes the size of the image in DIP.
40 // ImageSkia owns |source|.
40 ImageSkia(ImageSkiaSource* source, const gfx::Size& size); 41 ImageSkia(ImageSkiaSource* source, const gfx::Size& size);
41 42
42 // Adds ref to passed in bitmap. 43 // Adds ref to passed in bitmap.
43 // DIP width and height are set based on scale factor of 1x. 44 // DIP width and height are set based on scale factor of 1x.
44 // TODO(pkotwicz): This is temporary till conversion to gfx::ImageSkia is 45 // TODO(pkotwicz): This is temporary till conversion to gfx::ImageSkia is
45 // done. 46 // done.
46 ImageSkia(const SkBitmap& bitmap); 47 ImageSkia(const SkBitmap& bitmap);
47 48
48 ImageSkia(const gfx::ImageSkiaRep& image_rep); 49 ImageSkia(const gfx::ImageSkiaRep& image_rep);
49 50
(...skipping 12 matching lines...) Expand all
62 63
63 #if defined(OS_WIN) 64 #if defined(OS_WIN)
64 // Converts to gfx::ImageSkiaRep and SkBitmap. 65 // Converts to gfx::ImageSkiaRep and SkBitmap.
65 // TODO(pkotwicz): This is temporary till conversion to gfx::ImageSkia is 66 // TODO(pkotwicz): This is temporary till conversion to gfx::ImageSkia is
66 // done. 67 // done.
67 operator SkBitmap&() const { return GetBitmap(); } 68 operator SkBitmap&() const { return GetBitmap(); }
68 #endif 69 #endif
69 70
70 ~ImageSkia(); 71 ~ImageSkia();
71 72
73 // Returns a deep copy of this ImageSkia which has its own storage with
74 // the same ImageSkiaRep instances. This can be safely passed to and
75 // manipulated by another thread.
76 ImageSkia DeepCopy() const;
77
72 // Returns true if this object is backed by the same ImageSkiaStorage as 78 // Returns true if this object is backed by the same ImageSkiaStorage as
73 // |other|. Will also return true if both images are isNull(). 79 // |other|. Will also return true if both images are isNull().
74 bool BackedBySameObjectAs(const gfx::ImageSkia& other) const; 80 bool BackedBySameObjectAs(const gfx::ImageSkia& other) const;
75 81
76 // Adds |image_rep| to the image reps contained by this object. 82 // Adds |image_rep| to the image reps contained by this object.
77 void AddRepresentation(const gfx::ImageSkiaRep& image_rep); 83 void AddRepresentation(const gfx::ImageSkiaRep& image_rep);
78 84
79 // Removes the image rep of |scale_factor| if present. 85 // Removes the image rep of |scale_factor| if present.
80 void RemoveRepresentation(ui::ScaleFactor scale_factor); 86 void RemoveRepresentation(ui::ScaleFactor scale_factor);
81 87
82 // Returns true if the object owns an image rep whose density matches 88 // Returns true if the object owns an image rep whose density matches
83 // |scale_factor| exactly. 89 // |scale_factor| exactly.
84 bool HasRepresentation(ui::ScaleFactor scale_factor) const; 90 bool HasRepresentation(ui::ScaleFactor scale_factor) const;
85 91
86 // Returns the image rep whose density best matches 92 // Returns the image rep whose density best matches
87 // |scale_factor|. 93 // |scale_factor|.
88 // Returns a null image rep if the object contains no image reps. 94 // Returns a null image rep if the object contains no image reps.
89 const gfx::ImageSkiaRep& GetRepresentation( 95 const gfx::ImageSkiaRep& GetRepresentation(
90 ui::ScaleFactor scale_factor) const; 96 ui::ScaleFactor scale_factor) const;
91 97
92 #if defined(OS_MACOSX) 98 #if defined(OS_MACOSX)
93 // Returns the image reps contained by this object. 99 // Returns the image reps contained by this object.
94 // If the image has a source, this method will attempt to generate 100 // If the image has a source, this method will attempt to generate
95 // representations from the source for all supported scale factors. 101 // representations from the source for all supported scale factors.
96 // Mac only for now. 102 // Mac only for now.
97 std::vector<ImageSkiaRep> GetRepresentations() const; 103 std::vector<ImageSkiaRep> GetRepresentations() const;
98 #endif // OS_MACOSX 104 #endif // OS_MACOSX
99 105
106 // Make the image skia read only. Once it becomes read only,
107 // it can be safely accessed by any threads.
108 void SetReadOnly();
109 bool IsReadOnly() const;
110
100 // Returns true if this is a null object. 111 // Returns true if this is a null object.
101 // TODO(pkotwicz): Merge this function into empty(). 112 // TODO(pkotwicz): Merge this function into empty().
102 bool isNull() const { return storage_ == NULL; } 113 bool isNull() const { return storage_ == NULL; }
103 114
104 // Width and height of image in DIP coordinate system. 115 // Width and height of image in DIP coordinate system.
105 int width() const; 116 int width() const;
106 int height() const; 117 int height() const;
107 gfx::Size size() const; 118 gfx::Size size() const;
108 119
109 // Returns pointer to 1x bitmap contained by this object. If there is no 1x 120 // Returns pointer to 1x bitmap contained by this object. If there is no 1x
110 // bitmap, the bitmap whose scale factor is closest to 1x is returned. 121 // bitmap, the bitmap whose scale factor is closest to 1x is returned.
111 // This function should only be used in unittests and on platforms which do 122 // This function should only be used in unittests and on platforms which do
112 // not support scale factors other than 1x. 123 // not support scale factors other than 1x.
113 // TODO(pkotwicz): Return null SkBitmap when the object has no 1x bitmap. 124 // TODO(pkotwicz): Return null SkBitmap when the object has no 1x bitmap.
114 const SkBitmap* bitmap() const { return &GetBitmap(); } 125 const SkBitmap* bitmap() const { return &GetBitmap(); }
115 126
116 // Returns a vector with the image reps contained in this object. 127 // Returns a vector with the image reps contained in this object.
117 // There is no guarantee that this will return all images rep for 128 // There is no guarantee that this will return all images rep for
118 // supported scale factors. 129 // supported scale factors.
119 // TODO(oshima): Update all use of this API and make this to fail 130 // TODO(oshima): Update all use of this API and make this to fail
120 // when source is used. 131 // when source is used.
121 std::vector<gfx::ImageSkiaRep> image_reps() const; 132 std::vector<gfx::ImageSkiaRep> image_reps() const;
122 133
134 // Delete the ImageSkiaSource if any. It will make GetRepresentation
135 // thread safe because it will no longer update the storage.
136 void DeleteSource();
137
138 // When the source is available, generates all ImageReps for
139 // supported scale factors. This method is defined as const as
140 // the state change in the storage is agnostic to the caller.
141 void EnsureRepsForSupportedScaleFactors() const;
142
123 private: 143 private:
124 // Initialize ImageSkiaStorage with passed in parameters. 144 // Initialize ImageSkiaStorage with passed in parameters.
125 // If the image rep's bitmap is empty, ImageStorage is set to NULL. 145 // If the image rep's bitmap is empty, ImageStorage is set to NULL.
126 void Init(const gfx::ImageSkiaRep& image_rep); 146 void Init(const gfx::ImageSkiaRep& image_rep);
127 147
128 SkBitmap& GetBitmap() const; 148 SkBitmap& GetBitmap() const;
129 149
130 // A refptr so that ImageRepSkia can be copied cheaply. 150 // A refptr so that ImageRepSkia can be copied cheaply.
131 scoped_refptr<internal::ImageSkiaStorage> storage_; 151 scoped_refptr<internal::ImageSkiaStorage> storage_;
132 }; 152 };
133 153
134 } // namespace gfx 154 } // namespace gfx
135 155
136 #endif // UI_GFX_IMAGE_IMAGE_SKIA_H_ 156 #endif // UI_GFX_IMAGE_IMAGE_SKIA_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698