OLD | NEW |
---|---|
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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_ONE_COPY_TILE_TASK_WORKER_POOL_H_ | 5 #ifndef CC_RASTER_ONE_COPY_TILE_TASK_WORKER_POOL_H_ |
6 #define CC_RASTER_ONE_COPY_TILE_TASK_WORKER_POOL_H_ | 6 #define CC_RASTER_ONE_COPY_TILE_TASK_WORKER_POOL_H_ |
7 | 7 |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 | 9 |
10 #include <deque> | |
11 #include <set> | |
12 | |
13 #include "base/macros.h" | 10 #include "base/macros.h" |
14 #include "base/memory/weak_ptr.h" | |
15 #include "base/synchronization/lock.h" | |
16 #include "base/time/time.h" | |
17 #include "base/trace_event/memory_dump_provider.h" | |
18 #include "base/values.h" | |
19 #include "cc/output/context_provider.h" | 11 #include "cc/output/context_provider.h" |
20 #include "cc/raster/tile_task_runner.h" | 12 #include "cc/raster/tile_task_runner.h" |
21 #include "cc/raster/tile_task_worker_pool.h" | 13 #include "cc/raster/tile_task_worker_pool.h" |
22 #include "cc/resources/resource_provider.h" | 14 #include "cc/resources/resource_provider.h" |
23 | 15 |
24 namespace base { | |
25 namespace trace_event { | |
26 class ConvertableToTraceFormat; | |
27 class TracedValue; | |
28 } | |
29 } | |
30 | |
31 namespace gpu { | |
32 namespace gles2 { | |
33 class GLES2Interface; | |
34 } | |
35 } | |
36 | |
37 namespace cc { | 16 namespace cc { |
17 struct StagingBuffer; | |
18 class StagingBufferPool; | |
38 class ResourcePool; | 19 class ResourcePool; |
39 | 20 |
40 class CC_EXPORT OneCopyTileTaskWorkerPool | 21 class CC_EXPORT OneCopyTileTaskWorkerPool : public TileTaskWorkerPool, |
41 : public TileTaskWorkerPool, | 22 public TileTaskRunner { |
42 public TileTaskRunner, | |
43 public base::trace_event::MemoryDumpProvider { | |
44 public: | 23 public: |
45 ~OneCopyTileTaskWorkerPool() override; | 24 ~OneCopyTileTaskWorkerPool() override; |
46 | 25 |
47 static scoped_ptr<TileTaskWorkerPool> Create( | 26 static scoped_ptr<TileTaskWorkerPool> Create( |
48 base::SequencedTaskRunner* task_runner, | 27 base::SequencedTaskRunner* task_runner, |
49 TaskGraphRunner* task_graph_runner, | 28 TaskGraphRunner* task_graph_runner, |
50 ContextProvider* context_provider, | 29 ContextProvider* context_provider, |
51 ResourceProvider* resource_provider, | 30 ResourceProvider* resource_provider, |
52 int max_copy_texture_chromium_size, | 31 int max_copy_texture_chromium_size, |
53 bool use_partial_raster, | 32 bool use_partial_raster, |
(...skipping 10 matching lines...) Expand all Loading... | |
64 uint64_t previous_content_id) override; | 43 uint64_t previous_content_id) override; |
65 void ReleaseBufferForRaster(scoped_ptr<RasterBuffer> buffer) override; | 44 void ReleaseBufferForRaster(scoped_ptr<RasterBuffer> buffer) override; |
66 | 45 |
67 // Overridden from TileTaskRunner: | 46 // Overridden from TileTaskRunner: |
68 void Shutdown() override; | 47 void Shutdown() override; |
69 void ScheduleTasks(TaskGraph* graph) override; | 48 void ScheduleTasks(TaskGraph* graph) override; |
70 void CheckForCompletedTasks() override; | 49 void CheckForCompletedTasks() override; |
71 ResourceFormat GetResourceFormat(bool must_support_alpha) const override; | 50 ResourceFormat GetResourceFormat(bool must_support_alpha) const override; |
72 bool GetResourceRequiresSwizzle(bool must_support_alpha) const override; | 51 bool GetResourceRequiresSwizzle(bool must_support_alpha) const override; |
73 | 52 |
74 // Overridden from base::trace_event::MemoryDumpProvider: | |
75 bool OnMemoryDump(const base::trace_event::MemoryDumpArgs& args, | |
76 base::trace_event::ProcessMemoryDump* pmd) override; | |
77 | |
78 // Playback raster source and copy result into |resource|. | 53 // Playback raster source and copy result into |resource|. |
79 void PlaybackAndCopyOnWorkerThread( | 54 void PlaybackAndCopyOnWorkerThread( |
80 const Resource* resource, | 55 const Resource* resource, |
81 ResourceProvider::ScopedWriteLockGL* resource_lock, | 56 ResourceProvider::ScopedWriteLockGL* resource_lock, |
82 const RasterSource* raster_source, | 57 const RasterSource* raster_source, |
83 const gfx::Rect& raster_full_rect, | 58 const gfx::Rect& raster_full_rect, |
84 const gfx::Rect& raster_dirty_rect, | 59 const gfx::Rect& raster_dirty_rect, |
85 float scale, | 60 float scale, |
86 const RasterSource::PlaybackSettings& playback_settings, | 61 const RasterSource::PlaybackSettings& playback_settings, |
87 uint64_t resource_content_id, | 62 uint64_t previous_content_id, |
vmpstr
2016/04/06 17:53:01
Thanks!
| |
88 uint64_t previous_content_id); | 63 uint64_t new_content_id); |
89 | 64 |
90 protected: | 65 protected: |
91 OneCopyTileTaskWorkerPool(base::SequencedTaskRunner* task_runner, | 66 OneCopyTileTaskWorkerPool(base::SequencedTaskRunner* task_runner, |
92 TaskGraphRunner* task_graph_runner, | 67 TaskGraphRunner* task_graph_runner, |
93 ResourceProvider* resource_provider, | 68 ResourceProvider* resource_provider, |
94 int max_copy_texture_chromium_size, | 69 int max_copy_texture_chromium_size, |
95 bool use_partial_raster, | 70 bool use_partial_raster, |
96 int max_staging_buffer_usage_in_bytes, | 71 int max_staging_buffer_usage_in_bytes, |
97 ResourceFormat preferred_tile_format); | 72 ResourceFormat preferred_tile_format); |
98 | 73 |
99 private: | 74 private: |
100 struct StagingBuffer { | 75 void PlaybackToStagingBuffer( |
101 StagingBuffer(const gfx::Size& size, ResourceFormat format); | 76 StagingBuffer* staging_buffer, |
102 ~StagingBuffer(); | 77 const Resource* resource, |
78 const RasterSource* raster_source, | |
79 const gfx::Rect& raster_full_rect, | |
80 const gfx::Rect& raster_dirty_rect, | |
81 float scale, | |
82 const RasterSource::PlaybackSettings& playback_settings, | |
83 uint64_t previous_content_id, | |
84 uint64_t new_content_id); | |
85 void CopyOnWorkerThread(StagingBuffer* staging_buffer, | |
86 const Resource* resource, | |
87 ResourceProvider::ScopedWriteLockGL* resource_lock, | |
88 const RasterSource* raster_source, | |
89 uint64_t resource_content_id, | |
vmpstr
2016/04/06 17:53:01
Let's keep the order consistent: previous, then ne
| |
90 uint64_t previous_content_id); | |
103 | 91 |
104 void DestroyGLResources(gpu::gles2::GLES2Interface* gl); | |
105 void OnMemoryDump(base::trace_event::ProcessMemoryDump* pmd, | |
106 ResourceFormat format, | |
107 bool is_free) const; | |
108 | |
109 const gfx::Size size; | |
110 const ResourceFormat format; | |
111 scoped_ptr<gfx::GpuMemoryBuffer> gpu_memory_buffer; | |
112 base::TimeTicks last_usage; | |
113 unsigned texture_id; | |
114 unsigned image_id; | |
115 unsigned query_id; | |
116 uint64_t content_id; | |
117 }; | |
118 | |
119 void AddStagingBuffer(const StagingBuffer* staging_buffer, | |
120 ResourceFormat format); | |
121 void RemoveStagingBuffer(const StagingBuffer* staging_buffer); | |
122 void MarkStagingBufferAsFree(const StagingBuffer* staging_buffer); | |
123 void MarkStagingBufferAsBusy(const StagingBuffer* staging_buffer); | |
124 scoped_ptr<StagingBuffer> AcquireStagingBuffer(const Resource* resource, | |
125 uint64_t previous_content_id); | |
126 base::TimeTicks GetUsageTimeForLRUBuffer(); | |
127 void ScheduleReduceMemoryUsage(); | |
128 void ReduceMemoryUsage(); | |
129 void ReleaseBuffersNotUsedSince(base::TimeTicks time); | |
130 | |
131 scoped_ptr<base::trace_event::ConvertableToTraceFormat> StateAsValue() const; | |
132 void StagingStateAsValueInto( | |
133 base::trace_event::TracedValue* staging_state) const; | |
134 | |
135 scoped_refptr<base::SequencedTaskRunner> task_runner_; | |
136 TaskGraphRunner* task_graph_runner_; | 92 TaskGraphRunner* task_graph_runner_; |
137 const NamespaceToken namespace_token_; | 93 const NamespaceToken namespace_token_; |
138 ResourceProvider* const resource_provider_; | 94 ResourceProvider* const resource_provider_; |
139 const int max_bytes_per_copy_operation_; | 95 const int max_bytes_per_copy_operation_; |
140 const bool use_partial_raster_; | 96 bool use_partial_raster_; |
97 int bytes_scheduled_since_last_flush_; | |
98 ResourceFormat preferred_tile_format_; | |
99 scoped_ptr<StagingBufferPool> staging_pool_; | |
141 | 100 |
142 Task::Vector completed_tasks_; | 101 Task::Vector completed_tasks_; |
143 | 102 |
144 mutable base::Lock lock_; | |
145 // |lock_| must be acquired when accessing the following members. | |
146 using StagingBufferSet = std::set<const StagingBuffer*>; | |
147 StagingBufferSet buffers_; | |
148 using StagingBufferDeque = std::deque<scoped_ptr<StagingBuffer>>; | |
149 StagingBufferDeque free_buffers_; | |
150 StagingBufferDeque busy_buffers_; | |
151 int bytes_scheduled_since_last_flush_; | |
152 const int max_staging_buffer_usage_in_bytes_; | |
153 ResourceFormat preferred_tile_format_; | |
154 int staging_buffer_usage_in_bytes_; | |
155 int free_staging_buffer_usage_in_bytes_; | |
156 const base::TimeDelta staging_buffer_expiration_delay_; | |
157 bool reduce_memory_usage_pending_; | |
158 base::Closure reduce_memory_usage_callback_; | |
159 | |
160 base::WeakPtrFactory<OneCopyTileTaskWorkerPool> weak_ptr_factory_; | |
161 | |
162 DISALLOW_COPY_AND_ASSIGN(OneCopyTileTaskWorkerPool); | 103 DISALLOW_COPY_AND_ASSIGN(OneCopyTileTaskWorkerPool); |
163 }; | 104 }; |
164 | 105 |
165 } // namespace cc | 106 } // namespace cc |
166 | 107 |
167 #endif // CC_RASTER_ONE_COPY_TILE_TASK_WORKER_POOL_H_ | 108 #endif // CC_RASTER_ONE_COPY_TILE_TASK_WORKER_POOL_H_ |
OLD | NEW |