Add default implementations for AppWindowRegistry::Observer notifications.
[chromium-blink-merge.git] / cc / quads / render_pass.cc
blob535cb63f451b03a8c0d2457cbc89ee5f4384097e
1 // Copyright 2011 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/quads/render_pass.h"
7 #include "base/values.h"
8 #include "cc/base/math_util.h"
9 #include "cc/debug/traced_value.h"
10 #include "cc/output/copy_output_request.h"
11 #include "cc/quads/draw_quad.h"
12 #include "cc/quads/render_pass_draw_quad.h"
13 #include "cc/quads/shared_quad_state.h"
15 namespace {
16 const size_t kDefaultNumSharedQuadStatesToReserve = 32;
17 const size_t kDefaultNumQuadsToReserve = 128;
20 namespace cc {
22 void* RenderPass::Id::AsTracingId() const {
23 COMPILE_ASSERT(sizeof(size_t) <= sizeof(void*), // NOLINT(runtime/sizeof)
24 size_t_bigger_than_pointer);
25 return reinterpret_cast<void*>(base::HashPair(layer_id, index));
28 scoped_ptr<RenderPass> RenderPass::Create() {
29 return make_scoped_ptr(new RenderPass());
32 scoped_ptr<RenderPass> RenderPass::Create(size_t num_layers) {
33 return make_scoped_ptr(new RenderPass(num_layers));
36 RenderPass::RenderPass() : id(Id(-1, -1)), has_transparent_background(true) {
37 shared_quad_state_list.reserve(kDefaultNumSharedQuadStatesToReserve);
38 quad_list.reserve(kDefaultNumQuadsToReserve);
41 RenderPass::RenderPass(size_t num_layers)
42 : id(Id(-1, -1)), has_transparent_background(true) {
43 // Each layer usually produces one shared quad state, so the number of layers
44 // is a good hint for what to reserve here.
45 shared_quad_state_list.reserve(num_layers);
46 quad_list.reserve(kDefaultNumQuadsToReserve);
49 RenderPass::~RenderPass() {
50 TRACE_EVENT_OBJECT_DELETED_WITH_ID(
51 TRACE_DISABLED_BY_DEFAULT("cc.debug.quads"),
52 "cc::RenderPass", id.AsTracingId());
55 scoped_ptr<RenderPass> RenderPass::Copy(Id new_id) const {
56 scoped_ptr<RenderPass> copy_pass(Create());
57 copy_pass->SetAll(new_id,
58 output_rect,
59 damage_rect,
60 transform_to_root_target,
61 has_transparent_background);
62 return copy_pass.Pass();
65 // static
66 void RenderPass::CopyAll(const ScopedPtrVector<RenderPass>& in,
67 ScopedPtrVector<RenderPass>* out) {
68 for (size_t i = 0; i < in.size(); ++i) {
69 RenderPass* source = in[i];
71 // Since we can't copy these, it's wrong to use CopyAll in a situation where
72 // you may have copy_requests present.
73 DCHECK_EQ(source->copy_requests.size(), 0u);
75 scoped_ptr<RenderPass> copy_pass(Create());
76 copy_pass->SetAll(source->id,
77 source->output_rect,
78 source->damage_rect,
79 source->transform_to_root_target,
80 source->has_transparent_background);
81 for (size_t i = 0; i < source->shared_quad_state_list.size(); ++i) {
82 SharedQuadState* copy_shared_quad_state =
83 copy_pass->CreateAndAppendSharedQuadState();
84 copy_shared_quad_state->CopyFrom(source->shared_quad_state_list[i]);
86 for (size_t i = 0, sqs_i = 0; i < source->quad_list.size(); ++i) {
87 while (source->quad_list[i]->shared_quad_state !=
88 source->shared_quad_state_list[sqs_i]) {
89 ++sqs_i;
90 DCHECK_LT(sqs_i, source->shared_quad_state_list.size());
92 DCHECK(source->quad_list[i]->shared_quad_state ==
93 source->shared_quad_state_list[sqs_i]);
95 DrawQuad* quad = source->quad_list[i];
97 if (quad->material == DrawQuad::RENDER_PASS) {
98 const RenderPassDrawQuad* pass_quad =
99 RenderPassDrawQuad::MaterialCast(quad);
100 copy_pass->quad_list.push_back(
101 pass_quad->Copy(copy_pass->shared_quad_state_list[sqs_i],
102 pass_quad->render_pass_id).PassAs<DrawQuad>());
103 } else {
104 copy_pass->quad_list.push_back(source->quad_list[i]->Copy(
105 copy_pass->shared_quad_state_list[sqs_i]));
108 out->push_back(copy_pass.Pass());
112 void RenderPass::SetNew(Id id,
113 const gfx::Rect& output_rect,
114 const gfx::Rect& damage_rect,
115 const gfx::Transform& transform_to_root_target) {
116 DCHECK_GT(id.layer_id, 0);
117 DCHECK_GE(id.index, 0);
118 DCHECK(damage_rect.IsEmpty() || output_rect.Contains(damage_rect))
119 << "damage_rect: " << damage_rect.ToString()
120 << " output_rect: " << output_rect.ToString();
122 this->id = id;
123 this->output_rect = output_rect;
124 this->damage_rect = damage_rect;
125 this->transform_to_root_target = transform_to_root_target;
127 DCHECK(quad_list.empty());
128 DCHECK(shared_quad_state_list.empty());
131 void RenderPass::SetAll(Id id,
132 const gfx::Rect& output_rect,
133 const gfx::Rect& damage_rect,
134 const gfx::Transform& transform_to_root_target,
135 bool has_transparent_background) {
136 DCHECK_GT(id.layer_id, 0);
137 DCHECK_GE(id.index, 0);
139 this->id = id;
140 this->output_rect = output_rect;
141 this->damage_rect = damage_rect;
142 this->transform_to_root_target = transform_to_root_target;
143 this->has_transparent_background = has_transparent_background;
145 DCHECK(quad_list.empty());
146 DCHECK(shared_quad_state_list.empty());
149 scoped_ptr<base::Value> RenderPass::AsValue() const {
150 scoped_ptr<base::DictionaryValue> value(new base::DictionaryValue());
151 value->Set("output_rect", MathUtil::AsValue(output_rect).release());
152 value->Set("damage_rect", MathUtil::AsValue(damage_rect).release());
153 value->SetBoolean("has_transparent_background", has_transparent_background);
154 value->SetInteger("copy_requests", copy_requests.size());
155 scoped_ptr<base::ListValue> shared_states_value(new base::ListValue());
156 for (size_t i = 0; i < shared_quad_state_list.size(); ++i) {
157 shared_states_value->Append(shared_quad_state_list[i]->AsValue().release());
159 value->Set("shared_quad_state_list", shared_states_value.release());
160 scoped_ptr<base::ListValue> quad_list_value(new base::ListValue());
161 for (size_t i = 0; i < quad_list.size(); ++i) {
162 quad_list_value->Append(quad_list[i]->AsValue().release());
164 value->Set("quad_list", quad_list_value.release());
166 TracedValue::MakeDictIntoImplicitSnapshotWithCategory(
167 TRACE_DISABLED_BY_DEFAULT("cc.debug.quads"),
168 value.get(), "cc::RenderPass", id.AsTracingId());
169 return value.PassAs<base::Value>();
172 SharedQuadState* RenderPass::CreateAndAppendSharedQuadState() {
173 shared_quad_state_list.push_back(SharedQuadState::Create());
174 return shared_quad_state_list.back();
177 } // namespace cc