Move prefs::kLastPolicyStatisticsUpdate to the policy component.
[chromium-blink-merge.git] / cc / output / renderer_pixeltest.cc
blobf0187aacdb39bc17bb51cd9957bc8344b5d7df8d
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/sync_point_helper.h"
12 #include "cc/test/fake_picture_pile_impl.h"
13 #include "cc/test/pixel_test.h"
14 #include "gpu/GLES2/gl2extchromium.h"
15 #include "third_party/WebKit/public/platform/WebGraphicsContext3D.h"
16 #include "third_party/skia/include/core/SkImageFilter.h"
17 #include "third_party/skia/include/core/SkMatrix.h"
18 #include "third_party/skia/include/effects/SkColorFilterImageFilter.h"
19 #include "third_party/skia/include/effects/SkColorMatrixFilter.h"
20 #include "ui/gfx/rect_conversions.h"
22 namespace cc {
23 namespace {
25 scoped_ptr<RenderPass> CreateTestRootRenderPass(RenderPass::Id id,
26 gfx::Rect rect) {
27 scoped_ptr<RenderPass> pass = RenderPass::Create();
28 const gfx::Rect output_rect = rect;
29 const gfx::RectF damage_rect = rect;
30 const gfx::Transform transform_to_root_target;
31 pass->SetNew(id, output_rect, damage_rect, transform_to_root_target);
32 return pass.Pass();
35 scoped_ptr<RenderPass> CreateTestRenderPass(
36 RenderPass::Id id,
37 gfx::Rect rect,
38 const gfx::Transform& transform_to_root_target) {
39 scoped_ptr<RenderPass> pass = RenderPass::Create();
40 const gfx::Rect output_rect = rect;
41 const gfx::RectF damage_rect = rect;
42 pass->SetNew(id, output_rect, damage_rect, transform_to_root_target);
43 return pass.Pass();
46 scoped_ptr<SharedQuadState> CreateTestSharedQuadState(
47 gfx::Transform content_to_target_transform, gfx::Rect rect) {
48 const gfx::Size content_bounds = rect.size();
49 const gfx::Rect visible_content_rect = rect;
50 const gfx::Rect clip_rect = rect;
51 const bool is_clipped = false;
52 const float opacity = 1.0f;
53 scoped_ptr<SharedQuadState> shared_state = SharedQuadState::Create();
54 shared_state->SetAll(content_to_target_transform,
55 content_bounds,
56 visible_content_rect,
57 clip_rect,
58 is_clipped,
59 opacity);
60 return shared_state.Pass();
63 scoped_ptr<SharedQuadState> CreateTestSharedQuadStateClipped(
64 gfx::Transform content_to_target_transform,
65 gfx::Rect rect,
66 gfx::Rect clip_rect) {
67 const gfx::Size content_bounds = rect.size();
68 const gfx::Rect visible_content_rect = clip_rect;
69 const bool is_clipped = true;
70 const float opacity = 1.0f;
71 scoped_ptr<SharedQuadState> shared_state = SharedQuadState::Create();
72 shared_state->SetAll(content_to_target_transform,
73 content_bounds,
74 visible_content_rect,
75 clip_rect,
76 is_clipped,
77 opacity);
78 return shared_state.Pass();
81 scoped_ptr<DrawQuad> CreateTestRenderPassDrawQuad(
82 SharedQuadState* shared_state, gfx::Rect rect, RenderPass::Id pass_id) {
83 scoped_ptr<RenderPassDrawQuad> quad = RenderPassDrawQuad::Create();
84 quad->SetNew(shared_state,
85 rect,
86 pass_id,
87 false, // is_replica
88 0, // mask_resource_id
89 rect, // contents_changed_since_last_frame
90 gfx::RectF(), // mask_uv_rect
91 FilterOperations(), // foreground filters
92 skia::RefPtr<SkImageFilter>(), // foreground filter
93 FilterOperations()); // background filters
95 return quad.PassAs<DrawQuad>();
98 scoped_ptr<TextureDrawQuad> CreateTestTextureDrawQuad(
99 gfx::Rect rect,
100 SkColor texel_color,
101 SkColor background_color,
102 bool premultiplied_alpha,
103 SharedQuadState* shared_state,
104 ResourceProvider* resource_provider) {
105 SkPMColor pixel_color = premultiplied_alpha ?
106 SkPreMultiplyColor(texel_color) :
107 SkPackARGB32NoCheck(SkColorGetA(texel_color),
108 SkColorGetR(texel_color),
109 SkColorGetG(texel_color),
110 SkColorGetB(texel_color));
111 std::vector<uint32_t> pixels(rect.size().GetArea(), pixel_color);
113 ResourceProvider::ResourceId resource =
114 resource_provider->CreateResource(rect.size(),
115 GL_CLAMP_TO_EDGE,
116 ResourceProvider::TextureUsageAny,
117 RGBA_8888);
118 resource_provider->SetPixels(
119 resource,
120 reinterpret_cast<uint8_t*>(&pixels.front()),
121 rect,
122 rect,
123 gfx::Vector2d());
125 float vertex_opacity[4] = {1.0f, 1.0f, 1.0f, 1.0f};
127 scoped_ptr<TextureDrawQuad> quad = TextureDrawQuad::Create();
128 quad->SetNew(shared_state,
129 rect,
130 gfx::Rect(),
131 resource,
132 premultiplied_alpha,
133 gfx::PointF(0.0f, 0.0f), // uv_top_left
134 gfx::PointF(1.0f, 1.0f), // uv_bottom_right
135 background_color,
136 vertex_opacity,
137 false); // flipped
138 return quad.Pass();
141 typedef ::testing::Types<GLRenderer,
142 SoftwareRenderer,
143 GLRendererWithExpandedViewport,
144 SoftwareRendererWithExpandedViewport> RendererTypes;
145 TYPED_TEST_CASE(RendererPixelTest, RendererTypes);
147 typedef ::testing::Types<GLRenderer,
148 GLRendererWithSkiaGPUBackend,
149 SoftwareRenderer> RendererTypesWithSkiaGPUBackend;
150 template <typename RendererType>
151 class RendererPixelTestWithSkiaGPUBackend
152 : public RendererPixelTest<RendererType> {
154 TYPED_TEST_CASE(RendererPixelTestWithSkiaGPUBackend,
155 RendererTypesWithSkiaGPUBackend);
157 // All pixels can be off by one, but any more than that is an error.
158 class FuzzyPixelOffByOneComparator : public FuzzyPixelComparator {
159 public:
160 explicit FuzzyPixelOffByOneComparator(bool discard_alpha)
161 : FuzzyPixelComparator(discard_alpha, 100.f, 0.f, 1.f, 1, 0) {}
164 template <typename RendererType>
165 class FuzzyForSoftwareOnlyPixelComparator : public PixelComparator {
166 public:
167 explicit FuzzyForSoftwareOnlyPixelComparator(bool discard_alpha)
168 : fuzzy_(discard_alpha), exact_(discard_alpha) {}
170 virtual bool Compare(const SkBitmap& actual_bmp,
171 const SkBitmap& expected_bmp) const;
173 private:
174 FuzzyPixelOffByOneComparator fuzzy_;
175 ExactPixelComparator exact_;
178 template<>
179 bool FuzzyForSoftwareOnlyPixelComparator<SoftwareRenderer>::Compare(
180 const SkBitmap& actual_bmp,
181 const SkBitmap& expected_bmp) const {
182 return fuzzy_.Compare(actual_bmp, expected_bmp);
185 template <>
186 bool FuzzyForSoftwareOnlyPixelComparator<
187 SoftwareRendererWithExpandedViewport>::Compare(
188 const SkBitmap& actual_bmp,
189 const SkBitmap& expected_bmp) const {
190 return fuzzy_.Compare(actual_bmp, expected_bmp);
193 template<typename RendererType>
194 bool FuzzyForSoftwareOnlyPixelComparator<RendererType>::Compare(
195 const SkBitmap& actual_bmp,
196 const SkBitmap& expected_bmp) const {
197 return exact_.Compare(actual_bmp, expected_bmp);
200 #if !defined(OS_ANDROID)
201 TYPED_TEST(RendererPixelTest, SimpleGreenRect) {
202 gfx::Rect rect(this->device_viewport_size_);
204 RenderPass::Id id(1, 1);
205 scoped_ptr<RenderPass> pass = CreateTestRootRenderPass(id, rect);
207 scoped_ptr<SharedQuadState> shared_state =
208 CreateTestSharedQuadState(gfx::Transform(), rect);
210 scoped_ptr<SolidColorDrawQuad> color_quad = SolidColorDrawQuad::Create();
211 color_quad->SetNew(shared_state.get(), rect, SK_ColorGREEN, false);
213 pass->quad_list.push_back(color_quad.PassAs<DrawQuad>());
215 RenderPassList pass_list;
216 pass_list.push_back(pass.Pass());
218 EXPECT_TRUE(this->RunPixelTest(
219 &pass_list,
220 PixelTest::NoOffscreenContext,
221 base::FilePath(FILE_PATH_LITERAL("green.png")),
222 ExactPixelComparator(true)));
225 TYPED_TEST(RendererPixelTest, SimpleGreenRect_NonRootRenderPass) {
226 gfx::Rect rect(this->device_viewport_size_);
227 gfx::Rect small_rect(100, 100);
229 RenderPass::Id child_id(2, 1);
230 scoped_ptr<RenderPass> child_pass =
231 CreateTestRenderPass(child_id, small_rect, gfx::Transform());
233 scoped_ptr<SharedQuadState> child_shared_state =
234 CreateTestSharedQuadState(gfx::Transform(), small_rect);
236 scoped_ptr<SolidColorDrawQuad> color_quad = SolidColorDrawQuad::Create();
237 color_quad->SetNew(child_shared_state.get(), rect, SK_ColorGREEN, false);
238 child_pass->quad_list.push_back(color_quad.PassAs<DrawQuad>());
240 RenderPass::Id root_id(1, 1);
241 scoped_ptr<RenderPass> root_pass =
242 CreateTestRenderPass(root_id, rect, gfx::Transform());
244 scoped_ptr<SharedQuadState> root_shared_state =
245 CreateTestSharedQuadState(gfx::Transform(), rect);
247 scoped_ptr<DrawQuad> render_pass_quad =
248 CreateTestRenderPassDrawQuad(root_shared_state.get(),
249 small_rect,
250 child_id);
251 root_pass->quad_list.push_back(render_pass_quad.PassAs<DrawQuad>());
253 RenderPass* child_pass_ptr = child_pass.get();
255 RenderPassList pass_list;
256 pass_list.push_back(child_pass.Pass());
257 pass_list.push_back(root_pass.Pass());
259 EXPECT_TRUE(this->RunPixelTestWithReadbackTarget(
260 &pass_list,
261 child_pass_ptr,
262 PixelTest::NoOffscreenContext,
263 base::FilePath(FILE_PATH_LITERAL("green_small.png")),
264 ExactPixelComparator(true)));
267 TYPED_TEST(RendererPixelTest, PremultipliedTextureWithoutBackground) {
268 gfx::Rect rect(this->device_viewport_size_);
270 RenderPass::Id id(1, 1);
271 scoped_ptr<RenderPass> pass = CreateTestRootRenderPass(id, rect);
273 scoped_ptr<SharedQuadState> shared_state =
274 CreateTestSharedQuadState(gfx::Transform(), rect);
276 scoped_ptr<TextureDrawQuad> texture_quad = CreateTestTextureDrawQuad(
277 gfx::Rect(this->device_viewport_size_),
278 SkColorSetARGB(128, 0, 255, 0), // Texel color.
279 SK_ColorTRANSPARENT, // Background color.
280 true, // Premultiplied alpha.
281 shared_state.get(),
282 this->resource_provider_.get());
283 pass->quad_list.push_back(texture_quad.PassAs<DrawQuad>());
285 scoped_ptr<SolidColorDrawQuad> color_quad = SolidColorDrawQuad::Create();
286 color_quad->SetNew(shared_state.get(), rect, SK_ColorWHITE, false);
287 pass->quad_list.push_back(color_quad.PassAs<DrawQuad>());
289 RenderPassList pass_list;
290 pass_list.push_back(pass.Pass());
292 EXPECT_TRUE(this->RunPixelTest(
293 &pass_list,
294 PixelTest::NoOffscreenContext,
295 base::FilePath(FILE_PATH_LITERAL("green_alpha.png")),
296 FuzzyPixelOffByOneComparator(true)));
299 TYPED_TEST(RendererPixelTest, PremultipliedTextureWithBackground) {
300 gfx::Rect rect(this->device_viewport_size_);
302 RenderPass::Id id(1, 1);
303 scoped_ptr<RenderPass> pass = CreateTestRootRenderPass(id, rect);
305 scoped_ptr<SharedQuadState> texture_quad_state =
306 CreateTestSharedQuadState(gfx::Transform(), rect);
307 texture_quad_state->opacity = 0.8f;
309 scoped_ptr<TextureDrawQuad> texture_quad = CreateTestTextureDrawQuad(
310 gfx::Rect(this->device_viewport_size_),
311 SkColorSetARGB(204, 120, 255, 120), // Texel color.
312 SK_ColorGREEN, // Background color.
313 true, // Premultiplied alpha.
314 texture_quad_state.get(),
315 this->resource_provider_.get());
316 pass->quad_list.push_back(texture_quad.PassAs<DrawQuad>());
318 scoped_ptr<SharedQuadState> color_quad_state =
319 CreateTestSharedQuadState(gfx::Transform(), rect);
320 scoped_ptr<SolidColorDrawQuad> color_quad = SolidColorDrawQuad::Create();
321 color_quad->SetNew(color_quad_state.get(), rect, SK_ColorWHITE, false);
322 pass->quad_list.push_back(color_quad.PassAs<DrawQuad>());
324 RenderPassList pass_list;
325 pass_list.push_back(pass.Pass());
327 EXPECT_TRUE(this->RunPixelTest(
328 &pass_list,
329 PixelTest::NoOffscreenContext,
330 base::FilePath(FILE_PATH_LITERAL("green_alpha.png")),
331 FuzzyPixelOffByOneComparator(true)));
334 // TODO(skaslev): The software renderer does not support non-premultplied alpha.
335 TEST_F(GLRendererPixelTest, NonPremultipliedTextureWithoutBackground) {
336 gfx::Rect rect(this->device_viewport_size_);
338 RenderPass::Id id(1, 1);
339 scoped_ptr<RenderPass> pass = CreateTestRootRenderPass(id, rect);
341 scoped_ptr<SharedQuadState> shared_state =
342 CreateTestSharedQuadState(gfx::Transform(), rect);
344 scoped_ptr<TextureDrawQuad> texture_quad = CreateTestTextureDrawQuad(
345 gfx::Rect(this->device_viewport_size_),
346 SkColorSetARGB(128, 0, 255, 0), // Texel color.
347 SK_ColorTRANSPARENT, // Background color.
348 false, // Premultiplied alpha.
349 shared_state.get(),
350 this->resource_provider_.get());
351 pass->quad_list.push_back(texture_quad.PassAs<DrawQuad>());
353 scoped_ptr<SolidColorDrawQuad> color_quad = SolidColorDrawQuad::Create();
354 color_quad->SetNew(shared_state.get(), rect, SK_ColorWHITE, false);
355 pass->quad_list.push_back(color_quad.PassAs<DrawQuad>());
357 RenderPassList pass_list;
358 pass_list.push_back(pass.Pass());
360 EXPECT_TRUE(this->RunPixelTest(
361 &pass_list,
362 PixelTest::NoOffscreenContext,
363 base::FilePath(FILE_PATH_LITERAL("green_alpha.png")),
364 FuzzyPixelOffByOneComparator(true)));
367 // TODO(skaslev): The software renderer does not support non-premultplied alpha.
368 TEST_F(GLRendererPixelTest, NonPremultipliedTextureWithBackground) {
369 gfx::Rect rect(this->device_viewport_size_);
371 RenderPass::Id id(1, 1);
372 scoped_ptr<RenderPass> pass = CreateTestRootRenderPass(id, rect);
374 scoped_ptr<SharedQuadState> texture_quad_state =
375 CreateTestSharedQuadState(gfx::Transform(), rect);
376 texture_quad_state->opacity = 0.8f;
378 scoped_ptr<TextureDrawQuad> texture_quad = CreateTestTextureDrawQuad(
379 gfx::Rect(this->device_viewport_size_),
380 SkColorSetARGB(204, 120, 255, 120), // Texel color.
381 SK_ColorGREEN, // Background color.
382 false, // Premultiplied alpha.
383 texture_quad_state.get(),
384 this->resource_provider_.get());
385 pass->quad_list.push_back(texture_quad.PassAs<DrawQuad>());
387 scoped_ptr<SharedQuadState> color_quad_state =
388 CreateTestSharedQuadState(gfx::Transform(), rect);
389 scoped_ptr<SolidColorDrawQuad> color_quad = SolidColorDrawQuad::Create();
390 color_quad->SetNew(color_quad_state.get(), rect, SK_ColorWHITE, false);
391 pass->quad_list.push_back(color_quad.PassAs<DrawQuad>());
393 RenderPassList pass_list;
394 pass_list.push_back(pass.Pass());
396 EXPECT_TRUE(this->RunPixelTest(
397 &pass_list,
398 PixelTest::NoOffscreenContext,
399 base::FilePath(FILE_PATH_LITERAL("green_alpha.png")),
400 FuzzyPixelOffByOneComparator(true)));
403 class VideoGLRendererPixelTest : public GLRendererPixelTest {
404 protected:
405 scoped_ptr<YUVVideoDrawQuad> CreateTestYUVVideoDrawQuad(
406 SharedQuadState* shared_state, bool with_alpha, bool is_transparent) {
407 gfx::Rect rect(this->device_viewport_size_);
408 gfx::Rect opaque_rect(0, 0, 0, 0);
410 ResourceProvider::ResourceId y_resource =
411 resource_provider_->CreateResource(
412 this->device_viewport_size_,
413 GL_CLAMP_TO_EDGE,
414 ResourceProvider::TextureUsageAny,
415 LUMINANCE_8);
416 ResourceProvider::ResourceId u_resource =
417 resource_provider_->CreateResource(
418 this->device_viewport_size_,
419 GL_CLAMP_TO_EDGE,
420 ResourceProvider::TextureUsageAny,
421 LUMINANCE_8);
422 ResourceProvider::ResourceId v_resource =
423 resource_provider_->CreateResource(
424 this->device_viewport_size_,
425 GL_CLAMP_TO_EDGE,
426 ResourceProvider::TextureUsageAny,
427 LUMINANCE_8);
428 ResourceProvider::ResourceId a_resource = 0;
429 if (with_alpha) {
430 a_resource = resource_provider_->CreateResource(
431 this->device_viewport_size_,
432 GL_CLAMP_TO_EDGE,
433 ResourceProvider::TextureUsageAny,
434 LUMINANCE_8);
437 int w = this->device_viewport_size_.width();
438 int h = this->device_viewport_size_.height();
439 const int y_plane_size = w * h;
440 gfx::Rect uv_rect((w + 1) / 2, (h + 1) / 2);
441 const int uv_plane_size = uv_rect.size().GetArea();
442 scoped_ptr<uint8_t[]> y_plane(new uint8_t[y_plane_size]);
443 scoped_ptr<uint8_t[]> u_plane(new uint8_t[uv_plane_size]);
444 scoped_ptr<uint8_t[]> v_plane(new uint8_t[uv_plane_size]);
445 scoped_ptr<uint8_t[]> a_plane;
446 if (with_alpha)
447 a_plane.reset(new uint8_t[y_plane_size]);
448 // YUV values representing Green.
449 memset(y_plane.get(), 149, y_plane_size);
450 memset(u_plane.get(), 43, uv_plane_size);
451 memset(v_plane.get(), 21, uv_plane_size);
452 if (with_alpha)
453 memset(a_plane.get(), is_transparent ? 0 : 128, y_plane_size);
455 resource_provider_->SetPixels(y_resource, y_plane.get(), rect, rect,
456 gfx::Vector2d());
457 resource_provider_->SetPixels(u_resource, u_plane.get(), uv_rect, uv_rect,
458 gfx::Vector2d());
459 resource_provider_->SetPixels(v_resource, v_plane.get(), uv_rect, uv_rect,
460 gfx::Vector2d());
461 if (with_alpha) {
462 resource_provider_->SetPixels(a_resource, a_plane.get(), rect, rect,
463 gfx::Vector2d());
466 scoped_ptr<YUVVideoDrawQuad> yuv_quad = cc::YUVVideoDrawQuad::Create();
467 yuv_quad->SetNew(shared_state, rect, opaque_rect, gfx::Size(),
468 y_resource, u_resource, v_resource, a_resource);
469 return yuv_quad.Pass();
473 TEST_F(VideoGLRendererPixelTest, SimpleYUVRect) {
474 gfx::Rect rect(this->device_viewport_size_);
476 RenderPass::Id id(1, 1);
477 scoped_ptr<RenderPass> pass = CreateTestRootRenderPass(id, rect);
479 scoped_ptr<SharedQuadState> shared_state =
480 CreateTestSharedQuadState(gfx::Transform(), rect);
482 scoped_ptr<YUVVideoDrawQuad> yuv_quad =
483 CreateTestYUVVideoDrawQuad(shared_state.get(), false, false);
485 pass->quad_list.push_back(yuv_quad.PassAs<DrawQuad>());
487 RenderPassList pass_list;
488 pass_list.push_back(pass.Pass());
490 EXPECT_TRUE(this->RunPixelTest(
491 &pass_list,
492 PixelTest::NoOffscreenContext,
493 base::FilePath(FILE_PATH_LITERAL("green.png")),
494 ExactPixelComparator(true)));
497 TEST_F(VideoGLRendererPixelTest, SimpleYUVARect) {
498 gfx::Rect rect(this->device_viewport_size_);
500 RenderPass::Id id(1, 1);
501 scoped_ptr<RenderPass> pass = CreateTestRootRenderPass(id, rect);
503 scoped_ptr<SharedQuadState> shared_state =
504 CreateTestSharedQuadState(gfx::Transform(), rect);
506 scoped_ptr<YUVVideoDrawQuad> yuv_quad =
507 CreateTestYUVVideoDrawQuad(shared_state.get(), true, false);
509 pass->quad_list.push_back(yuv_quad.PassAs<DrawQuad>());
511 scoped_ptr<SolidColorDrawQuad> color_quad = SolidColorDrawQuad::Create();
512 color_quad->SetNew(shared_state.get(), rect, SK_ColorWHITE, false);
514 pass->quad_list.push_back(color_quad.PassAs<DrawQuad>());
516 RenderPassList pass_list;
517 pass_list.push_back(pass.Pass());
519 EXPECT_TRUE(this->RunPixelTest(
520 &pass_list,
521 PixelTest::NoOffscreenContext,
522 base::FilePath(FILE_PATH_LITERAL("green_alpha.png")),
523 ExactPixelComparator(true)));
526 TEST_F(VideoGLRendererPixelTest, FullyTransparentYUVARect) {
527 gfx::Rect rect(this->device_viewport_size_);
529 RenderPass::Id id(1, 1);
530 scoped_ptr<RenderPass> pass = CreateTestRootRenderPass(id, rect);
532 scoped_ptr<SharedQuadState> shared_state =
533 CreateTestSharedQuadState(gfx::Transform(), rect);
535 scoped_ptr<YUVVideoDrawQuad> yuv_quad =
536 CreateTestYUVVideoDrawQuad(shared_state.get(), true, true);
538 pass->quad_list.push_back(yuv_quad.PassAs<DrawQuad>());
540 scoped_ptr<SolidColorDrawQuad> color_quad = SolidColorDrawQuad::Create();
541 color_quad->SetNew(shared_state.get(), rect, SK_ColorBLACK, false);
543 pass->quad_list.push_back(color_quad.PassAs<DrawQuad>());
545 RenderPassList pass_list;
546 pass_list.push_back(pass.Pass());
548 EXPECT_TRUE(this->RunPixelTest(
549 &pass_list,
550 PixelTest::NoOffscreenContext,
551 base::FilePath(FILE_PATH_LITERAL("black.png")),
552 ExactPixelComparator(true)));
555 TYPED_TEST(RendererPixelTest, FastPassColorFilterAlpha) {
556 gfx::Rect viewport_rect(this->device_viewport_size_);
558 RenderPass::Id root_pass_id(1, 1);
559 scoped_ptr<RenderPass> root_pass =
560 CreateTestRootRenderPass(root_pass_id, viewport_rect);
562 RenderPass::Id child_pass_id(2, 2);
563 gfx::Rect pass_rect(this->device_viewport_size_);
564 gfx::Transform transform_to_root;
565 scoped_ptr<RenderPass> child_pass =
566 CreateTestRenderPass(child_pass_id, pass_rect, transform_to_root);
568 gfx::Transform content_to_target_transform;
569 scoped_ptr<SharedQuadState> shared_state =
570 CreateTestSharedQuadState(content_to_target_transform, viewport_rect);
571 shared_state->opacity = 0.5f;
573 scoped_ptr<SolidColorDrawQuad> blue = SolidColorDrawQuad::Create();
574 blue->SetNew(shared_state.get(),
575 gfx::Rect(0,
577 this->device_viewport_size_.width(),
578 this->device_viewport_size_.height() / 2),
579 SK_ColorBLUE,
580 false);
581 scoped_ptr<SolidColorDrawQuad> yellow = SolidColorDrawQuad::Create();
582 yellow->SetNew(shared_state.get(),
583 gfx::Rect(0,
584 this->device_viewport_size_.height() / 2,
585 this->device_viewport_size_.width(),
586 this->device_viewport_size_.height() / 2),
587 SK_ColorYELLOW,
588 false);
590 scoped_ptr<SharedQuadState> blank_state =
591 CreateTestSharedQuadState(content_to_target_transform, viewport_rect);
593 scoped_ptr<SolidColorDrawQuad> white = SolidColorDrawQuad::Create();
594 white->SetNew(blank_state.get(),
595 viewport_rect,
596 SK_ColorWHITE,
597 false);
599 child_pass->quad_list.push_back(blue.PassAs<DrawQuad>());
600 child_pass->quad_list.push_back(yellow.PassAs<DrawQuad>());
601 child_pass->quad_list.push_back(white.PassAs<DrawQuad>());
603 scoped_ptr<SharedQuadState> pass_shared_state =
604 CreateTestSharedQuadState(gfx::Transform(), pass_rect);
606 SkScalar matrix[20];
607 float amount = 0.5f;
608 matrix[0] = 0.213f + 0.787f * amount;
609 matrix[1] = 0.715f - 0.715f * amount;
610 matrix[2] = 1.f - (matrix[0] + matrix[1]);
611 matrix[3] = matrix[4] = 0;
612 matrix[5] = 0.213f - 0.213f * amount;
613 matrix[6] = 0.715f + 0.285f * amount;
614 matrix[7] = 1.f - (matrix[5] + matrix[6]);
615 matrix[8] = matrix[9] = 0;
616 matrix[10] = 0.213f - 0.213f * amount;
617 matrix[11] = 0.715f - 0.715f * amount;
618 matrix[12] = 1.f - (matrix[10] + matrix[11]);
619 matrix[13] = matrix[14] = 0;
620 matrix[15] = matrix[16] = matrix[17] = matrix[19] = 0;
621 matrix[18] = 1;
622 skia::RefPtr<SkColorFilter> colorFilter(skia::AdoptRef(
623 new SkColorMatrixFilter(matrix)));
624 skia::RefPtr<SkImageFilter> filter =
625 skia::AdoptRef(SkColorFilterImageFilter::Create(colorFilter.get(), NULL));
627 scoped_ptr<RenderPassDrawQuad> render_pass_quad =
628 RenderPassDrawQuad::Create();
629 render_pass_quad->SetNew(pass_shared_state.get(),
630 pass_rect,
631 child_pass_id,
632 false,
634 pass_rect,
635 gfx::RectF(),
636 FilterOperations(),
637 filter,
638 FilterOperations());
640 root_pass->quad_list.push_back(render_pass_quad.PassAs<DrawQuad>());
642 RenderPassList pass_list;
643 pass_list.push_back(child_pass.Pass());
644 pass_list.push_back(root_pass.Pass());
646 // This test has alpha=254 for the software renderer vs. alpha=255 for the gl
647 // renderer so use a fuzzy comparator.
648 EXPECT_TRUE(this->RunPixelTest(
649 &pass_list,
650 PixelTest::NoOffscreenContext,
651 base::FilePath(FILE_PATH_LITERAL("blue_yellow_alpha.png")),
652 FuzzyForSoftwareOnlyPixelComparator<TypeParam>(false)));
655 TYPED_TEST(RendererPixelTest, FastPassColorFilterAlphaTranslation) {
656 gfx::Rect viewport_rect(this->device_viewport_size_);
658 RenderPass::Id root_pass_id(1, 1);
659 scoped_ptr<RenderPass> root_pass =
660 CreateTestRootRenderPass(root_pass_id, viewport_rect);
662 RenderPass::Id child_pass_id(2, 2);
663 gfx::Rect pass_rect(this->device_viewport_size_);
664 gfx::Transform transform_to_root;
665 scoped_ptr<RenderPass> child_pass =
666 CreateTestRenderPass(child_pass_id, pass_rect, transform_to_root);
668 gfx::Transform content_to_target_transform;
669 scoped_ptr<SharedQuadState> shared_state =
670 CreateTestSharedQuadState(content_to_target_transform, viewport_rect);
671 shared_state->opacity = 0.5f;
673 scoped_ptr<SolidColorDrawQuad> blue = SolidColorDrawQuad::Create();
674 blue->SetNew(shared_state.get(),
675 gfx::Rect(0,
677 this->device_viewport_size_.width(),
678 this->device_viewport_size_.height() / 2),
679 SK_ColorBLUE,
680 false);
681 scoped_ptr<SolidColorDrawQuad> yellow = SolidColorDrawQuad::Create();
682 yellow->SetNew(shared_state.get(),
683 gfx::Rect(0,
684 this->device_viewport_size_.height() / 2,
685 this->device_viewport_size_.width(),
686 this->device_viewport_size_.height() / 2),
687 SK_ColorYELLOW,
688 false);
690 scoped_ptr<SharedQuadState> blank_state =
691 CreateTestSharedQuadState(content_to_target_transform, viewport_rect);
693 scoped_ptr<SolidColorDrawQuad> white = SolidColorDrawQuad::Create();
694 white->SetNew(blank_state.get(),
695 viewport_rect,
696 SK_ColorWHITE,
697 false);
699 child_pass->quad_list.push_back(blue.PassAs<DrawQuad>());
700 child_pass->quad_list.push_back(yellow.PassAs<DrawQuad>());
701 child_pass->quad_list.push_back(white.PassAs<DrawQuad>());
703 scoped_ptr<SharedQuadState> pass_shared_state =
704 CreateTestSharedQuadState(gfx::Transform(), pass_rect);
706 SkScalar matrix[20];
707 float amount = 0.5f;
708 matrix[0] = 0.213f + 0.787f * amount;
709 matrix[1] = 0.715f - 0.715f * amount;
710 matrix[2] = 1.f - (matrix[0] + matrix[1]);
711 matrix[3] = 0;
712 matrix[4] = 20.f;
713 matrix[5] = 0.213f - 0.213f * amount;
714 matrix[6] = 0.715f + 0.285f * amount;
715 matrix[7] = 1.f - (matrix[5] + matrix[6]);
716 matrix[8] = 0;
717 matrix[9] = 200.f;
718 matrix[10] = 0.213f - 0.213f * amount;
719 matrix[11] = 0.715f - 0.715f * amount;
720 matrix[12] = 1.f - (matrix[10] + matrix[11]);
721 matrix[13] = 0;
722 matrix[14] = 1.5f;
723 matrix[15] = matrix[16] = matrix[17] = matrix[19] = 0;
724 matrix[18] = 1;
725 skia::RefPtr<SkColorFilter> colorFilter(skia::AdoptRef(
726 new SkColorMatrixFilter(matrix)));
727 skia::RefPtr<SkImageFilter> filter =
728 skia::AdoptRef(SkColorFilterImageFilter::Create(colorFilter.get(), NULL));
730 scoped_ptr<RenderPassDrawQuad> render_pass_quad =
731 RenderPassDrawQuad::Create();
732 render_pass_quad->SetNew(pass_shared_state.get(),
733 pass_rect,
734 child_pass_id,
735 false,
737 pass_rect,
738 gfx::RectF(),
739 FilterOperations(),
740 filter,
741 FilterOperations());
743 root_pass->quad_list.push_back(render_pass_quad.PassAs<DrawQuad>());
744 RenderPassList pass_list;
746 pass_list.push_back(child_pass.Pass());
747 pass_list.push_back(root_pass.Pass());
749 // This test has alpha=254 for the software renderer vs. alpha=255 for the gl
750 // renderer so use a fuzzy comparator.
751 EXPECT_TRUE(this->RunPixelTest(
752 &pass_list,
753 PixelTest::NoOffscreenContext,
754 base::FilePath(FILE_PATH_LITERAL("blue_yellow_alpha_translate.png")),
755 FuzzyForSoftwareOnlyPixelComparator<TypeParam>(false)));
758 TYPED_TEST(RendererPixelTest, EnlargedRenderPassTexture) {
759 gfx::Rect viewport_rect(this->device_viewport_size_);
761 RenderPass::Id root_pass_id(1, 1);
762 scoped_ptr<RenderPass> root_pass =
763 CreateTestRootRenderPass(root_pass_id, viewport_rect);
765 RenderPass::Id child_pass_id(2, 2);
766 gfx::Rect pass_rect(this->device_viewport_size_);
767 gfx::Transform transform_to_root;
768 scoped_ptr<RenderPass> child_pass =
769 CreateTestRenderPass(child_pass_id, pass_rect, transform_to_root);
771 gfx::Transform content_to_target_transform;
772 scoped_ptr<SharedQuadState> shared_state =
773 CreateTestSharedQuadState(content_to_target_transform, viewport_rect);
775 scoped_ptr<SolidColorDrawQuad> blue = SolidColorDrawQuad::Create();
776 blue->SetNew(shared_state.get(),
777 gfx::Rect(0,
779 this->device_viewport_size_.width(),
780 this->device_viewport_size_.height() / 2),
781 SK_ColorBLUE,
782 false);
783 scoped_ptr<SolidColorDrawQuad> yellow = SolidColorDrawQuad::Create();
784 yellow->SetNew(shared_state.get(),
785 gfx::Rect(0,
786 this->device_viewport_size_.height() / 2,
787 this->device_viewport_size_.width(),
788 this->device_viewport_size_.height() / 2),
789 SK_ColorYELLOW,
790 false);
792 child_pass->quad_list.push_back(blue.PassAs<DrawQuad>());
793 child_pass->quad_list.push_back(yellow.PassAs<DrawQuad>());
795 scoped_ptr<SharedQuadState> pass_shared_state =
796 CreateTestSharedQuadState(gfx::Transform(), pass_rect);
797 root_pass->quad_list.push_back(
798 CreateTestRenderPassDrawQuad(pass_shared_state.get(),
799 pass_rect,
800 child_pass_id));
802 RenderPassList pass_list;
803 pass_list.push_back(child_pass.Pass());
804 pass_list.push_back(root_pass.Pass());
806 this->renderer_->SetEnlargePassTextureAmountForTesting(gfx::Vector2d(50, 75));
808 EXPECT_TRUE(this->RunPixelTest(
809 &pass_list,
810 PixelTest::NoOffscreenContext,
811 base::FilePath(FILE_PATH_LITERAL("blue_yellow.png")),
812 ExactPixelComparator(true)));
815 TYPED_TEST(RendererPixelTest, EnlargedRenderPassTextureWithAntiAliasing) {
816 gfx::Rect viewport_rect(this->device_viewport_size_);
818 RenderPass::Id root_pass_id(1, 1);
819 scoped_ptr<RenderPass> root_pass =
820 CreateTestRootRenderPass(root_pass_id, viewport_rect);
822 RenderPass::Id child_pass_id(2, 2);
823 gfx::Rect pass_rect(this->device_viewport_size_);
824 gfx::Transform transform_to_root;
825 scoped_ptr<RenderPass> child_pass =
826 CreateTestRenderPass(child_pass_id, pass_rect, transform_to_root);
828 gfx::Transform content_to_target_transform;
829 scoped_ptr<SharedQuadState> shared_state =
830 CreateTestSharedQuadState(content_to_target_transform, viewport_rect);
832 scoped_ptr<SolidColorDrawQuad> blue = SolidColorDrawQuad::Create();
833 blue->SetNew(shared_state.get(),
834 gfx::Rect(0,
836 this->device_viewport_size_.width(),
837 this->device_viewport_size_.height() / 2),
838 SK_ColorBLUE,
839 false);
840 scoped_ptr<SolidColorDrawQuad> yellow = SolidColorDrawQuad::Create();
841 yellow->SetNew(shared_state.get(),
842 gfx::Rect(0,
843 this->device_viewport_size_.height() / 2,
844 this->device_viewport_size_.width(),
845 this->device_viewport_size_.height() / 2),
846 SK_ColorYELLOW,
847 false);
849 child_pass->quad_list.push_back(blue.PassAs<DrawQuad>());
850 child_pass->quad_list.push_back(yellow.PassAs<DrawQuad>());
852 gfx::Transform aa_transform;
853 aa_transform.Translate(0.5, 0.0);
855 scoped_ptr<SharedQuadState> pass_shared_state =
856 CreateTestSharedQuadState(aa_transform, pass_rect);
857 root_pass->quad_list.push_back(
858 CreateTestRenderPassDrawQuad(pass_shared_state.get(),
859 pass_rect,
860 child_pass_id));
862 scoped_ptr<SharedQuadState> root_shared_state =
863 CreateTestSharedQuadState(gfx::Transform(), viewport_rect);
864 scoped_ptr<SolidColorDrawQuad> background = SolidColorDrawQuad::Create();
865 background->SetNew(root_shared_state.get(),
866 gfx::Rect(this->device_viewport_size_),
867 SK_ColorWHITE,
868 false);
869 root_pass->quad_list.push_back(background.PassAs<DrawQuad>());
871 RenderPassList pass_list;
872 pass_list.push_back(child_pass.Pass());
873 pass_list.push_back(root_pass.Pass());
875 this->renderer_->SetEnlargePassTextureAmountForTesting(gfx::Vector2d(50, 75));
877 EXPECT_TRUE(this->RunPixelTest(
878 &pass_list,
879 PixelTest::NoOffscreenContext,
880 base::FilePath(FILE_PATH_LITERAL("blue_yellow_anti_aliasing.png")),
881 FuzzyPixelOffByOneComparator(true)));
884 template <typename RendererType>
885 class RendererPixelTestWithBackgroundFilter
886 : public RendererPixelTest<RendererType> {
887 protected:
888 void SetUpRenderPassList() {
889 gfx::Rect device_viewport_rect(this->device_viewport_size_);
891 RenderPass::Id root_id(1, 1);
892 scoped_ptr<RenderPass> root_pass =
893 CreateTestRootRenderPass(root_id, device_viewport_rect);
894 root_pass->has_transparent_background = false;
896 gfx::Transform identity_content_to_target_transform;
898 RenderPass::Id filter_pass_id(2, 1);
899 gfx::Transform transform_to_root;
900 scoped_ptr<RenderPass> filter_pass =
901 CreateTestRenderPass(filter_pass_id,
902 filter_pass_content_rect_,
903 transform_to_root);
905 // A non-visible quad in the filtering render pass.
907 scoped_ptr<SharedQuadState> shared_state =
908 CreateTestSharedQuadState(identity_content_to_target_transform,
909 filter_pass_content_rect_);
910 scoped_ptr<SolidColorDrawQuad> color_quad = SolidColorDrawQuad::Create();
911 color_quad->SetNew(shared_state.get(),
912 filter_pass_content_rect_,
913 SK_ColorTRANSPARENT,
914 false);
915 filter_pass->quad_list.push_back(color_quad.PassAs<DrawQuad>());
916 filter_pass->shared_quad_state_list.push_back(shared_state.Pass());
920 scoped_ptr<SharedQuadState> shared_state =
921 CreateTestSharedQuadState(filter_pass_to_target_transform_,
922 filter_pass_content_rect_);
923 scoped_ptr<RenderPassDrawQuad> filter_pass_quad =
924 RenderPassDrawQuad::Create();
925 filter_pass_quad->SetNew(
926 shared_state.get(),
927 filter_pass_content_rect_,
928 filter_pass_id,
929 false, // is_replica
930 0, // mask_resource_id
931 filter_pass_content_rect_, // contents_changed_since_last_frame
932 gfx::RectF(), // mask_uv_rect
933 FilterOperations(), // filters
934 skia::RefPtr<SkImageFilter>(), // filter
935 this->background_filters_);
936 root_pass->quad_list.push_back(filter_pass_quad.PassAs<DrawQuad>());
937 root_pass->shared_quad_state_list.push_back(shared_state.Pass());
940 const int kColumnWidth = device_viewport_rect.width() / 3;
942 gfx::Rect left_rect = gfx::Rect(0, 0, kColumnWidth, 20);
943 for (int i = 0; left_rect.y() < device_viewport_rect.height(); ++i) {
944 scoped_ptr<SharedQuadState> shared_state =
945 CreateTestSharedQuadState(identity_content_to_target_transform,
946 left_rect);
947 scoped_ptr<SolidColorDrawQuad> color_quad = SolidColorDrawQuad::Create();
948 color_quad->SetNew(shared_state.get(), left_rect, SK_ColorGREEN, false);
949 root_pass->quad_list.push_back(color_quad.PassAs<DrawQuad>());
950 root_pass->shared_quad_state_list.push_back(shared_state.Pass());
951 left_rect += gfx::Vector2d(0, left_rect.height() + 1);
954 gfx::Rect middle_rect = gfx::Rect(kColumnWidth+1, 0, kColumnWidth, 20);
955 for (int i = 0; middle_rect.y() < device_viewport_rect.height(); ++i) {
956 scoped_ptr<SharedQuadState> shared_state =
957 CreateTestSharedQuadState(identity_content_to_target_transform,
958 middle_rect);
959 scoped_ptr<SolidColorDrawQuad> color_quad = SolidColorDrawQuad::Create();
960 color_quad->SetNew(shared_state.get(), middle_rect, SK_ColorRED, false);
961 root_pass->quad_list.push_back(color_quad.PassAs<DrawQuad>());
962 root_pass->shared_quad_state_list.push_back(shared_state.Pass());
963 middle_rect += gfx::Vector2d(0, middle_rect.height() + 1);
966 gfx::Rect right_rect = gfx::Rect((kColumnWidth+1)*2, 0, kColumnWidth, 20);
967 for (int i = 0; right_rect.y() < device_viewport_rect.height(); ++i) {
968 scoped_ptr<SharedQuadState> shared_state =
969 CreateTestSharedQuadState(identity_content_to_target_transform,
970 right_rect);
971 scoped_ptr<SolidColorDrawQuad> color_quad = SolidColorDrawQuad::Create();
972 color_quad->SetNew(shared_state.get(), right_rect, SK_ColorBLUE, false);
973 root_pass->quad_list.push_back(color_quad.PassAs<DrawQuad>());
974 root_pass->shared_quad_state_list.push_back(shared_state.Pass());
975 right_rect += gfx::Vector2d(0, right_rect.height() + 1);
978 scoped_ptr<SharedQuadState> shared_state =
979 CreateTestSharedQuadState(identity_content_to_target_transform,
980 device_viewport_rect);
981 scoped_ptr<SolidColorDrawQuad> background_quad =
982 SolidColorDrawQuad::Create();
983 background_quad->SetNew(shared_state.get(),
984 device_viewport_rect,
985 SK_ColorWHITE,
986 false);
987 root_pass->quad_list.push_back(background_quad.PassAs<DrawQuad>());
988 root_pass->shared_quad_state_list.push_back(shared_state.Pass());
990 pass_list_.push_back(filter_pass.Pass());
991 pass_list_.push_back(root_pass.Pass());
994 RenderPassList pass_list_;
995 FilterOperations background_filters_;
996 gfx::Transform filter_pass_to_target_transform_;
997 gfx::Rect filter_pass_content_rect_;
1000 typedef ::testing::Types<GLRenderer, SoftwareRenderer>
1001 BackgroundFilterRendererTypes;
1002 TYPED_TEST_CASE(RendererPixelTestWithBackgroundFilter,
1003 BackgroundFilterRendererTypes);
1005 typedef RendererPixelTestWithBackgroundFilter<GLRenderer>
1006 GLRendererPixelTestWithBackgroundFilter;
1008 // TODO(skaslev): The software renderer does not support filters yet.
1009 TEST_F(GLRendererPixelTestWithBackgroundFilter, InvertFilter) {
1010 this->background_filters_.Append(
1011 FilterOperation::CreateInvertFilter(1.f));
1013 this->filter_pass_content_rect_ = gfx::Rect(this->device_viewport_size_);
1014 this->filter_pass_content_rect_.Inset(12, 14, 16, 18);
1016 this->SetUpRenderPassList();
1017 EXPECT_TRUE(this->RunPixelTest(
1018 &this->pass_list_,
1019 PixelTest::WithOffscreenContext,
1020 base::FilePath(FILE_PATH_LITERAL("background_filter.png")),
1021 ExactPixelComparator(true)));
1024 class ExternalStencilPixelTest : public GLRendererPixelTest {
1025 protected:
1026 void ClearBackgroundToGreen() {
1027 WebKit::WebGraphicsContext3D* context3d =
1028 output_surface_->context_provider()->Context3d();
1029 output_surface_->EnsureBackbuffer();
1030 output_surface_->Reshape(device_viewport_size_, 1);
1031 context3d->clearColor(0.f, 1.f, 0.f, 1.f);
1032 context3d->clear(GL_COLOR_BUFFER_BIT);
1035 void PopulateStencilBuffer() {
1036 // Set two quadrants of the stencil buffer to 1.
1037 WebKit::WebGraphicsContext3D* context3d =
1038 output_surface_->context_provider()->Context3d();
1039 ASSERT_TRUE(context3d->getContextAttributes().stencil);
1040 output_surface_->EnsureBackbuffer();
1041 output_surface_->Reshape(device_viewport_size_, 1);
1042 context3d->clearStencil(0);
1043 context3d->clear(GL_STENCIL_BUFFER_BIT);
1044 context3d->enable(GL_SCISSOR_TEST);
1045 context3d->clearStencil(1);
1046 context3d->scissor(0,
1048 device_viewport_size_.width() / 2,
1049 device_viewport_size_.height() / 2);
1050 context3d->clear(GL_STENCIL_BUFFER_BIT);
1051 context3d->scissor(device_viewport_size_.width() / 2,
1052 device_viewport_size_.height() / 2,
1053 device_viewport_size_.width(),
1054 device_viewport_size_.height());
1055 context3d->clear(GL_STENCIL_BUFFER_BIT);
1059 TEST_F(ExternalStencilPixelTest, StencilTestEnabled) {
1060 ClearBackgroundToGreen();
1061 PopulateStencilBuffer();
1062 this->EnableExternalStencilTest();
1064 // Draw a blue quad that covers the entire device viewport. It should be
1065 // clipped to the bottom left and top right corners by the external stencil.
1066 gfx::Rect rect(this->device_viewport_size_);
1067 RenderPass::Id id(1, 1);
1068 scoped_ptr<RenderPass> pass = CreateTestRootRenderPass(id, rect);
1069 scoped_ptr<SharedQuadState> blue_shared_state =
1070 CreateTestSharedQuadState(gfx::Transform(), rect);
1071 scoped_ptr<SolidColorDrawQuad> blue = SolidColorDrawQuad::Create();
1072 blue->SetNew(blue_shared_state.get(), rect, SK_ColorBLUE, false);
1073 pass->quad_list.push_back(blue.PassAs<DrawQuad>());
1074 pass->has_transparent_background = false;
1075 RenderPassList pass_list;
1076 pass_list.push_back(pass.Pass());
1078 EXPECT_TRUE(this->RunPixelTest(
1079 &pass_list,
1080 PixelTest::NoOffscreenContext,
1081 base::FilePath(FILE_PATH_LITERAL("four_blue_green_checkers.png")),
1082 ExactPixelComparator(true)));
1085 TEST_F(ExternalStencilPixelTest, StencilTestDisabled) {
1086 PopulateStencilBuffer();
1088 // Draw a green quad that covers the entire device viewport. The stencil
1089 // buffer should be ignored.
1090 gfx::Rect rect(this->device_viewport_size_);
1091 RenderPass::Id id(1, 1);
1092 scoped_ptr<RenderPass> pass = CreateTestRootRenderPass(id, rect);
1093 scoped_ptr<SharedQuadState> green_shared_state =
1094 CreateTestSharedQuadState(gfx::Transform(), rect);
1095 scoped_ptr<SolidColorDrawQuad> green = SolidColorDrawQuad::Create();
1096 green->SetNew(green_shared_state.get(), rect, SK_ColorGREEN, false);
1097 pass->quad_list.push_back(green.PassAs<DrawQuad>());
1098 RenderPassList pass_list;
1099 pass_list.push_back(pass.Pass());
1101 EXPECT_TRUE(this->RunPixelTest(
1102 &pass_list,
1103 PixelTest::NoOffscreenContext,
1104 base::FilePath(FILE_PATH_LITERAL("green.png")),
1105 ExactPixelComparator(true)));
1108 TEST_F(ExternalStencilPixelTest, RenderSurfacesIgnoreStencil) {
1109 // The stencil test should apply only to the final render pass.
1110 ClearBackgroundToGreen();
1111 PopulateStencilBuffer();
1112 this->EnableExternalStencilTest();
1114 gfx::Rect viewport_rect(this->device_viewport_size_);
1116 RenderPass::Id root_pass_id(1, 1);
1117 scoped_ptr<RenderPass> root_pass =
1118 CreateTestRootRenderPass(root_pass_id, viewport_rect);
1119 root_pass->has_transparent_background = false;
1121 RenderPass::Id child_pass_id(2, 2);
1122 gfx::Rect pass_rect(this->device_viewport_size_);
1123 gfx::Transform transform_to_root;
1124 scoped_ptr<RenderPass> child_pass =
1125 CreateTestRenderPass(child_pass_id, pass_rect, transform_to_root);
1127 gfx::Transform content_to_target_transform;
1128 scoped_ptr<SharedQuadState> shared_state =
1129 CreateTestSharedQuadState(content_to_target_transform, viewport_rect);
1131 scoped_ptr<SolidColorDrawQuad> blue = SolidColorDrawQuad::Create();
1132 blue->SetNew(shared_state.get(),
1133 gfx::Rect(0,
1135 this->device_viewport_size_.width(),
1136 this->device_viewport_size_.height()),
1137 SK_ColorBLUE,
1138 false);
1139 child_pass->quad_list.push_back(blue.PassAs<DrawQuad>());
1141 scoped_ptr<SharedQuadState> pass_shared_state =
1142 CreateTestSharedQuadState(gfx::Transform(), pass_rect);
1143 root_pass->quad_list.push_back(
1144 CreateTestRenderPassDrawQuad(pass_shared_state.get(),
1145 pass_rect,
1146 child_pass_id));
1147 RenderPassList pass_list;
1148 pass_list.push_back(child_pass.Pass());
1149 pass_list.push_back(root_pass.Pass());
1151 EXPECT_TRUE(this->RunPixelTest(
1152 &pass_list,
1153 PixelTest::NoOffscreenContext,
1154 base::FilePath(FILE_PATH_LITERAL("four_blue_green_checkers.png")),
1155 ExactPixelComparator(true)));
1158 TEST_F(ExternalStencilPixelTest, DeviceClip) {
1159 ClearBackgroundToGreen();
1160 gfx::Rect clip_rect(gfx::Point(150, 150), gfx::Size(50, 50));
1161 this->ForceDeviceClip(clip_rect);
1163 // Draw a blue quad that covers the entire device viewport. It should be
1164 // clipped to the bottom right corner by the device clip.
1165 gfx::Rect rect(this->device_viewport_size_);
1166 RenderPass::Id id(1, 1);
1167 scoped_ptr<RenderPass> pass = CreateTestRootRenderPass(id, rect);
1168 scoped_ptr<SharedQuadState> blue_shared_state =
1169 CreateTestSharedQuadState(gfx::Transform(), rect);
1170 scoped_ptr<SolidColorDrawQuad> blue = SolidColorDrawQuad::Create();
1171 blue->SetNew(blue_shared_state.get(), rect, SK_ColorBLUE, false);
1172 pass->quad_list.push_back(blue.PassAs<DrawQuad>());
1173 RenderPassList pass_list;
1174 pass_list.push_back(pass.Pass());
1176 EXPECT_TRUE(this->RunPixelTest(
1177 &pass_list,
1178 PixelTest::NoOffscreenContext,
1179 base::FilePath(FILE_PATH_LITERAL("green_with_blue_corner.png")),
1180 ExactPixelComparator(true)));
1183 // Software renderer does not support anti-aliased edges.
1184 TEST_F(GLRendererPixelTest, AntiAliasing) {
1185 gfx::Rect rect(this->device_viewport_size_);
1187 RenderPass::Id id(1, 1);
1188 scoped_ptr<RenderPass> pass = CreateTestRootRenderPass(id, rect);
1190 gfx::Transform red_content_to_target_transform;
1191 red_content_to_target_transform.Rotate(10);
1192 scoped_ptr<SharedQuadState> red_shared_state =
1193 CreateTestSharedQuadState(red_content_to_target_transform, rect);
1195 scoped_ptr<SolidColorDrawQuad> red = SolidColorDrawQuad::Create();
1196 red->SetNew(red_shared_state.get(), rect, SK_ColorRED, false);
1198 pass->quad_list.push_back(red.PassAs<DrawQuad>());
1200 gfx::Transform yellow_content_to_target_transform;
1201 yellow_content_to_target_transform.Rotate(5);
1202 scoped_ptr<SharedQuadState> yellow_shared_state =
1203 CreateTestSharedQuadState(yellow_content_to_target_transform, rect);
1205 scoped_ptr<SolidColorDrawQuad> yellow = SolidColorDrawQuad::Create();
1206 yellow->SetNew(yellow_shared_state.get(), rect, SK_ColorYELLOW, false);
1208 pass->quad_list.push_back(yellow.PassAs<DrawQuad>());
1210 gfx::Transform blue_content_to_target_transform;
1211 scoped_ptr<SharedQuadState> blue_shared_state =
1212 CreateTestSharedQuadState(blue_content_to_target_transform, rect);
1214 scoped_ptr<SolidColorDrawQuad> blue = SolidColorDrawQuad::Create();
1215 blue->SetNew(blue_shared_state.get(), rect, SK_ColorBLUE, false);
1217 pass->quad_list.push_back(blue.PassAs<DrawQuad>());
1219 RenderPassList pass_list;
1220 pass_list.push_back(pass.Pass());
1222 EXPECT_TRUE(this->RunPixelTest(
1223 &pass_list,
1224 PixelTest::NoOffscreenContext,
1225 base::FilePath(FILE_PATH_LITERAL("anti_aliasing.png")),
1226 FuzzyPixelOffByOneComparator(true)));
1229 // This test tests that anti-aliasing works for axis aligned quads.
1230 // Anti-aliasing is only supported in the gl renderer.
1231 TEST_F(GLRendererPixelTest, AxisAligned) {
1232 gfx::Rect rect(this->device_viewport_size_);
1234 RenderPass::Id id(1, 1);
1235 gfx::Transform transform_to_root;
1236 scoped_ptr<RenderPass> pass =
1237 CreateTestRenderPass(id, rect, transform_to_root);
1239 gfx::Transform red_content_to_target_transform;
1240 red_content_to_target_transform.Translate(50, 50);
1241 red_content_to_target_transform.Scale(
1242 0.5f + 1.0f / (rect.width() * 2.0f),
1243 0.5f + 1.0f / (rect.height() * 2.0f));
1244 scoped_ptr<SharedQuadState> red_shared_state =
1245 CreateTestSharedQuadState(red_content_to_target_transform, rect);
1247 scoped_ptr<SolidColorDrawQuad> red = SolidColorDrawQuad::Create();
1248 red->SetNew(red_shared_state.get(), rect, SK_ColorRED, false);
1250 pass->quad_list.push_back(red.PassAs<DrawQuad>());
1252 gfx::Transform yellow_content_to_target_transform;
1253 yellow_content_to_target_transform.Translate(25.5f, 25.5f);
1254 yellow_content_to_target_transform.Scale(0.5f, 0.5f);
1255 scoped_ptr<SharedQuadState> yellow_shared_state =
1256 CreateTestSharedQuadState(yellow_content_to_target_transform, rect);
1258 scoped_ptr<SolidColorDrawQuad> yellow = SolidColorDrawQuad::Create();
1259 yellow->SetNew(yellow_shared_state.get(), rect, SK_ColorYELLOW, false);
1261 pass->quad_list.push_back(yellow.PassAs<DrawQuad>());
1263 gfx::Transform blue_content_to_target_transform;
1264 scoped_ptr<SharedQuadState> blue_shared_state =
1265 CreateTestSharedQuadState(blue_content_to_target_transform, rect);
1267 scoped_ptr<SolidColorDrawQuad> blue = SolidColorDrawQuad::Create();
1268 blue->SetNew(blue_shared_state.get(), rect, SK_ColorBLUE, false);
1270 pass->quad_list.push_back(blue.PassAs<DrawQuad>());
1272 RenderPassList pass_list;
1273 pass_list.push_back(pass.Pass());
1275 EXPECT_TRUE(this->RunPixelTest(
1276 &pass_list,
1277 PixelTest::NoOffscreenContext,
1278 base::FilePath(FILE_PATH_LITERAL("axis_aligned.png")),
1279 ExactPixelComparator(true)));
1282 // This test tests that forcing anti-aliasing off works as expected.
1283 // Anti-aliasing is only supported in the gl renderer.
1284 TEST_F(GLRendererPixelTest, ForceAntiAliasingOff) {
1285 gfx::Rect rect(this->device_viewport_size_);
1287 RenderPass::Id id(1, 1);
1288 gfx::Transform transform_to_root;
1289 scoped_ptr<RenderPass> pass =
1290 CreateTestRenderPass(id, rect, transform_to_root);
1292 gfx::Transform hole_content_to_target_transform;
1293 hole_content_to_target_transform.Translate(50, 50);
1294 hole_content_to_target_transform.Scale(
1295 0.5f + 1.0f / (rect.width() * 2.0f),
1296 0.5f + 1.0f / (rect.height() * 2.0f));
1297 scoped_ptr<SharedQuadState> hole_shared_state =
1298 CreateTestSharedQuadState(hole_content_to_target_transform, rect);
1300 scoped_ptr<SolidColorDrawQuad> hole = SolidColorDrawQuad::Create();
1301 hole->SetAll(hole_shared_state.get(), rect, rect, rect, false,
1302 SK_ColorTRANSPARENT, true);
1303 pass->quad_list.push_back(hole.PassAs<DrawQuad>());
1305 gfx::Transform green_content_to_target_transform;
1306 scoped_ptr<SharedQuadState> green_shared_state =
1307 CreateTestSharedQuadState(green_content_to_target_transform, rect);
1309 scoped_ptr<SolidColorDrawQuad> green = SolidColorDrawQuad::Create();
1310 green->SetNew(green_shared_state.get(), rect, SK_ColorGREEN, false);
1312 pass->quad_list.push_back(green.PassAs<DrawQuad>());
1314 RenderPassList pass_list;
1315 pass_list.push_back(pass.Pass());
1317 EXPECT_TRUE(this->RunPixelTest(
1318 &pass_list,
1319 PixelTest::NoOffscreenContext,
1320 base::FilePath(FILE_PATH_LITERAL("force_anti_aliasing_off.png")),
1321 ExactPixelComparator(false)));
1324 TEST_F(GLRendererPixelTest, AntiAliasingPerspective) {
1325 gfx::Rect rect(this->device_viewport_size_);
1327 scoped_ptr<RenderPass> pass =
1328 CreateTestRootRenderPass(RenderPass::Id(1, 1), rect);
1330 gfx::Rect red_rect(0, 0, 180, 500);
1331 gfx::Transform red_content_to_target_transform(
1332 1.0, 2.4520, 10.6206, 19.0,
1333 0.0, 0.3528, 5.9737, 9.5,
1334 0.0, -0.2250, -0.9744, 0.0,
1335 0.0, 0.0225, 0.0974, 1.0);
1336 scoped_ptr<SharedQuadState> red_shared_state =
1337 CreateTestSharedQuadState(red_content_to_target_transform, red_rect);
1338 scoped_ptr<SolidColorDrawQuad> red = SolidColorDrawQuad::Create();
1339 red->SetNew(red_shared_state.get(), red_rect, SK_ColorRED, false);
1340 pass->quad_list.push_back(red.PassAs<DrawQuad>());
1342 gfx::Rect green_rect(19, 7, 180, 10);
1343 scoped_ptr<SharedQuadState> green_shared_state =
1344 CreateTestSharedQuadState(gfx::Transform(), green_rect);
1345 scoped_ptr<SolidColorDrawQuad> green = SolidColorDrawQuad::Create();
1346 green->SetNew(green_shared_state.get(), green_rect, SK_ColorGREEN, false);
1347 pass->quad_list.push_back(green.PassAs<DrawQuad>());
1349 scoped_ptr<SharedQuadState> blue_shared_state =
1350 CreateTestSharedQuadState(gfx::Transform(), rect);
1351 scoped_ptr<SolidColorDrawQuad> blue = SolidColorDrawQuad::Create();
1352 blue->SetNew(blue_shared_state.get(), rect, SK_ColorBLUE, false);
1353 pass->quad_list.push_back(blue.PassAs<DrawQuad>());
1355 RenderPassList pass_list;
1356 pass_list.push_back(pass.Pass());
1358 EXPECT_TRUE(this->RunPixelTest(
1359 &pass_list,
1360 PixelTest::NoOffscreenContext,
1361 base::FilePath(FILE_PATH_LITERAL("anti_aliasing_perspective.png")),
1362 FuzzyPixelOffByOneComparator(true)));
1365 TYPED_TEST(RendererPixelTestWithSkiaGPUBackend, PictureDrawQuadIdentityScale) {
1366 gfx::Size pile_tile_size(1000, 1000);
1367 gfx::Rect viewport(this->device_viewport_size_);
1368 bool use_skia_gpu_backend = this->UseSkiaGPUBackend();
1369 // TODO(enne): the renderer should figure this out on its own.
1370 ResourceFormat texture_format = RGBA_8888;
1372 RenderPass::Id id(1, 1);
1373 gfx::Transform transform_to_root;
1374 scoped_ptr<RenderPass> pass =
1375 CreateTestRenderPass(id, viewport, transform_to_root);
1377 // One clipped blue quad in the lower right corner. Outside the clip
1378 // is red, which should not appear.
1379 gfx::Rect blue_rect(gfx::Size(100, 100));
1380 gfx::Rect blue_clip_rect(gfx::Point(50, 50), gfx::Size(50, 50));
1381 scoped_refptr<FakePicturePileImpl> blue_pile =
1382 FakePicturePileImpl::CreateFilledPile(pile_tile_size, blue_rect.size());
1383 SkPaint red_paint;
1384 red_paint.setColor(SK_ColorRED);
1385 blue_pile->add_draw_rect_with_paint(blue_rect, red_paint);
1386 SkPaint blue_paint;
1387 blue_paint.setColor(SK_ColorBLUE);
1388 blue_pile->add_draw_rect_with_paint(blue_clip_rect, blue_paint);
1389 blue_pile->RerecordPile();
1391 gfx::Transform blue_content_to_target_transform;
1392 gfx::Vector2d offset(viewport.bottom_right() - blue_rect.bottom_right());
1393 blue_content_to_target_transform.Translate(offset.x(), offset.y());
1394 gfx::RectF blue_scissor_rect = blue_clip_rect;
1395 blue_content_to_target_transform.TransformRect(&blue_scissor_rect);
1396 scoped_ptr<SharedQuadState> blue_shared_state =
1397 CreateTestSharedQuadStateClipped(blue_content_to_target_transform,
1398 blue_rect,
1399 gfx::ToEnclosingRect(blue_scissor_rect));
1401 scoped_ptr<PictureDrawQuad> blue_quad = PictureDrawQuad::Create();
1403 blue_quad->SetNew(blue_shared_state.get(),
1404 viewport, // Intentionally bigger than clip.
1405 gfx::Rect(),
1406 viewport,
1407 viewport.size(),
1408 texture_format,
1409 viewport,
1410 1.f,
1411 use_skia_gpu_backend,
1412 blue_pile);
1413 pass->quad_list.push_back(blue_quad.PassAs<DrawQuad>());
1415 // One viewport-filling green quad.
1416 scoped_refptr<FakePicturePileImpl> green_pile =
1417 FakePicturePileImpl::CreateFilledPile(pile_tile_size, viewport.size());
1418 SkPaint green_paint;
1419 green_paint.setColor(SK_ColorGREEN);
1420 green_pile->add_draw_rect_with_paint(viewport, green_paint);
1421 green_pile->RerecordPile();
1423 gfx::Transform green_content_to_target_transform;
1424 scoped_ptr<SharedQuadState> green_shared_state =
1425 CreateTestSharedQuadState(green_content_to_target_transform, viewport);
1427 scoped_ptr<PictureDrawQuad> green_quad = PictureDrawQuad::Create();
1428 green_quad->SetNew(green_shared_state.get(),
1429 viewport,
1430 gfx::Rect(),
1431 gfx::RectF(0.f, 0.f, 1.f, 1.f),
1432 viewport.size(),
1433 texture_format,
1434 viewport,
1435 1.f,
1436 use_skia_gpu_backend,
1437 green_pile);
1438 pass->quad_list.push_back(green_quad.PassAs<DrawQuad>());
1440 RenderPassList pass_list;
1441 pass_list.push_back(pass.Pass());
1443 EXPECT_TRUE(this->RunPixelTest(
1444 &pass_list,
1445 PixelTest::NoOffscreenContext,
1446 base::FilePath(FILE_PATH_LITERAL("green_with_blue_corner.png")),
1447 ExactPixelComparator(true)));
1450 // Not WithSkiaGPUBackend since that path currently requires tiles for opacity.
1451 TYPED_TEST(RendererPixelTest, PictureDrawQuadOpacity) {
1452 gfx::Size pile_tile_size(1000, 1000);
1453 gfx::Rect viewport(this->device_viewport_size_);
1454 bool use_skia_gpu_backend = this->UseSkiaGPUBackend();
1455 ResourceFormat texture_format = RGBA_8888;
1457 RenderPass::Id id(1, 1);
1458 gfx::Transform transform_to_root;
1459 scoped_ptr<RenderPass> pass =
1460 CreateTestRenderPass(id, viewport, transform_to_root);
1462 // One viewport-filling 0.5-opacity green quad.
1463 scoped_refptr<FakePicturePileImpl> green_pile =
1464 FakePicturePileImpl::CreateFilledPile(pile_tile_size, viewport.size());
1465 SkPaint green_paint;
1466 green_paint.setColor(SK_ColorGREEN);
1467 green_pile->add_draw_rect_with_paint(viewport, green_paint);
1468 green_pile->RerecordPile();
1470 gfx::Transform green_content_to_target_transform;
1471 scoped_ptr<SharedQuadState> green_shared_state =
1472 CreateTestSharedQuadState(green_content_to_target_transform, viewport);
1473 green_shared_state->opacity = 0.5f;
1475 scoped_ptr<PictureDrawQuad> green_quad = PictureDrawQuad::Create();
1476 green_quad->SetNew(green_shared_state.get(),
1477 viewport,
1478 gfx::Rect(),
1479 gfx::RectF(0, 0, 1, 1),
1480 viewport.size(),
1481 texture_format,
1482 viewport,
1483 1.f,
1484 use_skia_gpu_backend,
1485 green_pile);
1486 pass->quad_list.push_back(green_quad.PassAs<DrawQuad>());
1488 // One viewport-filling white quad.
1489 scoped_refptr<FakePicturePileImpl> white_pile =
1490 FakePicturePileImpl::CreateFilledPile(pile_tile_size, viewport.size());
1491 SkPaint white_paint;
1492 white_paint.setColor(SK_ColorWHITE);
1493 white_pile->add_draw_rect_with_paint(viewport, white_paint);
1494 white_pile->RerecordPile();
1496 gfx::Transform white_content_to_target_transform;
1497 scoped_ptr<SharedQuadState> white_shared_state =
1498 CreateTestSharedQuadState(white_content_to_target_transform, viewport);
1500 scoped_ptr<PictureDrawQuad> white_quad = PictureDrawQuad::Create();
1501 white_quad->SetNew(white_shared_state.get(),
1502 viewport,
1503 gfx::Rect(),
1504 gfx::RectF(0, 0, 1, 1),
1505 viewport.size(),
1506 texture_format,
1507 viewport,
1508 1.f,
1509 use_skia_gpu_backend,
1510 white_pile);
1511 pass->quad_list.push_back(white_quad.PassAs<DrawQuad>());
1513 RenderPassList pass_list;
1514 pass_list.push_back(pass.Pass());
1516 EXPECT_TRUE(this->RunPixelTest(
1517 &pass_list,
1518 PixelTest::NoOffscreenContext,
1519 base::FilePath(FILE_PATH_LITERAL("green_alpha.png")),
1520 FuzzyPixelOffByOneComparator(true)));
1523 TYPED_TEST(RendererPixelTestWithSkiaGPUBackend,
1524 PictureDrawQuadNonIdentityScale) {
1525 gfx::Size pile_tile_size(1000, 1000);
1526 gfx::Rect viewport(this->device_viewport_size_);
1527 bool use_skia_gpu_backend = this->UseSkiaGPUBackend();
1528 // TODO(enne): the renderer should figure this out on its own.
1529 ResourceFormat texture_format = RGBA_8888;
1531 RenderPass::Id id(1, 1);
1532 gfx::Transform transform_to_root;
1533 scoped_ptr<RenderPass> pass =
1534 CreateTestRenderPass(id, viewport, transform_to_root);
1536 // As scaling up the blue checkerboards will cause sampling on the GPU,
1537 // a few extra "cleanup rects" need to be added to clobber the blending
1538 // to make the output image more clean. This will also test subrects
1539 // of the layer.
1540 gfx::Transform green_content_to_target_transform;
1541 gfx::Rect green_rect1(gfx::Point(80, 0), gfx::Size(20, 100));
1542 gfx::Rect green_rect2(gfx::Point(0, 80), gfx::Size(100, 20));
1543 scoped_refptr<FakePicturePileImpl> green_pile =
1544 FakePicturePileImpl::CreateFilledPile(pile_tile_size, viewport.size());
1545 SkPaint red_paint;
1546 red_paint.setColor(SK_ColorRED);
1547 green_pile->add_draw_rect_with_paint(viewport, red_paint);
1548 SkPaint green_paint;
1549 green_paint.setColor(SK_ColorGREEN);
1550 green_pile->add_draw_rect_with_paint(green_rect1, green_paint);
1551 green_pile->add_draw_rect_with_paint(green_rect2, green_paint);
1552 green_pile->RerecordPile();
1554 scoped_ptr<SharedQuadState> top_right_green_shared_quad_state =
1555 CreateTestSharedQuadState(green_content_to_target_transform, viewport);
1557 scoped_ptr<PictureDrawQuad> green_quad1 = PictureDrawQuad::Create();
1558 green_quad1->SetNew(top_right_green_shared_quad_state.get(),
1559 green_rect1,
1560 gfx::Rect(),
1561 gfx::RectF(green_rect1.size()),
1562 green_rect1.size(),
1563 texture_format,
1564 green_rect1,
1565 1.f,
1566 use_skia_gpu_backend,
1567 green_pile);
1568 pass->quad_list.push_back(green_quad1.PassAs<DrawQuad>());
1570 scoped_ptr<PictureDrawQuad> green_quad2 = PictureDrawQuad::Create();
1571 green_quad2->SetNew(top_right_green_shared_quad_state.get(),
1572 green_rect2,
1573 gfx::Rect(),
1574 gfx::RectF(green_rect2.size()),
1575 green_rect2.size(),
1576 texture_format,
1577 green_rect2,
1578 1.f,
1579 use_skia_gpu_backend,
1580 green_pile);
1581 pass->quad_list.push_back(green_quad2.PassAs<DrawQuad>());
1583 // Add a green clipped checkerboard in the bottom right to help test
1584 // interleaving picture quad content and solid color content.
1585 gfx::Rect bottom_right_rect(
1586 gfx::Point(viewport.width() / 2, viewport.height() / 2),
1587 gfx::Size(viewport.width() / 2, viewport.height() / 2));
1588 scoped_ptr<SharedQuadState> bottom_right_green_shared_state =
1589 CreateTestSharedQuadStateClipped(
1590 green_content_to_target_transform, viewport, bottom_right_rect);
1591 scoped_ptr<SolidColorDrawQuad> bottom_right_color_quad =
1592 SolidColorDrawQuad::Create();
1593 bottom_right_color_quad->SetNew(
1594 bottom_right_green_shared_state.get(), viewport, SK_ColorGREEN, false);
1595 pass->quad_list.push_back(bottom_right_color_quad.PassAs<DrawQuad>());
1597 // Add two blue checkerboards taking up the bottom left and top right,
1598 // but use content scales as content rects to make this happen.
1599 // The content is at a 4x content scale.
1600 gfx::Rect layer_rect(gfx::Size(20, 30));
1601 float contents_scale = 4.f;
1602 // Two rects that touch at their corners, arbitrarily placed in the layer.
1603 gfx::RectF blue_layer_rect1(gfx::PointF(5.5f, 9.0f), gfx::SizeF(2.5f, 2.5f));
1604 gfx::RectF blue_layer_rect2(gfx::PointF(8.0f, 6.5f), gfx::SizeF(2.5f, 2.5f));
1605 gfx::RectF union_layer_rect = blue_layer_rect1;
1606 union_layer_rect.Union(blue_layer_rect2);
1608 // Because scaling up will cause sampling outside the rects, add one extra
1609 // pixel of buffer at the final content scale.
1610 float inset = -1.f / contents_scale;
1611 blue_layer_rect1.Inset(inset, inset, inset, inset);
1612 blue_layer_rect2.Inset(inset, inset, inset, inset);
1614 scoped_refptr<FakePicturePileImpl> pile =
1615 FakePicturePileImpl::CreateFilledPile(pile_tile_size, layer_rect.size());
1617 Region outside(layer_rect);
1618 outside.Subtract(gfx::ToEnclosingRect(union_layer_rect));
1619 for (Region::Iterator iter(outside); iter.has_rect(); iter.next()) {
1620 pile->add_draw_rect_with_paint(iter.rect(), red_paint);
1623 SkPaint blue_paint;
1624 blue_paint.setColor(SK_ColorBLUE);
1625 pile->add_draw_rect_with_paint(blue_layer_rect1, blue_paint);
1626 pile->add_draw_rect_with_paint(blue_layer_rect2, blue_paint);
1627 pile->RerecordPile();
1629 gfx::Rect content_rect(
1630 gfx::ScaleToEnclosingRect(layer_rect, contents_scale));
1631 gfx::Rect content_union_rect(
1632 gfx::ToEnclosingRect(gfx::ScaleRect(union_layer_rect, contents_scale)));
1634 // At a scale of 4x the rectangles with a width of 2.5 will take up 10 pixels,
1635 // so scale an additional 10x to make them 100x100.
1636 gfx::Transform content_to_target_transform;
1637 content_to_target_transform.Scale(10.0, 10.0);
1638 gfx::Rect quad_content_rect(gfx::Size(20, 20));
1639 scoped_ptr<SharedQuadState> blue_shared_state =
1640 CreateTestSharedQuadState(content_to_target_transform, quad_content_rect);
1642 scoped_ptr<PictureDrawQuad> blue_quad = PictureDrawQuad::Create();
1643 blue_quad->SetNew(blue_shared_state.get(),
1644 quad_content_rect,
1645 gfx::Rect(),
1646 quad_content_rect,
1647 content_union_rect.size(),
1648 texture_format,
1649 content_union_rect,
1650 contents_scale,
1651 use_skia_gpu_backend,
1652 pile);
1653 pass->quad_list.push_back(blue_quad.PassAs<DrawQuad>());
1655 // Fill left half of viewport with green.
1656 gfx::Transform half_green_content_to_target_transform;
1657 gfx::Rect half_green_rect(gfx::Size(viewport.width() / 2, viewport.height()));
1658 scoped_ptr<SharedQuadState> half_green_shared_state =
1659 CreateTestSharedQuadState(half_green_content_to_target_transform,
1660 half_green_rect);
1661 scoped_ptr<SolidColorDrawQuad> half_color_quad = SolidColorDrawQuad::Create();
1662 half_color_quad->SetNew(
1663 half_green_shared_state.get(), half_green_rect, SK_ColorGREEN, false);
1664 pass->quad_list.push_back(half_color_quad.PassAs<DrawQuad>());
1666 RenderPassList pass_list;
1667 pass_list.push_back(pass.Pass());
1669 EXPECT_TRUE(this->RunPixelTest(
1670 &pass_list,
1671 PixelTest::NoOffscreenContext,
1672 base::FilePath(FILE_PATH_LITERAL("four_blue_green_checkers.png")),
1673 ExactPixelComparator(true)));
1675 #endif // !defined(OS_ANDROID)
1677 } // namespace
1678 } // namespace cc