1 // Copyright 2013 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_PIXEL_BUFFER_TILE_TASK_WORKER_POOL_H_
6 #define CC_RESOURCES_PIXEL_BUFFER_TILE_TASK_WORKER_POOL_H_
11 #include "base/memory/weak_ptr.h"
12 #include "base/values.h"
13 #include "cc/base/delayed_unique_notifier.h"
14 #include "cc/output/context_provider.h"
15 #include "cc/resources/tile_task_runner.h"
16 #include "cc/resources/tile_task_worker_pool.h"
20 class ConvertableToTraceFormat
;
26 class ResourceProvider
;
28 class CC_EXPORT PixelBufferTileTaskWorkerPool
: public TileTaskWorkerPool
,
29 public TileTaskRunner
,
30 public TileTaskClient
{
32 ~PixelBufferTileTaskWorkerPool() override
;
34 static scoped_ptr
<TileTaskWorkerPool
> Create(
35 base::SequencedTaskRunner
* task_runner
,
36 TaskGraphRunner
* task_graph_runner
,
37 ContextProvider
* context_provider
,
38 ResourceProvider
* resource_provider
,
39 size_t max_transfer_buffer_usage_bytes
);
41 // Overridden from TileTaskWorkerPool:
42 TileTaskRunner
* AsTileTaskRunner() override
;
44 // Overridden from TileTaskRunner:
45 void SetClient(TileTaskRunnerClient
* client
) override
;
46 void Shutdown() override
;
47 void ScheduleTasks(TileTaskQueue
* queue
) override
;
48 void CheckForCompletedTasks() override
;
50 // Overridden from TileTaskClient:
51 scoped_ptr
<RasterBuffer
> AcquireBufferForRaster(
52 const Resource
* resource
) override
;
53 void ReleaseBufferForRaster(scoped_ptr
<RasterBuffer
> buffer
) override
;
56 struct RasterTaskState
{
57 class TaskComparator
{
59 explicit TaskComparator(const RasterTask
* task
) : task_(task
) {}
61 bool operator()(const RasterTaskState
& state
) const {
62 return state
.task
== task_
;
66 const RasterTask
* task_
;
69 typedef std::vector
<RasterTaskState
> Vector
;
71 RasterTaskState(RasterTask
* task
, const TaskSetCollection
& task_sets
);
73 enum { UNSCHEDULED
, SCHEDULED
, UPLOADING
, COMPLETED
} type
;
75 TaskSetCollection task_sets
;
78 typedef std::deque
<scoped_refptr
<RasterTask
>> RasterTaskDeque
;
80 PixelBufferTileTaskWorkerPool(base::SequencedTaskRunner
* task_runner
,
81 TaskGraphRunner
* task_graph_runner
,
82 ContextProvider
* context_provider
,
83 ResourceProvider
* resource_provider
,
84 size_t max_transfer_buffer_usage_bytes
);
86 void OnTaskSetFinished(TaskSet task_set
);
88 void CheckForCompletedUploads();
89 void CheckForCompletedRasterTasks();
90 void ScheduleMoreTasks();
91 unsigned PendingRasterTaskCount() const;
92 TaskSetCollection
PendingTasks() const;
93 void CheckForCompletedRasterizerTasks();
95 const char* StateName() const;
96 scoped_refptr
<base::debug::ConvertableToTraceFormat
> StateAsValue() const;
97 void ThrottleStateAsValueInto(base::debug::TracedValue
* throttle_state
) const;
99 scoped_refptr
<base::SequencedTaskRunner
> task_runner_
;
100 TaskGraphRunner
* task_graph_runner_
;
101 const NamespaceToken namespace_token_
;
102 TileTaskRunnerClient
* client_
;
103 ContextProvider
* context_provider_
;
104 ResourceProvider
* resource_provider_
;
108 TileTaskQueue raster_tasks_
;
109 RasterTaskState::Vector raster_task_states_
;
110 RasterTaskDeque raster_tasks_with_pending_upload_
;
111 RasterTask::Vector completed_raster_tasks_
;
112 TileTask::Vector completed_image_decode_tasks_
;
114 size_t scheduled_raster_task_count_
;
115 size_t task_counts_
[kNumberOfTaskSets
];
116 size_t bytes_pending_upload_
;
117 size_t max_bytes_pending_upload_
;
118 bool has_performed_uploads_since_last_flush_
;
120 TaskSetCollection should_notify_client_if_no_tasks_are_pending_
;
121 TaskSetCollection task_set_finished_tasks_pending_
;
123 DelayedUniqueNotifier check_for_completed_raster_task_notifier_
;
125 scoped_refptr
<TileTask
> task_set_finished_tasks_
[kNumberOfTaskSets
];
127 // Task graph used when scheduling tasks and vector used to gather
130 Task::Vector completed_tasks_
;
132 base::WeakPtrFactory
<PixelBufferTileTaskWorkerPool
>
133 task_set_finished_weak_ptr_factory_
;
135 DISALLOW_COPY_AND_ASSIGN(PixelBufferTileTaskWorkerPool
);
140 #endif // CC_RESOURCES_PIXEL_BUFFER_TILE_TASK_WORKER_POOL_H_