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
<cc::DrawQuad
> quad
) {
23 quad_list
.push_back(quad
.Pass());
26 void TestRenderPass::AppendSharedQuadState(
27 scoped_ptr
<cc::SharedQuadState
> state
) {
28 shared_quad_state_list
.push_back(state
.Pass());
31 void TestRenderPass::AppendOneOfEveryQuadType(
32 cc::ResourceProvider
* resource_provider
, RenderPass::Id child_pass
) {
33 gfx::Rect
rect(0, 0, 100, 100);
34 gfx::Rect
opaque_rect(10, 10, 80, 80);
35 const float vertex_opacity
[] = {1.0f
, 1.0f
, 1.0f
, 1.0f
};
36 cc::ResourceProvider::ResourceId resource1
=
37 resource_provider
->CreateResource(
39 resource_provider
->best_texture_format(),
40 ResourceProvider::TextureUsageAny
);
41 resource_provider
->AllocateForTesting(resource1
);
42 cc::ResourceProvider::ResourceId resource2
=
43 resource_provider
->CreateResource(
45 resource_provider
->best_texture_format(),
46 ResourceProvider::TextureUsageAny
);
47 resource_provider
->AllocateForTesting(resource2
);
48 cc::ResourceProvider::ResourceId resource3
=
49 resource_provider
->CreateResource(
51 resource_provider
->best_texture_format(),
52 ResourceProvider::TextureUsageAny
);
53 resource_provider
->AllocateForTesting(resource3
);
54 cc::ResourceProvider::ResourceId resource4
=
55 resource_provider
->CreateResource(
57 resource_provider
->best_texture_format(),
58 ResourceProvider::TextureUsageAny
);
59 resource_provider
->AllocateForTesting(resource4
);
60 cc::ResourceProvider::ResourceId resource5
=
61 resource_provider
->CreateResource(
63 resource_provider
->best_texture_format(),
64 ResourceProvider::TextureUsageAny
);
65 resource_provider
->AllocateForTesting(resource5
);
66 cc::ResourceProvider::ResourceId resource6
=
67 resource_provider
->CreateResource(
69 resource_provider
->best_texture_format(),
70 ResourceProvider::TextureUsageAny
);
71 resource_provider
->AllocateForTesting(resource6
);
72 cc::ResourceProvider::ResourceId resource7
=
73 resource_provider
->CreateResource(
75 resource_provider
->best_texture_format(),
76 ResourceProvider::TextureUsageAny
);
77 resource_provider
->AllocateForTesting(resource7
);
79 scoped_ptr
<cc::SharedQuadState
> shared_state
= cc::SharedQuadState::Create();
80 shared_state
->SetAll(gfx::Transform(),
87 scoped_ptr
<cc::CheckerboardDrawQuad
> checkerboard_quad
=
88 cc::CheckerboardDrawQuad::Create();
89 checkerboard_quad
->SetNew(shared_state
.get(),
92 AppendQuad(checkerboard_quad
.PassAs
<DrawQuad
>());
94 scoped_ptr
<cc::DebugBorderDrawQuad
> debug_border_quad
=
95 cc::DebugBorderDrawQuad::Create();
96 debug_border_quad
->SetNew(shared_state
.get(),
100 AppendQuad(debug_border_quad
.PassAs
<DrawQuad
>());
102 scoped_ptr
<cc::IOSurfaceDrawQuad
> io_surface_quad
=
103 cc::IOSurfaceDrawQuad::Create();
104 io_surface_quad
->SetNew(shared_state
.get(),
109 cc::IOSurfaceDrawQuad::FLIPPED
);
110 AppendQuad(io_surface_quad
.PassAs
<DrawQuad
>());
112 if (child_pass
.layer_id
) {
113 scoped_ptr
<cc::RenderPassDrawQuad
> render_pass_quad
=
114 cc::RenderPassDrawQuad::Create();
115 render_pass_quad
->SetNew(shared_state
.get(),
122 WebKit::WebFilterOperations(),
123 skia::RefPtr
<SkImageFilter
>(),
124 WebKit::WebFilterOperations());
125 AppendQuad(render_pass_quad
.PassAs
<DrawQuad
>());
127 scoped_ptr
<cc::RenderPassDrawQuad
> render_pass_replica_quad
=
128 cc::RenderPassDrawQuad::Create();
129 render_pass_replica_quad
->SetNew(shared_state
.get(),
136 WebKit::WebFilterOperations(),
137 skia::RefPtr
<SkImageFilter
>(),
138 WebKit::WebFilterOperations());
139 AppendQuad(render_pass_replica_quad
.PassAs
<DrawQuad
>());
142 scoped_ptr
<cc::SolidColorDrawQuad
> solid_color_quad
=
143 cc::SolidColorDrawQuad::Create();
144 solid_color_quad
->SetNew(shared_state
.get(),
147 AppendQuad(solid_color_quad
.PassAs
<DrawQuad
>());
149 scoped_ptr
<cc::StreamVideoDrawQuad
> stream_video_quad
=
150 cc::StreamVideoDrawQuad::Create();
151 stream_video_quad
->SetNew(shared_state
.get(),
156 AppendQuad(stream_video_quad
.PassAs
<DrawQuad
>());
158 scoped_ptr
<cc::TextureDrawQuad
> texture_quad
=
159 cc::TextureDrawQuad::Create();
160 texture_quad
->SetNew(shared_state
.get(),
165 gfx::PointF(0.f
, 0.f
),
166 gfx::PointF(1.f
, 1.f
),
169 AppendQuad(texture_quad
.PassAs
<DrawQuad
>());
171 scoped_ptr
<cc::TileDrawQuad
> scaled_tile_quad
=
172 cc::TileDrawQuad::Create();
173 scaled_tile_quad
->SetNew(shared_state
.get(),
177 gfx::RectF(0, 0, 50, 50),
180 AppendQuad(scaled_tile_quad
.PassAs
<DrawQuad
>());
182 scoped_ptr
<cc::SharedQuadState
> transformed_state
= shared_state
->Copy();
183 gfx::Transform rotation
;
185 transformed_state
->content_to_target_transform
=
186 transformed_state
->content_to_target_transform
* rotation
;
187 scoped_ptr
<cc::TileDrawQuad
> transformed_tile_quad
=
188 cc::TileDrawQuad::Create();
189 transformed_tile_quad
->SetNew(transformed_state
.get(),
193 gfx::RectF(0, 0, 100, 100),
196 AppendQuad(transformed_tile_quad
.PassAs
<DrawQuad
>());
198 scoped_ptr
<cc::TileDrawQuad
> tile_quad
=
199 cc::TileDrawQuad::Create();
200 tile_quad
->SetNew(shared_state
.get(),
204 gfx::RectF(0, 0, 100, 100),
207 AppendQuad(tile_quad
.PassAs
<DrawQuad
>());
209 ResourceProvider::ResourceId plane_resources
[3];
210 for (int i
= 0; i
< 3; ++i
) {
212 resource_provider
->CreateResource(
214 resource_provider
->best_texture_format(),
215 ResourceProvider::TextureUsageAny
);
216 resource_provider
->AllocateForTesting(plane_resources
[i
]);
218 scoped_ptr
<cc::YUVVideoDrawQuad
> yuv_quad
=
219 cc::YUVVideoDrawQuad::Create();
220 yuv_quad
->SetNew(shared_state
.get(),
227 AppendQuad(yuv_quad
.PassAs
<DrawQuad
>());
229 AppendSharedQuadState(transformed_state
.Pass());
230 AppendSharedQuadState(shared_state
.Pass());