| OLD | NEW |
| 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 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 117 void DecodeImage(const ImageKey& key, const DrawImage& image); | 117 void DecodeImage(const ImageKey& key, const DrawImage& image); |
| 118 | 118 |
| 119 void RemovePendingTask(const ImageKey& key); | 119 void RemovePendingTask(const ImageKey& key); |
| 120 | 120 |
| 121 private: | 121 private: |
| 122 // DecodedImage is a convenience storage for discardable memory. It can also | 122 // DecodedImage is a convenience storage for discardable memory. It can also |
| 123 // construct an image out of SkImageInfo and stored discardable memory. | 123 // construct an image out of SkImageInfo and stored discardable memory. |
| 124 class DecodedImage { | 124 class DecodedImage { |
| 125 public: | 125 public: |
| 126 DecodedImage(const SkImageInfo& info, | 126 DecodedImage(const SkImageInfo& info, |
| 127 scoped_ptr<base::DiscardableMemory> memory, | 127 std::unique_ptr<base::DiscardableMemory> memory, |
| 128 const SkSize& src_rect_offset); | 128 const SkSize& src_rect_offset); |
| 129 ~DecodedImage(); | 129 ~DecodedImage(); |
| 130 | 130 |
| 131 SkImage* image() const { | 131 SkImage* image() const { |
| 132 DCHECK(locked_); | 132 DCHECK(locked_); |
| 133 return image_.get(); | 133 return image_.get(); |
| 134 } | 134 } |
| 135 | 135 |
| 136 const SkSize& src_rect_offset() const { return src_rect_offset_; } | 136 const SkSize& src_rect_offset() const { return src_rect_offset_; } |
| 137 | 137 |
| 138 bool is_locked() const { return locked_; } | 138 bool is_locked() const { return locked_; } |
| 139 bool Lock(); | 139 bool Lock(); |
| 140 void Unlock(); | 140 void Unlock(); |
| 141 | 141 |
| 142 private: | 142 private: |
| 143 bool locked_; | 143 bool locked_; |
| 144 SkImageInfo image_info_; | 144 SkImageInfo image_info_; |
| 145 scoped_ptr<base::DiscardableMemory> memory_; | 145 std::unique_ptr<base::DiscardableMemory> memory_; |
| 146 skia::RefPtr<SkImage> image_; | 146 skia::RefPtr<SkImage> image_; |
| 147 SkSize src_rect_offset_; | 147 SkSize src_rect_offset_; |
| 148 }; | 148 }; |
| 149 | 149 |
| 150 // MemoryBudget is a convenience class for memory bookkeeping and ensuring | 150 // MemoryBudget is a convenience class for memory bookkeeping and ensuring |
| 151 // that we don't go over the limit when pre-decoding. | 151 // that we don't go over the limit when pre-decoding. |
| 152 // TODO(vmpstr): Add memory infra to keep track of memory usage of this class. | 152 // TODO(vmpstr): Add memory infra to keep track of memory usage of this class. |
| 153 class MemoryBudget { | 153 class MemoryBudget { |
| 154 public: | 154 public: |
| 155 explicit MemoryBudget(size_t limit_bytes); | 155 explicit MemoryBudget(size_t limit_bytes); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 167 }; | 167 }; |
| 168 | 168 |
| 169 // Looks for the key in the cache and returns true if it was found and was | 169 // Looks for the key in the cache and returns true if it was found and was |
| 170 // successfully locked (or if it was already locked). Note that if this | 170 // successfully locked (or if it was already locked). Note that if this |
| 171 // function returns true, then a ref count is increased for the image. | 171 // function returns true, then a ref count is increased for the image. |
| 172 bool LockDecodedImageIfPossibleAndRef(const ImageKey& key); | 172 bool LockDecodedImageIfPossibleAndRef(const ImageKey& key); |
| 173 | 173 |
| 174 // Actually decode the image. Note that this function can (and should) be | 174 // Actually decode the image. Note that this function can (and should) be |
| 175 // called with no lock acquired, since it can do a lot of work. Note that it | 175 // called with no lock acquired, since it can do a lot of work. Note that it |
| 176 // can also return nullptr to indicate the decode failed. | 176 // can also return nullptr to indicate the decode failed. |
| 177 scoped_ptr<DecodedImage> DecodeImageInternal(const ImageKey& key, | 177 std::unique_ptr<DecodedImage> DecodeImageInternal( |
| 178 const DrawImage& draw_image); | 178 const ImageKey& key, |
| 179 const DrawImage& draw_image); |
| 179 | 180 |
| 180 // Get the decoded draw image for the given key and draw_image. Note that this | 181 // Get the decoded draw image for the given key and draw_image. Note that this |
| 181 // function has to be called with no lock acquired, since it will acquire its | 182 // function has to be called with no lock acquired, since it will acquire its |
| 182 // own locks and might call DecodeImageInternal above. Also note that this | 183 // own locks and might call DecodeImageInternal above. Also note that this |
| 183 // function will use the provided key, even if | 184 // function will use the provided key, even if |
| 184 // ImageKey::FromDrawImage(draw_image) would return a different key. | 185 // ImageKey::FromDrawImage(draw_image) would return a different key. |
| 185 // Note that when used internally, we still require that | 186 // Note that when used internally, we still require that |
| 186 // DrawWithImageFinished() is called afterwards. | 187 // DrawWithImageFinished() is called afterwards. |
| 187 DecodedDrawImage GetDecodedImageForDrawInternal(const ImageKey& key, | 188 DecodedDrawImage GetDecodedImageForDrawInternal(const ImageKey& key, |
| 188 const DrawImage& draw_image); | 189 const DrawImage& draw_image); |
| (...skipping 10 matching lines...) Expand all Loading... |
| 199 // more of them. | 200 // more of them. |
| 200 bool CanHandleImage(const ImageKey& key); | 201 bool CanHandleImage(const ImageKey& key); |
| 201 | 202 |
| 202 std::unordered_map<ImageKey, scoped_refptr<ImageDecodeTask>, ImageKeyHash> | 203 std::unordered_map<ImageKey, scoped_refptr<ImageDecodeTask>, ImageKeyHash> |
| 203 pending_image_tasks_; | 204 pending_image_tasks_; |
| 204 | 205 |
| 205 // The members below this comment can only be accessed if the lock is held to | 206 // The members below this comment can only be accessed if the lock is held to |
| 206 // ensure that they are safe to access on multiple threads. | 207 // ensure that they are safe to access on multiple threads. |
| 207 base::Lock lock_; | 208 base::Lock lock_; |
| 208 | 209 |
| 209 using ImageMRUCache = | 210 using ImageMRUCache = base::HashingMRUCache<ImageKey, |
| 210 base::HashingMRUCache<ImageKey, scoped_ptr<DecodedImage>, ImageKeyHash>; | 211 std::unique_ptr<DecodedImage>, |
| 212 ImageKeyHash>; |
| 211 | 213 |
| 212 // Decoded images and ref counts (predecode path). | 214 // Decoded images and ref counts (predecode path). |
| 213 ImageMRUCache decoded_images_; | 215 ImageMRUCache decoded_images_; |
| 214 std::unordered_map<ImageKey, int, ImageKeyHash> decoded_images_ref_counts_; | 216 std::unordered_map<ImageKey, int, ImageKeyHash> decoded_images_ref_counts_; |
| 215 | 217 |
| 216 // Decoded image and ref counts (at-raster decode path). | 218 // Decoded image and ref counts (at-raster decode path). |
| 217 ImageMRUCache at_raster_decoded_images_; | 219 ImageMRUCache at_raster_decoded_images_; |
| 218 std::unordered_map<ImageKey, int, ImageKeyHash> | 220 std::unordered_map<ImageKey, int, ImageKeyHash> |
| 219 at_raster_decoded_images_ref_counts_; | 221 at_raster_decoded_images_ref_counts_; |
| 220 | 222 |
| 221 MemoryBudget locked_images_budget_; | 223 MemoryBudget locked_images_budget_; |
| 222 | 224 |
| 223 // Note that this is used for cases where the only thing we do is preroll the | 225 // Note that this is used for cases where the only thing we do is preroll the |
| 224 // image the first time we see it. This mimics the previous behavior and | 226 // image the first time we see it. This mimics the previous behavior and |
| 225 // should over time change as the compositor starts to handle more cases. | 227 // should over time change as the compositor starts to handle more cases. |
| 226 std::unordered_set<uint32_t> prerolled_images_; | 228 std::unordered_set<uint32_t> prerolled_images_; |
| 227 | 229 |
| 228 ResourceFormat format_; | 230 ResourceFormat format_; |
| 229 }; | 231 }; |
| 230 | 232 |
| 231 } // namespace cc | 233 } // namespace cc |
| 232 | 234 |
| 233 #endif // CC_TILES_SOFTWARE_IMAGE_DECODE_CONTROLLER_H_ | 235 #endif // CC_TILES_SOFTWARE_IMAGE_DECODE_CONTROLLER_H_ |
| OLD | NEW |