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

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

Issue 2286583002: Make cc::SoftwareImageDecodeController, cc::ResourcePool, and cc::StagingBufferPoo… (Closed)
Patch Set: Fixed DEPS. Created 4 years, 3 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_CONTROLLER_H_ 5 #ifndef CC_TILES_SOFTWARE_IMAGE_DECODE_CONTROLLER_H_
6 #define CC_TILES_SOFTWARE_IMAGE_DECODE_CONTROLLER_H_ 6 #define CC_TILES_SOFTWARE_IMAGE_DECODE_CONTROLLER_H_
7 7
8 #include <stdint.h> 8 #include <stdint.h>
9 9
10 #include <memory> 10 #include <memory>
11 #include <unordered_map> 11 #include <unordered_map>
12 #include <unordered_set> 12 #include <unordered_set>
13 13
14 #include "base/atomic_sequence_num.h" 14 #include "base/atomic_sequence_num.h"
15 #include "base/containers/mru_cache.h" 15 #include "base/containers/mru_cache.h"
16 #include "base/hash.h" 16 #include "base/hash.h"
17 #include "base/memory/discardable_memory_allocator.h" 17 #include "base/memory/discardable_memory_allocator.h"
18 #include "base/memory/ref_counted.h" 18 #include "base/memory/ref_counted.h"
19 #include "base/numerics/safe_math.h" 19 #include "base/numerics/safe_math.h"
20 #include "base/threading/thread_checker.h" 20 #include "base/threading/thread_checker.h"
21 #include "base/trace_event/memory_dump_provider.h" 21 #include "base/trace_event/memory_dump_provider.h"
22 #include "cc/base/cc_export.h" 22 #include "cc/base/cc_export.h"
23 #include "cc/playback/decoded_draw_image.h" 23 #include "cc/playback/decoded_draw_image.h"
24 #include "cc/playback/draw_image.h" 24 #include "cc/playback/draw_image.h"
25 #include "cc/resources/resource_format.h" 25 #include "cc/resources/resource_format.h"
26 #include "cc/tiles/image_decode_controller.h" 26 #include "cc/tiles/image_decode_controller.h"
27 #include "components/memory_coordinator/common/memory_coordinator_client.h"
27 #include "third_party/skia/include/core/SkRefCnt.h" 28 #include "third_party/skia/include/core/SkRefCnt.h"
28 29
29 namespace cc { 30 namespace cc {
30 31
31 // ImageDecodeControllerKey is a class that gets a cache key out of a given draw 32 // ImageDecodeControllerKey is a class that gets a cache key out of a given draw
32 // image. That is, this key uniquely identifies an image in the cache. Note that 33 // image. That is, this key uniquely identifies an image in the cache. Note that
33 // it's insufficient to use SkImage's unique id, since the same image can appear 34 // it's insufficient to use SkImage's unique id, since the same image can appear
34 // in the cache multiple times at different scales and filter qualities. 35 // in the cache multiple times at different scales and filter qualities.
35 class CC_EXPORT ImageDecodeControllerKey { 36 class CC_EXPORT ImageDecodeControllerKey {
36 public: 37 public:
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
94 95
95 // Hash function for the above ImageDecodeControllerKey. 96 // Hash function for the above ImageDecodeControllerKey.
96 struct ImageDecodeControllerKeyHash { 97 struct ImageDecodeControllerKeyHash {
97 size_t operator()(const ImageDecodeControllerKey& key) const { 98 size_t operator()(const ImageDecodeControllerKey& key) const {
98 return key.get_hash(); 99 return key.get_hash();
99 } 100 }
100 }; 101 };
101 102
102 class CC_EXPORT SoftwareImageDecodeController 103 class CC_EXPORT SoftwareImageDecodeController
103 : public ImageDecodeController, 104 : public ImageDecodeController,
104 public base::trace_event::MemoryDumpProvider { 105 public base::trace_event::MemoryDumpProvider,
106 public memory_coordinator::MemoryCoordinatorClient {
105 public: 107 public:
106 using ImageKey = ImageDecodeControllerKey; 108 using ImageKey = ImageDecodeControllerKey;
107 using ImageKeyHash = ImageDecodeControllerKeyHash; 109 using ImageKeyHash = ImageDecodeControllerKeyHash;
108 110
109 SoftwareImageDecodeController(ResourceFormat format, 111 SoftwareImageDecodeController(ResourceFormat format,
110 size_t locked_memory_limit_bytes); 112 size_t locked_memory_limit_bytes);
111 ~SoftwareImageDecodeController() override; 113 ~SoftwareImageDecodeController() override;
112 114
113 // ImageDecodeController overrides. 115 // ImageDecodeController overrides.
114 bool GetTaskForImageAndRef(const DrawImage& image, 116 bool GetTaskForImageAndRef(const DrawImage& image,
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after
256 void SanityCheckState(int line, bool lock_acquired); 258 void SanityCheckState(int line, bool lock_acquired);
257 void RefImage(const ImageKey& key); 259 void RefImage(const ImageKey& key);
258 void RefAtRasterImage(const ImageKey& key); 260 void RefAtRasterImage(const ImageKey& key);
259 void UnrefAtRasterImage(const ImageKey& key); 261 void UnrefAtRasterImage(const ImageKey& key);
260 262
261 // Helper function which dumps all images in a specific ImageMRUCache. 263 // Helper function which dumps all images in a specific ImageMRUCache.
262 void DumpImageMemoryForCache(const ImageMRUCache& cache, 264 void DumpImageMemoryForCache(const ImageMRUCache& cache,
263 const char* cache_name, 265 const char* cache_name,
264 base::trace_event::ProcessMemoryDump* pmd) const; 266 base::trace_event::ProcessMemoryDump* pmd) const;
265 267
268 // Overriden from memory_coordinator::MemoryCoordinatorClient.
269 void OnMemoryStateChange(
270 memory_coordinator::mojom::MemoryState state) override;
271
266 std::unordered_map<ImageKey, scoped_refptr<TileTask>, ImageKeyHash> 272 std::unordered_map<ImageKey, scoped_refptr<TileTask>, ImageKeyHash>
267 pending_image_tasks_; 273 pending_image_tasks_;
268 274
269 // The members below this comment can only be accessed if the lock is held to 275 // The members below this comment can only be accessed if the lock is held to
270 // ensure that they are safe to access on multiple threads. 276 // ensure that they are safe to access on multiple threads.
271 base::Lock lock_; 277 base::Lock lock_;
272 278
273 // Decoded images and ref counts (predecode path). 279 // Decoded images and ref counts (predecode path).
274 ImageMRUCache decoded_images_; 280 ImageMRUCache decoded_images_;
275 std::unordered_map<ImageKey, int, ImageKeyHash> decoded_images_ref_counts_; 281 std::unordered_map<ImageKey, int, ImageKeyHash> decoded_images_ref_counts_;
276 282
277 // Decoded image and ref counts (at-raster decode path). 283 // Decoded image and ref counts (at-raster decode path).
278 ImageMRUCache at_raster_decoded_images_; 284 ImageMRUCache at_raster_decoded_images_;
279 std::unordered_map<ImageKey, int, ImageKeyHash> 285 std::unordered_map<ImageKey, int, ImageKeyHash>
280 at_raster_decoded_images_ref_counts_; 286 at_raster_decoded_images_ref_counts_;
281 287
282 MemoryBudget locked_images_budget_; 288 MemoryBudget locked_images_budget_;
283 289
284 ResourceFormat format_; 290 ResourceFormat format_;
285 291
286 // Used to uniquely identify DecodedImages for memory traces. 292 // Used to uniquely identify DecodedImages for memory traces.
287 base::AtomicSequenceNumber next_tracing_id_; 293 base::AtomicSequenceNumber next_tracing_id_;
288 }; 294 };
289 295
290 } // namespace cc 296 } // namespace cc
291 297
292 #endif // CC_TILES_SOFTWARE_IMAGE_DECODE_CONTROLLER_H_ 298 #endif // CC_TILES_SOFTWARE_IMAGE_DECODE_CONTROLLER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698