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_RESOURCES_ONE_COPY_TILE_TASK_WORKER_POOL_H_
6 #define CC_RESOURCES_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/resources/resource_provider.h"
14 #include "cc/resources/tile_task_runner.h"
15 #include "cc/resources/tile_task_worker_pool.h"
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
);
43 // Overridden from TileTaskWorkerPool:
44 TileTaskRunner
* AsTileTaskRunner() override
;
46 // Overridden from TileTaskRunner:
47 void SetClient(TileTaskRunnerClient
* client
) override
;
48 void Shutdown() override
;
49 void ScheduleTasks(TileTaskQueue
* queue
) override
;
50 void CheckForCompletedTasks() override
;
52 // Overridden from TileTaskClient:
53 scoped_ptr
<RasterBuffer
> AcquireBufferForRaster(
54 const Resource
* resource
) override
;
55 void ReleaseBufferForRaster(scoped_ptr
<RasterBuffer
> buffer
) override
;
57 // Playback raster source and schedule copy of |src| resource to |dst|
58 // resource. Returns a non-zero sequence number for this copy operation.
59 CopySequenceNumber
PlaybackAndScheduleCopyOnWorkerThread(
60 scoped_ptr
<ResourceProvider::ScopedWriteLockGpuMemoryBuffer
> write_lock
,
61 scoped_ptr
<ScopedResource
> src
,
63 const RasterSource
* raster_source
,
64 const gfx::Rect
& rect
,
67 // Issues copy operations until |sequence| has been processed. This will
68 // return immediately if |sequence| has already been processed.
69 void AdvanceLastIssuedCopyTo(CopySequenceNumber sequence
);
72 OneCopyTileTaskWorkerPool(base::SequencedTaskRunner
* task_runner
,
73 TaskGraphRunner
* task_graph_runner
,
74 ContextProvider
* context_provider
,
75 ResourceProvider
* resource_provider
,
76 ResourcePool
* resource_pool
);
79 struct CopyOperation
{
80 typedef ScopedPtrDeque
<CopyOperation
> Deque
;
83 scoped_ptr
<ResourceProvider::ScopedWriteLockGpuMemoryBuffer
> write_lock
,
84 scoped_ptr
<ScopedResource
> src
,
88 scoped_ptr
<ResourceProvider::ScopedWriteLockGpuMemoryBuffer
> write_lock
;
89 scoped_ptr
<ScopedResource
> src
;
93 void OnTaskSetFinished(TaskSet task_set
);
94 void AdvanceLastFlushedCopyTo(CopySequenceNumber sequence
);
95 void IssueCopyOperations(int64 count
);
96 void ScheduleCheckForCompletedCopyOperationsWithLockAcquired(
98 void CheckForCompletedCopyOperations(bool wait_if_needed
);
99 scoped_refptr
<base::debug::ConvertableToTraceFormat
> StateAsValue() const;
100 void StagingStateAsValueInto(base::debug::TracedValue
* staging_state
) const;
102 scoped_refptr
<base::SequencedTaskRunner
> task_runner_
;
103 TaskGraphRunner
* task_graph_runner_
;
104 const NamespaceToken namespace_token_
;
105 TileTaskRunnerClient
* client_
;
106 ContextProvider
* context_provider_
;
107 ResourceProvider
* resource_provider_
;
108 ResourcePool
* resource_pool_
;
109 TaskSetCollection tasks_pending_
;
110 scoped_refptr
<TileTask
> task_set_finished_tasks_
[kNumberOfTaskSets
];
111 CopySequenceNumber last_issued_copy_operation_
;
112 CopySequenceNumber last_flushed_copy_operation_
;
114 // Task graph used when scheduling tasks and vector used to gather
117 Task::Vector completed_tasks_
;
120 // |lock_| must be acquired when accessing the following members.
121 base::ConditionVariable copy_operation_count_cv_
;
122 size_t scheduled_copy_operation_count_
;
123 size_t issued_copy_operation_count_
;
124 CopyOperation::Deque pending_copy_operations_
;
125 CopySequenceNumber next_copy_operation_sequence_
;
126 bool check_for_completed_copy_operations_pending_
;
127 base::TimeTicks last_check_for_completed_copy_operations_time_
;
130 base::WeakPtrFactory
<OneCopyTileTaskWorkerPool
> weak_ptr_factory_
;
131 // "raster finished" tasks need their own factory as they need to be
132 // canceled when ScheduleTasks() is called.
133 base::WeakPtrFactory
<OneCopyTileTaskWorkerPool
>
134 task_set_finished_weak_ptr_factory_
;
136 DISALLOW_COPY_AND_ASSIGN(OneCopyTileTaskWorkerPool
);
141 #endif // CC_RESOURCES_ONE_COPY_TILE_TASK_WORKER_POOL_H_