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/shared_quad_state.h"
16 void* RenderPass::Id::AsTracingId() const {
17 COMPILE_ASSERT(sizeof(size_t) <= sizeof(void*), size_t_bigger_than_pointer
);
18 return reinterpret_cast<void*>(base::HashPair(layer_id
, index
));
21 scoped_ptr
<RenderPass
> RenderPass::Create() {
22 return make_scoped_ptr(new RenderPass
);
25 RenderPass::RenderPass()
27 has_transparent_background(true),
28 has_occlusion_from_outside_target_surface(false) {}
30 RenderPass::~RenderPass() {
31 TRACE_EVENT_OBJECT_DELETED_WITH_ID(
32 TRACE_DISABLED_BY_DEFAULT("cc.debug.quads"),
33 "cc::RenderPass", id
.AsTracingId());
36 scoped_ptr
<RenderPass
> RenderPass::Copy(Id new_id
) const {
37 scoped_ptr
<RenderPass
> copy_pass(Create());
38 copy_pass
->SetAll(new_id
,
41 transform_to_root_target
,
42 has_transparent_background
,
43 has_occlusion_from_outside_target_surface
);
44 return copy_pass
.Pass();
47 void RenderPass::SetNew(Id id
,
48 gfx::Rect output_rect
,
49 gfx::RectF damage_rect
,
50 const gfx::Transform
& transform_to_root_target
) {
51 DCHECK_GT(id
.layer_id
, 0);
52 DCHECK_GE(id
.index
, 0);
55 this->output_rect
= output_rect
;
56 this->damage_rect
= damage_rect
;
57 this->transform_to_root_target
= transform_to_root_target
;
59 DCHECK(quad_list
.empty());
60 DCHECK(shared_quad_state_list
.empty());
63 void RenderPass::SetAll(Id id
,
64 gfx::Rect output_rect
,
65 gfx::RectF damage_rect
,
66 const gfx::Transform
& transform_to_root_target
,
67 bool has_transparent_background
,
68 bool has_occlusion_from_outside_target_surface
) {
69 DCHECK_GT(id
.layer_id
, 0);
70 DCHECK_GE(id
.index
, 0);
73 this->output_rect
= output_rect
;
74 this->damage_rect
= damage_rect
;
75 this->transform_to_root_target
= transform_to_root_target
;
76 this->has_transparent_background
= has_transparent_background
;
77 this->has_occlusion_from_outside_target_surface
=
78 has_occlusion_from_outside_target_surface
;
80 DCHECK(quad_list
.empty());
81 DCHECK(shared_quad_state_list
.empty());
84 scoped_ptr
<base::Value
> RenderPass::AsValue() const {
85 scoped_ptr
<base::DictionaryValue
> value(new base::DictionaryValue());
86 value
->Set("output_rect", MathUtil::AsValue(output_rect
).release());
87 value
->Set("damage_rect", MathUtil::AsValue(damage_rect
).release());
88 value
->SetBoolean("has_transparent_background", has_transparent_background
);
89 value
->SetBoolean("has_occlusion_from_outside_target_surface",
90 has_occlusion_from_outside_target_surface
);
91 value
->SetInteger("copy_requests", copy_requests
.size());
92 scoped_ptr
<base::ListValue
> shared_states_value(new base::ListValue());
93 for (size_t i
= 0; i
< shared_quad_state_list
.size(); ++i
) {
94 shared_states_value
->Append(shared_quad_state_list
[i
]->AsValue().release());
96 value
->Set("shared_quad_state_list", shared_states_value
.release());
97 scoped_ptr
<base::ListValue
> quad_list_value(new base::ListValue());
98 for (size_t i
= 0; i
< quad_list
.size(); ++i
) {
99 quad_list_value
->Append(quad_list
[i
]->AsValue().release());
101 value
->Set("quad_list", quad_list_value
.release());
103 TracedValue::MakeDictIntoImplicitSnapshotWithCategory(
104 TRACE_DISABLED_BY_DEFAULT("cc.debug.quads"),
105 value
.get(), "cc::RenderPass", id
.AsTracingId());
106 return value
.PassAs
<base::Value
>();