Setup a experiment to enable background tracing.
[chromium-blink-merge.git] / cc / test / render_pass_test_common.cc
blob3789efc7d7973ac685ed8d56b3cf72e4d66f83ab
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"
7 #include "base/bind.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"
22 namespace cc {
24 static void EmptyReleaseCallback(uint32 sync_point,
25 bool lost_resource,
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(),
86 rect.size(),
87 rect,
88 rect,
89 false,
91 SkXfermode::kSrcOver_Mode,
92 0);
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,
105 rect,
106 opaque_rect,
107 visible_rect,
108 gfx::Size(50, 50),
109 resource7,
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,
116 rect,
117 visible_rect,
118 child_pass,
119 resource5,
120 gfx::Vector2dF(1.f, 1.f),
121 resource5_size,
122 FilterOperations(),
123 gfx::Vector2dF(),
124 FilterOperations());
126 RenderPassDrawQuad* render_pass_replica_quad =
127 this->CreateAndAppendDrawQuad<RenderPassDrawQuad>();
128 render_pass_replica_quad->SetNew(shared_state,
129 rect,
130 visible_rect,
131 child_pass,
132 resource5,
133 gfx::Vector2dF(1.f, 1.f),
134 resource5_size,
135 FilterOperations(),
136 gfx::Vector2dF(),
137 FilterOperations());
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,
148 rect,
149 opaque_rect,
150 visible_rect,
151 resource6,
152 gfx::Transform());
154 TextureDrawQuad* texture_quad =
155 this->CreateAndAppendDrawQuad<TextureDrawQuad>();
156 texture_quad->SetNew(shared_state,
157 rect,
158 opaque_rect,
159 visible_rect,
160 resource1,
161 false,
162 gfx::PointF(0.f, 0.f),
163 gfx::PointF(1.f, 1.f),
164 SK_ColorTRANSPARENT,
165 vertex_opacity,
166 false,
167 false);
169 TextureDrawQuad* mailbox_texture_quad =
170 this->CreateAndAppendDrawQuad<TextureDrawQuad>();
171 mailbox_texture_quad->SetNew(shared_state,
172 rect,
173 opaque_rect,
174 visible_rect,
175 resource8,
176 false,
177 gfx::PointF(0.f, 0.f),
178 gfx::PointF(1.f, 1.f),
179 SK_ColorTRANSPARENT,
180 vertex_opacity,
181 false,
182 false);
184 TileDrawQuad* scaled_tile_quad =
185 this->CreateAndAppendDrawQuad<TileDrawQuad>();
186 scaled_tile_quad->SetNew(shared_state,
187 rect,
188 opaque_rect,
189 visible_rect,
190 resource2,
191 gfx::RectF(0, 0, 50, 50),
192 gfx::Size(50, 50),
193 false,
194 false);
196 SharedQuadState* transformed_state = this->CreateAndAppendSharedQuadState();
197 transformed_state->CopyFrom(shared_state);
198 gfx::Transform rotation;
199 rotation.Rotate(45);
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,
205 rect,
206 opaque_rect,
207 visible_rect,
208 resource3,
209 gfx::RectF(0, 0, 100, 100),
210 gfx::Size(100, 100),
211 false,
212 false);
214 SharedQuadState* shared_state2 = this->CreateAndAppendSharedQuadState();
215 shared_state->SetAll(gfx::Transform(),
216 rect.size(),
217 rect,
218 rect,
219 false,
221 SkXfermode::kSrcOver_Mode,
224 TileDrawQuad* tile_quad = this->CreateAndAppendDrawQuad<TileDrawQuad>();
225 tile_quad->SetNew(shared_state2,
226 rect,
227 opaque_rect,
228 visible_rect,
229 resource4,
230 gfx::RectF(0, 0, 100, 100),
231 gfx::Size(100, 100),
232 false,
233 false);
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);
253 } // namespace cc