Compute can_use_lcd_text using property trees.
[chromium-blink-merge.git] / cc / raster / bitmap_tile_task_worker_pool.cc
blobbd6af35215c9dbbf1452d92eba88ba82d2349ee9
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 #include "cc/raster/bitmap_tile_task_worker_pool.h"
7 #include <algorithm>
9 #include "base/strings/stringprintf.h"
10 #include "base/trace_event/trace_event.h"
11 #include "base/trace_event/trace_event_argument.h"
12 #include "cc/debug/traced_value.h"
13 #include "cc/playback/raster_source.h"
14 #include "cc/raster/raster_buffer.h"
15 #include "cc/resources/platform_color.h"
16 #include "cc/resources/resource.h"
18 namespace cc {
19 namespace {
21 class RasterBufferImpl : public RasterBuffer {
22 public:
23 RasterBufferImpl(ResourceProvider* resource_provider,
24 const Resource* resource,
25 uint64_t resource_content_id,
26 uint64_t previous_content_id)
27 : lock_(resource_provider, resource->id()),
28 resource_(resource),
29 resource_has_previous_content_(
30 resource_content_id && resource_content_id == previous_content_id) {
33 // Overridden from RasterBuffer:
34 void Playback(const RasterSource* raster_source,
35 const gfx::Rect& raster_full_rect,
36 const gfx::Rect& raster_dirty_rect,
37 uint64_t new_content_id,
38 float scale) override {
39 gfx::Rect playback_rect = raster_full_rect;
40 if (resource_has_previous_content_) {
41 playback_rect.Intersect(raster_dirty_rect);
43 DCHECK(!playback_rect.IsEmpty())
44 << "Why are we rastering a tile that's not dirty?";
46 size_t stride = 0u;
47 TileTaskWorkerPool::PlaybackToMemory(
48 lock_.sk_bitmap().getPixels(), resource_->format(), resource_->size(),
49 stride, raster_source, raster_full_rect, playback_rect, scale);
52 private:
53 ResourceProvider::ScopedWriteLockSoftware lock_;
54 const Resource* resource_;
55 bool resource_has_previous_content_;
57 DISALLOW_COPY_AND_ASSIGN(RasterBufferImpl);
60 } // namespace
62 // static
63 scoped_ptr<TileTaskWorkerPool> BitmapTileTaskWorkerPool::Create(
64 base::SequencedTaskRunner* task_runner,
65 TaskGraphRunner* task_graph_runner,
66 ResourceProvider* resource_provider) {
67 return make_scoped_ptr<TileTaskWorkerPool>(new BitmapTileTaskWorkerPool(
68 task_runner, task_graph_runner, resource_provider));
71 BitmapTileTaskWorkerPool::BitmapTileTaskWorkerPool(
72 base::SequencedTaskRunner* task_runner,
73 TaskGraphRunner* task_graph_runner,
74 ResourceProvider* resource_provider)
75 : task_runner_(task_runner),
76 task_graph_runner_(task_graph_runner),
77 namespace_token_(task_graph_runner->GetNamespaceToken()),
78 resource_provider_(resource_provider),
79 task_set_finished_weak_ptr_factory_(this) {
82 BitmapTileTaskWorkerPool::~BitmapTileTaskWorkerPool() {
85 TileTaskRunner* BitmapTileTaskWorkerPool::AsTileTaskRunner() {
86 return this;
89 void BitmapTileTaskWorkerPool::SetClient(TileTaskRunnerClient* client) {
90 client_ = client;
93 void BitmapTileTaskWorkerPool::Shutdown() {
94 TRACE_EVENT0("cc", "BitmapTileTaskWorkerPool::Shutdown");
96 TaskGraph empty;
97 task_graph_runner_->ScheduleTasks(namespace_token_, &empty);
98 task_graph_runner_->WaitForTasksToFinishRunning(namespace_token_);
101 void BitmapTileTaskWorkerPool::ScheduleTasks(TileTaskQueue* queue) {
102 TRACE_EVENT0("cc", "BitmapTileTaskWorkerPool::ScheduleTasks");
104 if (tasks_pending_.none())
105 TRACE_EVENT_ASYNC_BEGIN0("cc", "ScheduledTasks", this);
107 // Mark all task sets as pending.
108 tasks_pending_.set();
110 size_t priority = kTileTaskPriorityBase;
112 graph_.Reset();
114 // Cancel existing OnTaskSetFinished callbacks.
115 task_set_finished_weak_ptr_factory_.InvalidateWeakPtrs();
117 scoped_refptr<TileTask> new_task_set_finished_tasks[kNumberOfTaskSets];
119 size_t task_count[kNumberOfTaskSets] = {0};
121 for (TaskSet task_set = 0; task_set < kNumberOfTaskSets; ++task_set) {
122 new_task_set_finished_tasks[task_set] = CreateTaskSetFinishedTask(
123 task_runner_.get(),
124 base::Bind(&BitmapTileTaskWorkerPool::OnTaskSetFinished,
125 task_set_finished_weak_ptr_factory_.GetWeakPtr(), task_set));
128 for (TileTaskQueue::Item::Vector::const_iterator it = queue->items.begin();
129 it != queue->items.end(); ++it) {
130 const TileTaskQueue::Item& item = *it;
131 RasterTask* task = item.task;
132 DCHECK(!task->HasCompleted());
134 for (TaskSet task_set = 0; task_set < kNumberOfTaskSets; ++task_set) {
135 if (!item.task_sets[task_set])
136 continue;
138 ++task_count[task_set];
140 graph_.edges.push_back(
141 TaskGraph::Edge(task, new_task_set_finished_tasks[task_set].get()));
144 InsertNodesForRasterTask(&graph_, task, task->dependencies(), priority++);
147 for (TaskSet task_set = 0; task_set < kNumberOfTaskSets; ++task_set) {
148 InsertNodeForTask(&graph_, new_task_set_finished_tasks[task_set].get(),
149 kTaskSetFinishedTaskPriorityBase + task_set,
150 task_count[task_set]);
153 ScheduleTasksOnOriginThread(this, &graph_);
154 task_graph_runner_->ScheduleTasks(namespace_token_, &graph_);
156 std::copy(new_task_set_finished_tasks,
157 new_task_set_finished_tasks + kNumberOfTaskSets,
158 task_set_finished_tasks_);
160 TRACE_EVENT_ASYNC_STEP_INTO1("cc", "ScheduledTasks", this, "running", "state",
161 StateAsValue());
164 void BitmapTileTaskWorkerPool::CheckForCompletedTasks() {
165 TRACE_EVENT0("cc", "BitmapTileTaskWorkerPool::CheckForCompletedTasks");
167 task_graph_runner_->CollectCompletedTasks(namespace_token_,
168 &completed_tasks_);
169 for (Task::Vector::const_iterator it = completed_tasks_.begin();
170 it != completed_tasks_.end(); ++it) {
171 TileTask* task = static_cast<TileTask*>(it->get());
173 task->WillComplete();
174 task->CompleteOnOriginThread(this);
175 task->DidComplete();
177 task->RunReplyOnOriginThread();
179 completed_tasks_.clear();
182 ResourceFormat BitmapTileTaskWorkerPool::GetResourceFormat() const {
183 return resource_provider_->best_texture_format();
186 bool BitmapTileTaskWorkerPool::GetResourceRequiresSwizzle() const {
187 return !PlatformColor::SameComponentOrder(GetResourceFormat());
190 scoped_ptr<RasterBuffer> BitmapTileTaskWorkerPool::AcquireBufferForRaster(
191 const Resource* resource,
192 uint64_t resource_content_id,
193 uint64_t previous_content_id) {
194 return scoped_ptr<RasterBuffer>(new RasterBufferImpl(
195 resource_provider_, resource, resource_content_id, previous_content_id));
198 void BitmapTileTaskWorkerPool::ReleaseBufferForRaster(
199 scoped_ptr<RasterBuffer> buffer) {
200 // Nothing to do here. RasterBufferImpl destructor cleans up after itself.
203 void BitmapTileTaskWorkerPool::OnTaskSetFinished(TaskSet task_set) {
204 TRACE_EVENT1("cc", "BitmapTileTaskWorkerPool::OnTaskSetFinished", "task_set",
205 task_set);
207 DCHECK(tasks_pending_[task_set]);
208 tasks_pending_[task_set] = false;
209 if (tasks_pending_.any()) {
210 TRACE_EVENT_ASYNC_STEP_INTO1("cc", "ScheduledTasks", this, "running",
211 "state", StateAsValue());
212 } else {
213 TRACE_EVENT_ASYNC_END0("cc", "ScheduledTasks", this);
215 client_->DidFinishRunningTileTasks(task_set);
218 scoped_refptr<base::trace_event::ConvertableToTraceFormat>
219 BitmapTileTaskWorkerPool::StateAsValue() const {
220 scoped_refptr<base::trace_event::TracedValue> state =
221 new base::trace_event::TracedValue();
223 state->BeginArray("tasks_pending");
224 for (TaskSet task_set = 0; task_set < kNumberOfTaskSets; ++task_set)
225 state->AppendBoolean(tasks_pending_[task_set]);
226 state->EndArray();
227 return state;
230 } // namespace cc