[Do not revert] Roll-back V8 to version 4.4.63.
[chromium-blink-merge.git] / cc / resources / pixel_buffer_tile_task_worker_pool.h
blob82e59163502250e39e5ca224f27446c6a780f094
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_
8 #include <deque>
9 #include <vector>
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"
18 namespace base {
19 namespace trace_event {
20 class ConvertableToTraceFormat;
21 class TracedValue;
25 namespace cc {
26 class ResourceProvider;
28 class CC_EXPORT PixelBufferTileTaskWorkerPool : public TileTaskWorkerPool,
29 public TileTaskRunner,
30 public TileTaskClient {
31 public:
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;
49 ResourceFormat GetResourceFormat() override;
51 // Overridden from TileTaskClient:
52 scoped_ptr<RasterBuffer> AcquireBufferForRaster(
53 const Resource* resource) override;
54 void ReleaseBufferForRaster(scoped_ptr<RasterBuffer> buffer) override;
56 private:
57 struct RasterTaskState {
58 class TaskComparator {
59 public:
60 explicit TaskComparator(const RasterTask* task) : task_(task) {}
62 bool operator()(const RasterTaskState& state) const {
63 return state.task == task_;
66 private:
67 const RasterTask* task_;
70 typedef std::vector<RasterTaskState> Vector;
72 RasterTaskState(RasterTask* task, const TaskSetCollection& task_sets);
74 enum { UNSCHEDULED, SCHEDULED, UPLOADING, COMPLETED } type;
75 RasterTask* task;
76 TaskSetCollection task_sets;
79 typedef std::deque<scoped_refptr<RasterTask>> RasterTaskDeque;
81 PixelBufferTileTaskWorkerPool(base::SequencedTaskRunner* task_runner,
82 TaskGraphRunner* task_graph_runner,
83 ContextProvider* context_provider,
84 ResourceProvider* resource_provider,
85 size_t max_transfer_buffer_usage_bytes);
87 void OnTaskSetFinished(TaskSet task_set);
88 void FlushUploads();
89 void CheckForCompletedUploads();
90 void CheckForCompletedRasterTasks();
91 void ScheduleMoreTasks();
92 unsigned PendingRasterTaskCount() const;
93 TaskSetCollection PendingTasks() const;
94 void CheckForCompletedRasterizerTasks();
96 const char* StateName() const;
97 scoped_refptr<base::trace_event::ConvertableToTraceFormat> StateAsValue()
98 const;
99 void ThrottleStateAsValueInto(
100 base::trace_event::TracedValue* throttle_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_;
109 bool shutdown_;
111 TileTaskQueue raster_tasks_;
112 RasterTaskState::Vector raster_task_states_;
113 RasterTaskDeque raster_tasks_with_pending_upload_;
114 RasterTask::Vector completed_raster_tasks_;
115 TileTask::Vector completed_image_decode_tasks_;
117 size_t scheduled_raster_task_count_;
118 size_t task_counts_[kNumberOfTaskSets];
119 size_t bytes_pending_upload_;
120 size_t max_bytes_pending_upload_;
121 bool has_performed_uploads_since_last_flush_;
123 TaskSetCollection should_notify_client_if_no_tasks_are_pending_;
124 TaskSetCollection task_set_finished_tasks_pending_;
126 DelayedUniqueNotifier check_for_completed_raster_task_notifier_;
128 scoped_refptr<TileTask> task_set_finished_tasks_[kNumberOfTaskSets];
130 // Task graph used when scheduling tasks and vector used to gather
131 // completed tasks.
132 TaskGraph graph_;
133 Task::Vector completed_tasks_;
135 base::WeakPtrFactory<PixelBufferTileTaskWorkerPool>
136 task_set_finished_weak_ptr_factory_;
138 DISALLOW_COPY_AND_ASSIGN(PixelBufferTileTaskWorkerPool);
141 } // namespace cc
143 #endif // CC_RESOURCES_PIXEL_BUFFER_TILE_TASK_WORKER_POOL_H_