1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
|
// Copyright 2013 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CC_RESOURCES_PIXEL_BUFFER_RASTER_WORKER_POOL_H_
#define CC_RESOURCES_PIXEL_BUFFER_RASTER_WORKER_POOL_H_
#include <deque>
#include <vector>
#include "base/memory/weak_ptr.h"
#include "base/values.h"
#include "cc/base/delayed_unique_notifier.h"
#include "cc/output/context_provider.h"
#include "cc/resources/raster_worker_pool.h"
#include "cc/resources/rasterizer.h"
namespace base {
namespace debug {
class ConvertableToTraceFormat;
class TracedValue;
}
}
namespace cc {
class ResourceProvider;
class CC_EXPORT PixelBufferRasterWorkerPool : public RasterWorkerPool,
public Rasterizer,
public RasterizerTaskClient {
public:
virtual ~PixelBufferRasterWorkerPool();
static scoped_ptr<RasterWorkerPool> Create(
base::SequencedTaskRunner* task_runner,
TaskGraphRunner* task_graph_runner,
ContextProvider* context_provider,
ResourceProvider* resource_provider,
size_t max_transfer_buffer_usage_bytes);
// Overridden from RasterWorkerPool:
virtual Rasterizer* AsRasterizer() override;
// Overridden from Rasterizer:
virtual void SetClient(RasterizerClient* client) override;
virtual void Shutdown() override;
virtual void ScheduleTasks(RasterTaskQueue* queue) override;
virtual void CheckForCompletedTasks() override;
// Overridden from RasterizerTaskClient:
virtual scoped_ptr<RasterBuffer> AcquireBufferForRaster(
const Resource* resource) override;
virtual void ReleaseBufferForRaster(scoped_ptr<RasterBuffer> buffer) override;
private:
struct RasterTaskState {
class TaskComparator {
public:
explicit TaskComparator(const RasterTask* task) : task_(task) {}
bool operator()(const RasterTaskState& state) const {
return state.task == task_;
}
private:
const RasterTask* task_;
};
typedef std::vector<RasterTaskState> Vector;
RasterTaskState(RasterTask* task, const TaskSetCollection& task_sets);
enum { UNSCHEDULED, SCHEDULED, UPLOADING, COMPLETED } type;
RasterTask* task;
TaskSetCollection task_sets;
};
typedef std::deque<scoped_refptr<RasterTask> > RasterTaskDeque;
PixelBufferRasterWorkerPool(base::SequencedTaskRunner* task_runner,
TaskGraphRunner* task_graph_runner,
ContextProvider* context_provider,
ResourceProvider* resource_provider,
size_t max_transfer_buffer_usage_bytes);
void OnRasterFinished(TaskSet task_set);
void FlushUploads();
void CheckForCompletedUploads();
void CheckForCompletedRasterTasks();
void ScheduleMoreTasks();
unsigned PendingRasterTaskCount() const;
TaskSetCollection PendingTasks() const;
void CheckForCompletedRasterizerTasks();
const char* StateName() const;
scoped_refptr<base::debug::ConvertableToTraceFormat> StateAsValue() const;
void ThrottleStateAsValueInto(base::debug::TracedValue* throttle_state) const;
scoped_refptr<base::SequencedTaskRunner> task_runner_;
TaskGraphRunner* task_graph_runner_;
const NamespaceToken namespace_token_;
RasterizerClient* client_;
ContextProvider* context_provider_;
ResourceProvider* resource_provider_;
bool shutdown_;
RasterTaskQueue raster_tasks_;
RasterTaskState::Vector raster_task_states_;
RasterTaskDeque raster_tasks_with_pending_upload_;
RasterTask::Vector completed_raster_tasks_;
RasterizerTask::Vector completed_image_decode_tasks_;
size_t scheduled_raster_task_count_;
size_t task_counts_[kNumberOfTaskSets];
size_t bytes_pending_upload_;
size_t max_bytes_pending_upload_;
bool has_performed_uploads_since_last_flush_;
TaskSetCollection should_notify_client_if_no_tasks_are_pending_;
TaskSetCollection raster_finished_tasks_pending_;
DelayedUniqueNotifier check_for_completed_raster_task_notifier_;
scoped_refptr<RasterizerTask> raster_finished_tasks_[kNumberOfTaskSets];
// Task graph used when scheduling tasks and vector used to gather
// completed tasks.
TaskGraph graph_;
Task::Vector completed_tasks_;
base::WeakPtrFactory<PixelBufferRasterWorkerPool>
raster_finished_weak_ptr_factory_;
DISALLOW_COPY_AND_ASSIGN(PixelBufferRasterWorkerPool);
};
} // namespace cc
#endif // CC_RESOURCES_PIXEL_BUFFER_RASTER_WORKER_POOL_H_
|