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/checkerboard_draw_quad.h"
8 #include "cc/debug_border_draw_quad.h"
9 #include "cc/io_surface_draw_quad.h"
10 #include "cc/render_pass_draw_quad.h"
11 #include "cc/solid_color_draw_quad.h"
12 #include "cc/shared_quad_state.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"
17 #include "cc/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
* resourceProvider
, 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 texture_resource
=
37 resourceProvider
->createResource(
39 resourceProvider
->bestTextureFormat(),
40 ResourceProvider::TextureUsageAny
);
41 resourceProvider
->allocateForTesting(texture_resource
);
42 unsigned texture_id
= ResourceProvider::ScopedReadLockGL(
43 resourceProvider
, texture_resource
).textureId();
44 cc::ResourceProvider::ResourceId resource1
=
45 resourceProvider
->createResource(
47 resourceProvider
->bestTextureFormat(),
48 ResourceProvider::TextureUsageAny
);
49 resourceProvider
->allocateForTesting(resource1
);
50 cc::ResourceProvider::ResourceId resource2
=
51 resourceProvider
->createResource(
53 resourceProvider
->bestTextureFormat(),
54 ResourceProvider::TextureUsageAny
);
55 resourceProvider
->allocateForTesting(resource2
);
56 cc::ResourceProvider::ResourceId resource3
=
57 resourceProvider
->createResource(
59 resourceProvider
->bestTextureFormat(),
60 ResourceProvider::TextureUsageAny
);
61 resourceProvider
->allocateForTesting(resource3
);
62 cc::ResourceProvider::ResourceId resource4
=
63 resourceProvider
->createResource(
65 resourceProvider
->bestTextureFormat(),
66 ResourceProvider::TextureUsageAny
);
67 resourceProvider
->allocateForTesting(resource4
);
68 cc::ResourceProvider::ResourceId resource5
=
69 resourceProvider
->createResource(
71 resourceProvider
->bestTextureFormat(),
72 ResourceProvider::TextureUsageAny
);
73 resourceProvider
->allocateForTesting(resource5
);
75 scoped_ptr
<cc::SharedQuadState
> shared_state
= cc::SharedQuadState::Create();
76 shared_state
->SetAll(gfx::Transform(),
82 scoped_ptr
<cc::CheckerboardDrawQuad
> checkerboard_quad
=
83 cc::CheckerboardDrawQuad::Create();
84 checkerboard_quad
->SetNew(shared_state
.get(),
87 AppendQuad(checkerboard_quad
.PassAs
<DrawQuad
>());
89 scoped_ptr
<cc::DebugBorderDrawQuad
> debug_border_quad
=
90 cc::DebugBorderDrawQuad::Create();
91 debug_border_quad
->SetNew(shared_state
.get(),
95 AppendQuad(debug_border_quad
.PassAs
<DrawQuad
>());
97 scoped_ptr
<cc::IOSurfaceDrawQuad
> io_surface_quad
=
98 cc::IOSurfaceDrawQuad::Create();
99 io_surface_quad
->SetNew(shared_state
.get(),
104 cc::IOSurfaceDrawQuad::FLIPPED
);
105 AppendQuad(io_surface_quad
.PassAs
<DrawQuad
>());
107 if (child_pass
.layer_id
) {
108 scoped_ptr
<cc::RenderPassDrawQuad
> render_pass_quad
=
109 cc::RenderPassDrawQuad::Create();
110 render_pass_quad
->SetNew(shared_state
.get(),
117 WebKit::WebFilterOperations(),
118 skia::RefPtr
<SkImageFilter
>(),
119 WebKit::WebFilterOperations());
120 AppendQuad(render_pass_quad
.PassAs
<DrawQuad
>());
122 scoped_ptr
<cc::RenderPassDrawQuad
> render_pass_replica_quad
=
123 cc::RenderPassDrawQuad::Create();
124 render_pass_replica_quad
->SetNew(shared_state
.get(),
131 WebKit::WebFilterOperations(),
132 skia::RefPtr
<SkImageFilter
>(),
133 WebKit::WebFilterOperations());
134 AppendQuad(render_pass_replica_quad
.PassAs
<DrawQuad
>());
137 scoped_ptr
<cc::SolidColorDrawQuad
> solid_color_quad
=
138 cc::SolidColorDrawQuad::Create();
139 solid_color_quad
->SetNew(shared_state
.get(),
142 AppendQuad(solid_color_quad
.PassAs
<DrawQuad
>());
144 scoped_ptr
<cc::StreamVideoDrawQuad
> stream_video_quad
=
145 cc::StreamVideoDrawQuad::Create();
146 stream_video_quad
->SetNew(shared_state
.get(),
151 AppendQuad(stream_video_quad
.PassAs
<DrawQuad
>());
153 scoped_ptr
<cc::TextureDrawQuad
> texture_quad
=
154 cc::TextureDrawQuad::Create();
155 texture_quad
->SetNew(shared_state
.get(),
160 gfx::PointF(0.f
, 0.f
),
161 gfx::PointF(1.f
, 1.f
),
164 AppendQuad(texture_quad
.PassAs
<DrawQuad
>());
166 scoped_ptr
<cc::TileDrawQuad
> scaled_tile_quad
=
167 cc::TileDrawQuad::Create();
168 scaled_tile_quad
->SetNew(shared_state
.get(),
172 gfx::RectF(0, 0, 50, 50),
179 AppendQuad(scaled_tile_quad
.PassAs
<DrawQuad
>());
181 scoped_ptr
<cc::SharedQuadState
> transformed_state
= shared_state
->Copy();
182 gfx::Transform rotation
;
184 transformed_state
->content_to_target_transform
= transformed_state
->content_to_target_transform
* rotation
;
185 scoped_ptr
<cc::TileDrawQuad
> transformed_tile_quad
=
186 cc::TileDrawQuad::Create();
187 transformed_tile_quad
->SetNew(transformed_state
.get(),
191 gfx::RectF(0, 0, 100, 100),
198 AppendQuad(transformed_tile_quad
.PassAs
<DrawQuad
>());
200 scoped_ptr
<cc::TileDrawQuad
> tile_quad
=
201 cc::TileDrawQuad::Create();
202 tile_quad
->SetNew(shared_state
.get(),
206 gfx::RectF(0, 0, 100, 100),
213 AppendQuad(tile_quad
.PassAs
<DrawQuad
>());
215 cc::VideoLayerImpl::FramePlane planes
[3];
216 for (int i
= 0; i
< 3; ++i
) {
217 planes
[i
].resourceId
=
218 resourceProvider
->createResource(
220 resourceProvider
->bestTextureFormat(),
221 ResourceProvider::TextureUsageAny
);
222 resourceProvider
->allocateForTesting(planes
[i
].resourceId
);
223 planes
[i
].size
= gfx::Size(100, 100);
224 planes
[i
].format
= GL_LUMINANCE
;
226 scoped_ptr
<cc::YUVVideoDrawQuad
> yuv_quad
=
227 cc::YUVVideoDrawQuad::Create();
228 yuv_quad
->SetNew(shared_state
.get(),
235 AppendQuad(yuv_quad
.PassAs
<DrawQuad
>());
237 AppendSharedQuadState(transformed_state
.Pass());
238 AppendSharedQuadState(shared_state
.Pass());