Dismiss autofill popup on screen orientation change.
[chromium-blink-merge.git] / cc / output / renderer_pixeltest.cc
blobba76f169c9a1070d058ea9b3abb6facb6cb3381a
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 "base/message_loop/message_loop.h"
6 #include "cc/layers/append_quads_data.h"
7 #include "cc/output/gl_renderer.h"
8 #include "cc/quads/draw_quad.h"
9 #include "cc/quads/picture_draw_quad.h"
10 #include "cc/quads/texture_draw_quad.h"
11 #include "cc/resources/platform_color.h"
12 #include "cc/resources/sync_point_helper.h"
13 #include "cc/test/fake_picture_pile_impl.h"
14 #include "cc/test/pixel_test.h"
15 #include "gpu/GLES2/gl2extchromium.h"
16 #include "third_party/WebKit/public/platform/WebGraphicsContext3D.h"
17 #include "third_party/skia/include/core/SkImageFilter.h"
18 #include "third_party/skia/include/core/SkMatrix.h"
19 #include "third_party/skia/include/effects/SkColorFilterImageFilter.h"
20 #include "third_party/skia/include/effects/SkColorMatrixFilter.h"
21 #include "ui/gfx/rect_conversions.h"
23 namespace cc {
24 namespace {
26 scoped_ptr<RenderPass> CreateTestRootRenderPass(RenderPass::Id id,
27 gfx::Rect rect) {
28 scoped_ptr<RenderPass> pass = RenderPass::Create();
29 const gfx::Rect output_rect = rect;
30 const gfx::RectF damage_rect = rect;
31 const gfx::Transform transform_to_root_target;
32 pass->SetNew(id, output_rect, damage_rect, transform_to_root_target);
33 return pass.Pass();
36 scoped_ptr<RenderPass> CreateTestRenderPass(
37 RenderPass::Id id,
38 gfx::Rect rect,
39 const gfx::Transform& transform_to_root_target) {
40 scoped_ptr<RenderPass> pass = RenderPass::Create();
41 const gfx::Rect output_rect = rect;
42 const gfx::RectF damage_rect = rect;
43 pass->SetNew(id, output_rect, damage_rect, transform_to_root_target);
44 return pass.Pass();
47 scoped_ptr<SharedQuadState> CreateTestSharedQuadState(
48 gfx::Transform content_to_target_transform, gfx::Rect rect) {
49 const gfx::Size content_bounds = rect.size();
50 const gfx::Rect visible_content_rect = rect;
51 const gfx::Rect clip_rect = rect;
52 const bool is_clipped = false;
53 const float opacity = 1.0f;
54 scoped_ptr<SharedQuadState> shared_state = SharedQuadState::Create();
55 shared_state->SetAll(content_to_target_transform,
56 content_bounds,
57 visible_content_rect,
58 clip_rect,
59 is_clipped,
60 opacity);
61 return shared_state.Pass();
64 scoped_ptr<SharedQuadState> CreateTestSharedQuadStateClipped(
65 gfx::Transform content_to_target_transform,
66 gfx::Rect rect,
67 gfx::Rect clip_rect) {
68 const gfx::Size content_bounds = rect.size();
69 const gfx::Rect visible_content_rect = clip_rect;
70 const bool is_clipped = true;
71 const float opacity = 1.0f;
72 scoped_ptr<SharedQuadState> shared_state = SharedQuadState::Create();
73 shared_state->SetAll(content_to_target_transform,
74 content_bounds,
75 visible_content_rect,
76 clip_rect,
77 is_clipped,
78 opacity);
79 return shared_state.Pass();
82 scoped_ptr<DrawQuad> CreateTestRenderPassDrawQuad(
83 SharedQuadState* shared_state, gfx::Rect rect, RenderPass::Id pass_id) {
84 scoped_ptr<RenderPassDrawQuad> quad = RenderPassDrawQuad::Create();
85 quad->SetNew(shared_state,
86 rect,
87 pass_id,
88 false, // is_replica
89 0, // mask_resource_id
90 rect, // contents_changed_since_last_frame
91 gfx::RectF(), // mask_uv_rect
92 FilterOperations(), // foreground filters
93 skia::RefPtr<SkImageFilter>(), // foreground filter
94 FilterOperations()); // background filters
96 return quad.PassAs<DrawQuad>();
99 scoped_ptr<TextureDrawQuad> CreateTestTextureDrawQuad(
100 gfx::Rect rect,
101 SkColor texel_color,
102 SkColor background_color,
103 bool premultiplied_alpha,
104 SharedQuadState* shared_state,
105 ResourceProvider* resource_provider) {
106 SkPMColor pixel_color = premultiplied_alpha ?
107 SkPreMultiplyColor(texel_color) :
108 SkPackARGB32NoCheck(SkColorGetA(texel_color),
109 SkColorGetR(texel_color),
110 SkColorGetG(texel_color),
111 SkColorGetB(texel_color));
112 std::vector<uint32_t> pixels(rect.size().GetArea(), pixel_color);
114 ResourceProvider::ResourceId resource = resource_provider->CreateResource(
115 rect.size(), GL_RGBA, ResourceProvider::TextureUsageAny);
116 resource_provider->SetPixels(
117 resource,
118 reinterpret_cast<uint8_t*>(&pixels.front()),
119 rect,
120 rect,
121 gfx::Vector2d());
123 float vertex_opacity[4] = {1.0f, 1.0f, 1.0f, 1.0f};
125 scoped_ptr<TextureDrawQuad> quad = TextureDrawQuad::Create();
126 quad->SetNew(shared_state,
127 rect,
128 gfx::Rect(),
129 resource,
130 premultiplied_alpha,
131 gfx::PointF(0.0f, 0.0f), // uv_top_left
132 gfx::PointF(1.0f, 1.0f), // uv_bottom_right
133 background_color,
134 vertex_opacity,
135 false); // flipped
136 return quad.Pass();
139 typedef ::testing::Types<GLRenderer,
140 SoftwareRenderer,
141 GLRendererWithExpandedViewport,
142 SoftwareRendererWithExpandedViewport> RendererTypes;
143 TYPED_TEST_CASE(RendererPixelTest, RendererTypes);
145 typedef ::testing::Types<GLRenderer,
146 GLRendererWithSkiaGPUBackend,
147 SoftwareRenderer> RendererTypesWithSkiaGPUBackend;
148 template <typename RendererType>
149 class RendererPixelTestWithSkiaGPUBackend
150 : public RendererPixelTest<RendererType> {
152 TYPED_TEST_CASE(RendererPixelTestWithSkiaGPUBackend,
153 RendererTypesWithSkiaGPUBackend);
155 // All pixels can be off by one, but any more than that is an error.
156 class FuzzyPixelOffByOneComparator : public FuzzyPixelComparator {
157 public:
158 explicit FuzzyPixelOffByOneComparator(bool discard_alpha)
159 : FuzzyPixelComparator(discard_alpha, 100.f, 0.f, 1.f, 1, 0) {}
162 template <typename RendererType>
163 class FuzzyForSoftwareOnlyPixelComparator : public PixelComparator {
164 public:
165 explicit FuzzyForSoftwareOnlyPixelComparator(bool discard_alpha)
166 : fuzzy_(discard_alpha), exact_(discard_alpha) {}
168 virtual bool Compare(const SkBitmap& actual_bmp,
169 const SkBitmap& expected_bmp) const;
171 private:
172 FuzzyPixelOffByOneComparator fuzzy_;
173 ExactPixelComparator exact_;
176 template<>
177 bool FuzzyForSoftwareOnlyPixelComparator<SoftwareRenderer>::Compare(
178 const SkBitmap& actual_bmp,
179 const SkBitmap& expected_bmp) const {
180 return fuzzy_.Compare(actual_bmp, expected_bmp);
183 template <>
184 bool FuzzyForSoftwareOnlyPixelComparator<
185 SoftwareRendererWithExpandedViewport>::Compare(
186 const SkBitmap& actual_bmp,
187 const SkBitmap& expected_bmp) const {
188 return fuzzy_.Compare(actual_bmp, expected_bmp);
191 template<typename RendererType>
192 bool FuzzyForSoftwareOnlyPixelComparator<RendererType>::Compare(
193 const SkBitmap& actual_bmp,
194 const SkBitmap& expected_bmp) const {
195 return exact_.Compare(actual_bmp, expected_bmp);
198 #if !defined(OS_ANDROID)
199 TYPED_TEST(RendererPixelTest, SimpleGreenRect) {
200 gfx::Rect rect(this->device_viewport_size_);
202 RenderPass::Id id(1, 1);
203 scoped_ptr<RenderPass> pass = CreateTestRootRenderPass(id, rect);
205 scoped_ptr<SharedQuadState> shared_state =
206 CreateTestSharedQuadState(gfx::Transform(), rect);
208 scoped_ptr<SolidColorDrawQuad> color_quad = SolidColorDrawQuad::Create();
209 color_quad->SetNew(shared_state.get(), rect, SK_ColorGREEN, false);
211 pass->quad_list.push_back(color_quad.PassAs<DrawQuad>());
213 RenderPassList pass_list;
214 pass_list.push_back(pass.Pass());
216 EXPECT_TRUE(this->RunPixelTest(
217 &pass_list,
218 base::FilePath(FILE_PATH_LITERAL("green.png")),
219 ExactPixelComparator(true)));
222 TYPED_TEST(RendererPixelTest, SimpleGreenRect_NonRootRenderPass) {
223 gfx::Rect rect(this->device_viewport_size_);
224 gfx::Rect small_rect(100, 100);
226 RenderPass::Id child_id(2, 1);
227 scoped_ptr<RenderPass> child_pass =
228 CreateTestRenderPass(child_id, small_rect, gfx::Transform());
230 scoped_ptr<SharedQuadState> child_shared_state =
231 CreateTestSharedQuadState(gfx::Transform(), small_rect);
233 scoped_ptr<SolidColorDrawQuad> color_quad = SolidColorDrawQuad::Create();
234 color_quad->SetNew(child_shared_state.get(), rect, SK_ColorGREEN, false);
235 child_pass->quad_list.push_back(color_quad.PassAs<DrawQuad>());
237 RenderPass::Id root_id(1, 1);
238 scoped_ptr<RenderPass> root_pass =
239 CreateTestRenderPass(root_id, rect, gfx::Transform());
241 scoped_ptr<SharedQuadState> root_shared_state =
242 CreateTestSharedQuadState(gfx::Transform(), rect);
244 scoped_ptr<DrawQuad> render_pass_quad =
245 CreateTestRenderPassDrawQuad(root_shared_state.get(),
246 small_rect,
247 child_id);
248 root_pass->quad_list.push_back(render_pass_quad.PassAs<DrawQuad>());
250 RenderPass* child_pass_ptr = child_pass.get();
252 RenderPassList pass_list;
253 pass_list.push_back(child_pass.Pass());
254 pass_list.push_back(root_pass.Pass());
256 EXPECT_TRUE(this->RunPixelTestWithReadbackTarget(
257 &pass_list,
258 child_pass_ptr,
259 base::FilePath(FILE_PATH_LITERAL("green_small.png")),
260 ExactPixelComparator(true)));
263 TYPED_TEST(RendererPixelTest, PremultipliedTextureWithoutBackground) {
264 gfx::Rect rect(this->device_viewport_size_);
266 RenderPass::Id id(1, 1);
267 scoped_ptr<RenderPass> pass = CreateTestRootRenderPass(id, rect);
269 scoped_ptr<SharedQuadState> shared_state =
270 CreateTestSharedQuadState(gfx::Transform(), rect);
272 scoped_ptr<TextureDrawQuad> texture_quad = CreateTestTextureDrawQuad(
273 gfx::Rect(this->device_viewport_size_),
274 SkColorSetARGB(128, 0, 255, 0), // Texel color.
275 SK_ColorTRANSPARENT, // Background color.
276 true, // Premultiplied alpha.
277 shared_state.get(),
278 this->resource_provider_.get());
279 pass->quad_list.push_back(texture_quad.PassAs<DrawQuad>());
281 scoped_ptr<SolidColorDrawQuad> color_quad = SolidColorDrawQuad::Create();
282 color_quad->SetNew(shared_state.get(), rect, SK_ColorWHITE, false);
283 pass->quad_list.push_back(color_quad.PassAs<DrawQuad>());
285 RenderPassList pass_list;
286 pass_list.push_back(pass.Pass());
288 EXPECT_TRUE(this->RunPixelTest(
289 &pass_list,
290 base::FilePath(FILE_PATH_LITERAL("green_alpha.png")),
291 FuzzyPixelOffByOneComparator(true)));
294 TYPED_TEST(RendererPixelTest, PremultipliedTextureWithBackground) {
295 gfx::Rect rect(this->device_viewport_size_);
297 RenderPass::Id id(1, 1);
298 scoped_ptr<RenderPass> pass = CreateTestRootRenderPass(id, rect);
300 scoped_ptr<SharedQuadState> texture_quad_state =
301 CreateTestSharedQuadState(gfx::Transform(), rect);
302 texture_quad_state->opacity = 0.8f;
304 scoped_ptr<TextureDrawQuad> texture_quad = CreateTestTextureDrawQuad(
305 gfx::Rect(this->device_viewport_size_),
306 SkColorSetARGB(204, 120, 255, 120), // Texel color.
307 SK_ColorGREEN, // Background color.
308 true, // Premultiplied alpha.
309 texture_quad_state.get(),
310 this->resource_provider_.get());
311 pass->quad_list.push_back(texture_quad.PassAs<DrawQuad>());
313 scoped_ptr<SharedQuadState> color_quad_state =
314 CreateTestSharedQuadState(gfx::Transform(), rect);
315 scoped_ptr<SolidColorDrawQuad> color_quad = SolidColorDrawQuad::Create();
316 color_quad->SetNew(color_quad_state.get(), rect, SK_ColorWHITE, false);
317 pass->quad_list.push_back(color_quad.PassAs<DrawQuad>());
319 RenderPassList pass_list;
320 pass_list.push_back(pass.Pass());
322 EXPECT_TRUE(this->RunPixelTest(
323 &pass_list,
324 base::FilePath(FILE_PATH_LITERAL("green_alpha.png")),
325 FuzzyPixelOffByOneComparator(true)));
328 // TODO(skaslev): The software renderer does not support non-premultplied alpha.
329 TEST_F(GLRendererPixelTest, NonPremultipliedTextureWithoutBackground) {
330 gfx::Rect rect(this->device_viewport_size_);
332 RenderPass::Id id(1, 1);
333 scoped_ptr<RenderPass> pass = CreateTestRootRenderPass(id, rect);
335 scoped_ptr<SharedQuadState> shared_state =
336 CreateTestSharedQuadState(gfx::Transform(), rect);
338 scoped_ptr<TextureDrawQuad> texture_quad = CreateTestTextureDrawQuad(
339 gfx::Rect(this->device_viewport_size_),
340 SkColorSetARGB(128, 0, 255, 0), // Texel color.
341 SK_ColorTRANSPARENT, // Background color.
342 false, // Premultiplied alpha.
343 shared_state.get(),
344 this->resource_provider_.get());
345 pass->quad_list.push_back(texture_quad.PassAs<DrawQuad>());
347 scoped_ptr<SolidColorDrawQuad> color_quad = SolidColorDrawQuad::Create();
348 color_quad->SetNew(shared_state.get(), rect, SK_ColorWHITE, false);
349 pass->quad_list.push_back(color_quad.PassAs<DrawQuad>());
351 RenderPassList pass_list;
352 pass_list.push_back(pass.Pass());
354 EXPECT_TRUE(this->RunPixelTest(
355 &pass_list,
356 base::FilePath(FILE_PATH_LITERAL("green_alpha.png")),
357 FuzzyPixelOffByOneComparator(true)));
360 // TODO(skaslev): The software renderer does not support non-premultplied alpha.
361 TEST_F(GLRendererPixelTest, NonPremultipliedTextureWithBackground) {
362 gfx::Rect rect(this->device_viewport_size_);
364 RenderPass::Id id(1, 1);
365 scoped_ptr<RenderPass> pass = CreateTestRootRenderPass(id, rect);
367 scoped_ptr<SharedQuadState> texture_quad_state =
368 CreateTestSharedQuadState(gfx::Transform(), rect);
369 texture_quad_state->opacity = 0.8f;
371 scoped_ptr<TextureDrawQuad> texture_quad = CreateTestTextureDrawQuad(
372 gfx::Rect(this->device_viewport_size_),
373 SkColorSetARGB(204, 120, 255, 120), // Texel color.
374 SK_ColorGREEN, // Background color.
375 false, // Premultiplied alpha.
376 texture_quad_state.get(),
377 this->resource_provider_.get());
378 pass->quad_list.push_back(texture_quad.PassAs<DrawQuad>());
380 scoped_ptr<SharedQuadState> color_quad_state =
381 CreateTestSharedQuadState(gfx::Transform(), rect);
382 scoped_ptr<SolidColorDrawQuad> color_quad = SolidColorDrawQuad::Create();
383 color_quad->SetNew(color_quad_state.get(), rect, SK_ColorWHITE, false);
384 pass->quad_list.push_back(color_quad.PassAs<DrawQuad>());
386 RenderPassList pass_list;
387 pass_list.push_back(pass.Pass());
389 EXPECT_TRUE(this->RunPixelTest(
390 &pass_list,
391 base::FilePath(FILE_PATH_LITERAL("green_alpha.png")),
392 FuzzyPixelOffByOneComparator(true)));
395 class VideoGLRendererPixelTest : public GLRendererPixelTest {
396 protected:
397 scoped_ptr<YUVVideoDrawQuad> CreateTestYUVVideoDrawQuad(
398 SharedQuadState* shared_state, bool with_alpha, bool is_transparent) {
399 gfx::Rect rect(this->device_viewport_size_);
400 gfx::Rect opaque_rect(0, 0, 0, 0);
402 ResourceProvider::ResourceId y_resource =
403 resource_provider_->CreateResource(
404 this->device_viewport_size_,
405 GL_LUMINANCE,
406 ResourceProvider::TextureUsageAny);
407 ResourceProvider::ResourceId u_resource =
408 resource_provider_->CreateResource(
409 this->device_viewport_size_,
410 GL_LUMINANCE,
411 ResourceProvider::TextureUsageAny);
412 ResourceProvider::ResourceId v_resource =
413 resource_provider_->CreateResource(
414 this->device_viewport_size_,
415 GL_LUMINANCE,
416 ResourceProvider::TextureUsageAny);
417 ResourceProvider::ResourceId a_resource = 0;
418 if (with_alpha) {
419 a_resource = resource_provider_->CreateResource(
420 this->device_viewport_size_,
421 GL_LUMINANCE,
422 ResourceProvider::TextureUsageAny);
425 int w = this->device_viewport_size_.width();
426 int h = this->device_viewport_size_.height();
427 const int y_plane_size = w * h;
428 gfx::Rect uv_rect((w + 1) / 2, (h + 1) / 2);
429 const int uv_plane_size = uv_rect.size().GetArea();
430 scoped_ptr<uint8_t[]> y_plane(new uint8_t[y_plane_size]);
431 scoped_ptr<uint8_t[]> u_plane(new uint8_t[uv_plane_size]);
432 scoped_ptr<uint8_t[]> v_plane(new uint8_t[uv_plane_size]);
433 scoped_ptr<uint8_t[]> a_plane;
434 if (with_alpha)
435 a_plane.reset(new uint8_t[y_plane_size]);
436 // YUV values representing Green.
437 memset(y_plane.get(), 149, y_plane_size);
438 memset(u_plane.get(), 43, uv_plane_size);
439 memset(v_plane.get(), 21, uv_plane_size);
440 if (with_alpha)
441 memset(a_plane.get(), is_transparent ? 0 : 128, y_plane_size);
443 resource_provider_->SetPixels(y_resource, y_plane.get(), rect, rect,
444 gfx::Vector2d());
445 resource_provider_->SetPixels(u_resource, u_plane.get(), uv_rect, uv_rect,
446 gfx::Vector2d());
447 resource_provider_->SetPixels(v_resource, v_plane.get(), uv_rect, uv_rect,
448 gfx::Vector2d());
449 if (with_alpha) {
450 resource_provider_->SetPixels(a_resource, a_plane.get(), rect, rect,
451 gfx::Vector2d());
454 scoped_ptr<YUVVideoDrawQuad> yuv_quad = cc::YUVVideoDrawQuad::Create();
455 yuv_quad->SetNew(shared_state, rect, opaque_rect, gfx::Size(),
456 y_resource, u_resource, v_resource, a_resource);
457 return yuv_quad.Pass();
461 TEST_F(VideoGLRendererPixelTest, SimpleYUVRect) {
462 gfx::Rect rect(this->device_viewport_size_);
464 RenderPass::Id id(1, 1);
465 scoped_ptr<RenderPass> pass = CreateTestRootRenderPass(id, rect);
467 scoped_ptr<SharedQuadState> shared_state =
468 CreateTestSharedQuadState(gfx::Transform(), rect);
470 scoped_ptr<YUVVideoDrawQuad> yuv_quad =
471 CreateTestYUVVideoDrawQuad(shared_state.get(), false, false);
473 pass->quad_list.push_back(yuv_quad.PassAs<DrawQuad>());
475 RenderPassList pass_list;
476 pass_list.push_back(pass.Pass());
478 EXPECT_TRUE(this->RunPixelTest(
479 &pass_list,
480 base::FilePath(FILE_PATH_LITERAL("green.png")),
481 ExactPixelComparator(true)));
484 TEST_F(VideoGLRendererPixelTest, SimpleYUVARect) {
485 gfx::Rect rect(this->device_viewport_size_);
487 RenderPass::Id id(1, 1);
488 scoped_ptr<RenderPass> pass = CreateTestRootRenderPass(id, rect);
490 scoped_ptr<SharedQuadState> shared_state =
491 CreateTestSharedQuadState(gfx::Transform(), rect);
493 scoped_ptr<YUVVideoDrawQuad> yuv_quad =
494 CreateTestYUVVideoDrawQuad(shared_state.get(), true, false);
496 pass->quad_list.push_back(yuv_quad.PassAs<DrawQuad>());
498 scoped_ptr<SolidColorDrawQuad> color_quad = SolidColorDrawQuad::Create();
499 color_quad->SetNew(shared_state.get(), rect, SK_ColorWHITE, false);
501 pass->quad_list.push_back(color_quad.PassAs<DrawQuad>());
503 RenderPassList pass_list;
504 pass_list.push_back(pass.Pass());
506 EXPECT_TRUE(this->RunPixelTest(
507 &pass_list,
508 base::FilePath(FILE_PATH_LITERAL("green_alpha.png")),
509 ExactPixelComparator(true)));
512 TEST_F(VideoGLRendererPixelTest, FullyTransparentYUVARect) {
513 gfx::Rect rect(this->device_viewport_size_);
515 RenderPass::Id id(1, 1);
516 scoped_ptr<RenderPass> pass = CreateTestRootRenderPass(id, rect);
518 scoped_ptr<SharedQuadState> shared_state =
519 CreateTestSharedQuadState(gfx::Transform(), rect);
521 scoped_ptr<YUVVideoDrawQuad> yuv_quad =
522 CreateTestYUVVideoDrawQuad(shared_state.get(), true, true);
524 pass->quad_list.push_back(yuv_quad.PassAs<DrawQuad>());
526 scoped_ptr<SolidColorDrawQuad> color_quad = SolidColorDrawQuad::Create();
527 color_quad->SetNew(shared_state.get(), rect, SK_ColorBLACK, false);
529 pass->quad_list.push_back(color_quad.PassAs<DrawQuad>());
531 RenderPassList pass_list;
532 pass_list.push_back(pass.Pass());
534 EXPECT_TRUE(this->RunPixelTest(
535 &pass_list,
536 base::FilePath(FILE_PATH_LITERAL("black.png")),
537 ExactPixelComparator(true)));
540 TYPED_TEST(RendererPixelTest, FastPassColorFilterAlpha) {
541 gfx::Rect viewport_rect(this->device_viewport_size_);
543 RenderPass::Id root_pass_id(1, 1);
544 scoped_ptr<RenderPass> root_pass =
545 CreateTestRootRenderPass(root_pass_id, viewport_rect);
547 RenderPass::Id child_pass_id(2, 2);
548 gfx::Rect pass_rect(this->device_viewport_size_);
549 gfx::Transform transform_to_root;
550 scoped_ptr<RenderPass> child_pass =
551 CreateTestRenderPass(child_pass_id, pass_rect, transform_to_root);
553 gfx::Transform content_to_target_transform;
554 scoped_ptr<SharedQuadState> shared_state =
555 CreateTestSharedQuadState(content_to_target_transform, viewport_rect);
556 shared_state->opacity = 0.5f;
558 scoped_ptr<SolidColorDrawQuad> blue = SolidColorDrawQuad::Create();
559 blue->SetNew(shared_state.get(),
560 gfx::Rect(0,
562 this->device_viewport_size_.width(),
563 this->device_viewport_size_.height() / 2),
564 SK_ColorBLUE,
565 false);
566 scoped_ptr<SolidColorDrawQuad> yellow = SolidColorDrawQuad::Create();
567 yellow->SetNew(shared_state.get(),
568 gfx::Rect(0,
569 this->device_viewport_size_.height() / 2,
570 this->device_viewport_size_.width(),
571 this->device_viewport_size_.height() / 2),
572 SK_ColorYELLOW,
573 false);
575 scoped_ptr<SharedQuadState> blank_state =
576 CreateTestSharedQuadState(content_to_target_transform, viewport_rect);
578 scoped_ptr<SolidColorDrawQuad> white = SolidColorDrawQuad::Create();
579 white->SetNew(blank_state.get(),
580 viewport_rect,
581 SK_ColorWHITE,
582 false);
584 child_pass->quad_list.push_back(blue.PassAs<DrawQuad>());
585 child_pass->quad_list.push_back(yellow.PassAs<DrawQuad>());
586 child_pass->quad_list.push_back(white.PassAs<DrawQuad>());
588 scoped_ptr<SharedQuadState> pass_shared_state =
589 CreateTestSharedQuadState(gfx::Transform(), pass_rect);
591 SkScalar matrix[20];
592 float amount = 0.5f;
593 matrix[0] = 0.213f + 0.787f * amount;
594 matrix[1] = 0.715f - 0.715f * amount;
595 matrix[2] = 1.f - (matrix[0] + matrix[1]);
596 matrix[3] = matrix[4] = 0;
597 matrix[5] = 0.213f - 0.213f * amount;
598 matrix[6] = 0.715f + 0.285f * amount;
599 matrix[7] = 1.f - (matrix[5] + matrix[6]);
600 matrix[8] = matrix[9] = 0;
601 matrix[10] = 0.213f - 0.213f * amount;
602 matrix[11] = 0.715f - 0.715f * amount;
603 matrix[12] = 1.f - (matrix[10] + matrix[11]);
604 matrix[13] = matrix[14] = 0;
605 matrix[15] = matrix[16] = matrix[17] = matrix[19] = 0;
606 matrix[18] = 1;
607 skia::RefPtr<SkColorFilter> colorFilter(skia::AdoptRef(
608 new SkColorMatrixFilter(matrix)));
609 skia::RefPtr<SkImageFilter> filter =
610 skia::AdoptRef(SkColorFilterImageFilter::Create(colorFilter.get(), NULL));
612 scoped_ptr<RenderPassDrawQuad> render_pass_quad =
613 RenderPassDrawQuad::Create();
614 render_pass_quad->SetNew(pass_shared_state.get(),
615 pass_rect,
616 child_pass_id,
617 false,
619 pass_rect,
620 gfx::RectF(),
621 FilterOperations(),
622 filter,
623 FilterOperations());
625 root_pass->quad_list.push_back(render_pass_quad.PassAs<DrawQuad>());
627 RenderPassList pass_list;
628 pass_list.push_back(child_pass.Pass());
629 pass_list.push_back(root_pass.Pass());
631 // This test has alpha=254 for the software renderer vs. alpha=255 for the gl
632 // renderer so use a fuzzy comparator.
633 EXPECT_TRUE(this->RunPixelTest(
634 &pass_list,
635 base::FilePath(FILE_PATH_LITERAL("blue_yellow_alpha.png")),
636 FuzzyForSoftwareOnlyPixelComparator<TypeParam>(false)));
639 TYPED_TEST(RendererPixelTest, FastPassColorFilterAlphaTranslation) {
640 gfx::Rect viewport_rect(this->device_viewport_size_);
642 RenderPass::Id root_pass_id(1, 1);
643 scoped_ptr<RenderPass> root_pass =
644 CreateTestRootRenderPass(root_pass_id, viewport_rect);
646 RenderPass::Id child_pass_id(2, 2);
647 gfx::Rect pass_rect(this->device_viewport_size_);
648 gfx::Transform transform_to_root;
649 scoped_ptr<RenderPass> child_pass =
650 CreateTestRenderPass(child_pass_id, pass_rect, transform_to_root);
652 gfx::Transform content_to_target_transform;
653 scoped_ptr<SharedQuadState> shared_state =
654 CreateTestSharedQuadState(content_to_target_transform, viewport_rect);
655 shared_state->opacity = 0.5f;
657 scoped_ptr<SolidColorDrawQuad> blue = SolidColorDrawQuad::Create();
658 blue->SetNew(shared_state.get(),
659 gfx::Rect(0,
661 this->device_viewport_size_.width(),
662 this->device_viewport_size_.height() / 2),
663 SK_ColorBLUE,
664 false);
665 scoped_ptr<SolidColorDrawQuad> yellow = SolidColorDrawQuad::Create();
666 yellow->SetNew(shared_state.get(),
667 gfx::Rect(0,
668 this->device_viewport_size_.height() / 2,
669 this->device_viewport_size_.width(),
670 this->device_viewport_size_.height() / 2),
671 SK_ColorYELLOW,
672 false);
674 scoped_ptr<SharedQuadState> blank_state =
675 CreateTestSharedQuadState(content_to_target_transform, viewport_rect);
677 scoped_ptr<SolidColorDrawQuad> white = SolidColorDrawQuad::Create();
678 white->SetNew(blank_state.get(),
679 viewport_rect,
680 SK_ColorWHITE,
681 false);
683 child_pass->quad_list.push_back(blue.PassAs<DrawQuad>());
684 child_pass->quad_list.push_back(yellow.PassAs<DrawQuad>());
685 child_pass->quad_list.push_back(white.PassAs<DrawQuad>());
687 scoped_ptr<SharedQuadState> pass_shared_state =
688 CreateTestSharedQuadState(gfx::Transform(), pass_rect);
690 SkScalar matrix[20];
691 float amount = 0.5f;
692 matrix[0] = 0.213f + 0.787f * amount;
693 matrix[1] = 0.715f - 0.715f * amount;
694 matrix[2] = 1.f - (matrix[0] + matrix[1]);
695 matrix[3] = 0;
696 matrix[4] = 20.f;
697 matrix[5] = 0.213f - 0.213f * amount;
698 matrix[6] = 0.715f + 0.285f * amount;
699 matrix[7] = 1.f - (matrix[5] + matrix[6]);
700 matrix[8] = 0;
701 matrix[9] = 200.f;
702 matrix[10] = 0.213f - 0.213f * amount;
703 matrix[11] = 0.715f - 0.715f * amount;
704 matrix[12] = 1.f - (matrix[10] + matrix[11]);
705 matrix[13] = 0;
706 matrix[14] = 1.5f;
707 matrix[15] = matrix[16] = matrix[17] = matrix[19] = 0;
708 matrix[18] = 1;
709 skia::RefPtr<SkColorFilter> colorFilter(skia::AdoptRef(
710 new SkColorMatrixFilter(matrix)));
711 skia::RefPtr<SkImageFilter> filter =
712 skia::AdoptRef(SkColorFilterImageFilter::Create(colorFilter.get(), NULL));
714 scoped_ptr<RenderPassDrawQuad> render_pass_quad =
715 RenderPassDrawQuad::Create();
716 render_pass_quad->SetNew(pass_shared_state.get(),
717 pass_rect,
718 child_pass_id,
719 false,
721 pass_rect,
722 gfx::RectF(),
723 FilterOperations(),
724 filter,
725 FilterOperations());
727 root_pass->quad_list.push_back(render_pass_quad.PassAs<DrawQuad>());
728 RenderPassList pass_list;
730 pass_list.push_back(child_pass.Pass());
731 pass_list.push_back(root_pass.Pass());
733 // This test has alpha=254 for the software renderer vs. alpha=255 for the gl
734 // renderer so use a fuzzy comparator.
735 EXPECT_TRUE(this->RunPixelTest(
736 &pass_list,
737 base::FilePath(FILE_PATH_LITERAL("blue_yellow_alpha_translate.png")),
738 FuzzyForSoftwareOnlyPixelComparator<TypeParam>(false)));
741 TYPED_TEST(RendererPixelTest, EnlargedRenderPassTexture) {
742 gfx::Rect viewport_rect(this->device_viewport_size_);
744 RenderPass::Id root_pass_id(1, 1);
745 scoped_ptr<RenderPass> root_pass =
746 CreateTestRootRenderPass(root_pass_id, viewport_rect);
748 RenderPass::Id child_pass_id(2, 2);
749 gfx::Rect pass_rect(this->device_viewport_size_);
750 gfx::Transform transform_to_root;
751 scoped_ptr<RenderPass> child_pass =
752 CreateTestRenderPass(child_pass_id, pass_rect, transform_to_root);
754 gfx::Transform content_to_target_transform;
755 scoped_ptr<SharedQuadState> shared_state =
756 CreateTestSharedQuadState(content_to_target_transform, viewport_rect);
758 scoped_ptr<SolidColorDrawQuad> blue = SolidColorDrawQuad::Create();
759 blue->SetNew(shared_state.get(),
760 gfx::Rect(0,
762 this->device_viewport_size_.width(),
763 this->device_viewport_size_.height() / 2),
764 SK_ColorBLUE,
765 false);
766 scoped_ptr<SolidColorDrawQuad> yellow = SolidColorDrawQuad::Create();
767 yellow->SetNew(shared_state.get(),
768 gfx::Rect(0,
769 this->device_viewport_size_.height() / 2,
770 this->device_viewport_size_.width(),
771 this->device_viewport_size_.height() / 2),
772 SK_ColorYELLOW,
773 false);
775 child_pass->quad_list.push_back(blue.PassAs<DrawQuad>());
776 child_pass->quad_list.push_back(yellow.PassAs<DrawQuad>());
778 scoped_ptr<SharedQuadState> pass_shared_state =
779 CreateTestSharedQuadState(gfx::Transform(), pass_rect);
780 root_pass->quad_list.push_back(
781 CreateTestRenderPassDrawQuad(pass_shared_state.get(),
782 pass_rect,
783 child_pass_id));
785 RenderPassList pass_list;
786 pass_list.push_back(child_pass.Pass());
787 pass_list.push_back(root_pass.Pass());
789 this->renderer_->SetEnlargePassTextureAmountForTesting(gfx::Vector2d(50, 75));
791 EXPECT_TRUE(this->RunPixelTest(
792 &pass_list,
793 base::FilePath(FILE_PATH_LITERAL("blue_yellow.png")),
794 ExactPixelComparator(true)));
797 TYPED_TEST(RendererPixelTest, EnlargedRenderPassTextureWithAntiAliasing) {
798 gfx::Rect viewport_rect(this->device_viewport_size_);
800 RenderPass::Id root_pass_id(1, 1);
801 scoped_ptr<RenderPass> root_pass =
802 CreateTestRootRenderPass(root_pass_id, viewport_rect);
804 RenderPass::Id child_pass_id(2, 2);
805 gfx::Rect pass_rect(this->device_viewport_size_);
806 gfx::Transform transform_to_root;
807 scoped_ptr<RenderPass> child_pass =
808 CreateTestRenderPass(child_pass_id, pass_rect, transform_to_root);
810 gfx::Transform content_to_target_transform;
811 scoped_ptr<SharedQuadState> shared_state =
812 CreateTestSharedQuadState(content_to_target_transform, viewport_rect);
814 scoped_ptr<SolidColorDrawQuad> blue = SolidColorDrawQuad::Create();
815 blue->SetNew(shared_state.get(),
816 gfx::Rect(0,
818 this->device_viewport_size_.width(),
819 this->device_viewport_size_.height() / 2),
820 SK_ColorBLUE,
821 false);
822 scoped_ptr<SolidColorDrawQuad> yellow = SolidColorDrawQuad::Create();
823 yellow->SetNew(shared_state.get(),
824 gfx::Rect(0,
825 this->device_viewport_size_.height() / 2,
826 this->device_viewport_size_.width(),
827 this->device_viewport_size_.height() / 2),
828 SK_ColorYELLOW,
829 false);
831 child_pass->quad_list.push_back(blue.PassAs<DrawQuad>());
832 child_pass->quad_list.push_back(yellow.PassAs<DrawQuad>());
834 gfx::Transform aa_transform;
835 aa_transform.Translate(0.5, 0.0);
837 scoped_ptr<SharedQuadState> pass_shared_state =
838 CreateTestSharedQuadState(aa_transform, pass_rect);
839 root_pass->quad_list.push_back(
840 CreateTestRenderPassDrawQuad(pass_shared_state.get(),
841 pass_rect,
842 child_pass_id));
844 scoped_ptr<SharedQuadState> root_shared_state =
845 CreateTestSharedQuadState(gfx::Transform(), viewport_rect);
846 scoped_ptr<SolidColorDrawQuad> background = SolidColorDrawQuad::Create();
847 background->SetNew(root_shared_state.get(),
848 gfx::Rect(this->device_viewport_size_),
849 SK_ColorWHITE,
850 false);
851 root_pass->quad_list.push_back(background.PassAs<DrawQuad>());
853 RenderPassList pass_list;
854 pass_list.push_back(child_pass.Pass());
855 pass_list.push_back(root_pass.Pass());
857 this->renderer_->SetEnlargePassTextureAmountForTesting(gfx::Vector2d(50, 75));
859 EXPECT_TRUE(this->RunPixelTest(
860 &pass_list,
861 base::FilePath(FILE_PATH_LITERAL("blue_yellow_anti_aliasing.png")),
862 FuzzyPixelOffByOneComparator(true)));
865 template <typename RendererType>
866 class RendererPixelTestWithBackgroundFilter
867 : public RendererPixelTest<RendererType> {
868 protected:
869 void SetUpRenderPassList() {
870 gfx::Rect device_viewport_rect(this->device_viewport_size_);
872 RenderPass::Id root_id(1, 1);
873 scoped_ptr<RenderPass> root_pass =
874 CreateTestRootRenderPass(root_id, device_viewport_rect);
875 root_pass->has_transparent_background = false;
877 gfx::Transform identity_content_to_target_transform;
879 RenderPass::Id filter_pass_id(2, 1);
880 gfx::Transform transform_to_root;
881 scoped_ptr<RenderPass> filter_pass =
882 CreateTestRenderPass(filter_pass_id,
883 filter_pass_content_rect_,
884 transform_to_root);
886 // A non-visible quad in the filtering render pass.
888 scoped_ptr<SharedQuadState> shared_state =
889 CreateTestSharedQuadState(identity_content_to_target_transform,
890 filter_pass_content_rect_);
891 scoped_ptr<SolidColorDrawQuad> color_quad = SolidColorDrawQuad::Create();
892 color_quad->SetNew(shared_state.get(),
893 filter_pass_content_rect_,
894 SK_ColorTRANSPARENT,
895 false);
896 filter_pass->quad_list.push_back(color_quad.PassAs<DrawQuad>());
897 filter_pass->shared_quad_state_list.push_back(shared_state.Pass());
901 scoped_ptr<SharedQuadState> shared_state =
902 CreateTestSharedQuadState(filter_pass_to_target_transform_,
903 filter_pass_content_rect_);
904 scoped_ptr<RenderPassDrawQuad> filter_pass_quad =
905 RenderPassDrawQuad::Create();
906 filter_pass_quad->SetNew(
907 shared_state.get(),
908 filter_pass_content_rect_,
909 filter_pass_id,
910 false, // is_replica
911 0, // mask_resource_id
912 filter_pass_content_rect_, // contents_changed_since_last_frame
913 gfx::RectF(), // mask_uv_rect
914 FilterOperations(), // filters
915 skia::RefPtr<SkImageFilter>(), // filter
916 this->background_filters_);
917 root_pass->quad_list.push_back(filter_pass_quad.PassAs<DrawQuad>());
918 root_pass->shared_quad_state_list.push_back(shared_state.Pass());
921 const int kColumnWidth = device_viewport_rect.width() / 3;
923 gfx::Rect left_rect = gfx::Rect(0, 0, kColumnWidth, 20);
924 for (int i = 0; left_rect.y() < device_viewport_rect.height(); ++i) {
925 scoped_ptr<SharedQuadState> shared_state =
926 CreateTestSharedQuadState(identity_content_to_target_transform,
927 left_rect);
928 scoped_ptr<SolidColorDrawQuad> color_quad = SolidColorDrawQuad::Create();
929 color_quad->SetNew(shared_state.get(), left_rect, SK_ColorGREEN, false);
930 root_pass->quad_list.push_back(color_quad.PassAs<DrawQuad>());
931 root_pass->shared_quad_state_list.push_back(shared_state.Pass());
932 left_rect += gfx::Vector2d(0, left_rect.height() + 1);
935 gfx::Rect middle_rect = gfx::Rect(kColumnWidth+1, 0, kColumnWidth, 20);
936 for (int i = 0; middle_rect.y() < device_viewport_rect.height(); ++i) {
937 scoped_ptr<SharedQuadState> shared_state =
938 CreateTestSharedQuadState(identity_content_to_target_transform,
939 middle_rect);
940 scoped_ptr<SolidColorDrawQuad> color_quad = SolidColorDrawQuad::Create();
941 color_quad->SetNew(shared_state.get(), middle_rect, SK_ColorRED, false);
942 root_pass->quad_list.push_back(color_quad.PassAs<DrawQuad>());
943 root_pass->shared_quad_state_list.push_back(shared_state.Pass());
944 middle_rect += gfx::Vector2d(0, middle_rect.height() + 1);
947 gfx::Rect right_rect = gfx::Rect((kColumnWidth+1)*2, 0, kColumnWidth, 20);
948 for (int i = 0; right_rect.y() < device_viewport_rect.height(); ++i) {
949 scoped_ptr<SharedQuadState> shared_state =
950 CreateTestSharedQuadState(identity_content_to_target_transform,
951 right_rect);
952 scoped_ptr<SolidColorDrawQuad> color_quad = SolidColorDrawQuad::Create();
953 color_quad->SetNew(shared_state.get(), right_rect, SK_ColorBLUE, false);
954 root_pass->quad_list.push_back(color_quad.PassAs<DrawQuad>());
955 root_pass->shared_quad_state_list.push_back(shared_state.Pass());
956 right_rect += gfx::Vector2d(0, right_rect.height() + 1);
959 scoped_ptr<SharedQuadState> shared_state =
960 CreateTestSharedQuadState(identity_content_to_target_transform,
961 device_viewport_rect);
962 scoped_ptr<SolidColorDrawQuad> background_quad =
963 SolidColorDrawQuad::Create();
964 background_quad->SetNew(shared_state.get(),
965 device_viewport_rect,
966 SK_ColorWHITE,
967 false);
968 root_pass->quad_list.push_back(background_quad.PassAs<DrawQuad>());
969 root_pass->shared_quad_state_list.push_back(shared_state.Pass());
971 pass_list_.push_back(filter_pass.Pass());
972 pass_list_.push_back(root_pass.Pass());
975 RenderPassList pass_list_;
976 FilterOperations background_filters_;
977 gfx::Transform filter_pass_to_target_transform_;
978 gfx::Rect filter_pass_content_rect_;
981 typedef ::testing::Types<GLRenderer, SoftwareRenderer>
982 BackgroundFilterRendererTypes;
983 TYPED_TEST_CASE(RendererPixelTestWithBackgroundFilter,
984 BackgroundFilterRendererTypes);
986 typedef RendererPixelTestWithBackgroundFilter<GLRenderer>
987 GLRendererPixelTestWithBackgroundFilter;
989 // TODO(skaslev): The software renderer does not support filters yet.
990 TEST_F(GLRendererPixelTestWithBackgroundFilter, InvertFilter) {
991 this->background_filters_.Append(
992 FilterOperation::CreateInvertFilter(1.f));
994 this->filter_pass_content_rect_ = gfx::Rect(this->device_viewport_size_);
995 this->filter_pass_content_rect_.Inset(12, 14, 16, 18);
997 this->SetUpRenderPassList();
998 EXPECT_TRUE(this->RunPixelTest(
999 &this->pass_list_,
1000 base::FilePath(FILE_PATH_LITERAL("background_filter.png")),
1001 ExactPixelComparator(true)));
1004 class ExternalStencilPixelTest : public GLRendererPixelTest {
1005 protected:
1006 void ClearBackgroundToGreen() {
1007 WebKit::WebGraphicsContext3D* context3d =
1008 output_surface_->context_provider()->Context3d();
1009 output_surface_->EnsureBackbuffer();
1010 output_surface_->Reshape(device_viewport_size_, 1);
1011 context3d->clearColor(0.f, 1.f, 0.f, 1.f);
1012 context3d->clear(GL_COLOR_BUFFER_BIT);
1015 void PopulateStencilBuffer() {
1016 // Set two quadrants of the stencil buffer to 1.
1017 WebKit::WebGraphicsContext3D* context3d =
1018 output_surface_->context_provider()->Context3d();
1019 ASSERT_TRUE(context3d->getContextAttributes().stencil);
1020 output_surface_->EnsureBackbuffer();
1021 output_surface_->Reshape(device_viewport_size_, 1);
1022 context3d->clearStencil(0);
1023 context3d->clear(GL_STENCIL_BUFFER_BIT);
1024 context3d->enable(GL_SCISSOR_TEST);
1025 context3d->clearStencil(1);
1026 context3d->scissor(0,
1028 device_viewport_size_.width() / 2,
1029 device_viewport_size_.height() / 2);
1030 context3d->clear(GL_STENCIL_BUFFER_BIT);
1031 context3d->scissor(device_viewport_size_.width() / 2,
1032 device_viewport_size_.height() / 2,
1033 device_viewport_size_.width(),
1034 device_viewport_size_.height());
1035 context3d->clear(GL_STENCIL_BUFFER_BIT);
1039 TEST_F(ExternalStencilPixelTest, StencilTestEnabled) {
1040 ClearBackgroundToGreen();
1041 PopulateStencilBuffer();
1042 this->EnableExternalStencilTest();
1044 // Draw a blue quad that covers the entire device viewport. It should be
1045 // clipped to the bottom left and top right corners by the external stencil.
1046 gfx::Rect rect(this->device_viewport_size_);
1047 RenderPass::Id id(1, 1);
1048 scoped_ptr<RenderPass> pass = CreateTestRootRenderPass(id, rect);
1049 scoped_ptr<SharedQuadState> blue_shared_state =
1050 CreateTestSharedQuadState(gfx::Transform(), rect);
1051 scoped_ptr<SolidColorDrawQuad> blue = SolidColorDrawQuad::Create();
1052 blue->SetNew(blue_shared_state.get(), rect, SK_ColorBLUE, false);
1053 pass->quad_list.push_back(blue.PassAs<DrawQuad>());
1054 pass->has_transparent_background = false;
1055 RenderPassList pass_list;
1056 pass_list.push_back(pass.Pass());
1058 EXPECT_TRUE(this->RunPixelTest(
1059 &pass_list,
1060 base::FilePath(FILE_PATH_LITERAL("four_blue_green_checkers.png")),
1061 ExactPixelComparator(true)));
1064 TEST_F(ExternalStencilPixelTest, StencilTestDisabled) {
1065 PopulateStencilBuffer();
1067 // Draw a green quad that covers the entire device viewport. The stencil
1068 // buffer should be ignored.
1069 gfx::Rect rect(this->device_viewport_size_);
1070 RenderPass::Id id(1, 1);
1071 scoped_ptr<RenderPass> pass = CreateTestRootRenderPass(id, rect);
1072 scoped_ptr<SharedQuadState> green_shared_state =
1073 CreateTestSharedQuadState(gfx::Transform(), rect);
1074 scoped_ptr<SolidColorDrawQuad> green = SolidColorDrawQuad::Create();
1075 green->SetNew(green_shared_state.get(), rect, SK_ColorGREEN, false);
1076 pass->quad_list.push_back(green.PassAs<DrawQuad>());
1077 RenderPassList pass_list;
1078 pass_list.push_back(pass.Pass());
1080 EXPECT_TRUE(this->RunPixelTest(
1081 &pass_list,
1082 base::FilePath(FILE_PATH_LITERAL("green.png")),
1083 ExactPixelComparator(true)));
1086 TEST_F(ExternalStencilPixelTest, RenderSurfacesIgnoreStencil) {
1087 // The stencil test should apply only to the final render pass.
1088 ClearBackgroundToGreen();
1089 PopulateStencilBuffer();
1090 this->EnableExternalStencilTest();
1092 gfx::Rect viewport_rect(this->device_viewport_size_);
1094 RenderPass::Id root_pass_id(1, 1);
1095 scoped_ptr<RenderPass> root_pass =
1096 CreateTestRootRenderPass(root_pass_id, viewport_rect);
1097 root_pass->has_transparent_background = false;
1099 RenderPass::Id child_pass_id(2, 2);
1100 gfx::Rect pass_rect(this->device_viewport_size_);
1101 gfx::Transform transform_to_root;
1102 scoped_ptr<RenderPass> child_pass =
1103 CreateTestRenderPass(child_pass_id, pass_rect, transform_to_root);
1105 gfx::Transform content_to_target_transform;
1106 scoped_ptr<SharedQuadState> shared_state =
1107 CreateTestSharedQuadState(content_to_target_transform, viewport_rect);
1109 scoped_ptr<SolidColorDrawQuad> blue = SolidColorDrawQuad::Create();
1110 blue->SetNew(shared_state.get(),
1111 gfx::Rect(0,
1113 this->device_viewport_size_.width(),
1114 this->device_viewport_size_.height()),
1115 SK_ColorBLUE,
1116 false);
1117 child_pass->quad_list.push_back(blue.PassAs<DrawQuad>());
1119 scoped_ptr<SharedQuadState> pass_shared_state =
1120 CreateTestSharedQuadState(gfx::Transform(), pass_rect);
1121 root_pass->quad_list.push_back(
1122 CreateTestRenderPassDrawQuad(pass_shared_state.get(),
1123 pass_rect,
1124 child_pass_id));
1125 RenderPassList pass_list;
1126 pass_list.push_back(child_pass.Pass());
1127 pass_list.push_back(root_pass.Pass());
1129 EXPECT_TRUE(this->RunPixelTest(
1130 &pass_list,
1131 base::FilePath(FILE_PATH_LITERAL("four_blue_green_checkers.png")),
1132 ExactPixelComparator(true)));
1135 // Software renderer does not support anti-aliased edges.
1136 TEST_F(GLRendererPixelTest, AntiAliasing) {
1137 gfx::Rect rect(this->device_viewport_size_);
1139 RenderPass::Id id(1, 1);
1140 scoped_ptr<RenderPass> pass = CreateTestRootRenderPass(id, rect);
1142 gfx::Transform red_content_to_target_transform;
1143 red_content_to_target_transform.Rotate(10);
1144 scoped_ptr<SharedQuadState> red_shared_state =
1145 CreateTestSharedQuadState(red_content_to_target_transform, rect);
1147 scoped_ptr<SolidColorDrawQuad> red = SolidColorDrawQuad::Create();
1148 red->SetNew(red_shared_state.get(), rect, SK_ColorRED, false);
1150 pass->quad_list.push_back(red.PassAs<DrawQuad>());
1152 gfx::Transform yellow_content_to_target_transform;
1153 yellow_content_to_target_transform.Rotate(5);
1154 scoped_ptr<SharedQuadState> yellow_shared_state =
1155 CreateTestSharedQuadState(yellow_content_to_target_transform, rect);
1157 scoped_ptr<SolidColorDrawQuad> yellow = SolidColorDrawQuad::Create();
1158 yellow->SetNew(yellow_shared_state.get(), rect, SK_ColorYELLOW, false);
1160 pass->quad_list.push_back(yellow.PassAs<DrawQuad>());
1162 gfx::Transform blue_content_to_target_transform;
1163 scoped_ptr<SharedQuadState> blue_shared_state =
1164 CreateTestSharedQuadState(blue_content_to_target_transform, rect);
1166 scoped_ptr<SolidColorDrawQuad> blue = SolidColorDrawQuad::Create();
1167 blue->SetNew(blue_shared_state.get(), rect, SK_ColorBLUE, false);
1169 pass->quad_list.push_back(blue.PassAs<DrawQuad>());
1171 RenderPassList pass_list;
1172 pass_list.push_back(pass.Pass());
1174 EXPECT_TRUE(this->RunPixelTest(
1175 &pass_list,
1176 base::FilePath(FILE_PATH_LITERAL("anti_aliasing.png")),
1177 FuzzyPixelOffByOneComparator(true)));
1180 // This test tests that anti-aliasing works for axis aligned quads.
1181 // Anti-aliasing is only supported in the gl renderer.
1182 TEST_F(GLRendererPixelTest, AxisAligned) {
1183 gfx::Rect rect(this->device_viewport_size_);
1185 RenderPass::Id id(1, 1);
1186 gfx::Transform transform_to_root;
1187 scoped_ptr<RenderPass> pass =
1188 CreateTestRenderPass(id, rect, transform_to_root);
1190 gfx::Transform red_content_to_target_transform;
1191 red_content_to_target_transform.Translate(50, 50);
1192 red_content_to_target_transform.Scale(
1193 0.5f + 1.0f / (rect.width() * 2.0f),
1194 0.5f + 1.0f / (rect.height() * 2.0f));
1195 scoped_ptr<SharedQuadState> red_shared_state =
1196 CreateTestSharedQuadState(red_content_to_target_transform, rect);
1198 scoped_ptr<SolidColorDrawQuad> red = SolidColorDrawQuad::Create();
1199 red->SetNew(red_shared_state.get(), rect, SK_ColorRED, false);
1201 pass->quad_list.push_back(red.PassAs<DrawQuad>());
1203 gfx::Transform yellow_content_to_target_transform;
1204 yellow_content_to_target_transform.Translate(25.5f, 25.5f);
1205 yellow_content_to_target_transform.Scale(0.5f, 0.5f);
1206 scoped_ptr<SharedQuadState> yellow_shared_state =
1207 CreateTestSharedQuadState(yellow_content_to_target_transform, rect);
1209 scoped_ptr<SolidColorDrawQuad> yellow = SolidColorDrawQuad::Create();
1210 yellow->SetNew(yellow_shared_state.get(), rect, SK_ColorYELLOW, false);
1212 pass->quad_list.push_back(yellow.PassAs<DrawQuad>());
1214 gfx::Transform blue_content_to_target_transform;
1215 scoped_ptr<SharedQuadState> blue_shared_state =
1216 CreateTestSharedQuadState(blue_content_to_target_transform, rect);
1218 scoped_ptr<SolidColorDrawQuad> blue = SolidColorDrawQuad::Create();
1219 blue->SetNew(blue_shared_state.get(), rect, SK_ColorBLUE, false);
1221 pass->quad_list.push_back(blue.PassAs<DrawQuad>());
1223 RenderPassList pass_list;
1224 pass_list.push_back(pass.Pass());
1226 EXPECT_TRUE(this->RunPixelTest(
1227 &pass_list,
1228 base::FilePath(FILE_PATH_LITERAL("axis_aligned.png")),
1229 ExactPixelComparator(true)));
1232 // This test tests that forcing anti-aliasing off works as expected.
1233 // Anti-aliasing is only supported in the gl renderer.
1234 TEST_F(GLRendererPixelTest, ForceAntiAliasingOff) {
1235 gfx::Rect rect(this->device_viewport_size_);
1237 RenderPass::Id id(1, 1);
1238 gfx::Transform transform_to_root;
1239 scoped_ptr<RenderPass> pass =
1240 CreateTestRenderPass(id, rect, transform_to_root);
1242 gfx::Transform hole_content_to_target_transform;
1243 hole_content_to_target_transform.Translate(50, 50);
1244 hole_content_to_target_transform.Scale(
1245 0.5f + 1.0f / (rect.width() * 2.0f),
1246 0.5f + 1.0f / (rect.height() * 2.0f));
1247 scoped_ptr<SharedQuadState> hole_shared_state =
1248 CreateTestSharedQuadState(hole_content_to_target_transform, rect);
1250 scoped_ptr<SolidColorDrawQuad> hole = SolidColorDrawQuad::Create();
1251 hole->SetAll(hole_shared_state.get(), rect, rect, rect, false,
1252 SK_ColorTRANSPARENT, true);
1253 pass->quad_list.push_back(hole.PassAs<DrawQuad>());
1255 gfx::Transform green_content_to_target_transform;
1256 scoped_ptr<SharedQuadState> green_shared_state =
1257 CreateTestSharedQuadState(green_content_to_target_transform, rect);
1259 scoped_ptr<SolidColorDrawQuad> green = SolidColorDrawQuad::Create();
1260 green->SetNew(green_shared_state.get(), rect, SK_ColorGREEN, false);
1262 pass->quad_list.push_back(green.PassAs<DrawQuad>());
1264 RenderPassList pass_list;
1265 pass_list.push_back(pass.Pass());
1267 EXPECT_TRUE(this->RunPixelTest(
1268 &pass_list,
1269 base::FilePath(FILE_PATH_LITERAL("force_anti_aliasing_off.png")),
1270 ExactPixelComparator(false)));
1273 TEST_F(GLRendererPixelTest, AntiAliasingPerspective) {
1274 gfx::Rect rect(this->device_viewport_size_);
1276 scoped_ptr<RenderPass> pass =
1277 CreateTestRootRenderPass(RenderPass::Id(1, 1), rect);
1279 gfx::Rect red_rect(0, 0, 180, 500);
1280 gfx::Transform red_content_to_target_transform(
1281 1.0, 2.4520, 10.6206, 19.0,
1282 0.0, 0.3528, 5.9737, 9.5,
1283 0.0, -0.2250, -0.9744, 0.0,
1284 0.0, 0.0225, 0.0974, 1.0);
1285 scoped_ptr<SharedQuadState> red_shared_state =
1286 CreateTestSharedQuadState(red_content_to_target_transform, red_rect);
1287 scoped_ptr<SolidColorDrawQuad> red = SolidColorDrawQuad::Create();
1288 red->SetNew(red_shared_state.get(), red_rect, SK_ColorRED, false);
1289 pass->quad_list.push_back(red.PassAs<DrawQuad>());
1291 gfx::Rect green_rect(19, 7, 180, 10);
1292 scoped_ptr<SharedQuadState> green_shared_state =
1293 CreateTestSharedQuadState(gfx::Transform(), green_rect);
1294 scoped_ptr<SolidColorDrawQuad> green = SolidColorDrawQuad::Create();
1295 green->SetNew(green_shared_state.get(), green_rect, SK_ColorGREEN, false);
1296 pass->quad_list.push_back(green.PassAs<DrawQuad>());
1298 scoped_ptr<SharedQuadState> blue_shared_state =
1299 CreateTestSharedQuadState(gfx::Transform(), rect);
1300 scoped_ptr<SolidColorDrawQuad> blue = SolidColorDrawQuad::Create();
1301 blue->SetNew(blue_shared_state.get(), rect, SK_ColorBLUE, false);
1302 pass->quad_list.push_back(blue.PassAs<DrawQuad>());
1304 RenderPassList pass_list;
1305 pass_list.push_back(pass.Pass());
1307 EXPECT_TRUE(this->RunPixelTest(
1308 &pass_list,
1309 base::FilePath(FILE_PATH_LITERAL("anti_aliasing_perspective.png")),
1310 FuzzyPixelOffByOneComparator(true)));
1313 TYPED_TEST(RendererPixelTestWithSkiaGPUBackend, PictureDrawQuadIdentityScale) {
1314 gfx::Size pile_tile_size(1000, 1000);
1315 gfx::Rect viewport(this->device_viewport_size_);
1316 bool use_skia_gpu_backend = this->UseSkiaGPUBackend();
1317 // TODO(enne): the renderer should figure this out on its own.
1318 bool contents_swizzled = !PlatformColor::SameComponentOrder(GL_RGBA);
1320 RenderPass::Id id(1, 1);
1321 gfx::Transform transform_to_root;
1322 scoped_ptr<RenderPass> pass =
1323 CreateTestRenderPass(id, viewport, transform_to_root);
1325 // One clipped blue quad in the lower right corner. Outside the clip
1326 // is red, which should not appear.
1327 gfx::Rect blue_rect(gfx::Size(100, 100));
1328 gfx::Rect blue_clip_rect(gfx::Point(50, 50), gfx::Size(50, 50));
1329 scoped_refptr<FakePicturePileImpl> blue_pile =
1330 FakePicturePileImpl::CreateFilledPile(pile_tile_size, blue_rect.size());
1331 SkPaint red_paint;
1332 red_paint.setColor(SK_ColorRED);
1333 blue_pile->add_draw_rect_with_paint(blue_rect, red_paint);
1334 SkPaint blue_paint;
1335 blue_paint.setColor(SK_ColorBLUE);
1336 blue_pile->add_draw_rect_with_paint(blue_clip_rect, blue_paint);
1337 blue_pile->RerecordPile();
1339 gfx::Transform blue_content_to_target_transform;
1340 gfx::Vector2d offset(viewport.bottom_right() - blue_rect.bottom_right());
1341 blue_content_to_target_transform.Translate(offset.x(), offset.y());
1342 gfx::RectF blue_scissor_rect = blue_clip_rect;
1343 blue_content_to_target_transform.TransformRect(&blue_scissor_rect);
1344 scoped_ptr<SharedQuadState> blue_shared_state =
1345 CreateTestSharedQuadStateClipped(blue_content_to_target_transform,
1346 blue_rect,
1347 gfx::ToEnclosingRect(blue_scissor_rect));
1349 scoped_ptr<PictureDrawQuad> blue_quad = PictureDrawQuad::Create();
1351 blue_quad->SetNew(blue_shared_state.get(),
1352 viewport, // Intentionally bigger than clip.
1353 gfx::Rect(),
1354 viewport,
1355 viewport.size(),
1356 contents_swizzled,
1357 viewport,
1358 1.f,
1359 use_skia_gpu_backend,
1360 blue_pile);
1361 pass->quad_list.push_back(blue_quad.PassAs<DrawQuad>());
1363 // One viewport-filling green quad.
1364 scoped_refptr<FakePicturePileImpl> green_pile =
1365 FakePicturePileImpl::CreateFilledPile(pile_tile_size, viewport.size());
1366 SkPaint green_paint;
1367 green_paint.setColor(SK_ColorGREEN);
1368 green_pile->add_draw_rect_with_paint(viewport, green_paint);
1369 green_pile->RerecordPile();
1371 gfx::Transform green_content_to_target_transform;
1372 scoped_ptr<SharedQuadState> green_shared_state =
1373 CreateTestSharedQuadState(green_content_to_target_transform, viewport);
1375 scoped_ptr<PictureDrawQuad> green_quad = PictureDrawQuad::Create();
1376 green_quad->SetNew(green_shared_state.get(),
1377 viewport,
1378 gfx::Rect(),
1379 gfx::RectF(0.f, 0.f, 1.f, 1.f),
1380 viewport.size(),
1381 contents_swizzled,
1382 viewport,
1383 1.f,
1384 use_skia_gpu_backend,
1385 green_pile);
1386 pass->quad_list.push_back(green_quad.PassAs<DrawQuad>());
1388 RenderPassList pass_list;
1389 pass_list.push_back(pass.Pass());
1391 EXPECT_TRUE(this->RunPixelTest(
1392 &pass_list,
1393 base::FilePath(FILE_PATH_LITERAL("green_with_blue_corner.png")),
1394 ExactPixelComparator(true)));
1397 TYPED_TEST(RendererPixelTestWithSkiaGPUBackend,
1398 PictureDrawQuadNonIdentityScale) {
1399 gfx::Size pile_tile_size(1000, 1000);
1400 gfx::Rect viewport(this->device_viewport_size_);
1401 bool use_skia_gpu_backend = this->UseSkiaGPUBackend();
1402 // TODO(enne): the renderer should figure this out on its own.
1403 bool contents_swizzled = !PlatformColor::SameComponentOrder(GL_RGBA);
1405 RenderPass::Id id(1, 1);
1406 gfx::Transform transform_to_root;
1407 scoped_ptr<RenderPass> pass =
1408 CreateTestRenderPass(id, viewport, transform_to_root);
1410 // As scaling up the blue checkerboards will cause sampling on the GPU,
1411 // a few extra "cleanup rects" need to be added to clobber the blending
1412 // to make the output image more clean. This will also test subrects
1413 // of the layer.
1414 gfx::Transform green_content_to_target_transform;
1415 gfx::Rect green_rect1(gfx::Point(80, 0), gfx::Size(20, 100));
1416 gfx::Rect green_rect2(gfx::Point(0, 80), gfx::Size(100, 20));
1417 scoped_refptr<FakePicturePileImpl> green_pile =
1418 FakePicturePileImpl::CreateFilledPile(pile_tile_size, viewport.size());
1419 SkPaint red_paint;
1420 red_paint.setColor(SK_ColorRED);
1421 green_pile->add_draw_rect_with_paint(viewport, red_paint);
1422 SkPaint green_paint;
1423 green_paint.setColor(SK_ColorGREEN);
1424 green_pile->add_draw_rect_with_paint(green_rect1, green_paint);
1425 green_pile->add_draw_rect_with_paint(green_rect2, green_paint);
1426 green_pile->RerecordPile();
1428 scoped_ptr<SharedQuadState> top_right_green_shared_quad_state =
1429 CreateTestSharedQuadState(green_content_to_target_transform, viewport);
1431 scoped_ptr<PictureDrawQuad> green_quad1 = PictureDrawQuad::Create();
1432 green_quad1->SetNew(top_right_green_shared_quad_state.get(),
1433 green_rect1,
1434 gfx::Rect(),
1435 gfx::RectF(green_rect1.size()),
1436 green_rect1.size(),
1437 contents_swizzled,
1438 green_rect1,
1439 1.f,
1440 use_skia_gpu_backend,
1441 green_pile);
1442 pass->quad_list.push_back(green_quad1.PassAs<DrawQuad>());
1444 scoped_ptr<PictureDrawQuad> green_quad2 = PictureDrawQuad::Create();
1445 green_quad2->SetNew(top_right_green_shared_quad_state.get(),
1446 green_rect2,
1447 gfx::Rect(),
1448 gfx::RectF(green_rect2.size()),
1449 green_rect2.size(),
1450 contents_swizzled,
1451 green_rect2,
1452 1.f,
1453 use_skia_gpu_backend,
1454 green_pile);
1455 pass->quad_list.push_back(green_quad2.PassAs<DrawQuad>());
1457 // Add a green clipped checkerboard in the bottom right to help test
1458 // interleaving picture quad content and solid color content.
1459 gfx::Rect bottom_right_rect(
1460 gfx::Point(viewport.width() / 2, viewport.height() / 2),
1461 gfx::Size(viewport.width() / 2, viewport.height() / 2));
1462 scoped_ptr<SharedQuadState> bottom_right_green_shared_state =
1463 CreateTestSharedQuadStateClipped(
1464 green_content_to_target_transform, viewport, bottom_right_rect);
1465 scoped_ptr<SolidColorDrawQuad> bottom_right_color_quad =
1466 SolidColorDrawQuad::Create();
1467 bottom_right_color_quad->SetNew(
1468 bottom_right_green_shared_state.get(), viewport, SK_ColorGREEN, false);
1469 pass->quad_list.push_back(bottom_right_color_quad.PassAs<DrawQuad>());
1471 // Add two blue checkerboards taking up the bottom left and top right,
1472 // but use content scales as content rects to make this happen.
1473 // The content is at a 4x content scale.
1474 gfx::Rect layer_rect(gfx::Size(20, 30));
1475 float contents_scale = 4.f;
1476 // Two rects that touch at their corners, arbitrarily placed in the layer.
1477 gfx::RectF blue_layer_rect1(gfx::PointF(5.5f, 9.0f), gfx::SizeF(2.5f, 2.5f));
1478 gfx::RectF blue_layer_rect2(gfx::PointF(8.0f, 6.5f), gfx::SizeF(2.5f, 2.5f));
1479 gfx::RectF union_layer_rect = blue_layer_rect1;
1480 union_layer_rect.Union(blue_layer_rect2);
1482 // Because scaling up will cause sampling outside the rects, add one extra
1483 // pixel of buffer at the final content scale.
1484 float inset = -1.f / contents_scale;
1485 blue_layer_rect1.Inset(inset, inset, inset, inset);
1486 blue_layer_rect2.Inset(inset, inset, inset, inset);
1488 scoped_refptr<FakePicturePileImpl> pile =
1489 FakePicturePileImpl::CreateFilledPile(pile_tile_size, layer_rect.size());
1491 Region outside(layer_rect);
1492 outside.Subtract(gfx::ToEnclosingRect(union_layer_rect));
1493 for (Region::Iterator iter(outside); iter.has_rect(); iter.next()) {
1494 pile->add_draw_rect_with_paint(iter.rect(), red_paint);
1497 SkPaint blue_paint;
1498 blue_paint.setColor(SK_ColorBLUE);
1499 pile->add_draw_rect_with_paint(blue_layer_rect1, blue_paint);
1500 pile->add_draw_rect_with_paint(blue_layer_rect2, blue_paint);
1501 pile->RerecordPile();
1503 gfx::Rect content_rect(
1504 gfx::ScaleToEnclosingRect(layer_rect, contents_scale));
1505 gfx::Rect content_union_rect(
1506 gfx::ToEnclosingRect(gfx::ScaleRect(union_layer_rect, contents_scale)));
1508 // At a scale of 4x the rectangles with a width of 2.5 will take up 10 pixels,
1509 // so scale an additional 10x to make them 100x100.
1510 gfx::Transform content_to_target_transform;
1511 content_to_target_transform.Scale(10.0, 10.0);
1512 gfx::Rect quad_content_rect(gfx::Size(20, 20));
1513 scoped_ptr<SharedQuadState> blue_shared_state =
1514 CreateTestSharedQuadState(content_to_target_transform, quad_content_rect);
1516 scoped_ptr<PictureDrawQuad> blue_quad = PictureDrawQuad::Create();
1517 blue_quad->SetNew(blue_shared_state.get(),
1518 quad_content_rect,
1519 gfx::Rect(),
1520 quad_content_rect,
1521 content_union_rect.size(),
1522 contents_swizzled,
1523 content_union_rect,
1524 contents_scale,
1525 use_skia_gpu_backend,
1526 pile);
1527 pass->quad_list.push_back(blue_quad.PassAs<DrawQuad>());
1529 // Fill left half of viewport with green.
1530 gfx::Transform half_green_content_to_target_transform;
1531 gfx::Rect half_green_rect(gfx::Size(viewport.width() / 2, viewport.height()));
1532 scoped_ptr<SharedQuadState> half_green_shared_state =
1533 CreateTestSharedQuadState(half_green_content_to_target_transform,
1534 half_green_rect);
1535 scoped_ptr<SolidColorDrawQuad> half_color_quad = SolidColorDrawQuad::Create();
1536 half_color_quad->SetNew(
1537 half_green_shared_state.get(), half_green_rect, SK_ColorGREEN, false);
1538 pass->quad_list.push_back(half_color_quad.PassAs<DrawQuad>());
1540 RenderPassList pass_list;
1541 pass_list.push_back(pass.Pass());
1543 EXPECT_TRUE(this->RunPixelTest(
1544 &pass_list,
1545 base::FilePath(FILE_PATH_LITERAL("four_blue_green_checkers.png")),
1546 ExactPixelComparator(true)));
1548 #endif // !defined(OS_ANDROID)
1550 } // namespace
1551 } // namespace cc