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 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 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 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 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 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 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 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 ResourceId resource8
= resource_provider
->CreateResourceFromTextureMailbox(
81 mailbox
, callback
.Pass());
82 resource_provider
->AllocateForTesting(resource8
);
84 SharedQuadState
* shared_state
= this->CreateAndAppendSharedQuadState();
85 shared_state
->SetAll(gfx::Transform(),
91 SkXfermode::kSrcOver_Mode
,
94 CheckerboardDrawQuad
* checkerboard_quad
=
95 this->CreateAndAppendDrawQuad
<CheckerboardDrawQuad
>();
96 checkerboard_quad
->SetNew(shared_state
, rect
, visible_rect
, SK_ColorRED
, 1.f
);
98 DebugBorderDrawQuad
* debug_border_quad
=
99 this->CreateAndAppendDrawQuad
<DebugBorderDrawQuad
>();
100 debug_border_quad
->SetNew(shared_state
, rect
, visible_rect
, SK_ColorRED
, 1);
102 IOSurfaceDrawQuad
* io_surface_quad
=
103 this->CreateAndAppendDrawQuad
<IOSurfaceDrawQuad
>();
104 io_surface_quad
->SetNew(shared_state
,
110 IOSurfaceDrawQuad::FLIPPED
);
112 if (child_pass
.layer_id
) {
113 RenderPassDrawQuad
* render_pass_quad
=
114 this->CreateAndAppendDrawQuad
<RenderPassDrawQuad
>();
115 render_pass_quad
->SetNew(shared_state
,
120 gfx::Vector2dF(1.f
, 1.f
),
126 RenderPassDrawQuad
* render_pass_replica_quad
=
127 this->CreateAndAppendDrawQuad
<RenderPassDrawQuad
>();
128 render_pass_replica_quad
->SetNew(shared_state
,
133 gfx::Vector2dF(1.f
, 1.f
),
140 SolidColorDrawQuad
* solid_color_quad
=
141 this->CreateAndAppendDrawQuad
<SolidColorDrawQuad
>();
142 solid_color_quad
->SetNew(
143 shared_state
, rect
, visible_rect
, SK_ColorRED
, false);
145 StreamVideoDrawQuad
* stream_video_quad
=
146 this->CreateAndAppendDrawQuad
<StreamVideoDrawQuad
>();
147 stream_video_quad
->SetNew(shared_state
,
154 TextureDrawQuad
* texture_quad
=
155 this->CreateAndAppendDrawQuad
<TextureDrawQuad
>();
156 texture_quad
->SetNew(shared_state
,
162 gfx::PointF(0.f
, 0.f
),
163 gfx::PointF(1.f
, 1.f
),
169 TextureDrawQuad
* mailbox_texture_quad
=
170 this->CreateAndAppendDrawQuad
<TextureDrawQuad
>();
171 mailbox_texture_quad
->SetNew(shared_state
,
177 gfx::PointF(0.f
, 0.f
),
178 gfx::PointF(1.f
, 1.f
),
184 TileDrawQuad
* scaled_tile_quad
=
185 this->CreateAndAppendDrawQuad
<TileDrawQuad
>();
186 scaled_tile_quad
->SetNew(shared_state
,
191 gfx::RectF(0, 0, 50, 50),
196 SharedQuadState
* transformed_state
= this->CreateAndAppendSharedQuadState();
197 transformed_state
->CopyFrom(shared_state
);
198 gfx::Transform rotation
;
200 transformed_state
->content_to_target_transform
=
201 transformed_state
->content_to_target_transform
* rotation
;
202 TileDrawQuad
* transformed_tile_quad
=
203 this->CreateAndAppendDrawQuad
<TileDrawQuad
>();
204 transformed_tile_quad
->SetNew(transformed_state
,
209 gfx::RectF(0, 0, 100, 100),
214 SharedQuadState
* shared_state2
= this->CreateAndAppendSharedQuadState();
215 shared_state
->SetAll(gfx::Transform(),
221 SkXfermode::kSrcOver_Mode
,
224 TileDrawQuad
* tile_quad
= this->CreateAndAppendDrawQuad
<TileDrawQuad
>();
225 tile_quad
->SetNew(shared_state2
,
230 gfx::RectF(0, 0, 100, 100),
235 ResourceId plane_resources
[4];
236 for (int i
= 0; i
< 4; ++i
) {
237 plane_resources
[i
] = resource_provider
->CreateResource(
238 gfx::Size(20, 12), GL_CLAMP_TO_EDGE
,
239 ResourceProvider::TEXTURE_HINT_IMMUTABLE
,
240 resource_provider
->best_texture_format());
241 resource_provider
->AllocateForTesting(plane_resources
[i
]);
243 YUVVideoDrawQuad::ColorSpace color_space
= YUVVideoDrawQuad::REC_601
;
244 YUVVideoDrawQuad
* yuv_quad
=
245 this->CreateAndAppendDrawQuad
<YUVVideoDrawQuad
>();
246 yuv_quad
->SetNew(shared_state2
, rect
, opaque_rect
, visible_rect
,
247 gfx::RectF(.0f
, .0f
, 100.0f
, 100.0f
),
248 gfx::RectF(.0f
, .0f
, 50.0f
, 50.0f
), gfx::Size(100, 100),
249 gfx::Size(50, 50), plane_resources
[0], plane_resources
[1],
250 plane_resources
[2], plane_resources
[3], color_space
);