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 |
| 11 #include "base/optional.h" |
11 #include "cc/cc_export.h" | 12 #include "cc/cc_export.h" |
12 #include "cc/paint/image_id.h" | 13 #include "cc/paint/image_id.h" |
13 #include "cc/tiles/image_controller.h" | 14 #include "cc/tiles/image_controller.h" |
14 #include "third_party/skia/include/core/SkImage.h" | 15 #include "third_party/skia/include/core/SkImage.h" |
15 | 16 |
16 namespace cc { | 17 namespace cc { |
17 | 18 |
18 class CC_EXPORT CheckerImageTrackerClient { | 19 class CC_EXPORT CheckerImageTrackerClient { |
19 public: | 20 public: |
20 virtual ~CheckerImageTrackerClient() = default; | 21 virtual ~CheckerImageTrackerClient() = default; |
(...skipping 11 matching lines...) Expand all Loading... |
32 // sync tree until the previous tree is activated. | 33 // sync tree until the previous tree is activated. |
33 class CC_EXPORT CheckerImageTracker { | 34 class CC_EXPORT CheckerImageTracker { |
34 public: | 35 public: |
35 CheckerImageTracker(ImageController* image_controller, | 36 CheckerImageTracker(ImageController* image_controller, |
36 CheckerImageTrackerClient* client, | 37 CheckerImageTrackerClient* client, |
37 bool enable_checker_imaging); | 38 bool enable_checker_imaging); |
38 ~CheckerImageTracker(); | 39 ~CheckerImageTracker(); |
39 | 40 |
40 // Returns true if the decode for |image| will be deferred to the image decode | 41 // Returns true if the decode for |image| will be deferred to the image decode |
41 // service and it should be be skipped during raster. | 42 // service and it should be be skipped during raster. |
42 bool ShouldCheckerImage(const sk_sp<const SkImage>& image, WhichTree tree); | 43 bool ShouldCheckerImage(const PaintImage& image, WhichTree tree); |
43 | 44 |
44 using ImageDecodeQueue = std::vector<sk_sp<const SkImage>>; | 45 using ImageDecodeQueue = std::vector<PaintImage>; |
45 void ScheduleImageDecodeQueue(ImageDecodeQueue image_decode_queue); | 46 void ScheduleImageDecodeQueue(ImageDecodeQueue image_decode_queue); |
46 | 47 |
47 // Returns the set of images to invalidate on the sync tree. | 48 // Returns the set of images to invalidate on the sync tree. |
48 const ImageIdFlatSet& TakeImagesToInvalidateOnSyncTree(); | 49 const PaintImageIdFlatSet& TakeImagesToInvalidateOnSyncTree(); |
49 | 50 |
50 void DidActivateSyncTree(); | 51 void DidActivateSyncTree(); |
51 | 52 |
52 private: | 53 private: |
53 enum class DecodePolicy { | 54 enum class DecodePolicy { |
54 // The image can be decoded asynchronously from raster. When set, the image | 55 // The image can be decoded asynchronously from raster. When set, the image |
55 // is always skipped during rasterization of content that includes this | 56 // is always skipped during rasterization of content that includes this |
56 // image until it has been decoded using the decode service. | 57 // image until it has been decoded using the decode service. |
57 ASYNC, | 58 ASYNC, |
58 // The image has been decoded asynchronously once and should now be | 59 // The image has been decoded asynchronously once and should now be |
59 // synchronously rasterized with the content. | 60 // synchronously rasterized with the content. |
60 SYNC_DECODED_ONCE, | 61 SYNC_DECODED_ONCE, |
61 // The image has been permanently vetoed from being decoded async. | 62 // The image has been permanently vetoed from being decoded async. |
62 SYNC_PERMANENT, | 63 SYNC_PERMANENT, |
63 }; | 64 }; |
64 | 65 |
65 void DidFinishImageDecode(ImageId image_id, | 66 void DidFinishImageDecode(PaintImage::Id image_id, |
66 ImageController::ImageDecodeRequestId request_id, | 67 ImageController::ImageDecodeRequestId request_id, |
67 ImageController::ImageDecodeResult result); | 68 ImageController::ImageDecodeResult result); |
68 | 69 |
69 // Called when the next request in the |image_decode_queue_| should be | 70 // Called when the next request in the |image_decode_queue_| should be |
70 // scheduled with the image decode service. | 71 // scheduled with the image decode service. |
71 void ScheduleNextImageDecode(); | 72 void ScheduleNextImageDecode(); |
72 | 73 |
73 ImageController* image_controller_; | 74 ImageController* image_controller_; |
74 CheckerImageTrackerClient* client_; | 75 CheckerImageTrackerClient* client_; |
75 const bool enable_checker_imaging_; | 76 const bool enable_checker_imaging_; |
76 | 77 |
77 // A set of images which have been decoded and are pending invalidation for | 78 // A set of images which have been decoded and are pending invalidation for |
78 // raster on the checkered tiles. | 79 // raster on the checkered tiles. |
79 ImageIdFlatSet images_pending_invalidation_; | 80 PaintImageIdFlatSet images_pending_invalidation_; |
80 | 81 |
81 // A set of images which were invalidated on the current sync tree. | 82 // A set of images which were invalidated on the current sync tree. |
82 ImageIdFlatSet invalidated_images_on_current_sync_tree_; | 83 PaintImageIdFlatSet invalidated_images_on_current_sync_tree_; |
83 | 84 |
84 // The queue of images pending decode. We maintain a queue to ensure that the | 85 // 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 | 86 // order in which images are decoded is aligned with the priority of the tiles |
86 // dependent on these images. | 87 // dependent on these images. |
87 ImageDecodeQueue image_decode_queue_; | 88 ImageDecodeQueue image_decode_queue_; |
88 | 89 |
89 // The currently outstanding image decode that has been scheduled with the | 90 // The currently outstanding image decode that has been scheduled with the |
90 // decode service. There can be only one outstanding decode at a time. | 91 // decode service. There can be only one outstanding decode at a time. |
91 sk_sp<const SkImage> outstanding_image_decode_; | 92 base::Optional<PaintImage> outstanding_image_decode_; |
92 | 93 |
93 // A map of ImageId to its DecodePolicy. | 94 // A map of ImageId to its DecodePolicy. |
94 // TODO(khushalsagar): Limit the size of this set. | 95 // TODO(khushalsagar): Limit the size of this set. |
95 // TODO(khushalsagar): Plumb navigation changes here to reset this. See | 96 // TODO(khushalsagar): Plumb navigation changes here to reset this. See |
96 // crbug.com/693228. | 97 // crbug.com/693228. |
97 std::unordered_map<ImageId, DecodePolicy> image_async_decode_state_; | 98 std::unordered_map<PaintImage::Id, DecodePolicy> image_async_decode_state_; |
98 | 99 |
99 // A map of image id to image decode request id for images to be unlocked. | 100 // A map of image id to image decode request id for images to be unlocked. |
100 std::unordered_map<ImageId, ImageController::ImageDecodeRequestId> | 101 std::unordered_map<PaintImage::Id, ImageController::ImageDecodeRequestId> |
101 image_id_to_decode_request_id_; | 102 image_id_to_decode_request_id_; |
102 | 103 |
103 base::WeakPtrFactory<CheckerImageTracker> weak_factory_; | 104 base::WeakPtrFactory<CheckerImageTracker> weak_factory_; |
104 }; | 105 }; |
105 | 106 |
106 } // namespace cc | 107 } // namespace cc |
107 | 108 |
108 #endif // CC_TILES_CHECKER_IMAGE_TRACKER_H_ | 109 #endif // CC_TILES_CHECKER_IMAGE_TRACKER_H_ |
OLD | NEW |