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/surface_draw_quad.h"
19 #include "cc/quads/texture_draw_quad.h"
20 #include "cc/quads/tile_draw_quad.h"
21 #include "cc/quads/yuv_video_draw_quad.h"
22 #include "ui/gfx/quad_f.h"
25 template<typename T
> T
* TypedCopy(const cc::DrawQuad
* other
) {
26 return new T(*T::MaterialCast(other
));
34 needs_blending(false),
38 void DrawQuad::SetAll(const SharedQuadState
* shared_quad_state
,
40 const gfx::Rect
& rect
,
41 const gfx::Rect
& opaque_rect
,
42 const gfx::Rect
& visible_rect
,
43 bool needs_blending
) {
44 DCHECK(rect
.Contains(visible_rect
)) << "rect: " << rect
.ToString()
46 << visible_rect
.ToString();
47 DCHECK(opaque_rect
.IsEmpty() || rect
.Contains(opaque_rect
))
48 << "rect: " << rect
.ToString() << "opaque_rect "
49 << opaque_rect
.ToString();
51 this->material
= material
;
53 this->opaque_rect
= opaque_rect
;
54 this->visible_rect
= visible_rect
;
55 this->needs_blending
= needs_blending
;
56 this->shared_quad_state
= shared_quad_state
;
58 DCHECK(shared_quad_state
);
59 DCHECK(material
!= INVALID
);
62 DrawQuad::~DrawQuad() {
65 scoped_ptr
<DrawQuad
> DrawQuad::Copy(
66 const SharedQuadState
* copied_shared_quad_state
) const {
67 scoped_ptr
<DrawQuad
> copy_quad
;
70 copy_quad
.reset(TypedCopy
<CheckerboardDrawQuad
>(this));
73 copy_quad
.reset(TypedCopy
<DebugBorderDrawQuad
>(this));
75 case IO_SURFACE_CONTENT
:
76 copy_quad
.reset(TypedCopy
<IOSurfaceDrawQuad
>(this));
79 copy_quad
.reset(TypedCopy
<PictureDrawQuad
>(this));
82 copy_quad
.reset(TypedCopy
<TextureDrawQuad
>(this));
85 copy_quad
.reset(TypedCopy
<SolidColorDrawQuad
>(this));
88 copy_quad
.reset(TypedCopy
<TileDrawQuad
>(this));
90 case STREAM_VIDEO_CONTENT
:
91 copy_quad
.reset(TypedCopy
<StreamVideoDrawQuad
>(this));
94 copy_quad
.reset(TypedCopy
<SurfaceDrawQuad
>(this));
96 case YUV_VIDEO_CONTENT
:
97 copy_quad
.reset(TypedCopy
<YUVVideoDrawQuad
>(this));
99 case RENDER_PASS
: // RenderPass quads have their own copy() method.
101 LOG(FATAL
) << "Invalid DrawQuad material " << material
;
104 copy_quad
->shared_quad_state
= copied_shared_quad_state
;
105 return copy_quad
.Pass();
108 scoped_ptr
<base::Value
> DrawQuad::AsValue() const {
109 scoped_ptr
<base::DictionaryValue
> value(new base::DictionaryValue());
110 value
->SetInteger("material", material
);
111 value
->Set("shared_state",
112 TracedValue::CreateIDRef(shared_quad_state
).release());
114 value
->Set("content_space_rect", MathUtil::AsValue(rect
).release());
115 bool rect_is_clipped
;
116 gfx::QuadF rect_as_target_space_quad
= MathUtil::MapQuad(
117 shared_quad_state
->content_to_target_transform
,
120 value
->Set("rect_as_target_space_quad",
121 MathUtil::AsValue(rect_as_target_space_quad
).release());
122 value
->SetBoolean("rect_is_clipped", rect_is_clipped
);
124 value
->Set("content_space_opaque_rect",
125 MathUtil::AsValue(opaque_rect
).release());
126 bool opaque_rect_is_clipped
;
127 gfx::QuadF opaque_rect_as_target_space_quad
= MathUtil::MapQuad(
128 shared_quad_state
->content_to_target_transform
,
129 gfx::QuadF(opaque_rect
),
130 &opaque_rect_is_clipped
);
131 value
->Set("opaque_rect_as_target_space_quad",
132 MathUtil::AsValue(opaque_rect_as_target_space_quad
).release());
133 value
->SetBoolean("opaque_rect_is_clipped", opaque_rect_is_clipped
);
135 value
->Set("content_space_visible_rect",
136 MathUtil::AsValue(visible_rect
).release());
137 bool visible_rect_is_clipped
;
138 gfx::QuadF visible_rect_as_target_space_quad
= MathUtil::MapQuad(
139 shared_quad_state
->content_to_target_transform
,
140 gfx::QuadF(visible_rect
),
141 &visible_rect_is_clipped
);
142 value
->Set("visible_rect_as_target_space_quad",
143 MathUtil::AsValue(visible_rect_as_target_space_quad
).release());
144 value
->SetBoolean("visible_rect_is_clipped", visible_rect_is_clipped
);
146 value
->SetBoolean("needs_blending", needs_blending
);
147 value
->SetBoolean("should_draw_with_blending", ShouldDrawWithBlending());
148 ExtendValue(value
.get());
149 return value
.PassAs
<base::Value
>();