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"
26 scoped_ptr
<RenderPass
> CreateTestRootRenderPass(RenderPass::Id id
,
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
);
36 scoped_ptr
<RenderPass
> CreateTestRenderPass(
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
);
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
,
61 return shared_state
.Pass();
64 scoped_ptr
<SharedQuadState
> CreateTestSharedQuadStateClipped(
65 gfx::Transform content_to_target_transform
,
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
,
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
,
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(
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(
118 reinterpret_cast<uint8_t*>(&pixels
.front()),
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
,
131 gfx::PointF(0.0f
, 0.0f
), // uv_top_left
132 gfx::PointF(1.0f
, 1.0f
), // uv_bottom_right
139 typedef ::testing::Types
<GLRenderer
,
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
{
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
{
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;
172 FuzzyPixelOffByOneComparator fuzzy_
;
173 ExactPixelComparator exact_
;
177 bool FuzzyForSoftwareOnlyPixelComparator
<SoftwareRenderer
>::Compare(
178 const SkBitmap
& actual_bmp
,
179 const SkBitmap
& expected_bmp
) const {
180 return fuzzy_
.Compare(actual_bmp
, expected_bmp
);
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(
218 base::FilePath(FILE_PATH_LITERAL("green.png")),
219 ExactPixelComparator(true)));
222 TYPED_TEST(RendererPixelTest
, SimpleGreenRect_NonRootRenderPass
) {
223 gfx::Rect
rect(this->device_viewport_size_
);
224 gfx::Rect
small_rect(100, 100);
226 RenderPass::Id
child_id(2, 1);
227 scoped_ptr
<RenderPass
> child_pass
=
228 CreateTestRenderPass(child_id
, small_rect
, gfx::Transform());
230 scoped_ptr
<SharedQuadState
> child_shared_state
=
231 CreateTestSharedQuadState(gfx::Transform(), small_rect
);
233 scoped_ptr
<SolidColorDrawQuad
> color_quad
= SolidColorDrawQuad::Create();
234 color_quad
->SetNew(child_shared_state
.get(), rect
, SK_ColorGREEN
, false);
235 child_pass
->quad_list
.push_back(color_quad
.PassAs
<DrawQuad
>());
237 RenderPass::Id
root_id(1, 1);
238 scoped_ptr
<RenderPass
> root_pass
=
239 CreateTestRenderPass(root_id
, rect
, gfx::Transform());
241 scoped_ptr
<SharedQuadState
> root_shared_state
=
242 CreateTestSharedQuadState(gfx::Transform(), rect
);
244 scoped_ptr
<DrawQuad
> render_pass_quad
=
245 CreateTestRenderPassDrawQuad(root_shared_state
.get(),
248 root_pass
->quad_list
.push_back(render_pass_quad
.PassAs
<DrawQuad
>());
250 RenderPass
* child_pass_ptr
= child_pass
.get();
252 RenderPassList pass_list
;
253 pass_list
.push_back(child_pass
.Pass());
254 pass_list
.push_back(root_pass
.Pass());
256 EXPECT_TRUE(this->RunPixelTestWithReadbackTarget(
259 base::FilePath(FILE_PATH_LITERAL("green_small.png")),
260 ExactPixelComparator(true)));
263 TYPED_TEST(RendererPixelTest
, PremultipliedTextureWithoutBackground
) {
264 gfx::Rect
rect(this->device_viewport_size_
);
266 RenderPass::Id
id(1, 1);
267 scoped_ptr
<RenderPass
> pass
= CreateTestRootRenderPass(id
, rect
);
269 scoped_ptr
<SharedQuadState
> shared_state
=
270 CreateTestSharedQuadState(gfx::Transform(), rect
);
272 scoped_ptr
<TextureDrawQuad
> texture_quad
= CreateTestTextureDrawQuad(
273 gfx::Rect(this->device_viewport_size_
),
274 SkColorSetARGB(128, 0, 255, 0), // Texel color.
275 SK_ColorTRANSPARENT
, // Background color.
276 true, // Premultiplied alpha.
278 this->resource_provider_
.get());
279 pass
->quad_list
.push_back(texture_quad
.PassAs
<DrawQuad
>());
281 scoped_ptr
<SolidColorDrawQuad
> color_quad
= SolidColorDrawQuad::Create();
282 color_quad
->SetNew(shared_state
.get(), rect
, SK_ColorWHITE
, false);
283 pass
->quad_list
.push_back(color_quad
.PassAs
<DrawQuad
>());
285 RenderPassList pass_list
;
286 pass_list
.push_back(pass
.Pass());
288 EXPECT_TRUE(this->RunPixelTest(
290 base::FilePath(FILE_PATH_LITERAL("green_alpha.png")),
291 FuzzyPixelOffByOneComparator(true)));
294 TYPED_TEST(RendererPixelTest
, PremultipliedTextureWithBackground
) {
295 gfx::Rect
rect(this->device_viewport_size_
);
297 RenderPass::Id
id(1, 1);
298 scoped_ptr
<RenderPass
> pass
= CreateTestRootRenderPass(id
, rect
);
300 scoped_ptr
<SharedQuadState
> texture_quad_state
=
301 CreateTestSharedQuadState(gfx::Transform(), rect
);
302 texture_quad_state
->opacity
= 0.8f
;
304 scoped_ptr
<TextureDrawQuad
> texture_quad
= CreateTestTextureDrawQuad(
305 gfx::Rect(this->device_viewport_size_
),
306 SkColorSetARGB(204, 120, 255, 120), // Texel color.
307 SK_ColorGREEN
, // Background color.
308 true, // Premultiplied alpha.
309 texture_quad_state
.get(),
310 this->resource_provider_
.get());
311 pass
->quad_list
.push_back(texture_quad
.PassAs
<DrawQuad
>());
313 scoped_ptr
<SharedQuadState
> color_quad_state
=
314 CreateTestSharedQuadState(gfx::Transform(), rect
);
315 scoped_ptr
<SolidColorDrawQuad
> color_quad
= SolidColorDrawQuad::Create();
316 color_quad
->SetNew(color_quad_state
.get(), rect
, SK_ColorWHITE
, false);
317 pass
->quad_list
.push_back(color_quad
.PassAs
<DrawQuad
>());
319 RenderPassList pass_list
;
320 pass_list
.push_back(pass
.Pass());
322 EXPECT_TRUE(this->RunPixelTest(
324 base::FilePath(FILE_PATH_LITERAL("green_alpha.png")),
325 FuzzyPixelOffByOneComparator(true)));
328 // TODO(skaslev): The software renderer does not support non-premultplied alpha.
329 TEST_F(GLRendererPixelTest
, NonPremultipliedTextureWithoutBackground
) {
330 gfx::Rect
rect(this->device_viewport_size_
);
332 RenderPass::Id
id(1, 1);
333 scoped_ptr
<RenderPass
> pass
= CreateTestRootRenderPass(id
, rect
);
335 scoped_ptr
<SharedQuadState
> shared_state
=
336 CreateTestSharedQuadState(gfx::Transform(), rect
);
338 scoped_ptr
<TextureDrawQuad
> texture_quad
= CreateTestTextureDrawQuad(
339 gfx::Rect(this->device_viewport_size_
),
340 SkColorSetARGB(128, 0, 255, 0), // Texel color.
341 SK_ColorTRANSPARENT
, // Background color.
342 false, // Premultiplied alpha.
344 this->resource_provider_
.get());
345 pass
->quad_list
.push_back(texture_quad
.PassAs
<DrawQuad
>());
347 scoped_ptr
<SolidColorDrawQuad
> color_quad
= SolidColorDrawQuad::Create();
348 color_quad
->SetNew(shared_state
.get(), rect
, SK_ColorWHITE
, false);
349 pass
->quad_list
.push_back(color_quad
.PassAs
<DrawQuad
>());
351 RenderPassList pass_list
;
352 pass_list
.push_back(pass
.Pass());
354 EXPECT_TRUE(this->RunPixelTest(
356 base::FilePath(FILE_PATH_LITERAL("green_alpha.png")),
357 FuzzyPixelOffByOneComparator(true)));
360 // TODO(skaslev): The software renderer does not support non-premultplied alpha.
361 TEST_F(GLRendererPixelTest
, NonPremultipliedTextureWithBackground
) {
362 gfx::Rect
rect(this->device_viewport_size_
);
364 RenderPass::Id
id(1, 1);
365 scoped_ptr
<RenderPass
> pass
= CreateTestRootRenderPass(id
, rect
);
367 scoped_ptr
<SharedQuadState
> texture_quad_state
=
368 CreateTestSharedQuadState(gfx::Transform(), rect
);
369 texture_quad_state
->opacity
= 0.8f
;
371 scoped_ptr
<TextureDrawQuad
> texture_quad
= CreateTestTextureDrawQuad(
372 gfx::Rect(this->device_viewport_size_
),
373 SkColorSetARGB(204, 120, 255, 120), // Texel color.
374 SK_ColorGREEN
, // Background color.
375 false, // Premultiplied alpha.
376 texture_quad_state
.get(),
377 this->resource_provider_
.get());
378 pass
->quad_list
.push_back(texture_quad
.PassAs
<DrawQuad
>());
380 scoped_ptr
<SharedQuadState
> color_quad_state
=
381 CreateTestSharedQuadState(gfx::Transform(), rect
);
382 scoped_ptr
<SolidColorDrawQuad
> color_quad
= SolidColorDrawQuad::Create();
383 color_quad
->SetNew(color_quad_state
.get(), rect
, SK_ColorWHITE
, false);
384 pass
->quad_list
.push_back(color_quad
.PassAs
<DrawQuad
>());
386 RenderPassList pass_list
;
387 pass_list
.push_back(pass
.Pass());
389 EXPECT_TRUE(this->RunPixelTest(
391 base::FilePath(FILE_PATH_LITERAL("green_alpha.png")),
392 FuzzyPixelOffByOneComparator(true)));
395 class VideoGLRendererPixelTest
: public GLRendererPixelTest
{
397 scoped_ptr
<YUVVideoDrawQuad
> CreateTestYUVVideoDrawQuad(
398 SharedQuadState
* shared_state
, bool with_alpha
, bool is_transparent
) {
399 gfx::Rect
rect(this->device_viewport_size_
);
400 gfx::Rect
opaque_rect(0, 0, 0, 0);
402 ResourceProvider::ResourceId y_resource
=
403 resource_provider_
->CreateResource(
404 this->device_viewport_size_
,
406 ResourceProvider::TextureUsageAny
);
407 ResourceProvider::ResourceId u_resource
=
408 resource_provider_
->CreateResource(
409 this->device_viewport_size_
,
411 ResourceProvider::TextureUsageAny
);
412 ResourceProvider::ResourceId v_resource
=
413 resource_provider_
->CreateResource(
414 this->device_viewport_size_
,
416 ResourceProvider::TextureUsageAny
);
417 ResourceProvider::ResourceId a_resource
= 0;
419 a_resource
= resource_provider_
->CreateResource(
420 this->device_viewport_size_
,
422 ResourceProvider::TextureUsageAny
);
425 int w
= this->device_viewport_size_
.width();
426 int h
= this->device_viewport_size_
.height();
427 const int y_plane_size
= w
* h
;
428 gfx::Rect
uv_rect((w
+ 1) / 2, (h
+ 1) / 2);
429 const int uv_plane_size
= uv_rect
.size().GetArea();
430 scoped_ptr
<uint8_t[]> y_plane(new uint8_t[y_plane_size
]);
431 scoped_ptr
<uint8_t[]> u_plane(new uint8_t[uv_plane_size
]);
432 scoped_ptr
<uint8_t[]> v_plane(new uint8_t[uv_plane_size
]);
433 scoped_ptr
<uint8_t[]> a_plane
;
435 a_plane
.reset(new uint8_t[y_plane_size
]);
436 // YUV values representing Green.
437 memset(y_plane
.get(), 149, y_plane_size
);
438 memset(u_plane
.get(), 43, uv_plane_size
);
439 memset(v_plane
.get(), 21, uv_plane_size
);
441 memset(a_plane
.get(), is_transparent
? 0 : 128, y_plane_size
);
443 resource_provider_
->SetPixels(y_resource
, y_plane
.get(), rect
, rect
,
445 resource_provider_
->SetPixels(u_resource
, u_plane
.get(), uv_rect
, uv_rect
,
447 resource_provider_
->SetPixels(v_resource
, v_plane
.get(), uv_rect
, uv_rect
,
450 resource_provider_
->SetPixels(a_resource
, a_plane
.get(), rect
, rect
,
454 scoped_ptr
<YUVVideoDrawQuad
> yuv_quad
= cc::YUVVideoDrawQuad::Create();
455 yuv_quad
->SetNew(shared_state
, rect
, opaque_rect
, gfx::Size(),
456 y_resource
, u_resource
, v_resource
, a_resource
);
457 return yuv_quad
.Pass();
461 TEST_F(VideoGLRendererPixelTest
, SimpleYUVRect
) {
462 gfx::Rect
rect(this->device_viewport_size_
);
464 RenderPass::Id
id(1, 1);
465 scoped_ptr
<RenderPass
> pass
= CreateTestRootRenderPass(id
, rect
);
467 scoped_ptr
<SharedQuadState
> shared_state
=
468 CreateTestSharedQuadState(gfx::Transform(), rect
);
470 scoped_ptr
<YUVVideoDrawQuad
> yuv_quad
=
471 CreateTestYUVVideoDrawQuad(shared_state
.get(), false, false);
473 pass
->quad_list
.push_back(yuv_quad
.PassAs
<DrawQuad
>());
475 RenderPassList pass_list
;
476 pass_list
.push_back(pass
.Pass());
478 EXPECT_TRUE(this->RunPixelTest(
480 base::FilePath(FILE_PATH_LITERAL("green.png")),
481 ExactPixelComparator(true)));
484 TEST_F(VideoGLRendererPixelTest
, SimpleYUVARect
) {
485 gfx::Rect
rect(this->device_viewport_size_
);
487 RenderPass::Id
id(1, 1);
488 scoped_ptr
<RenderPass
> pass
= CreateTestRootRenderPass(id
, rect
);
490 scoped_ptr
<SharedQuadState
> shared_state
=
491 CreateTestSharedQuadState(gfx::Transform(), rect
);
493 scoped_ptr
<YUVVideoDrawQuad
> yuv_quad
=
494 CreateTestYUVVideoDrawQuad(shared_state
.get(), true, false);
496 pass
->quad_list
.push_back(yuv_quad
.PassAs
<DrawQuad
>());
498 scoped_ptr
<SolidColorDrawQuad
> color_quad
= SolidColorDrawQuad::Create();
499 color_quad
->SetNew(shared_state
.get(), rect
, SK_ColorWHITE
, false);
501 pass
->quad_list
.push_back(color_quad
.PassAs
<DrawQuad
>());
503 RenderPassList pass_list
;
504 pass_list
.push_back(pass
.Pass());
506 EXPECT_TRUE(this->RunPixelTest(
508 base::FilePath(FILE_PATH_LITERAL("green_alpha.png")),
509 ExactPixelComparator(true)));
512 TEST_F(VideoGLRendererPixelTest
, FullyTransparentYUVARect
) {
513 gfx::Rect
rect(this->device_viewport_size_
);
515 RenderPass::Id
id(1, 1);
516 scoped_ptr
<RenderPass
> pass
= CreateTestRootRenderPass(id
, rect
);
518 scoped_ptr
<SharedQuadState
> shared_state
=
519 CreateTestSharedQuadState(gfx::Transform(), rect
);
521 scoped_ptr
<YUVVideoDrawQuad
> yuv_quad
=
522 CreateTestYUVVideoDrawQuad(shared_state
.get(), true, true);
524 pass
->quad_list
.push_back(yuv_quad
.PassAs
<DrawQuad
>());
526 scoped_ptr
<SolidColorDrawQuad
> color_quad
= SolidColorDrawQuad::Create();
527 color_quad
->SetNew(shared_state
.get(), rect
, SK_ColorBLACK
, false);
529 pass
->quad_list
.push_back(color_quad
.PassAs
<DrawQuad
>());
531 RenderPassList pass_list
;
532 pass_list
.push_back(pass
.Pass());
534 EXPECT_TRUE(this->RunPixelTest(
536 base::FilePath(FILE_PATH_LITERAL("black.png")),
537 ExactPixelComparator(true)));
540 TYPED_TEST(RendererPixelTest
, FastPassColorFilterAlpha
) {
541 gfx::Rect
viewport_rect(this->device_viewport_size_
);
543 RenderPass::Id
root_pass_id(1, 1);
544 scoped_ptr
<RenderPass
> root_pass
=
545 CreateTestRootRenderPass(root_pass_id
, viewport_rect
);
547 RenderPass::Id
child_pass_id(2, 2);
548 gfx::Rect
pass_rect(this->device_viewport_size_
);
549 gfx::Transform transform_to_root
;
550 scoped_ptr
<RenderPass
> child_pass
=
551 CreateTestRenderPass(child_pass_id
, pass_rect
, transform_to_root
);
553 gfx::Transform content_to_target_transform
;
554 scoped_ptr
<SharedQuadState
> shared_state
=
555 CreateTestSharedQuadState(content_to_target_transform
, viewport_rect
);
556 shared_state
->opacity
= 0.5f
;
558 scoped_ptr
<SolidColorDrawQuad
> blue
= SolidColorDrawQuad::Create();
559 blue
->SetNew(shared_state
.get(),
562 this->device_viewport_size_
.width(),
563 this->device_viewport_size_
.height() / 2),
566 scoped_ptr
<SolidColorDrawQuad
> yellow
= SolidColorDrawQuad::Create();
567 yellow
->SetNew(shared_state
.get(),
569 this->device_viewport_size_
.height() / 2,
570 this->device_viewport_size_
.width(),
571 this->device_viewport_size_
.height() / 2),
575 scoped_ptr
<SharedQuadState
> blank_state
=
576 CreateTestSharedQuadState(content_to_target_transform
, viewport_rect
);
578 scoped_ptr
<SolidColorDrawQuad
> white
= SolidColorDrawQuad::Create();
579 white
->SetNew(blank_state
.get(),
584 child_pass
->quad_list
.push_back(blue
.PassAs
<DrawQuad
>());
585 child_pass
->quad_list
.push_back(yellow
.PassAs
<DrawQuad
>());
586 child_pass
->quad_list
.push_back(white
.PassAs
<DrawQuad
>());
588 scoped_ptr
<SharedQuadState
> pass_shared_state
=
589 CreateTestSharedQuadState(gfx::Transform(), pass_rect
);
593 matrix
[0] = 0.213f
+ 0.787f
* amount
;
594 matrix
[1] = 0.715f
- 0.715f
* amount
;
595 matrix
[2] = 1.f
- (matrix
[0] + matrix
[1]);
596 matrix
[3] = matrix
[4] = 0;
597 matrix
[5] = 0.213f
- 0.213f
* amount
;
598 matrix
[6] = 0.715f
+ 0.285f
* amount
;
599 matrix
[7] = 1.f
- (matrix
[5] + matrix
[6]);
600 matrix
[8] = matrix
[9] = 0;
601 matrix
[10] = 0.213f
- 0.213f
* amount
;
602 matrix
[11] = 0.715f
- 0.715f
* amount
;
603 matrix
[12] = 1.f
- (matrix
[10] + matrix
[11]);
604 matrix
[13] = matrix
[14] = 0;
605 matrix
[15] = matrix
[16] = matrix
[17] = matrix
[19] = 0;
607 skia::RefPtr
<SkColorFilter
> colorFilter(skia::AdoptRef(
608 new SkColorMatrixFilter(matrix
)));
609 skia::RefPtr
<SkImageFilter
> filter
=
610 skia::AdoptRef(SkColorFilterImageFilter::Create(colorFilter
.get(), NULL
));
612 scoped_ptr
<RenderPassDrawQuad
> render_pass_quad
=
613 RenderPassDrawQuad::Create();
614 render_pass_quad
->SetNew(pass_shared_state
.get(),
625 root_pass
->quad_list
.push_back(render_pass_quad
.PassAs
<DrawQuad
>());
627 RenderPassList pass_list
;
628 pass_list
.push_back(child_pass
.Pass());
629 pass_list
.push_back(root_pass
.Pass());
631 // This test has alpha=254 for the software renderer vs. alpha=255 for the gl
632 // renderer so use a fuzzy comparator.
633 EXPECT_TRUE(this->RunPixelTest(
635 base::FilePath(FILE_PATH_LITERAL("blue_yellow_alpha.png")),
636 FuzzyForSoftwareOnlyPixelComparator
<TypeParam
>(false)));
639 TYPED_TEST(RendererPixelTest
, FastPassColorFilterAlphaTranslation
) {
640 gfx::Rect
viewport_rect(this->device_viewport_size_
);
642 RenderPass::Id
root_pass_id(1, 1);
643 scoped_ptr
<RenderPass
> root_pass
=
644 CreateTestRootRenderPass(root_pass_id
, viewport_rect
);
646 RenderPass::Id
child_pass_id(2, 2);
647 gfx::Rect
pass_rect(this->device_viewport_size_
);
648 gfx::Transform transform_to_root
;
649 scoped_ptr
<RenderPass
> child_pass
=
650 CreateTestRenderPass(child_pass_id
, pass_rect
, transform_to_root
);
652 gfx::Transform content_to_target_transform
;
653 scoped_ptr
<SharedQuadState
> shared_state
=
654 CreateTestSharedQuadState(content_to_target_transform
, viewport_rect
);
655 shared_state
->opacity
= 0.5f
;
657 scoped_ptr
<SolidColorDrawQuad
> blue
= SolidColorDrawQuad::Create();
658 blue
->SetNew(shared_state
.get(),
661 this->device_viewport_size_
.width(),
662 this->device_viewport_size_
.height() / 2),
665 scoped_ptr
<SolidColorDrawQuad
> yellow
= SolidColorDrawQuad::Create();
666 yellow
->SetNew(shared_state
.get(),
668 this->device_viewport_size_
.height() / 2,
669 this->device_viewport_size_
.width(),
670 this->device_viewport_size_
.height() / 2),
674 scoped_ptr
<SharedQuadState
> blank_state
=
675 CreateTestSharedQuadState(content_to_target_transform
, viewport_rect
);
677 scoped_ptr
<SolidColorDrawQuad
> white
= SolidColorDrawQuad::Create();
678 white
->SetNew(blank_state
.get(),
683 child_pass
->quad_list
.push_back(blue
.PassAs
<DrawQuad
>());
684 child_pass
->quad_list
.push_back(yellow
.PassAs
<DrawQuad
>());
685 child_pass
->quad_list
.push_back(white
.PassAs
<DrawQuad
>());
687 scoped_ptr
<SharedQuadState
> pass_shared_state
=
688 CreateTestSharedQuadState(gfx::Transform(), pass_rect
);
692 matrix
[0] = 0.213f
+ 0.787f
* amount
;
693 matrix
[1] = 0.715f
- 0.715f
* amount
;
694 matrix
[2] = 1.f
- (matrix
[0] + matrix
[1]);
697 matrix
[5] = 0.213f
- 0.213f
* amount
;
698 matrix
[6] = 0.715f
+ 0.285f
* amount
;
699 matrix
[7] = 1.f
- (matrix
[5] + matrix
[6]);
702 matrix
[10] = 0.213f
- 0.213f
* amount
;
703 matrix
[11] = 0.715f
- 0.715f
* amount
;
704 matrix
[12] = 1.f
- (matrix
[10] + matrix
[11]);
707 matrix
[15] = matrix
[16] = matrix
[17] = matrix
[19] = 0;
709 skia::RefPtr
<SkColorFilter
> colorFilter(skia::AdoptRef(
710 new SkColorMatrixFilter(matrix
)));
711 skia::RefPtr
<SkImageFilter
> filter
=
712 skia::AdoptRef(SkColorFilterImageFilter::Create(colorFilter
.get(), NULL
));
714 scoped_ptr
<RenderPassDrawQuad
> render_pass_quad
=
715 RenderPassDrawQuad::Create();
716 render_pass_quad
->SetNew(pass_shared_state
.get(),
727 root_pass
->quad_list
.push_back(render_pass_quad
.PassAs
<DrawQuad
>());
728 RenderPassList pass_list
;
730 pass_list
.push_back(child_pass
.Pass());
731 pass_list
.push_back(root_pass
.Pass());
733 // This test has alpha=254 for the software renderer vs. alpha=255 for the gl
734 // renderer so use a fuzzy comparator.
735 EXPECT_TRUE(this->RunPixelTest(
737 base::FilePath(FILE_PATH_LITERAL("blue_yellow_alpha_translate.png")),
738 FuzzyForSoftwareOnlyPixelComparator
<TypeParam
>(false)));
741 TYPED_TEST(RendererPixelTest
, EnlargedRenderPassTexture
) {
742 gfx::Rect
viewport_rect(this->device_viewport_size_
);
744 RenderPass::Id
root_pass_id(1, 1);
745 scoped_ptr
<RenderPass
> root_pass
=
746 CreateTestRootRenderPass(root_pass_id
, viewport_rect
);
748 RenderPass::Id
child_pass_id(2, 2);
749 gfx::Rect
pass_rect(this->device_viewport_size_
);
750 gfx::Transform transform_to_root
;
751 scoped_ptr
<RenderPass
> child_pass
=
752 CreateTestRenderPass(child_pass_id
, pass_rect
, transform_to_root
);
754 gfx::Transform content_to_target_transform
;
755 scoped_ptr
<SharedQuadState
> shared_state
=
756 CreateTestSharedQuadState(content_to_target_transform
, viewport_rect
);
758 scoped_ptr
<SolidColorDrawQuad
> blue
= SolidColorDrawQuad::Create();
759 blue
->SetNew(shared_state
.get(),
762 this->device_viewport_size_
.width(),
763 this->device_viewport_size_
.height() / 2),
766 scoped_ptr
<SolidColorDrawQuad
> yellow
= SolidColorDrawQuad::Create();
767 yellow
->SetNew(shared_state
.get(),
769 this->device_viewport_size_
.height() / 2,
770 this->device_viewport_size_
.width(),
771 this->device_viewport_size_
.height() / 2),
775 child_pass
->quad_list
.push_back(blue
.PassAs
<DrawQuad
>());
776 child_pass
->quad_list
.push_back(yellow
.PassAs
<DrawQuad
>());
778 scoped_ptr
<SharedQuadState
> pass_shared_state
=
779 CreateTestSharedQuadState(gfx::Transform(), pass_rect
);
780 root_pass
->quad_list
.push_back(
781 CreateTestRenderPassDrawQuad(pass_shared_state
.get(),
785 RenderPassList pass_list
;
786 pass_list
.push_back(child_pass
.Pass());
787 pass_list
.push_back(root_pass
.Pass());
789 this->renderer_
->SetEnlargePassTextureAmountForTesting(gfx::Vector2d(50, 75));
791 EXPECT_TRUE(this->RunPixelTest(
793 base::FilePath(FILE_PATH_LITERAL("blue_yellow.png")),
794 ExactPixelComparator(true)));
797 TYPED_TEST(RendererPixelTest
, EnlargedRenderPassTextureWithAntiAliasing
) {
798 gfx::Rect
viewport_rect(this->device_viewport_size_
);
800 RenderPass::Id
root_pass_id(1, 1);
801 scoped_ptr
<RenderPass
> root_pass
=
802 CreateTestRootRenderPass(root_pass_id
, viewport_rect
);
804 RenderPass::Id
child_pass_id(2, 2);
805 gfx::Rect
pass_rect(this->device_viewport_size_
);
806 gfx::Transform transform_to_root
;
807 scoped_ptr
<RenderPass
> child_pass
=
808 CreateTestRenderPass(child_pass_id
, pass_rect
, transform_to_root
);
810 gfx::Transform content_to_target_transform
;
811 scoped_ptr
<SharedQuadState
> shared_state
=
812 CreateTestSharedQuadState(content_to_target_transform
, viewport_rect
);
814 scoped_ptr
<SolidColorDrawQuad
> blue
= SolidColorDrawQuad::Create();
815 blue
->SetNew(shared_state
.get(),
818 this->device_viewport_size_
.width(),
819 this->device_viewport_size_
.height() / 2),
822 scoped_ptr
<SolidColorDrawQuad
> yellow
= SolidColorDrawQuad::Create();
823 yellow
->SetNew(shared_state
.get(),
825 this->device_viewport_size_
.height() / 2,
826 this->device_viewport_size_
.width(),
827 this->device_viewport_size_
.height() / 2),
831 child_pass
->quad_list
.push_back(blue
.PassAs
<DrawQuad
>());
832 child_pass
->quad_list
.push_back(yellow
.PassAs
<DrawQuad
>());
834 gfx::Transform aa_transform
;
835 aa_transform
.Translate(0.5, 0.0);
837 scoped_ptr
<SharedQuadState
> pass_shared_state
=
838 CreateTestSharedQuadState(aa_transform
, pass_rect
);
839 root_pass
->quad_list
.push_back(
840 CreateTestRenderPassDrawQuad(pass_shared_state
.get(),
844 scoped_ptr
<SharedQuadState
> root_shared_state
=
845 CreateTestSharedQuadState(gfx::Transform(), viewport_rect
);
846 scoped_ptr
<SolidColorDrawQuad
> background
= SolidColorDrawQuad::Create();
847 background
->SetNew(root_shared_state
.get(),
848 gfx::Rect(this->device_viewport_size_
),
851 root_pass
->quad_list
.push_back(background
.PassAs
<DrawQuad
>());
853 RenderPassList pass_list
;
854 pass_list
.push_back(child_pass
.Pass());
855 pass_list
.push_back(root_pass
.Pass());
857 this->renderer_
->SetEnlargePassTextureAmountForTesting(gfx::Vector2d(50, 75));
859 EXPECT_TRUE(this->RunPixelTest(
861 base::FilePath(FILE_PATH_LITERAL("blue_yellow_anti_aliasing.png")),
862 FuzzyPixelOffByOneComparator(true)));
865 template <typename RendererType
>
866 class RendererPixelTestWithBackgroundFilter
867 : public RendererPixelTest
<RendererType
> {
869 void SetUpRenderPassList() {
870 gfx::Rect
device_viewport_rect(this->device_viewport_size_
);
872 RenderPass::Id
root_id(1, 1);
873 scoped_ptr
<RenderPass
> root_pass
=
874 CreateTestRootRenderPass(root_id
, device_viewport_rect
);
875 root_pass
->has_transparent_background
= false;
877 gfx::Transform identity_content_to_target_transform
;
879 RenderPass::Id
filter_pass_id(2, 1);
880 gfx::Transform transform_to_root
;
881 scoped_ptr
<RenderPass
> filter_pass
=
882 CreateTestRenderPass(filter_pass_id
,
883 filter_pass_content_rect_
,
886 // A non-visible quad in the filtering render pass.
888 scoped_ptr
<SharedQuadState
> shared_state
=
889 CreateTestSharedQuadState(identity_content_to_target_transform
,
890 filter_pass_content_rect_
);
891 scoped_ptr
<SolidColorDrawQuad
> color_quad
= SolidColorDrawQuad::Create();
892 color_quad
->SetNew(shared_state
.get(),
893 filter_pass_content_rect_
,
896 filter_pass
->quad_list
.push_back(color_quad
.PassAs
<DrawQuad
>());
897 filter_pass
->shared_quad_state_list
.push_back(shared_state
.Pass());
901 scoped_ptr
<SharedQuadState
> shared_state
=
902 CreateTestSharedQuadState(filter_pass_to_target_transform_
,
903 filter_pass_content_rect_
);
904 scoped_ptr
<RenderPassDrawQuad
> filter_pass_quad
=
905 RenderPassDrawQuad::Create();
906 filter_pass_quad
->SetNew(
908 filter_pass_content_rect_
,
911 0, // mask_resource_id
912 filter_pass_content_rect_
, // contents_changed_since_last_frame
913 gfx::RectF(), // mask_uv_rect
914 FilterOperations(), // filters
915 skia::RefPtr
<SkImageFilter
>(), // filter
916 this->background_filters_
);
917 root_pass
->quad_list
.push_back(filter_pass_quad
.PassAs
<DrawQuad
>());
918 root_pass
->shared_quad_state_list
.push_back(shared_state
.Pass());
921 const int kColumnWidth
= device_viewport_rect
.width() / 3;
923 gfx::Rect left_rect
= gfx::Rect(0, 0, kColumnWidth
, 20);
924 for (int i
= 0; left_rect
.y() < device_viewport_rect
.height(); ++i
) {
925 scoped_ptr
<SharedQuadState
> shared_state
=
926 CreateTestSharedQuadState(identity_content_to_target_transform
,
928 scoped_ptr
<SolidColorDrawQuad
> color_quad
= SolidColorDrawQuad::Create();
929 color_quad
->SetNew(shared_state
.get(), left_rect
, SK_ColorGREEN
, false);
930 root_pass
->quad_list
.push_back(color_quad
.PassAs
<DrawQuad
>());
931 root_pass
->shared_quad_state_list
.push_back(shared_state
.Pass());
932 left_rect
+= gfx::Vector2d(0, left_rect
.height() + 1);
935 gfx::Rect middle_rect
= gfx::Rect(kColumnWidth
+1, 0, kColumnWidth
, 20);
936 for (int i
= 0; middle_rect
.y() < device_viewport_rect
.height(); ++i
) {
937 scoped_ptr
<SharedQuadState
> shared_state
=
938 CreateTestSharedQuadState(identity_content_to_target_transform
,
940 scoped_ptr
<SolidColorDrawQuad
> color_quad
= SolidColorDrawQuad::Create();
941 color_quad
->SetNew(shared_state
.get(), middle_rect
, SK_ColorRED
, false);
942 root_pass
->quad_list
.push_back(color_quad
.PassAs
<DrawQuad
>());
943 root_pass
->shared_quad_state_list
.push_back(shared_state
.Pass());
944 middle_rect
+= gfx::Vector2d(0, middle_rect
.height() + 1);
947 gfx::Rect right_rect
= gfx::Rect((kColumnWidth
+1)*2, 0, kColumnWidth
, 20);
948 for (int i
= 0; right_rect
.y() < device_viewport_rect
.height(); ++i
) {
949 scoped_ptr
<SharedQuadState
> shared_state
=
950 CreateTestSharedQuadState(identity_content_to_target_transform
,
952 scoped_ptr
<SolidColorDrawQuad
> color_quad
= SolidColorDrawQuad::Create();
953 color_quad
->SetNew(shared_state
.get(), right_rect
, SK_ColorBLUE
, false);
954 root_pass
->quad_list
.push_back(color_quad
.PassAs
<DrawQuad
>());
955 root_pass
->shared_quad_state_list
.push_back(shared_state
.Pass());
956 right_rect
+= gfx::Vector2d(0, right_rect
.height() + 1);
959 scoped_ptr
<SharedQuadState
> shared_state
=
960 CreateTestSharedQuadState(identity_content_to_target_transform
,
961 device_viewport_rect
);
962 scoped_ptr
<SolidColorDrawQuad
> background_quad
=
963 SolidColorDrawQuad::Create();
964 background_quad
->SetNew(shared_state
.get(),
965 device_viewport_rect
,
968 root_pass
->quad_list
.push_back(background_quad
.PassAs
<DrawQuad
>());
969 root_pass
->shared_quad_state_list
.push_back(shared_state
.Pass());
971 pass_list_
.push_back(filter_pass
.Pass());
972 pass_list_
.push_back(root_pass
.Pass());
975 RenderPassList pass_list_
;
976 FilterOperations background_filters_
;
977 gfx::Transform filter_pass_to_target_transform_
;
978 gfx::Rect filter_pass_content_rect_
;
981 typedef ::testing::Types
<GLRenderer
, SoftwareRenderer
>
982 BackgroundFilterRendererTypes
;
983 TYPED_TEST_CASE(RendererPixelTestWithBackgroundFilter
,
984 BackgroundFilterRendererTypes
);
986 typedef RendererPixelTestWithBackgroundFilter
<GLRenderer
>
987 GLRendererPixelTestWithBackgroundFilter
;
989 // TODO(skaslev): The software renderer does not support filters yet.
990 TEST_F(GLRendererPixelTestWithBackgroundFilter
, InvertFilter
) {
991 this->background_filters_
.Append(
992 FilterOperation::CreateInvertFilter(1.f
));
994 this->filter_pass_content_rect_
= gfx::Rect(this->device_viewport_size_
);
995 this->filter_pass_content_rect_
.Inset(12, 14, 16, 18);
997 this->SetUpRenderPassList();
998 EXPECT_TRUE(this->RunPixelTest(
1000 base::FilePath(FILE_PATH_LITERAL("background_filter.png")),
1001 ExactPixelComparator(true)));
1004 class ExternalStencilPixelTest
: public GLRendererPixelTest
{
1006 void ClearBackgroundToGreen() {
1007 WebKit::WebGraphicsContext3D
* context3d
=
1008 output_surface_
->context_provider()->Context3d();
1009 output_surface_
->EnsureBackbuffer();
1010 output_surface_
->Reshape(device_viewport_size_
, 1);
1011 context3d
->clearColor(0.f
, 1.f
, 0.f
, 1.f
);
1012 context3d
->clear(GL_COLOR_BUFFER_BIT
);
1015 void PopulateStencilBuffer() {
1016 // Set two quadrants of the stencil buffer to 1.
1017 WebKit::WebGraphicsContext3D
* context3d
=
1018 output_surface_
->context_provider()->Context3d();
1019 ASSERT_TRUE(context3d
->getContextAttributes().stencil
);
1020 output_surface_
->EnsureBackbuffer();
1021 output_surface_
->Reshape(device_viewport_size_
, 1);
1022 context3d
->clearStencil(0);
1023 context3d
->clear(GL_STENCIL_BUFFER_BIT
);
1024 context3d
->enable(GL_SCISSOR_TEST
);
1025 context3d
->clearStencil(1);
1026 context3d
->scissor(0,
1028 device_viewport_size_
.width() / 2,
1029 device_viewport_size_
.height() / 2);
1030 context3d
->clear(GL_STENCIL_BUFFER_BIT
);
1031 context3d
->scissor(device_viewport_size_
.width() / 2,
1032 device_viewport_size_
.height() / 2,
1033 device_viewport_size_
.width(),
1034 device_viewport_size_
.height());
1035 context3d
->clear(GL_STENCIL_BUFFER_BIT
);
1039 TEST_F(ExternalStencilPixelTest
, StencilTestEnabled
) {
1040 ClearBackgroundToGreen();
1041 PopulateStencilBuffer();
1042 this->EnableExternalStencilTest();
1044 // Draw a blue quad that covers the entire device viewport. It should be
1045 // clipped to the bottom left and top right corners by the external stencil.
1046 gfx::Rect
rect(this->device_viewport_size_
);
1047 RenderPass::Id
id(1, 1);
1048 scoped_ptr
<RenderPass
> pass
= CreateTestRootRenderPass(id
, rect
);
1049 scoped_ptr
<SharedQuadState
> blue_shared_state
=
1050 CreateTestSharedQuadState(gfx::Transform(), rect
);
1051 scoped_ptr
<SolidColorDrawQuad
> blue
= SolidColorDrawQuad::Create();
1052 blue
->SetNew(blue_shared_state
.get(), rect
, SK_ColorBLUE
, false);
1053 pass
->quad_list
.push_back(blue
.PassAs
<DrawQuad
>());
1054 pass
->has_transparent_background
= false;
1055 RenderPassList pass_list
;
1056 pass_list
.push_back(pass
.Pass());
1058 EXPECT_TRUE(this->RunPixelTest(
1060 base::FilePath(FILE_PATH_LITERAL("four_blue_green_checkers.png")),
1061 ExactPixelComparator(true)));
1064 TEST_F(ExternalStencilPixelTest
, StencilTestDisabled
) {
1065 PopulateStencilBuffer();
1067 // Draw a green quad that covers the entire device viewport. The stencil
1068 // buffer should be ignored.
1069 gfx::Rect
rect(this->device_viewport_size_
);
1070 RenderPass::Id
id(1, 1);
1071 scoped_ptr
<RenderPass
> pass
= CreateTestRootRenderPass(id
, rect
);
1072 scoped_ptr
<SharedQuadState
> green_shared_state
=
1073 CreateTestSharedQuadState(gfx::Transform(), rect
);
1074 scoped_ptr
<SolidColorDrawQuad
> green
= SolidColorDrawQuad::Create();
1075 green
->SetNew(green_shared_state
.get(), rect
, SK_ColorGREEN
, false);
1076 pass
->quad_list
.push_back(green
.PassAs
<DrawQuad
>());
1077 RenderPassList pass_list
;
1078 pass_list
.push_back(pass
.Pass());
1080 EXPECT_TRUE(this->RunPixelTest(
1082 base::FilePath(FILE_PATH_LITERAL("green.png")),
1083 ExactPixelComparator(true)));
1086 TEST_F(ExternalStencilPixelTest
, RenderSurfacesIgnoreStencil
) {
1087 // The stencil test should apply only to the final render pass.
1088 ClearBackgroundToGreen();
1089 PopulateStencilBuffer();
1090 this->EnableExternalStencilTest();
1092 gfx::Rect
viewport_rect(this->device_viewport_size_
);
1094 RenderPass::Id
root_pass_id(1, 1);
1095 scoped_ptr
<RenderPass
> root_pass
=
1096 CreateTestRootRenderPass(root_pass_id
, viewport_rect
);
1097 root_pass
->has_transparent_background
= false;
1099 RenderPass::Id
child_pass_id(2, 2);
1100 gfx::Rect
pass_rect(this->device_viewport_size_
);
1101 gfx::Transform transform_to_root
;
1102 scoped_ptr
<RenderPass
> child_pass
=
1103 CreateTestRenderPass(child_pass_id
, pass_rect
, transform_to_root
);
1105 gfx::Transform content_to_target_transform
;
1106 scoped_ptr
<SharedQuadState
> shared_state
=
1107 CreateTestSharedQuadState(content_to_target_transform
, viewport_rect
);
1109 scoped_ptr
<SolidColorDrawQuad
> blue
= SolidColorDrawQuad::Create();
1110 blue
->SetNew(shared_state
.get(),
1113 this->device_viewport_size_
.width(),
1114 this->device_viewport_size_
.height()),
1117 child_pass
->quad_list
.push_back(blue
.PassAs
<DrawQuad
>());
1119 scoped_ptr
<SharedQuadState
> pass_shared_state
=
1120 CreateTestSharedQuadState(gfx::Transform(), pass_rect
);
1121 root_pass
->quad_list
.push_back(
1122 CreateTestRenderPassDrawQuad(pass_shared_state
.get(),
1125 RenderPassList pass_list
;
1126 pass_list
.push_back(child_pass
.Pass());
1127 pass_list
.push_back(root_pass
.Pass());
1129 EXPECT_TRUE(this->RunPixelTest(
1131 base::FilePath(FILE_PATH_LITERAL("four_blue_green_checkers.png")),
1132 ExactPixelComparator(true)));
1135 // Software renderer does not support anti-aliased edges.
1136 TEST_F(GLRendererPixelTest
, AntiAliasing
) {
1137 gfx::Rect
rect(this->device_viewport_size_
);
1139 RenderPass::Id
id(1, 1);
1140 scoped_ptr
<RenderPass
> pass
= CreateTestRootRenderPass(id
, rect
);
1142 gfx::Transform red_content_to_target_transform
;
1143 red_content_to_target_transform
.Rotate(10);
1144 scoped_ptr
<SharedQuadState
> red_shared_state
=
1145 CreateTestSharedQuadState(red_content_to_target_transform
, rect
);
1147 scoped_ptr
<SolidColorDrawQuad
> red
= SolidColorDrawQuad::Create();
1148 red
->SetNew(red_shared_state
.get(), rect
, SK_ColorRED
, false);
1150 pass
->quad_list
.push_back(red
.PassAs
<DrawQuad
>());
1152 gfx::Transform yellow_content_to_target_transform
;
1153 yellow_content_to_target_transform
.Rotate(5);
1154 scoped_ptr
<SharedQuadState
> yellow_shared_state
=
1155 CreateTestSharedQuadState(yellow_content_to_target_transform
, rect
);
1157 scoped_ptr
<SolidColorDrawQuad
> yellow
= SolidColorDrawQuad::Create();
1158 yellow
->SetNew(yellow_shared_state
.get(), rect
, SK_ColorYELLOW
, false);
1160 pass
->quad_list
.push_back(yellow
.PassAs
<DrawQuad
>());
1162 gfx::Transform blue_content_to_target_transform
;
1163 scoped_ptr
<SharedQuadState
> blue_shared_state
=
1164 CreateTestSharedQuadState(blue_content_to_target_transform
, rect
);
1166 scoped_ptr
<SolidColorDrawQuad
> blue
= SolidColorDrawQuad::Create();
1167 blue
->SetNew(blue_shared_state
.get(), rect
, SK_ColorBLUE
, false);
1169 pass
->quad_list
.push_back(blue
.PassAs
<DrawQuad
>());
1171 RenderPassList pass_list
;
1172 pass_list
.push_back(pass
.Pass());
1174 EXPECT_TRUE(this->RunPixelTest(
1176 base::FilePath(FILE_PATH_LITERAL("anti_aliasing.png")),
1177 FuzzyPixelOffByOneComparator(true)));
1180 // This test tests that anti-aliasing works for axis aligned quads.
1181 // Anti-aliasing is only supported in the gl renderer.
1182 TEST_F(GLRendererPixelTest
, AxisAligned
) {
1183 gfx::Rect
rect(this->device_viewport_size_
);
1185 RenderPass::Id
id(1, 1);
1186 gfx::Transform transform_to_root
;
1187 scoped_ptr
<RenderPass
> pass
=
1188 CreateTestRenderPass(id
, rect
, transform_to_root
);
1190 gfx::Transform red_content_to_target_transform
;
1191 red_content_to_target_transform
.Translate(50, 50);
1192 red_content_to_target_transform
.Scale(
1193 0.5f
+ 1.0f
/ (rect
.width() * 2.0f
),
1194 0.5f
+ 1.0f
/ (rect
.height() * 2.0f
));
1195 scoped_ptr
<SharedQuadState
> red_shared_state
=
1196 CreateTestSharedQuadState(red_content_to_target_transform
, rect
);
1198 scoped_ptr
<SolidColorDrawQuad
> red
= SolidColorDrawQuad::Create();
1199 red
->SetNew(red_shared_state
.get(), rect
, SK_ColorRED
, false);
1201 pass
->quad_list
.push_back(red
.PassAs
<DrawQuad
>());
1203 gfx::Transform yellow_content_to_target_transform
;
1204 yellow_content_to_target_transform
.Translate(25.5f
, 25.5f
);
1205 yellow_content_to_target_transform
.Scale(0.5f
, 0.5f
);
1206 scoped_ptr
<SharedQuadState
> yellow_shared_state
=
1207 CreateTestSharedQuadState(yellow_content_to_target_transform
, rect
);
1209 scoped_ptr
<SolidColorDrawQuad
> yellow
= SolidColorDrawQuad::Create();
1210 yellow
->SetNew(yellow_shared_state
.get(), rect
, SK_ColorYELLOW
, false);
1212 pass
->quad_list
.push_back(yellow
.PassAs
<DrawQuad
>());
1214 gfx::Transform blue_content_to_target_transform
;
1215 scoped_ptr
<SharedQuadState
> blue_shared_state
=
1216 CreateTestSharedQuadState(blue_content_to_target_transform
, rect
);
1218 scoped_ptr
<SolidColorDrawQuad
> blue
= SolidColorDrawQuad::Create();
1219 blue
->SetNew(blue_shared_state
.get(), rect
, SK_ColorBLUE
, false);
1221 pass
->quad_list
.push_back(blue
.PassAs
<DrawQuad
>());
1223 RenderPassList pass_list
;
1224 pass_list
.push_back(pass
.Pass());
1226 EXPECT_TRUE(this->RunPixelTest(
1228 base::FilePath(FILE_PATH_LITERAL("axis_aligned.png")),
1229 ExactPixelComparator(true)));
1232 // This test tests that forcing anti-aliasing off works as expected.
1233 // Anti-aliasing is only supported in the gl renderer.
1234 TEST_F(GLRendererPixelTest
, ForceAntiAliasingOff
) {
1235 gfx::Rect
rect(this->device_viewport_size_
);
1237 RenderPass::Id
id(1, 1);
1238 gfx::Transform transform_to_root
;
1239 scoped_ptr
<RenderPass
> pass
=
1240 CreateTestRenderPass(id
, rect
, transform_to_root
);
1242 gfx::Transform hole_content_to_target_transform
;
1243 hole_content_to_target_transform
.Translate(50, 50);
1244 hole_content_to_target_transform
.Scale(
1245 0.5f
+ 1.0f
/ (rect
.width() * 2.0f
),
1246 0.5f
+ 1.0f
/ (rect
.height() * 2.0f
));
1247 scoped_ptr
<SharedQuadState
> hole_shared_state
=
1248 CreateTestSharedQuadState(hole_content_to_target_transform
, rect
);
1250 scoped_ptr
<SolidColorDrawQuad
> hole
= SolidColorDrawQuad::Create();
1251 hole
->SetAll(hole_shared_state
.get(), rect
, rect
, rect
, false,
1252 SK_ColorTRANSPARENT
, true);
1253 pass
->quad_list
.push_back(hole
.PassAs
<DrawQuad
>());
1255 gfx::Transform green_content_to_target_transform
;
1256 scoped_ptr
<SharedQuadState
> green_shared_state
=
1257 CreateTestSharedQuadState(green_content_to_target_transform
, rect
);
1259 scoped_ptr
<SolidColorDrawQuad
> green
= SolidColorDrawQuad::Create();
1260 green
->SetNew(green_shared_state
.get(), rect
, SK_ColorGREEN
, false);
1262 pass
->quad_list
.push_back(green
.PassAs
<DrawQuad
>());
1264 RenderPassList pass_list
;
1265 pass_list
.push_back(pass
.Pass());
1267 EXPECT_TRUE(this->RunPixelTest(
1269 base::FilePath(FILE_PATH_LITERAL("force_anti_aliasing_off.png")),
1270 ExactPixelComparator(false)));
1273 TEST_F(GLRendererPixelTest
, AntiAliasingPerspective
) {
1274 gfx::Rect
rect(this->device_viewport_size_
);
1276 scoped_ptr
<RenderPass
> pass
=
1277 CreateTestRootRenderPass(RenderPass::Id(1, 1), rect
);
1279 gfx::Rect
red_rect(0, 0, 180, 500);
1280 gfx::Transform
red_content_to_target_transform(
1281 1.0, 2.4520, 10.6206, 19.0,
1282 0.0, 0.3528, 5.9737, 9.5,
1283 0.0, -0.2250, -0.9744, 0.0,
1284 0.0, 0.0225, 0.0974, 1.0);
1285 scoped_ptr
<SharedQuadState
> red_shared_state
=
1286 CreateTestSharedQuadState(red_content_to_target_transform
, red_rect
);
1287 scoped_ptr
<SolidColorDrawQuad
> red
= SolidColorDrawQuad::Create();
1288 red
->SetNew(red_shared_state
.get(), red_rect
, SK_ColorRED
, false);
1289 pass
->quad_list
.push_back(red
.PassAs
<DrawQuad
>());
1291 gfx::Rect
green_rect(19, 7, 180, 10);
1292 scoped_ptr
<SharedQuadState
> green_shared_state
=
1293 CreateTestSharedQuadState(gfx::Transform(), green_rect
);
1294 scoped_ptr
<SolidColorDrawQuad
> green
= SolidColorDrawQuad::Create();
1295 green
->SetNew(green_shared_state
.get(), green_rect
, SK_ColorGREEN
, false);
1296 pass
->quad_list
.push_back(green
.PassAs
<DrawQuad
>());
1298 scoped_ptr
<SharedQuadState
> blue_shared_state
=
1299 CreateTestSharedQuadState(gfx::Transform(), rect
);
1300 scoped_ptr
<SolidColorDrawQuad
> blue
= SolidColorDrawQuad::Create();
1301 blue
->SetNew(blue_shared_state
.get(), rect
, SK_ColorBLUE
, false);
1302 pass
->quad_list
.push_back(blue
.PassAs
<DrawQuad
>());
1304 RenderPassList pass_list
;
1305 pass_list
.push_back(pass
.Pass());
1307 EXPECT_TRUE(this->RunPixelTest(
1309 base::FilePath(FILE_PATH_LITERAL("anti_aliasing_perspective.png")),
1310 FuzzyPixelOffByOneComparator(true)));
1313 TYPED_TEST(RendererPixelTestWithSkiaGPUBackend
, PictureDrawQuadIdentityScale
) {
1314 gfx::Size
pile_tile_size(1000, 1000);
1315 gfx::Rect
viewport(this->device_viewport_size_
);
1316 bool use_skia_gpu_backend
= this->UseSkiaGPUBackend();
1317 // TODO(enne): the renderer should figure this out on its own.
1318 bool contents_swizzled
= !PlatformColor::SameComponentOrder(GL_RGBA
);
1320 RenderPass::Id
id(1, 1);
1321 gfx::Transform transform_to_root
;
1322 scoped_ptr
<RenderPass
> pass
=
1323 CreateTestRenderPass(id
, viewport
, transform_to_root
);
1325 // One clipped blue quad in the lower right corner. Outside the clip
1326 // is red, which should not appear.
1327 gfx::Rect
blue_rect(gfx::Size(100, 100));
1328 gfx::Rect
blue_clip_rect(gfx::Point(50, 50), gfx::Size(50, 50));
1329 scoped_refptr
<FakePicturePileImpl
> blue_pile
=
1330 FakePicturePileImpl::CreateFilledPile(pile_tile_size
, blue_rect
.size());
1332 red_paint
.setColor(SK_ColorRED
);
1333 blue_pile
->add_draw_rect_with_paint(blue_rect
, red_paint
);
1335 blue_paint
.setColor(SK_ColorBLUE
);
1336 blue_pile
->add_draw_rect_with_paint(blue_clip_rect
, blue_paint
);
1337 blue_pile
->RerecordPile();
1339 gfx::Transform blue_content_to_target_transform
;
1340 gfx::Vector2d
offset(viewport
.bottom_right() - blue_rect
.bottom_right());
1341 blue_content_to_target_transform
.Translate(offset
.x(), offset
.y());
1342 gfx::RectF blue_scissor_rect
= blue_clip_rect
;
1343 blue_content_to_target_transform
.TransformRect(&blue_scissor_rect
);
1344 scoped_ptr
<SharedQuadState
> blue_shared_state
=
1345 CreateTestSharedQuadStateClipped(blue_content_to_target_transform
,
1347 gfx::ToEnclosingRect(blue_scissor_rect
));
1349 scoped_ptr
<PictureDrawQuad
> blue_quad
= PictureDrawQuad::Create();
1351 blue_quad
->SetNew(blue_shared_state
.get(),
1352 viewport
, // Intentionally bigger than clip.
1359 use_skia_gpu_backend
,
1361 pass
->quad_list
.push_back(blue_quad
.PassAs
<DrawQuad
>());
1363 // One viewport-filling green quad.
1364 scoped_refptr
<FakePicturePileImpl
> green_pile
=
1365 FakePicturePileImpl::CreateFilledPile(pile_tile_size
, viewport
.size());
1366 SkPaint green_paint
;
1367 green_paint
.setColor(SK_ColorGREEN
);
1368 green_pile
->add_draw_rect_with_paint(viewport
, green_paint
);
1369 green_pile
->RerecordPile();
1371 gfx::Transform green_content_to_target_transform
;
1372 scoped_ptr
<SharedQuadState
> green_shared_state
=
1373 CreateTestSharedQuadState(green_content_to_target_transform
, viewport
);
1375 scoped_ptr
<PictureDrawQuad
> green_quad
= PictureDrawQuad::Create();
1376 green_quad
->SetNew(green_shared_state
.get(),
1379 gfx::RectF(0.f
, 0.f
, 1.f
, 1.f
),
1384 use_skia_gpu_backend
,
1386 pass
->quad_list
.push_back(green_quad
.PassAs
<DrawQuad
>());
1388 RenderPassList pass_list
;
1389 pass_list
.push_back(pass
.Pass());
1391 EXPECT_TRUE(this->RunPixelTest(
1393 base::FilePath(FILE_PATH_LITERAL("green_with_blue_corner.png")),
1394 ExactPixelComparator(true)));
1397 TYPED_TEST(RendererPixelTestWithSkiaGPUBackend
,
1398 PictureDrawQuadNonIdentityScale
) {
1399 gfx::Size
pile_tile_size(1000, 1000);
1400 gfx::Rect
viewport(this->device_viewport_size_
);
1401 bool use_skia_gpu_backend
= this->UseSkiaGPUBackend();
1402 // TODO(enne): the renderer should figure this out on its own.
1403 bool contents_swizzled
= !PlatformColor::SameComponentOrder(GL_RGBA
);
1405 RenderPass::Id
id(1, 1);
1406 gfx::Transform transform_to_root
;
1407 scoped_ptr
<RenderPass
> pass
=
1408 CreateTestRenderPass(id
, viewport
, transform_to_root
);
1410 // As scaling up the blue checkerboards will cause sampling on the GPU,
1411 // a few extra "cleanup rects" need to be added to clobber the blending
1412 // to make the output image more clean. This will also test subrects
1414 gfx::Transform green_content_to_target_transform
;
1415 gfx::Rect
green_rect1(gfx::Point(80, 0), gfx::Size(20, 100));
1416 gfx::Rect
green_rect2(gfx::Point(0, 80), gfx::Size(100, 20));
1417 scoped_refptr
<FakePicturePileImpl
> green_pile
=
1418 FakePicturePileImpl::CreateFilledPile(pile_tile_size
, viewport
.size());
1420 red_paint
.setColor(SK_ColorRED
);
1421 green_pile
->add_draw_rect_with_paint(viewport
, red_paint
);
1422 SkPaint green_paint
;
1423 green_paint
.setColor(SK_ColorGREEN
);
1424 green_pile
->add_draw_rect_with_paint(green_rect1
, green_paint
);
1425 green_pile
->add_draw_rect_with_paint(green_rect2
, green_paint
);
1426 green_pile
->RerecordPile();
1428 scoped_ptr
<SharedQuadState
> top_right_green_shared_quad_state
=
1429 CreateTestSharedQuadState(green_content_to_target_transform
, viewport
);
1431 scoped_ptr
<PictureDrawQuad
> green_quad1
= PictureDrawQuad::Create();
1432 green_quad1
->SetNew(top_right_green_shared_quad_state
.get(),
1435 gfx::RectF(green_rect1
.size()),
1440 use_skia_gpu_backend
,
1442 pass
->quad_list
.push_back(green_quad1
.PassAs
<DrawQuad
>());
1444 scoped_ptr
<PictureDrawQuad
> green_quad2
= PictureDrawQuad::Create();
1445 green_quad2
->SetNew(top_right_green_shared_quad_state
.get(),
1448 gfx::RectF(green_rect2
.size()),
1453 use_skia_gpu_backend
,
1455 pass
->quad_list
.push_back(green_quad2
.PassAs
<DrawQuad
>());
1457 // Add a green clipped checkerboard in the bottom right to help test
1458 // interleaving picture quad content and solid color content.
1459 gfx::Rect
bottom_right_rect(
1460 gfx::Point(viewport
.width() / 2, viewport
.height() / 2),
1461 gfx::Size(viewport
.width() / 2, viewport
.height() / 2));
1462 scoped_ptr
<SharedQuadState
> bottom_right_green_shared_state
=
1463 CreateTestSharedQuadStateClipped(
1464 green_content_to_target_transform
, viewport
, bottom_right_rect
);
1465 scoped_ptr
<SolidColorDrawQuad
> bottom_right_color_quad
=
1466 SolidColorDrawQuad::Create();
1467 bottom_right_color_quad
->SetNew(
1468 bottom_right_green_shared_state
.get(), viewport
, SK_ColorGREEN
, false);
1469 pass
->quad_list
.push_back(bottom_right_color_quad
.PassAs
<DrawQuad
>());
1471 // Add two blue checkerboards taking up the bottom left and top right,
1472 // but use content scales as content rects to make this happen.
1473 // The content is at a 4x content scale.
1474 gfx::Rect
layer_rect(gfx::Size(20, 30));
1475 float contents_scale
= 4.f
;
1476 // Two rects that touch at their corners, arbitrarily placed in the layer.
1477 gfx::RectF
blue_layer_rect1(gfx::PointF(5.5f
, 9.0f
), gfx::SizeF(2.5f
, 2.5f
));
1478 gfx::RectF
blue_layer_rect2(gfx::PointF(8.0f
, 6.5f
), gfx::SizeF(2.5f
, 2.5f
));
1479 gfx::RectF union_layer_rect
= blue_layer_rect1
;
1480 union_layer_rect
.Union(blue_layer_rect2
);
1482 // Because scaling up will cause sampling outside the rects, add one extra
1483 // pixel of buffer at the final content scale.
1484 float inset
= -1.f
/ contents_scale
;
1485 blue_layer_rect1
.Inset(inset
, inset
, inset
, inset
);
1486 blue_layer_rect2
.Inset(inset
, inset
, inset
, inset
);
1488 scoped_refptr
<FakePicturePileImpl
> pile
=
1489 FakePicturePileImpl::CreateFilledPile(pile_tile_size
, layer_rect
.size());
1491 Region
outside(layer_rect
);
1492 outside
.Subtract(gfx::ToEnclosingRect(union_layer_rect
));
1493 for (Region::Iterator
iter(outside
); iter
.has_rect(); iter
.next()) {
1494 pile
->add_draw_rect_with_paint(iter
.rect(), red_paint
);
1498 blue_paint
.setColor(SK_ColorBLUE
);
1499 pile
->add_draw_rect_with_paint(blue_layer_rect1
, blue_paint
);
1500 pile
->add_draw_rect_with_paint(blue_layer_rect2
, blue_paint
);
1501 pile
->RerecordPile();
1503 gfx::Rect
content_rect(
1504 gfx::ScaleToEnclosingRect(layer_rect
, contents_scale
));
1505 gfx::Rect
content_union_rect(
1506 gfx::ToEnclosingRect(gfx::ScaleRect(union_layer_rect
, contents_scale
)));
1508 // At a scale of 4x the rectangles with a width of 2.5 will take up 10 pixels,
1509 // so scale an additional 10x to make them 100x100.
1510 gfx::Transform content_to_target_transform
;
1511 content_to_target_transform
.Scale(10.0, 10.0);
1512 gfx::Rect
quad_content_rect(gfx::Size(20, 20));
1513 scoped_ptr
<SharedQuadState
> blue_shared_state
=
1514 CreateTestSharedQuadState(content_to_target_transform
, quad_content_rect
);
1516 scoped_ptr
<PictureDrawQuad
> blue_quad
= PictureDrawQuad::Create();
1517 blue_quad
->SetNew(blue_shared_state
.get(),
1521 content_union_rect
.size(),
1525 use_skia_gpu_backend
,
1527 pass
->quad_list
.push_back(blue_quad
.PassAs
<DrawQuad
>());
1529 // Fill left half of viewport with green.
1530 gfx::Transform half_green_content_to_target_transform
;
1531 gfx::Rect
half_green_rect(gfx::Size(viewport
.width() / 2, viewport
.height()));
1532 scoped_ptr
<SharedQuadState
> half_green_shared_state
=
1533 CreateTestSharedQuadState(half_green_content_to_target_transform
,
1535 scoped_ptr
<SolidColorDrawQuad
> half_color_quad
= SolidColorDrawQuad::Create();
1536 half_color_quad
->SetNew(
1537 half_green_shared_state
.get(), half_green_rect
, SK_ColorGREEN
, false);
1538 pass
->quad_list
.push_back(half_color_quad
.PassAs
<DrawQuad
>());
1540 RenderPassList pass_list
;
1541 pass_list
.push_back(pass
.Pass());
1543 EXPECT_TRUE(this->RunPixelTest(
1545 base::FilePath(FILE_PATH_LITERAL("four_blue_green_checkers.png")),
1546 ExactPixelComparator(true)));
1548 #endif // !defined(OS_ANDROID)