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_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> |
11 | 11 |
12 #include "base/containers/mru_cache.h" | 12 #include "base/containers/mru_cache.h" |
13 #include "base/memory/discardable_memory.h" | 13 #include "base/memory/discardable_memory.h" |
| 14 #include "base/memory/memory_coordinator_client.h" |
14 #include "base/synchronization/lock.h" | 15 #include "base/synchronization/lock.h" |
15 #include "base/trace_event/memory_dump_provider.h" | 16 #include "base/trace_event/memory_dump_provider.h" |
16 #include "cc/base/cc_export.h" | 17 #include "cc/base/cc_export.h" |
17 #include "cc/resources/resource_format.h" | 18 #include "cc/resources/resource_format.h" |
18 #include "cc/tiles/image_decode_controller.h" | 19 #include "cc/tiles/image_decode_controller.h" |
19 #include "third_party/skia/include/core/SkRefCnt.h" | 20 #include "third_party/skia/include/core/SkRefCnt.h" |
20 | 21 |
21 class SkImageTextureData; | 22 class SkImageTextureData; |
22 | 23 |
23 namespace cc { | 24 namespace cc { |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
90 // ref-count reaches 0 it will be deleted. | 91 // ref-count reaches 0 it will be deleted. |
91 // 3) scoped_refptr ref-counts. | 92 // 3) scoped_refptr ref-counts. |
92 // Because both the persistent_cache_ and the in_use_cache_ point at the | 93 // Because both the persistent_cache_ and the in_use_cache_ point at the |
93 // same ImageDatas (and may need to keep these ImageDatas alive independent | 94 // same ImageDatas (and may need to keep these ImageDatas alive independent |
94 // of each other), they hold ImageDatas by scoped_refptr. The scoped_refptr | 95 // of each other), they hold ImageDatas by scoped_refptr. The scoped_refptr |
95 // keeps an ImageData alive while it is present in either the | 96 // keeps an ImageData alive while it is present in either the |
96 // |persistent_cache_| or |in_use_cache_|. | 97 // |persistent_cache_| or |in_use_cache_|. |
97 // | 98 // |
98 class CC_EXPORT GpuImageDecodeController | 99 class CC_EXPORT GpuImageDecodeController |
99 : public ImageDecodeController, | 100 : public ImageDecodeController, |
100 public base::trace_event::MemoryDumpProvider { | 101 public base::trace_event::MemoryDumpProvider, |
| 102 public base::MemoryCoordinatorClient { |
101 public: | 103 public: |
102 explicit GpuImageDecodeController(ContextProvider* context, | 104 explicit GpuImageDecodeController(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 ~GpuImageDecodeController() override; | 107 ~GpuImageDecodeController() override; |
106 | 108 |
107 // ImageDecodeController overrides. | 109 // ImageDecodeController 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. |
(...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
294 // 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 |
295 // DrawImage. | 297 // DrawImage. |
296 bool IsCompatible(const ImageData* image_data, | 298 bool IsCompatible(const ImageData* image_data, |
297 const DrawImage& draw_image) const; | 299 const DrawImage& draw_image) const; |
298 | 300 |
299 // 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. |
300 void UploadImageIfNecessary(const DrawImage& draw_image, | 302 void UploadImageIfNecessary(const DrawImage& draw_image, |
301 ImageData* image_data); | 303 ImageData* image_data); |
302 void DeletePendingImages(); | 304 void DeletePendingImages(); |
303 | 305 |
| 306 // Overriden from base::MemoryCoordinatorClient. |
| 307 void OnMemoryStateChange(base::MemoryState state) override; |
| 308 |
304 const ResourceFormat format_; | 309 const ResourceFormat format_; |
305 ContextProvider* context_; | 310 ContextProvider* context_; |
306 sk_sp<GrContextThreadSafeProxy> context_threadsafe_proxy_; | 311 sk_sp<GrContextThreadSafeProxy> context_threadsafe_proxy_; |
307 | 312 |
308 // All members below this point must only be accessed while holding |lock_|. | 313 // All members below this point must only be accessed while holding |lock_|. |
309 base::Lock lock_; | 314 base::Lock lock_; |
310 | 315 |
311 // |persistent_cache_| represents the long-lived cache, keeping a certain | 316 // |persistent_cache_| represents the long-lived cache, keeping a certain |
312 // budget of ImageDatas alive even when their ref count reaches zero. | 317 // budget of ImageDatas alive even when their ref count reaches zero. |
313 using PersistentCache = base::MRUCache<uint32_t, scoped_refptr<ImageData>>; | 318 using PersistentCache = base::MRUCache<uint32_t, scoped_refptr<ImageData>>; |
(...skipping 11 matching lines...) Expand all Loading... |
325 | 330 |
326 // We can't release GPU backed SkImages without holding the context lock, | 331 // 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 | 332 // so we add them to this list and defer deletion until the next time the lock |
328 // is held. | 333 // is held. |
329 std::vector<sk_sp<SkImage>> images_pending_deletion_; | 334 std::vector<sk_sp<SkImage>> images_pending_deletion_; |
330 }; | 335 }; |
331 | 336 |
332 } // namespace cc | 337 } // namespace cc |
333 | 338 |
334 #endif // CC_TILES_GPU_IMAGE_DECODE_CONTROLLER_H_ | 339 #endif // CC_TILES_GPU_IMAGE_DECODE_CONTROLLER_H_ |
OLD | NEW |