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_RASTER_STAGING_BUFFER_POOL_H_ | 5 #ifndef CC_RASTER_STAGING_BUFFER_POOL_H_ |
6 #define CC_RASTER_STAGING_BUFFER_POOL_H_ | 6 #define CC_RASTER_STAGING_BUFFER_POOL_H_ |
7 | 7 |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 | 9 |
10 #include <deque> | 10 #include <deque> |
11 #include <memory> | 11 #include <memory> |
12 #include <set> | 12 #include <set> |
13 | 13 |
14 #include "base/macros.h" | 14 #include "base/macros.h" |
| 15 #include "base/memory/memory_pressure_listener.h" |
15 #include "base/memory/weak_ptr.h" | 16 #include "base/memory/weak_ptr.h" |
16 #include "base/synchronization/lock.h" | 17 #include "base/synchronization/lock.h" |
17 #include "base/time/time.h" | 18 #include "base/time/time.h" |
18 #include "base/trace_event/memory_dump_provider.h" | 19 #include "base/trace_event/memory_dump_provider.h" |
19 #include "cc/output/context_provider.h" | 20 #include "cc/output/context_provider.h" |
20 #include "cc/resources/resource_provider.h" | 21 #include "cc/resources/resource_provider.h" |
21 | 22 |
22 namespace gpu { | 23 namespace gpu { |
23 namespace gles2 { | 24 namespace gles2 { |
24 class GLES2Interface; | 25 class GLES2Interface; |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
71 void ReleaseStagingBuffer(std::unique_ptr<StagingBuffer> staging_buffer); | 72 void ReleaseStagingBuffer(std::unique_ptr<StagingBuffer> staging_buffer); |
72 | 73 |
73 private: | 74 private: |
74 void AddStagingBuffer(const StagingBuffer* staging_buffer, | 75 void AddStagingBuffer(const StagingBuffer* staging_buffer, |
75 ResourceFormat format); | 76 ResourceFormat format); |
76 void RemoveStagingBuffer(const StagingBuffer* staging_buffer); | 77 void RemoveStagingBuffer(const StagingBuffer* staging_buffer); |
77 void MarkStagingBufferAsFree(const StagingBuffer* staging_buffer); | 78 void MarkStagingBufferAsFree(const StagingBuffer* staging_buffer); |
78 void MarkStagingBufferAsBusy(const StagingBuffer* staging_buffer); | 79 void MarkStagingBufferAsBusy(const StagingBuffer* staging_buffer); |
79 | 80 |
80 base::TimeTicks GetUsageTimeForLRUBuffer(); | 81 base::TimeTicks GetUsageTimeForLRUBuffer(); |
| 82 void OnMemoryPressure( |
| 83 base::MemoryPressureListener::MemoryPressureLevel memory_pressure_level); |
81 void ScheduleReduceMemoryUsage(); | 84 void ScheduleReduceMemoryUsage(); |
82 void ReduceMemoryUsage(); | 85 void ReduceMemoryUsage(); |
83 void ReleaseBuffersNotUsedSince(base::TimeTicks time); | 86 void ReleaseBuffersNotUsedSince(base::TimeTicks time); |
84 | 87 |
85 std::unique_ptr<base::trace_event::ConvertableToTraceFormat> StateAsValue() | 88 std::unique_ptr<base::trace_event::ConvertableToTraceFormat> StateAsValue() |
86 const; | 89 const; |
87 void StagingStateAsValueInto( | 90 void StagingStateAsValueInto( |
88 base::trace_event::TracedValue* staging_state) const; | 91 base::trace_event::TracedValue* staging_state) const; |
89 | 92 |
90 scoped_refptr<base::SequencedTaskRunner> task_runner_; | 93 scoped_refptr<base::SequencedTaskRunner> task_runner_; |
91 ContextProvider* const worker_context_provider_; | 94 ContextProvider* const worker_context_provider_; |
92 ResourceProvider* const resource_provider_; | 95 ResourceProvider* const resource_provider_; |
93 const bool use_partial_raster_; | 96 const bool use_partial_raster_; |
| 97 std::unique_ptr<base::MemoryPressureListener> memory_pressure_listener_; |
94 | 98 |
95 mutable base::Lock lock_; | 99 mutable base::Lock lock_; |
96 // |lock_| must be acquired when accessing the following members. | 100 // |lock_| must be acquired when accessing the following members. |
97 using StagingBufferSet = std::set<const StagingBuffer*>; | 101 using StagingBufferSet = std::set<const StagingBuffer*>; |
98 StagingBufferSet buffers_; | 102 StagingBufferSet buffers_; |
99 using StagingBufferDeque = std::deque<std::unique_ptr<StagingBuffer>>; | 103 using StagingBufferDeque = std::deque<std::unique_ptr<StagingBuffer>>; |
100 StagingBufferDeque free_buffers_; | 104 StagingBufferDeque free_buffers_; |
101 StagingBufferDeque busy_buffers_; | 105 StagingBufferDeque busy_buffers_; |
102 const int max_staging_buffer_usage_in_bytes_; | 106 const int max_staging_buffer_usage_in_bytes_; |
103 int staging_buffer_usage_in_bytes_; | 107 int staging_buffer_usage_in_bytes_; |
104 int free_staging_buffer_usage_in_bytes_; | 108 int free_staging_buffer_usage_in_bytes_; |
105 const base::TimeDelta staging_buffer_expiration_delay_; | 109 const base::TimeDelta staging_buffer_expiration_delay_; |
106 bool reduce_memory_usage_pending_; | 110 bool reduce_memory_usage_pending_; |
107 base::Closure reduce_memory_usage_callback_; | 111 base::Closure reduce_memory_usage_callback_; |
108 | 112 |
109 base::WeakPtrFactory<StagingBufferPool> weak_ptr_factory_; | 113 base::WeakPtrFactory<StagingBufferPool> weak_ptr_factory_; |
110 | 114 |
111 DISALLOW_COPY_AND_ASSIGN(StagingBufferPool); | 115 DISALLOW_COPY_AND_ASSIGN(StagingBufferPool); |
112 }; | 116 }; |
113 | 117 |
114 } // namespace cc | 118 } // namespace cc |
115 | 119 |
116 #endif // CC_RASTER_STAGING_BUFFER_POOL_H_ | 120 #endif // CC_RASTER_STAGING_BUFFER_POOL_H_ |
OLD | NEW |