Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(143)

Side by Side Diff: cc/tiles/gpu_image_decode_controller.h

Issue 2367953002: Implement OnMemoryStateChange for Various CC Classes (Closed)
Patch Set: feedback Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « cc/resources/resource_pool_unittest.cc ('k') | cc/tiles/gpu_image_decode_controller.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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_CONTROLLER_H_ 5 #ifndef CC_TILES_GPU_IMAGE_DECODE_CONTROLLER_H_
6 #define CC_TILES_GPU_IMAGE_DECODE_CONTROLLER_H_ 6 #define CC_TILES_GPU_IMAGE_DECODE_CONTROLLER_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
118 void DrawWithImageFinished(const DrawImage& image, 118 void DrawWithImageFinished(const DrawImage& image,
119 const DecodedDrawImage& decoded_image) override; 119 const DecodedDrawImage& decoded_image) override;
120 void ReduceCacheUsage() override; 120 void ReduceCacheUsage() override;
121 void SetShouldAggressivelyFreeResources( 121 void SetShouldAggressivelyFreeResources(
122 bool aggressively_free_resources) override; 122 bool aggressively_free_resources) override;
123 123
124 // MemoryDumpProvider overrides. 124 // MemoryDumpProvider overrides.
125 bool OnMemoryDump(const base::trace_event::MemoryDumpArgs& args, 125 bool OnMemoryDump(const base::trace_event::MemoryDumpArgs& args,
126 base::trace_event::ProcessMemoryDump* pmd) override; 126 base::trace_event::ProcessMemoryDump* pmd) override;
127 127
128 // base::MemoryCoordinatorClient overrides.
129 void OnMemoryStateChange(base::MemoryState state) override;
130
128 // Called by Decode / Upload tasks. 131 // Called by Decode / Upload tasks.
129 void DecodeImage(const DrawImage& image); 132 void DecodeImage(const DrawImage& image);
130 void UploadImage(const DrawImage& image); 133 void UploadImage(const DrawImage& image);
131 134
132 // Called by Decode / Upload tasks when tasks are finished. 135 // Called by Decode / Upload tasks when tasks are finished.
133 void OnImageDecodeTaskCompleted(const DrawImage& image); 136 void OnImageDecodeTaskCompleted(const DrawImage& image);
134 void OnImageUploadTaskCompleted(const DrawImage& image); 137 void OnImageUploadTaskCompleted(const DrawImage& image);
135 138
136 // For testing only. 139 // For testing only.
137 void SetCachedItemLimitForTesting(size_t limit) {
138 cached_items_limit_ = limit;
139 }
140 void SetCachedBytesLimitForTesting(size_t limit) { 140 void SetCachedBytesLimitForTesting(size_t limit) {
141 cached_bytes_limit_ = limit; 141 cached_bytes_limit_ = limit;
142 } 142 }
143 size_t GetBytesUsedForTesting() const { return bytes_used_; } 143 size_t GetBytesUsedForTesting() const { return bytes_used_; }
144 size_t GetNumCacheEntriesForTesting() const {
145 return persistent_cache_.size();
146 }
144 size_t GetDrawImageSizeForTesting(const DrawImage& image); 147 size_t GetDrawImageSizeForTesting(const DrawImage& image);
145 void SetImageDecodingFailedForTesting(const DrawImage& image); 148 void SetImageDecodingFailedForTesting(const DrawImage& image);
146 bool DiscardableIsLockedForTesting(const DrawImage& image); 149 bool DiscardableIsLockedForTesting(const DrawImage& image);
147 150
148 private: 151 private:
149 enum class DecodedDataMode { GPU, CPU }; 152 enum class DecodedDataMode { GPU, CPU };
150 153
151 // Stores the CPU-side decoded bits of an image and supporting fields. 154 // Stores the CPU-side decoded bits of an image and supporting fields.
152 struct DecodedImageData { 155 struct DecodedImageData {
153 DecodedImageData(); 156 DecodedImageData();
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after
293 // Returns true if the given ImageData can be used to draw the specified 296 // Returns true if the given ImageData can be used to draw the specified
294 // DrawImage. 297 // DrawImage.
295 bool IsCompatible(const ImageData* image_data, 298 bool IsCompatible(const ImageData* image_data,
296 const DrawImage& draw_image) const; 299 const DrawImage& draw_image) const;
297 300
298 // The following two functions also require the |context_| lock to be held. 301 // The following two functions also require the |context_| lock to be held.
299 void UploadImageIfNecessary(const DrawImage& draw_image, 302 void UploadImageIfNecessary(const DrawImage& draw_image,
300 ImageData* image_data); 303 ImageData* image_data);
301 void DeletePendingImages(); 304 void DeletePendingImages();
302 305
303 // Overriden from base::MemoryCoordinatorClient.
304 void OnMemoryStateChange(base::MemoryState state) override;
305
306 const ResourceFormat format_; 306 const ResourceFormat format_;
307 ContextProvider* context_; 307 ContextProvider* context_;
308 sk_sp<GrContextThreadSafeProxy> context_threadsafe_proxy_; 308 sk_sp<GrContextThreadSafeProxy> context_threadsafe_proxy_;
309 309
310 // All members below this point must only be accessed while holding |lock_|. 310 // All members below this point must only be accessed while holding |lock_|.
311 base::Lock lock_; 311 base::Lock lock_;
312 312
313 // |persistent_cache_| represents the long-lived cache, keeping a certain 313 // |persistent_cache_| represents the long-lived cache, keeping a certain
314 // budget of ImageDatas alive even when their ref count reaches zero. 314 // budget of ImageDatas alive even when their ref count reaches zero.
315 using PersistentCache = base::MRUCache<uint32_t, scoped_refptr<ImageData>>; 315 using PersistentCache = base::MRUCache<uint32_t, scoped_refptr<ImageData>>;
316 PersistentCache persistent_cache_; 316 PersistentCache persistent_cache_;
317 317
318 // |in_use_cache_| represents the in-use (short-lived) cache. Entries are 318 // |in_use_cache_| represents the in-use (short-lived) cache. Entries are
319 // cleaned up as soon as their ref count reaches zero. 319 // cleaned up as soon as their ref count reaches zero.
320 using InUseCache = std::unordered_map<InUseCacheKey, InUseCacheEntry>; 320 using InUseCache = std::unordered_map<InUseCacheKey, InUseCacheEntry>;
321 InUseCache in_use_cache_; 321 InUseCache in_use_cache_;
322 322
323 size_t cached_items_limit_; 323 const size_t normal_max_gpu_image_bytes_;
324 size_t cached_bytes_limit_; 324 size_t cached_bytes_limit_ = normal_max_gpu_image_bytes_;
325 size_t bytes_used_; 325 size_t bytes_used_ = 0;
326 const size_t max_gpu_image_bytes_; 326 base::MemoryState memory_state_ = base::MemoryState::NORMAL;
327 327
328 // We can't release GPU backed SkImages without holding the context lock, 328 // We can't release GPU backed SkImages without holding the context lock,
329 // so we add them to this list and defer deletion until the next time the lock 329 // so we add them to this list and defer deletion until the next time the lock
330 // is held. 330 // is held.
331 std::vector<sk_sp<SkImage>> images_pending_deletion_; 331 std::vector<sk_sp<SkImage>> images_pending_deletion_;
332 }; 332 };
333 333
334 } // namespace cc 334 } // namespace cc
335 335
336 #endif // CC_TILES_GPU_IMAGE_DECODE_CONTROLLER_H_ 336 #endif // CC_TILES_GPU_IMAGE_DECODE_CONTROLLER_H_
OLDNEW
« no previous file with comments | « cc/resources/resource_pool_unittest.cc ('k') | cc/tiles/gpu_image_decode_controller.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698