OLD | NEW |
| (Empty) |
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. | |
4 | |
5 #include "cc/output/gl_renderer.h" | |
6 | |
7 #include "base/message_loop.h" | |
8 #include "cc/layers/append_quads_data.h" | |
9 #include "cc/quads/draw_quad.h" | |
10 #include "cc/resources/sync_point_helper.h" | |
11 #include "cc/test/pixel_test.h" | |
12 #include "gpu/GLES2/gl2extchromium.h" | |
13 #include "third_party/skia/include/core/SkImageFilter.h" | |
14 #include "third_party/skia/include/core/SkMatrix.h" | |
15 #include "third_party/skia/include/effects/SkColorFilterImageFilter.h" | |
16 #include "third_party/skia/include/effects/SkColorMatrixFilter.h" | |
17 | |
18 namespace cc { | |
19 namespace { | |
20 | |
21 class GLRendererPixelTest : public PixelTest {}; | |
22 | |
23 scoped_ptr<RenderPass> CreateTestRootRenderPass(RenderPass::Id id, | |
24 gfx::Rect rect) { | |
25 scoped_ptr<RenderPass> pass = RenderPass::Create(); | |
26 const gfx::Rect output_rect = rect; | |
27 const gfx::RectF damage_rect = rect; | |
28 const gfx::Transform transform_to_root_target; | |
29 pass->SetNew(id, output_rect, damage_rect, transform_to_root_target); | |
30 return pass.Pass(); | |
31 } | |
32 | |
33 scoped_ptr<RenderPass> CreateTestRenderPass( | |
34 RenderPass::Id id, | |
35 gfx::Rect rect, | |
36 const gfx::Transform& transform_to_root_target) { | |
37 scoped_ptr<RenderPass> pass = RenderPass::Create(); | |
38 const gfx::Rect output_rect = rect; | |
39 const gfx::RectF damage_rect = rect; | |
40 pass->SetNew(id, output_rect, damage_rect, transform_to_root_target); | |
41 return pass.Pass(); | |
42 } | |
43 | |
44 scoped_ptr<SharedQuadState> CreateTestSharedQuadState( | |
45 gfx::Transform content_to_target_transform, gfx::Rect rect) { | |
46 const gfx::Size content_bounds = rect.size(); | |
47 const gfx::Rect visible_content_rect = rect; | |
48 const gfx::Rect clip_rect = rect; | |
49 const bool is_clipped = false; | |
50 const float opacity = 1.0f; | |
51 scoped_ptr<SharedQuadState> shared_state = SharedQuadState::Create(); | |
52 shared_state->SetAll(content_to_target_transform, | |
53 content_bounds, | |
54 visible_content_rect, | |
55 clip_rect, | |
56 is_clipped, | |
57 opacity); | |
58 return shared_state.Pass(); | |
59 } | |
60 | |
61 scoped_ptr<DrawQuad> CreateTestRenderPassDrawQuad( | |
62 SharedQuadState* shared_state, gfx::Rect rect, RenderPass::Id pass_id) { | |
63 scoped_ptr<RenderPassDrawQuad> quad = RenderPassDrawQuad::Create(); | |
64 quad->SetNew(shared_state, | |
65 rect, | |
66 pass_id, | |
67 false, // is_replica | |
68 0, // mask_resource_id | |
69 rect, // contents_changed_since_last_frame | |
70 gfx::RectF(), // mask_uv_rect | |
71 WebKit::WebFilterOperations(), // foreground filters | |
72 skia::RefPtr<SkImageFilter>(), // foreground filter | |
73 WebKit::WebFilterOperations()); // background filters | |
74 | |
75 return quad.PassAs<DrawQuad>(); | |
76 } | |
77 | |
78 | |
79 #if !defined(OS_ANDROID) | |
80 TEST_F(GLRendererPixelTest, SimpleGreenRect) { | |
81 gfx::Rect rect(device_viewport_size_); | |
82 | |
83 RenderPass::Id id(1, 1); | |
84 scoped_ptr<RenderPass> pass = CreateTestRootRenderPass(id, rect); | |
85 | |
86 gfx::Transform content_to_target_transform; | |
87 scoped_ptr<SharedQuadState> shared_state = | |
88 CreateTestSharedQuadState(content_to_target_transform, rect); | |
89 | |
90 scoped_ptr<SolidColorDrawQuad> color_quad = SolidColorDrawQuad::Create(); | |
91 color_quad->SetNew(shared_state.get(), rect, SK_ColorGREEN); | |
92 | |
93 pass->quad_list.push_back(color_quad.PassAs<DrawQuad>()); | |
94 | |
95 RenderPassList pass_list; | |
96 pass_list.push_back(pass.Pass()); | |
97 | |
98 EXPECT_TRUE(RunPixelTest( | |
99 &pass_list, | |
100 base::FilePath(FILE_PATH_LITERAL("green.png")), | |
101 ExactPixelComparator(true))); | |
102 } | |
103 | |
104 TEST_F(GLRendererPixelTest, FastPassColorFilterAlpha) { | |
105 gfx::Rect viewport_rect(device_viewport_size_); | |
106 | |
107 RenderPass::Id root_pass_id(1, 1); | |
108 scoped_ptr<RenderPass> root_pass = | |
109 CreateTestRootRenderPass(root_pass_id, viewport_rect); | |
110 | |
111 RenderPass::Id child_pass_id(2, 2); | |
112 gfx::Rect pass_rect(device_viewport_size_); | |
113 gfx::Transform transform_to_root; | |
114 scoped_ptr<RenderPass> child_pass = | |
115 CreateTestRenderPass(child_pass_id, pass_rect, transform_to_root); | |
116 | |
117 gfx::Transform content_to_target_transform; | |
118 scoped_ptr<SharedQuadState> shared_state = | |
119 CreateTestSharedQuadState(content_to_target_transform, viewport_rect); | |
120 shared_state->opacity = 0.5f; | |
121 | |
122 scoped_ptr<SolidColorDrawQuad> blue = SolidColorDrawQuad::Create(); | |
123 blue->SetNew(shared_state.get(), | |
124 gfx::Rect(0, | |
125 0, | |
126 device_viewport_size_.width() / 2, | |
127 device_viewport_size_.height()), | |
128 SK_ColorBLUE); | |
129 scoped_ptr<SolidColorDrawQuad> yellow = SolidColorDrawQuad::Create(); | |
130 yellow->SetNew(shared_state.get(), | |
131 gfx::Rect(device_viewport_size_.width() / 2, | |
132 0, | |
133 device_viewport_size_.width() / 2, | |
134 device_viewport_size_.height()), | |
135 SK_ColorYELLOW); | |
136 | |
137 scoped_ptr<SharedQuadState> blank_state = | |
138 CreateTestSharedQuadState(content_to_target_transform, viewport_rect); | |
139 | |
140 scoped_ptr<SolidColorDrawQuad> white = SolidColorDrawQuad::Create(); | |
141 white->SetNew(blank_state.get(), | |
142 viewport_rect, | |
143 SK_ColorWHITE); | |
144 | |
145 child_pass->quad_list.push_back(blue.PassAs<DrawQuad>()); | |
146 child_pass->quad_list.push_back(yellow.PassAs<DrawQuad>()); | |
147 child_pass->quad_list.push_back(white.PassAs<DrawQuad>()); | |
148 | |
149 scoped_ptr<SharedQuadState> pass_shared_state = | |
150 CreateTestSharedQuadState(gfx::Transform(), pass_rect); | |
151 | |
152 SkScalar matrix[20]; | |
153 float amount = 0.5f; | |
154 matrix[0] = 0.213f + 0.787f * amount; | |
155 matrix[1] = 0.715f - 0.715f * amount; | |
156 matrix[2] = 1.f - (matrix[0] + matrix[1]); | |
157 matrix[3] = matrix[4] = 0; | |
158 matrix[5] = 0.213f - 0.213f * amount; | |
159 matrix[6] = 0.715f + 0.285f * amount; | |
160 matrix[7] = 1.f - (matrix[5] + matrix[6]); | |
161 matrix[8] = matrix[9] = 0; | |
162 matrix[10] = 0.213f - 0.213f * amount; | |
163 matrix[11] = 0.715f - 0.715f * amount; | |
164 matrix[12] = 1.f - (matrix[10] + matrix[11]); | |
165 matrix[13] = matrix[14] = 0; | |
166 matrix[15] = matrix[16] = matrix[17] = matrix[19] = 0; | |
167 matrix[18] = 1; | |
168 skia::RefPtr<SkColorFilter> colorFilter(skia::AdoptRef( | |
169 new SkColorMatrixFilter(matrix))); | |
170 skia::RefPtr<SkImageFilter> filter = | |
171 skia::AdoptRef(SkColorFilterImageFilter::Create(colorFilter.get(), NULL)); | |
172 | |
173 scoped_ptr<RenderPassDrawQuad> render_pass_quad = | |
174 RenderPassDrawQuad::Create(); | |
175 render_pass_quad->SetNew(pass_shared_state.get(), | |
176 pass_rect, | |
177 child_pass_id, | |
178 false, | |
179 0, | |
180 pass_rect, | |
181 gfx::RectF(), | |
182 WebKit::WebFilterOperations(), | |
183 filter, | |
184 WebKit::WebFilterOperations()); | |
185 | |
186 root_pass->quad_list.push_back(render_pass_quad.PassAs<DrawQuad>()); | |
187 | |
188 RenderPassList pass_list; | |
189 pass_list.push_back(child_pass.Pass()); | |
190 pass_list.push_back(root_pass.Pass()); | |
191 | |
192 EXPECT_TRUE(RunPixelTest( | |
193 &pass_list, | |
194 base::FilePath(FILE_PATH_LITERAL("blue_yellow_alpha.png")), | |
195 ExactPixelComparator(false))); | |
196 } | |
197 | |
198 TEST_F(GLRendererPixelTest, FastPassColorFilterAlphaTranslation) { | |
199 gfx::Rect viewport_rect(device_viewport_size_); | |
200 | |
201 RenderPass::Id root_pass_id(1, 1); | |
202 scoped_ptr<RenderPass> root_pass = | |
203 CreateTestRootRenderPass(root_pass_id, viewport_rect); | |
204 | |
205 RenderPass::Id child_pass_id(2, 2); | |
206 gfx::Rect pass_rect(device_viewport_size_); | |
207 gfx::Transform transform_to_root; | |
208 scoped_ptr<RenderPass> child_pass = | |
209 CreateTestRenderPass(child_pass_id, pass_rect, transform_to_root); | |
210 | |
211 gfx::Transform content_to_target_transform; | |
212 scoped_ptr<SharedQuadState> shared_state = | |
213 CreateTestSharedQuadState(content_to_target_transform, viewport_rect); | |
214 shared_state->opacity = 0.5f; | |
215 | |
216 scoped_ptr<SolidColorDrawQuad> blue = SolidColorDrawQuad::Create(); | |
217 blue->SetNew(shared_state.get(), | |
218 gfx::Rect(0, | |
219 0, | |
220 device_viewport_size_.width() / 2, | |
221 device_viewport_size_.height()), | |
222 SK_ColorBLUE); | |
223 scoped_ptr<SolidColorDrawQuad> yellow = SolidColorDrawQuad::Create(); | |
224 yellow->SetNew(shared_state.get(), | |
225 gfx::Rect(device_viewport_size_.width() / 2, | |
226 0, | |
227 device_viewport_size_.width() / 2, | |
228 device_viewport_size_.height()), | |
229 SK_ColorYELLOW); | |
230 | |
231 scoped_ptr<SharedQuadState> blank_state = | |
232 CreateTestSharedQuadState(content_to_target_transform, viewport_rect); | |
233 | |
234 scoped_ptr<SolidColorDrawQuad> white = SolidColorDrawQuad::Create(); | |
235 white->SetNew(blank_state.get(), | |
236 viewport_rect, | |
237 SK_ColorWHITE); | |
238 | |
239 child_pass->quad_list.push_back(blue.PassAs<DrawQuad>()); | |
240 child_pass->quad_list.push_back(yellow.PassAs<DrawQuad>()); | |
241 child_pass->quad_list.push_back(white.PassAs<DrawQuad>()); | |
242 | |
243 scoped_ptr<SharedQuadState> pass_shared_state = | |
244 CreateTestSharedQuadState(gfx::Transform(), pass_rect); | |
245 | |
246 SkScalar matrix[20]; | |
247 float amount = 0.5f; | |
248 matrix[0] = 0.213f + 0.787f * amount; | |
249 matrix[1] = 0.715f - 0.715f * amount; | |
250 matrix[2] = 1.f - (matrix[0] + matrix[1]); | |
251 matrix[3] = 0; | |
252 matrix[4] = 20.f; | |
253 matrix[5] = 0.213f - 0.213f * amount; | |
254 matrix[6] = 0.715f + 0.285f * amount; | |
255 matrix[7] = 1.f - (matrix[5] + matrix[6]); | |
256 matrix[8] = 0; | |
257 matrix[9] = 200.f; | |
258 matrix[10] = 0.213f - 0.213f * amount; | |
259 matrix[11] = 0.715f - 0.715f * amount; | |
260 matrix[12] = 1.f - (matrix[10] + matrix[11]); | |
261 matrix[13] = 0; | |
262 matrix[14] = 1.5f; | |
263 matrix[15] = matrix[16] = matrix[17] = matrix[19] = 0; | |
264 matrix[18] = 1; | |
265 skia::RefPtr<SkColorFilter> colorFilter(skia::AdoptRef( | |
266 new SkColorMatrixFilter(matrix))); | |
267 skia::RefPtr<SkImageFilter> filter = | |
268 skia::AdoptRef(SkColorFilterImageFilter::Create(colorFilter.get(), NULL)); | |
269 | |
270 scoped_ptr<RenderPassDrawQuad> render_pass_quad = | |
271 RenderPassDrawQuad::Create(); | |
272 render_pass_quad->SetNew(pass_shared_state.get(), | |
273 pass_rect, | |
274 child_pass_id, | |
275 false, | |
276 0, | |
277 pass_rect, | |
278 gfx::RectF(), | |
279 WebKit::WebFilterOperations(), | |
280 filter, | |
281 WebKit::WebFilterOperations()); | |
282 | |
283 root_pass->quad_list.push_back(render_pass_quad.PassAs<DrawQuad>()); | |
284 RenderPassList pass_list; | |
285 | |
286 pass_list.push_back(child_pass.Pass()); | |
287 pass_list.push_back(root_pass.Pass()); | |
288 | |
289 EXPECT_TRUE(RunPixelTest( | |
290 &pass_list, | |
291 base::FilePath(FILE_PATH_LITERAL("blue_yellow_alpha_translate.png")), | |
292 ExactPixelComparator(false))); | |
293 } | |
294 | |
295 TEST_F(GLRendererPixelTest, RenderPassChangesSize) { | |
296 gfx::Rect viewport_rect(device_viewport_size_); | |
297 | |
298 RenderPass::Id root_pass_id(1, 1); | |
299 scoped_ptr<RenderPass> root_pass = | |
300 CreateTestRootRenderPass(root_pass_id, viewport_rect); | |
301 | |
302 RenderPass::Id child_pass_id(2, 2); | |
303 gfx::Rect pass_rect(device_viewport_size_); | |
304 gfx::Transform transform_to_root; | |
305 scoped_ptr<RenderPass> child_pass = | |
306 CreateTestRenderPass(child_pass_id, pass_rect, transform_to_root); | |
307 | |
308 gfx::Transform content_to_target_transform; | |
309 scoped_ptr<SharedQuadState> shared_state = | |
310 CreateTestSharedQuadState(content_to_target_transform, viewport_rect); | |
311 | |
312 scoped_ptr<SolidColorDrawQuad> blue = SolidColorDrawQuad::Create(); | |
313 blue->SetNew(shared_state.get(), | |
314 gfx::Rect(0, | |
315 0, | |
316 device_viewport_size_.width() / 2, | |
317 device_viewport_size_.height()), | |
318 SK_ColorBLUE); | |
319 scoped_ptr<SolidColorDrawQuad> yellow = SolidColorDrawQuad::Create(); | |
320 yellow->SetNew(shared_state.get(), | |
321 gfx::Rect(device_viewport_size_.width() / 2, | |
322 0, | |
323 device_viewport_size_.width() / 2, | |
324 device_viewport_size_.height()), | |
325 SK_ColorYELLOW); | |
326 | |
327 child_pass->quad_list.push_back(blue.PassAs<DrawQuad>()); | |
328 child_pass->quad_list.push_back(yellow.PassAs<DrawQuad>()); | |
329 | |
330 scoped_ptr<SharedQuadState> pass_shared_state = | |
331 CreateTestSharedQuadState(gfx::Transform(), pass_rect); | |
332 root_pass->quad_list.push_back( | |
333 CreateTestRenderPassDrawQuad(pass_shared_state.get(), | |
334 pass_rect, | |
335 child_pass_id)); | |
336 | |
337 RenderPassList pass_list; | |
338 pass_list.push_back(child_pass.Pass()); | |
339 pass_list.push_back(root_pass.Pass()); | |
340 | |
341 renderer_->SetEnlargePassTextureAmountForTesting(gfx::Vector2d(50, 75)); | |
342 | |
343 EXPECT_TRUE(RunPixelTest( | |
344 &pass_list, | |
345 base::FilePath(FILE_PATH_LITERAL("blue_yellow.png")), | |
346 ExactPixelComparator(true))); | |
347 } | |
348 | |
349 class GLRendererPixelTestWithBackgroundFilter : public GLRendererPixelTest { | |
350 protected: | |
351 void SetUpRenderPassList() { | |
352 gfx::Rect device_viewport_rect(device_viewport_size_); | |
353 | |
354 RenderPass::Id root_id(1, 1); | |
355 scoped_ptr<RenderPass> root_pass = | |
356 CreateTestRootRenderPass(root_id, device_viewport_rect); | |
357 root_pass->has_transparent_background = false; | |
358 | |
359 gfx::Transform identity_content_to_target_transform; | |
360 | |
361 RenderPass::Id filter_pass_id(2, 1); | |
362 gfx::Transform transform_to_root; | |
363 scoped_ptr<RenderPass> filter_pass = | |
364 CreateTestRenderPass(filter_pass_id, | |
365 filter_pass_content_rect_, | |
366 transform_to_root); | |
367 | |
368 // A non-visible quad in the filtering render pass. | |
369 { | |
370 scoped_ptr<SharedQuadState> shared_state = | |
371 CreateTestSharedQuadState(identity_content_to_target_transform, | |
372 filter_pass_content_rect_); | |
373 scoped_ptr<SolidColorDrawQuad> color_quad = SolidColorDrawQuad::Create(); | |
374 color_quad->SetNew(shared_state.get(), | |
375 filter_pass_content_rect_, | |
376 SK_ColorTRANSPARENT); | |
377 filter_pass->quad_list.push_back(color_quad.PassAs<DrawQuad>()); | |
378 filter_pass->shared_quad_state_list.push_back(shared_state.Pass()); | |
379 } | |
380 | |
381 { | |
382 scoped_ptr<SharedQuadState> shared_state = | |
383 CreateTestSharedQuadState(filter_pass_to_target_transform_, | |
384 filter_pass_content_rect_); | |
385 scoped_ptr<RenderPassDrawQuad> filter_pass_quad = | |
386 RenderPassDrawQuad::Create(); | |
387 filter_pass_quad->SetNew( | |
388 shared_state.get(), | |
389 filter_pass_content_rect_, | |
390 filter_pass_id, | |
391 false, // is_replica | |
392 0, // mask_resource_id | |
393 filter_pass_content_rect_, // contents_changed_since_last_frame | |
394 gfx::RectF(), // mask_uv_rect | |
395 WebKit::WebFilterOperations(), // filters | |
396 skia::RefPtr<SkImageFilter>(), // filter | |
397 background_filters_); | |
398 root_pass->quad_list.push_back(filter_pass_quad.PassAs<DrawQuad>()); | |
399 root_pass->shared_quad_state_list.push_back(shared_state.Pass()); | |
400 } | |
401 | |
402 const int kColumnWidth = device_viewport_rect.width() / 3; | |
403 | |
404 gfx::Rect left_rect = gfx::Rect(0, 0, kColumnWidth, 20); | |
405 for (int i = 0; left_rect.y() < device_viewport_rect.height(); ++i) { | |
406 scoped_ptr<SharedQuadState> shared_state = | |
407 CreateTestSharedQuadState(identity_content_to_target_transform, | |
408 left_rect); | |
409 scoped_ptr<SolidColorDrawQuad> color_quad = SolidColorDrawQuad::Create(); | |
410 color_quad->SetNew(shared_state.get(), left_rect, SK_ColorGREEN); | |
411 root_pass->quad_list.push_back(color_quad.PassAs<DrawQuad>()); | |
412 root_pass->shared_quad_state_list.push_back(shared_state.Pass()); | |
413 left_rect += gfx::Vector2d(0, left_rect.height() + 1); | |
414 } | |
415 | |
416 gfx::Rect middle_rect = gfx::Rect(kColumnWidth+1, 0, kColumnWidth, 20); | |
417 for (int i = 0; middle_rect.y() < device_viewport_rect.height(); ++i) { | |
418 scoped_ptr<SharedQuadState> shared_state = | |
419 CreateTestSharedQuadState(identity_content_to_target_transform, | |
420 middle_rect); | |
421 scoped_ptr<SolidColorDrawQuad> color_quad = SolidColorDrawQuad::Create(); | |
422 color_quad->SetNew(shared_state.get(), middle_rect, SK_ColorRED); | |
423 root_pass->quad_list.push_back(color_quad.PassAs<DrawQuad>()); | |
424 root_pass->shared_quad_state_list.push_back(shared_state.Pass()); | |
425 middle_rect += gfx::Vector2d(0, middle_rect.height() + 1); | |
426 } | |
427 | |
428 gfx::Rect right_rect = gfx::Rect((kColumnWidth+1)*2, 0, kColumnWidth, 20); | |
429 for (int i = 0; right_rect.y() < device_viewport_rect.height(); ++i) { | |
430 scoped_ptr<SharedQuadState> shared_state = | |
431 CreateTestSharedQuadState(identity_content_to_target_transform, | |
432 right_rect); | |
433 scoped_ptr<SolidColorDrawQuad> color_quad = SolidColorDrawQuad::Create(); | |
434 color_quad->SetNew(shared_state.get(), right_rect, SK_ColorBLUE); | |
435 root_pass->quad_list.push_back(color_quad.PassAs<DrawQuad>()); | |
436 root_pass->shared_quad_state_list.push_back(shared_state.Pass()); | |
437 right_rect += gfx::Vector2d(0, right_rect.height() + 1); | |
438 } | |
439 | |
440 scoped_ptr<SharedQuadState> shared_state = | |
441 CreateTestSharedQuadState(identity_content_to_target_transform, | |
442 device_viewport_rect); | |
443 scoped_ptr<SolidColorDrawQuad> background_quad = | |
444 SolidColorDrawQuad::Create(); | |
445 background_quad->SetNew(shared_state.get(), | |
446 device_viewport_rect, | |
447 SK_ColorWHITE); | |
448 root_pass->quad_list.push_back(background_quad.PassAs<DrawQuad>()); | |
449 root_pass->shared_quad_state_list.push_back(shared_state.Pass()); | |
450 | |
451 pass_list_.push_back(filter_pass.Pass()); | |
452 pass_list_.push_back(root_pass.Pass()); | |
453 } | |
454 | |
455 RenderPassList pass_list_; | |
456 WebKit::WebFilterOperations background_filters_; | |
457 gfx::Transform filter_pass_to_target_transform_; | |
458 gfx::Rect filter_pass_content_rect_; | |
459 }; | |
460 | |
461 TEST_F(GLRendererPixelTestWithBackgroundFilter, InvertFilter) { | |
462 background_filters_.append( | |
463 WebKit::WebFilterOperation::createInvertFilter(1.f)); | |
464 | |
465 filter_pass_content_rect_ = gfx::Rect(device_viewport_size_); | |
466 filter_pass_content_rect_.Inset(12, 14, 16, 18); | |
467 | |
468 SetUpRenderPassList(); | |
469 EXPECT_TRUE(RunPixelTest( | |
470 &pass_list_, | |
471 base::FilePath(FILE_PATH_LITERAL("background_filter.png")), | |
472 ExactPixelComparator(true))); | |
473 } | |
474 | |
475 TEST_F(GLRendererPixelTest, AntiAliasing) { | |
476 gfx::Rect rect(0, 0, 200, 200); | |
477 | |
478 RenderPass::Id id(1, 1); | |
479 scoped_ptr<RenderPass> pass = CreateTestRootRenderPass(id, rect); | |
480 | |
481 gfx::Transform red_content_to_target_transform; | |
482 red_content_to_target_transform.Rotate(10); | |
483 scoped_ptr<SharedQuadState> red_shared_state = | |
484 CreateTestSharedQuadState(red_content_to_target_transform, rect); | |
485 | |
486 scoped_ptr<SolidColorDrawQuad> red = SolidColorDrawQuad::Create(); | |
487 red->SetNew(red_shared_state.get(), rect, SK_ColorRED); | |
488 | |
489 pass->quad_list.push_back(red.PassAs<DrawQuad>()); | |
490 | |
491 gfx::Transform yellow_content_to_target_transform; | |
492 yellow_content_to_target_transform.Rotate(5); | |
493 scoped_ptr<SharedQuadState> yellow_shared_state = | |
494 CreateTestSharedQuadState(yellow_content_to_target_transform, rect); | |
495 | |
496 scoped_ptr<SolidColorDrawQuad> yellow = SolidColorDrawQuad::Create(); | |
497 yellow->SetNew(yellow_shared_state.get(), rect, SK_ColorYELLOW); | |
498 | |
499 pass->quad_list.push_back(yellow.PassAs<DrawQuad>()); | |
500 | |
501 gfx::Transform blue_content_to_target_transform; | |
502 scoped_ptr<SharedQuadState> blue_shared_state = | |
503 CreateTestSharedQuadState(blue_content_to_target_transform, rect); | |
504 | |
505 scoped_ptr<SolidColorDrawQuad> blue = SolidColorDrawQuad::Create(); | |
506 blue->SetNew(blue_shared_state.get(), rect, SK_ColorBLUE); | |
507 | |
508 pass->quad_list.push_back(blue.PassAs<DrawQuad>()); | |
509 | |
510 RenderPassList pass_list; | |
511 pass_list.push_back(pass.Pass()); | |
512 | |
513 EXPECT_TRUE(RunPixelTest( | |
514 &pass_list, | |
515 base::FilePath(FILE_PATH_LITERAL("anti_aliasing.png")), | |
516 ExactPixelComparator(true))); | |
517 } | |
518 | |
519 TEST_F(GLRendererPixelTest, AxisAligned) { | |
520 gfx::Rect rect(0, 0, 200, 200); | |
521 | |
522 RenderPass::Id id(1, 1); | |
523 gfx::Transform transform_to_root; | |
524 scoped_ptr<RenderPass> pass = | |
525 CreateTestRenderPass(id, rect, transform_to_root); | |
526 | |
527 gfx::Transform red_content_to_target_transform; | |
528 red_content_to_target_transform.Translate(50, 50); | |
529 red_content_to_target_transform.Scale( | |
530 0.5f + 1.0f / (rect.width() * 2.0f), | |
531 0.5f + 1.0f / (rect.height() * 2.0f)); | |
532 scoped_ptr<SharedQuadState> red_shared_state = | |
533 CreateTestSharedQuadState(red_content_to_target_transform, rect); | |
534 | |
535 scoped_ptr<SolidColorDrawQuad> red = SolidColorDrawQuad::Create(); | |
536 red->SetNew(red_shared_state.get(), rect, SK_ColorRED); | |
537 | |
538 pass->quad_list.push_back(red.PassAs<DrawQuad>()); | |
539 | |
540 gfx::Transform yellow_content_to_target_transform; | |
541 yellow_content_to_target_transform.Translate(25.5f, 25.5f); | |
542 yellow_content_to_target_transform.Scale(0.5f, 0.5f); | |
543 scoped_ptr<SharedQuadState> yellow_shared_state = | |
544 CreateTestSharedQuadState(yellow_content_to_target_transform, rect); | |
545 | |
546 scoped_ptr<SolidColorDrawQuad> yellow = SolidColorDrawQuad::Create(); | |
547 yellow->SetNew(yellow_shared_state.get(), rect, SK_ColorYELLOW); | |
548 | |
549 pass->quad_list.push_back(yellow.PassAs<DrawQuad>()); | |
550 | |
551 gfx::Transform blue_content_to_target_transform; | |
552 scoped_ptr<SharedQuadState> blue_shared_state = | |
553 CreateTestSharedQuadState(blue_content_to_target_transform, rect); | |
554 | |
555 scoped_ptr<SolidColorDrawQuad> blue = SolidColorDrawQuad::Create(); | |
556 blue->SetNew(blue_shared_state.get(), rect, SK_ColorBLUE); | |
557 | |
558 pass->quad_list.push_back(blue.PassAs<DrawQuad>()); | |
559 | |
560 RenderPassList pass_list; | |
561 pass_list.push_back(pass.Pass()); | |
562 | |
563 EXPECT_TRUE(RunPixelTest( | |
564 &pass_list, | |
565 base::FilePath(FILE_PATH_LITERAL("axis_aligned.png")), | |
566 ExactPixelComparator(true))); | |
567 } | |
568 | |
569 static void SyncPointCallback(int* callback_count) { | |
570 ++(*callback_count); | |
571 base::MessageLoop::current()->QuitWhenIdle(); | |
572 } | |
573 | |
574 static void OtherCallback(int* callback_count) { | |
575 ++(*callback_count); | |
576 base::MessageLoop::current()->QuitWhenIdle(); | |
577 } | |
578 | |
579 TEST_F(GLRendererPixelTest, SignalSyncPointOnLostContext) { | |
580 int sync_point_callback_count = 0; | |
581 int other_callback_count = 0; | |
582 unsigned sync_point = output_surface_->context3d()->insertSyncPoint(); | |
583 | |
584 output_surface_->context3d()->loseContextCHROMIUM( | |
585 GL_GUILTY_CONTEXT_RESET_ARB, GL_INNOCENT_CONTEXT_RESET_ARB); | |
586 | |
587 SyncPointHelper::SignalSyncPoint( | |
588 output_surface_->context3d(), | |
589 sync_point, | |
590 base::Bind(&SyncPointCallback, &sync_point_callback_count)); | |
591 EXPECT_EQ(0, sync_point_callback_count); | |
592 EXPECT_EQ(0, other_callback_count); | |
593 | |
594 // Make the sync point happen. | |
595 output_surface_->context3d()->finish(); | |
596 // Post a task after the sync point. | |
597 base::MessageLoop::current()->PostTask( | |
598 FROM_HERE, | |
599 base::Bind(&OtherCallback, &other_callback_count)); | |
600 | |
601 base::MessageLoop::current()->Run(); | |
602 | |
603 // The sync point shouldn't have happened since the context was lost. | |
604 EXPECT_EQ(0, sync_point_callback_count); | |
605 EXPECT_EQ(1, other_callback_count); | |
606 } | |
607 | |
608 TEST_F(GLRendererPixelTest, SignalSyncPoint) { | |
609 int sync_point_callback_count = 0; | |
610 int other_callback_count = 0; | |
611 unsigned sync_point = output_surface_->context3d()->insertSyncPoint(); | |
612 | |
613 SyncPointHelper::SignalSyncPoint( | |
614 output_surface_->context3d(), | |
615 sync_point, | |
616 base::Bind(&SyncPointCallback, &sync_point_callback_count)); | |
617 EXPECT_EQ(0, sync_point_callback_count); | |
618 EXPECT_EQ(0, other_callback_count); | |
619 | |
620 // Make the sync point happen. | |
621 output_surface_->context3d()->finish(); | |
622 // Post a task after the sync point. | |
623 base::MessageLoop::current()->PostTask( | |
624 FROM_HERE, | |
625 base::Bind(&OtherCallback, &other_callback_count)); | |
626 | |
627 base::MessageLoop::current()->Run(); | |
628 | |
629 // The sync point should have happened. | |
630 EXPECT_EQ(1, sync_point_callback_count); | |
631 EXPECT_EQ(1, other_callback_count); | |
632 } | |
633 #endif | |
634 | |
635 } // namespace | |
636 } // namespace cc | |
OLD | NEW |