Roll src/buildtools ea47835:451dcd0
[chromium-blink-merge.git] / cc / test / render_pass_test_common.cc
blob7237ce1099f92ae9911127eeb8c2598408dab39e
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 ResourceProvider::ResourceId resource1 = resource_provider->CreateResource(
38 gfx::Size(45, 5),
39 GL_CLAMP_TO_EDGE,
40 ResourceProvider::TextureHintImmutable,
41 resource_provider->best_texture_format());
42 resource_provider->AllocateForTesting(resource1);
43 ResourceProvider::ResourceId resource2 = resource_provider->CreateResource(
44 gfx::Size(346, 61),
45 GL_CLAMP_TO_EDGE,
46 ResourceProvider::TextureHintImmutable,
47 resource_provider->best_texture_format());
48 resource_provider->AllocateForTesting(resource2);
49 ResourceProvider::ResourceId resource3 = resource_provider->CreateResource(
50 gfx::Size(12, 134),
51 GL_CLAMP_TO_EDGE,
52 ResourceProvider::TextureHintImmutable,
53 resource_provider->best_texture_format());
54 resource_provider->AllocateForTesting(resource3);
55 ResourceProvider::ResourceId resource4 = resource_provider->CreateResource(
56 gfx::Size(56, 12),
57 GL_CLAMP_TO_EDGE,
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(
63 resource5_size,
64 GL_CLAMP_TO_EDGE,
65 ResourceProvider::TextureHintImmutable,
66 resource_provider->best_texture_format());
67 resource_provider->AllocateForTesting(resource5);
68 ResourceProvider::ResourceId resource6 = resource_provider->CreateResource(
69 gfx::Size(64, 92),
70 GL_CLAMP_TO_EDGE,
71 ResourceProvider::TextureHintImmutable,
72 resource_provider->best_texture_format());
73 resource_provider->AllocateForTesting(resource6);
74 ResourceProvider::ResourceId resource7 = resource_provider->CreateResource(
75 gfx::Size(9, 14),
76 GL_CLAMP_TO_EDGE,
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,
89 callback.Pass());
90 resource_provider->AllocateForTesting(resource8);
92 SharedQuadState* shared_state = this->CreateAndAppendSharedQuadState();
93 shared_state->SetAll(gfx::Transform(),
94 rect.size(),
95 rect,
96 rect,
97 false,
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,
113 rect,
114 opaque_rect,
115 visible_rect,
116 gfx::Size(50, 50),
117 resource7,
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,
124 rect,
125 visible_rect,
126 child_pass,
127 resource5,
128 gfx::Vector2dF(1.f, 1.f),
129 resource5_size,
130 FilterOperations(),
131 gfx::Vector2dF(),
132 FilterOperations());
134 RenderPassDrawQuad* render_pass_replica_quad =
135 this->CreateAndAppendDrawQuad<RenderPassDrawQuad>();
136 render_pass_replica_quad->SetNew(shared_state,
137 rect,
138 visible_rect,
139 child_pass,
140 resource5,
141 gfx::Vector2dF(1.f, 1.f),
142 resource5_size,
143 FilterOperations(),
144 gfx::Vector2dF(),
145 FilterOperations());
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,
156 rect,
157 opaque_rect,
158 visible_rect,
159 resource6,
160 gfx::Transform());
162 TextureDrawQuad* texture_quad =
163 this->CreateAndAppendDrawQuad<TextureDrawQuad>();
164 texture_quad->SetNew(shared_state,
165 rect,
166 opaque_rect,
167 visible_rect,
168 resource1,
169 false,
170 gfx::PointF(0.f, 0.f),
171 gfx::PointF(1.f, 1.f),
172 SK_ColorTRANSPARENT,
173 vertex_opacity,
174 false,
175 false);
177 TextureDrawQuad* mailbox_texture_quad =
178 this->CreateAndAppendDrawQuad<TextureDrawQuad>();
179 mailbox_texture_quad->SetNew(shared_state,
180 rect,
181 opaque_rect,
182 visible_rect,
183 resource8,
184 false,
185 gfx::PointF(0.f, 0.f),
186 gfx::PointF(1.f, 1.f),
187 SK_ColorTRANSPARENT,
188 vertex_opacity,
189 false,
190 false);
192 TileDrawQuad* scaled_tile_quad =
193 this->CreateAndAppendDrawQuad<TileDrawQuad>();
194 scaled_tile_quad->SetNew(shared_state,
195 rect,
196 opaque_rect,
197 visible_rect,
198 resource2,
199 gfx::RectF(0, 0, 50, 50),
200 gfx::Size(50, 50),
201 false,
202 false);
204 SharedQuadState* transformed_state = this->CreateAndAppendSharedQuadState();
205 transformed_state->CopyFrom(shared_state);
206 gfx::Transform rotation;
207 rotation.Rotate(45);
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,
213 rect,
214 opaque_rect,
215 visible_rect,
216 resource3,
217 gfx::RectF(0, 0, 100, 100),
218 gfx::Size(100, 100),
219 false,
220 false);
222 SharedQuadState* shared_state2 = this->CreateAndAppendSharedQuadState();
223 shared_state->SetAll(gfx::Transform(),
224 rect.size(),
225 rect,
226 rect,
227 false,
229 SkXfermode::kSrcOver_Mode,
232 TileDrawQuad* tile_quad = this->CreateAndAppendDrawQuad<TileDrawQuad>();
233 tile_quad->SetNew(shared_state2,
234 rect,
235 opaque_rect,
236 visible_rect,
237 resource4,
238 gfx::RectF(0, 0, 100, 100),
239 gfx::Size(100, 100),
240 false,
241 false);
243 ResourceProvider::ResourceId plane_resources[4];
244 for (int i = 0; i < 4; ++i) {
245 plane_resources[i] = resource_provider->CreateResource(
246 gfx::Size(20, 12),
247 GL_CLAMP_TO_EDGE,
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,
256 rect,
257 opaque_rect,
258 visible_rect,
259 gfx::RectF(0, 0, 100, 100),
260 plane_resources[0],
261 plane_resources[1],
262 plane_resources[2],
263 plane_resources[3],
264 color_space);
267 } // namespace cc