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
,
77 // Issues copy operations until |sequence| has been processed. This will
78 // return immediately if |sequence| has already been processed.
79 void AdvanceLastIssuedCopyTo(CopySequenceNumber sequence
);
81 bool have_persistent_gpu_memory_buffers() const {
82 return have_persistent_gpu_memory_buffers_
;
86 OneCopyTileTaskWorkerPool(base::SequencedTaskRunner
* task_runner
,
87 TaskGraphRunner
* task_graph_runner
,
88 ContextProvider
* context_provider
,
89 ResourceProvider
* resource_provider
,
90 ResourcePool
* resource_pool
,
91 int max_copy_texture_chromium_size
,
92 bool have_persistent_gpu_memory_buffers
);
95 struct CopyOperation
{
96 typedef ScopedPtrDeque
<CopyOperation
> Deque
;
98 CopyOperation(scoped_ptr
<ResourceProvider::ScopedWriteLockGpuMemoryBuffer
>
102 const gfx::Rect
& rect
);
105 scoped_ptr
<ResourceProvider::ScopedWriteLockGpuMemoryBuffer
> src_write_lock
;
108 const gfx::Rect rect
;
111 void OnTaskSetFinished(TaskSet task_set
);
112 void AdvanceLastFlushedCopyTo(CopySequenceNumber sequence
);
113 void IssueCopyOperations(int64 count
);
114 void ScheduleCheckForCompletedCopyOperationsWithLockAcquired(
115 bool wait_if_needed
);
116 void CheckForCompletedCopyOperations(bool wait_if_needed
);
117 scoped_refptr
<base::trace_event::ConvertableToTraceFormat
> StateAsValue()
119 void StagingStateAsValueInto(
120 base::trace_event::TracedValue
* staging_state
) const;
122 scoped_refptr
<base::SequencedTaskRunner
> task_runner_
;
123 TaskGraphRunner
* task_graph_runner_
;
124 const NamespaceToken namespace_token_
;
125 TileTaskRunnerClient
* client_
;
126 ContextProvider
* context_provider_
;
127 ResourceProvider
* resource_provider_
;
128 ResourcePool
* resource_pool_
;
129 const int max_bytes_per_copy_operation_
;
130 const bool have_persistent_gpu_memory_buffers_
;
131 TaskSetCollection tasks_pending_
;
132 scoped_refptr
<TileTask
> task_set_finished_tasks_
[kNumberOfTaskSets
];
133 CopySequenceNumber last_issued_copy_operation_
;
134 CopySequenceNumber last_flushed_copy_operation_
;
136 // Task graph used when scheduling tasks and vector used to gather
139 Task::Vector completed_tasks_
;
142 // |lock_| must be acquired when accessing the following members.
143 base::ConditionVariable copy_operation_count_cv_
;
144 int bytes_scheduled_since_last_flush_
;
145 size_t issued_copy_operation_count_
;
146 CopyOperation::Deque pending_copy_operations_
;
147 CopySequenceNumber next_copy_operation_sequence_
;
148 bool check_for_completed_copy_operations_pending_
;
149 base::TimeTicks last_check_for_completed_copy_operations_time_
;
152 base::WeakPtrFactory
<OneCopyTileTaskWorkerPool
> weak_ptr_factory_
;
153 // "raster finished" tasks need their own factory as they need to be
154 // canceled when ScheduleTasks() is called.
155 base::WeakPtrFactory
<OneCopyTileTaskWorkerPool
>
156 task_set_finished_weak_ptr_factory_
;
158 DISALLOW_COPY_AND_ASSIGN(OneCopyTileTaskWorkerPool
);
163 #endif // CC_RASTER_ONE_COPY_TILE_TASK_WORKER_POOL_H_