cc: Added inline to Tile::IsReadyToDraw
[chromium-blink-merge.git] / cc / output / renderer_pixeltest.cc
blobe8d13237208d17442ad59c9eb7018673586b4664
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 PixelTest::NoOffscreenContext,
219 base::FilePath(FILE_PATH_LITERAL("green.png")),
220 ExactPixelComparator(true)));
223 TYPED_TEST(RendererPixelTest, SimpleGreenRect_NonRootRenderPass) {
224 gfx::Rect rect(this->device_viewport_size_);
225 gfx::Rect small_rect(100, 100);
227 RenderPass::Id child_id(2, 1);
228 scoped_ptr<RenderPass> child_pass =
229 CreateTestRenderPass(child_id, small_rect, gfx::Transform());
231 scoped_ptr<SharedQuadState> child_shared_state =
232 CreateTestSharedQuadState(gfx::Transform(), small_rect);
234 scoped_ptr<SolidColorDrawQuad> color_quad = SolidColorDrawQuad::Create();
235 color_quad->SetNew(child_shared_state.get(), rect, SK_ColorGREEN, false);
236 child_pass->quad_list.push_back(color_quad.PassAs<DrawQuad>());
238 RenderPass::Id root_id(1, 1);
239 scoped_ptr<RenderPass> root_pass =
240 CreateTestRenderPass(root_id, rect, gfx::Transform());
242 scoped_ptr<SharedQuadState> root_shared_state =
243 CreateTestSharedQuadState(gfx::Transform(), rect);
245 scoped_ptr<DrawQuad> render_pass_quad =
246 CreateTestRenderPassDrawQuad(root_shared_state.get(),
247 small_rect,
248 child_id);
249 root_pass->quad_list.push_back(render_pass_quad.PassAs<DrawQuad>());
251 RenderPass* child_pass_ptr = child_pass.get();
253 RenderPassList pass_list;
254 pass_list.push_back(child_pass.Pass());
255 pass_list.push_back(root_pass.Pass());
257 EXPECT_TRUE(this->RunPixelTestWithReadbackTarget(
258 &pass_list,
259 child_pass_ptr,
260 PixelTest::NoOffscreenContext,
261 base::FilePath(FILE_PATH_LITERAL("green_small.png")),
262 ExactPixelComparator(true)));
265 TYPED_TEST(RendererPixelTest, PremultipliedTextureWithoutBackground) {
266 gfx::Rect rect(this->device_viewport_size_);
268 RenderPass::Id id(1, 1);
269 scoped_ptr<RenderPass> pass = CreateTestRootRenderPass(id, rect);
271 scoped_ptr<SharedQuadState> shared_state =
272 CreateTestSharedQuadState(gfx::Transform(), rect);
274 scoped_ptr<TextureDrawQuad> texture_quad = CreateTestTextureDrawQuad(
275 gfx::Rect(this->device_viewport_size_),
276 SkColorSetARGB(128, 0, 255, 0), // Texel color.
277 SK_ColorTRANSPARENT, // Background color.
278 true, // Premultiplied alpha.
279 shared_state.get(),
280 this->resource_provider_.get());
281 pass->quad_list.push_back(texture_quad.PassAs<DrawQuad>());
283 scoped_ptr<SolidColorDrawQuad> color_quad = SolidColorDrawQuad::Create();
284 color_quad->SetNew(shared_state.get(), rect, SK_ColorWHITE, false);
285 pass->quad_list.push_back(color_quad.PassAs<DrawQuad>());
287 RenderPassList pass_list;
288 pass_list.push_back(pass.Pass());
290 EXPECT_TRUE(this->RunPixelTest(
291 &pass_list,
292 PixelTest::NoOffscreenContext,
293 base::FilePath(FILE_PATH_LITERAL("green_alpha.png")),
294 FuzzyPixelOffByOneComparator(true)));
297 TYPED_TEST(RendererPixelTest, PremultipliedTextureWithBackground) {
298 gfx::Rect rect(this->device_viewport_size_);
300 RenderPass::Id id(1, 1);
301 scoped_ptr<RenderPass> pass = CreateTestRootRenderPass(id, rect);
303 scoped_ptr<SharedQuadState> texture_quad_state =
304 CreateTestSharedQuadState(gfx::Transform(), rect);
305 texture_quad_state->opacity = 0.8f;
307 scoped_ptr<TextureDrawQuad> texture_quad = CreateTestTextureDrawQuad(
308 gfx::Rect(this->device_viewport_size_),
309 SkColorSetARGB(204, 120, 255, 120), // Texel color.
310 SK_ColorGREEN, // Background color.
311 true, // Premultiplied alpha.
312 texture_quad_state.get(),
313 this->resource_provider_.get());
314 pass->quad_list.push_back(texture_quad.PassAs<DrawQuad>());
316 scoped_ptr<SharedQuadState> color_quad_state =
317 CreateTestSharedQuadState(gfx::Transform(), rect);
318 scoped_ptr<SolidColorDrawQuad> color_quad = SolidColorDrawQuad::Create();
319 color_quad->SetNew(color_quad_state.get(), rect, SK_ColorWHITE, false);
320 pass->quad_list.push_back(color_quad.PassAs<DrawQuad>());
322 RenderPassList pass_list;
323 pass_list.push_back(pass.Pass());
325 EXPECT_TRUE(this->RunPixelTest(
326 &pass_list,
327 PixelTest::NoOffscreenContext,
328 base::FilePath(FILE_PATH_LITERAL("green_alpha.png")),
329 FuzzyPixelOffByOneComparator(true)));
332 // TODO(skaslev): The software renderer does not support non-premultplied alpha.
333 TEST_F(GLRendererPixelTest, NonPremultipliedTextureWithoutBackground) {
334 gfx::Rect rect(this->device_viewport_size_);
336 RenderPass::Id id(1, 1);
337 scoped_ptr<RenderPass> pass = CreateTestRootRenderPass(id, rect);
339 scoped_ptr<SharedQuadState> shared_state =
340 CreateTestSharedQuadState(gfx::Transform(), rect);
342 scoped_ptr<TextureDrawQuad> texture_quad = CreateTestTextureDrawQuad(
343 gfx::Rect(this->device_viewport_size_),
344 SkColorSetARGB(128, 0, 255, 0), // Texel color.
345 SK_ColorTRANSPARENT, // Background color.
346 false, // Premultiplied alpha.
347 shared_state.get(),
348 this->resource_provider_.get());
349 pass->quad_list.push_back(texture_quad.PassAs<DrawQuad>());
351 scoped_ptr<SolidColorDrawQuad> color_quad = SolidColorDrawQuad::Create();
352 color_quad->SetNew(shared_state.get(), rect, SK_ColorWHITE, false);
353 pass->quad_list.push_back(color_quad.PassAs<DrawQuad>());
355 RenderPassList pass_list;
356 pass_list.push_back(pass.Pass());
358 EXPECT_TRUE(this->RunPixelTest(
359 &pass_list,
360 PixelTest::NoOffscreenContext,
361 base::FilePath(FILE_PATH_LITERAL("green_alpha.png")),
362 FuzzyPixelOffByOneComparator(true)));
365 // TODO(skaslev): The software renderer does not support non-premultplied alpha.
366 TEST_F(GLRendererPixelTest, NonPremultipliedTextureWithBackground) {
367 gfx::Rect rect(this->device_viewport_size_);
369 RenderPass::Id id(1, 1);
370 scoped_ptr<RenderPass> pass = CreateTestRootRenderPass(id, rect);
372 scoped_ptr<SharedQuadState> texture_quad_state =
373 CreateTestSharedQuadState(gfx::Transform(), rect);
374 texture_quad_state->opacity = 0.8f;
376 scoped_ptr<TextureDrawQuad> texture_quad = CreateTestTextureDrawQuad(
377 gfx::Rect(this->device_viewport_size_),
378 SkColorSetARGB(204, 120, 255, 120), // Texel color.
379 SK_ColorGREEN, // Background color.
380 false, // Premultiplied alpha.
381 texture_quad_state.get(),
382 this->resource_provider_.get());
383 pass->quad_list.push_back(texture_quad.PassAs<DrawQuad>());
385 scoped_ptr<SharedQuadState> color_quad_state =
386 CreateTestSharedQuadState(gfx::Transform(), rect);
387 scoped_ptr<SolidColorDrawQuad> color_quad = SolidColorDrawQuad::Create();
388 color_quad->SetNew(color_quad_state.get(), rect, SK_ColorWHITE, false);
389 pass->quad_list.push_back(color_quad.PassAs<DrawQuad>());
391 RenderPassList pass_list;
392 pass_list.push_back(pass.Pass());
394 EXPECT_TRUE(this->RunPixelTest(
395 &pass_list,
396 PixelTest::NoOffscreenContext,
397 base::FilePath(FILE_PATH_LITERAL("green_alpha.png")),
398 FuzzyPixelOffByOneComparator(true)));
401 class VideoGLRendererPixelTest : public GLRendererPixelTest {
402 protected:
403 scoped_ptr<YUVVideoDrawQuad> CreateTestYUVVideoDrawQuad(
404 SharedQuadState* shared_state, bool with_alpha, bool is_transparent) {
405 gfx::Rect rect(this->device_viewport_size_);
406 gfx::Rect opaque_rect(0, 0, 0, 0);
408 ResourceProvider::ResourceId y_resource =
409 resource_provider_->CreateResource(
410 this->device_viewport_size_,
411 GL_LUMINANCE,
412 ResourceProvider::TextureUsageAny);
413 ResourceProvider::ResourceId u_resource =
414 resource_provider_->CreateResource(
415 this->device_viewport_size_,
416 GL_LUMINANCE,
417 ResourceProvider::TextureUsageAny);
418 ResourceProvider::ResourceId v_resource =
419 resource_provider_->CreateResource(
420 this->device_viewport_size_,
421 GL_LUMINANCE,
422 ResourceProvider::TextureUsageAny);
423 ResourceProvider::ResourceId a_resource = 0;
424 if (with_alpha) {
425 a_resource = resource_provider_->CreateResource(
426 this->device_viewport_size_,
427 GL_LUMINANCE,
428 ResourceProvider::TextureUsageAny);
431 int w = this->device_viewport_size_.width();
432 int h = this->device_viewport_size_.height();
433 const int y_plane_size = w * h;
434 gfx::Rect uv_rect((w + 1) / 2, (h + 1) / 2);
435 const int uv_plane_size = uv_rect.size().GetArea();
436 scoped_ptr<uint8_t[]> y_plane(new uint8_t[y_plane_size]);
437 scoped_ptr<uint8_t[]> u_plane(new uint8_t[uv_plane_size]);
438 scoped_ptr<uint8_t[]> v_plane(new uint8_t[uv_plane_size]);
439 scoped_ptr<uint8_t[]> a_plane;
440 if (with_alpha)
441 a_plane.reset(new uint8_t[y_plane_size]);
442 // YUV values representing Green.
443 memset(y_plane.get(), 149, y_plane_size);
444 memset(u_plane.get(), 43, uv_plane_size);
445 memset(v_plane.get(), 21, uv_plane_size);
446 if (with_alpha)
447 memset(a_plane.get(), is_transparent ? 0 : 128, y_plane_size);
449 resource_provider_->SetPixels(y_resource, y_plane.get(), rect, rect,
450 gfx::Vector2d());
451 resource_provider_->SetPixels(u_resource, u_plane.get(), uv_rect, uv_rect,
452 gfx::Vector2d());
453 resource_provider_->SetPixels(v_resource, v_plane.get(), uv_rect, uv_rect,
454 gfx::Vector2d());
455 if (with_alpha) {
456 resource_provider_->SetPixels(a_resource, a_plane.get(), rect, rect,
457 gfx::Vector2d());
460 scoped_ptr<YUVVideoDrawQuad> yuv_quad = cc::YUVVideoDrawQuad::Create();
461 yuv_quad->SetNew(shared_state, rect, opaque_rect, gfx::Size(),
462 y_resource, u_resource, v_resource, a_resource);
463 return yuv_quad.Pass();
467 TEST_F(VideoGLRendererPixelTest, SimpleYUVRect) {
468 gfx::Rect rect(this->device_viewport_size_);
470 RenderPass::Id id(1, 1);
471 scoped_ptr<RenderPass> pass = CreateTestRootRenderPass(id, rect);
473 scoped_ptr<SharedQuadState> shared_state =
474 CreateTestSharedQuadState(gfx::Transform(), rect);
476 scoped_ptr<YUVVideoDrawQuad> yuv_quad =
477 CreateTestYUVVideoDrawQuad(shared_state.get(), false, false);
479 pass->quad_list.push_back(yuv_quad.PassAs<DrawQuad>());
481 RenderPassList pass_list;
482 pass_list.push_back(pass.Pass());
484 EXPECT_TRUE(this->RunPixelTest(
485 &pass_list,
486 PixelTest::NoOffscreenContext,
487 base::FilePath(FILE_PATH_LITERAL("green.png")),
488 ExactPixelComparator(true)));
491 TEST_F(VideoGLRendererPixelTest, SimpleYUVARect) {
492 gfx::Rect rect(this->device_viewport_size_);
494 RenderPass::Id id(1, 1);
495 scoped_ptr<RenderPass> pass = CreateTestRootRenderPass(id, rect);
497 scoped_ptr<SharedQuadState> shared_state =
498 CreateTestSharedQuadState(gfx::Transform(), rect);
500 scoped_ptr<YUVVideoDrawQuad> yuv_quad =
501 CreateTestYUVVideoDrawQuad(shared_state.get(), true, false);
503 pass->quad_list.push_back(yuv_quad.PassAs<DrawQuad>());
505 scoped_ptr<SolidColorDrawQuad> color_quad = SolidColorDrawQuad::Create();
506 color_quad->SetNew(shared_state.get(), rect, SK_ColorWHITE, false);
508 pass->quad_list.push_back(color_quad.PassAs<DrawQuad>());
510 RenderPassList pass_list;
511 pass_list.push_back(pass.Pass());
513 EXPECT_TRUE(this->RunPixelTest(
514 &pass_list,
515 PixelTest::NoOffscreenContext,
516 base::FilePath(FILE_PATH_LITERAL("green_alpha.png")),
517 ExactPixelComparator(true)));
520 TEST_F(VideoGLRendererPixelTest, FullyTransparentYUVARect) {
521 gfx::Rect rect(this->device_viewport_size_);
523 RenderPass::Id id(1, 1);
524 scoped_ptr<RenderPass> pass = CreateTestRootRenderPass(id, rect);
526 scoped_ptr<SharedQuadState> shared_state =
527 CreateTestSharedQuadState(gfx::Transform(), rect);
529 scoped_ptr<YUVVideoDrawQuad> yuv_quad =
530 CreateTestYUVVideoDrawQuad(shared_state.get(), true, true);
532 pass->quad_list.push_back(yuv_quad.PassAs<DrawQuad>());
534 scoped_ptr<SolidColorDrawQuad> color_quad = SolidColorDrawQuad::Create();
535 color_quad->SetNew(shared_state.get(), rect, SK_ColorBLACK, false);
537 pass->quad_list.push_back(color_quad.PassAs<DrawQuad>());
539 RenderPassList pass_list;
540 pass_list.push_back(pass.Pass());
542 EXPECT_TRUE(this->RunPixelTest(
543 &pass_list,
544 PixelTest::NoOffscreenContext,
545 base::FilePath(FILE_PATH_LITERAL("black.png")),
546 ExactPixelComparator(true)));
549 TYPED_TEST(RendererPixelTest, FastPassColorFilterAlpha) {
550 gfx::Rect viewport_rect(this->device_viewport_size_);
552 RenderPass::Id root_pass_id(1, 1);
553 scoped_ptr<RenderPass> root_pass =
554 CreateTestRootRenderPass(root_pass_id, viewport_rect);
556 RenderPass::Id child_pass_id(2, 2);
557 gfx::Rect pass_rect(this->device_viewport_size_);
558 gfx::Transform transform_to_root;
559 scoped_ptr<RenderPass> child_pass =
560 CreateTestRenderPass(child_pass_id, pass_rect, transform_to_root);
562 gfx::Transform content_to_target_transform;
563 scoped_ptr<SharedQuadState> shared_state =
564 CreateTestSharedQuadState(content_to_target_transform, viewport_rect);
565 shared_state->opacity = 0.5f;
567 scoped_ptr<SolidColorDrawQuad> blue = SolidColorDrawQuad::Create();
568 blue->SetNew(shared_state.get(),
569 gfx::Rect(0,
571 this->device_viewport_size_.width(),
572 this->device_viewport_size_.height() / 2),
573 SK_ColorBLUE,
574 false);
575 scoped_ptr<SolidColorDrawQuad> yellow = SolidColorDrawQuad::Create();
576 yellow->SetNew(shared_state.get(),
577 gfx::Rect(0,
578 this->device_viewport_size_.height() / 2,
579 this->device_viewport_size_.width(),
580 this->device_viewport_size_.height() / 2),
581 SK_ColorYELLOW,
582 false);
584 scoped_ptr<SharedQuadState> blank_state =
585 CreateTestSharedQuadState(content_to_target_transform, viewport_rect);
587 scoped_ptr<SolidColorDrawQuad> white = SolidColorDrawQuad::Create();
588 white->SetNew(blank_state.get(),
589 viewport_rect,
590 SK_ColorWHITE,
591 false);
593 child_pass->quad_list.push_back(blue.PassAs<DrawQuad>());
594 child_pass->quad_list.push_back(yellow.PassAs<DrawQuad>());
595 child_pass->quad_list.push_back(white.PassAs<DrawQuad>());
597 scoped_ptr<SharedQuadState> pass_shared_state =
598 CreateTestSharedQuadState(gfx::Transform(), pass_rect);
600 SkScalar matrix[20];
601 float amount = 0.5f;
602 matrix[0] = 0.213f + 0.787f * amount;
603 matrix[1] = 0.715f - 0.715f * amount;
604 matrix[2] = 1.f - (matrix[0] + matrix[1]);
605 matrix[3] = matrix[4] = 0;
606 matrix[5] = 0.213f - 0.213f * amount;
607 matrix[6] = 0.715f + 0.285f * amount;
608 matrix[7] = 1.f - (matrix[5] + matrix[6]);
609 matrix[8] = matrix[9] = 0;
610 matrix[10] = 0.213f - 0.213f * amount;
611 matrix[11] = 0.715f - 0.715f * amount;
612 matrix[12] = 1.f - (matrix[10] + matrix[11]);
613 matrix[13] = matrix[14] = 0;
614 matrix[15] = matrix[16] = matrix[17] = matrix[19] = 0;
615 matrix[18] = 1;
616 skia::RefPtr<SkColorFilter> colorFilter(skia::AdoptRef(
617 new SkColorMatrixFilter(matrix)));
618 skia::RefPtr<SkImageFilter> filter =
619 skia::AdoptRef(SkColorFilterImageFilter::Create(colorFilter.get(), NULL));
621 scoped_ptr<RenderPassDrawQuad> render_pass_quad =
622 RenderPassDrawQuad::Create();
623 render_pass_quad->SetNew(pass_shared_state.get(),
624 pass_rect,
625 child_pass_id,
626 false,
628 pass_rect,
629 gfx::RectF(),
630 FilterOperations(),
631 filter,
632 FilterOperations());
634 root_pass->quad_list.push_back(render_pass_quad.PassAs<DrawQuad>());
636 RenderPassList pass_list;
637 pass_list.push_back(child_pass.Pass());
638 pass_list.push_back(root_pass.Pass());
640 // This test has alpha=254 for the software renderer vs. alpha=255 for the gl
641 // renderer so use a fuzzy comparator.
642 EXPECT_TRUE(this->RunPixelTest(
643 &pass_list,
644 PixelTest::NoOffscreenContext,
645 base::FilePath(FILE_PATH_LITERAL("blue_yellow_alpha.png")),
646 FuzzyForSoftwareOnlyPixelComparator<TypeParam>(false)));
649 TYPED_TEST(RendererPixelTest, FastPassColorFilterAlphaTranslation) {
650 gfx::Rect viewport_rect(this->device_viewport_size_);
652 RenderPass::Id root_pass_id(1, 1);
653 scoped_ptr<RenderPass> root_pass =
654 CreateTestRootRenderPass(root_pass_id, viewport_rect);
656 RenderPass::Id child_pass_id(2, 2);
657 gfx::Rect pass_rect(this->device_viewport_size_);
658 gfx::Transform transform_to_root;
659 scoped_ptr<RenderPass> child_pass =
660 CreateTestRenderPass(child_pass_id, pass_rect, transform_to_root);
662 gfx::Transform content_to_target_transform;
663 scoped_ptr<SharedQuadState> shared_state =
664 CreateTestSharedQuadState(content_to_target_transform, viewport_rect);
665 shared_state->opacity = 0.5f;
667 scoped_ptr<SolidColorDrawQuad> blue = SolidColorDrawQuad::Create();
668 blue->SetNew(shared_state.get(),
669 gfx::Rect(0,
671 this->device_viewport_size_.width(),
672 this->device_viewport_size_.height() / 2),
673 SK_ColorBLUE,
674 false);
675 scoped_ptr<SolidColorDrawQuad> yellow = SolidColorDrawQuad::Create();
676 yellow->SetNew(shared_state.get(),
677 gfx::Rect(0,
678 this->device_viewport_size_.height() / 2,
679 this->device_viewport_size_.width(),
680 this->device_viewport_size_.height() / 2),
681 SK_ColorYELLOW,
682 false);
684 scoped_ptr<SharedQuadState> blank_state =
685 CreateTestSharedQuadState(content_to_target_transform, viewport_rect);
687 scoped_ptr<SolidColorDrawQuad> white = SolidColorDrawQuad::Create();
688 white->SetNew(blank_state.get(),
689 viewport_rect,
690 SK_ColorWHITE,
691 false);
693 child_pass->quad_list.push_back(blue.PassAs<DrawQuad>());
694 child_pass->quad_list.push_back(yellow.PassAs<DrawQuad>());
695 child_pass->quad_list.push_back(white.PassAs<DrawQuad>());
697 scoped_ptr<SharedQuadState> pass_shared_state =
698 CreateTestSharedQuadState(gfx::Transform(), pass_rect);
700 SkScalar matrix[20];
701 float amount = 0.5f;
702 matrix[0] = 0.213f + 0.787f * amount;
703 matrix[1] = 0.715f - 0.715f * amount;
704 matrix[2] = 1.f - (matrix[0] + matrix[1]);
705 matrix[3] = 0;
706 matrix[4] = 20.f;
707 matrix[5] = 0.213f - 0.213f * amount;
708 matrix[6] = 0.715f + 0.285f * amount;
709 matrix[7] = 1.f - (matrix[5] + matrix[6]);
710 matrix[8] = 0;
711 matrix[9] = 200.f;
712 matrix[10] = 0.213f - 0.213f * amount;
713 matrix[11] = 0.715f - 0.715f * amount;
714 matrix[12] = 1.f - (matrix[10] + matrix[11]);
715 matrix[13] = 0;
716 matrix[14] = 1.5f;
717 matrix[15] = matrix[16] = matrix[17] = matrix[19] = 0;
718 matrix[18] = 1;
719 skia::RefPtr<SkColorFilter> colorFilter(skia::AdoptRef(
720 new SkColorMatrixFilter(matrix)));
721 skia::RefPtr<SkImageFilter> filter =
722 skia::AdoptRef(SkColorFilterImageFilter::Create(colorFilter.get(), NULL));
724 scoped_ptr<RenderPassDrawQuad> render_pass_quad =
725 RenderPassDrawQuad::Create();
726 render_pass_quad->SetNew(pass_shared_state.get(),
727 pass_rect,
728 child_pass_id,
729 false,
731 pass_rect,
732 gfx::RectF(),
733 FilterOperations(),
734 filter,
735 FilterOperations());
737 root_pass->quad_list.push_back(render_pass_quad.PassAs<DrawQuad>());
738 RenderPassList pass_list;
740 pass_list.push_back(child_pass.Pass());
741 pass_list.push_back(root_pass.Pass());
743 // This test has alpha=254 for the software renderer vs. alpha=255 for the gl
744 // renderer so use a fuzzy comparator.
745 EXPECT_TRUE(this->RunPixelTest(
746 &pass_list,
747 PixelTest::NoOffscreenContext,
748 base::FilePath(FILE_PATH_LITERAL("blue_yellow_alpha_translate.png")),
749 FuzzyForSoftwareOnlyPixelComparator<TypeParam>(false)));
752 TYPED_TEST(RendererPixelTest, EnlargedRenderPassTexture) {
753 gfx::Rect viewport_rect(this->device_viewport_size_);
755 RenderPass::Id root_pass_id(1, 1);
756 scoped_ptr<RenderPass> root_pass =
757 CreateTestRootRenderPass(root_pass_id, viewport_rect);
759 RenderPass::Id child_pass_id(2, 2);
760 gfx::Rect pass_rect(this->device_viewport_size_);
761 gfx::Transform transform_to_root;
762 scoped_ptr<RenderPass> child_pass =
763 CreateTestRenderPass(child_pass_id, pass_rect, transform_to_root);
765 gfx::Transform content_to_target_transform;
766 scoped_ptr<SharedQuadState> shared_state =
767 CreateTestSharedQuadState(content_to_target_transform, viewport_rect);
769 scoped_ptr<SolidColorDrawQuad> blue = SolidColorDrawQuad::Create();
770 blue->SetNew(shared_state.get(),
771 gfx::Rect(0,
773 this->device_viewport_size_.width(),
774 this->device_viewport_size_.height() / 2),
775 SK_ColorBLUE,
776 false);
777 scoped_ptr<SolidColorDrawQuad> yellow = SolidColorDrawQuad::Create();
778 yellow->SetNew(shared_state.get(),
779 gfx::Rect(0,
780 this->device_viewport_size_.height() / 2,
781 this->device_viewport_size_.width(),
782 this->device_viewport_size_.height() / 2),
783 SK_ColorYELLOW,
784 false);
786 child_pass->quad_list.push_back(blue.PassAs<DrawQuad>());
787 child_pass->quad_list.push_back(yellow.PassAs<DrawQuad>());
789 scoped_ptr<SharedQuadState> pass_shared_state =
790 CreateTestSharedQuadState(gfx::Transform(), pass_rect);
791 root_pass->quad_list.push_back(
792 CreateTestRenderPassDrawQuad(pass_shared_state.get(),
793 pass_rect,
794 child_pass_id));
796 RenderPassList pass_list;
797 pass_list.push_back(child_pass.Pass());
798 pass_list.push_back(root_pass.Pass());
800 this->renderer_->SetEnlargePassTextureAmountForTesting(gfx::Vector2d(50, 75));
802 EXPECT_TRUE(this->RunPixelTest(
803 &pass_list,
804 PixelTest::NoOffscreenContext,
805 base::FilePath(FILE_PATH_LITERAL("blue_yellow.png")),
806 ExactPixelComparator(true)));
809 TYPED_TEST(RendererPixelTest, EnlargedRenderPassTextureWithAntiAliasing) {
810 gfx::Rect viewport_rect(this->device_viewport_size_);
812 RenderPass::Id root_pass_id(1, 1);
813 scoped_ptr<RenderPass> root_pass =
814 CreateTestRootRenderPass(root_pass_id, viewport_rect);
816 RenderPass::Id child_pass_id(2, 2);
817 gfx::Rect pass_rect(this->device_viewport_size_);
818 gfx::Transform transform_to_root;
819 scoped_ptr<RenderPass> child_pass =
820 CreateTestRenderPass(child_pass_id, pass_rect, transform_to_root);
822 gfx::Transform content_to_target_transform;
823 scoped_ptr<SharedQuadState> shared_state =
824 CreateTestSharedQuadState(content_to_target_transform, viewport_rect);
826 scoped_ptr<SolidColorDrawQuad> blue = SolidColorDrawQuad::Create();
827 blue->SetNew(shared_state.get(),
828 gfx::Rect(0,
830 this->device_viewport_size_.width(),
831 this->device_viewport_size_.height() / 2),
832 SK_ColorBLUE,
833 false);
834 scoped_ptr<SolidColorDrawQuad> yellow = SolidColorDrawQuad::Create();
835 yellow->SetNew(shared_state.get(),
836 gfx::Rect(0,
837 this->device_viewport_size_.height() / 2,
838 this->device_viewport_size_.width(),
839 this->device_viewport_size_.height() / 2),
840 SK_ColorYELLOW,
841 false);
843 child_pass->quad_list.push_back(blue.PassAs<DrawQuad>());
844 child_pass->quad_list.push_back(yellow.PassAs<DrawQuad>());
846 gfx::Transform aa_transform;
847 aa_transform.Translate(0.5, 0.0);
849 scoped_ptr<SharedQuadState> pass_shared_state =
850 CreateTestSharedQuadState(aa_transform, pass_rect);
851 root_pass->quad_list.push_back(
852 CreateTestRenderPassDrawQuad(pass_shared_state.get(),
853 pass_rect,
854 child_pass_id));
856 scoped_ptr<SharedQuadState> root_shared_state =
857 CreateTestSharedQuadState(gfx::Transform(), viewport_rect);
858 scoped_ptr<SolidColorDrawQuad> background = SolidColorDrawQuad::Create();
859 background->SetNew(root_shared_state.get(),
860 gfx::Rect(this->device_viewport_size_),
861 SK_ColorWHITE,
862 false);
863 root_pass->quad_list.push_back(background.PassAs<DrawQuad>());
865 RenderPassList pass_list;
866 pass_list.push_back(child_pass.Pass());
867 pass_list.push_back(root_pass.Pass());
869 this->renderer_->SetEnlargePassTextureAmountForTesting(gfx::Vector2d(50, 75));
871 EXPECT_TRUE(this->RunPixelTest(
872 &pass_list,
873 PixelTest::NoOffscreenContext,
874 base::FilePath(FILE_PATH_LITERAL("blue_yellow_anti_aliasing.png")),
875 FuzzyPixelOffByOneComparator(true)));
878 template <typename RendererType>
879 class RendererPixelTestWithBackgroundFilter
880 : public RendererPixelTest<RendererType> {
881 protected:
882 void SetUpRenderPassList() {
883 gfx::Rect device_viewport_rect(this->device_viewport_size_);
885 RenderPass::Id root_id(1, 1);
886 scoped_ptr<RenderPass> root_pass =
887 CreateTestRootRenderPass(root_id, device_viewport_rect);
888 root_pass->has_transparent_background = false;
890 gfx::Transform identity_content_to_target_transform;
892 RenderPass::Id filter_pass_id(2, 1);
893 gfx::Transform transform_to_root;
894 scoped_ptr<RenderPass> filter_pass =
895 CreateTestRenderPass(filter_pass_id,
896 filter_pass_content_rect_,
897 transform_to_root);
899 // A non-visible quad in the filtering render pass.
901 scoped_ptr<SharedQuadState> shared_state =
902 CreateTestSharedQuadState(identity_content_to_target_transform,
903 filter_pass_content_rect_);
904 scoped_ptr<SolidColorDrawQuad> color_quad = SolidColorDrawQuad::Create();
905 color_quad->SetNew(shared_state.get(),
906 filter_pass_content_rect_,
907 SK_ColorTRANSPARENT,
908 false);
909 filter_pass->quad_list.push_back(color_quad.PassAs<DrawQuad>());
910 filter_pass->shared_quad_state_list.push_back(shared_state.Pass());
914 scoped_ptr<SharedQuadState> shared_state =
915 CreateTestSharedQuadState(filter_pass_to_target_transform_,
916 filter_pass_content_rect_);
917 scoped_ptr<RenderPassDrawQuad> filter_pass_quad =
918 RenderPassDrawQuad::Create();
919 filter_pass_quad->SetNew(
920 shared_state.get(),
921 filter_pass_content_rect_,
922 filter_pass_id,
923 false, // is_replica
924 0, // mask_resource_id
925 filter_pass_content_rect_, // contents_changed_since_last_frame
926 gfx::RectF(), // mask_uv_rect
927 FilterOperations(), // filters
928 skia::RefPtr<SkImageFilter>(), // filter
929 this->background_filters_);
930 root_pass->quad_list.push_back(filter_pass_quad.PassAs<DrawQuad>());
931 root_pass->shared_quad_state_list.push_back(shared_state.Pass());
934 const int kColumnWidth = device_viewport_rect.width() / 3;
936 gfx::Rect left_rect = gfx::Rect(0, 0, kColumnWidth, 20);
937 for (int i = 0; left_rect.y() < device_viewport_rect.height(); ++i) {
938 scoped_ptr<SharedQuadState> shared_state =
939 CreateTestSharedQuadState(identity_content_to_target_transform,
940 left_rect);
941 scoped_ptr<SolidColorDrawQuad> color_quad = SolidColorDrawQuad::Create();
942 color_quad->SetNew(shared_state.get(), left_rect, SK_ColorGREEN, false);
943 root_pass->quad_list.push_back(color_quad.PassAs<DrawQuad>());
944 root_pass->shared_quad_state_list.push_back(shared_state.Pass());
945 left_rect += gfx::Vector2d(0, left_rect.height() + 1);
948 gfx::Rect middle_rect = gfx::Rect(kColumnWidth+1, 0, kColumnWidth, 20);
949 for (int i = 0; middle_rect.y() < device_viewport_rect.height(); ++i) {
950 scoped_ptr<SharedQuadState> shared_state =
951 CreateTestSharedQuadState(identity_content_to_target_transform,
952 middle_rect);
953 scoped_ptr<SolidColorDrawQuad> color_quad = SolidColorDrawQuad::Create();
954 color_quad->SetNew(shared_state.get(), middle_rect, SK_ColorRED, false);
955 root_pass->quad_list.push_back(color_quad.PassAs<DrawQuad>());
956 root_pass->shared_quad_state_list.push_back(shared_state.Pass());
957 middle_rect += gfx::Vector2d(0, middle_rect.height() + 1);
960 gfx::Rect right_rect = gfx::Rect((kColumnWidth+1)*2, 0, kColumnWidth, 20);
961 for (int i = 0; right_rect.y() < device_viewport_rect.height(); ++i) {
962 scoped_ptr<SharedQuadState> shared_state =
963 CreateTestSharedQuadState(identity_content_to_target_transform,
964 right_rect);
965 scoped_ptr<SolidColorDrawQuad> color_quad = SolidColorDrawQuad::Create();
966 color_quad->SetNew(shared_state.get(), right_rect, SK_ColorBLUE, false);
967 root_pass->quad_list.push_back(color_quad.PassAs<DrawQuad>());
968 root_pass->shared_quad_state_list.push_back(shared_state.Pass());
969 right_rect += gfx::Vector2d(0, right_rect.height() + 1);
972 scoped_ptr<SharedQuadState> shared_state =
973 CreateTestSharedQuadState(identity_content_to_target_transform,
974 device_viewport_rect);
975 scoped_ptr<SolidColorDrawQuad> background_quad =
976 SolidColorDrawQuad::Create();
977 background_quad->SetNew(shared_state.get(),
978 device_viewport_rect,
979 SK_ColorWHITE,
980 false);
981 root_pass->quad_list.push_back(background_quad.PassAs<DrawQuad>());
982 root_pass->shared_quad_state_list.push_back(shared_state.Pass());
984 pass_list_.push_back(filter_pass.Pass());
985 pass_list_.push_back(root_pass.Pass());
988 RenderPassList pass_list_;
989 FilterOperations background_filters_;
990 gfx::Transform filter_pass_to_target_transform_;
991 gfx::Rect filter_pass_content_rect_;
994 typedef ::testing::Types<GLRenderer, SoftwareRenderer>
995 BackgroundFilterRendererTypes;
996 TYPED_TEST_CASE(RendererPixelTestWithBackgroundFilter,
997 BackgroundFilterRendererTypes);
999 typedef RendererPixelTestWithBackgroundFilter<GLRenderer>
1000 GLRendererPixelTestWithBackgroundFilter;
1002 // TODO(skaslev): The software renderer does not support filters yet.
1003 TEST_F(GLRendererPixelTestWithBackgroundFilter, InvertFilter) {
1004 this->background_filters_.Append(
1005 FilterOperation::CreateInvertFilter(1.f));
1007 this->filter_pass_content_rect_ = gfx::Rect(this->device_viewport_size_);
1008 this->filter_pass_content_rect_.Inset(12, 14, 16, 18);
1010 this->SetUpRenderPassList();
1011 EXPECT_TRUE(this->RunPixelTest(
1012 &this->pass_list_,
1013 PixelTest::WithOffscreenContext,
1014 base::FilePath(FILE_PATH_LITERAL("background_filter.png")),
1015 ExactPixelComparator(true)));
1018 class ExternalStencilPixelTest : public GLRendererPixelTest {
1019 protected:
1020 void ClearBackgroundToGreen() {
1021 WebKit::WebGraphicsContext3D* context3d =
1022 output_surface_->context_provider()->Context3d();
1023 output_surface_->EnsureBackbuffer();
1024 output_surface_->Reshape(device_viewport_size_, 1);
1025 context3d->clearColor(0.f, 1.f, 0.f, 1.f);
1026 context3d->clear(GL_COLOR_BUFFER_BIT);
1029 void PopulateStencilBuffer() {
1030 // Set two quadrants of the stencil buffer to 1.
1031 WebKit::WebGraphicsContext3D* context3d =
1032 output_surface_->context_provider()->Context3d();
1033 ASSERT_TRUE(context3d->getContextAttributes().stencil);
1034 output_surface_->EnsureBackbuffer();
1035 output_surface_->Reshape(device_viewport_size_, 1);
1036 context3d->clearStencil(0);
1037 context3d->clear(GL_STENCIL_BUFFER_BIT);
1038 context3d->enable(GL_SCISSOR_TEST);
1039 context3d->clearStencil(1);
1040 context3d->scissor(0,
1042 device_viewport_size_.width() / 2,
1043 device_viewport_size_.height() / 2);
1044 context3d->clear(GL_STENCIL_BUFFER_BIT);
1045 context3d->scissor(device_viewport_size_.width() / 2,
1046 device_viewport_size_.height() / 2,
1047 device_viewport_size_.width(),
1048 device_viewport_size_.height());
1049 context3d->clear(GL_STENCIL_BUFFER_BIT);
1053 TEST_F(ExternalStencilPixelTest, StencilTestEnabled) {
1054 ClearBackgroundToGreen();
1055 PopulateStencilBuffer();
1056 this->EnableExternalStencilTest();
1058 // Draw a blue quad that covers the entire device viewport. It should be
1059 // clipped to the bottom left and top right corners by the external stencil.
1060 gfx::Rect rect(this->device_viewport_size_);
1061 RenderPass::Id id(1, 1);
1062 scoped_ptr<RenderPass> pass = CreateTestRootRenderPass(id, rect);
1063 scoped_ptr<SharedQuadState> blue_shared_state =
1064 CreateTestSharedQuadState(gfx::Transform(), rect);
1065 scoped_ptr<SolidColorDrawQuad> blue = SolidColorDrawQuad::Create();
1066 blue->SetNew(blue_shared_state.get(), rect, SK_ColorBLUE, false);
1067 pass->quad_list.push_back(blue.PassAs<DrawQuad>());
1068 pass->has_transparent_background = false;
1069 RenderPassList pass_list;
1070 pass_list.push_back(pass.Pass());
1072 EXPECT_TRUE(this->RunPixelTest(
1073 &pass_list,
1074 PixelTest::NoOffscreenContext,
1075 base::FilePath(FILE_PATH_LITERAL("four_blue_green_checkers.png")),
1076 ExactPixelComparator(true)));
1079 TEST_F(ExternalStencilPixelTest, StencilTestDisabled) {
1080 PopulateStencilBuffer();
1082 // Draw a green quad that covers the entire device viewport. The stencil
1083 // buffer should be ignored.
1084 gfx::Rect rect(this->device_viewport_size_);
1085 RenderPass::Id id(1, 1);
1086 scoped_ptr<RenderPass> pass = CreateTestRootRenderPass(id, rect);
1087 scoped_ptr<SharedQuadState> green_shared_state =
1088 CreateTestSharedQuadState(gfx::Transform(), rect);
1089 scoped_ptr<SolidColorDrawQuad> green = SolidColorDrawQuad::Create();
1090 green->SetNew(green_shared_state.get(), rect, SK_ColorGREEN, false);
1091 pass->quad_list.push_back(green.PassAs<DrawQuad>());
1092 RenderPassList pass_list;
1093 pass_list.push_back(pass.Pass());
1095 EXPECT_TRUE(this->RunPixelTest(
1096 &pass_list,
1097 PixelTest::NoOffscreenContext,
1098 base::FilePath(FILE_PATH_LITERAL("green.png")),
1099 ExactPixelComparator(true)));
1102 TEST_F(ExternalStencilPixelTest, RenderSurfacesIgnoreStencil) {
1103 // The stencil test should apply only to the final render pass.
1104 ClearBackgroundToGreen();
1105 PopulateStencilBuffer();
1106 this->EnableExternalStencilTest();
1108 gfx::Rect viewport_rect(this->device_viewport_size_);
1110 RenderPass::Id root_pass_id(1, 1);
1111 scoped_ptr<RenderPass> root_pass =
1112 CreateTestRootRenderPass(root_pass_id, viewport_rect);
1113 root_pass->has_transparent_background = false;
1115 RenderPass::Id child_pass_id(2, 2);
1116 gfx::Rect pass_rect(this->device_viewport_size_);
1117 gfx::Transform transform_to_root;
1118 scoped_ptr<RenderPass> child_pass =
1119 CreateTestRenderPass(child_pass_id, pass_rect, transform_to_root);
1121 gfx::Transform content_to_target_transform;
1122 scoped_ptr<SharedQuadState> shared_state =
1123 CreateTestSharedQuadState(content_to_target_transform, viewport_rect);
1125 scoped_ptr<SolidColorDrawQuad> blue = SolidColorDrawQuad::Create();
1126 blue->SetNew(shared_state.get(),
1127 gfx::Rect(0,
1129 this->device_viewport_size_.width(),
1130 this->device_viewport_size_.height()),
1131 SK_ColorBLUE,
1132 false);
1133 child_pass->quad_list.push_back(blue.PassAs<DrawQuad>());
1135 scoped_ptr<SharedQuadState> pass_shared_state =
1136 CreateTestSharedQuadState(gfx::Transform(), pass_rect);
1137 root_pass->quad_list.push_back(
1138 CreateTestRenderPassDrawQuad(pass_shared_state.get(),
1139 pass_rect,
1140 child_pass_id));
1141 RenderPassList pass_list;
1142 pass_list.push_back(child_pass.Pass());
1143 pass_list.push_back(root_pass.Pass());
1145 EXPECT_TRUE(this->RunPixelTest(
1146 &pass_list,
1147 PixelTest::NoOffscreenContext,
1148 base::FilePath(FILE_PATH_LITERAL("four_blue_green_checkers.png")),
1149 ExactPixelComparator(true)));
1152 // Software renderer does not support anti-aliased edges.
1153 TEST_F(GLRendererPixelTest, AntiAliasing) {
1154 gfx::Rect rect(this->device_viewport_size_);
1156 RenderPass::Id id(1, 1);
1157 scoped_ptr<RenderPass> pass = CreateTestRootRenderPass(id, rect);
1159 gfx::Transform red_content_to_target_transform;
1160 red_content_to_target_transform.Rotate(10);
1161 scoped_ptr<SharedQuadState> red_shared_state =
1162 CreateTestSharedQuadState(red_content_to_target_transform, rect);
1164 scoped_ptr<SolidColorDrawQuad> red = SolidColorDrawQuad::Create();
1165 red->SetNew(red_shared_state.get(), rect, SK_ColorRED, false);
1167 pass->quad_list.push_back(red.PassAs<DrawQuad>());
1169 gfx::Transform yellow_content_to_target_transform;
1170 yellow_content_to_target_transform.Rotate(5);
1171 scoped_ptr<SharedQuadState> yellow_shared_state =
1172 CreateTestSharedQuadState(yellow_content_to_target_transform, rect);
1174 scoped_ptr<SolidColorDrawQuad> yellow = SolidColorDrawQuad::Create();
1175 yellow->SetNew(yellow_shared_state.get(), rect, SK_ColorYELLOW, false);
1177 pass->quad_list.push_back(yellow.PassAs<DrawQuad>());
1179 gfx::Transform blue_content_to_target_transform;
1180 scoped_ptr<SharedQuadState> blue_shared_state =
1181 CreateTestSharedQuadState(blue_content_to_target_transform, rect);
1183 scoped_ptr<SolidColorDrawQuad> blue = SolidColorDrawQuad::Create();
1184 blue->SetNew(blue_shared_state.get(), rect, SK_ColorBLUE, false);
1186 pass->quad_list.push_back(blue.PassAs<DrawQuad>());
1188 RenderPassList pass_list;
1189 pass_list.push_back(pass.Pass());
1191 EXPECT_TRUE(this->RunPixelTest(
1192 &pass_list,
1193 PixelTest::NoOffscreenContext,
1194 base::FilePath(FILE_PATH_LITERAL("anti_aliasing.png")),
1195 FuzzyPixelOffByOneComparator(true)));
1198 // This test tests that anti-aliasing works for axis aligned quads.
1199 // Anti-aliasing is only supported in the gl renderer.
1200 TEST_F(GLRendererPixelTest, AxisAligned) {
1201 gfx::Rect rect(this->device_viewport_size_);
1203 RenderPass::Id id(1, 1);
1204 gfx::Transform transform_to_root;
1205 scoped_ptr<RenderPass> pass =
1206 CreateTestRenderPass(id, rect, transform_to_root);
1208 gfx::Transform red_content_to_target_transform;
1209 red_content_to_target_transform.Translate(50, 50);
1210 red_content_to_target_transform.Scale(
1211 0.5f + 1.0f / (rect.width() * 2.0f),
1212 0.5f + 1.0f / (rect.height() * 2.0f));
1213 scoped_ptr<SharedQuadState> red_shared_state =
1214 CreateTestSharedQuadState(red_content_to_target_transform, rect);
1216 scoped_ptr<SolidColorDrawQuad> red = SolidColorDrawQuad::Create();
1217 red->SetNew(red_shared_state.get(), rect, SK_ColorRED, false);
1219 pass->quad_list.push_back(red.PassAs<DrawQuad>());
1221 gfx::Transform yellow_content_to_target_transform;
1222 yellow_content_to_target_transform.Translate(25.5f, 25.5f);
1223 yellow_content_to_target_transform.Scale(0.5f, 0.5f);
1224 scoped_ptr<SharedQuadState> yellow_shared_state =
1225 CreateTestSharedQuadState(yellow_content_to_target_transform, rect);
1227 scoped_ptr<SolidColorDrawQuad> yellow = SolidColorDrawQuad::Create();
1228 yellow->SetNew(yellow_shared_state.get(), rect, SK_ColorYELLOW, false);
1230 pass->quad_list.push_back(yellow.PassAs<DrawQuad>());
1232 gfx::Transform blue_content_to_target_transform;
1233 scoped_ptr<SharedQuadState> blue_shared_state =
1234 CreateTestSharedQuadState(blue_content_to_target_transform, rect);
1236 scoped_ptr<SolidColorDrawQuad> blue = SolidColorDrawQuad::Create();
1237 blue->SetNew(blue_shared_state.get(), rect, SK_ColorBLUE, false);
1239 pass->quad_list.push_back(blue.PassAs<DrawQuad>());
1241 RenderPassList pass_list;
1242 pass_list.push_back(pass.Pass());
1244 EXPECT_TRUE(this->RunPixelTest(
1245 &pass_list,
1246 PixelTest::NoOffscreenContext,
1247 base::FilePath(FILE_PATH_LITERAL("axis_aligned.png")),
1248 ExactPixelComparator(true)));
1251 // This test tests that forcing anti-aliasing off works as expected.
1252 // Anti-aliasing is only supported in the gl renderer.
1253 TEST_F(GLRendererPixelTest, ForceAntiAliasingOff) {
1254 gfx::Rect rect(this->device_viewport_size_);
1256 RenderPass::Id id(1, 1);
1257 gfx::Transform transform_to_root;
1258 scoped_ptr<RenderPass> pass =
1259 CreateTestRenderPass(id, rect, transform_to_root);
1261 gfx::Transform hole_content_to_target_transform;
1262 hole_content_to_target_transform.Translate(50, 50);
1263 hole_content_to_target_transform.Scale(
1264 0.5f + 1.0f / (rect.width() * 2.0f),
1265 0.5f + 1.0f / (rect.height() * 2.0f));
1266 scoped_ptr<SharedQuadState> hole_shared_state =
1267 CreateTestSharedQuadState(hole_content_to_target_transform, rect);
1269 scoped_ptr<SolidColorDrawQuad> hole = SolidColorDrawQuad::Create();
1270 hole->SetAll(hole_shared_state.get(), rect, rect, rect, false,
1271 SK_ColorTRANSPARENT, true);
1272 pass->quad_list.push_back(hole.PassAs<DrawQuad>());
1274 gfx::Transform green_content_to_target_transform;
1275 scoped_ptr<SharedQuadState> green_shared_state =
1276 CreateTestSharedQuadState(green_content_to_target_transform, rect);
1278 scoped_ptr<SolidColorDrawQuad> green = SolidColorDrawQuad::Create();
1279 green->SetNew(green_shared_state.get(), rect, SK_ColorGREEN, false);
1281 pass->quad_list.push_back(green.PassAs<DrawQuad>());
1283 RenderPassList pass_list;
1284 pass_list.push_back(pass.Pass());
1286 EXPECT_TRUE(this->RunPixelTest(
1287 &pass_list,
1288 PixelTest::NoOffscreenContext,
1289 base::FilePath(FILE_PATH_LITERAL("force_anti_aliasing_off.png")),
1290 ExactPixelComparator(false)));
1293 TEST_F(GLRendererPixelTest, AntiAliasingPerspective) {
1294 gfx::Rect rect(this->device_viewport_size_);
1296 scoped_ptr<RenderPass> pass =
1297 CreateTestRootRenderPass(RenderPass::Id(1, 1), rect);
1299 gfx::Rect red_rect(0, 0, 180, 500);
1300 gfx::Transform red_content_to_target_transform(
1301 1.0, 2.4520, 10.6206, 19.0,
1302 0.0, 0.3528, 5.9737, 9.5,
1303 0.0, -0.2250, -0.9744, 0.0,
1304 0.0, 0.0225, 0.0974, 1.0);
1305 scoped_ptr<SharedQuadState> red_shared_state =
1306 CreateTestSharedQuadState(red_content_to_target_transform, red_rect);
1307 scoped_ptr<SolidColorDrawQuad> red = SolidColorDrawQuad::Create();
1308 red->SetNew(red_shared_state.get(), red_rect, SK_ColorRED, false);
1309 pass->quad_list.push_back(red.PassAs<DrawQuad>());
1311 gfx::Rect green_rect(19, 7, 180, 10);
1312 scoped_ptr<SharedQuadState> green_shared_state =
1313 CreateTestSharedQuadState(gfx::Transform(), green_rect);
1314 scoped_ptr<SolidColorDrawQuad> green = SolidColorDrawQuad::Create();
1315 green->SetNew(green_shared_state.get(), green_rect, SK_ColorGREEN, false);
1316 pass->quad_list.push_back(green.PassAs<DrawQuad>());
1318 scoped_ptr<SharedQuadState> blue_shared_state =
1319 CreateTestSharedQuadState(gfx::Transform(), rect);
1320 scoped_ptr<SolidColorDrawQuad> blue = SolidColorDrawQuad::Create();
1321 blue->SetNew(blue_shared_state.get(), rect, SK_ColorBLUE, false);
1322 pass->quad_list.push_back(blue.PassAs<DrawQuad>());
1324 RenderPassList pass_list;
1325 pass_list.push_back(pass.Pass());
1327 EXPECT_TRUE(this->RunPixelTest(
1328 &pass_list,
1329 PixelTest::NoOffscreenContext,
1330 base::FilePath(FILE_PATH_LITERAL("anti_aliasing_perspective.png")),
1331 FuzzyPixelOffByOneComparator(true)));
1334 TYPED_TEST(RendererPixelTestWithSkiaGPUBackend, PictureDrawQuadIdentityScale) {
1335 gfx::Size pile_tile_size(1000, 1000);
1336 gfx::Rect viewport(this->device_viewport_size_);
1337 bool use_skia_gpu_backend = this->UseSkiaGPUBackend();
1338 // TODO(enne): the renderer should figure this out on its own.
1339 bool contents_swizzled = !PlatformColor::SameComponentOrder(GL_RGBA);
1341 RenderPass::Id id(1, 1);
1342 gfx::Transform transform_to_root;
1343 scoped_ptr<RenderPass> pass =
1344 CreateTestRenderPass(id, viewport, transform_to_root);
1346 // One clipped blue quad in the lower right corner. Outside the clip
1347 // is red, which should not appear.
1348 gfx::Rect blue_rect(gfx::Size(100, 100));
1349 gfx::Rect blue_clip_rect(gfx::Point(50, 50), gfx::Size(50, 50));
1350 scoped_refptr<FakePicturePileImpl> blue_pile =
1351 FakePicturePileImpl::CreateFilledPile(pile_tile_size, blue_rect.size());
1352 SkPaint red_paint;
1353 red_paint.setColor(SK_ColorRED);
1354 blue_pile->add_draw_rect_with_paint(blue_rect, red_paint);
1355 SkPaint blue_paint;
1356 blue_paint.setColor(SK_ColorBLUE);
1357 blue_pile->add_draw_rect_with_paint(blue_clip_rect, blue_paint);
1358 blue_pile->RerecordPile();
1360 gfx::Transform blue_content_to_target_transform;
1361 gfx::Vector2d offset(viewport.bottom_right() - blue_rect.bottom_right());
1362 blue_content_to_target_transform.Translate(offset.x(), offset.y());
1363 gfx::RectF blue_scissor_rect = blue_clip_rect;
1364 blue_content_to_target_transform.TransformRect(&blue_scissor_rect);
1365 scoped_ptr<SharedQuadState> blue_shared_state =
1366 CreateTestSharedQuadStateClipped(blue_content_to_target_transform,
1367 blue_rect,
1368 gfx::ToEnclosingRect(blue_scissor_rect));
1370 scoped_ptr<PictureDrawQuad> blue_quad = PictureDrawQuad::Create();
1372 blue_quad->SetNew(blue_shared_state.get(),
1373 viewport, // Intentionally bigger than clip.
1374 gfx::Rect(),
1375 viewport,
1376 viewport.size(),
1377 contents_swizzled,
1378 viewport,
1379 1.f,
1380 use_skia_gpu_backend,
1381 blue_pile);
1382 pass->quad_list.push_back(blue_quad.PassAs<DrawQuad>());
1384 // One viewport-filling green quad.
1385 scoped_refptr<FakePicturePileImpl> green_pile =
1386 FakePicturePileImpl::CreateFilledPile(pile_tile_size, viewport.size());
1387 SkPaint green_paint;
1388 green_paint.setColor(SK_ColorGREEN);
1389 green_pile->add_draw_rect_with_paint(viewport, green_paint);
1390 green_pile->RerecordPile();
1392 gfx::Transform green_content_to_target_transform;
1393 scoped_ptr<SharedQuadState> green_shared_state =
1394 CreateTestSharedQuadState(green_content_to_target_transform, viewport);
1396 scoped_ptr<PictureDrawQuad> green_quad = PictureDrawQuad::Create();
1397 green_quad->SetNew(green_shared_state.get(),
1398 viewport,
1399 gfx::Rect(),
1400 gfx::RectF(0.f, 0.f, 1.f, 1.f),
1401 viewport.size(),
1402 contents_swizzled,
1403 viewport,
1404 1.f,
1405 use_skia_gpu_backend,
1406 green_pile);
1407 pass->quad_list.push_back(green_quad.PassAs<DrawQuad>());
1409 RenderPassList pass_list;
1410 pass_list.push_back(pass.Pass());
1412 EXPECT_TRUE(this->RunPixelTest(
1413 &pass_list,
1414 PixelTest::NoOffscreenContext,
1415 base::FilePath(FILE_PATH_LITERAL("green_with_blue_corner.png")),
1416 ExactPixelComparator(true)));
1419 // Not WithSkiaGPUBackend since that path currently requires tiles for opacity.
1420 TYPED_TEST(RendererPixelTest, PictureDrawQuadOpacity) {
1421 gfx::Size pile_tile_size(1000, 1000);
1422 gfx::Rect viewport(this->device_viewport_size_);
1423 bool use_skia_gpu_backend = this->UseSkiaGPUBackend();
1424 bool contents_swizzled = !PlatformColor::SameComponentOrder(GL_RGBA);
1426 RenderPass::Id id(1, 1);
1427 gfx::Transform transform_to_root;
1428 scoped_ptr<RenderPass> pass =
1429 CreateTestRenderPass(id, viewport, transform_to_root);
1431 // One viewport-filling 0.5-opacity green quad.
1432 scoped_refptr<FakePicturePileImpl> green_pile =
1433 FakePicturePileImpl::CreateFilledPile(pile_tile_size, viewport.size());
1434 SkPaint green_paint;
1435 green_paint.setColor(SK_ColorGREEN);
1436 green_pile->add_draw_rect_with_paint(viewport, green_paint);
1437 green_pile->RerecordPile();
1439 gfx::Transform green_content_to_target_transform;
1440 scoped_ptr<SharedQuadState> green_shared_state =
1441 CreateTestSharedQuadState(green_content_to_target_transform, viewport);
1442 green_shared_state->opacity = 0.5f;
1444 scoped_ptr<PictureDrawQuad> green_quad = PictureDrawQuad::Create();
1445 green_quad->SetNew(green_shared_state.get(),
1446 viewport,
1447 gfx::Rect(),
1448 gfx::RectF(0, 0, 1, 1),
1449 viewport.size(),
1450 contents_swizzled,
1451 viewport,
1452 1.f,
1453 use_skia_gpu_backend,
1454 green_pile);
1455 pass->quad_list.push_back(green_quad.PassAs<DrawQuad>());
1457 // One viewport-filling white quad.
1458 scoped_refptr<FakePicturePileImpl> white_pile =
1459 FakePicturePileImpl::CreateFilledPile(pile_tile_size, viewport.size());
1460 SkPaint white_paint;
1461 white_paint.setColor(SK_ColorWHITE);
1462 white_pile->add_draw_rect_with_paint(viewport, white_paint);
1463 white_pile->RerecordPile();
1465 gfx::Transform white_content_to_target_transform;
1466 scoped_ptr<SharedQuadState> white_shared_state =
1467 CreateTestSharedQuadState(white_content_to_target_transform, viewport);
1469 scoped_ptr<PictureDrawQuad> white_quad = PictureDrawQuad::Create();
1470 white_quad->SetNew(white_shared_state.get(),
1471 viewport,
1472 gfx::Rect(),
1473 gfx::RectF(0, 0, 1, 1),
1474 viewport.size(),
1475 contents_swizzled,
1476 viewport,
1477 1.f,
1478 use_skia_gpu_backend,
1479 white_pile);
1480 pass->quad_list.push_back(white_quad.PassAs<DrawQuad>());
1482 RenderPassList pass_list;
1483 pass_list.push_back(pass.Pass());
1485 EXPECT_TRUE(this->RunPixelTest(
1486 &pass_list,
1487 PixelTest::NoOffscreenContext,
1488 base::FilePath(FILE_PATH_LITERAL("green_alpha.png")),
1489 FuzzyPixelOffByOneComparator(true)));
1492 TYPED_TEST(RendererPixelTestWithSkiaGPUBackend,
1493 PictureDrawQuadNonIdentityScale) {
1494 gfx::Size pile_tile_size(1000, 1000);
1495 gfx::Rect viewport(this->device_viewport_size_);
1496 bool use_skia_gpu_backend = this->UseSkiaGPUBackend();
1497 // TODO(enne): the renderer should figure this out on its own.
1498 bool contents_swizzled = !PlatformColor::SameComponentOrder(GL_RGBA);
1500 RenderPass::Id id(1, 1);
1501 gfx::Transform transform_to_root;
1502 scoped_ptr<RenderPass> pass =
1503 CreateTestRenderPass(id, viewport, transform_to_root);
1505 // As scaling up the blue checkerboards will cause sampling on the GPU,
1506 // a few extra "cleanup rects" need to be added to clobber the blending
1507 // to make the output image more clean. This will also test subrects
1508 // of the layer.
1509 gfx::Transform green_content_to_target_transform;
1510 gfx::Rect green_rect1(gfx::Point(80, 0), gfx::Size(20, 100));
1511 gfx::Rect green_rect2(gfx::Point(0, 80), gfx::Size(100, 20));
1512 scoped_refptr<FakePicturePileImpl> green_pile =
1513 FakePicturePileImpl::CreateFilledPile(pile_tile_size, viewport.size());
1514 SkPaint red_paint;
1515 red_paint.setColor(SK_ColorRED);
1516 green_pile->add_draw_rect_with_paint(viewport, red_paint);
1517 SkPaint green_paint;
1518 green_paint.setColor(SK_ColorGREEN);
1519 green_pile->add_draw_rect_with_paint(green_rect1, green_paint);
1520 green_pile->add_draw_rect_with_paint(green_rect2, green_paint);
1521 green_pile->RerecordPile();
1523 scoped_ptr<SharedQuadState> top_right_green_shared_quad_state =
1524 CreateTestSharedQuadState(green_content_to_target_transform, viewport);
1526 scoped_ptr<PictureDrawQuad> green_quad1 = PictureDrawQuad::Create();
1527 green_quad1->SetNew(top_right_green_shared_quad_state.get(),
1528 green_rect1,
1529 gfx::Rect(),
1530 gfx::RectF(green_rect1.size()),
1531 green_rect1.size(),
1532 contents_swizzled,
1533 green_rect1,
1534 1.f,
1535 use_skia_gpu_backend,
1536 green_pile);
1537 pass->quad_list.push_back(green_quad1.PassAs<DrawQuad>());
1539 scoped_ptr<PictureDrawQuad> green_quad2 = PictureDrawQuad::Create();
1540 green_quad2->SetNew(top_right_green_shared_quad_state.get(),
1541 green_rect2,
1542 gfx::Rect(),
1543 gfx::RectF(green_rect2.size()),
1544 green_rect2.size(),
1545 contents_swizzled,
1546 green_rect2,
1547 1.f,
1548 use_skia_gpu_backend,
1549 green_pile);
1550 pass->quad_list.push_back(green_quad2.PassAs<DrawQuad>());
1552 // Add a green clipped checkerboard in the bottom right to help test
1553 // interleaving picture quad content and solid color content.
1554 gfx::Rect bottom_right_rect(
1555 gfx::Point(viewport.width() / 2, viewport.height() / 2),
1556 gfx::Size(viewport.width() / 2, viewport.height() / 2));
1557 scoped_ptr<SharedQuadState> bottom_right_green_shared_state =
1558 CreateTestSharedQuadStateClipped(
1559 green_content_to_target_transform, viewport, bottom_right_rect);
1560 scoped_ptr<SolidColorDrawQuad> bottom_right_color_quad =
1561 SolidColorDrawQuad::Create();
1562 bottom_right_color_quad->SetNew(
1563 bottom_right_green_shared_state.get(), viewport, SK_ColorGREEN, false);
1564 pass->quad_list.push_back(bottom_right_color_quad.PassAs<DrawQuad>());
1566 // Add two blue checkerboards taking up the bottom left and top right,
1567 // but use content scales as content rects to make this happen.
1568 // The content is at a 4x content scale.
1569 gfx::Rect layer_rect(gfx::Size(20, 30));
1570 float contents_scale = 4.f;
1571 // Two rects that touch at their corners, arbitrarily placed in the layer.
1572 gfx::RectF blue_layer_rect1(gfx::PointF(5.5f, 9.0f), gfx::SizeF(2.5f, 2.5f));
1573 gfx::RectF blue_layer_rect2(gfx::PointF(8.0f, 6.5f), gfx::SizeF(2.5f, 2.5f));
1574 gfx::RectF union_layer_rect = blue_layer_rect1;
1575 union_layer_rect.Union(blue_layer_rect2);
1577 // Because scaling up will cause sampling outside the rects, add one extra
1578 // pixel of buffer at the final content scale.
1579 float inset = -1.f / contents_scale;
1580 blue_layer_rect1.Inset(inset, inset, inset, inset);
1581 blue_layer_rect2.Inset(inset, inset, inset, inset);
1583 scoped_refptr<FakePicturePileImpl> pile =
1584 FakePicturePileImpl::CreateFilledPile(pile_tile_size, layer_rect.size());
1586 Region outside(layer_rect);
1587 outside.Subtract(gfx::ToEnclosingRect(union_layer_rect));
1588 for (Region::Iterator iter(outside); iter.has_rect(); iter.next()) {
1589 pile->add_draw_rect_with_paint(iter.rect(), red_paint);
1592 SkPaint blue_paint;
1593 blue_paint.setColor(SK_ColorBLUE);
1594 pile->add_draw_rect_with_paint(blue_layer_rect1, blue_paint);
1595 pile->add_draw_rect_with_paint(blue_layer_rect2, blue_paint);
1596 pile->RerecordPile();
1598 gfx::Rect content_rect(
1599 gfx::ScaleToEnclosingRect(layer_rect, contents_scale));
1600 gfx::Rect content_union_rect(
1601 gfx::ToEnclosingRect(gfx::ScaleRect(union_layer_rect, contents_scale)));
1603 // At a scale of 4x the rectangles with a width of 2.5 will take up 10 pixels,
1604 // so scale an additional 10x to make them 100x100.
1605 gfx::Transform content_to_target_transform;
1606 content_to_target_transform.Scale(10.0, 10.0);
1607 gfx::Rect quad_content_rect(gfx::Size(20, 20));
1608 scoped_ptr<SharedQuadState> blue_shared_state =
1609 CreateTestSharedQuadState(content_to_target_transform, quad_content_rect);
1611 scoped_ptr<PictureDrawQuad> blue_quad = PictureDrawQuad::Create();
1612 blue_quad->SetNew(blue_shared_state.get(),
1613 quad_content_rect,
1614 gfx::Rect(),
1615 quad_content_rect,
1616 content_union_rect.size(),
1617 contents_swizzled,
1618 content_union_rect,
1619 contents_scale,
1620 use_skia_gpu_backend,
1621 pile);
1622 pass->quad_list.push_back(blue_quad.PassAs<DrawQuad>());
1624 // Fill left half of viewport with green.
1625 gfx::Transform half_green_content_to_target_transform;
1626 gfx::Rect half_green_rect(gfx::Size(viewport.width() / 2, viewport.height()));
1627 scoped_ptr<SharedQuadState> half_green_shared_state =
1628 CreateTestSharedQuadState(half_green_content_to_target_transform,
1629 half_green_rect);
1630 scoped_ptr<SolidColorDrawQuad> half_color_quad = SolidColorDrawQuad::Create();
1631 half_color_quad->SetNew(
1632 half_green_shared_state.get(), half_green_rect, SK_ColorGREEN, false);
1633 pass->quad_list.push_back(half_color_quad.PassAs<DrawQuad>());
1635 RenderPassList pass_list;
1636 pass_list.push_back(pass.Pass());
1638 EXPECT_TRUE(this->RunPixelTest(
1639 &pass_list,
1640 PixelTest::NoOffscreenContext,
1641 base::FilePath(FILE_PATH_LITERAL("four_blue_green_checkers.png")),
1642 ExactPixelComparator(true)));
1644 #endif // !defined(OS_ANDROID)
1646 } // namespace
1647 } // namespace cc