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/test/render_pass_test_common.h"
7 #include "cc/quads/checkerboard_draw_quad.h"
8 #include "cc/quads/debug_border_draw_quad.h"
9 #include "cc/quads/io_surface_draw_quad.h"
10 #include "cc/quads/render_pass_draw_quad.h"
11 #include "cc/quads/shared_quad_state.h"
12 #include "cc/quads/solid_color_draw_quad.h"
13 #include "cc/quads/stream_video_draw_quad.h"
14 #include "cc/quads/texture_draw_quad.h"
15 #include "cc/quads/tile_draw_quad.h"
16 #include "cc/quads/yuv_video_draw_quad.h"
17 #include "cc/resources/resource_provider.h"
18 #include "ui/gfx/transform.h"
22 void TestRenderPass::AppendQuad(scoped_ptr
<DrawQuad
> quad
) {
23 quad_list
.push_back(quad
.Pass());
26 void TestRenderPass::AppendOneOfEveryQuadType(
27 ResourceProvider
* resource_provider
,
28 RenderPass::Id child_pass
) {
29 gfx::Rect
rect(0, 0, 100, 100);
30 gfx::Rect
opaque_rect(10, 10, 80, 80);
31 gfx::Rect
visible_rect(0, 0, 100, 100);
32 const float vertex_opacity
[] = {1.0f
, 1.0f
, 1.0f
, 1.0f
};
33 ResourceProvider::ResourceId resource1
= resource_provider
->CreateResource(
36 ResourceProvider::TextureUsageAny
,
37 resource_provider
->best_texture_format());
38 resource_provider
->AllocateForTesting(resource1
);
39 ResourceProvider::ResourceId resource2
= resource_provider
->CreateResource(
42 ResourceProvider::TextureUsageAny
,
43 resource_provider
->best_texture_format());
44 resource_provider
->AllocateForTesting(resource2
);
45 ResourceProvider::ResourceId resource3
= resource_provider
->CreateResource(
48 ResourceProvider::TextureUsageAny
,
49 resource_provider
->best_texture_format());
50 resource_provider
->AllocateForTesting(resource3
);
51 ResourceProvider::ResourceId resource4
= resource_provider
->CreateResource(
54 ResourceProvider::TextureUsageAny
,
55 resource_provider
->best_texture_format());
56 resource_provider
->AllocateForTesting(resource4
);
57 ResourceProvider::ResourceId resource5
= resource_provider
->CreateResource(
60 ResourceProvider::TextureUsageAny
,
61 resource_provider
->best_texture_format());
62 resource_provider
->AllocateForTesting(resource5
);
63 ResourceProvider::ResourceId resource6
= resource_provider
->CreateResource(
66 ResourceProvider::TextureUsageAny
,
67 resource_provider
->best_texture_format());
68 resource_provider
->AllocateForTesting(resource6
);
69 ResourceProvider::ResourceId resource7
= resource_provider
->CreateResource(
72 ResourceProvider::TextureUsageAny
,
73 resource_provider
->best_texture_format());
74 resource_provider
->AllocateForTesting(resource7
);
76 SharedQuadState
* shared_state
= this->CreateAndAppendSharedQuadState();
77 shared_state
->SetAll(gfx::Transform(),
83 SkXfermode::kSrcOver_Mode
);
85 scoped_ptr
<CheckerboardDrawQuad
> checkerboard_quad
=
86 CheckerboardDrawQuad::Create();
87 checkerboard_quad
->SetNew(shared_state
, rect
, visible_rect
, SK_ColorRED
);
88 AppendQuad(checkerboard_quad
.PassAs
<DrawQuad
>());
90 scoped_ptr
<DebugBorderDrawQuad
> debug_border_quad
=
91 DebugBorderDrawQuad::Create();
92 debug_border_quad
->SetNew(shared_state
, rect
, visible_rect
, SK_ColorRED
, 1);
93 AppendQuad(debug_border_quad
.PassAs
<DrawQuad
>());
95 scoped_ptr
<IOSurfaceDrawQuad
> io_surface_quad
= IOSurfaceDrawQuad::Create();
96 io_surface_quad
->SetNew(shared_state
,
102 IOSurfaceDrawQuad::FLIPPED
);
103 AppendQuad(io_surface_quad
.PassAs
<DrawQuad
>());
105 if (child_pass
.layer_id
) {
106 scoped_ptr
<RenderPassDrawQuad
> render_pass_quad
=
107 RenderPassDrawQuad::Create();
108 render_pass_quad
->SetNew(shared_state
,
118 AppendQuad(render_pass_quad
.PassAs
<DrawQuad
>());
120 scoped_ptr
<RenderPassDrawQuad
> render_pass_replica_quad
=
121 RenderPassDrawQuad::Create();
122 render_pass_replica_quad
->SetNew(shared_state
,
132 AppendQuad(render_pass_replica_quad
.PassAs
<DrawQuad
>());
135 scoped_ptr
<SolidColorDrawQuad
> solid_color_quad
=
136 SolidColorDrawQuad::Create();
137 solid_color_quad
->SetNew(
138 shared_state
, rect
, visible_rect
, SK_ColorRED
, false);
139 AppendQuad(solid_color_quad
.PassAs
<DrawQuad
>());
141 scoped_ptr
<StreamVideoDrawQuad
> stream_video_quad
=
142 StreamVideoDrawQuad::Create();
143 stream_video_quad
->SetNew(shared_state
,
149 AppendQuad(stream_video_quad
.PassAs
<DrawQuad
>());
151 scoped_ptr
<TextureDrawQuad
> texture_quad
= TextureDrawQuad::Create();
152 texture_quad
->SetNew(shared_state
,
158 gfx::PointF(0.f
, 0.f
),
159 gfx::PointF(1.f
, 1.f
),
163 AppendQuad(texture_quad
.PassAs
<DrawQuad
>());
165 scoped_ptr
<TileDrawQuad
> scaled_tile_quad
= TileDrawQuad::Create();
166 scaled_tile_quad
->SetNew(shared_state
,
171 gfx::RectF(0, 0, 50, 50),
174 AppendQuad(scaled_tile_quad
.PassAs
<DrawQuad
>());
176 SharedQuadState
* transformed_state
= this->CreateAndAppendSharedQuadState();
177 transformed_state
->CopyFrom(shared_state
);
178 gfx::Transform rotation
;
180 transformed_state
->content_to_target_transform
=
181 transformed_state
->content_to_target_transform
* rotation
;
182 scoped_ptr
<TileDrawQuad
> transformed_tile_quad
= TileDrawQuad::Create();
183 transformed_tile_quad
->SetNew(transformed_state
,
188 gfx::RectF(0, 0, 100, 100),
191 AppendQuad(transformed_tile_quad
.PassAs
<DrawQuad
>());
193 SharedQuadState
* shared_state2
= this->CreateAndAppendSharedQuadState();
194 shared_state
->SetAll(gfx::Transform(),
200 SkXfermode::kSrcOver_Mode
);
202 scoped_ptr
<TileDrawQuad
> tile_quad
= TileDrawQuad::Create();
203 tile_quad
->SetNew(shared_state2
,
208 gfx::RectF(0, 0, 100, 100),
211 AppendQuad(tile_quad
.PassAs
<DrawQuad
>());
213 ResourceProvider::ResourceId plane_resources
[4];
214 for (int i
= 0; i
< 4; ++i
) {
216 resource_provider
->CreateResource(
219 ResourceProvider::TextureUsageAny
,
220 resource_provider
->best_texture_format());
221 resource_provider
->AllocateForTesting(plane_resources
[i
]);
223 YUVVideoDrawQuad::ColorSpace color_space
= YUVVideoDrawQuad::REC_601
;
224 scoped_ptr
<YUVVideoDrawQuad
> yuv_quad
= YUVVideoDrawQuad::Create();
225 yuv_quad
->SetNew(shared_state2
,
229 gfx::RectF(0, 0, 100, 100),
235 AppendQuad(yuv_quad
.PassAs
<DrawQuad
>());