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"
17 void* RenderPass::Id::AsTracingId() const {
18 COMPILE_ASSERT(sizeof(size_t) <= sizeof(void*), // NOLINT(runtime/sizeof)
19 size_t_bigger_than_pointer
);
20 return reinterpret_cast<void*>(base::HashPair(layer_id
, index
));
23 scoped_ptr
<RenderPass
> RenderPass::Create() {
24 return make_scoped_ptr(new RenderPass
);
27 RenderPass::RenderPass()
29 has_transparent_background(true) {}
31 RenderPass::~RenderPass() {
32 TRACE_EVENT_OBJECT_DELETED_WITH_ID(
33 TRACE_DISABLED_BY_DEFAULT("cc.debug.quads"),
34 "cc::RenderPass", id
.AsTracingId());
37 scoped_ptr
<RenderPass
> RenderPass::Copy(Id new_id
) const {
38 scoped_ptr
<RenderPass
> copy_pass(Create());
39 copy_pass
->SetAll(new_id
,
42 transform_to_root_target
,
43 has_transparent_background
);
44 return copy_pass
.Pass();
48 void RenderPass::CopyAll(const ScopedPtrVector
<RenderPass
>& in
,
49 ScopedPtrVector
<RenderPass
>* out
) {
50 for (size_t i
= 0; i
< in
.size(); ++i
) {
51 RenderPass
* source
= in
[i
];
53 // Since we can't copy these, it's wrong to use CopyAll in a situation where
54 // you may have copy_requests present.
55 DCHECK_EQ(source
->copy_requests
.size(), 0u);
57 scoped_ptr
<RenderPass
> copy_pass(Create());
58 copy_pass
->SetAll(source
->id
,
61 source
->transform_to_root_target
,
62 source
->has_transparent_background
);
63 for (size_t i
= 0; i
< source
->shared_quad_state_list
.size(); ++i
) {
64 copy_pass
->shared_quad_state_list
.push_back(
65 source
->shared_quad_state_list
[i
]->Copy());
67 for (size_t i
= 0, sqs_i
= 0; i
< source
->quad_list
.size(); ++i
) {
68 if (source
->quad_list
[i
]->shared_quad_state
!=
69 source
->shared_quad_state_list
[sqs_i
])
71 DCHECK(sqs_i
< source
->shared_quad_state_list
.size());
72 DCHECK(source
->quad_list
[i
]->shared_quad_state
==
73 source
->shared_quad_state_list
[sqs_i
]);
75 DrawQuad
* quad
= source
->quad_list
[i
];
77 if (quad
->material
== DrawQuad::RENDER_PASS
) {
78 const RenderPassDrawQuad
* pass_quad
=
79 RenderPassDrawQuad::MaterialCast(quad
);
80 copy_pass
->quad_list
.push_back(
81 pass_quad
->Copy(copy_pass
->shared_quad_state_list
[sqs_i
],
82 pass_quad
->render_pass_id
).PassAs
<DrawQuad
>());
84 copy_pass
->quad_list
.push_back(source
->quad_list
[i
]->Copy(
85 copy_pass
->shared_quad_state_list
[sqs_i
]));
88 out
->push_back(copy_pass
.Pass());
92 void RenderPass::SetNew(Id id
,
93 gfx::Rect output_rect
,
94 gfx::RectF damage_rect
,
95 const gfx::Transform
& transform_to_root_target
) {
96 DCHECK_GT(id
.layer_id
, 0);
97 DCHECK_GE(id
.index
, 0);
100 this->output_rect
= output_rect
;
101 this->damage_rect
= damage_rect
;
102 this->transform_to_root_target
= transform_to_root_target
;
104 DCHECK(quad_list
.empty());
105 DCHECK(shared_quad_state_list
.empty());
108 void RenderPass::SetAll(Id id
,
109 gfx::Rect output_rect
,
110 gfx::RectF damage_rect
,
111 const gfx::Transform
& transform_to_root_target
,
112 bool has_transparent_background
) {
113 DCHECK_GT(id
.layer_id
, 0);
114 DCHECK_GE(id
.index
, 0);
117 this->output_rect
= output_rect
;
118 this->damage_rect
= damage_rect
;
119 this->transform_to_root_target
= transform_to_root_target
;
120 this->has_transparent_background
= has_transparent_background
;
122 DCHECK(quad_list
.empty());
123 DCHECK(shared_quad_state_list
.empty());
126 scoped_ptr
<base::Value
> RenderPass::AsValue() const {
127 scoped_ptr
<base::DictionaryValue
> value(new base::DictionaryValue());
128 value
->Set("output_rect", MathUtil::AsValue(output_rect
).release());
129 value
->Set("damage_rect", MathUtil::AsValue(damage_rect
).release());
130 value
->SetBoolean("has_transparent_background", has_transparent_background
);
131 value
->SetInteger("copy_requests", copy_requests
.size());
132 scoped_ptr
<base::ListValue
> shared_states_value(new base::ListValue());
133 for (size_t i
= 0; i
< shared_quad_state_list
.size(); ++i
) {
134 shared_states_value
->Append(shared_quad_state_list
[i
]->AsValue().release());
136 value
->Set("shared_quad_state_list", shared_states_value
.release());
137 scoped_ptr
<base::ListValue
> quad_list_value(new base::ListValue());
138 for (size_t i
= 0; i
< quad_list
.size(); ++i
) {
139 quad_list_value
->Append(quad_list
[i
]->AsValue().release());
141 value
->Set("quad_list", quad_list_value
.release());
143 TracedValue::MakeDictIntoImplicitSnapshotWithCategory(
144 TRACE_DISABLED_BY_DEFAULT("cc.debug.quads"),
145 value
.get(), "cc::RenderPass", id
.AsTracingId());
146 return value
.PassAs
<base::Value
>();