| 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 <memory> | 10 #include <memory> |
| (...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 204 // Get the decoded draw image for the given key and draw_image. Note that this | 204 // Get the decoded draw image for the given key and draw_image. Note that this |
| 205 // function has to be called with no lock acquired, since it will acquire its | 205 // function has to be called with no lock acquired, since it will acquire its |
| 206 // own locks and might call DecodeImageInternal above. Also note that this | 206 // own locks and might call DecodeImageInternal above. Also note that this |
| 207 // function will use the provided key, even if | 207 // function will use the provided key, even if |
| 208 // ImageKey::FromDrawImage(draw_image) would return a different key. | 208 // ImageKey::FromDrawImage(draw_image) would return a different key. |
| 209 // Note that when used internally, we still require that | 209 // Note that when used internally, we still require that |
| 210 // DrawWithImageFinished() is called afterwards. | 210 // DrawWithImageFinished() is called afterwards. |
| 211 DecodedDrawImage GetDecodedImageForDrawInternal(const ImageKey& key, | 211 DecodedDrawImage GetDecodedImageForDrawInternal(const ImageKey& key, |
| 212 const DrawImage& draw_image); | 212 const DrawImage& draw_image); |
| 213 | 213 |
| 214 // DecodeImageMediumQuality is called by DecodeImageInternal to get the |
| 215 // decoded and scaled image for medium quality. |
| 216 // Like DecodeImageInternal, it should be called with no lock acquired |
| 217 // and it also returns nullptr if the decoding or scaling failed. |
| 218 std::unique_ptr<DecodedImage> DecodeImageMediumQuality(const ImageKey& key, |
| 219 const SkImage& image); |
| 220 |
| 214 // GetOriginalImageDecode is called by DecodeImageInternal when the quality | 221 // GetOriginalImageDecode is called by DecodeImageInternal when the quality |
| 215 // does not scale the image. Like DecodeImageInternal, it should be called | 222 // does not scale the image. Like DecodeImageInternal, it should be called |
| 216 // with no lock acquired and it returns nullptr if the decoding failed. | 223 // with no lock acquired and it returns nullptr if the decoding failed. |
| 217 std::unique_ptr<DecodedImage> GetOriginalImageDecode(const ImageKey& key, | 224 std::unique_ptr<DecodedImage> GetOriginalImageDecode(const ImageKey& key, |
| 218 const SkImage& image); | 225 const SkImage& image); |
| 219 | 226 |
| 220 // GetScaledImageDecode is called by DecodeImageInternal when the quality | 227 // GetScaledImageDecode is called by DecodeImageInternal when the quality |
| 221 // requires the image be scaled. Like DecodeImageInternal, it should be | 228 // requires the image be scaled. Like DecodeImageInternal, it should be |
| 222 // called with no lock acquired and it returns nullptr if the decoding or | 229 // called with no lock acquired and it returns nullptr if the decoding or |
| 223 // scaling failed. | 230 // scaling failed. |
| 224 std::unique_ptr<DecodedImage> GetScaledImageDecode(const ImageKey& key, | 231 std::unique_ptr<DecodedImage> GetScaledImageDecode(const ImageKey& key, |
| 225 const SkImage& image); | 232 const SkImage& image); |
| 226 | 233 |
| 227 void SanityCheckState(int line, bool lock_acquired); | 234 void SanityCheckState(int line, bool lock_acquired); |
| 228 void RefImage(const ImageKey& key); | 235 void RefImage(const ImageKey& key); |
| 229 void RefAtRasterImage(const ImageKey& key); | 236 void RefAtRasterImage(const ImageKey& key); |
| 230 void UnrefAtRasterImage(const ImageKey& key); | 237 void UnrefAtRasterImage(const ImageKey& key); |
| 231 | 238 |
| 232 // These functions indicate whether the images can be handled and cached by | |
| 233 // ImageDecodeController or whether they will fall through to Skia (with | |
| 234 // exception of possibly prerolling them). Over time these should return | |
| 235 // "false" in less cases, as the ImageDecodeController should start handling | |
| 236 // more of them. | |
| 237 bool CanHandleImage(const ImageKey& key); | |
| 238 | |
| 239 // Helper function which dumps all images in a specific ImageMRUCache. | 239 // Helper function which dumps all images in a specific ImageMRUCache. |
| 240 void DumpImageMemoryForCache(const ImageMRUCache& cache, | 240 void DumpImageMemoryForCache(const ImageMRUCache& cache, |
| 241 const char* cache_name, | 241 const char* cache_name, |
| 242 base::trace_event::ProcessMemoryDump* pmd) const; | 242 base::trace_event::ProcessMemoryDump* pmd) const; |
| 243 | 243 |
| 244 std::unordered_map<ImageKey, scoped_refptr<TileTask>, ImageKeyHash> | 244 std::unordered_map<ImageKey, scoped_refptr<TileTask>, ImageKeyHash> |
| 245 pending_image_tasks_; | 245 pending_image_tasks_; |
| 246 | 246 |
| 247 // The members below this comment can only be accessed if the lock is held to | 247 // The members below this comment can only be accessed if the lock is held to |
| 248 // ensure that they are safe to access on multiple threads. | 248 // ensure that they are safe to access on multiple threads. |
| 249 base::Lock lock_; | 249 base::Lock lock_; |
| 250 | 250 |
| 251 // Decoded images and ref counts (predecode path). | 251 // Decoded images and ref counts (predecode path). |
| 252 ImageMRUCache decoded_images_; | 252 ImageMRUCache decoded_images_; |
| 253 std::unordered_map<ImageKey, int, ImageKeyHash> decoded_images_ref_counts_; | 253 std::unordered_map<ImageKey, int, ImageKeyHash> decoded_images_ref_counts_; |
| 254 | 254 |
| 255 // Decoded image and ref counts (at-raster decode path). | 255 // Decoded image and ref counts (at-raster decode path). |
| 256 ImageMRUCache at_raster_decoded_images_; | 256 ImageMRUCache at_raster_decoded_images_; |
| 257 std::unordered_map<ImageKey, int, ImageKeyHash> | 257 std::unordered_map<ImageKey, int, ImageKeyHash> |
| 258 at_raster_decoded_images_ref_counts_; | 258 at_raster_decoded_images_ref_counts_; |
| 259 | 259 |
| 260 MemoryBudget locked_images_budget_; | 260 MemoryBudget locked_images_budget_; |
| 261 | 261 |
| 262 // Note that this is used for cases where the only thing we do is preroll the | |
| 263 // image the first time we see it. This mimics the previous behavior and | |
| 264 // should over time change as the compositor starts to handle more cases. | |
| 265 std::unordered_set<uint32_t> prerolled_images_; | |
| 266 | |
| 267 ResourceFormat format_; | 262 ResourceFormat format_; |
| 268 | 263 |
| 269 // Used to uniquely identify DecodedImages for memory traces. | 264 // Used to uniquely identify DecodedImages for memory traces. |
| 270 base::AtomicSequenceNumber next_tracing_id_; | 265 base::AtomicSequenceNumber next_tracing_id_; |
| 271 }; | 266 }; |
| 272 | 267 |
| 273 } // namespace cc | 268 } // namespace cc |
| 274 | 269 |
| 275 #endif // CC_TILES_SOFTWARE_IMAGE_DECODE_CONTROLLER_H_ | 270 #endif // CC_TILES_SOFTWARE_IMAGE_DECODE_CONTROLLER_H_ |
| OLD | NEW |