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_GPU_IMAGE_DECODE_CACHE_H_ | 5 #ifndef CC_TILES_GPU_IMAGE_DECODE_CACHE_H_ |
6 #define CC_TILES_GPU_IMAGE_DECODE_CACHE_H_ | 6 #define CC_TILES_GPU_IMAGE_DECODE_CACHE_H_ |
7 | 7 |
8 #include <memory> | 8 #include <memory> |
9 #include <unordered_map> | 9 #include <unordered_map> |
10 #include <vector> | 10 #include <vector> |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
92 // same ImageDatas (and may need to keep these ImageDatas alive independent | 92 // same ImageDatas (and may need to keep these ImageDatas alive independent |
93 // of each other), they hold ImageDatas by scoped_refptr. The scoped_refptr | 93 // of each other), they hold ImageDatas by scoped_refptr. The scoped_refptr |
94 // keeps an ImageData alive while it is present in either the | 94 // keeps an ImageData alive while it is present in either the |
95 // |persistent_cache_| or |in_use_cache_|. | 95 // |persistent_cache_| or |in_use_cache_|. |
96 // | 96 // |
97 class CC_EXPORT GpuImageDecodeCache | 97 class CC_EXPORT GpuImageDecodeCache |
98 : public ImageDecodeCache, | 98 : public ImageDecodeCache, |
99 public base::trace_event::MemoryDumpProvider, | 99 public base::trace_event::MemoryDumpProvider, |
100 public base::MemoryCoordinatorClient { | 100 public base::MemoryCoordinatorClient { |
101 public: | 101 public: |
102 enum class DecodeTaskType { PART_OF_UPLOAD_TASK, STAND_ALONE_DECODE_TASK }; | |
103 | |
104 explicit GpuImageDecodeCache(ContextProvider* context, | 102 explicit GpuImageDecodeCache(ContextProvider* context, |
105 ResourceFormat decode_format, | 103 ResourceFormat decode_format, |
106 size_t max_gpu_image_bytes); | 104 size_t max_gpu_image_bytes); |
107 ~GpuImageDecodeCache() override; | 105 ~GpuImageDecodeCache() override; |
108 | 106 |
109 // ImageDecodeCache overrides. | 107 // ImageDecodeCache overrides. |
110 | 108 |
111 // Finds the existing uploaded image for the provided DrawImage. Creates an | 109 // Finds the existing uploaded image for the provided DrawImage. Creates an |
112 // upload task to upload the image if an exsiting image does not exist. | 110 // upload task to upload the image if an exsiting image does not exist. |
113 bool GetTaskForImageAndRef(const DrawImage& image, | 111 bool GetTaskForImageAndRef(const DrawImage& image, |
114 const TracingInfo& tracing_info, | 112 const TracingInfo& tracing_info, |
115 scoped_refptr<TileTask>* task) override; | 113 scoped_refptr<TileTask>* task) override; |
116 bool GetOutOfRasterDecodeTaskForImageAndRef( | |
117 const DrawImage& image, | |
118 scoped_refptr<TileTask>* task) override; | |
119 void UnrefImage(const DrawImage& image) override; | 114 void UnrefImage(const DrawImage& image) override; |
120 DecodedDrawImage GetDecodedImageForDraw(const DrawImage& draw_image) override; | 115 DecodedDrawImage GetDecodedImageForDraw(const DrawImage& draw_image) override; |
121 void DrawWithImageFinished(const DrawImage& image, | 116 void DrawWithImageFinished(const DrawImage& image, |
122 const DecodedDrawImage& decoded_image) override; | 117 const DecodedDrawImage& decoded_image) override; |
123 void ReduceCacheUsage() override; | 118 void ReduceCacheUsage() override; |
124 void SetShouldAggressivelyFreeResources( | 119 void SetShouldAggressivelyFreeResources( |
125 bool aggressively_free_resources) override; | 120 bool aggressively_free_resources) override; |
126 | 121 |
127 // MemoryDumpProvider overrides. | 122 // MemoryDumpProvider overrides. |
128 bool OnMemoryDump(const base::trace_event::MemoryDumpArgs& args, | 123 bool OnMemoryDump(const base::trace_event::MemoryDumpArgs& args, |
129 base::trace_event::ProcessMemoryDump* pmd) override; | 124 base::trace_event::ProcessMemoryDump* pmd) override; |
130 | 125 |
131 // base::MemoryCoordinatorClient overrides. | 126 // base::MemoryCoordinatorClient overrides. |
132 void OnMemoryStateChange(base::MemoryState state) override; | 127 void OnMemoryStateChange(base::MemoryState state) override; |
133 | 128 |
134 // Called by Decode / Upload tasks. | 129 // Called by Decode / Upload tasks. |
135 void DecodeImage(const DrawImage& image); | 130 void DecodeImage(const DrawImage& image); |
136 void UploadImage(const DrawImage& image); | 131 void UploadImage(const DrawImage& image); |
137 | 132 |
138 // Called by Decode / Upload tasks when tasks are finished. | 133 // Called by Decode / Upload tasks when tasks are finished. |
139 void OnImageDecodeTaskCompleted(const DrawImage& image, | 134 void OnImageDecodeTaskCompleted(const DrawImage& image); |
140 DecodeTaskType task_type); | |
141 void OnImageUploadTaskCompleted(const DrawImage& image); | 135 void OnImageUploadTaskCompleted(const DrawImage& image); |
142 | 136 |
143 // For testing only. | 137 // For testing only. |
144 void SetCachedBytesLimitForTesting(size_t limit) { | 138 void SetCachedBytesLimitForTesting(size_t limit) { |
145 cached_bytes_limit_ = limit; | 139 cached_bytes_limit_ = limit; |
146 } | 140 } |
147 size_t GetBytesUsedForTesting() const { return bytes_used_; } | 141 size_t GetBytesUsedForTesting() const { return bytes_used_; } |
148 size_t GetNumCacheEntriesForTesting() const { | 142 size_t GetNumCacheEntriesForTesting() const { |
149 return persistent_cache_.size(); | 143 return persistent_cache_.size(); |
150 } | 144 } |
(...skipping 15 matching lines...) Expand all Loading... |
166 void SetLockedData(std::unique_ptr<base::DiscardableMemory> data); | 160 void SetLockedData(std::unique_ptr<base::DiscardableMemory> data); |
167 void ResetData(); | 161 void ResetData(); |
168 base::DiscardableMemory* data() const { return data_.get(); } | 162 base::DiscardableMemory* data() const { return data_.get(); } |
169 void mark_used() { usage_stats_.used = true; } | 163 void mark_used() { usage_stats_.used = true; } |
170 | 164 |
171 uint32_t ref_count = 0; | 165 uint32_t ref_count = 0; |
172 // Set to true if the image was corrupt and could not be decoded. | 166 // Set to true if the image was corrupt and could not be decoded. |
173 bool decode_failure = false; | 167 bool decode_failure = false; |
174 // If non-null, this is the pending decode task for this image. | 168 // If non-null, this is the pending decode task for this image. |
175 scoped_refptr<TileTask> task; | 169 scoped_refptr<TileTask> task; |
176 // Similar to above, but only is generated if there is no associated upload | |
177 // generated for this task (ie, this is an out-of-raster request for decode. | |
178 scoped_refptr<TileTask> stand_alone_task; | |
179 | 170 |
180 private: | 171 private: |
181 struct UsageStats { | 172 struct UsageStats { |
182 int lock_count = 1; | 173 int lock_count = 1; |
183 bool used = false; | 174 bool used = false; |
184 bool first_lock_wasted = false; | 175 bool first_lock_wasted = false; |
185 }; | 176 }; |
186 | 177 |
187 void ReportUsageStats() const; | 178 void ReportUsageStats() const; |
188 | 179 |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
264 using InUseCacheKey = uint64_t; | 255 using InUseCacheKey = uint64_t; |
265 | 256 |
266 // All private functions should only be called while holding |lock_|. Some | 257 // All private functions should only be called while holding |lock_|. Some |
267 // functions also require the |context_| lock. These are indicated by | 258 // functions also require the |context_| lock. These are indicated by |
268 // additional comments. | 259 // additional comments. |
269 | 260 |
270 // Similar to GetTaskForImageAndRef, but gets the dependent decode task | 261 // Similar to GetTaskForImageAndRef, but gets the dependent decode task |
271 // rather than the upload task, if necessary. | 262 // rather than the upload task, if necessary. |
272 scoped_refptr<TileTask> GetImageDecodeTaskAndRef( | 263 scoped_refptr<TileTask> GetImageDecodeTaskAndRef( |
273 const DrawImage& image, | 264 const DrawImage& image, |
274 const TracingInfo& tracing_info, | 265 const TracingInfo& tracing_info); |
275 DecodeTaskType task_type); | |
276 | |
277 // Note that this function behaves as if it was public (all of the same locks | |
278 // need to be acquired). | |
279 bool GetTaskForImageAndRefInternal(const DrawImage& image, | |
280 const TracingInfo& tracing_info, | |
281 DecodeTaskType task_type, | |
282 scoped_refptr<TileTask>* task); | |
283 | 266 |
284 void RefImageDecode(const DrawImage& draw_image); | 267 void RefImageDecode(const DrawImage& draw_image); |
285 void UnrefImageDecode(const DrawImage& draw_image); | 268 void UnrefImageDecode(const DrawImage& draw_image); |
286 void RefImage(const DrawImage& draw_image); | 269 void RefImage(const DrawImage& draw_image); |
287 void UnrefImageInternal(const DrawImage& draw_image); | 270 void UnrefImageInternal(const DrawImage& draw_image); |
288 | 271 |
289 // Called any time the ownership of an object changed. This includes changes | 272 // Called any time the ownership of an object changed. This includes changes |
290 // to ref-count or to orphaned status. | 273 // to ref-count or to orphaned status. |
291 void OwnershipChanged(const DrawImage& draw_image, ImageData* image_data); | 274 void OwnershipChanged(const DrawImage& draw_image, ImageData* image_data); |
292 | 275 |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
342 | 325 |
343 // We can't release GPU backed SkImages without holding the context lock, | 326 // We can't release GPU backed SkImages without holding the context lock, |
344 // so we add them to this list and defer deletion until the next time the lock | 327 // so we add them to this list and defer deletion until the next time the lock |
345 // is held. | 328 // is held. |
346 std::vector<sk_sp<SkImage>> images_pending_deletion_; | 329 std::vector<sk_sp<SkImage>> images_pending_deletion_; |
347 }; | 330 }; |
348 | 331 |
349 } // namespace cc | 332 } // namespace cc |
350 | 333 |
351 #endif // CC_TILES_GPU_IMAGE_DECODE_CACHE_H_ | 334 #endif // CC_TILES_GPU_IMAGE_DECODE_CACHE_H_ |
OLD | NEW |