1 // Copyright 2012 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/draw_quad.h"
7 #include "base/logging.h"
8 #include "base/values.h"
9 #include "cc/base/math_util.h"
10 #include "cc/debug/traced_value.h"
11 #include "cc/quads/checkerboard_draw_quad.h"
12 #include "cc/quads/debug_border_draw_quad.h"
13 #include "cc/quads/io_surface_draw_quad.h"
14 #include "cc/quads/picture_draw_quad.h"
15 #include "cc/quads/render_pass_draw_quad.h"
16 #include "cc/quads/solid_color_draw_quad.h"
17 #include "cc/quads/stream_video_draw_quad.h"
18 #include "cc/quads/texture_draw_quad.h"
19 #include "cc/quads/tile_draw_quad.h"
20 #include "cc/quads/yuv_video_draw_quad.h"
21 #include "ui/gfx/quad_f.h"
24 template<typename T
> T
* TypedCopy(const cc::DrawQuad
* other
) {
25 return new T(*T::MaterialCast(other
));
33 needs_blending(false),
37 void DrawQuad::SetAll(const SharedQuadState
* shared_quad_state
,
40 gfx::Rect opaque_rect
,
41 gfx::Rect visible_rect
,
42 bool needs_blending
) {
43 this->material
= material
;
45 this->opaque_rect
= opaque_rect
;
46 this->visible_rect
= visible_rect
;
47 this->needs_blending
= needs_blending
;
48 this->shared_quad_state
= shared_quad_state
;
50 DCHECK(shared_quad_state
);
51 DCHECK(material
!= INVALID
);
54 DrawQuad::~DrawQuad() {
57 scoped_ptr
<DrawQuad
> DrawQuad::Copy(
58 const SharedQuadState
* copied_shared_quad_state
) const {
59 scoped_ptr
<DrawQuad
> copy_quad
;
62 copy_quad
.reset(TypedCopy
<CheckerboardDrawQuad
>(this));
65 copy_quad
.reset(TypedCopy
<DebugBorderDrawQuad
>(this));
67 case IO_SURFACE_CONTENT
:
68 copy_quad
.reset(TypedCopy
<IOSurfaceDrawQuad
>(this));
71 copy_quad
.reset(TypedCopy
<PictureDrawQuad
>(this));
74 copy_quad
.reset(TypedCopy
<TextureDrawQuad
>(this));
77 copy_quad
.reset(TypedCopy
<SolidColorDrawQuad
>(this));
80 copy_quad
.reset(TypedCopy
<TileDrawQuad
>(this));
82 case STREAM_VIDEO_CONTENT
:
83 copy_quad
.reset(TypedCopy
<StreamVideoDrawQuad
>(this));
85 case YUV_VIDEO_CONTENT
:
86 copy_quad
.reset(TypedCopy
<YUVVideoDrawQuad
>(this));
88 case RENDER_PASS
: // RenderPass quads have their own copy() method.
90 LOG(FATAL
) << "Invalid DrawQuad material " << material
;
93 copy_quad
->shared_quad_state
= copied_shared_quad_state
;
94 return copy_quad
.Pass();
97 scoped_ptr
<base::Value
> DrawQuad::AsValue() const {
98 scoped_ptr
<base::DictionaryValue
> value(new base::DictionaryValue());
99 value
->SetInteger("material", material
);
100 value
->Set("shared_state",
101 TracedValue::CreateIDRef(shared_quad_state
).release());
103 value
->Set("content_space_rect", MathUtil::AsValue(rect
).release());
104 bool rect_is_clipped
;
105 gfx::QuadF rect_as_target_space_quad
= MathUtil::MapQuad(
106 shared_quad_state
->content_to_target_transform
,
109 value
->Set("rect_as_target_space_quad",
110 MathUtil::AsValue(rect_as_target_space_quad
).release());
111 value
->SetBoolean("rect_is_clipped", rect_is_clipped
);
113 value
->Set("content_space_opaque_rect",
114 MathUtil::AsValue(opaque_rect
).release());
115 bool opaque_rect_is_clipped
;
116 gfx::QuadF opaque_rect_as_target_space_quad
= MathUtil::MapQuad(
117 shared_quad_state
->content_to_target_transform
,
118 gfx::QuadF(opaque_rect
),
119 &opaque_rect_is_clipped
);
120 value
->Set("opaque_rect_as_target_space_quad",
121 MathUtil::AsValue(opaque_rect_as_target_space_quad
).release());
122 value
->SetBoolean("opaque_rect_is_clipped", opaque_rect_is_clipped
);
124 value
->Set("content_space_visible_rect",
125 MathUtil::AsValue(visible_rect
).release());
126 bool visible_rect_is_clipped
;
127 gfx::QuadF visible_rect_as_target_space_quad
= MathUtil::MapQuad(
128 shared_quad_state
->content_to_target_transform
,
129 gfx::QuadF(visible_rect
),
130 &visible_rect_is_clipped
);
131 value
->Set("visible_rect_as_target_space_quad",
132 MathUtil::AsValue(visible_rect_as_target_space_quad
).release());
133 value
->SetBoolean("visible_rect_is_clipped", visible_rect_is_clipped
);
135 value
->SetBoolean("needs_blending", needs_blending
);
136 value
->SetBoolean("should_draw_with_blending", ShouldDrawWithBlending());
137 ExtendValue(value
.get());
138 return value
.PassAs
<base::Value
>();