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"
8 #include "cc/quads/checkerboard_draw_quad.h"
9 #include "cc/quads/debug_border_draw_quad.h"
10 #include "cc/quads/io_surface_draw_quad.h"
11 #include "cc/quads/render_pass_draw_quad.h"
12 #include "cc/quads/shared_quad_state.h"
13 #include "cc/quads/solid_color_draw_quad.h"
14 #include "cc/quads/stream_video_draw_quad.h"
15 #include "cc/quads/texture_draw_quad.h"
16 #include "cc/quads/tile_draw_quad.h"
17 #include "cc/quads/yuv_video_draw_quad.h"
18 #include "cc/resources/resource_provider.h"
19 #include "cc/trees/blocking_task_runner.h"
20 #include "ui/gfx/transform.h"
24 static void EmptyReleaseCallback(uint32 sync_point
,
26 BlockingTaskRunner
* main_thread_task_runner
) {
29 void TestRenderPass::AppendOneOfEveryQuadType(
30 ResourceProvider
* resource_provider
,
31 RenderPassId child_pass
) {
32 gfx::Rect
rect(0, 0, 100, 100);
33 gfx::Rect
opaque_rect(10, 10, 80, 80);
34 gfx::Rect
visible_rect(0, 0, 100, 100);
35 const float vertex_opacity
[] = {1.0f
, 1.0f
, 1.0f
, 1.0f
};
37 ResourceProvider::ResourceId resource1
= resource_provider
->CreateResource(
38 gfx::Size(45, 5), GL_CLAMP_TO_EDGE
,
39 ResourceProvider::TEXTURE_HINT_IMMUTABLE
,
40 resource_provider
->best_texture_format());
41 resource_provider
->AllocateForTesting(resource1
);
42 ResourceProvider::ResourceId resource2
= resource_provider
->CreateResource(
43 gfx::Size(346, 61), GL_CLAMP_TO_EDGE
,
44 ResourceProvider::TEXTURE_HINT_IMMUTABLE
,
45 resource_provider
->best_texture_format());
46 resource_provider
->AllocateForTesting(resource2
);
47 ResourceProvider::ResourceId resource3
= resource_provider
->CreateResource(
48 gfx::Size(12, 134), GL_CLAMP_TO_EDGE
,
49 ResourceProvider::TEXTURE_HINT_IMMUTABLE
,
50 resource_provider
->best_texture_format());
51 resource_provider
->AllocateForTesting(resource3
);
52 ResourceProvider::ResourceId resource4
= resource_provider
->CreateResource(
53 gfx::Size(56, 12), GL_CLAMP_TO_EDGE
,
54 ResourceProvider::TEXTURE_HINT_IMMUTABLE
,
55 resource_provider
->best_texture_format());
56 resource_provider
->AllocateForTesting(resource4
);
57 gfx::Size
resource5_size(73, 26);
58 ResourceProvider::ResourceId resource5
= resource_provider
->CreateResource(
59 resource5_size
, GL_CLAMP_TO_EDGE
,
60 ResourceProvider::TEXTURE_HINT_IMMUTABLE
,
61 resource_provider
->best_texture_format());
62 resource_provider
->AllocateForTesting(resource5
);
63 ResourceProvider::ResourceId resource6
= resource_provider
->CreateResource(
64 gfx::Size(64, 92), GL_CLAMP_TO_EDGE
,
65 ResourceProvider::TEXTURE_HINT_IMMUTABLE
,
66 resource_provider
->best_texture_format());
67 resource_provider
->AllocateForTesting(resource6
);
68 ResourceProvider::ResourceId resource7
= resource_provider
->CreateResource(
69 gfx::Size(9, 14), GL_CLAMP_TO_EDGE
,
70 ResourceProvider::TEXTURE_HINT_IMMUTABLE
,
71 resource_provider
->best_texture_format());
72 resource_provider
->AllocateForTesting(resource7
);
74 unsigned target
= GL_TEXTURE_2D
;
75 gpu::Mailbox gpu_mailbox
;
76 memcpy(gpu_mailbox
.name
, "Hello world", strlen("Hello world") + 1);
77 scoped_ptr
<SingleReleaseCallbackImpl
> callback
=
78 SingleReleaseCallbackImpl::Create(base::Bind(&EmptyReleaseCallback
));
79 TextureMailbox
mailbox(gpu_mailbox
, target
, kSyncPointForMailboxTextureQuad
);
80 ResourceProvider::ResourceId resource8
=
81 resource_provider
->CreateResourceFromTextureMailbox(mailbox
,
83 resource_provider
->AllocateForTesting(resource8
);
85 SharedQuadState
* shared_state
= this->CreateAndAppendSharedQuadState();
86 shared_state
->SetAll(gfx::Transform(),
92 SkXfermode::kSrcOver_Mode
,
95 CheckerboardDrawQuad
* checkerboard_quad
=
96 this->CreateAndAppendDrawQuad
<CheckerboardDrawQuad
>();
97 checkerboard_quad
->SetNew(shared_state
, rect
, visible_rect
, SK_ColorRED
, 1.f
);
99 DebugBorderDrawQuad
* debug_border_quad
=
100 this->CreateAndAppendDrawQuad
<DebugBorderDrawQuad
>();
101 debug_border_quad
->SetNew(shared_state
, rect
, visible_rect
, SK_ColorRED
, 1);
103 IOSurfaceDrawQuad
* io_surface_quad
=
104 this->CreateAndAppendDrawQuad
<IOSurfaceDrawQuad
>();
105 io_surface_quad
->SetNew(shared_state
,
111 IOSurfaceDrawQuad::FLIPPED
);
113 if (child_pass
.layer_id
) {
114 RenderPassDrawQuad
* render_pass_quad
=
115 this->CreateAndAppendDrawQuad
<RenderPassDrawQuad
>();
116 render_pass_quad
->SetNew(shared_state
,
121 gfx::Vector2dF(1.f
, 1.f
),
127 RenderPassDrawQuad
* render_pass_replica_quad
=
128 this->CreateAndAppendDrawQuad
<RenderPassDrawQuad
>();
129 render_pass_replica_quad
->SetNew(shared_state
,
134 gfx::Vector2dF(1.f
, 1.f
),
141 SolidColorDrawQuad
* solid_color_quad
=
142 this->CreateAndAppendDrawQuad
<SolidColorDrawQuad
>();
143 solid_color_quad
->SetNew(
144 shared_state
, rect
, visible_rect
, SK_ColorRED
, false);
146 StreamVideoDrawQuad
* stream_video_quad
=
147 this->CreateAndAppendDrawQuad
<StreamVideoDrawQuad
>();
148 stream_video_quad
->SetNew(shared_state
,
155 TextureDrawQuad
* texture_quad
=
156 this->CreateAndAppendDrawQuad
<TextureDrawQuad
>();
157 texture_quad
->SetNew(shared_state
,
163 gfx::PointF(0.f
, 0.f
),
164 gfx::PointF(1.f
, 1.f
),
170 TextureDrawQuad
* mailbox_texture_quad
=
171 this->CreateAndAppendDrawQuad
<TextureDrawQuad
>();
172 mailbox_texture_quad
->SetNew(shared_state
,
178 gfx::PointF(0.f
, 0.f
),
179 gfx::PointF(1.f
, 1.f
),
185 TileDrawQuad
* scaled_tile_quad
=
186 this->CreateAndAppendDrawQuad
<TileDrawQuad
>();
187 scaled_tile_quad
->SetNew(shared_state
,
192 gfx::RectF(0, 0, 50, 50),
197 SharedQuadState
* transformed_state
= this->CreateAndAppendSharedQuadState();
198 transformed_state
->CopyFrom(shared_state
);
199 gfx::Transform rotation
;
201 transformed_state
->content_to_target_transform
=
202 transformed_state
->content_to_target_transform
* rotation
;
203 TileDrawQuad
* transformed_tile_quad
=
204 this->CreateAndAppendDrawQuad
<TileDrawQuad
>();
205 transformed_tile_quad
->SetNew(transformed_state
,
210 gfx::RectF(0, 0, 100, 100),
215 SharedQuadState
* shared_state2
= this->CreateAndAppendSharedQuadState();
216 shared_state
->SetAll(gfx::Transform(),
222 SkXfermode::kSrcOver_Mode
,
225 TileDrawQuad
* tile_quad
= this->CreateAndAppendDrawQuad
<TileDrawQuad
>();
226 tile_quad
->SetNew(shared_state2
,
231 gfx::RectF(0, 0, 100, 100),
236 ResourceProvider::ResourceId plane_resources
[4];
237 for (int i
= 0; i
< 4; ++i
) {
238 plane_resources
[i
] = resource_provider
->CreateResource(
239 gfx::Size(20, 12), GL_CLAMP_TO_EDGE
,
240 ResourceProvider::TEXTURE_HINT_IMMUTABLE
,
241 resource_provider
->best_texture_format());
242 resource_provider
->AllocateForTesting(plane_resources
[i
]);
244 YUVVideoDrawQuad::ColorSpace color_space
= YUVVideoDrawQuad::REC_601
;
245 YUVVideoDrawQuad
* yuv_quad
=
246 this->CreateAndAppendDrawQuad
<YUVVideoDrawQuad
>();
247 yuv_quad
->SetNew(shared_state2
, rect
, opaque_rect
, visible_rect
,
248 gfx::RectF(0, 0, 100, 100), gfx::Size(100, 100),
249 gfx::Size(50, 50), plane_resources
[0], plane_resources
[1],
250 plane_resources
[2], plane_resources
[3], color_space
);