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

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

Issue 2537683002: cc: Add image decode queue functionality to image manager. (Closed)
Patch Set: update Created 3 years, 12 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
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_SOFTWARE_IMAGE_DECODE_CACHE_H_ 5 #ifndef CC_TILES_SOFTWARE_IMAGE_DECODE_CACHE_H_
6 #define CC_TILES_SOFTWARE_IMAGE_DECODE_CACHE_H_ 6 #define CC_TILES_SOFTWARE_IMAGE_DECODE_CACHE_H_
7 7
8 #include <stdint.h> 8 #include <stdint.h>
9 9
10 #include <memory> 10 #include <memory>
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
102 }; 102 };
103 103
104 class CC_EXPORT SoftwareImageDecodeCache 104 class CC_EXPORT SoftwareImageDecodeCache
105 : public ImageDecodeCache, 105 : public ImageDecodeCache,
106 public base::trace_event::MemoryDumpProvider, 106 public base::trace_event::MemoryDumpProvider,
107 public base::MemoryCoordinatorClient { 107 public base::MemoryCoordinatorClient {
108 public: 108 public:
109 using ImageKey = ImageDecodeCacheKey; 109 using ImageKey = ImageDecodeCacheKey;
110 using ImageKeyHash = ImageDecodeCacheKeyHash; 110 using ImageKeyHash = ImageDecodeCacheKeyHash;
111 111
112 enum class DecodeTaskType { USE_IN_RASTER_TASKS, USE_OUT_OF_RASTER_TASKS };
113
112 SoftwareImageDecodeCache(ResourceFormat format, 114 SoftwareImageDecodeCache(ResourceFormat format,
113 size_t locked_memory_limit_bytes); 115 size_t locked_memory_limit_bytes);
114 ~SoftwareImageDecodeCache() override; 116 ~SoftwareImageDecodeCache() override;
115 117
116 // ImageDecodeCache overrides. 118 // ImageDecodeCache overrides.
117 bool GetTaskForImageAndRef(const DrawImage& image, 119 bool GetTaskForImageAndRef(const DrawImage& image,
118 const TracingInfo& tracing_info, 120 const TracingInfo& tracing_info,
119 scoped_refptr<TileTask>* task) override; 121 scoped_refptr<TileTask>* task) override;
122 bool GetOutOfRasterDecodeTaskForImageAndRef(
123 const DrawImage& image,
124 scoped_refptr<TileTask>* task) override;
120 void UnrefImage(const DrawImage& image) override; 125 void UnrefImage(const DrawImage& image) override;
121 DecodedDrawImage GetDecodedImageForDraw(const DrawImage& image) override; 126 DecodedDrawImage GetDecodedImageForDraw(const DrawImage& image) override;
122 void DrawWithImageFinished(const DrawImage& image, 127 void DrawWithImageFinished(const DrawImage& image,
123 const DecodedDrawImage& decoded_image) override; 128 const DecodedDrawImage& decoded_image) override;
124 void ReduceCacheUsage() override; 129 void ReduceCacheUsage() override;
125 // Software doesn't keep outstanding images pinned, so this is a no-op. 130 // Software doesn't keep outstanding images pinned, so this is a no-op.
126 void SetShouldAggressivelyFreeResources( 131 void SetShouldAggressivelyFreeResources(
127 bool aggressively_free_resources) override {} 132 bool aggressively_free_resources) override {}
128 133
129 // Decode the given image and store it in the cache. This is only called by an 134 // Decode the given image and store it in the cache. This is only called by an
130 // image decode task from a worker thread. 135 // image decode task from a worker thread.
131 void DecodeImage(const ImageKey& key, const DrawImage& image); 136 void DecodeImage(const ImageKey& key,
137 const DrawImage& image,
138 DecodeTaskType task_type);
132 139
133 void RemovePendingTask(const ImageKey& key); 140 void RemovePendingTask(const ImageKey& key, DecodeTaskType task_type);
134 141
135 // MemoryDumpProvider overrides. 142 // MemoryDumpProvider overrides.
136 bool OnMemoryDump(const base::trace_event::MemoryDumpArgs& args, 143 bool OnMemoryDump(const base::trace_event::MemoryDumpArgs& args,
137 base::trace_event::ProcessMemoryDump* pmd) override; 144 base::trace_event::ProcessMemoryDump* pmd) override;
138 145
139 private: 146 private:
140 // DecodedImage is a convenience storage for discardable memory. It can also 147 // DecodedImage is a convenience storage for discardable memory. It can also
141 // construct an image out of SkImageInfo and stored discardable memory. 148 // construct an image out of SkImageInfo and stored discardable memory.
142 class DecodedImage { 149 class DecodedImage {
143 public: 150 public:
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after
260 void UnrefAtRasterImage(const ImageKey& key); 267 void UnrefAtRasterImage(const ImageKey& key);
261 268
262 // Helper function which dumps all images in a specific ImageMRUCache. 269 // Helper function which dumps all images in a specific ImageMRUCache.
263 void DumpImageMemoryForCache(const ImageMRUCache& cache, 270 void DumpImageMemoryForCache(const ImageMRUCache& cache,
264 const char* cache_name, 271 const char* cache_name,
265 base::trace_event::ProcessMemoryDump* pmd) const; 272 base::trace_event::ProcessMemoryDump* pmd) const;
266 273
267 // Overriden from base::MemoryCoordinatorClient. 274 // Overriden from base::MemoryCoordinatorClient.
268 void OnMemoryStateChange(base::MemoryState state) override; 275 void OnMemoryStateChange(base::MemoryState state) override;
269 276
277 // Helper method to get the different tasks. Note that this should be used as
278 // if it was public (ie, all of the locks need to be properly acquired).
279 bool GetTaskForImageAndRefInternal(const DrawImage& image,
280 const TracingInfo& tracing_info,
281 DecodeTaskType type,
282 scoped_refptr<TileTask>* task);
283
270 std::unordered_map<ImageKey, scoped_refptr<TileTask>, ImageKeyHash> 284 std::unordered_map<ImageKey, scoped_refptr<TileTask>, ImageKeyHash>
271 pending_image_tasks_; 285 pending_in_raster_image_tasks_;
enne (OOO) 2017/01/03 21:15:25 Why do you need a second map for out of raster ima
vmpstr 2017/01/03 21:40:34 Yeah this is here as a safeguard against the task
enne (OOO) 2017/01/03 21:49:42 Ah, ok thanks. That makes more sense why they nee
286 std::unordered_map<ImageKey, scoped_refptr<TileTask>, ImageKeyHash>
287 pending_out_of_raster_image_tasks_;
272 288
273 // The members below this comment can only be accessed if the lock is held to 289 // The members below this comment can only be accessed if the lock is held to
274 // ensure that they are safe to access on multiple threads. 290 // ensure that they are safe to access on multiple threads.
275 base::Lock lock_; 291 base::Lock lock_;
276 292
277 // Decoded images and ref counts (predecode path). 293 // Decoded images and ref counts (predecode path).
278 ImageMRUCache decoded_images_; 294 ImageMRUCache decoded_images_;
279 std::unordered_map<ImageKey, int, ImageKeyHash> decoded_images_ref_counts_; 295 std::unordered_map<ImageKey, int, ImageKeyHash> decoded_images_ref_counts_;
280 296
281 // Decoded image and ref counts (at-raster decode path). 297 // Decoded image and ref counts (at-raster decode path).
282 ImageMRUCache at_raster_decoded_images_; 298 ImageMRUCache at_raster_decoded_images_;
283 std::unordered_map<ImageKey, int, ImageKeyHash> 299 std::unordered_map<ImageKey, int, ImageKeyHash>
284 at_raster_decoded_images_ref_counts_; 300 at_raster_decoded_images_ref_counts_;
285 301
286 MemoryBudget locked_images_budget_; 302 MemoryBudget locked_images_budget_;
287 303
288 ResourceFormat format_; 304 ResourceFormat format_;
289 size_t max_items_in_cache_; 305 size_t max_items_in_cache_;
290 306
291 // Used to uniquely identify DecodedImages for memory traces. 307 // Used to uniquely identify DecodedImages for memory traces.
292 base::AtomicSequenceNumber next_tracing_id_; 308 base::AtomicSequenceNumber next_tracing_id_;
293 }; 309 };
294 310
295 } // namespace cc 311 } // namespace cc
296 312
297 #endif // CC_TILES_SOFTWARE_IMAGE_DECODE_CACHE_H_ 313 #endif // CC_TILES_SOFTWARE_IMAGE_DECODE_CACHE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698