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

Side by Side Diff: cc/tiles/software_image_decode_controller.h

Issue 1778673005: cc: ImageDecodes: Remove ref counting from SIDC::DecodedImage. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 9 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
« no previous file with comments | « no previous file | cc/tiles/software_image_decode_controller.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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 CC_TILES_SOFTWARE_IMAGE_DECODE_CONTROLLER_H_ 5 #ifndef CC_TILES_SOFTWARE_IMAGE_DECODE_CONTROLLER_H_
6 #define CC_TILES_SOFTWARE_IMAGE_DECODE_CONTROLLER_H_ 6 #define CC_TILES_SOFTWARE_IMAGE_DECODE_CONTROLLER_H_
7 7
8 #include <stdint.h> 8 #include <stdint.h>
9 9
10 #include <unordered_map> 10 #include <unordered_map>
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
111 111
112 // Decode the given image and store it in the cache. This is only called by an 112 // Decode the given image and store it in the cache. This is only called by an
113 // image decode task from a worker thread. 113 // image decode task from a worker thread.
114 void DecodeImage(const ImageKey& key, const DrawImage& image); 114 void DecodeImage(const ImageKey& key, const DrawImage& image);
115 115
116 void RemovePendingTask(const ImageKey& key); 116 void RemovePendingTask(const ImageKey& key);
117 117
118 private: 118 private:
119 // DecodedImage is a convenience storage for discardable memory. It can also 119 // DecodedImage is a convenience storage for discardable memory. It can also
120 // construct an image out of SkImageInfo and stored discardable memory. 120 // construct an image out of SkImageInfo and stored discardable memory.
121 // TODO(vmpstr): Make this scoped_ptr. 121 class DecodedImage {
122 class DecodedImage : public base::RefCounted<DecodedImage> {
123 public: 122 public:
124 DecodedImage(const SkImageInfo& info, 123 DecodedImage(const SkImageInfo& info,
125 scoped_ptr<base::DiscardableMemory> memory, 124 scoped_ptr<base::DiscardableMemory> memory,
126 const SkSize& src_rect_offset); 125 const SkSize& src_rect_offset);
126 ~DecodedImage();
127 127
128 SkImage* image() const { 128 SkImage* image() const {
129 DCHECK(locked_); 129 DCHECK(locked_);
130 return image_.get(); 130 return image_.get();
131 } 131 }
132 132
133 const SkSize& src_rect_offset() const { return src_rect_offset_; } 133 const SkSize& src_rect_offset() const { return src_rect_offset_; }
134 134
135 bool is_locked() const { return locked_; } 135 bool is_locked() const { return locked_; }
136 bool Lock(); 136 bool Lock();
137 void Unlock(); 137 void Unlock();
138 138
139 private: 139 private:
140 friend class base::RefCounted<DecodedImage>;
141
142 ~DecodedImage();
143
144 bool locked_; 140 bool locked_;
145 SkImageInfo image_info_; 141 SkImageInfo image_info_;
146 scoped_ptr<base::DiscardableMemory> memory_; 142 scoped_ptr<base::DiscardableMemory> memory_;
147 skia::RefPtr<SkImage> image_; 143 skia::RefPtr<SkImage> image_;
148 SkSize src_rect_offset_; 144 SkSize src_rect_offset_;
149 }; 145 };
150 146
151 // MemoryBudget is a convenience class for memory bookkeeping and ensuring 147 // MemoryBudget is a convenience class for memory bookkeeping and ensuring
152 // that we don't go over the limit when pre-decoding. 148 // that we don't go over the limit when pre-decoding.
153 // TODO(vmpstr): Add memory infra to keep track of memory usage of this class. 149 // TODO(vmpstr): Add memory infra to keep track of memory usage of this class.
(...skipping 14 matching lines...) Expand all
168 }; 164 };
169 165
170 // Looks for the key in the cache and returns true if it was found and was 166 // Looks for the key in the cache and returns true if it was found and was
171 // successfully locked (or if it was already locked). Note that if this 167 // successfully locked (or if it was already locked). Note that if this
172 // function returns true, then a ref count is increased for the image. 168 // function returns true, then a ref count is increased for the image.
173 bool LockDecodedImageIfPossibleAndRef(const ImageKey& key); 169 bool LockDecodedImageIfPossibleAndRef(const ImageKey& key);
174 170
175 // Actually decode the image. Note that this function can (and should) be 171 // Actually decode the image. Note that this function can (and should) be
176 // called with no lock acquired, since it can do a lot of work. Note that it 172 // called with no lock acquired, since it can do a lot of work. Note that it
177 // can also return nullptr to indicate the decode failed. 173 // can also return nullptr to indicate the decode failed.
178 scoped_refptr<DecodedImage> DecodeImageInternal(const ImageKey& key, 174 scoped_ptr<DecodedImage> DecodeImageInternal(const ImageKey& key,
179 const DrawImage& draw_image); 175 const DrawImage& draw_image);
180 176
181 // Get the decoded draw image for the given key and draw_image. Note that this 177 // Get the decoded draw image for the given key and draw_image. Note that this
182 // function has to be called with no lock acquired, since it will acquire its 178 // function has to be called with no lock acquired, since it will acquire its
183 // own locks and might call DecodeImageInternal above. Also note that this 179 // own locks and might call DecodeImageInternal above. Also note that this
184 // function will use the provided key, even if 180 // function will use the provided key, even if
185 // ImageKey::FromDrawImage(draw_image) would return a different key. 181 // ImageKey::FromDrawImage(draw_image) would return a different key.
186 // Note that when used internally, we still require that 182 // Note that when used internally, we still require that
187 // DrawWithImageFinished() is called afterwards. 183 // DrawWithImageFinished() is called afterwards.
188 DecodedDrawImage GetDecodedImageForDrawInternal(const ImageKey& key, 184 DecodedDrawImage GetDecodedImageForDrawInternal(const ImageKey& key,
189 const DrawImage& draw_image); 185 const DrawImage& draw_image);
(...skipping 10 matching lines...) Expand all
200 // more of them. 196 // more of them.
201 bool CanHandleImage(const ImageKey& key); 197 bool CanHandleImage(const ImageKey& key);
202 198
203 std::unordered_map<ImageKey, scoped_refptr<ImageDecodeTask>, ImageKeyHash> 199 std::unordered_map<ImageKey, scoped_refptr<ImageDecodeTask>, ImageKeyHash>
204 pending_image_tasks_; 200 pending_image_tasks_;
205 201
206 // The members below this comment can only be accessed if the lock is held to 202 // The members below this comment can only be accessed if the lock is held to
207 // ensure that they are safe to access on multiple threads. 203 // ensure that they are safe to access on multiple threads.
208 base::Lock lock_; 204 base::Lock lock_;
209 205
210 using ImageMRUCache = base::HashingMRUCache<ImageKey, 206 using ImageMRUCache =
211 scoped_refptr<DecodedImage>, 207 base::HashingMRUCache<ImageKey, scoped_ptr<DecodedImage>, ImageKeyHash>;
212 ImageKeyHash>;
213 208
214 // Decoded images and ref counts (predecode path). 209 // Decoded images and ref counts (predecode path).
215 ImageMRUCache decoded_images_; 210 ImageMRUCache decoded_images_;
216 std::unordered_map<ImageKey, int, ImageKeyHash> decoded_images_ref_counts_; 211 std::unordered_map<ImageKey, int, ImageKeyHash> decoded_images_ref_counts_;
217 212
218 // Decoded image and ref counts (at-raster decode path). 213 // Decoded image and ref counts (at-raster decode path).
219 ImageMRUCache at_raster_decoded_images_; 214 ImageMRUCache at_raster_decoded_images_;
220 std::unordered_map<ImageKey, int, ImageKeyHash> 215 std::unordered_map<ImageKey, int, ImageKeyHash>
221 at_raster_decoded_images_ref_counts_; 216 at_raster_decoded_images_ref_counts_;
222 217
223 MemoryBudget locked_images_budget_; 218 MemoryBudget locked_images_budget_;
224 219
225 // Note that this is used for cases where the only thing we do is preroll the 220 // Note that this is used for cases where the only thing we do is preroll the
226 // image the first time we see it. This mimics the previous behavior and 221 // image the first time we see it. This mimics the previous behavior and
227 // should over time change as the compositor starts to handle more cases. 222 // should over time change as the compositor starts to handle more cases.
228 std::unordered_set<uint32_t> prerolled_images_; 223 std::unordered_set<uint32_t> prerolled_images_;
229 }; 224 };
230 225
231 } // namespace cc 226 } // namespace cc
232 227
233 #endif // CC_TILES_SOFTWARE_IMAGE_DECODE_CONTROLLER_H_ 228 #endif // CC_TILES_SOFTWARE_IMAGE_DECODE_CONTROLLER_H_
OLDNEW
« no previous file with comments | « no previous file | cc/tiles/software_image_decode_controller.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698