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/debug_border_draw_quad.h"
9 #include "cc/quads/io_surface_draw_quad.h"
10 #include "cc/quads/render_pass_draw_quad.h"
11 #include "cc/quads/shared_quad_state.h"
12 #include "cc/quads/solid_color_draw_quad.h"
13 #include "cc/quads/stream_video_draw_quad.h"
14 #include "cc/quads/texture_draw_quad.h"
15 #include "cc/quads/tile_draw_quad.h"
16 #include "cc/quads/yuv_video_draw_quad.h"
17 #include "cc/resources/resource_provider.h"
18 #include "cc/trees/blocking_task_runner.h"
19 #include "ui/gfx/transform.h"
23 static void EmptyReleaseCallback(uint32 sync_point
,
25 BlockingTaskRunner
* main_thread_task_runner
) {
28 void TestRenderPass::AppendOneOfEveryQuadType(
29 ResourceProvider
* resource_provider
,
30 RenderPassId child_pass
) {
31 gfx::Rect
rect(0, 0, 100, 100);
32 gfx::Rect
opaque_rect(10, 10, 80, 80);
33 gfx::Rect
visible_rect(0, 0, 100, 100);
34 const float vertex_opacity
[] = {1.0f
, 1.0f
, 1.0f
, 1.0f
};
36 ResourceId resource1
= resource_provider
->CreateResource(
37 gfx::Size(45, 5), GL_CLAMP_TO_EDGE
,
38 ResourceProvider::TEXTURE_HINT_IMMUTABLE
,
39 resource_provider
->best_texture_format());
40 resource_provider
->AllocateForTesting(resource1
);
41 ResourceId resource2
= resource_provider
->CreateResource(
42 gfx::Size(346, 61), GL_CLAMP_TO_EDGE
,
43 ResourceProvider::TEXTURE_HINT_IMMUTABLE
,
44 resource_provider
->best_texture_format());
45 resource_provider
->AllocateForTesting(resource2
);
46 ResourceId resource3
= resource_provider
->CreateResource(
47 gfx::Size(12, 134), GL_CLAMP_TO_EDGE
,
48 ResourceProvider::TEXTURE_HINT_IMMUTABLE
,
49 resource_provider
->best_texture_format());
50 resource_provider
->AllocateForTesting(resource3
);
51 ResourceId resource4
= resource_provider
->CreateResource(
52 gfx::Size(56, 12), GL_CLAMP_TO_EDGE
,
53 ResourceProvider::TEXTURE_HINT_IMMUTABLE
,
54 resource_provider
->best_texture_format());
55 resource_provider
->AllocateForTesting(resource4
);
56 gfx::Size
resource5_size(73, 26);
57 ResourceId resource5
= resource_provider
->CreateResource(
58 resource5_size
, GL_CLAMP_TO_EDGE
,
59 ResourceProvider::TEXTURE_HINT_IMMUTABLE
,
60 resource_provider
->best_texture_format());
61 resource_provider
->AllocateForTesting(resource5
);
62 ResourceId resource6
= resource_provider
->CreateResource(
63 gfx::Size(64, 92), GL_CLAMP_TO_EDGE
,
64 ResourceProvider::TEXTURE_HINT_IMMUTABLE
,
65 resource_provider
->best_texture_format());
66 resource_provider
->AllocateForTesting(resource6
);
67 ResourceId resource7
= resource_provider
->CreateResource(
68 gfx::Size(9, 14), GL_CLAMP_TO_EDGE
,
69 ResourceProvider::TEXTURE_HINT_IMMUTABLE
,
70 resource_provider
->best_texture_format());
71 resource_provider
->AllocateForTesting(resource7
);
73 unsigned target
= GL_TEXTURE_2D
;
74 gpu::Mailbox gpu_mailbox
;
75 memcpy(gpu_mailbox
.name
, "Hello world", strlen("Hello world") + 1);
76 scoped_ptr
<SingleReleaseCallbackImpl
> callback
=
77 SingleReleaseCallbackImpl::Create(base::Bind(&EmptyReleaseCallback
));
78 TextureMailbox
mailbox(gpu_mailbox
, target
, kSyncPointForMailboxTextureQuad
);
79 ResourceId resource8
= resource_provider
->CreateResourceFromTextureMailbox(
80 mailbox
, callback
.Pass());
81 resource_provider
->AllocateForTesting(resource8
);
83 SharedQuadState
* shared_state
= this->CreateAndAppendSharedQuadState();
84 shared_state
->SetAll(gfx::Transform(),
90 SkXfermode::kSrcOver_Mode
,
93 DebugBorderDrawQuad
* debug_border_quad
=
94 this->CreateAndAppendDrawQuad
<DebugBorderDrawQuad
>();
95 debug_border_quad
->SetNew(shared_state
, rect
, visible_rect
, SK_ColorRED
, 1);
97 IOSurfaceDrawQuad
* io_surface_quad
=
98 this->CreateAndAppendDrawQuad
<IOSurfaceDrawQuad
>();
99 io_surface_quad
->SetNew(shared_state
,
105 IOSurfaceDrawQuad::FLIPPED
);
107 if (child_pass
.layer_id
) {
108 RenderPassDrawQuad
* render_pass_quad
=
109 this->CreateAndAppendDrawQuad
<RenderPassDrawQuad
>();
110 render_pass_quad
->SetNew(shared_state
,
115 gfx::Vector2dF(1.f
, 1.f
),
121 RenderPassDrawQuad
* render_pass_replica_quad
=
122 this->CreateAndAppendDrawQuad
<RenderPassDrawQuad
>();
123 render_pass_replica_quad
->SetNew(shared_state
,
128 gfx::Vector2dF(1.f
, 1.f
),
135 SolidColorDrawQuad
* solid_color_quad
=
136 this->CreateAndAppendDrawQuad
<SolidColorDrawQuad
>();
137 solid_color_quad
->SetNew(
138 shared_state
, rect
, visible_rect
, SK_ColorRED
, false);
140 StreamVideoDrawQuad
* stream_video_quad
=
141 this->CreateAndAppendDrawQuad
<StreamVideoDrawQuad
>();
142 stream_video_quad
->SetNew(shared_state
, rect
, opaque_rect
, visible_rect
,
143 resource6
, gfx::Size(), false, gfx::Transform());
145 TextureDrawQuad
* texture_quad
=
146 this->CreateAndAppendDrawQuad
<TextureDrawQuad
>();
147 texture_quad
->SetNew(shared_state
,
153 gfx::PointF(0.f
, 0.f
),
154 gfx::PointF(1.f
, 1.f
),
160 TextureDrawQuad
* mailbox_texture_quad
=
161 this->CreateAndAppendDrawQuad
<TextureDrawQuad
>();
162 mailbox_texture_quad
->SetNew(shared_state
,
168 gfx::PointF(0.f
, 0.f
),
169 gfx::PointF(1.f
, 1.f
),
175 TileDrawQuad
* scaled_tile_quad
=
176 this->CreateAndAppendDrawQuad
<TileDrawQuad
>();
177 scaled_tile_quad
->SetNew(shared_state
,
182 gfx::RectF(0, 0, 50, 50),
187 SharedQuadState
* transformed_state
= this->CreateAndAppendSharedQuadState();
188 transformed_state
->CopyFrom(shared_state
);
189 gfx::Transform rotation
;
191 transformed_state
->quad_to_target_transform
=
192 transformed_state
->quad_to_target_transform
* rotation
;
193 TileDrawQuad
* transformed_tile_quad
=
194 this->CreateAndAppendDrawQuad
<TileDrawQuad
>();
195 transformed_tile_quad
->SetNew(transformed_state
,
200 gfx::RectF(0, 0, 100, 100),
205 SharedQuadState
* shared_state2
= this->CreateAndAppendSharedQuadState();
206 shared_state
->SetAll(gfx::Transform(),
212 SkXfermode::kSrcOver_Mode
,
215 TileDrawQuad
* tile_quad
= this->CreateAndAppendDrawQuad
<TileDrawQuad
>();
216 tile_quad
->SetNew(shared_state2
,
221 gfx::RectF(0, 0, 100, 100),
226 ResourceId plane_resources
[4];
227 for (int i
= 0; i
< 4; ++i
) {
228 plane_resources
[i
] = resource_provider
->CreateResource(
229 gfx::Size(20, 12), GL_CLAMP_TO_EDGE
,
230 ResourceProvider::TEXTURE_HINT_IMMUTABLE
,
231 resource_provider
->best_texture_format());
232 resource_provider
->AllocateForTesting(plane_resources
[i
]);
234 YUVVideoDrawQuad::ColorSpace color_space
= YUVVideoDrawQuad::REC_601
;
235 YUVVideoDrawQuad
* yuv_quad
=
236 this->CreateAndAppendDrawQuad
<YUVVideoDrawQuad
>();
237 yuv_quad
->SetNew(shared_state2
, rect
, opaque_rect
, visible_rect
,
238 gfx::RectF(.0f
, .0f
, 100.0f
, 100.0f
),
239 gfx::RectF(.0f
, .0f
, 50.0f
, 50.0f
), gfx::Size(100, 100),
240 gfx::Size(50, 50), plane_resources
[0], plane_resources
[1],
241 plane_resources
[2], plane_resources
[3], color_space
);