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(
40 ResourceProvider::TextureHintImmutable
,
41 resource_provider
->best_texture_format());
42 resource_provider
->AllocateForTesting(resource1
);
43 ResourceProvider::ResourceId resource2
= resource_provider
->CreateResource(
46 ResourceProvider::TextureHintImmutable
,
47 resource_provider
->best_texture_format());
48 resource_provider
->AllocateForTesting(resource2
);
49 ResourceProvider::ResourceId resource3
= resource_provider
->CreateResource(
52 ResourceProvider::TextureHintImmutable
,
53 resource_provider
->best_texture_format());
54 resource_provider
->AllocateForTesting(resource3
);
55 ResourceProvider::ResourceId resource4
= resource_provider
->CreateResource(
58 ResourceProvider::TextureHintImmutable
,
59 resource_provider
->best_texture_format());
60 resource_provider
->AllocateForTesting(resource4
);
61 ResourceProvider::ResourceId resource5
= resource_provider
->CreateResource(
64 ResourceProvider::TextureHintImmutable
,
65 resource_provider
->best_texture_format());
66 resource_provider
->AllocateForTesting(resource5
);
67 ResourceProvider::ResourceId resource6
= resource_provider
->CreateResource(
70 ResourceProvider::TextureHintImmutable
,
71 resource_provider
->best_texture_format());
72 resource_provider
->AllocateForTesting(resource6
);
73 ResourceProvider::ResourceId resource7
= resource_provider
->CreateResource(
76 ResourceProvider::TextureHintImmutable
,
77 resource_provider
->best_texture_format());
78 resource_provider
->AllocateForTesting(resource7
);
80 unsigned target
= GL_TEXTURE_2D
;
81 gpu::Mailbox gpu_mailbox
;
82 memcpy(gpu_mailbox
.name
, "Hello world", strlen("Hello world") + 1);
83 scoped_ptr
<SingleReleaseCallbackImpl
> callback
=
84 SingleReleaseCallbackImpl::Create(base::Bind(&EmptyReleaseCallback
));
85 TextureMailbox
mailbox(gpu_mailbox
, target
, kSyncPointForMailboxTextureQuad
);
86 ResourceProvider::ResourceId resource8
=
87 resource_provider
->CreateResourceFromTextureMailbox(mailbox
,
89 resource_provider
->AllocateForTesting(resource8
);
91 SharedQuadState
* shared_state
= this->CreateAndAppendSharedQuadState();
92 shared_state
->SetAll(gfx::Transform(),
98 SkXfermode::kSrcOver_Mode
,
101 CheckerboardDrawQuad
* checkerboard_quad
=
102 this->CreateAndAppendDrawQuad
<CheckerboardDrawQuad
>();
103 checkerboard_quad
->SetNew(shared_state
, rect
, visible_rect
, SK_ColorRED
);
105 DebugBorderDrawQuad
* debug_border_quad
=
106 this->CreateAndAppendDrawQuad
<DebugBorderDrawQuad
>();
107 debug_border_quad
->SetNew(shared_state
, rect
, visible_rect
, SK_ColorRED
, 1);
109 IOSurfaceDrawQuad
* io_surface_quad
=
110 this->CreateAndAppendDrawQuad
<IOSurfaceDrawQuad
>();
111 io_surface_quad
->SetNew(shared_state
,
117 IOSurfaceDrawQuad::FLIPPED
);
119 if (child_pass
.layer_id
) {
120 RenderPassDrawQuad
* render_pass_quad
=
121 this->CreateAndAppendDrawQuad
<RenderPassDrawQuad
>();
122 render_pass_quad
->SetNew(shared_state
,
132 RenderPassDrawQuad
* render_pass_replica_quad
=
133 this->CreateAndAppendDrawQuad
<RenderPassDrawQuad
>();
134 render_pass_replica_quad
->SetNew(shared_state
,
145 SolidColorDrawQuad
* solid_color_quad
=
146 this->CreateAndAppendDrawQuad
<SolidColorDrawQuad
>();
147 solid_color_quad
->SetNew(
148 shared_state
, rect
, visible_rect
, SK_ColorRED
, false);
150 StreamVideoDrawQuad
* stream_video_quad
=
151 this->CreateAndAppendDrawQuad
<StreamVideoDrawQuad
>();
152 stream_video_quad
->SetNew(shared_state
,
159 TextureDrawQuad
* texture_quad
=
160 this->CreateAndAppendDrawQuad
<TextureDrawQuad
>();
161 texture_quad
->SetNew(shared_state
,
167 gfx::PointF(0.f
, 0.f
),
168 gfx::PointF(1.f
, 1.f
),
173 TextureDrawQuad
* mailbox_texture_quad
=
174 this->CreateAndAppendDrawQuad
<TextureDrawQuad
>();
175 mailbox_texture_quad
->SetNew(shared_state
,
181 gfx::PointF(0.f
, 0.f
),
182 gfx::PointF(1.f
, 1.f
),
187 TileDrawQuad
* scaled_tile_quad
=
188 this->CreateAndAppendDrawQuad
<TileDrawQuad
>();
189 scaled_tile_quad
->SetNew(shared_state
,
194 gfx::RectF(0, 0, 50, 50),
198 SharedQuadState
* transformed_state
= this->CreateAndAppendSharedQuadState();
199 transformed_state
->CopyFrom(shared_state
);
200 gfx::Transform rotation
;
202 transformed_state
->content_to_target_transform
=
203 transformed_state
->content_to_target_transform
* rotation
;
204 TileDrawQuad
* transformed_tile_quad
=
205 this->CreateAndAppendDrawQuad
<TileDrawQuad
>();
206 transformed_tile_quad
->SetNew(transformed_state
,
211 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),
235 ResourceProvider::ResourceId plane_resources
[4];
236 for (int i
= 0; i
< 4; ++i
) {
237 plane_resources
[i
] = resource_provider
->CreateResource(
240 ResourceProvider::TextureHintImmutable
,
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
,
251 gfx::RectF(0, 0, 100, 100),