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
3 // found in the LICENSE file.
5 #ifndef CC_RASTER_ONE_COPY_TILE_TASK_WORKER_POOL_H_
6 #define CC_RASTER_ONE_COPY_TILE_TASK_WORKER_POOL_H_
10 #include "base/memory/weak_ptr.h"
11 #include "base/synchronization/lock.h"
12 #include "base/time/time.h"
13 #include "base/trace_event/memory_dump_provider.h"
14 #include "base/values.h"
15 #include "cc/base/scoped_ptr_deque.h"
16 #include "cc/output/context_provider.h"
17 #include "cc/raster/tile_task_runner.h"
18 #include "cc/raster/tile_task_worker_pool.h"
19 #include "cc/resources/resource_provider.h"
22 namespace trace_event
{
23 class ConvertableToTraceFormat
;
37 class CC_EXPORT OneCopyTileTaskWorkerPool
38 : public TileTaskWorkerPool
,
39 public TileTaskRunner
,
40 public TileTaskClient
,
41 public base::trace_event::MemoryDumpProvider
{
43 ~OneCopyTileTaskWorkerPool() override
;
45 static scoped_ptr
<TileTaskWorkerPool
> Create(
46 base::SequencedTaskRunner
* task_runner
,
47 TaskGraphRunner
* task_graph_runner
,
48 ContextProvider
* context_provider
,
49 ResourceProvider
* resource_provider
,
50 int max_copy_texture_chromium_size
,
51 bool use_persistent_gpu_memory_buffers
,
52 int max_staging_buffers
);
54 // Overridden from TileTaskWorkerPool:
55 TileTaskRunner
* AsTileTaskRunner() override
;
57 // Overridden from TileTaskRunner:
58 void SetClient(TileTaskRunnerClient
* client
) override
;
59 void Shutdown() override
;
60 void ScheduleTasks(TileTaskQueue
* queue
) override
;
61 void CheckForCompletedTasks() override
;
62 ResourceFormat
GetResourceFormat() const override
;
63 bool GetResourceRequiresSwizzle() const override
;
65 // Overridden from TileTaskClient:
66 scoped_ptr
<RasterBuffer
> AcquireBufferForRaster(
67 const Resource
* resource
,
68 uint64_t resource_content_id
,
69 uint64_t previous_content_id
) override
;
70 void ReleaseBufferForRaster(scoped_ptr
<RasterBuffer
> buffer
) override
;
72 // Overridden from base::trace_event::MemoryDumpProvider:
73 bool OnMemoryDump(const base::trace_event::MemoryDumpArgs
& args
,
74 base::trace_event::ProcessMemoryDump
* pmd
) override
;
76 // Playback raster source and copy result into |resource|.
77 void PlaybackAndCopyOnWorkerThread(
78 const Resource
* resource
,
79 const ResourceProvider::ScopedWriteLockGL
* resource_lock
,
80 const RasterSource
* raster_source
,
81 const gfx::Rect
& raster_full_rect
,
82 const gfx::Rect
& raster_dirty_rect
,
85 uint64_t resource_content_id
,
86 uint64_t previous_content_id
);
89 OneCopyTileTaskWorkerPool(base::SequencedTaskRunner
* task_runner
,
90 TaskGraphRunner
* task_graph_runner
,
91 ResourceProvider
* resource_provider
,
92 int max_copy_texture_chromium_size
,
93 bool use_persistent_gpu_memory_buffers
,
94 int max_staging_buffers
);
97 struct StagingBuffer
{
98 explicit StagingBuffer(const gfx::Size
& size
);
101 void DestroyGLResources(gpu::gles2::GLES2Interface
* gl
);
102 void OnMemoryDump(base::trace_event::ProcessMemoryDump
* pmd
,
103 ResourceFormat format
,
106 const gfx::Size size
;
107 scoped_ptr
<gfx::GpuMemoryBuffer
> gpu_memory_buffer
;
108 base::TimeTicks last_usage
;
115 scoped_ptr
<StagingBuffer
> AcquireStagingBuffer(const Resource
* resource
,
116 uint64_t previous_content_id
);
117 base::TimeTicks
GetUsageTimeForLRUBuffer();
118 void ScheduleReduceMemoryUsage();
119 void ReduceMemoryUsage();
120 void ReleaseBuffersNotUsedSince(base::TimeTicks time
);
122 void OnTaskSetFinished(TaskSet task_set
);
123 scoped_refptr
<base::trace_event::ConvertableToTraceFormat
> StateAsValue()
125 void StagingStateAsValueInto(
126 base::trace_event::TracedValue
* staging_state
) const;
128 scoped_refptr
<base::SequencedTaskRunner
> task_runner_
;
129 TaskGraphRunner
* task_graph_runner_
;
130 const NamespaceToken namespace_token_
;
131 TileTaskRunnerClient
* client_
;
132 ResourceProvider
* const resource_provider_
;
133 const int max_bytes_per_copy_operation_
;
134 const bool use_persistent_gpu_memory_buffers_
;
135 TaskSetCollection tasks_pending_
;
136 scoped_refptr
<TileTask
> task_set_finished_tasks_
[kNumberOfTaskSets
];
138 // Task graph used when scheduling tasks and vector used to gather
141 Task::Vector completed_tasks_
;
143 mutable base::Lock lock_
;
144 // |lock_| must be acquired when accessing the following members.
145 using StagingBufferSet
= std::set
<StagingBuffer
*>;
146 StagingBufferSet buffers_
;
147 using StagingBufferDeque
= ScopedPtrDeque
<StagingBuffer
>;
148 StagingBufferDeque free_buffers_
;
149 StagingBufferDeque busy_buffers_
;
150 int bytes_scheduled_since_last_flush_
;
151 size_t max_staging_buffers_
;
152 const base::TimeDelta staging_buffer_expiration_delay_
;
153 bool reduce_memory_usage_pending_
;
154 base::Closure reduce_memory_usage_callback_
;
156 base::WeakPtrFactory
<OneCopyTileTaskWorkerPool
> weak_ptr_factory_
;
157 // "raster finished" tasks need their own factory as they need to be
158 // canceled when ScheduleTasks() is called.
159 base::WeakPtrFactory
<OneCopyTileTaskWorkerPool
>
160 task_set_finished_weak_ptr_factory_
;
162 DISALLOW_COPY_AND_ASSIGN(OneCopyTileTaskWorkerPool
);
167 #endif // CC_RASTER_ONE_COPY_TILE_TASK_WORKER_POOL_H_