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_
8 #include "base/memory/weak_ptr.h"
9 #include "base/synchronization/lock.h"
10 #include "base/values.h"
11 #include "cc/base/scoped_ptr_deque.h"
12 #include "cc/output/context_provider.h"
13 #include "cc/raster/tile_task_runner.h"
14 #include "cc/raster/tile_task_worker_pool.h"
15 #include "cc/resources/resource_provider.h"
18 namespace trace_event
{
19 class ConvertableToTraceFormat
;
28 typedef int64 CopySequenceNumber
;
30 class CC_EXPORT OneCopyTileTaskWorkerPool
: public TileTaskWorkerPool
,
31 public TileTaskRunner
,
32 public TileTaskClient
{
34 ~OneCopyTileTaskWorkerPool() override
;
36 static scoped_ptr
<TileTaskWorkerPool
> Create(
37 base::SequencedTaskRunner
* task_runner
,
38 TaskGraphRunner
* task_graph_runner
,
39 ContextProvider
* context_provider
,
40 ResourceProvider
* resource_provider
,
41 ResourcePool
* resource_pool
,
42 int max_copy_texture_chromium_size
,
43 bool have_persistent_gpu_memory_buffers
);
45 // Overridden from TileTaskWorkerPool:
46 TileTaskRunner
* AsTileTaskRunner() override
;
48 // Overridden from TileTaskRunner:
49 void SetClient(TileTaskRunnerClient
* client
) override
;
50 void Shutdown() override
;
51 void ScheduleTasks(TileTaskQueue
* queue
) override
;
52 void CheckForCompletedTasks() override
;
53 ResourceFormat
GetResourceFormat() const override
;
54 bool GetResourceRequiresSwizzle() const override
;
56 // Overridden from TileTaskClient:
57 scoped_ptr
<RasterBuffer
> AcquireBufferForRaster(
58 const Resource
* resource
,
59 uint64_t resource_content_id
,
60 uint64_t previous_content_id
) override
;
61 void ReleaseBufferForRaster(scoped_ptr
<RasterBuffer
> buffer
) override
;
63 // Playback raster source and schedule copy of |raster_resource| resource to
64 // |output_resource|. Returns a non-zero sequence number for this copy
66 CopySequenceNumber
PlaybackAndScheduleCopyOnWorkerThread(
67 bool reusing_raster_resource
,
68 scoped_ptr
<ResourceProvider::ScopedWriteLockGpuMemoryBuffer
>
69 raster_resource_write_lock
,
70 const Resource
* raster_resource
,
71 const Resource
* output_resource
,
72 const RasterSource
* raster_source
,
73 const gfx::Rect
& raster_full_rect
,
74 const gfx::Rect
& raster_dirty_rect
,
78 // Issues copy operations until |sequence| has been processed. This will
79 // return immediately if |sequence| has already been processed.
80 void AdvanceLastIssuedCopyTo(CopySequenceNumber sequence
);
82 bool have_persistent_gpu_memory_buffers() const {
83 return have_persistent_gpu_memory_buffers_
;
87 OneCopyTileTaskWorkerPool(base::SequencedTaskRunner
* task_runner
,
88 TaskGraphRunner
* task_graph_runner
,
89 ContextProvider
* context_provider
,
90 ResourceProvider
* resource_provider
,
91 ResourcePool
* resource_pool
,
92 int max_copy_texture_chromium_size
,
93 bool have_persistent_gpu_memory_buffers
);
96 struct CopyOperation
{
97 typedef ScopedPtrDeque
<CopyOperation
> Deque
;
99 CopyOperation(scoped_ptr
<ResourceProvider::ScopedWriteLockGpuMemoryBuffer
>
103 const gfx::Rect
& rect
);
106 scoped_ptr
<ResourceProvider::ScopedWriteLockGpuMemoryBuffer
> src_write_lock
;
109 const gfx::Rect rect
;
112 void OnTaskSetFinished(TaskSet task_set
);
113 void AdvanceLastFlushedCopyTo(CopySequenceNumber sequence
);
114 void IssueCopyOperations(int64 count
);
115 void ScheduleCheckForCompletedCopyOperationsWithLockAcquired(
116 bool wait_if_needed
);
117 void CheckForCompletedCopyOperations(bool wait_if_needed
);
118 scoped_refptr
<base::trace_event::ConvertableToTraceFormat
> StateAsValue()
120 void StagingStateAsValueInto(
121 base::trace_event::TracedValue
* staging_state
) const;
123 scoped_refptr
<base::SequencedTaskRunner
> task_runner_
;
124 TaskGraphRunner
* task_graph_runner_
;
125 const NamespaceToken namespace_token_
;
126 TileTaskRunnerClient
* client_
;
127 ContextProvider
* context_provider_
;
128 ResourceProvider
* resource_provider_
;
129 ResourcePool
* resource_pool_
;
130 const int max_bytes_per_copy_operation_
;
131 const bool have_persistent_gpu_memory_buffers_
;
132 TaskSetCollection tasks_pending_
;
133 scoped_refptr
<TileTask
> task_set_finished_tasks_
[kNumberOfTaskSets
];
134 CopySequenceNumber last_issued_copy_operation_
;
135 CopySequenceNumber last_flushed_copy_operation_
;
137 // Task graph used when scheduling tasks and vector used to gather
140 Task::Vector completed_tasks_
;
143 // |lock_| must be acquired when accessing the following members.
144 base::ConditionVariable copy_operation_count_cv_
;
145 int bytes_scheduled_since_last_flush_
;
146 size_t issued_copy_operation_count_
;
147 CopyOperation::Deque pending_copy_operations_
;
148 CopySequenceNumber next_copy_operation_sequence_
;
149 bool check_for_completed_copy_operations_pending_
;
150 base::TimeTicks last_check_for_completed_copy_operations_time_
;
153 base::WeakPtrFactory
<OneCopyTileTaskWorkerPool
> weak_ptr_factory_
;
154 // "raster finished" tasks need their own factory as they need to be
155 // canceled when ScheduleTasks() is called.
156 base::WeakPtrFactory
<OneCopyTileTaskWorkerPool
>
157 task_set_finished_weak_ptr_factory_
;
159 DISALLOW_COPY_AND_ASSIGN(OneCopyTileTaskWorkerPool
);
164 #endif // CC_RASTER_ONE_COPY_TILE_TASK_WORKER_POOL_H_