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