Revert 268405 "Make sure that ScratchBuffer::Allocate() always r..."
[chromium-blink-merge.git] / cc / resources / rasterizer_delegate.cc
blobdcceb1f2155c747b4a5edd4a1a438c4f1c88a6a8
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/resources/rasterizer_delegate.h"
7 #include "base/debug/trace_event.h"
9 namespace cc {
11 RasterizerDelegate::RasterizerDelegate(RasterizerClient* client,
12 Rasterizer** rasterizers,
13 size_t num_rasterizers)
14 : client_(client),
15 rasterizers_(rasterizers, rasterizers + num_rasterizers),
16 did_finish_running_tasks_pending_count_(0u),
17 did_finish_running_tasks_required_for_activation_pending_count_(0u) {
18 DCHECK(client_);
19 for (RasterizerVector::iterator it = rasterizers_.begin();
20 it != rasterizers_.end();
21 ++it)
22 (*it)->SetClient(this);
25 RasterizerDelegate::~RasterizerDelegate() {}
27 // static
28 scoped_ptr<RasterizerDelegate> RasterizerDelegate::Create(
29 RasterizerClient* client,
30 Rasterizer** rasterizers,
31 size_t num_rasterizers) {
32 return make_scoped_ptr(
33 new RasterizerDelegate(client, rasterizers, num_rasterizers));
36 void RasterizerDelegate::Shutdown() {
37 for (RasterizerVector::iterator it = rasterizers_.begin();
38 it != rasterizers_.end();
39 ++it)
40 (*it)->Shutdown();
43 void RasterizerDelegate::ScheduleTasks(RasterTaskQueue* queue) {
44 for (size_t i = 0; i < rasterizers_.size(); ++i)
45 rasterizers_[i]->ScheduleTasks(&queue[i]);
47 did_finish_running_tasks_pending_count_ = rasterizers_.size();
48 did_finish_running_tasks_required_for_activation_pending_count_ =
49 rasterizers_.size();
52 void RasterizerDelegate::CheckForCompletedTasks() {
53 for (RasterizerVector::iterator it = rasterizers_.begin();
54 it != rasterizers_.end();
55 ++it)
56 (*it)->CheckForCompletedTasks();
59 bool RasterizerDelegate::ShouldForceTasksRequiredForActivationToComplete()
60 const {
61 return client_->ShouldForceTasksRequiredForActivationToComplete();
64 void RasterizerDelegate::DidFinishRunningTasks() {
65 TRACE_EVENT1("cc",
66 "RasterizerDelegate::DidFinishRunningTasks",
67 "pending_count",
68 did_finish_running_tasks_pending_count_);
70 DCHECK_LT(0u, did_finish_running_tasks_pending_count_);
71 if (--did_finish_running_tasks_pending_count_)
72 return;
73 client_->DidFinishRunningTasks();
76 void RasterizerDelegate::DidFinishRunningTasksRequiredForActivation() {
77 TRACE_EVENT1("cc",
78 "RasterizerDelegate::DidFinishRunningTasksRequiredForActivation",
79 "pending_count",
80 did_finish_running_tasks_required_for_activation_pending_count_);
82 DCHECK_LT(0u,
83 did_finish_running_tasks_required_for_activation_pending_count_);
84 if (--did_finish_running_tasks_required_for_activation_pending_count_)
85 return;
86 client_->DidFinishRunningTasksRequiredForActivation();
89 } // namespace cc