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 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
118 const DrawImage& image, | 118 const DrawImage& image, |
119 scoped_refptr<TileTask>* task) override; | 119 scoped_refptr<TileTask>* task) override; |
120 void UnrefImage(const DrawImage& image) override; | 120 void UnrefImage(const DrawImage& image) override; |
121 DecodedDrawImage GetDecodedImageForDraw(const DrawImage& draw_image) override; | 121 DecodedDrawImage GetDecodedImageForDraw(const DrawImage& draw_image) override; |
122 void DrawWithImageFinished(const DrawImage& image, | 122 void DrawWithImageFinished(const DrawImage& image, |
123 const DecodedDrawImage& decoded_image) override; | 123 const DecodedDrawImage& decoded_image) override; |
124 void ReduceCacheUsage() override; | 124 void ReduceCacheUsage() override; |
125 void SetShouldAggressivelyFreeResources( | 125 void SetShouldAggressivelyFreeResources( |
126 bool aggressively_free_resources) override; | 126 bool aggressively_free_resources) override; |
127 void ClearCache() override; | 127 void ClearCache() override; |
| 128 size_t GetMaximumMemoryLimitBytes() const override; |
128 | 129 |
129 // MemoryDumpProvider overrides. | 130 // MemoryDumpProvider overrides. |
130 bool OnMemoryDump(const base::trace_event::MemoryDumpArgs& args, | 131 bool OnMemoryDump(const base::trace_event::MemoryDumpArgs& args, |
131 base::trace_event::ProcessMemoryDump* pmd) override; | 132 base::trace_event::ProcessMemoryDump* pmd) override; |
132 | 133 |
133 // base::MemoryCoordinatorClient overrides. | 134 // base::MemoryCoordinatorClient overrides. |
134 void OnMemoryStateChange(base::MemoryState state) override; | 135 void OnMemoryStateChange(base::MemoryState state) override; |
135 void OnPurgeMemory() override; | 136 void OnPurgeMemory() override; |
136 | 137 |
137 // Called by Decode / Upload tasks. | 138 // Called by Decode / Upload tasks. |
(...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
340 // The following two functions also require the |context_| lock to be held. | 341 // The following two functions also require the |context_| lock to be held. |
341 void UploadImageIfNecessary(const DrawImage& draw_image, | 342 void UploadImageIfNecessary(const DrawImage& draw_image, |
342 ImageData* image_data); | 343 ImageData* image_data); |
343 void DeletePendingImages(); | 344 void DeletePendingImages(); |
344 | 345 |
345 const ResourceFormat format_; | 346 const ResourceFormat format_; |
346 ContextProvider* context_; | 347 ContextProvider* context_; |
347 sk_sp<GrContextThreadSafeProxy> context_threadsafe_proxy_; | 348 sk_sp<GrContextThreadSafeProxy> context_threadsafe_proxy_; |
348 | 349 |
349 // All members below this point must only be accessed while holding |lock_|. | 350 // All members below this point must only be accessed while holding |lock_|. |
| 351 // The exception are const members like |normal_max_cache_bytes_| that can |
| 352 // be accessed without a lock since they are thread safe. |
350 base::Lock lock_; | 353 base::Lock lock_; |
351 | 354 |
352 // |persistent_cache_| represents the long-lived cache, keeping a certain | 355 // |persistent_cache_| represents the long-lived cache, keeping a certain |
353 // budget of ImageDatas alive even when their ref count reaches zero. | 356 // budget of ImageDatas alive even when their ref count reaches zero. |
354 using PersistentCache = base::MRUCache<uint32_t, scoped_refptr<ImageData>>; | 357 using PersistentCache = base::MRUCache<uint32_t, scoped_refptr<ImageData>>; |
355 PersistentCache persistent_cache_; | 358 PersistentCache persistent_cache_; |
356 | 359 |
357 // |in_use_cache_| represents the in-use (short-lived) cache. Entries are | 360 // |in_use_cache_| represents the in-use (short-lived) cache. Entries are |
358 // cleaned up as soon as their ref count reaches zero. | 361 // cleaned up as soon as their ref count reaches zero. |
359 using InUseCache = | 362 using InUseCache = |
360 std::unordered_map<InUseCacheKey, InUseCacheEntry, InUseCacheKeyHash>; | 363 std::unordered_map<InUseCacheKey, InUseCacheEntry, InUseCacheKeyHash>; |
361 InUseCache in_use_cache_; | 364 InUseCache in_use_cache_; |
362 | 365 |
363 size_t max_working_set_bytes_; | 366 size_t max_working_set_bytes_; |
364 const size_t normal_max_cache_bytes_; | 367 const size_t normal_max_cache_bytes_; |
365 size_t cached_bytes_limit_ = normal_max_cache_bytes_; | 368 size_t cached_bytes_limit_ = normal_max_cache_bytes_; |
366 size_t bytes_used_ = 0; | 369 size_t bytes_used_ = 0; |
367 base::MemoryState memory_state_ = base::MemoryState::NORMAL; | 370 base::MemoryState memory_state_ = base::MemoryState::NORMAL; |
368 | 371 |
369 // We can't release GPU backed SkImages without holding the context lock, | 372 // We can't release GPU backed SkImages without holding the context lock, |
370 // so we add them to this list and defer deletion until the next time the lock | 373 // so we add them to this list and defer deletion until the next time the lock |
371 // is held. | 374 // is held. |
372 std::vector<sk_sp<SkImage>> images_pending_deletion_; | 375 std::vector<sk_sp<SkImage>> images_pending_deletion_; |
373 }; | 376 }; |
374 | 377 |
375 } // namespace cc | 378 } // namespace cc |
376 | 379 |
377 #endif // CC_TILES_GPU_IMAGE_DECODE_CACHE_H_ | 380 #endif // CC_TILES_GPU_IMAGE_DECODE_CACHE_H_ |
OLD | NEW |