| OLD | NEW |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 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_CHECKER_IMAGE_TRACKER_H_ | 5 #ifndef CC_TILES_CHECKER_IMAGE_TRACKER_H_ |
| 6 #define CC_TILES_CHECKER_IMAGE_TRACKER_H_ | 6 #define CC_TILES_CHECKER_IMAGE_TRACKER_H_ |
| 7 | 7 |
| 8 #include <unordered_map> | 8 #include <unordered_map> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| (...skipping 29 matching lines...) Expand all Loading... |
| 40 // Returns true if the decode for |image| will be deferred to the image decode | 40 // Returns true if the decode for |image| will be deferred to the image decode |
| 41 // service and it should be be skipped during raster. | 41 // service and it should be be skipped during raster. |
| 42 bool ShouldCheckerImage(const sk_sp<const SkImage>& image, WhichTree tree); | 42 bool ShouldCheckerImage(const sk_sp<const SkImage>& image, WhichTree tree); |
| 43 | 43 |
| 44 using ImageDecodeQueue = std::vector<sk_sp<const SkImage>>; | 44 using ImageDecodeQueue = std::vector<sk_sp<const SkImage>>; |
| 45 void ScheduleImageDecodeQueue(ImageDecodeQueue image_decode_queue); | 45 void ScheduleImageDecodeQueue(ImageDecodeQueue image_decode_queue); |
| 46 | 46 |
| 47 // Returns the set of images to invalidate on the sync tree. | 47 // Returns the set of images to invalidate on the sync tree. |
| 48 const ImageIdFlatSet& TakeImagesToInvalidateOnSyncTree(); | 48 const ImageIdFlatSet& TakeImagesToInvalidateOnSyncTree(); |
| 49 | 49 |
| 50 // Called when the sync tree is activated. Each call to |
| 51 // TakeImagesToInvalidateOnSyncTree() must be followed by this when the |
| 52 // invalidated sync tree is activated. |
| 50 void DidActivateSyncTree(); | 53 void DidActivateSyncTree(); |
| 51 | 54 |
| 55 // Called to reset the tracker state on navigation. This will release all |
| 56 // cached images. Setting |can_clear_decode_policy_tracking| will also result |
| 57 // in re-checkering any images already decoded by the tracker. |
| 58 void ClearTracker(bool can_clear_decode_policy_tracking); |
| 59 |
| 52 private: | 60 private: |
| 53 enum class DecodePolicy { | 61 enum class DecodePolicy { |
| 54 // The image can be decoded asynchronously from raster. When set, the image | 62 // The image can be decoded asynchronously from raster. When set, the image |
| 55 // is always skipped during rasterization of content that includes this | 63 // is always skipped during rasterization of content that includes this |
| 56 // image until it has been decoded using the decode service. | 64 // image until it has been decoded using the decode service. |
| 57 ASYNC, | 65 ASYNC, |
| 58 // The image has been decoded asynchronously once and should now be | 66 // The image has been decoded asynchronously once and should now be |
| 59 // synchronously rasterized with the content. | 67 // synchronously rasterized with the content. |
| 60 SYNC_DECODED_ONCE, | 68 SYNC_DECODED_ONCE, |
| 61 // The image has been permanently vetoed from being decoded async. | 69 // The image has been permanently vetoed from being decoded async. |
| 62 SYNC_PERMANENT, | 70 SYNC_PERMANENT, |
| 63 }; | 71 }; |
| 64 | 72 |
| 73 // Wrapper to unlock an image decode requested from the ImageController on |
| 74 // destruction. |
| 75 class ScopedDecodeHolder { |
| 76 public: |
| 77 ScopedDecodeHolder(ImageController* controller, |
| 78 ImageController::ImageDecodeRequestId request_id) |
| 79 : controller_(controller), request_id_(request_id) {} |
| 80 ~ScopedDecodeHolder() { controller_->UnlockImageDecode(request_id_); } |
| 81 |
| 82 private: |
| 83 ImageController* controller_; |
| 84 ImageController::ImageDecodeRequestId request_id_; |
| 85 |
| 86 DISALLOW_COPY_AND_ASSIGN(ScopedDecodeHolder); |
| 87 }; |
| 88 |
| 65 void DidFinishImageDecode(ImageId image_id, | 89 void DidFinishImageDecode(ImageId image_id, |
| 66 ImageController::ImageDecodeRequestId request_id, | 90 ImageController::ImageDecodeRequestId request_id, |
| 67 ImageController::ImageDecodeResult result); | 91 ImageController::ImageDecodeResult result); |
| 68 | 92 |
| 69 // Called when the next request in the |image_decode_queue_| should be | 93 // Called when the next request in the |image_decode_queue_| should be |
| 70 // scheduled with the image decode service. | 94 // scheduled with the image decode service. |
| 71 void ScheduleNextImageDecode(); | 95 void ScheduleNextImageDecode(); |
| 72 | 96 |
| 73 ImageController* image_controller_; | 97 ImageController* image_controller_; |
| 74 CheckerImageTrackerClient* client_; | 98 CheckerImageTrackerClient* client_; |
| 75 const bool enable_checker_imaging_; | 99 const bool enable_checker_imaging_; |
| 76 | 100 |
| 77 // A set of images which have been decoded and are pending invalidation for | 101 // A set of images which have been decoded and are pending invalidation for |
| 78 // raster on the checkered tiles. | 102 // raster on the checkered tiles. |
| 79 ImageIdFlatSet images_pending_invalidation_; | 103 ImageIdFlatSet images_pending_invalidation_; |
| 80 | 104 |
| 81 // A set of images which were invalidated on the current sync tree. | 105 // A set of images which were invalidated on the current sync tree. |
| 82 ImageIdFlatSet invalidated_images_on_current_sync_tree_; | 106 ImageIdFlatSet invalidated_images_on_current_sync_tree_; |
| 83 | 107 |
| 84 // The queue of images pending decode. We maintain a queue to ensure that the | 108 // The queue of images pending decode. We maintain a queue to ensure that the |
| 85 // order in which images are decoded is aligned with the priority of the tiles | 109 // order in which images are decoded is aligned with the priority of the tiles |
| 86 // dependent on these images. | 110 // dependent on these images. |
| 87 ImageDecodeQueue image_decode_queue_; | 111 ImageDecodeQueue image_decode_queue_; |
| 88 | 112 |
| 89 // The currently outstanding image decode that has been scheduled with the | 113 // The currently outstanding image decode that has been scheduled with the |
| 90 // decode service. There can be only one outstanding decode at a time. | 114 // decode service. There can be only one outstanding decode at a time. |
| 91 sk_sp<const SkImage> outstanding_image_decode_; | 115 sk_sp<const SkImage> outstanding_image_decode_; |
| 92 | 116 |
| 93 // A map of ImageId to its DecodePolicy. | 117 // A map of ImageId to its DecodePolicy. |
| 94 // TODO(khushalsagar): Limit the size of this set. | |
| 95 // TODO(khushalsagar): Plumb navigation changes here to reset this. See | |
| 96 // crbug.com/693228. | |
| 97 std::unordered_map<ImageId, DecodePolicy> image_async_decode_state_; | 118 std::unordered_map<ImageId, DecodePolicy> image_async_decode_state_; |
| 98 | 119 |
| 99 // A map of image id to image decode request id for images to be unlocked. | 120 // A map of image id to image decode request id for images to be unlocked. |
| 100 std::unordered_map<ImageId, ImageController::ImageDecodeRequestId> | 121 std::unordered_map<ImageId, std::unique_ptr<ScopedDecodeHolder>> |
| 101 image_id_to_decode_request_id_; | 122 image_id_to_decode_; |
| 102 | 123 |
| 103 base::WeakPtrFactory<CheckerImageTracker> weak_factory_; | 124 base::WeakPtrFactory<CheckerImageTracker> weak_factory_; |
| 104 }; | 125 }; |
| 105 | 126 |
| 106 } // namespace cc | 127 } // namespace cc |
| 107 | 128 |
| 108 #endif // CC_TILES_CHECKER_IMAGE_TRACKER_H_ | 129 #endif // CC_TILES_CHECKER_IMAGE_TRACKER_H_ |
| OLD | NEW |