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/video_resource_updater.h"
12 #include "cc/test/fake_picture_pile_impl.h"
13 #include "cc/test/pixel_test.h"
14 #include "gpu/GLES2/gl2extchromium.h"
15 #include "gpu/command_buffer/client/gles2_interface.h"
16 #include "media/base/video_frame.h"
17 #include "third_party/skia/include/core/SkBitmapDevice.h"
18 #include "third_party/skia/include/core/SkImageFilter.h"
19 #include "third_party/skia/include/core/SkMatrix.h"
20 #include "third_party/skia/include/effects/SkColorFilterImageFilter.h"
21 #include "third_party/skia/include/effects/SkColorMatrixFilter.h"
22 #include "ui/gfx/rect_conversions.h"
24 using gpu::gles2::GLES2Interface
;
29 #if !defined(OS_ANDROID)
30 scoped_ptr
<RenderPass
> CreateTestRootRenderPass(RenderPass::Id id
,
31 const gfx::Rect
& rect
) {
32 scoped_ptr
<RenderPass
> pass
= RenderPass::Create();
33 const gfx::Rect output_rect
= rect
;
34 const gfx::Rect damage_rect
= rect
;
35 const gfx::Transform transform_to_root_target
;
36 pass
->SetNew(id
, output_rect
, damage_rect
, transform_to_root_target
);
40 scoped_ptr
<RenderPass
> CreateTestRenderPass(
42 const gfx::Rect
& rect
,
43 const gfx::Transform
& transform_to_root_target
) {
44 scoped_ptr
<RenderPass
> pass
= RenderPass::Create();
45 const gfx::Rect output_rect
= rect
;
46 const gfx::Rect damage_rect
= rect
;
47 pass
->SetNew(id
, output_rect
, damage_rect
, transform_to_root_target
);
51 scoped_ptr
<SharedQuadState
> CreateTestSharedQuadState(
52 gfx::Transform content_to_target_transform
, const gfx::Rect
& rect
) {
53 const gfx::Size content_bounds
= rect
.size();
54 const gfx::Rect visible_content_rect
= rect
;
55 const gfx::Rect clip_rect
= rect
;
56 const bool is_clipped
= false;
57 const float opacity
= 1.0f
;
58 const SkXfermode::Mode blend_mode
= SkXfermode::kSrcOver_Mode
;
59 scoped_ptr
<SharedQuadState
> shared_state
= SharedQuadState::Create();
60 shared_state
->SetAll(content_to_target_transform
,
67 return shared_state
.Pass();
70 scoped_ptr
<SharedQuadState
> CreateTestSharedQuadStateClipped(
71 gfx::Transform content_to_target_transform
,
72 const gfx::Rect
& rect
,
73 const gfx::Rect
& clip_rect
) {
74 const gfx::Size content_bounds
= rect
.size();
75 const gfx::Rect visible_content_rect
= clip_rect
;
76 const bool is_clipped
= true;
77 const float opacity
= 1.0f
;
78 const SkXfermode::Mode blend_mode
= SkXfermode::kSrcOver_Mode
;
79 scoped_ptr
<SharedQuadState
> shared_state
= SharedQuadState::Create();
80 shared_state
->SetAll(content_to_target_transform
,
87 return shared_state
.Pass();
90 scoped_ptr
<DrawQuad
> CreateTestRenderPassDrawQuad(
91 SharedQuadState
* shared_state
,
92 const gfx::Rect
& rect
,
93 RenderPass::Id pass_id
) {
94 scoped_ptr
<RenderPassDrawQuad
> quad
= RenderPassDrawQuad::Create();
95 quad
->SetNew(shared_state
,
100 0, // mask_resource_id
101 rect
, // contents_changed_since_last_frame
102 gfx::RectF(1.f
, 1.f
), // mask_uv_rect
103 FilterOperations(), // foreground filters
104 FilterOperations()); // background filters
106 return quad
.PassAs
<DrawQuad
>();
109 scoped_ptr
<TextureDrawQuad
> CreateTestTextureDrawQuad(
110 const gfx::Rect
& rect
,
112 SkColor background_color
,
113 bool premultiplied_alpha
,
114 SharedQuadState
* shared_state
,
115 ResourceProvider
* resource_provider
) {
116 SkPMColor pixel_color
= premultiplied_alpha
?
117 SkPreMultiplyColor(texel_color
) :
118 SkPackARGB32NoCheck(SkColorGetA(texel_color
),
119 SkColorGetR(texel_color
),
120 SkColorGetG(texel_color
),
121 SkColorGetB(texel_color
));
122 std::vector
<uint32_t> pixels(rect
.size().GetArea(), pixel_color
);
124 ResourceProvider::ResourceId resource
=
125 resource_provider
->CreateResource(rect
.size(),
127 ResourceProvider::TextureUsageAny
,
129 resource_provider
->SetPixels(
131 reinterpret_cast<uint8_t*>(&pixels
.front()),
136 float vertex_opacity
[4] = {1.0f
, 1.0f
, 1.0f
, 1.0f
};
138 scoped_ptr
<TextureDrawQuad
> quad
= TextureDrawQuad::Create();
139 quad
->SetNew(shared_state
,
145 gfx::PointF(0.0f
, 0.0f
), // uv_top_left
146 gfx::PointF(1.0f
, 1.0f
), // uv_bottom_right
153 typedef ::testing::Types
<GLRenderer
,
155 GLRendererWithExpandedViewport
,
156 SoftwareRendererWithExpandedViewport
> RendererTypes
;
157 TYPED_TEST_CASE(RendererPixelTest
, RendererTypes
);
159 // All pixels can be off by one, but any more than that is an error.
160 class FuzzyPixelOffByOneComparator
: public FuzzyPixelComparator
{
162 explicit FuzzyPixelOffByOneComparator(bool discard_alpha
)
163 : FuzzyPixelComparator(discard_alpha
, 100.f
, 0.f
, 1.f
, 1, 0) {}
166 template <typename RendererType
>
167 class FuzzyForSoftwareOnlyPixelComparator
: public PixelComparator
{
169 explicit FuzzyForSoftwareOnlyPixelComparator(bool discard_alpha
)
170 : fuzzy_(discard_alpha
), exact_(discard_alpha
) {}
172 virtual bool Compare(const SkBitmap
& actual_bmp
,
173 const SkBitmap
& expected_bmp
) const;
176 FuzzyPixelOffByOneComparator fuzzy_
;
177 ExactPixelComparator exact_
;
181 bool FuzzyForSoftwareOnlyPixelComparator
<SoftwareRenderer
>::Compare(
182 const SkBitmap
& actual_bmp
,
183 const SkBitmap
& expected_bmp
) const {
184 return fuzzy_
.Compare(actual_bmp
, expected_bmp
);
188 bool FuzzyForSoftwareOnlyPixelComparator
<
189 SoftwareRendererWithExpandedViewport
>::Compare(
190 const SkBitmap
& actual_bmp
,
191 const SkBitmap
& expected_bmp
) const {
192 return fuzzy_
.Compare(actual_bmp
, expected_bmp
);
195 template<typename RendererType
>
196 bool FuzzyForSoftwareOnlyPixelComparator
<RendererType
>::Compare(
197 const SkBitmap
& actual_bmp
,
198 const SkBitmap
& expected_bmp
) const {
199 return exact_
.Compare(actual_bmp
, expected_bmp
);
202 TYPED_TEST(RendererPixelTest
, SimpleGreenRect
) {
203 gfx::Rect
rect(this->device_viewport_size_
);
205 RenderPass::Id
id(1, 1);
206 scoped_ptr
<RenderPass
> pass
= CreateTestRootRenderPass(id
, rect
);
208 scoped_ptr
<SharedQuadState
> shared_state
=
209 CreateTestSharedQuadState(gfx::Transform(), rect
);
211 scoped_ptr
<SolidColorDrawQuad
> color_quad
= SolidColorDrawQuad::Create();
212 color_quad
->SetNew(shared_state
.get(), rect
, rect
, SK_ColorGREEN
, false);
214 pass
->quad_list
.push_back(color_quad
.PassAs
<DrawQuad
>());
216 RenderPassList pass_list
;
217 pass_list
.push_back(pass
.Pass());
219 EXPECT_TRUE(this->RunPixelTest(
221 base::FilePath(FILE_PATH_LITERAL("green.png")),
222 ExactPixelComparator(true)));
225 TYPED_TEST(RendererPixelTest
, SimpleGreenRect_NonRootRenderPass
) {
226 gfx::Rect
rect(this->device_viewport_size_
);
227 gfx::Rect
small_rect(100, 100);
229 RenderPass::Id
child_id(2, 1);
230 scoped_ptr
<RenderPass
> child_pass
=
231 CreateTestRenderPass(child_id
, small_rect
, gfx::Transform());
233 scoped_ptr
<SharedQuadState
> child_shared_state
=
234 CreateTestSharedQuadState(gfx::Transform(), small_rect
);
236 scoped_ptr
<SolidColorDrawQuad
> color_quad
= SolidColorDrawQuad::Create();
238 child_shared_state
.get(), rect
, rect
, SK_ColorGREEN
, false);
239 child_pass
->quad_list
.push_back(color_quad
.PassAs
<DrawQuad
>());
241 RenderPass::Id
root_id(1, 1);
242 scoped_ptr
<RenderPass
> root_pass
=
243 CreateTestRenderPass(root_id
, rect
, gfx::Transform());
245 scoped_ptr
<SharedQuadState
> root_shared_state
=
246 CreateTestSharedQuadState(gfx::Transform(), rect
);
248 scoped_ptr
<DrawQuad
> render_pass_quad
=
249 CreateTestRenderPassDrawQuad(root_shared_state
.get(),
252 root_pass
->quad_list
.push_back(render_pass_quad
.PassAs
<DrawQuad
>());
254 RenderPass
* child_pass_ptr
= child_pass
.get();
256 RenderPassList pass_list
;
257 pass_list
.push_back(child_pass
.Pass());
258 pass_list
.push_back(root_pass
.Pass());
260 EXPECT_TRUE(this->RunPixelTestWithReadbackTarget(
263 base::FilePath(FILE_PATH_LITERAL("green_small.png")),
264 ExactPixelComparator(true)));
267 TYPED_TEST(RendererPixelTest
, PremultipliedTextureWithoutBackground
) {
268 gfx::Rect
rect(this->device_viewport_size_
);
270 RenderPass::Id
id(1, 1);
271 scoped_ptr
<RenderPass
> pass
= CreateTestRootRenderPass(id
, rect
);
273 scoped_ptr
<SharedQuadState
> shared_state
=
274 CreateTestSharedQuadState(gfx::Transform(), rect
);
276 scoped_ptr
<TextureDrawQuad
> texture_quad
= CreateTestTextureDrawQuad(
277 gfx::Rect(this->device_viewport_size_
),
278 SkColorSetARGB(128, 0, 255, 0), // Texel color.
279 SK_ColorTRANSPARENT
, // Background color.
280 true, // Premultiplied alpha.
282 this->resource_provider_
.get());
283 pass
->quad_list
.push_back(texture_quad
.PassAs
<DrawQuad
>());
285 scoped_ptr
<SolidColorDrawQuad
> color_quad
= SolidColorDrawQuad::Create();
286 color_quad
->SetNew(shared_state
.get(), rect
, rect
, SK_ColorWHITE
, false);
287 pass
->quad_list
.push_back(color_quad
.PassAs
<DrawQuad
>());
289 RenderPassList pass_list
;
290 pass_list
.push_back(pass
.Pass());
292 EXPECT_TRUE(this->RunPixelTest(
294 base::FilePath(FILE_PATH_LITERAL("green_alpha.png")),
295 FuzzyPixelOffByOneComparator(true)));
298 TYPED_TEST(RendererPixelTest
, PremultipliedTextureWithBackground
) {
299 gfx::Rect
rect(this->device_viewport_size_
);
301 RenderPass::Id
id(1, 1);
302 scoped_ptr
<RenderPass
> pass
= CreateTestRootRenderPass(id
, rect
);
304 scoped_ptr
<SharedQuadState
> texture_quad_state
=
305 CreateTestSharedQuadState(gfx::Transform(), rect
);
306 texture_quad_state
->opacity
= 0.8f
;
308 scoped_ptr
<TextureDrawQuad
> texture_quad
= CreateTestTextureDrawQuad(
309 gfx::Rect(this->device_viewport_size_
),
310 SkColorSetARGB(204, 120, 255, 120), // Texel color.
311 SK_ColorGREEN
, // Background color.
312 true, // Premultiplied alpha.
313 texture_quad_state
.get(),
314 this->resource_provider_
.get());
315 pass
->quad_list
.push_back(texture_quad
.PassAs
<DrawQuad
>());
317 scoped_ptr
<SharedQuadState
> color_quad_state
=
318 CreateTestSharedQuadState(gfx::Transform(), rect
);
319 scoped_ptr
<SolidColorDrawQuad
> color_quad
= SolidColorDrawQuad::Create();
320 color_quad
->SetNew(color_quad_state
.get(), rect
, rect
, SK_ColorWHITE
, false);
321 pass
->quad_list
.push_back(color_quad
.PassAs
<DrawQuad
>());
323 RenderPassList pass_list
;
324 pass_list
.push_back(pass
.Pass());
326 EXPECT_TRUE(this->RunPixelTest(
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.
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
, 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(
360 base::FilePath(FILE_PATH_LITERAL("green_alpha.png")),
361 FuzzyPixelOffByOneComparator(true)));
364 // TODO(skaslev): The software renderer does not support non-premultplied alpha.
365 TEST_F(GLRendererPixelTest
, NonPremultipliedTextureWithBackground
) {
366 gfx::Rect
rect(this->device_viewport_size_
);
368 RenderPass::Id
id(1, 1);
369 scoped_ptr
<RenderPass
> pass
= CreateTestRootRenderPass(id
, rect
);
371 scoped_ptr
<SharedQuadState
> texture_quad_state
=
372 CreateTestSharedQuadState(gfx::Transform(), rect
);
373 texture_quad_state
->opacity
= 0.8f
;
375 scoped_ptr
<TextureDrawQuad
> texture_quad
= CreateTestTextureDrawQuad(
376 gfx::Rect(this->device_viewport_size_
),
377 SkColorSetARGB(204, 120, 255, 120), // Texel color.
378 SK_ColorGREEN
, // Background color.
379 false, // Premultiplied alpha.
380 texture_quad_state
.get(),
381 this->resource_provider_
.get());
382 pass
->quad_list
.push_back(texture_quad
.PassAs
<DrawQuad
>());
384 scoped_ptr
<SharedQuadState
> color_quad_state
=
385 CreateTestSharedQuadState(gfx::Transform(), rect
);
386 scoped_ptr
<SolidColorDrawQuad
> color_quad
= SolidColorDrawQuad::Create();
387 color_quad
->SetNew(color_quad_state
.get(), rect
, rect
, SK_ColorWHITE
, false);
388 pass
->quad_list
.push_back(color_quad
.PassAs
<DrawQuad
>());
390 RenderPassList pass_list
;
391 pass_list
.push_back(pass
.Pass());
393 EXPECT_TRUE(this->RunPixelTest(
395 base::FilePath(FILE_PATH_LITERAL("green_alpha.png")),
396 FuzzyPixelOffByOneComparator(true)));
399 class VideoGLRendererPixelTest
: public GLRendererPixelTest
{
401 scoped_ptr
<YUVVideoDrawQuad
> CreateTestYUVVideoDrawQuad_Striped(
402 SharedQuadState
* shared_state
,
403 media::VideoFrame::Format format
,
405 const gfx::RectF
& tex_coord_rect
) {
406 const gfx::Rect
rect(this->device_viewport_size_
);
408 scoped_refptr
<media::VideoFrame
> video_frame
=
409 media::VideoFrame::CreateFrame(
410 format
, rect
.size(), rect
, rect
.size(), base::TimeDelta());
412 // YUV values representing a striped pattern, for validating texture
413 // coordinates for sampling.
417 for (int i
= 0; i
< video_frame
->rows(media::VideoFrame::kYPlane
); ++i
) {
418 uint8_t* y_row
= video_frame
->data(media::VideoFrame::kYPlane
) +
419 video_frame
->stride(media::VideoFrame::kYPlane
) * i
;
420 for (int j
= 0; j
< video_frame
->row_bytes(media::VideoFrame::kYPlane
);
422 y_row
[j
] = (y_value
+= 1);
425 for (int i
= 0; i
< video_frame
->rows(media::VideoFrame::kUPlane
); ++i
) {
426 uint8_t* u_row
= video_frame
->data(media::VideoFrame::kUPlane
) +
427 video_frame
->stride(media::VideoFrame::kUPlane
) * i
;
428 uint8_t* v_row
= video_frame
->data(media::VideoFrame::kVPlane
) +
429 video_frame
->stride(media::VideoFrame::kVPlane
) * i
;
430 for (int j
= 0; j
< video_frame
->row_bytes(media::VideoFrame::kUPlane
);
432 u_row
[j
] = (u_value
+= 3);
433 v_row
[j
] = (v_value
+= 5);
436 return CreateTestYUVVideoDrawQuad_FromVideoFrame(
437 shared_state
, video_frame
, is_transparent
, tex_coord_rect
);
440 scoped_ptr
<YUVVideoDrawQuad
> CreateTestYUVVideoDrawQuad_Solid(
441 SharedQuadState
* shared_state
,
442 media::VideoFrame::Format format
,
444 const gfx::RectF
& tex_coord_rect
,
448 const gfx::Rect
rect(this->device_viewport_size_
);
450 scoped_refptr
<media::VideoFrame
> video_frame
=
451 media::VideoFrame::CreateFrame(
452 format
, rect
.size(), rect
, rect
.size(), base::TimeDelta());
454 // YUV values of a solid, constant, color. Useful for testing that color
455 // space/color range are being handled properly.
456 memset(video_frame
->data(media::VideoFrame::kYPlane
),
458 video_frame
->stride(media::VideoFrame::kYPlane
) *
459 video_frame
->rows(media::VideoFrame::kYPlane
));
460 memset(video_frame
->data(media::VideoFrame::kUPlane
),
462 video_frame
->stride(media::VideoFrame::kUPlane
) *
463 video_frame
->rows(media::VideoFrame::kUPlane
));
464 memset(video_frame
->data(media::VideoFrame::kVPlane
),
466 video_frame
->stride(media::VideoFrame::kVPlane
) *
467 video_frame
->rows(media::VideoFrame::kVPlane
));
469 return CreateTestYUVVideoDrawQuad_FromVideoFrame(
470 shared_state
, video_frame
, is_transparent
, tex_coord_rect
);
473 scoped_ptr
<YUVVideoDrawQuad
> CreateTestYUVVideoDrawQuad_FromVideoFrame(
474 SharedQuadState
* shared_state
,
475 scoped_refptr
<media::VideoFrame
> video_frame
,
477 const gfx::RectF
& tex_coord_rect
) {
478 const bool with_alpha
= (video_frame
->format() == media::VideoFrame::YV12A
);
479 const YUVVideoDrawQuad::ColorSpace color_space
=
480 (video_frame
->format() == media::VideoFrame::YV12J
481 ? YUVVideoDrawQuad::REC_601_JPEG
482 : YUVVideoDrawQuad::REC_601
);
483 const gfx::Rect
rect(this->device_viewport_size_
);
484 const gfx::Rect
opaque_rect(0, 0, 0, 0);
487 memset(video_frame
->data(media::VideoFrame::kAPlane
),
488 is_transparent
? 0 : 128,
489 video_frame
->stride(media::VideoFrame::kAPlane
) *
490 video_frame
->rows(media::VideoFrame::kAPlane
));
492 VideoFrameExternalResources resources
=
493 video_resource_updater_
->CreateExternalResourcesFromVideoFrame(
496 EXPECT_EQ(VideoFrameExternalResources::YUV_RESOURCE
, resources
.type
);
497 EXPECT_EQ(media::VideoFrame::NumPlanes(video_frame
->format()),
498 resources
.mailboxes
.size());
499 EXPECT_EQ(media::VideoFrame::NumPlanes(video_frame
->format()),
500 resources
.release_callbacks
.size());
502 ResourceProvider::ResourceId y_resource
=
503 resource_provider_
->CreateResourceFromTextureMailbox(
504 resources
.mailboxes
[media::VideoFrame::kYPlane
],
505 SingleReleaseCallback::Create(
506 resources
.release_callbacks
[media::VideoFrame::kYPlane
]));
507 ResourceProvider::ResourceId u_resource
=
508 resource_provider_
->CreateResourceFromTextureMailbox(
509 resources
.mailboxes
[media::VideoFrame::kUPlane
],
510 SingleReleaseCallback::Create(
511 resources
.release_callbacks
[media::VideoFrame::kUPlane
]));
512 ResourceProvider::ResourceId v_resource
=
513 resource_provider_
->CreateResourceFromTextureMailbox(
514 resources
.mailboxes
[media::VideoFrame::kVPlane
],
515 SingleReleaseCallback::Create(
516 resources
.release_callbacks
[media::VideoFrame::kVPlane
]));
517 ResourceProvider::ResourceId a_resource
= 0;
519 a_resource
= resource_provider_
->CreateResourceFromTextureMailbox(
520 resources
.mailboxes
[media::VideoFrame::kAPlane
],
521 SingleReleaseCallback::Create(
522 resources
.release_callbacks
[media::VideoFrame::kAPlane
]));
525 scoped_ptr
<YUVVideoDrawQuad
> yuv_quad
= YUVVideoDrawQuad::Create();
526 yuv_quad
->SetNew(shared_state
,
536 return yuv_quad
.Pass();
539 virtual void SetUp() OVERRIDE
{
540 GLRendererPixelTest::SetUp();
541 video_resource_updater_
.reset(new VideoResourceUpdater(
542 output_surface_
->context_provider().get(), resource_provider_
.get()));
546 scoped_ptr
<VideoResourceUpdater
> video_resource_updater_
;
549 TEST_F(VideoGLRendererPixelTest
, SimpleYUVRect
) {
550 gfx::Rect
rect(this->device_viewport_size_
);
552 RenderPass::Id
id(1, 1);
553 scoped_ptr
<RenderPass
> pass
= CreateTestRootRenderPass(id
, rect
);
555 scoped_ptr
<SharedQuadState
> shared_state
=
556 CreateTestSharedQuadState(gfx::Transform(), rect
);
558 scoped_ptr
<YUVVideoDrawQuad
> yuv_quad
=
559 CreateTestYUVVideoDrawQuad_Striped(shared_state
.get(),
560 media::VideoFrame::YV12
,
562 gfx::RectF(0.0f
, 0.0f
, 1.0f
, 1.0f
));
564 pass
->quad_list
.push_back(yuv_quad
.PassAs
<DrawQuad
>());
566 RenderPassList pass_list
;
567 pass_list
.push_back(pass
.Pass());
570 this->RunPixelTest(&pass_list
,
571 base::FilePath(FILE_PATH_LITERAL("yuv_stripes.png")),
572 FuzzyPixelOffByOneComparator(true)));
575 TEST_F(VideoGLRendererPixelTest
, OffsetYUVRect
) {
576 gfx::Rect
rect(this->device_viewport_size_
);
578 RenderPass::Id
id(1, 1);
579 scoped_ptr
<RenderPass
> pass
= CreateTestRootRenderPass(id
, rect
);
581 scoped_ptr
<SharedQuadState
> shared_state
=
582 CreateTestSharedQuadState(gfx::Transform(), rect
);
584 // Intentionally sets frame format to I420 for testing coverage.
585 scoped_ptr
<YUVVideoDrawQuad
> yuv_quad
= CreateTestYUVVideoDrawQuad_Striped(
587 media::VideoFrame::I420
,
589 gfx::RectF(0.125f
, 0.25f
, 0.75f
, 0.5f
));
591 pass
->quad_list
.push_back(yuv_quad
.PassAs
<DrawQuad
>());
593 RenderPassList pass_list
;
594 pass_list
.push_back(pass
.Pass());
596 EXPECT_TRUE(this->RunPixelTest(
598 base::FilePath(FILE_PATH_LITERAL("yuv_stripes_offset.png")),
599 FuzzyPixelOffByOneComparator(true)));
602 TEST_F(VideoGLRendererPixelTest
, SimpleYUVRectBlack
) {
603 gfx::Rect
rect(this->device_viewport_size_
);
605 RenderPass::Id
id(1, 1);
606 scoped_ptr
<RenderPass
> pass
= CreateTestRootRenderPass(id
, rect
);
608 scoped_ptr
<SharedQuadState
> shared_state
=
609 CreateTestSharedQuadState(gfx::Transform(), rect
);
611 // In MPEG color range YUV values of (15,128,128) should produce black.
612 scoped_ptr
<YUVVideoDrawQuad
> yuv_quad
=
613 CreateTestYUVVideoDrawQuad_Solid(shared_state
.get(),
614 media::VideoFrame::YV12
,
616 gfx::RectF(0.0f
, 0.0f
, 1.0f
, 1.0f
),
621 pass
->quad_list
.push_back(yuv_quad
.PassAs
<DrawQuad
>());
623 RenderPassList pass_list
;
624 pass_list
.push_back(pass
.Pass());
626 // If we didn't get black out of the YUV values above, then we probably have a
627 // color range issue.
628 EXPECT_TRUE(this->RunPixelTest(&pass_list
,
629 base::FilePath(FILE_PATH_LITERAL("black.png")),
630 FuzzyPixelOffByOneComparator(true)));
633 TEST_F(VideoGLRendererPixelTest
, SimpleYUVJRect
) {
634 gfx::Rect
rect(this->device_viewport_size_
);
636 RenderPass::Id
id(1, 1);
637 scoped_ptr
<RenderPass
> pass
= CreateTestRootRenderPass(id
, rect
);
639 scoped_ptr
<SharedQuadState
> shared_state
=
640 CreateTestSharedQuadState(gfx::Transform(), rect
);
642 // YUV of (149,43,21) should be green (0,255,0) in RGB.
643 scoped_ptr
<YUVVideoDrawQuad
> yuv_quad
=
644 CreateTestYUVVideoDrawQuad_Solid(shared_state
.get(),
645 media::VideoFrame::YV12J
,
647 gfx::RectF(0.0f
, 0.0f
, 1.0f
, 1.0f
),
652 pass
->quad_list
.push_back(yuv_quad
.PassAs
<DrawQuad
>());
654 RenderPassList pass_list
;
655 pass_list
.push_back(pass
.Pass());
657 EXPECT_TRUE(this->RunPixelTest(&pass_list
,
658 base::FilePath(FILE_PATH_LITERAL("green.png")),
659 FuzzyPixelOffByOneComparator(true)));
662 TEST_F(VideoGLRendererPixelTest
, SimpleYUVJRectGrey
) {
663 gfx::Rect
rect(this->device_viewport_size_
);
665 RenderPass::Id
id(1, 1);
666 scoped_ptr
<RenderPass
> pass
= CreateTestRootRenderPass(id
, rect
);
668 scoped_ptr
<SharedQuadState
> shared_state
=
669 CreateTestSharedQuadState(gfx::Transform(), rect
);
671 // Dark grey in JPEG color range (in MPEG, this is black).
672 scoped_ptr
<YUVVideoDrawQuad
> yuv_quad
=
673 CreateTestYUVVideoDrawQuad_Solid(shared_state
.get(),
674 media::VideoFrame::YV12J
,
676 gfx::RectF(0.0f
, 0.0f
, 1.0f
, 1.0f
),
681 pass
->quad_list
.push_back(yuv_quad
.PassAs
<DrawQuad
>());
683 RenderPassList pass_list
;
684 pass_list
.push_back(pass
.Pass());
687 this->RunPixelTest(&pass_list
,
688 base::FilePath(FILE_PATH_LITERAL("dark_grey.png")),
689 FuzzyPixelOffByOneComparator(true)));
692 TEST_F(VideoGLRendererPixelTest
, SimpleYUVARect
) {
693 gfx::Rect
rect(this->device_viewport_size_
);
695 RenderPass::Id
id(1, 1);
696 scoped_ptr
<RenderPass
> pass
= CreateTestRootRenderPass(id
, rect
);
698 scoped_ptr
<SharedQuadState
> shared_state
=
699 CreateTestSharedQuadState(gfx::Transform(), rect
);
701 scoped_ptr
<YUVVideoDrawQuad
> yuv_quad
=
702 CreateTestYUVVideoDrawQuad_Striped(shared_state
.get(),
703 media::VideoFrame::YV12A
,
705 gfx::RectF(0.0f
, 0.0f
, 1.0f
, 1.0f
));
707 pass
->quad_list
.push_back(yuv_quad
.PassAs
<DrawQuad
>());
709 scoped_ptr
<SolidColorDrawQuad
> color_quad
= SolidColorDrawQuad::Create();
710 color_quad
->SetNew(shared_state
.get(), rect
, rect
, SK_ColorWHITE
, false);
712 pass
->quad_list
.push_back(color_quad
.PassAs
<DrawQuad
>());
714 RenderPassList pass_list
;
715 pass_list
.push_back(pass
.Pass());
717 EXPECT_TRUE(this->RunPixelTest(
719 base::FilePath(FILE_PATH_LITERAL("yuv_stripes_alpha.png")),
720 FuzzyPixelOffByOneComparator(true)));
723 TEST_F(VideoGLRendererPixelTest
, FullyTransparentYUVARect
) {
724 gfx::Rect
rect(this->device_viewport_size_
);
726 RenderPass::Id
id(1, 1);
727 scoped_ptr
<RenderPass
> pass
= CreateTestRootRenderPass(id
, rect
);
729 scoped_ptr
<SharedQuadState
> shared_state
=
730 CreateTestSharedQuadState(gfx::Transform(), rect
);
732 scoped_ptr
<YUVVideoDrawQuad
> yuv_quad
=
733 CreateTestYUVVideoDrawQuad_Striped(shared_state
.get(),
734 media::VideoFrame::YV12A
,
736 gfx::RectF(0.0f
, 0.0f
, 1.0f
, 1.0f
));
738 pass
->quad_list
.push_back(yuv_quad
.PassAs
<DrawQuad
>());
740 scoped_ptr
<SolidColorDrawQuad
> color_quad
= SolidColorDrawQuad::Create();
741 color_quad
->SetNew(shared_state
.get(), rect
, rect
, SK_ColorBLACK
, false);
743 pass
->quad_list
.push_back(color_quad
.PassAs
<DrawQuad
>());
745 RenderPassList pass_list
;
746 pass_list
.push_back(pass
.Pass());
748 EXPECT_TRUE(this->RunPixelTest(
750 base::FilePath(FILE_PATH_LITERAL("black.png")),
751 ExactPixelComparator(true)));
754 TYPED_TEST(RendererPixelTest
, FastPassColorFilterAlpha
) {
755 gfx::Rect
viewport_rect(this->device_viewport_size_
);
757 RenderPass::Id
root_pass_id(1, 1);
758 scoped_ptr
<RenderPass
> root_pass
=
759 CreateTestRootRenderPass(root_pass_id
, viewport_rect
);
761 RenderPass::Id
child_pass_id(2, 2);
762 gfx::Rect
pass_rect(this->device_viewport_size_
);
763 gfx::Transform transform_to_root
;
764 scoped_ptr
<RenderPass
> child_pass
=
765 CreateTestRenderPass(child_pass_id
, pass_rect
, transform_to_root
);
767 gfx::Transform content_to_target_transform
;
768 scoped_ptr
<SharedQuadState
> shared_state
=
769 CreateTestSharedQuadState(content_to_target_transform
, viewport_rect
);
770 shared_state
->opacity
= 0.5f
;
772 gfx::Rect
blue_rect(0,
774 this->device_viewport_size_
.width(),
775 this->device_viewport_size_
.height() / 2);
776 scoped_ptr
<SolidColorDrawQuad
> blue
= SolidColorDrawQuad::Create();
777 blue
->SetNew(shared_state
.get(), blue_rect
, blue_rect
, SK_ColorBLUE
, false);
778 gfx::Rect
yellow_rect(0,
779 this->device_viewport_size_
.height() / 2,
780 this->device_viewport_size_
.width(),
781 this->device_viewport_size_
.height() / 2);
782 scoped_ptr
<SolidColorDrawQuad
> yellow
= SolidColorDrawQuad::Create();
784 shared_state
.get(), yellow_rect
, yellow_rect
, SK_ColorYELLOW
, false);
786 scoped_ptr
<SharedQuadState
> blank_state
=
787 CreateTestSharedQuadState(content_to_target_transform
, viewport_rect
);
789 scoped_ptr
<SolidColorDrawQuad
> white
= SolidColorDrawQuad::Create();
791 blank_state
.get(), viewport_rect
, viewport_rect
, SK_ColorWHITE
, false);
793 child_pass
->quad_list
.push_back(blue
.PassAs
<DrawQuad
>());
794 child_pass
->quad_list
.push_back(yellow
.PassAs
<DrawQuad
>());
795 child_pass
->quad_list
.push_back(white
.PassAs
<DrawQuad
>());
797 scoped_ptr
<SharedQuadState
> pass_shared_state
=
798 CreateTestSharedQuadState(gfx::Transform(), pass_rect
);
802 matrix
[0] = 0.213f
+ 0.787f
* amount
;
803 matrix
[1] = 0.715f
- 0.715f
* amount
;
804 matrix
[2] = 1.f
- (matrix
[0] + matrix
[1]);
805 matrix
[3] = matrix
[4] = 0;
806 matrix
[5] = 0.213f
- 0.213f
* amount
;
807 matrix
[6] = 0.715f
+ 0.285f
* amount
;
808 matrix
[7] = 1.f
- (matrix
[5] + matrix
[6]);
809 matrix
[8] = matrix
[9] = 0;
810 matrix
[10] = 0.213f
- 0.213f
* amount
;
811 matrix
[11] = 0.715f
- 0.715f
* amount
;
812 matrix
[12] = 1.f
- (matrix
[10] + matrix
[11]);
813 matrix
[13] = matrix
[14] = 0;
814 matrix
[15] = matrix
[16] = matrix
[17] = matrix
[19] = 0;
816 skia::RefPtr
<SkColorFilter
> colorFilter(skia::AdoptRef(
817 new SkColorMatrixFilter(matrix
)));
818 skia::RefPtr
<SkImageFilter
> filter
=
819 skia::AdoptRef(SkColorFilterImageFilter::Create(colorFilter
.get(), NULL
));
820 FilterOperations filters
;
821 filters
.Append(FilterOperation::CreateReferenceFilter(filter
));
823 scoped_ptr
<RenderPassDrawQuad
> render_pass_quad
=
824 RenderPassDrawQuad::Create();
825 render_pass_quad
->SetNew(pass_shared_state
.get(),
836 root_pass
->quad_list
.push_back(render_pass_quad
.PassAs
<DrawQuad
>());
838 RenderPassList pass_list
;
839 pass_list
.push_back(child_pass
.Pass());
840 pass_list
.push_back(root_pass
.Pass());
842 // This test has alpha=254 for the software renderer vs. alpha=255 for the gl
843 // renderer so use a fuzzy comparator.
844 EXPECT_TRUE(this->RunPixelTest(
846 base::FilePath(FILE_PATH_LITERAL("blue_yellow_alpha.png")),
847 FuzzyForSoftwareOnlyPixelComparator
<TypeParam
>(false)));
850 TYPED_TEST(RendererPixelTest
, FastPassSaturateFilter
) {
851 gfx::Rect
viewport_rect(this->device_viewport_size_
);
853 RenderPass::Id
root_pass_id(1, 1);
854 scoped_ptr
<RenderPass
> root_pass
=
855 CreateTestRootRenderPass(root_pass_id
, viewport_rect
);
857 RenderPass::Id
child_pass_id(2, 2);
858 gfx::Rect
pass_rect(this->device_viewport_size_
);
859 gfx::Transform transform_to_root
;
860 scoped_ptr
<RenderPass
> child_pass
=
861 CreateTestRenderPass(child_pass_id
, pass_rect
, transform_to_root
);
863 gfx::Transform content_to_target_transform
;
864 scoped_ptr
<SharedQuadState
> shared_state
=
865 CreateTestSharedQuadState(content_to_target_transform
, viewport_rect
);
866 shared_state
->opacity
= 0.5f
;
868 gfx::Rect
blue_rect(0,
870 this->device_viewport_size_
.width(),
871 this->device_viewport_size_
.height() / 2);
872 scoped_ptr
<SolidColorDrawQuad
> blue
= SolidColorDrawQuad::Create();
873 blue
->SetNew(shared_state
.get(), blue_rect
, blue_rect
, SK_ColorBLUE
, false);
874 gfx::Rect
yellow_rect(0,
875 this->device_viewport_size_
.height() / 2,
876 this->device_viewport_size_
.width(),
877 this->device_viewport_size_
.height() / 2);
878 scoped_ptr
<SolidColorDrawQuad
> yellow
= SolidColorDrawQuad::Create();
880 shared_state
.get(), yellow_rect
, yellow_rect
, SK_ColorYELLOW
, false);
882 scoped_ptr
<SharedQuadState
> blank_state
=
883 CreateTestSharedQuadState(content_to_target_transform
, viewport_rect
);
885 scoped_ptr
<SolidColorDrawQuad
> white
= SolidColorDrawQuad::Create();
887 blank_state
.get(), viewport_rect
, viewport_rect
, SK_ColorWHITE
, false);
889 child_pass
->quad_list
.push_back(blue
.PassAs
<DrawQuad
>());
890 child_pass
->quad_list
.push_back(yellow
.PassAs
<DrawQuad
>());
891 child_pass
->quad_list
.push_back(white
.PassAs
<DrawQuad
>());
893 scoped_ptr
<SharedQuadState
> pass_shared_state
=
894 CreateTestSharedQuadState(gfx::Transform(), pass_rect
);
896 FilterOperations filters
;
897 filters
.Append(FilterOperation::CreateSaturateFilter(0.5f
));
899 scoped_ptr
<RenderPassDrawQuad
> render_pass_quad
=
900 RenderPassDrawQuad::Create();
901 render_pass_quad
->SetNew(pass_shared_state
.get(),
912 root_pass
->quad_list
.push_back(render_pass_quad
.PassAs
<DrawQuad
>());
914 RenderPassList pass_list
;
915 pass_list
.push_back(child_pass
.Pass());
916 pass_list
.push_back(root_pass
.Pass());
918 EXPECT_TRUE(this->RunPixelTest(
920 base::FilePath(FILE_PATH_LITERAL("blue_yellow_alpha.png")),
921 ExactPixelComparator(true)));
924 TYPED_TEST(RendererPixelTest
, FastPassFilterChain
) {
925 gfx::Rect
viewport_rect(this->device_viewport_size_
);
927 RenderPass::Id
root_pass_id(1, 1);
928 scoped_ptr
<RenderPass
> root_pass
=
929 CreateTestRootRenderPass(root_pass_id
, viewport_rect
);
931 RenderPass::Id
child_pass_id(2, 2);
932 gfx::Rect
pass_rect(this->device_viewport_size_
);
933 gfx::Transform transform_to_root
;
934 scoped_ptr
<RenderPass
> child_pass
=
935 CreateTestRenderPass(child_pass_id
, pass_rect
, transform_to_root
);
937 gfx::Transform content_to_target_transform
;
938 scoped_ptr
<SharedQuadState
> shared_state
=
939 CreateTestSharedQuadState(content_to_target_transform
, viewport_rect
);
940 shared_state
->opacity
= 0.5f
;
942 gfx::Rect
blue_rect(0,
944 this->device_viewport_size_
.width(),
945 this->device_viewport_size_
.height() / 2);
946 scoped_ptr
<SolidColorDrawQuad
> blue
= SolidColorDrawQuad::Create();
947 blue
->SetNew(shared_state
.get(), blue_rect
, blue_rect
, SK_ColorBLUE
, false);
948 gfx::Rect
yellow_rect(0,
949 this->device_viewport_size_
.height() / 2,
950 this->device_viewport_size_
.width(),
951 this->device_viewport_size_
.height() / 2);
952 scoped_ptr
<SolidColorDrawQuad
> yellow
= SolidColorDrawQuad::Create();
954 shared_state
.get(), yellow_rect
, yellow_rect
, SK_ColorYELLOW
, false);
956 scoped_ptr
<SharedQuadState
> blank_state
=
957 CreateTestSharedQuadState(content_to_target_transform
, viewport_rect
);
959 scoped_ptr
<SolidColorDrawQuad
> white
= SolidColorDrawQuad::Create();
961 blank_state
.get(), viewport_rect
, viewport_rect
, SK_ColorWHITE
, false);
963 child_pass
->quad_list
.push_back(blue
.PassAs
<DrawQuad
>());
964 child_pass
->quad_list
.push_back(yellow
.PassAs
<DrawQuad
>());
965 child_pass
->quad_list
.push_back(white
.PassAs
<DrawQuad
>());
967 scoped_ptr
<SharedQuadState
> pass_shared_state
=
968 CreateTestSharedQuadState(gfx::Transform(), pass_rect
);
970 FilterOperations filters
;
971 filters
.Append(FilterOperation::CreateGrayscaleFilter(1.f
));
972 filters
.Append(FilterOperation::CreateBrightnessFilter(0.5f
));
974 scoped_ptr
<RenderPassDrawQuad
> render_pass_quad
=
975 RenderPassDrawQuad::Create();
976 render_pass_quad
->SetNew(pass_shared_state
.get(),
987 root_pass
->quad_list
.push_back(render_pass_quad
.PassAs
<DrawQuad
>());
989 RenderPassList pass_list
;
990 pass_list
.push_back(child_pass
.Pass());
991 pass_list
.push_back(root_pass
.Pass());
993 EXPECT_TRUE(this->RunPixelTest(
995 base::FilePath(FILE_PATH_LITERAL("blue_yellow_filter_chain.png")),
996 ExactPixelComparator(true)));
999 TYPED_TEST(RendererPixelTest
, FastPassColorFilterAlphaTranslation
) {
1000 gfx::Rect
viewport_rect(this->device_viewport_size_
);
1002 RenderPass::Id
root_pass_id(1, 1);
1003 scoped_ptr
<RenderPass
> root_pass
=
1004 CreateTestRootRenderPass(root_pass_id
, viewport_rect
);
1006 RenderPass::Id
child_pass_id(2, 2);
1007 gfx::Rect
pass_rect(this->device_viewport_size_
);
1008 gfx::Transform transform_to_root
;
1009 scoped_ptr
<RenderPass
> child_pass
=
1010 CreateTestRenderPass(child_pass_id
, pass_rect
, transform_to_root
);
1012 gfx::Transform content_to_target_transform
;
1013 scoped_ptr
<SharedQuadState
> shared_state
=
1014 CreateTestSharedQuadState(content_to_target_transform
, viewport_rect
);
1015 shared_state
->opacity
= 0.5f
;
1017 gfx::Rect
blue_rect(0,
1019 this->device_viewport_size_
.width(),
1020 this->device_viewport_size_
.height() / 2);
1021 scoped_ptr
<SolidColorDrawQuad
> blue
= SolidColorDrawQuad::Create();
1022 blue
->SetNew(shared_state
.get(), blue_rect
, blue_rect
, SK_ColorBLUE
, false);
1023 gfx::Rect
yellow_rect(0,
1024 this->device_viewport_size_
.height() / 2,
1025 this->device_viewport_size_
.width(),
1026 this->device_viewport_size_
.height() / 2);
1027 scoped_ptr
<SolidColorDrawQuad
> yellow
= SolidColorDrawQuad::Create();
1029 shared_state
.get(), yellow_rect
, yellow_rect
, SK_ColorYELLOW
, false);
1031 scoped_ptr
<SharedQuadState
> blank_state
=
1032 CreateTestSharedQuadState(content_to_target_transform
, viewport_rect
);
1034 scoped_ptr
<SolidColorDrawQuad
> white
= SolidColorDrawQuad::Create();
1036 blank_state
.get(), viewport_rect
, viewport_rect
, SK_ColorWHITE
, false);
1038 child_pass
->quad_list
.push_back(blue
.PassAs
<DrawQuad
>());
1039 child_pass
->quad_list
.push_back(yellow
.PassAs
<DrawQuad
>());
1040 child_pass
->quad_list
.push_back(white
.PassAs
<DrawQuad
>());
1042 scoped_ptr
<SharedQuadState
> pass_shared_state
=
1043 CreateTestSharedQuadState(gfx::Transform(), pass_rect
);
1045 SkScalar matrix
[20];
1046 float amount
= 0.5f
;
1047 matrix
[0] = 0.213f
+ 0.787f
* amount
;
1048 matrix
[1] = 0.715f
- 0.715f
* amount
;
1049 matrix
[2] = 1.f
- (matrix
[0] + matrix
[1]);
1052 matrix
[5] = 0.213f
- 0.213f
* amount
;
1053 matrix
[6] = 0.715f
+ 0.285f
* amount
;
1054 matrix
[7] = 1.f
- (matrix
[5] + matrix
[6]);
1057 matrix
[10] = 0.213f
- 0.213f
* amount
;
1058 matrix
[11] = 0.715f
- 0.715f
* amount
;
1059 matrix
[12] = 1.f
- (matrix
[10] + matrix
[11]);
1062 matrix
[15] = matrix
[16] = matrix
[17] = matrix
[19] = 0;
1064 skia::RefPtr
<SkColorFilter
> colorFilter(skia::AdoptRef(
1065 new SkColorMatrixFilter(matrix
)));
1066 skia::RefPtr
<SkImageFilter
> filter
=
1067 skia::AdoptRef(SkColorFilterImageFilter::Create(colorFilter
.get(), NULL
));
1068 FilterOperations filters
;
1069 filters
.Append(FilterOperation::CreateReferenceFilter(filter
));
1071 scoped_ptr
<RenderPassDrawQuad
> render_pass_quad
=
1072 RenderPassDrawQuad::Create();
1073 render_pass_quad
->SetNew(pass_shared_state
.get(),
1082 FilterOperations());
1084 root_pass
->quad_list
.push_back(render_pass_quad
.PassAs
<DrawQuad
>());
1085 RenderPassList pass_list
;
1087 pass_list
.push_back(child_pass
.Pass());
1088 pass_list
.push_back(root_pass
.Pass());
1090 // This test has alpha=254 for the software renderer vs. alpha=255 for the gl
1091 // renderer so use a fuzzy comparator.
1092 EXPECT_TRUE(this->RunPixelTest(
1094 base::FilePath(FILE_PATH_LITERAL("blue_yellow_alpha_translate.png")),
1095 FuzzyForSoftwareOnlyPixelComparator
<TypeParam
>(false)));
1098 TYPED_TEST(RendererPixelTest
, EnlargedRenderPassTexture
) {
1099 gfx::Rect
viewport_rect(this->device_viewport_size_
);
1101 RenderPass::Id
root_pass_id(1, 1);
1102 scoped_ptr
<RenderPass
> root_pass
=
1103 CreateTestRootRenderPass(root_pass_id
, viewport_rect
);
1105 RenderPass::Id
child_pass_id(2, 2);
1106 gfx::Rect
pass_rect(this->device_viewport_size_
);
1107 gfx::Transform transform_to_root
;
1108 scoped_ptr
<RenderPass
> child_pass
=
1109 CreateTestRenderPass(child_pass_id
, pass_rect
, transform_to_root
);
1111 gfx::Transform content_to_target_transform
;
1112 scoped_ptr
<SharedQuadState
> shared_state
=
1113 CreateTestSharedQuadState(content_to_target_transform
, viewport_rect
);
1115 gfx::Rect
blue_rect(0,
1117 this->device_viewport_size_
.width(),
1118 this->device_viewport_size_
.height() / 2);
1119 scoped_ptr
<SolidColorDrawQuad
> blue
= SolidColorDrawQuad::Create();
1120 blue
->SetNew(shared_state
.get(), blue_rect
, blue_rect
, SK_ColorBLUE
, false);
1121 gfx::Rect
yellow_rect(0,
1122 this->device_viewport_size_
.height() / 2,
1123 this->device_viewport_size_
.width(),
1124 this->device_viewport_size_
.height() / 2);
1125 scoped_ptr
<SolidColorDrawQuad
> yellow
= SolidColorDrawQuad::Create();
1127 shared_state
.get(), yellow_rect
, yellow_rect
, SK_ColorYELLOW
, false);
1129 child_pass
->quad_list
.push_back(blue
.PassAs
<DrawQuad
>());
1130 child_pass
->quad_list
.push_back(yellow
.PassAs
<DrawQuad
>());
1132 scoped_ptr
<SharedQuadState
> pass_shared_state
=
1133 CreateTestSharedQuadState(gfx::Transform(), pass_rect
);
1134 root_pass
->quad_list
.push_back(
1135 CreateTestRenderPassDrawQuad(pass_shared_state
.get(),
1139 RenderPassList pass_list
;
1140 pass_list
.push_back(child_pass
.Pass());
1141 pass_list
.push_back(root_pass
.Pass());
1143 this->renderer_
->SetEnlargePassTextureAmountForTesting(gfx::Vector2d(50, 75));
1145 EXPECT_TRUE(this->RunPixelTest(
1147 base::FilePath(FILE_PATH_LITERAL("blue_yellow.png")),
1148 ExactPixelComparator(true)));
1151 TYPED_TEST(RendererPixelTest
, EnlargedRenderPassTextureWithAntiAliasing
) {
1152 gfx::Rect
viewport_rect(this->device_viewport_size_
);
1154 RenderPass::Id
root_pass_id(1, 1);
1155 scoped_ptr
<RenderPass
> root_pass
=
1156 CreateTestRootRenderPass(root_pass_id
, viewport_rect
);
1158 RenderPass::Id
child_pass_id(2, 2);
1159 gfx::Rect
pass_rect(this->device_viewport_size_
);
1160 gfx::Transform transform_to_root
;
1161 scoped_ptr
<RenderPass
> child_pass
=
1162 CreateTestRenderPass(child_pass_id
, pass_rect
, transform_to_root
);
1164 gfx::Transform content_to_target_transform
;
1165 scoped_ptr
<SharedQuadState
> shared_state
=
1166 CreateTestSharedQuadState(content_to_target_transform
, viewport_rect
);
1168 gfx::Rect
blue_rect(0,
1170 this->device_viewport_size_
.width(),
1171 this->device_viewport_size_
.height() / 2);
1172 scoped_ptr
<SolidColorDrawQuad
> blue
= SolidColorDrawQuad::Create();
1173 blue
->SetNew(shared_state
.get(), blue_rect
, blue_rect
, SK_ColorBLUE
, false);
1174 gfx::Rect
yellow_rect(0,
1175 this->device_viewport_size_
.height() / 2,
1176 this->device_viewport_size_
.width(),
1177 this->device_viewport_size_
.height() / 2);
1178 scoped_ptr
<SolidColorDrawQuad
> yellow
= SolidColorDrawQuad::Create();
1180 shared_state
.get(), yellow_rect
, yellow_rect
, SK_ColorYELLOW
, false);
1182 child_pass
->quad_list
.push_back(blue
.PassAs
<DrawQuad
>());
1183 child_pass
->quad_list
.push_back(yellow
.PassAs
<DrawQuad
>());
1185 gfx::Transform aa_transform
;
1186 aa_transform
.Translate(0.5, 0.0);
1188 scoped_ptr
<SharedQuadState
> pass_shared_state
=
1189 CreateTestSharedQuadState(aa_transform
, pass_rect
);
1190 root_pass
->quad_list
.push_back(
1191 CreateTestRenderPassDrawQuad(pass_shared_state
.get(),
1195 scoped_ptr
<SharedQuadState
> root_shared_state
=
1196 CreateTestSharedQuadState(gfx::Transform(), viewport_rect
);
1197 scoped_ptr
<SolidColorDrawQuad
> background
= SolidColorDrawQuad::Create();
1198 background
->SetNew(root_shared_state
.get(),
1199 gfx::Rect(this->device_viewport_size_
),
1200 gfx::Rect(this->device_viewport_size_
),
1203 root_pass
->quad_list
.push_back(background
.PassAs
<DrawQuad
>());
1205 RenderPassList pass_list
;
1206 pass_list
.push_back(child_pass
.Pass());
1207 pass_list
.push_back(root_pass
.Pass());
1209 this->renderer_
->SetEnlargePassTextureAmountForTesting(gfx::Vector2d(50, 75));
1211 EXPECT_TRUE(this->RunPixelTest(
1213 base::FilePath(FILE_PATH_LITERAL("blue_yellow_anti_aliasing.png")),
1214 FuzzyPixelOffByOneComparator(true)));
1217 // This tests the case where we have a RenderPass with a mask, but the quad
1218 // for the masked surface does not include the full surface texture.
1219 TYPED_TEST(RendererPixelTest
, RenderPassAndMaskWithPartialQuad
) {
1220 gfx::Rect
viewport_rect(this->device_viewport_size_
);
1222 RenderPass::Id
root_pass_id(1, 1);
1223 scoped_ptr
<RenderPass
> root_pass
=
1224 CreateTestRootRenderPass(root_pass_id
, viewport_rect
);
1225 scoped_ptr
<SharedQuadState
> root_pass_shared_state
=
1226 CreateTestSharedQuadState(gfx::Transform(), viewport_rect
);
1228 RenderPass::Id
child_pass_id(2, 2);
1229 gfx::Transform transform_to_root
;
1230 scoped_ptr
<RenderPass
> child_pass
=
1231 CreateTestRenderPass(child_pass_id
, viewport_rect
, transform_to_root
);
1232 scoped_ptr
<SharedQuadState
> child_pass_shared_state
=
1233 CreateTestSharedQuadState(gfx::Transform(), viewport_rect
);
1235 // The child render pass is just a green box.
1236 static const SkColor kCSSGreen
= 0xff008000;
1237 scoped_ptr
<SolidColorDrawQuad
> green
= SolidColorDrawQuad::Create();
1238 green
->SetNew(child_pass_shared_state
.get(),
1243 child_pass
->quad_list
.push_back(green
.PassAs
<DrawQuad
>());
1246 gfx::Rect mask_rect
= viewport_rect
;
1249 SkImageInfo::MakeN32Premul(mask_rect
.width(), mask_rect
.height()));
1250 SkCanvas
canvas(bitmap
);
1252 paint
.setStyle(SkPaint::kStroke_Style
);
1253 paint
.setStrokeWidth(SkIntToScalar(4));
1254 paint
.setColor(SK_ColorWHITE
);
1255 canvas
.clear(SK_ColorTRANSPARENT
);
1256 gfx::Rect rect
= mask_rect
;
1257 while (!rect
.IsEmpty()) {
1258 rect
.Inset(6, 6, 4, 4);
1260 SkRect::MakeXYWH(rect
.x(), rect
.y(), rect
.width(), rect
.height()),
1262 rect
.Inset(6, 6, 4, 4);
1265 ResourceProvider::ResourceId mask_resource_id
=
1266 this->resource_provider_
->CreateResource(
1269 ResourceProvider::TextureUsageAny
,
1272 SkAutoLockPixels
lock(bitmap
);
1273 this->resource_provider_
->SetPixels(
1275 reinterpret_cast<uint8_t*>(bitmap
.getPixels()),
1281 // This RenderPassDrawQuad does not include the full |viewport_rect| which is
1282 // the size of the child render pass.
1283 gfx::Rect sub_rect
= gfx::Rect(50, 50, 100, 100);
1284 EXPECT_NE(sub_rect
.x(), child_pass
->output_rect
.x());
1285 EXPECT_NE(sub_rect
.y(), child_pass
->output_rect
.y());
1286 EXPECT_NE(sub_rect
.right(), child_pass
->output_rect
.right());
1287 EXPECT_NE(sub_rect
.bottom(), child_pass
->output_rect
.bottom());
1288 EXPECT_TRUE(child_pass
->output_rect
.Contains(sub_rect
));
1290 // Set up a mask on the RenderPassDrawQuad.
1291 scoped_ptr
<RenderPassDrawQuad
> mask_quad
= RenderPassDrawQuad::Create();
1292 mask_quad
->SetNew(root_pass_shared_state
.get(),
1296 false, // is_replica
1298 sub_rect
, // contents_changed_since_last_frame
1299 gfx::RectF(1.f
, 1.f
), // mask_uv_rect
1300 FilterOperations(), // foreground filters
1301 FilterOperations()); // background filters
1302 root_pass
->quad_list
.push_back(mask_quad
.PassAs
<DrawQuad
>());
1304 // White background behind the masked render pass.
1305 scoped_ptr
<SolidColorDrawQuad
> white
= SolidColorDrawQuad::Create();
1306 white
->SetNew(root_pass_shared_state
.get(),
1311 root_pass
->quad_list
.push_back(white
.PassAs
<DrawQuad
>());
1313 RenderPassList pass_list
;
1314 pass_list
.push_back(child_pass
.Pass());
1315 pass_list
.push_back(root_pass
.Pass());
1317 EXPECT_TRUE(this->RunPixelTest(
1319 base::FilePath(FILE_PATH_LITERAL("image_mask_of_layer.png")),
1320 ExactPixelComparator(true)));
1323 template <typename RendererType
>
1324 class RendererPixelTestWithBackgroundFilter
1325 : public RendererPixelTest
<RendererType
> {
1327 void SetUpRenderPassList() {
1328 gfx::Rect
device_viewport_rect(this->device_viewport_size_
);
1330 RenderPass::Id
root_id(1, 1);
1331 scoped_ptr
<RenderPass
> root_pass
=
1332 CreateTestRootRenderPass(root_id
, device_viewport_rect
);
1333 root_pass
->has_transparent_background
= false;
1335 gfx::Transform identity_content_to_target_transform
;
1337 RenderPass::Id
filter_pass_id(2, 1);
1338 gfx::Transform transform_to_root
;
1339 scoped_ptr
<RenderPass
> filter_pass
=
1340 CreateTestRenderPass(filter_pass_id
,
1341 filter_pass_content_rect_
,
1344 // A non-visible quad in the filtering render pass.
1346 scoped_ptr
<SharedQuadState
> shared_state
=
1347 CreateTestSharedQuadState(identity_content_to_target_transform
,
1348 filter_pass_content_rect_
);
1349 scoped_ptr
<SolidColorDrawQuad
> color_quad
= SolidColorDrawQuad::Create();
1350 color_quad
->SetNew(shared_state
.get(),
1351 filter_pass_content_rect_
,
1352 filter_pass_content_rect_
,
1353 SK_ColorTRANSPARENT
,
1355 filter_pass
->quad_list
.push_back(color_quad
.PassAs
<DrawQuad
>());
1356 filter_pass
->shared_quad_state_list
.push_back(shared_state
.Pass());
1360 scoped_ptr
<SharedQuadState
> shared_state
=
1361 CreateTestSharedQuadState(filter_pass_to_target_transform_
,
1362 filter_pass_content_rect_
);
1363 scoped_ptr
<RenderPassDrawQuad
> filter_pass_quad
=
1364 RenderPassDrawQuad::Create();
1365 filter_pass_quad
->SetNew(
1367 filter_pass_content_rect_
,
1368 filter_pass_content_rect_
,
1370 false, // is_replica
1371 0, // mask_resource_id
1372 filter_pass_content_rect_
, // contents_changed_since_last_frame
1373 gfx::RectF(), // mask_uv_rect
1374 FilterOperations(), // filters
1375 this->background_filters_
);
1376 root_pass
->quad_list
.push_back(filter_pass_quad
.PassAs
<DrawQuad
>());
1377 root_pass
->shared_quad_state_list
.push_back(shared_state
.Pass());
1380 const int kColumnWidth
= device_viewport_rect
.width() / 3;
1382 gfx::Rect left_rect
= gfx::Rect(0, 0, kColumnWidth
, 20);
1383 for (int i
= 0; left_rect
.y() < device_viewport_rect
.height(); ++i
) {
1384 scoped_ptr
<SharedQuadState
> shared_state
=
1385 CreateTestSharedQuadState(identity_content_to_target_transform
,
1387 scoped_ptr
<SolidColorDrawQuad
> color_quad
= SolidColorDrawQuad::Create();
1389 shared_state
.get(), left_rect
, left_rect
, SK_ColorGREEN
, false);
1390 root_pass
->quad_list
.push_back(color_quad
.PassAs
<DrawQuad
>());
1391 root_pass
->shared_quad_state_list
.push_back(shared_state
.Pass());
1392 left_rect
+= gfx::Vector2d(0, left_rect
.height() + 1);
1395 gfx::Rect middle_rect
= gfx::Rect(kColumnWidth
+1, 0, kColumnWidth
, 20);
1396 for (int i
= 0; middle_rect
.y() < device_viewport_rect
.height(); ++i
) {
1397 scoped_ptr
<SharedQuadState
> shared_state
=
1398 CreateTestSharedQuadState(identity_content_to_target_transform
,
1400 scoped_ptr
<SolidColorDrawQuad
> color_quad
= SolidColorDrawQuad::Create();
1402 shared_state
.get(), middle_rect
, middle_rect
, SK_ColorRED
, false);
1403 root_pass
->quad_list
.push_back(color_quad
.PassAs
<DrawQuad
>());
1404 root_pass
->shared_quad_state_list
.push_back(shared_state
.Pass());
1405 middle_rect
+= gfx::Vector2d(0, middle_rect
.height() + 1);
1408 gfx::Rect right_rect
= gfx::Rect((kColumnWidth
+1)*2, 0, kColumnWidth
, 20);
1409 for (int i
= 0; right_rect
.y() < device_viewport_rect
.height(); ++i
) {
1410 scoped_ptr
<SharedQuadState
> shared_state
=
1411 CreateTestSharedQuadState(identity_content_to_target_transform
,
1413 scoped_ptr
<SolidColorDrawQuad
> color_quad
= SolidColorDrawQuad::Create();
1415 shared_state
.get(), right_rect
, right_rect
, SK_ColorBLUE
, false);
1416 root_pass
->quad_list
.push_back(color_quad
.PassAs
<DrawQuad
>());
1417 root_pass
->shared_quad_state_list
.push_back(shared_state
.Pass());
1418 right_rect
+= gfx::Vector2d(0, right_rect
.height() + 1);
1421 scoped_ptr
<SharedQuadState
> shared_state
=
1422 CreateTestSharedQuadState(identity_content_to_target_transform
,
1423 device_viewport_rect
);
1424 scoped_ptr
<SolidColorDrawQuad
> background_quad
=
1425 SolidColorDrawQuad::Create();
1426 background_quad
->SetNew(shared_state
.get(),
1427 device_viewport_rect
,
1428 device_viewport_rect
,
1431 root_pass
->quad_list
.push_back(background_quad
.PassAs
<DrawQuad
>());
1432 root_pass
->shared_quad_state_list
.push_back(shared_state
.Pass());
1434 pass_list_
.push_back(filter_pass
.Pass());
1435 pass_list_
.push_back(root_pass
.Pass());
1438 RenderPassList pass_list_
;
1439 FilterOperations background_filters_
;
1440 gfx::Transform filter_pass_to_target_transform_
;
1441 gfx::Rect filter_pass_content_rect_
;
1444 typedef ::testing::Types
<GLRenderer
, SoftwareRenderer
>
1445 BackgroundFilterRendererTypes
;
1446 TYPED_TEST_CASE(RendererPixelTestWithBackgroundFilter
,
1447 BackgroundFilterRendererTypes
);
1449 typedef RendererPixelTestWithBackgroundFilter
<GLRenderer
>
1450 GLRendererPixelTestWithBackgroundFilter
;
1452 // TODO(skaslev): The software renderer does not support filters yet.
1453 TEST_F(GLRendererPixelTestWithBackgroundFilter
, InvertFilter
) {
1454 this->background_filters_
.Append(
1455 FilterOperation::CreateInvertFilter(1.f
));
1457 this->filter_pass_content_rect_
= gfx::Rect(this->device_viewport_size_
);
1458 this->filter_pass_content_rect_
.Inset(12, 14, 16, 18);
1460 this->SetUpRenderPassList();
1461 EXPECT_TRUE(this->RunPixelTest(
1463 base::FilePath(FILE_PATH_LITERAL("background_filter.png")),
1464 ExactPixelComparator(true)));
1467 class ExternalStencilPixelTest
: public GLRendererPixelTest
{
1469 void ClearBackgroundToGreen() {
1470 GLES2Interface
* gl
= output_surface_
->context_provider()->ContextGL();
1471 output_surface_
->EnsureBackbuffer();
1472 output_surface_
->Reshape(device_viewport_size_
, 1);
1473 gl
->ClearColor(0.f
, 1.f
, 0.f
, 1.f
);
1474 gl
->Clear(GL_COLOR_BUFFER_BIT
);
1477 void PopulateStencilBuffer() {
1478 // Set two quadrants of the stencil buffer to 1.
1479 GLES2Interface
* gl
= output_surface_
->context_provider()->ContextGL();
1480 output_surface_
->EnsureBackbuffer();
1481 output_surface_
->Reshape(device_viewport_size_
, 1);
1482 gl
->ClearStencil(0);
1483 gl
->Clear(GL_STENCIL_BUFFER_BIT
);
1484 gl
->Enable(GL_SCISSOR_TEST
);
1485 gl
->ClearStencil(1);
1488 device_viewport_size_
.width() / 2,
1489 device_viewport_size_
.height() / 2);
1490 gl
->Clear(GL_STENCIL_BUFFER_BIT
);
1491 gl
->Scissor(device_viewport_size_
.width() / 2,
1492 device_viewport_size_
.height() / 2,
1493 device_viewport_size_
.width(),
1494 device_viewport_size_
.height());
1495 gl
->Clear(GL_STENCIL_BUFFER_BIT
);
1499 TEST_F(ExternalStencilPixelTest
, StencilTestEnabled
) {
1500 ClearBackgroundToGreen();
1501 PopulateStencilBuffer();
1502 this->EnableExternalStencilTest();
1504 // Draw a blue quad that covers the entire device viewport. It should be
1505 // clipped to the bottom left and top right corners by the external stencil.
1506 gfx::Rect
rect(this->device_viewport_size_
);
1507 RenderPass::Id
id(1, 1);
1508 scoped_ptr
<RenderPass
> pass
= CreateTestRootRenderPass(id
, rect
);
1509 scoped_ptr
<SharedQuadState
> blue_shared_state
=
1510 CreateTestSharedQuadState(gfx::Transform(), rect
);
1511 scoped_ptr
<SolidColorDrawQuad
> blue
= SolidColorDrawQuad::Create();
1512 blue
->SetNew(blue_shared_state
.get(), rect
, rect
, SK_ColorBLUE
, false);
1513 pass
->quad_list
.push_back(blue
.PassAs
<DrawQuad
>());
1514 pass
->has_transparent_background
= false;
1515 RenderPassList pass_list
;
1516 pass_list
.push_back(pass
.Pass());
1518 EXPECT_TRUE(this->RunPixelTest(
1520 base::FilePath(FILE_PATH_LITERAL("four_blue_green_checkers.png")),
1521 ExactPixelComparator(true)));
1524 TEST_F(ExternalStencilPixelTest
, StencilTestDisabled
) {
1525 PopulateStencilBuffer();
1527 // Draw a green quad that covers the entire device viewport. The stencil
1528 // buffer should be ignored.
1529 gfx::Rect
rect(this->device_viewport_size_
);
1530 RenderPass::Id
id(1, 1);
1531 scoped_ptr
<RenderPass
> pass
= CreateTestRootRenderPass(id
, rect
);
1532 scoped_ptr
<SharedQuadState
> green_shared_state
=
1533 CreateTestSharedQuadState(gfx::Transform(), rect
);
1534 scoped_ptr
<SolidColorDrawQuad
> green
= SolidColorDrawQuad::Create();
1535 green
->SetNew(green_shared_state
.get(), rect
, rect
, SK_ColorGREEN
, false);
1536 pass
->quad_list
.push_back(green
.PassAs
<DrawQuad
>());
1537 RenderPassList pass_list
;
1538 pass_list
.push_back(pass
.Pass());
1540 EXPECT_TRUE(this->RunPixelTest(
1542 base::FilePath(FILE_PATH_LITERAL("green.png")),
1543 ExactPixelComparator(true)));
1546 TEST_F(ExternalStencilPixelTest
, RenderSurfacesIgnoreStencil
) {
1547 // The stencil test should apply only to the final render pass.
1548 ClearBackgroundToGreen();
1549 PopulateStencilBuffer();
1550 this->EnableExternalStencilTest();
1552 gfx::Rect
viewport_rect(this->device_viewport_size_
);
1554 RenderPass::Id
root_pass_id(1, 1);
1555 scoped_ptr
<RenderPass
> root_pass
=
1556 CreateTestRootRenderPass(root_pass_id
, viewport_rect
);
1557 root_pass
->has_transparent_background
= false;
1559 RenderPass::Id
child_pass_id(2, 2);
1560 gfx::Rect
pass_rect(this->device_viewport_size_
);
1561 gfx::Transform transform_to_root
;
1562 scoped_ptr
<RenderPass
> child_pass
=
1563 CreateTestRenderPass(child_pass_id
, pass_rect
, transform_to_root
);
1565 gfx::Transform content_to_target_transform
;
1566 scoped_ptr
<SharedQuadState
> shared_state
=
1567 CreateTestSharedQuadState(content_to_target_transform
, viewport_rect
);
1569 gfx::Rect
blue_rect(0,
1571 this->device_viewport_size_
.width(),
1572 this->device_viewport_size_
.height());
1573 scoped_ptr
<SolidColorDrawQuad
> blue
= SolidColorDrawQuad::Create();
1574 blue
->SetNew(shared_state
.get(), blue_rect
, blue_rect
, SK_ColorBLUE
, false);
1575 child_pass
->quad_list
.push_back(blue
.PassAs
<DrawQuad
>());
1577 scoped_ptr
<SharedQuadState
> pass_shared_state
=
1578 CreateTestSharedQuadState(gfx::Transform(), pass_rect
);
1579 root_pass
->quad_list
.push_back(
1580 CreateTestRenderPassDrawQuad(pass_shared_state
.get(),
1583 RenderPassList pass_list
;
1584 pass_list
.push_back(child_pass
.Pass());
1585 pass_list
.push_back(root_pass
.Pass());
1587 EXPECT_TRUE(this->RunPixelTest(
1589 base::FilePath(FILE_PATH_LITERAL("four_blue_green_checkers.png")),
1590 ExactPixelComparator(true)));
1593 TEST_F(ExternalStencilPixelTest
, DeviceClip
) {
1594 ClearBackgroundToGreen();
1595 gfx::Rect
clip_rect(gfx::Point(150, 150), gfx::Size(50, 50));
1596 this->ForceDeviceClip(clip_rect
);
1598 // Draw a blue quad that covers the entire device viewport. It should be
1599 // clipped to the bottom right corner by the device clip.
1600 gfx::Rect
rect(this->device_viewport_size_
);
1601 RenderPass::Id
id(1, 1);
1602 scoped_ptr
<RenderPass
> pass
= CreateTestRootRenderPass(id
, rect
);
1603 scoped_ptr
<SharedQuadState
> blue_shared_state
=
1604 CreateTestSharedQuadState(gfx::Transform(), rect
);
1605 scoped_ptr
<SolidColorDrawQuad
> blue
= SolidColorDrawQuad::Create();
1606 blue
->SetNew(blue_shared_state
.get(), rect
, rect
, SK_ColorBLUE
, false);
1607 pass
->quad_list
.push_back(blue
.PassAs
<DrawQuad
>());
1608 RenderPassList pass_list
;
1609 pass_list
.push_back(pass
.Pass());
1611 EXPECT_TRUE(this->RunPixelTest(
1613 base::FilePath(FILE_PATH_LITERAL("green_with_blue_corner.png")),
1614 ExactPixelComparator(true)));
1617 // Software renderer does not support anti-aliased edges.
1618 TEST_F(GLRendererPixelTest
, AntiAliasing
) {
1619 gfx::Rect
rect(this->device_viewport_size_
);
1621 RenderPass::Id
id(1, 1);
1622 scoped_ptr
<RenderPass
> pass
= CreateTestRootRenderPass(id
, rect
);
1624 gfx::Transform red_content_to_target_transform
;
1625 red_content_to_target_transform
.Rotate(10);
1626 scoped_ptr
<SharedQuadState
> red_shared_state
=
1627 CreateTestSharedQuadState(red_content_to_target_transform
, rect
);
1629 scoped_ptr
<SolidColorDrawQuad
> red
= SolidColorDrawQuad::Create();
1630 red
->SetNew(red_shared_state
.get(), rect
, rect
, SK_ColorRED
, false);
1632 pass
->quad_list
.push_back(red
.PassAs
<DrawQuad
>());
1634 gfx::Transform yellow_content_to_target_transform
;
1635 yellow_content_to_target_transform
.Rotate(5);
1636 scoped_ptr
<SharedQuadState
> yellow_shared_state
=
1637 CreateTestSharedQuadState(yellow_content_to_target_transform
, rect
);
1639 scoped_ptr
<SolidColorDrawQuad
> yellow
= SolidColorDrawQuad::Create();
1640 yellow
->SetNew(yellow_shared_state
.get(), rect
, rect
, SK_ColorYELLOW
, false);
1642 pass
->quad_list
.push_back(yellow
.PassAs
<DrawQuad
>());
1644 gfx::Transform blue_content_to_target_transform
;
1645 scoped_ptr
<SharedQuadState
> blue_shared_state
=
1646 CreateTestSharedQuadState(blue_content_to_target_transform
, rect
);
1648 scoped_ptr
<SolidColorDrawQuad
> blue
= SolidColorDrawQuad::Create();
1649 blue
->SetNew(blue_shared_state
.get(), rect
, rect
, SK_ColorBLUE
, false);
1651 pass
->quad_list
.push_back(blue
.PassAs
<DrawQuad
>());
1653 RenderPassList pass_list
;
1654 pass_list
.push_back(pass
.Pass());
1656 EXPECT_TRUE(this->RunPixelTest(
1658 base::FilePath(FILE_PATH_LITERAL("anti_aliasing.png")),
1659 FuzzyPixelOffByOneComparator(true)));
1662 // This test tests that anti-aliasing works for axis aligned quads.
1663 // Anti-aliasing is only supported in the gl renderer.
1664 TEST_F(GLRendererPixelTest
, AxisAligned
) {
1665 gfx::Rect
rect(this->device_viewport_size_
);
1667 RenderPass::Id
id(1, 1);
1668 gfx::Transform transform_to_root
;
1669 scoped_ptr
<RenderPass
> pass
=
1670 CreateTestRenderPass(id
, rect
, transform_to_root
);
1672 gfx::Transform red_content_to_target_transform
;
1673 red_content_to_target_transform
.Translate(50, 50);
1674 red_content_to_target_transform
.Scale(
1675 0.5f
+ 1.0f
/ (rect
.width() * 2.0f
),
1676 0.5f
+ 1.0f
/ (rect
.height() * 2.0f
));
1677 scoped_ptr
<SharedQuadState
> red_shared_state
=
1678 CreateTestSharedQuadState(red_content_to_target_transform
, rect
);
1680 scoped_ptr
<SolidColorDrawQuad
> red
= SolidColorDrawQuad::Create();
1681 red
->SetNew(red_shared_state
.get(), rect
, rect
, SK_ColorRED
, false);
1683 pass
->quad_list
.push_back(red
.PassAs
<DrawQuad
>());
1685 gfx::Transform yellow_content_to_target_transform
;
1686 yellow_content_to_target_transform
.Translate(25.5f
, 25.5f
);
1687 yellow_content_to_target_transform
.Scale(0.5f
, 0.5f
);
1688 scoped_ptr
<SharedQuadState
> yellow_shared_state
=
1689 CreateTestSharedQuadState(yellow_content_to_target_transform
, rect
);
1691 scoped_ptr
<SolidColorDrawQuad
> yellow
= SolidColorDrawQuad::Create();
1692 yellow
->SetNew(yellow_shared_state
.get(), rect
, rect
, SK_ColorYELLOW
, false);
1694 pass
->quad_list
.push_back(yellow
.PassAs
<DrawQuad
>());
1696 gfx::Transform blue_content_to_target_transform
;
1697 scoped_ptr
<SharedQuadState
> blue_shared_state
=
1698 CreateTestSharedQuadState(blue_content_to_target_transform
, rect
);
1700 scoped_ptr
<SolidColorDrawQuad
> blue
= SolidColorDrawQuad::Create();
1701 blue
->SetNew(blue_shared_state
.get(), rect
, rect
, SK_ColorBLUE
, false);
1703 pass
->quad_list
.push_back(blue
.PassAs
<DrawQuad
>());
1705 RenderPassList pass_list
;
1706 pass_list
.push_back(pass
.Pass());
1708 EXPECT_TRUE(this->RunPixelTest(
1710 base::FilePath(FILE_PATH_LITERAL("axis_aligned.png")),
1711 ExactPixelComparator(true)));
1714 // This test tests that forcing anti-aliasing off works as expected.
1715 // Anti-aliasing is only supported in the gl renderer.
1716 TEST_F(GLRendererPixelTest
, ForceAntiAliasingOff
) {
1717 gfx::Rect
rect(this->device_viewport_size_
);
1719 RenderPass::Id
id(1, 1);
1720 gfx::Transform transform_to_root
;
1721 scoped_ptr
<RenderPass
> pass
=
1722 CreateTestRenderPass(id
, rect
, transform_to_root
);
1724 gfx::Transform hole_content_to_target_transform
;
1725 hole_content_to_target_transform
.Translate(50, 50);
1726 hole_content_to_target_transform
.Scale(
1727 0.5f
+ 1.0f
/ (rect
.width() * 2.0f
),
1728 0.5f
+ 1.0f
/ (rect
.height() * 2.0f
));
1729 scoped_ptr
<SharedQuadState
> hole_shared_state
=
1730 CreateTestSharedQuadState(hole_content_to_target_transform
, rect
);
1732 scoped_ptr
<SolidColorDrawQuad
> hole
= SolidColorDrawQuad::Create();
1733 hole
->SetAll(hole_shared_state
.get(), rect
, rect
, rect
, false,
1734 SK_ColorTRANSPARENT
, true);
1735 pass
->quad_list
.push_back(hole
.PassAs
<DrawQuad
>());
1737 gfx::Transform green_content_to_target_transform
;
1738 scoped_ptr
<SharedQuadState
> green_shared_state
=
1739 CreateTestSharedQuadState(green_content_to_target_transform
, rect
);
1741 scoped_ptr
<SolidColorDrawQuad
> green
= SolidColorDrawQuad::Create();
1742 green
->SetNew(green_shared_state
.get(), rect
, rect
, SK_ColorGREEN
, false);
1744 pass
->quad_list
.push_back(green
.PassAs
<DrawQuad
>());
1746 RenderPassList pass_list
;
1747 pass_list
.push_back(pass
.Pass());
1749 EXPECT_TRUE(this->RunPixelTest(
1751 base::FilePath(FILE_PATH_LITERAL("force_anti_aliasing_off.png")),
1752 ExactPixelComparator(false)));
1755 TEST_F(GLRendererPixelTest
, AntiAliasingPerspective
) {
1756 gfx::Rect
rect(this->device_viewport_size_
);
1758 scoped_ptr
<RenderPass
> pass
=
1759 CreateTestRootRenderPass(RenderPass::Id(1, 1), rect
);
1761 gfx::Rect
red_rect(0, 0, 180, 500);
1762 gfx::Transform
red_content_to_target_transform(
1763 1.0f
, 2.4520f
, 10.6206f
, 19.0f
,
1764 0.0f
, 0.3528f
, 5.9737f
, 9.5f
,
1765 0.0f
, -0.2250f
, -0.9744f
, 0.0f
,
1766 0.0f
, 0.0225f
, 0.0974f
, 1.0f
);
1767 scoped_ptr
<SharedQuadState
> red_shared_state
=
1768 CreateTestSharedQuadState(red_content_to_target_transform
, red_rect
);
1769 scoped_ptr
<SolidColorDrawQuad
> red
= SolidColorDrawQuad::Create();
1770 red
->SetNew(red_shared_state
.get(), red_rect
, red_rect
, SK_ColorRED
, false);
1771 pass
->quad_list
.push_back(red
.PassAs
<DrawQuad
>());
1773 gfx::Rect
green_rect(19, 7, 180, 10);
1774 scoped_ptr
<SharedQuadState
> green_shared_state
=
1775 CreateTestSharedQuadState(gfx::Transform(), green_rect
);
1776 scoped_ptr
<SolidColorDrawQuad
> green
= SolidColorDrawQuad::Create();
1778 green_shared_state
.get(), green_rect
, green_rect
, SK_ColorGREEN
, false);
1779 pass
->quad_list
.push_back(green
.PassAs
<DrawQuad
>());
1781 scoped_ptr
<SharedQuadState
> blue_shared_state
=
1782 CreateTestSharedQuadState(gfx::Transform(), rect
);
1783 scoped_ptr
<SolidColorDrawQuad
> blue
= SolidColorDrawQuad::Create();
1784 blue
->SetNew(blue_shared_state
.get(), rect
, rect
, SK_ColorBLUE
, false);
1785 pass
->quad_list
.push_back(blue
.PassAs
<DrawQuad
>());
1787 RenderPassList pass_list
;
1788 pass_list
.push_back(pass
.Pass());
1790 EXPECT_TRUE(this->RunPixelTest(
1792 base::FilePath(FILE_PATH_LITERAL("anti_aliasing_perspective.png")),
1793 FuzzyPixelOffByOneComparator(true)));
1796 TYPED_TEST(RendererPixelTest
, PictureDrawQuadIdentityScale
) {
1797 gfx::Size
pile_tile_size(1000, 1000);
1798 gfx::Rect
viewport(this->device_viewport_size_
);
1799 // TODO(enne): the renderer should figure this out on its own.
1800 ResourceFormat texture_format
= RGBA_8888
;
1802 RenderPass::Id
id(1, 1);
1803 gfx::Transform transform_to_root
;
1804 scoped_ptr
<RenderPass
> pass
=
1805 CreateTestRenderPass(id
, viewport
, transform_to_root
);
1807 // One clipped blue quad in the lower right corner. Outside the clip
1808 // is red, which should not appear.
1809 gfx::Rect
blue_rect(gfx::Size(100, 100));
1810 gfx::Rect
blue_clip_rect(gfx::Point(50, 50), gfx::Size(50, 50));
1811 scoped_refptr
<FakePicturePileImpl
> blue_pile
=
1812 FakePicturePileImpl::CreateFilledPile(pile_tile_size
, blue_rect
.size());
1814 red_paint
.setColor(SK_ColorRED
);
1815 blue_pile
->add_draw_rect_with_paint(blue_rect
, red_paint
);
1817 blue_paint
.setColor(SK_ColorBLUE
);
1818 blue_pile
->add_draw_rect_with_paint(blue_clip_rect
, blue_paint
);
1819 blue_pile
->RerecordPile();
1821 gfx::Transform blue_content_to_target_transform
;
1822 gfx::Vector2d
offset(viewport
.bottom_right() - blue_rect
.bottom_right());
1823 blue_content_to_target_transform
.Translate(offset
.x(), offset
.y());
1824 gfx::RectF blue_scissor_rect
= blue_clip_rect
;
1825 blue_content_to_target_transform
.TransformRect(&blue_scissor_rect
);
1826 scoped_ptr
<SharedQuadState
> blue_shared_state
=
1827 CreateTestSharedQuadStateClipped(blue_content_to_target_transform
,
1829 gfx::ToEnclosingRect(blue_scissor_rect
));
1831 scoped_ptr
<PictureDrawQuad
> blue_quad
= PictureDrawQuad::Create();
1833 blue_quad
->SetNew(blue_shared_state
.get(),
1834 viewport
, // Intentionally bigger than clip.
1837 gfx::RectF(viewport
),
1842 PicturePileImpl::CreateFromOther(blue_pile
));
1843 pass
->quad_list
.push_back(blue_quad
.PassAs
<DrawQuad
>());
1845 // One viewport-filling green quad.
1846 scoped_refptr
<FakePicturePileImpl
> green_pile
=
1847 FakePicturePileImpl::CreateFilledPile(pile_tile_size
, viewport
.size());
1848 SkPaint green_paint
;
1849 green_paint
.setColor(SK_ColorGREEN
);
1850 green_pile
->add_draw_rect_with_paint(viewport
, green_paint
);
1851 green_pile
->RerecordPile();
1853 gfx::Transform green_content_to_target_transform
;
1854 scoped_ptr
<SharedQuadState
> green_shared_state
=
1855 CreateTestSharedQuadState(green_content_to_target_transform
, viewport
);
1857 scoped_ptr
<PictureDrawQuad
> green_quad
= PictureDrawQuad::Create();
1858 green_quad
->SetNew(green_shared_state
.get(),
1862 gfx::RectF(0.f
, 0.f
, 1.f
, 1.f
),
1867 PicturePileImpl::CreateFromOther(green_pile
));
1868 pass
->quad_list
.push_back(green_quad
.PassAs
<DrawQuad
>());
1870 RenderPassList pass_list
;
1871 pass_list
.push_back(pass
.Pass());
1873 EXPECT_TRUE(this->RunPixelTest(
1875 base::FilePath(FILE_PATH_LITERAL("green_with_blue_corner.png")),
1876 ExactPixelComparator(true)));
1879 // Not WithSkiaGPUBackend since that path currently requires tiles for opacity.
1880 TYPED_TEST(RendererPixelTest
, PictureDrawQuadOpacity
) {
1881 gfx::Size
pile_tile_size(1000, 1000);
1882 gfx::Rect
viewport(this->device_viewport_size_
);
1883 ResourceFormat texture_format
= RGBA_8888
;
1885 RenderPass::Id
id(1, 1);
1886 gfx::Transform transform_to_root
;
1887 scoped_ptr
<RenderPass
> pass
=
1888 CreateTestRenderPass(id
, viewport
, transform_to_root
);
1890 // One viewport-filling 0.5-opacity green quad.
1891 scoped_refptr
<FakePicturePileImpl
> green_pile
=
1892 FakePicturePileImpl::CreateFilledPile(pile_tile_size
, viewport
.size());
1893 SkPaint green_paint
;
1894 green_paint
.setColor(SK_ColorGREEN
);
1895 green_pile
->add_draw_rect_with_paint(viewport
, green_paint
);
1896 green_pile
->RerecordPile();
1898 gfx::Transform green_content_to_target_transform
;
1899 scoped_ptr
<SharedQuadState
> green_shared_state
=
1900 CreateTestSharedQuadState(green_content_to_target_transform
, viewport
);
1901 green_shared_state
->opacity
= 0.5f
;
1903 scoped_ptr
<PictureDrawQuad
> green_quad
= PictureDrawQuad::Create();
1904 green_quad
->SetNew(green_shared_state
.get(),
1908 gfx::RectF(0, 0, 1, 1),
1913 PicturePileImpl::CreateFromOther(green_pile
));
1914 pass
->quad_list
.push_back(green_quad
.PassAs
<DrawQuad
>());
1916 // One viewport-filling white quad.
1917 scoped_refptr
<FakePicturePileImpl
> white_pile
=
1918 FakePicturePileImpl::CreateFilledPile(pile_tile_size
, viewport
.size());
1919 SkPaint white_paint
;
1920 white_paint
.setColor(SK_ColorWHITE
);
1921 white_pile
->add_draw_rect_with_paint(viewport
, white_paint
);
1922 white_pile
->RerecordPile();
1924 gfx::Transform white_content_to_target_transform
;
1925 scoped_ptr
<SharedQuadState
> white_shared_state
=
1926 CreateTestSharedQuadState(white_content_to_target_transform
, viewport
);
1928 scoped_ptr
<PictureDrawQuad
> white_quad
= PictureDrawQuad::Create();
1929 white_quad
->SetNew(white_shared_state
.get(),
1933 gfx::RectF(0, 0, 1, 1),
1938 PicturePileImpl::CreateFromOther(white_pile
));
1939 pass
->quad_list
.push_back(white_quad
.PassAs
<DrawQuad
>());
1941 RenderPassList pass_list
;
1942 pass_list
.push_back(pass
.Pass());
1944 EXPECT_TRUE(this->RunPixelTest(
1946 base::FilePath(FILE_PATH_LITERAL("green_alpha.png")),
1947 FuzzyPixelOffByOneComparator(true)));
1950 template<typename TypeParam
> bool IsSoftwareRenderer() {
1955 bool IsSoftwareRenderer
<SoftwareRenderer
>() {
1960 bool IsSoftwareRenderer
<SoftwareRendererWithExpandedViewport
>() {
1964 // If we disable image filtering, then a 2x2 bitmap should appear as four
1965 // huge sharp squares.
1966 TYPED_TEST(RendererPixelTest
, PictureDrawQuadDisableImageFiltering
) {
1967 // We only care about this in software mode since bilinear filtering is
1968 // cheap in hardware.
1969 if (!IsSoftwareRenderer
<TypeParam
>())
1972 gfx::Size
pile_tile_size(1000, 1000);
1973 gfx::Rect
viewport(this->device_viewport_size_
);
1974 ResourceFormat texture_format
= RGBA_8888
;
1976 RenderPass::Id
id(1, 1);
1977 gfx::Transform transform_to_root
;
1978 scoped_ptr
<RenderPass
> pass
=
1979 CreateTestRenderPass(id
, viewport
, transform_to_root
);
1982 bitmap
.allocN32Pixels(2, 2);
1984 SkAutoLockPixels
lock(bitmap
);
1985 SkCanvas
canvas(bitmap
);
1986 canvas
.drawPoint(0, 0, SK_ColorGREEN
);
1987 canvas
.drawPoint(0, 1, SK_ColorBLUE
);
1988 canvas
.drawPoint(1, 0, SK_ColorBLUE
);
1989 canvas
.drawPoint(1, 1, SK_ColorGREEN
);
1992 scoped_refptr
<FakePicturePileImpl
> pile
=
1993 FakePicturePileImpl::CreateFilledPile(pile_tile_size
, viewport
.size());
1995 paint
.setFilterLevel(SkPaint::kLow_FilterLevel
);
1996 pile
->add_draw_bitmap_with_paint(bitmap
, gfx::Point(), paint
);
1997 pile
->RerecordPile();
1999 gfx::Transform content_to_target_transform
;
2000 scoped_ptr
<SharedQuadState
> shared_state
=
2001 CreateTestSharedQuadState(content_to_target_transform
, viewport
);
2003 scoped_ptr
<PictureDrawQuad
> quad
= PictureDrawQuad::Create();
2004 quad
->SetNew(shared_state
.get(),
2008 gfx::RectF(0, 0, 2, 2),
2013 PicturePileImpl::CreateFromOther(pile
));
2014 pass
->quad_list
.push_back(quad
.PassAs
<DrawQuad
>());
2016 RenderPassList pass_list
;
2017 pass_list
.push_back(pass
.Pass());
2019 this->disable_picture_quad_image_filtering_
= true;
2021 EXPECT_TRUE(this->RunPixelTest(
2023 base::FilePath(FILE_PATH_LITERAL("four_blue_green_checkers.png")),
2024 ExactPixelComparator(true)));
2027 TYPED_TEST(RendererPixelTest
, PictureDrawQuadNonIdentityScale
) {
2028 gfx::Size
pile_tile_size(1000, 1000);
2029 gfx::Rect
viewport(this->device_viewport_size_
);
2030 // TODO(enne): the renderer should figure this out on its own.
2031 ResourceFormat texture_format
= RGBA_8888
;
2033 RenderPass::Id
id(1, 1);
2034 gfx::Transform transform_to_root
;
2035 scoped_ptr
<RenderPass
> pass
=
2036 CreateTestRenderPass(id
, viewport
, transform_to_root
);
2038 // As scaling up the blue checkerboards will cause sampling on the GPU,
2039 // a few extra "cleanup rects" need to be added to clobber the blending
2040 // to make the output image more clean. This will also test subrects
2042 gfx::Transform green_content_to_target_transform
;
2043 gfx::Rect
green_rect1(gfx::Point(80, 0), gfx::Size(20, 100));
2044 gfx::Rect
green_rect2(gfx::Point(0, 80), gfx::Size(100, 20));
2045 scoped_refptr
<FakePicturePileImpl
> green_pile
=
2046 FakePicturePileImpl::CreateFilledPile(pile_tile_size
, viewport
.size());
2048 red_paint
.setColor(SK_ColorRED
);
2049 green_pile
->add_draw_rect_with_paint(viewport
, red_paint
);
2050 SkPaint green_paint
;
2051 green_paint
.setColor(SK_ColorGREEN
);
2052 green_pile
->add_draw_rect_with_paint(green_rect1
, green_paint
);
2053 green_pile
->add_draw_rect_with_paint(green_rect2
, green_paint
);
2054 green_pile
->RerecordPile();
2056 scoped_ptr
<SharedQuadState
> top_right_green_shared_quad_state
=
2057 CreateTestSharedQuadState(green_content_to_target_transform
, viewport
);
2059 scoped_ptr
<PictureDrawQuad
> green_quad1
= PictureDrawQuad::Create();
2060 green_quad1
->SetNew(top_right_green_shared_quad_state
.get(),
2064 gfx::RectF(green_rect1
.size()),
2069 PicturePileImpl::CreateFromOther(green_pile
));
2070 pass
->quad_list
.push_back(green_quad1
.PassAs
<DrawQuad
>());
2072 scoped_ptr
<PictureDrawQuad
> green_quad2
= PictureDrawQuad::Create();
2073 green_quad2
->SetNew(top_right_green_shared_quad_state
.get(),
2077 gfx::RectF(green_rect2
.size()),
2082 PicturePileImpl::CreateFromOther(green_pile
));
2083 pass
->quad_list
.push_back(green_quad2
.PassAs
<DrawQuad
>());
2085 // Add a green clipped checkerboard in the bottom right to help test
2086 // interleaving picture quad content and solid color content.
2087 gfx::Rect
bottom_right_rect(
2088 gfx::Point(viewport
.width() / 2, viewport
.height() / 2),
2089 gfx::Size(viewport
.width() / 2, viewport
.height() / 2));
2090 scoped_ptr
<SharedQuadState
> bottom_right_green_shared_state
=
2091 CreateTestSharedQuadStateClipped(
2092 green_content_to_target_transform
, viewport
, bottom_right_rect
);
2093 scoped_ptr
<SolidColorDrawQuad
> bottom_right_color_quad
=
2094 SolidColorDrawQuad::Create();
2095 bottom_right_color_quad
->SetNew(bottom_right_green_shared_state
.get(),
2100 pass
->quad_list
.push_back(bottom_right_color_quad
.PassAs
<DrawQuad
>());
2102 // Add two blue checkerboards taking up the bottom left and top right,
2103 // but use content scales as content rects to make this happen.
2104 // The content is at a 4x content scale.
2105 gfx::Rect
layer_rect(gfx::Size(20, 30));
2106 float contents_scale
= 4.f
;
2107 // Two rects that touch at their corners, arbitrarily placed in the layer.
2108 gfx::RectF
blue_layer_rect1(gfx::PointF(5.5f
, 9.0f
), gfx::SizeF(2.5f
, 2.5f
));
2109 gfx::RectF
blue_layer_rect2(gfx::PointF(8.0f
, 6.5f
), gfx::SizeF(2.5f
, 2.5f
));
2110 gfx::RectF union_layer_rect
= blue_layer_rect1
;
2111 union_layer_rect
.Union(blue_layer_rect2
);
2113 // Because scaling up will cause sampling outside the rects, add one extra
2114 // pixel of buffer at the final content scale.
2115 float inset
= -1.f
/ contents_scale
;
2116 blue_layer_rect1
.Inset(inset
, inset
, inset
, inset
);
2117 blue_layer_rect2
.Inset(inset
, inset
, inset
, inset
);
2119 scoped_refptr
<FakePicturePileImpl
> pile
=
2120 FakePicturePileImpl::CreateFilledPile(pile_tile_size
, layer_rect
.size());
2122 Region
outside(layer_rect
);
2123 outside
.Subtract(gfx::ToEnclosingRect(union_layer_rect
));
2124 for (Region::Iterator
iter(outside
); iter
.has_rect(); iter
.next()) {
2125 pile
->add_draw_rect_with_paint(iter
.rect(), red_paint
);
2129 blue_paint
.setColor(SK_ColorBLUE
);
2130 pile
->add_draw_rect_with_paint(blue_layer_rect1
, blue_paint
);
2131 pile
->add_draw_rect_with_paint(blue_layer_rect2
, blue_paint
);
2132 pile
->RerecordPile();
2134 gfx::Rect
content_rect(
2135 gfx::ScaleToEnclosingRect(layer_rect
, contents_scale
));
2136 gfx::Rect
content_union_rect(
2137 gfx::ToEnclosingRect(gfx::ScaleRect(union_layer_rect
, contents_scale
)));
2139 // At a scale of 4x the rectangles with a width of 2.5 will take up 10 pixels,
2140 // so scale an additional 10x to make them 100x100.
2141 gfx::Transform content_to_target_transform
;
2142 content_to_target_transform
.Scale(10.0, 10.0);
2143 gfx::Rect
quad_content_rect(gfx::Size(20, 20));
2144 scoped_ptr
<SharedQuadState
> blue_shared_state
=
2145 CreateTestSharedQuadState(content_to_target_transform
, quad_content_rect
);
2147 scoped_ptr
<PictureDrawQuad
> blue_quad
= PictureDrawQuad::Create();
2148 blue_quad
->SetNew(blue_shared_state
.get(),
2152 gfx::RectF(quad_content_rect
),
2153 content_union_rect
.size(),
2157 PicturePileImpl::CreateFromOther(pile
));
2158 pass
->quad_list
.push_back(blue_quad
.PassAs
<DrawQuad
>());
2160 // Fill left half of viewport with green.
2161 gfx::Transform half_green_content_to_target_transform
;
2162 gfx::Rect
half_green_rect(gfx::Size(viewport
.width() / 2, viewport
.height()));
2163 scoped_ptr
<SharedQuadState
> half_green_shared_state
=
2164 CreateTestSharedQuadState(half_green_content_to_target_transform
,
2166 scoped_ptr
<SolidColorDrawQuad
> half_color_quad
= SolidColorDrawQuad::Create();
2167 half_color_quad
->SetNew(half_green_shared_state
.get(),
2172 pass
->quad_list
.push_back(half_color_quad
.PassAs
<DrawQuad
>());
2174 RenderPassList pass_list
;
2175 pass_list
.push_back(pass
.Pass());
2177 EXPECT_TRUE(this->RunPixelTest(
2179 base::FilePath(FILE_PATH_LITERAL("four_blue_green_checkers.png")),
2180 ExactPixelComparator(true)));
2183 TYPED_TEST(RendererPixelTest
, WrapModeRepeat
) {
2184 gfx::Rect
rect(this->device_viewport_size_
);
2186 RenderPass::Id
id(1, 1);
2187 scoped_ptr
<RenderPass
> pass
= CreateTestRootRenderPass(id
, rect
);
2189 scoped_ptr
<SharedQuadState
> shared_state
=
2190 CreateTestSharedQuadState(gfx::Transform(), rect
);
2192 gfx::Rect
texture_rect(4, 4);
2193 SkPMColor colors
[4] = {
2194 SkPreMultiplyColor(SkColorSetARGB(255, 0, 255, 0)),
2195 SkPreMultiplyColor(SkColorSetARGB(255, 0, 128, 0)),
2196 SkPreMultiplyColor(SkColorSetARGB(255, 0, 64, 0)),
2197 SkPreMultiplyColor(SkColorSetARGB(255, 0, 0, 0)),
2199 uint32_t pixels
[16] = {
2200 colors
[0], colors
[0], colors
[1], colors
[1],
2201 colors
[0], colors
[0], colors
[1], colors
[1],
2202 colors
[2], colors
[2], colors
[3], colors
[3],
2203 colors
[2], colors
[2], colors
[3], colors
[3],
2205 ResourceProvider::ResourceId resource
=
2206 this->resource_provider_
->CreateResource(
2207 texture_rect
.size(),
2209 ResourceProvider::TextureUsageAny
,
2211 this->resource_provider_
->SetPixels(
2213 reinterpret_cast<uint8_t*>(pixels
),
2218 float vertex_opacity
[4] = {1.0f
, 1.0f
, 1.0f
, 1.0f
};
2219 scoped_ptr
<TextureDrawQuad
> texture_quad
= TextureDrawQuad::Create();
2220 texture_quad
->SetNew(
2222 gfx::Rect(this->device_viewport_size_
),
2224 gfx::Rect(this->device_viewport_size_
),
2226 true, // premultiplied_alpha
2227 gfx::PointF(0.0f
, 0.0f
), // uv_top_left
2228 gfx::PointF( // uv_bottom_right
2229 this->device_viewport_size_
.width() / texture_rect
.width(),
2230 this->device_viewport_size_
.height() / texture_rect
.height()),
2234 pass
->quad_list
.push_back(texture_quad
.PassAs
<DrawQuad
>());
2236 RenderPassList pass_list
;
2237 pass_list
.push_back(pass
.Pass());
2239 EXPECT_TRUE(this->RunPixelTest(
2241 base::FilePath(FILE_PATH_LITERAL("wrap_mode_repeat.png")),
2242 FuzzyPixelOffByOneComparator(true)));
2245 #endif // !defined(OS_ANDROID)