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/draw_quad.h"
7 #include "base/logging.h"
8 #include "cc/checkerboard_draw_quad.h"
9 #include "cc/debug_border_draw_quad.h"
10 #include "cc/io_surface_draw_quad.h"
11 #include "cc/render_pass_draw_quad.h"
12 #include "cc/solid_color_draw_quad.h"
13 #include "cc/stream_video_draw_quad.h"
14 #include "cc/texture_draw_quad.h"
15 #include "cc/tile_draw_quad.h"
16 #include "cc/yuv_video_draw_quad.h"
20 template<typename T
> T
* TypedCopy(const cc::DrawQuad
* other
) {
21 return new T(*T::MaterialCast(other
));
29 : shared_quad_state(),
31 needs_blending(false) {
34 void DrawQuad::SetAll(const SharedQuadState
* shared_quad_state
,
37 gfx::Rect opaque_rect
,
38 gfx::Rect visible_rect
,
39 bool needs_blending
) {
40 this->material
= material
;
42 this->opaque_rect
= opaque_rect
;
43 this->visible_rect
= visible_rect
;
44 this->needs_blending
= needs_blending
;
45 this->shared_quad_state
= shared_quad_state
;
47 DCHECK(shared_quad_state
);
48 DCHECK(material
!= INVALID
);
51 DrawQuad::~DrawQuad() {
54 scoped_ptr
<DrawQuad
> DrawQuad::Copy(
55 const SharedQuadState
* copied_shared_quad_state
) const
57 scoped_ptr
<DrawQuad
> copy_quad
;
60 copy_quad
.reset(TypedCopy
<CheckerboardDrawQuad
>(this));
63 copy_quad
.reset(TypedCopy
<DebugBorderDrawQuad
>(this));
65 case IO_SURFACE_CONTENT
:
66 copy_quad
.reset(TypedCopy
<IOSurfaceDrawQuad
>(this));
69 copy_quad
.reset(TypedCopy
<TextureDrawQuad
>(this));
72 copy_quad
.reset(TypedCopy
<SolidColorDrawQuad
>(this));
75 copy_quad
.reset(TypedCopy
<TileDrawQuad
>(this));
77 case STREAM_VIDEO_CONTENT
:
78 copy_quad
.reset(TypedCopy
<StreamVideoDrawQuad
>(this));
80 case YUV_VIDEO_CONTENT
:
81 copy_quad
.reset(TypedCopy
<YUVVideoDrawQuad
>(this));
83 case RENDER_PASS
: // RenderPass quads have their own copy() method.
85 LOG(FATAL
) << "Invalid DrawQuad material " << material
;
88 copy_quad
->shared_quad_state
= copied_shared_quad_state
;
89 return copy_quad
.Pass();