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 gfx::Size
resource5_size(73, 26);
62 ResourceProvider::ResourceId resource5
= resource_provider
->CreateResource(
65 ResourceProvider::TextureHintImmutable
,
66 resource_provider
->best_texture_format());
67 resource_provider
->AllocateForTesting(resource5
);
68 ResourceProvider::ResourceId resource6
= resource_provider
->CreateResource(
71 ResourceProvider::TextureHintImmutable
,
72 resource_provider
->best_texture_format());
73 resource_provider
->AllocateForTesting(resource6
);
74 ResourceProvider::ResourceId resource7
= resource_provider
->CreateResource(
77 ResourceProvider::TextureHintImmutable
,
78 resource_provider
->best_texture_format());
79 resource_provider
->AllocateForTesting(resource7
);
81 unsigned target
= GL_TEXTURE_2D
;
82 gpu::Mailbox gpu_mailbox
;
83 memcpy(gpu_mailbox
.name
, "Hello world", strlen("Hello world") + 1);
84 scoped_ptr
<SingleReleaseCallbackImpl
> callback
=
85 SingleReleaseCallbackImpl::Create(base::Bind(&EmptyReleaseCallback
));
86 TextureMailbox
mailbox(gpu_mailbox
, target
, kSyncPointForMailboxTextureQuad
);
87 ResourceProvider::ResourceId resource8
=
88 resource_provider
->CreateResourceFromTextureMailbox(mailbox
,
90 resource_provider
->AllocateForTesting(resource8
);
92 SharedQuadState
* shared_state
= this->CreateAndAppendSharedQuadState();
93 shared_state
->SetAll(gfx::Transform(),
99 SkXfermode::kSrcOver_Mode
,
102 CheckerboardDrawQuad
* checkerboard_quad
=
103 this->CreateAndAppendDrawQuad
<CheckerboardDrawQuad
>();
104 checkerboard_quad
->SetNew(shared_state
, rect
, visible_rect
, SK_ColorRED
);
106 DebugBorderDrawQuad
* debug_border_quad
=
107 this->CreateAndAppendDrawQuad
<DebugBorderDrawQuad
>();
108 debug_border_quad
->SetNew(shared_state
, rect
, visible_rect
, SK_ColorRED
, 1);
110 IOSurfaceDrawQuad
* io_surface_quad
=
111 this->CreateAndAppendDrawQuad
<IOSurfaceDrawQuad
>();
112 io_surface_quad
->SetNew(shared_state
,
118 IOSurfaceDrawQuad::FLIPPED
);
120 if (child_pass
.layer_id
) {
121 RenderPassDrawQuad
* render_pass_quad
=
122 this->CreateAndAppendDrawQuad
<RenderPassDrawQuad
>();
123 render_pass_quad
->SetNew(shared_state
,
128 gfx::Vector2dF(1.f
, 1.f
),
134 RenderPassDrawQuad
* render_pass_replica_quad
=
135 this->CreateAndAppendDrawQuad
<RenderPassDrawQuad
>();
136 render_pass_replica_quad
->SetNew(shared_state
,
141 gfx::Vector2dF(1.f
, 1.f
),
148 SolidColorDrawQuad
* solid_color_quad
=
149 this->CreateAndAppendDrawQuad
<SolidColorDrawQuad
>();
150 solid_color_quad
->SetNew(
151 shared_state
, rect
, visible_rect
, SK_ColorRED
, false);
153 StreamVideoDrawQuad
* stream_video_quad
=
154 this->CreateAndAppendDrawQuad
<StreamVideoDrawQuad
>();
155 stream_video_quad
->SetNew(shared_state
,
162 TextureDrawQuad
* texture_quad
=
163 this->CreateAndAppendDrawQuad
<TextureDrawQuad
>();
164 texture_quad
->SetNew(shared_state
,
170 gfx::PointF(0.f
, 0.f
),
171 gfx::PointF(1.f
, 1.f
),
177 TextureDrawQuad
* mailbox_texture_quad
=
178 this->CreateAndAppendDrawQuad
<TextureDrawQuad
>();
179 mailbox_texture_quad
->SetNew(shared_state
,
185 gfx::PointF(0.f
, 0.f
),
186 gfx::PointF(1.f
, 1.f
),
192 TileDrawQuad
* scaled_tile_quad
=
193 this->CreateAndAppendDrawQuad
<TileDrawQuad
>();
194 scaled_tile_quad
->SetNew(shared_state
,
199 gfx::RectF(0, 0, 50, 50),
204 SharedQuadState
* transformed_state
= this->CreateAndAppendSharedQuadState();
205 transformed_state
->CopyFrom(shared_state
);
206 gfx::Transform rotation
;
208 transformed_state
->content_to_target_transform
=
209 transformed_state
->content_to_target_transform
* rotation
;
210 TileDrawQuad
* transformed_tile_quad
=
211 this->CreateAndAppendDrawQuad
<TileDrawQuad
>();
212 transformed_tile_quad
->SetNew(transformed_state
,
217 gfx::RectF(0, 0, 100, 100),
222 SharedQuadState
* shared_state2
= this->CreateAndAppendSharedQuadState();
223 shared_state
->SetAll(gfx::Transform(),
229 SkXfermode::kSrcOver_Mode
,
232 TileDrawQuad
* tile_quad
= this->CreateAndAppendDrawQuad
<TileDrawQuad
>();
233 tile_quad
->SetNew(shared_state2
,
238 gfx::RectF(0, 0, 100, 100),
243 ResourceProvider::ResourceId plane_resources
[4];
244 for (int i
= 0; i
< 4; ++i
) {
245 plane_resources
[i
] = resource_provider
->CreateResource(
248 ResourceProvider::TextureHintImmutable
,
249 resource_provider
->best_texture_format());
250 resource_provider
->AllocateForTesting(plane_resources
[i
]);
252 YUVVideoDrawQuad::ColorSpace color_space
= YUVVideoDrawQuad::REC_601
;
253 YUVVideoDrawQuad
* yuv_quad
=
254 this->CreateAndAppendDrawQuad
<YUVVideoDrawQuad
>();
255 yuv_quad
->SetNew(shared_state2
,
259 gfx::RectF(0, 0, 100, 100),