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_IMAGE_CONTROLLER_H_ | 5 #ifndef CC_TILES_IMAGE_CONTROLLER_H_ |
6 #define CC_TILES_IMAGE_CONTROLLER_H_ | 6 #define CC_TILES_IMAGE_CONTROLLER_H_ |
7 | 7 |
8 #include <set> | 8 #include <set> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
49 virtual void UnlockImageDecode(ImageDecodeRequestId id); | 49 virtual void UnlockImageDecode(ImageDecodeRequestId id); |
50 | 50 |
51 // This function requests that the given image be decoded and locked. Once the | 51 // This function requests that the given image be decoded and locked. Once the |
52 // callback has been issued, it is passed an ID, which should be used to | 52 // callback has been issued, it is passed an ID, which should be used to |
53 // unlock this image. It is up to the caller to ensure that the image is later | 53 // unlock this image. It is up to the caller to ensure that the image is later |
54 // unlocked using UnlockImageDecode. | 54 // unlocked using UnlockImageDecode. |
55 // Virtual for testing. | 55 // Virtual for testing. |
56 virtual ImageDecodeRequestId QueueImageDecode( | 56 virtual ImageDecodeRequestId QueueImageDecode( |
57 sk_sp<const SkImage> image, | 57 sk_sp<const SkImage> image, |
58 const ImageDecodedCallback& callback); | 58 const ImageDecodedCallback& callback); |
| 59 size_t image_cache_max_limit_bytes() const { |
| 60 return image_cache_max_limit_bytes_; |
| 61 } |
| 62 |
| 63 void SetMaxImageCacheLimitBytesForTesting(size_t bytes) { |
| 64 image_cache_max_limit_bytes_ = bytes; |
| 65 } |
59 | 66 |
60 protected: | 67 protected: |
61 scoped_refptr<base::SequencedTaskRunner> worker_task_runner_; | 68 scoped_refptr<base::SequencedTaskRunner> worker_task_runner_; |
62 | 69 |
63 private: | 70 private: |
64 struct ImageDecodeRequest { | 71 struct ImageDecodeRequest { |
65 ImageDecodeRequest(); | 72 ImageDecodeRequest(); |
66 ImageDecodeRequest(ImageDecodeRequestId id, | 73 ImageDecodeRequest(ImageDecodeRequestId id, |
67 const DrawImage& draw_image, | 74 const DrawImage& draw_image, |
68 const ImageDecodedCallback& callback, | 75 const ImageDecodedCallback& callback, |
(...skipping 21 matching lines...) Expand all Loading... |
90 void ImageDecodeCompleted(ImageDecodeRequestId id); | 97 void ImageDecodeCompleted(ImageDecodeRequestId id); |
91 void GenerateTasksForOrphanedRequests(); | 98 void GenerateTasksForOrphanedRequests(); |
92 | 99 |
93 ImageDecodeCache* cache_ = nullptr; | 100 ImageDecodeCache* cache_ = nullptr; |
94 std::vector<DrawImage> predecode_locked_images_; | 101 std::vector<DrawImage> predecode_locked_images_; |
95 | 102 |
96 static ImageDecodeRequestId s_next_image_decode_queue_id_; | 103 static ImageDecodeRequestId s_next_image_decode_queue_id_; |
97 base::flat_map<ImageDecodeRequestId, DrawImage> requested_locked_images_; | 104 base::flat_map<ImageDecodeRequestId, DrawImage> requested_locked_images_; |
98 | 105 |
99 base::SequencedTaskRunner* origin_task_runner_ = nullptr; | 106 base::SequencedTaskRunner* origin_task_runner_ = nullptr; |
| 107 size_t image_cache_max_limit_bytes_ = 0u; |
100 | 108 |
101 // The variables defined below this lock (aside from weak_ptr_factory_) can | 109 // The variables defined below this lock (aside from weak_ptr_factory_) can |
102 // only be accessed when the lock is acquired. | 110 // only be accessed when the lock is acquired. |
103 base::Lock lock_; | 111 base::Lock lock_; |
104 std::map<ImageDecodeRequestId, ImageDecodeRequest> image_decode_queue_; | 112 std::map<ImageDecodeRequestId, ImageDecodeRequest> image_decode_queue_; |
105 std::map<ImageDecodeRequestId, ImageDecodeRequest> | 113 std::map<ImageDecodeRequestId, ImageDecodeRequest> |
106 requests_needing_completion_; | 114 requests_needing_completion_; |
107 bool abort_tasks_ = false; | 115 bool abort_tasks_ = false; |
108 // Orphaned requests are requests that were either in queue or needed a | 116 // Orphaned requests are requests that were either in queue or needed a |
109 // completion callback when we set the decode cache to be nullptr. When a new | 117 // completion callback when we set the decode cache to be nullptr. When a new |
110 // decode cache is set, these requests are re-enqueued again with tasks | 118 // decode cache is set, these requests are re-enqueued again with tasks |
111 // generated by the new cache. Note that when the cache is set, then aside | 119 // generated by the new cache. Note that when the cache is set, then aside |
112 // from generating new tasks, this vector should be empty. | 120 // from generating new tasks, this vector should be empty. |
113 std::vector<ImageDecodeRequest> orphaned_decode_requests_; | 121 std::vector<ImageDecodeRequest> orphaned_decode_requests_; |
114 | 122 |
115 base::WeakPtrFactory<ImageController> weak_ptr_factory_; | 123 base::WeakPtrFactory<ImageController> weak_ptr_factory_; |
116 | 124 |
117 DISALLOW_COPY_AND_ASSIGN(ImageController); | 125 DISALLOW_COPY_AND_ASSIGN(ImageController); |
118 }; | 126 }; |
119 | 127 |
120 } // namespace cc | 128 } // namespace cc |
121 | 129 |
122 #endif // CC_TILES_IMAGE_CONTROLLER_H_ | 130 #endif // CC_TILES_IMAGE_CONTROLLER_H_ |
OLD | NEW |