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/command_buffer/client/gles2_interface.h"
15 #include "media/base/video_frame.h"
16 #include "third_party/skia/include/core/SkColorPriv.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/geometry/rect_conversions.h"
23 using gpu::gles2::GLES2Interface
;
28 #if !defined(OS_ANDROID)
29 scoped_ptr
<RenderPass
> CreateTestRootRenderPass(RenderPassId id
,
30 const gfx::Rect
& rect
) {
31 scoped_ptr
<RenderPass
> pass
= RenderPass::Create();
32 const gfx::Rect output_rect
= rect
;
33 const gfx::Rect damage_rect
= rect
;
34 const gfx::Transform transform_to_root_target
;
35 pass
->SetNew(id
, output_rect
, damage_rect
, transform_to_root_target
);
39 scoped_ptr
<RenderPass
> CreateTestRenderPass(
41 const gfx::Rect
& rect
,
42 const gfx::Transform
& transform_to_root_target
) {
43 scoped_ptr
<RenderPass
> pass
= RenderPass::Create();
44 const gfx::Rect output_rect
= rect
;
45 const gfx::Rect damage_rect
= rect
;
46 pass
->SetNew(id
, output_rect
, damage_rect
, transform_to_root_target
);
50 SharedQuadState
* CreateTestSharedQuadState(
51 gfx::Transform content_to_target_transform
,
52 const gfx::Rect
& rect
,
53 RenderPass
* render_pass
) {
54 const gfx::Size content_bounds
= rect
.size();
55 const gfx::Rect visible_content_rect
= rect
;
56 const gfx::Rect clip_rect
= rect
;
57 const bool is_clipped
= false;
58 const float opacity
= 1.0f
;
59 const SkXfermode::Mode blend_mode
= SkXfermode::kSrcOver_Mode
;
60 int sorting_context_id
= 0;
61 SharedQuadState
* shared_state
= render_pass
->CreateAndAppendSharedQuadState();
62 shared_state
->SetAll(content_to_target_transform
,
73 SharedQuadState
* CreateTestSharedQuadStateClipped(
74 gfx::Transform content_to_target_transform
,
75 const gfx::Rect
& rect
,
76 const gfx::Rect
& clip_rect
,
77 RenderPass
* render_pass
) {
78 const gfx::Size content_bounds
= rect
.size();
79 const gfx::Rect visible_content_rect
= clip_rect
;
80 const bool is_clipped
= true;
81 const float opacity
= 1.0f
;
82 const SkXfermode::Mode blend_mode
= SkXfermode::kSrcOver_Mode
;
83 int sorting_context_id
= 0;
84 SharedQuadState
* shared_state
= render_pass
->CreateAndAppendSharedQuadState();
85 shared_state
->SetAll(content_to_target_transform
,
96 void CreateTestRenderPassDrawQuad(const SharedQuadState
* shared_state
,
97 const gfx::Rect
& rect
,
99 RenderPass
* render_pass
) {
100 RenderPassDrawQuad
* quad
=
101 render_pass
->CreateAndAppendDrawQuad
<RenderPassDrawQuad
>();
102 quad
->SetNew(shared_state
,
106 0, // mask_resource_id
107 gfx::Vector2dF(), // mask_uv_scale
108 gfx::Size(), // mask_texture_size
109 FilterOperations(), // foreground filters
110 gfx::Vector2dF(), // filters scale
111 FilterOperations()); // background filters
114 void CreateTestTextureDrawQuad(const gfx::Rect
& rect
,
116 SkColor background_color
,
117 bool premultiplied_alpha
,
118 const SharedQuadState
* shared_state
,
119 ResourceProvider
* resource_provider
,
120 RenderPass
* render_pass
) {
121 SkPMColor pixel_color
= premultiplied_alpha
?
122 SkPreMultiplyColor(texel_color
) :
123 SkPackARGB32NoCheck(SkColorGetA(texel_color
),
124 SkColorGetR(texel_color
),
125 SkColorGetG(texel_color
),
126 SkColorGetB(texel_color
));
127 std::vector
<uint32_t> pixels(rect
.size().GetArea(), pixel_color
);
129 ResourceProvider::ResourceId resource
=
130 resource_provider
->CreateResource(rect
.size(),
132 ResourceProvider::TextureHintImmutable
,
134 resource_provider
->SetPixels(
136 reinterpret_cast<uint8_t*>(&pixels
.front()),
141 float vertex_opacity
[4] = {1.0f
, 1.0f
, 1.0f
, 1.0f
};
143 TextureDrawQuad
* quad
=
144 render_pass
->CreateAndAppendDrawQuad
<TextureDrawQuad
>();
145 quad
->SetNew(shared_state
,
151 gfx::PointF(0.0f
, 0.0f
), // uv_top_left
152 gfx::PointF(1.0f
, 1.0f
), // uv_bottom_right
158 typedef ::testing::Types
<GLRenderer
,
160 GLRendererWithExpandedViewport
,
161 SoftwareRendererWithExpandedViewport
> RendererTypes
;
162 TYPED_TEST_CASE(RendererPixelTest
, RendererTypes
);
164 template <typename RendererType
>
165 class FuzzyForSoftwareOnlyPixelComparator
: public PixelComparator
{
167 explicit FuzzyForSoftwareOnlyPixelComparator(bool discard_alpha
)
168 : fuzzy_(discard_alpha
), exact_(discard_alpha
) {}
170 virtual bool Compare(const SkBitmap
& actual_bmp
,
171 const SkBitmap
& expected_bmp
) const;
174 FuzzyPixelOffByOneComparator fuzzy_
;
175 ExactPixelComparator exact_
;
179 bool FuzzyForSoftwareOnlyPixelComparator
<SoftwareRenderer
>::Compare(
180 const SkBitmap
& actual_bmp
,
181 const SkBitmap
& expected_bmp
) const {
182 return fuzzy_
.Compare(actual_bmp
, expected_bmp
);
186 bool FuzzyForSoftwareOnlyPixelComparator
<
187 SoftwareRendererWithExpandedViewport
>::Compare(
188 const SkBitmap
& actual_bmp
,
189 const SkBitmap
& expected_bmp
) const {
190 return fuzzy_
.Compare(actual_bmp
, expected_bmp
);
193 template<typename RendererType
>
194 bool FuzzyForSoftwareOnlyPixelComparator
<RendererType
>::Compare(
195 const SkBitmap
& actual_bmp
,
196 const SkBitmap
& expected_bmp
) const {
197 return exact_
.Compare(actual_bmp
, expected_bmp
);
200 TYPED_TEST(RendererPixelTest
, SimpleGreenRect
) {
201 gfx::Rect
rect(this->device_viewport_size_
);
203 RenderPassId
id(1, 1);
204 scoped_ptr
<RenderPass
> pass
= CreateTestRootRenderPass(id
, rect
);
206 SharedQuadState
* shared_state
=
207 CreateTestSharedQuadState(gfx::Transform(), rect
, pass
.get());
209 SolidColorDrawQuad
* color_quad
=
210 pass
->CreateAndAppendDrawQuad
<SolidColorDrawQuad
>();
211 color_quad
->SetNew(shared_state
, rect
, rect
, SK_ColorGREEN
, false);
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 RenderPassId
child_id(2, 1);
227 scoped_ptr
<RenderPass
> child_pass
=
228 CreateTestRenderPass(child_id
, small_rect
, gfx::Transform());
230 SharedQuadState
* child_shared_state
=
231 CreateTestSharedQuadState(gfx::Transform(), small_rect
, child_pass
.get());
233 SolidColorDrawQuad
* color_quad
=
234 child_pass
->CreateAndAppendDrawQuad
<SolidColorDrawQuad
>();
235 color_quad
->SetNew(child_shared_state
, rect
, rect
, SK_ColorGREEN
, false);
237 RenderPassId
root_id(1, 1);
238 scoped_ptr
<RenderPass
> root_pass
=
239 CreateTestRenderPass(root_id
, rect
, gfx::Transform());
241 SharedQuadState
* root_shared_state
=
242 CreateTestSharedQuadState(gfx::Transform(), rect
, root_pass
.get());
244 CreateTestRenderPassDrawQuad(
245 root_shared_state
, small_rect
, child_id
, root_pass
.get());
247 RenderPass
* child_pass_ptr
= child_pass
.get();
249 RenderPassList pass_list
;
250 pass_list
.push_back(child_pass
.Pass());
251 pass_list
.push_back(root_pass
.Pass());
253 EXPECT_TRUE(this->RunPixelTestWithReadbackTarget(
256 base::FilePath(FILE_PATH_LITERAL("green_small.png")),
257 ExactPixelComparator(true)));
260 TYPED_TEST(RendererPixelTest
, PremultipliedTextureWithoutBackground
) {
261 gfx::Rect
rect(this->device_viewport_size_
);
263 RenderPassId
id(1, 1);
264 scoped_ptr
<RenderPass
> pass
= CreateTestRootRenderPass(id
, rect
);
266 SharedQuadState
* shared_state
=
267 CreateTestSharedQuadState(gfx::Transform(), rect
, pass
.get());
269 CreateTestTextureDrawQuad(gfx::Rect(this->device_viewport_size_
),
270 SkColorSetARGB(128, 0, 255, 0), // Texel color.
271 SK_ColorTRANSPARENT
, // Background color.
272 true, // Premultiplied alpha.
274 this->resource_provider_
.get(),
277 SolidColorDrawQuad
* color_quad
=
278 pass
->CreateAndAppendDrawQuad
<SolidColorDrawQuad
>();
279 color_quad
->SetNew(shared_state
, rect
, rect
, SK_ColorWHITE
, false);
281 RenderPassList pass_list
;
282 pass_list
.push_back(pass
.Pass());
284 EXPECT_TRUE(this->RunPixelTest(
286 base::FilePath(FILE_PATH_LITERAL("green_alpha.png")),
287 FuzzyPixelOffByOneComparator(true)));
290 TYPED_TEST(RendererPixelTest
, PremultipliedTextureWithBackground
) {
291 gfx::Rect
rect(this->device_viewport_size_
);
293 RenderPassId
id(1, 1);
294 scoped_ptr
<RenderPass
> pass
= CreateTestRootRenderPass(id
, rect
);
296 SharedQuadState
* texture_quad_state
=
297 CreateTestSharedQuadState(gfx::Transform(), rect
, pass
.get());
298 texture_quad_state
->opacity
= 0.8f
;
300 CreateTestTextureDrawQuad(gfx::Rect(this->device_viewport_size_
),
301 SkColorSetARGB(204, 120, 255, 120), // Texel color.
302 SK_ColorGREEN
, // Background color.
303 true, // Premultiplied alpha.
305 this->resource_provider_
.get(),
308 SharedQuadState
* color_quad_state
=
309 CreateTestSharedQuadState(gfx::Transform(), rect
, pass
.get());
310 SolidColorDrawQuad
* color_quad
=
311 pass
->CreateAndAppendDrawQuad
<SolidColorDrawQuad
>();
312 color_quad
->SetNew(color_quad_state
, rect
, rect
, SK_ColorWHITE
, false);
314 RenderPassList pass_list
;
315 pass_list
.push_back(pass
.Pass());
317 EXPECT_TRUE(this->RunPixelTest(
319 base::FilePath(FILE_PATH_LITERAL("green_alpha.png")),
320 FuzzyPixelOffByOneComparator(true)));
323 // TODO(skaslev): The software renderer does not support non-premultplied alpha.
324 TEST_F(GLRendererPixelTest
, NonPremultipliedTextureWithoutBackground
) {
325 gfx::Rect
rect(this->device_viewport_size_
);
327 RenderPassId
id(1, 1);
328 scoped_ptr
<RenderPass
> pass
= CreateTestRootRenderPass(id
, rect
);
330 SharedQuadState
* shared_state
=
331 CreateTestSharedQuadState(gfx::Transform(), rect
, pass
.get());
333 CreateTestTextureDrawQuad(gfx::Rect(this->device_viewport_size_
),
334 SkColorSetARGB(128, 0, 255, 0), // Texel color.
335 SK_ColorTRANSPARENT
, // Background color.
336 false, // Premultiplied alpha.
338 this->resource_provider_
.get(),
341 SolidColorDrawQuad
* color_quad
=
342 pass
->CreateAndAppendDrawQuad
<SolidColorDrawQuad
>();
343 color_quad
->SetNew(shared_state
, rect
, rect
, SK_ColorWHITE
, false);
345 RenderPassList pass_list
;
346 pass_list
.push_back(pass
.Pass());
348 EXPECT_TRUE(this->RunPixelTest(
350 base::FilePath(FILE_PATH_LITERAL("green_alpha.png")),
351 FuzzyPixelOffByOneComparator(true)));
354 // TODO(skaslev): The software renderer does not support non-premultplied alpha.
355 TEST_F(GLRendererPixelTest
, NonPremultipliedTextureWithBackground
) {
356 gfx::Rect
rect(this->device_viewport_size_
);
358 RenderPassId
id(1, 1);
359 scoped_ptr
<RenderPass
> pass
= CreateTestRootRenderPass(id
, rect
);
361 SharedQuadState
* texture_quad_state
=
362 CreateTestSharedQuadState(gfx::Transform(), rect
, pass
.get());
363 texture_quad_state
->opacity
= 0.8f
;
365 CreateTestTextureDrawQuad(gfx::Rect(this->device_viewport_size_
),
366 SkColorSetARGB(204, 120, 255, 120), // Texel color.
367 SK_ColorGREEN
, // Background color.
368 false, // Premultiplied alpha.
370 this->resource_provider_
.get(),
373 SharedQuadState
* color_quad_state
=
374 CreateTestSharedQuadState(gfx::Transform(), rect
, pass
.get());
375 SolidColorDrawQuad
* color_quad
=
376 pass
->CreateAndAppendDrawQuad
<SolidColorDrawQuad
>();
377 color_quad
->SetNew(color_quad_state
, rect
, rect
, SK_ColorWHITE
, false);
379 RenderPassList pass_list
;
380 pass_list
.push_back(pass
.Pass());
382 EXPECT_TRUE(this->RunPixelTest(
384 base::FilePath(FILE_PATH_LITERAL("green_alpha.png")),
385 FuzzyPixelOffByOneComparator(true)));
388 class VideoGLRendererPixelTest
: public GLRendererPixelTest
{
390 void CreateTestYUVVideoDrawQuad_Striped(const SharedQuadState
* shared_state
,
391 media::VideoFrame::Format format
,
393 const gfx::RectF
& tex_coord_rect
,
394 RenderPass
* render_pass
) {
395 const gfx::Rect
rect(this->device_viewport_size_
);
397 scoped_refptr
<media::VideoFrame
> video_frame
=
398 media::VideoFrame::CreateFrame(
399 format
, rect
.size(), rect
, rect
.size(), base::TimeDelta());
401 // YUV values representing a striped pattern, for validating texture
402 // coordinates for sampling.
406 for (int i
= 0; i
< video_frame
->rows(media::VideoFrame::kYPlane
); ++i
) {
407 uint8_t* y_row
= video_frame
->data(media::VideoFrame::kYPlane
) +
408 video_frame
->stride(media::VideoFrame::kYPlane
) * i
;
409 for (int j
= 0; j
< video_frame
->row_bytes(media::VideoFrame::kYPlane
);
411 y_row
[j
] = (y_value
+= 1);
414 for (int i
= 0; i
< video_frame
->rows(media::VideoFrame::kUPlane
); ++i
) {
415 uint8_t* u_row
= video_frame
->data(media::VideoFrame::kUPlane
) +
416 video_frame
->stride(media::VideoFrame::kUPlane
) * i
;
417 uint8_t* v_row
= video_frame
->data(media::VideoFrame::kVPlane
) +
418 video_frame
->stride(media::VideoFrame::kVPlane
) * i
;
419 for (int j
= 0; j
< video_frame
->row_bytes(media::VideoFrame::kUPlane
);
421 u_row
[j
] = (u_value
+= 3);
422 v_row
[j
] = (v_value
+= 5);
425 CreateTestYUVVideoDrawQuad_FromVideoFrame(
426 shared_state
, video_frame
, is_transparent
, tex_coord_rect
, render_pass
);
429 void CreateTestYUVVideoDrawQuad_Solid(const SharedQuadState
* shared_state
,
430 media::VideoFrame::Format format
,
432 const gfx::RectF
& tex_coord_rect
,
436 RenderPass
* render_pass
) {
437 const gfx::Rect
rect(this->device_viewport_size_
);
439 scoped_refptr
<media::VideoFrame
> video_frame
=
440 media::VideoFrame::CreateFrame(
441 format
, rect
.size(), rect
, rect
.size(), base::TimeDelta());
443 // YUV values of a solid, constant, color. Useful for testing that color
444 // space/color range are being handled properly.
445 memset(video_frame
->data(media::VideoFrame::kYPlane
),
447 video_frame
->stride(media::VideoFrame::kYPlane
) *
448 video_frame
->rows(media::VideoFrame::kYPlane
));
449 memset(video_frame
->data(media::VideoFrame::kUPlane
),
451 video_frame
->stride(media::VideoFrame::kUPlane
) *
452 video_frame
->rows(media::VideoFrame::kUPlane
));
453 memset(video_frame
->data(media::VideoFrame::kVPlane
),
455 video_frame
->stride(media::VideoFrame::kVPlane
) *
456 video_frame
->rows(media::VideoFrame::kVPlane
));
458 CreateTestYUVVideoDrawQuad_FromVideoFrame(
459 shared_state
, video_frame
, is_transparent
, tex_coord_rect
, render_pass
);
462 void CreateTestYUVVideoDrawQuad_FromVideoFrame(
463 const SharedQuadState
* shared_state
,
464 scoped_refptr
<media::VideoFrame
> video_frame
,
466 const gfx::RectF
& tex_coord_rect
,
467 RenderPass
* render_pass
) {
468 const bool with_alpha
= (video_frame
->format() == media::VideoFrame::YV12A
);
469 const YUVVideoDrawQuad::ColorSpace color_space
=
470 (video_frame
->format() == media::VideoFrame::YV12J
471 ? YUVVideoDrawQuad::REC_601_JPEG
472 : YUVVideoDrawQuad::REC_601
);
473 const gfx::Rect
rect(this->device_viewport_size_
);
474 const gfx::Rect
opaque_rect(0, 0, 0, 0);
477 memset(video_frame
->data(media::VideoFrame::kAPlane
),
478 is_transparent
? 0 : 128,
479 video_frame
->stride(media::VideoFrame::kAPlane
) *
480 video_frame
->rows(media::VideoFrame::kAPlane
));
482 VideoFrameExternalResources resources
=
483 video_resource_updater_
->CreateExternalResourcesFromVideoFrame(
486 EXPECT_EQ(VideoFrameExternalResources::YUV_RESOURCE
, resources
.type
);
487 EXPECT_EQ(media::VideoFrame::NumPlanes(video_frame
->format()),
488 resources
.mailboxes
.size());
489 EXPECT_EQ(media::VideoFrame::NumPlanes(video_frame
->format()),
490 resources
.release_callbacks
.size());
492 ResourceProvider::ResourceId y_resource
=
493 resource_provider_
->CreateResourceFromTextureMailbox(
494 resources
.mailboxes
[media::VideoFrame::kYPlane
],
495 SingleReleaseCallbackImpl::Create(
496 resources
.release_callbacks
[media::VideoFrame::kYPlane
]));
497 ResourceProvider::ResourceId u_resource
=
498 resource_provider_
->CreateResourceFromTextureMailbox(
499 resources
.mailboxes
[media::VideoFrame::kUPlane
],
500 SingleReleaseCallbackImpl::Create(
501 resources
.release_callbacks
[media::VideoFrame::kUPlane
]));
502 ResourceProvider::ResourceId v_resource
=
503 resource_provider_
->CreateResourceFromTextureMailbox(
504 resources
.mailboxes
[media::VideoFrame::kVPlane
],
505 SingleReleaseCallbackImpl::Create(
506 resources
.release_callbacks
[media::VideoFrame::kVPlane
]));
507 ResourceProvider::ResourceId a_resource
= 0;
509 a_resource
= resource_provider_
->CreateResourceFromTextureMailbox(
510 resources
.mailboxes
[media::VideoFrame::kAPlane
],
511 SingleReleaseCallbackImpl::Create(
512 resources
.release_callbacks
[media::VideoFrame::kAPlane
]));
515 YUVVideoDrawQuad
* yuv_quad
=
516 render_pass
->CreateAndAppendDrawQuad
<YUVVideoDrawQuad
>();
517 yuv_quad
->SetNew(shared_state
,
529 void SetUp() override
{
530 GLRendererPixelTest::SetUp();
531 video_resource_updater_
.reset(new VideoResourceUpdater(
532 output_surface_
->context_provider(), resource_provider_
.get()));
536 scoped_ptr
<VideoResourceUpdater
> video_resource_updater_
;
539 TEST_F(VideoGLRendererPixelTest
, SimpleYUVRect
) {
540 gfx::Rect
rect(this->device_viewport_size_
);
542 RenderPassId
id(1, 1);
543 scoped_ptr
<RenderPass
> pass
= CreateTestRootRenderPass(id
, rect
);
545 SharedQuadState
* shared_state
=
546 CreateTestSharedQuadState(gfx::Transform(), rect
, pass
.get());
548 CreateTestYUVVideoDrawQuad_Striped(shared_state
,
549 media::VideoFrame::YV12
,
551 gfx::RectF(0.0f
, 0.0f
, 1.0f
, 1.0f
),
554 RenderPassList pass_list
;
555 pass_list
.push_back(pass
.Pass());
558 this->RunPixelTest(&pass_list
,
559 base::FilePath(FILE_PATH_LITERAL("yuv_stripes.png")),
560 FuzzyPixelOffByOneComparator(true)));
563 TEST_F(VideoGLRendererPixelTest
, OffsetYUVRect
) {
564 gfx::Rect
rect(this->device_viewport_size_
);
566 RenderPassId
id(1, 1);
567 scoped_ptr
<RenderPass
> pass
= CreateTestRootRenderPass(id
, rect
);
569 SharedQuadState
* shared_state
=
570 CreateTestSharedQuadState(gfx::Transform(), rect
, pass
.get());
572 // Intentionally sets frame format to I420 for testing coverage.
573 CreateTestYUVVideoDrawQuad_Striped(shared_state
,
574 media::VideoFrame::I420
,
576 gfx::RectF(0.125f
, 0.25f
, 0.75f
, 0.5f
),
579 RenderPassList pass_list
;
580 pass_list
.push_back(pass
.Pass());
582 EXPECT_TRUE(this->RunPixelTest(
584 base::FilePath(FILE_PATH_LITERAL("yuv_stripes_offset.png")),
585 FuzzyPixelOffByOneComparator(true)));
588 TEST_F(VideoGLRendererPixelTest
, SimpleYUVRectBlack
) {
589 gfx::Rect
rect(this->device_viewport_size_
);
591 RenderPassId
id(1, 1);
592 scoped_ptr
<RenderPass
> pass
= CreateTestRootRenderPass(id
, rect
);
594 SharedQuadState
* shared_state
=
595 CreateTestSharedQuadState(gfx::Transform(), rect
, pass
.get());
597 // In MPEG color range YUV values of (15,128,128) should produce black.
598 CreateTestYUVVideoDrawQuad_Solid(shared_state
,
599 media::VideoFrame::YV12
,
601 gfx::RectF(0.0f
, 0.0f
, 1.0f
, 1.0f
),
607 RenderPassList pass_list
;
608 pass_list
.push_back(pass
.Pass());
610 // If we didn't get black out of the YUV values above, then we probably have a
611 // color range issue.
612 EXPECT_TRUE(this->RunPixelTest(&pass_list
,
613 base::FilePath(FILE_PATH_LITERAL("black.png")),
614 FuzzyPixelOffByOneComparator(true)));
617 TEST_F(VideoGLRendererPixelTest
, SimpleYUVJRect
) {
618 gfx::Rect
rect(this->device_viewport_size_
);
620 RenderPassId
id(1, 1);
621 scoped_ptr
<RenderPass
> pass
= CreateTestRootRenderPass(id
, rect
);
623 SharedQuadState
* shared_state
=
624 CreateTestSharedQuadState(gfx::Transform(), rect
, pass
.get());
626 // YUV of (149,43,21) should be green (0,255,0) in RGB.
627 CreateTestYUVVideoDrawQuad_Solid(shared_state
,
628 media::VideoFrame::YV12J
,
630 gfx::RectF(0.0f
, 0.0f
, 1.0f
, 1.0f
),
636 RenderPassList pass_list
;
637 pass_list
.push_back(pass
.Pass());
639 EXPECT_TRUE(this->RunPixelTest(&pass_list
,
640 base::FilePath(FILE_PATH_LITERAL("green.png")),
641 FuzzyPixelOffByOneComparator(true)));
644 TEST_F(VideoGLRendererPixelTest
, SimpleYUVJRectGrey
) {
645 gfx::Rect
rect(this->device_viewport_size_
);
647 RenderPassId
id(1, 1);
648 scoped_ptr
<RenderPass
> pass
= CreateTestRootRenderPass(id
, rect
);
650 SharedQuadState
* shared_state
=
651 CreateTestSharedQuadState(gfx::Transform(), rect
, pass
.get());
653 // Dark grey in JPEG color range (in MPEG, this is black).
654 CreateTestYUVVideoDrawQuad_Solid(shared_state
,
655 media::VideoFrame::YV12J
,
657 gfx::RectF(0.0f
, 0.0f
, 1.0f
, 1.0f
),
663 RenderPassList pass_list
;
664 pass_list
.push_back(pass
.Pass());
667 this->RunPixelTest(&pass_list
,
668 base::FilePath(FILE_PATH_LITERAL("dark_grey.png")),
669 FuzzyPixelOffByOneComparator(true)));
672 TEST_F(VideoGLRendererPixelTest
, SimpleYUVARect
) {
673 gfx::Rect
rect(this->device_viewport_size_
);
675 RenderPassId
id(1, 1);
676 scoped_ptr
<RenderPass
> pass
= CreateTestRootRenderPass(id
, rect
);
678 SharedQuadState
* shared_state
=
679 CreateTestSharedQuadState(gfx::Transform(), rect
, pass
.get());
681 CreateTestYUVVideoDrawQuad_Striped(shared_state
,
682 media::VideoFrame::YV12A
,
684 gfx::RectF(0.0f
, 0.0f
, 1.0f
, 1.0f
),
687 SolidColorDrawQuad
* color_quad
=
688 pass
->CreateAndAppendDrawQuad
<SolidColorDrawQuad
>();
689 color_quad
->SetNew(shared_state
, rect
, rect
, SK_ColorWHITE
, false);
691 RenderPassList pass_list
;
692 pass_list
.push_back(pass
.Pass());
694 EXPECT_TRUE(this->RunPixelTest(
696 base::FilePath(FILE_PATH_LITERAL("yuv_stripes_alpha.png")),
697 FuzzyPixelOffByOneComparator(true)));
700 TEST_F(VideoGLRendererPixelTest
, FullyTransparentYUVARect
) {
701 gfx::Rect
rect(this->device_viewport_size_
);
703 RenderPassId
id(1, 1);
704 scoped_ptr
<RenderPass
> pass
= CreateTestRootRenderPass(id
, rect
);
706 SharedQuadState
* shared_state
=
707 CreateTestSharedQuadState(gfx::Transform(), rect
, pass
.get());
709 CreateTestYUVVideoDrawQuad_Striped(shared_state
,
710 media::VideoFrame::YV12A
,
712 gfx::RectF(0.0f
, 0.0f
, 1.0f
, 1.0f
),
715 SolidColorDrawQuad
* color_quad
=
716 pass
->CreateAndAppendDrawQuad
<SolidColorDrawQuad
>();
717 color_quad
->SetNew(shared_state
, rect
, rect
, SK_ColorBLACK
, false);
719 RenderPassList pass_list
;
720 pass_list
.push_back(pass
.Pass());
722 EXPECT_TRUE(this->RunPixelTest(
724 base::FilePath(FILE_PATH_LITERAL("black.png")),
725 ExactPixelComparator(true)));
728 TYPED_TEST(RendererPixelTest
, FastPassColorFilterAlpha
) {
729 gfx::Rect
viewport_rect(this->device_viewport_size_
);
731 RenderPassId
root_pass_id(1, 1);
732 scoped_ptr
<RenderPass
> root_pass
=
733 CreateTestRootRenderPass(root_pass_id
, viewport_rect
);
735 RenderPassId
child_pass_id(2, 2);
736 gfx::Rect
pass_rect(this->device_viewport_size_
);
737 gfx::Transform transform_to_root
;
738 scoped_ptr
<RenderPass
> child_pass
=
739 CreateTestRenderPass(child_pass_id
, pass_rect
, transform_to_root
);
741 gfx::Transform content_to_target_transform
;
742 SharedQuadState
* shared_state
= CreateTestSharedQuadState(
743 content_to_target_transform
, viewport_rect
, child_pass
.get());
744 shared_state
->opacity
= 0.5f
;
746 gfx::Rect
blue_rect(0,
748 this->device_viewport_size_
.width(),
749 this->device_viewport_size_
.height() / 2);
750 SolidColorDrawQuad
* blue
=
751 child_pass
->CreateAndAppendDrawQuad
<SolidColorDrawQuad
>();
752 blue
->SetNew(shared_state
, blue_rect
, blue_rect
, SK_ColorBLUE
, false);
753 gfx::Rect
yellow_rect(0,
754 this->device_viewport_size_
.height() / 2,
755 this->device_viewport_size_
.width(),
756 this->device_viewport_size_
.height() / 2);
757 SolidColorDrawQuad
* yellow
=
758 child_pass
->CreateAndAppendDrawQuad
<SolidColorDrawQuad
>();
759 yellow
->SetNew(shared_state
, yellow_rect
, yellow_rect
, SK_ColorYELLOW
, false);
761 SharedQuadState
* blank_state
= CreateTestSharedQuadState(
762 content_to_target_transform
, viewport_rect
, child_pass
.get());
764 SolidColorDrawQuad
* white
=
765 child_pass
->CreateAndAppendDrawQuad
<SolidColorDrawQuad
>();
767 blank_state
, viewport_rect
, viewport_rect
, SK_ColorWHITE
, false);
769 SharedQuadState
* pass_shared_state
=
770 CreateTestSharedQuadState(gfx::Transform(), pass_rect
, root_pass
.get());
774 matrix
[0] = 0.213f
+ 0.787f
* amount
;
775 matrix
[1] = 0.715f
- 0.715f
* amount
;
776 matrix
[2] = 1.f
- (matrix
[0] + matrix
[1]);
777 matrix
[3] = matrix
[4] = 0;
778 matrix
[5] = 0.213f
- 0.213f
* amount
;
779 matrix
[6] = 0.715f
+ 0.285f
* amount
;
780 matrix
[7] = 1.f
- (matrix
[5] + matrix
[6]);
781 matrix
[8] = matrix
[9] = 0;
782 matrix
[10] = 0.213f
- 0.213f
* amount
;
783 matrix
[11] = 0.715f
- 0.715f
* amount
;
784 matrix
[12] = 1.f
- (matrix
[10] + matrix
[11]);
785 matrix
[13] = matrix
[14] = 0;
786 matrix
[15] = matrix
[16] = matrix
[17] = matrix
[19] = 0;
788 skia::RefPtr
<SkColorFilter
> colorFilter(
789 skia::AdoptRef(SkColorMatrixFilter::Create(matrix
)));
790 skia::RefPtr
<SkImageFilter
> filter
=
791 skia::AdoptRef(SkColorFilterImageFilter::Create(colorFilter
.get(), NULL
));
792 FilterOperations filters
;
793 filters
.Append(FilterOperation::CreateReferenceFilter(filter
));
795 RenderPassDrawQuad
* render_pass_quad
=
796 root_pass
->CreateAndAppendDrawQuad
<RenderPassDrawQuad
>();
797 render_pass_quad
->SetNew(pass_shared_state
,
808 RenderPassList pass_list
;
809 pass_list
.push_back(child_pass
.Pass());
810 pass_list
.push_back(root_pass
.Pass());
812 // This test has alpha=254 for the software renderer vs. alpha=255 for the gl
813 // renderer so use a fuzzy comparator.
814 EXPECT_TRUE(this->RunPixelTest(
816 base::FilePath(FILE_PATH_LITERAL("blue_yellow_alpha.png")),
817 FuzzyForSoftwareOnlyPixelComparator
<TypeParam
>(false)));
820 TYPED_TEST(RendererPixelTest
, FastPassSaturateFilter
) {
821 gfx::Rect
viewport_rect(this->device_viewport_size_
);
823 RenderPassId
root_pass_id(1, 1);
824 scoped_ptr
<RenderPass
> root_pass
=
825 CreateTestRootRenderPass(root_pass_id
, viewport_rect
);
827 RenderPassId
child_pass_id(2, 2);
828 gfx::Rect
pass_rect(this->device_viewport_size_
);
829 gfx::Transform transform_to_root
;
830 scoped_ptr
<RenderPass
> child_pass
=
831 CreateTestRenderPass(child_pass_id
, pass_rect
, transform_to_root
);
833 gfx::Transform content_to_target_transform
;
834 SharedQuadState
* shared_state
= CreateTestSharedQuadState(
835 content_to_target_transform
, viewport_rect
, child_pass
.get());
836 shared_state
->opacity
= 0.5f
;
838 gfx::Rect
blue_rect(0,
840 this->device_viewport_size_
.width(),
841 this->device_viewport_size_
.height() / 2);
842 SolidColorDrawQuad
* blue
=
843 child_pass
->CreateAndAppendDrawQuad
<SolidColorDrawQuad
>();
844 blue
->SetNew(shared_state
, blue_rect
, blue_rect
, SK_ColorBLUE
, false);
845 gfx::Rect
yellow_rect(0,
846 this->device_viewport_size_
.height() / 2,
847 this->device_viewport_size_
.width(),
848 this->device_viewport_size_
.height() / 2);
849 SolidColorDrawQuad
* yellow
=
850 child_pass
->CreateAndAppendDrawQuad
<SolidColorDrawQuad
>();
851 yellow
->SetNew(shared_state
, yellow_rect
, yellow_rect
, SK_ColorYELLOW
, false);
853 SharedQuadState
* blank_state
= CreateTestSharedQuadState(
854 content_to_target_transform
, viewport_rect
, child_pass
.get());
856 SolidColorDrawQuad
* white
=
857 child_pass
->CreateAndAppendDrawQuad
<SolidColorDrawQuad
>();
859 blank_state
, viewport_rect
, viewport_rect
, SK_ColorWHITE
, false);
861 SharedQuadState
* pass_shared_state
=
862 CreateTestSharedQuadState(gfx::Transform(), pass_rect
, root_pass
.get());
864 FilterOperations filters
;
865 filters
.Append(FilterOperation::CreateSaturateFilter(0.5f
));
867 RenderPassDrawQuad
* render_pass_quad
=
868 root_pass
->CreateAndAppendDrawQuad
<RenderPassDrawQuad
>();
869 render_pass_quad
->SetNew(pass_shared_state
,
880 RenderPassList pass_list
;
881 pass_list
.push_back(child_pass
.Pass());
882 pass_list
.push_back(root_pass
.Pass());
884 EXPECT_TRUE(this->RunPixelTest(
886 base::FilePath(FILE_PATH_LITERAL("blue_yellow_alpha.png")),
887 ExactPixelComparator(true)));
890 TYPED_TEST(RendererPixelTest
, FastPassFilterChain
) {
891 gfx::Rect
viewport_rect(this->device_viewport_size_
);
893 RenderPassId
root_pass_id(1, 1);
894 scoped_ptr
<RenderPass
> root_pass
=
895 CreateTestRootRenderPass(root_pass_id
, viewport_rect
);
897 RenderPassId
child_pass_id(2, 2);
898 gfx::Rect
pass_rect(this->device_viewport_size_
);
899 gfx::Transform transform_to_root
;
900 scoped_ptr
<RenderPass
> child_pass
=
901 CreateTestRenderPass(child_pass_id
, pass_rect
, transform_to_root
);
903 gfx::Transform content_to_target_transform
;
904 SharedQuadState
* shared_state
= CreateTestSharedQuadState(
905 content_to_target_transform
, viewport_rect
, child_pass
.get());
906 shared_state
->opacity
= 0.5f
;
908 gfx::Rect
blue_rect(0,
910 this->device_viewport_size_
.width(),
911 this->device_viewport_size_
.height() / 2);
912 SolidColorDrawQuad
* blue
=
913 child_pass
->CreateAndAppendDrawQuad
<SolidColorDrawQuad
>();
914 blue
->SetNew(shared_state
, blue_rect
, blue_rect
, SK_ColorBLUE
, false);
915 gfx::Rect
yellow_rect(0,
916 this->device_viewport_size_
.height() / 2,
917 this->device_viewport_size_
.width(),
918 this->device_viewport_size_
.height() / 2);
919 SolidColorDrawQuad
* yellow
=
920 child_pass
->CreateAndAppendDrawQuad
<SolidColorDrawQuad
>();
921 yellow
->SetNew(shared_state
, yellow_rect
, yellow_rect
, SK_ColorYELLOW
, false);
923 SharedQuadState
* blank_state
= CreateTestSharedQuadState(
924 content_to_target_transform
, viewport_rect
, child_pass
.get());
926 SolidColorDrawQuad
* white
=
927 child_pass
->CreateAndAppendDrawQuad
<SolidColorDrawQuad
>();
929 blank_state
, viewport_rect
, viewport_rect
, SK_ColorWHITE
, false);
931 SharedQuadState
* pass_shared_state
=
932 CreateTestSharedQuadState(gfx::Transform(), pass_rect
, root_pass
.get());
934 FilterOperations filters
;
935 filters
.Append(FilterOperation::CreateGrayscaleFilter(1.f
));
936 filters
.Append(FilterOperation::CreateBrightnessFilter(0.5f
));
938 RenderPassDrawQuad
* render_pass_quad
=
939 root_pass
->CreateAndAppendDrawQuad
<RenderPassDrawQuad
>();
940 render_pass_quad
->SetNew(pass_shared_state
,
951 RenderPassList pass_list
;
952 pass_list
.push_back(child_pass
.Pass());
953 pass_list
.push_back(root_pass
.Pass());
955 EXPECT_TRUE(this->RunPixelTest(
957 base::FilePath(FILE_PATH_LITERAL("blue_yellow_filter_chain.png")),
958 ExactPixelComparator(true)));
961 TYPED_TEST(RendererPixelTest
, FastPassColorFilterAlphaTranslation
) {
962 gfx::Rect
viewport_rect(this->device_viewport_size_
);
964 RenderPassId
root_pass_id(1, 1);
965 scoped_ptr
<RenderPass
> root_pass
=
966 CreateTestRootRenderPass(root_pass_id
, viewport_rect
);
968 RenderPassId
child_pass_id(2, 2);
969 gfx::Rect
pass_rect(this->device_viewport_size_
);
970 gfx::Transform transform_to_root
;
971 scoped_ptr
<RenderPass
> child_pass
=
972 CreateTestRenderPass(child_pass_id
, pass_rect
, transform_to_root
);
974 gfx::Transform content_to_target_transform
;
975 SharedQuadState
* shared_state
= CreateTestSharedQuadState(
976 content_to_target_transform
, viewport_rect
, child_pass
.get());
977 shared_state
->opacity
= 0.5f
;
979 gfx::Rect
blue_rect(0,
981 this->device_viewport_size_
.width(),
982 this->device_viewport_size_
.height() / 2);
983 SolidColorDrawQuad
* blue
=
984 child_pass
->CreateAndAppendDrawQuad
<SolidColorDrawQuad
>();
985 blue
->SetNew(shared_state
, blue_rect
, blue_rect
, SK_ColorBLUE
, false);
986 gfx::Rect
yellow_rect(0,
987 this->device_viewport_size_
.height() / 2,
988 this->device_viewport_size_
.width(),
989 this->device_viewport_size_
.height() / 2);
990 SolidColorDrawQuad
* yellow
=
991 child_pass
->CreateAndAppendDrawQuad
<SolidColorDrawQuad
>();
992 yellow
->SetNew(shared_state
, yellow_rect
, yellow_rect
, SK_ColorYELLOW
, false);
994 SharedQuadState
* blank_state
= CreateTestSharedQuadState(
995 content_to_target_transform
, viewport_rect
, child_pass
.get());
997 SolidColorDrawQuad
* white
=
998 child_pass
->CreateAndAppendDrawQuad
<SolidColorDrawQuad
>();
1000 blank_state
, viewport_rect
, viewport_rect
, SK_ColorWHITE
, false);
1002 SharedQuadState
* pass_shared_state
=
1003 CreateTestSharedQuadState(gfx::Transform(), pass_rect
, root_pass
.get());
1005 SkScalar matrix
[20];
1006 float amount
= 0.5f
;
1007 matrix
[0] = 0.213f
+ 0.787f
* amount
;
1008 matrix
[1] = 0.715f
- 0.715f
* amount
;
1009 matrix
[2] = 1.f
- (matrix
[0] + matrix
[1]);
1012 matrix
[5] = 0.213f
- 0.213f
* amount
;
1013 matrix
[6] = 0.715f
+ 0.285f
* amount
;
1014 matrix
[7] = 1.f
- (matrix
[5] + matrix
[6]);
1017 matrix
[10] = 0.213f
- 0.213f
* amount
;
1018 matrix
[11] = 0.715f
- 0.715f
* amount
;
1019 matrix
[12] = 1.f
- (matrix
[10] + matrix
[11]);
1022 matrix
[15] = matrix
[16] = matrix
[17] = matrix
[19] = 0;
1024 skia::RefPtr
<SkColorFilter
> colorFilter(
1025 skia::AdoptRef(SkColorMatrixFilter::Create(matrix
)));
1026 skia::RefPtr
<SkImageFilter
> filter
=
1027 skia::AdoptRef(SkColorFilterImageFilter::Create(colorFilter
.get(), NULL
));
1028 FilterOperations filters
;
1029 filters
.Append(FilterOperation::CreateReferenceFilter(filter
));
1031 RenderPassDrawQuad
* render_pass_quad
=
1032 root_pass
->CreateAndAppendDrawQuad
<RenderPassDrawQuad
>();
1033 render_pass_quad
->SetNew(pass_shared_state
,
1042 FilterOperations());
1044 RenderPassList pass_list
;
1046 pass_list
.push_back(child_pass
.Pass());
1047 pass_list
.push_back(root_pass
.Pass());
1049 // This test has alpha=254 for the software renderer vs. alpha=255 for the gl
1050 // renderer so use a fuzzy comparator.
1051 EXPECT_TRUE(this->RunPixelTest(
1053 base::FilePath(FILE_PATH_LITERAL("blue_yellow_alpha_translate.png")),
1054 FuzzyForSoftwareOnlyPixelComparator
<TypeParam
>(false)));
1057 TYPED_TEST(RendererPixelTest
, EnlargedRenderPassTexture
) {
1058 gfx::Rect
viewport_rect(this->device_viewport_size_
);
1060 RenderPassId
root_pass_id(1, 1);
1061 scoped_ptr
<RenderPass
> root_pass
=
1062 CreateTestRootRenderPass(root_pass_id
, viewport_rect
);
1064 RenderPassId
child_pass_id(2, 2);
1065 gfx::Rect
pass_rect(this->device_viewport_size_
);
1066 gfx::Transform transform_to_root
;
1067 scoped_ptr
<RenderPass
> child_pass
=
1068 CreateTestRenderPass(child_pass_id
, pass_rect
, transform_to_root
);
1070 gfx::Transform content_to_target_transform
;
1071 SharedQuadState
* shared_state
= CreateTestSharedQuadState(
1072 content_to_target_transform
, viewport_rect
, child_pass
.get());
1074 gfx::Rect
blue_rect(0,
1076 this->device_viewport_size_
.width(),
1077 this->device_viewport_size_
.height() / 2);
1078 SolidColorDrawQuad
* blue
=
1079 child_pass
->CreateAndAppendDrawQuad
<SolidColorDrawQuad
>();
1080 blue
->SetNew(shared_state
, blue_rect
, blue_rect
, SK_ColorBLUE
, false);
1081 gfx::Rect
yellow_rect(0,
1082 this->device_viewport_size_
.height() / 2,
1083 this->device_viewport_size_
.width(),
1084 this->device_viewport_size_
.height() / 2);
1085 SolidColorDrawQuad
* yellow
=
1086 child_pass
->CreateAndAppendDrawQuad
<SolidColorDrawQuad
>();
1087 yellow
->SetNew(shared_state
, yellow_rect
, yellow_rect
, SK_ColorYELLOW
, false);
1089 SharedQuadState
* pass_shared_state
=
1090 CreateTestSharedQuadState(gfx::Transform(), pass_rect
, root_pass
.get());
1091 CreateTestRenderPassDrawQuad(
1092 pass_shared_state
, pass_rect
, child_pass_id
, root_pass
.get());
1094 RenderPassList pass_list
;
1095 pass_list
.push_back(child_pass
.Pass());
1096 pass_list
.push_back(root_pass
.Pass());
1098 this->renderer_
->SetEnlargePassTextureAmountForTesting(gfx::Vector2d(50, 75));
1100 EXPECT_TRUE(this->RunPixelTest(
1102 base::FilePath(FILE_PATH_LITERAL("blue_yellow.png")),
1103 ExactPixelComparator(true)));
1106 TYPED_TEST(RendererPixelTest
, EnlargedRenderPassTextureWithAntiAliasing
) {
1107 gfx::Rect
viewport_rect(this->device_viewport_size_
);
1109 RenderPassId
root_pass_id(1, 1);
1110 scoped_ptr
<RenderPass
> root_pass
=
1111 CreateTestRootRenderPass(root_pass_id
, viewport_rect
);
1113 RenderPassId
child_pass_id(2, 2);
1114 gfx::Rect
pass_rect(this->device_viewport_size_
);
1115 gfx::Transform transform_to_root
;
1116 scoped_ptr
<RenderPass
> child_pass
=
1117 CreateTestRenderPass(child_pass_id
, pass_rect
, transform_to_root
);
1119 gfx::Transform content_to_target_transform
;
1120 SharedQuadState
* shared_state
= CreateTestSharedQuadState(
1121 content_to_target_transform
, viewport_rect
, child_pass
.get());
1123 gfx::Rect
blue_rect(0,
1125 this->device_viewport_size_
.width(),
1126 this->device_viewport_size_
.height() / 2);
1127 SolidColorDrawQuad
* blue
=
1128 child_pass
->CreateAndAppendDrawQuad
<SolidColorDrawQuad
>();
1129 blue
->SetNew(shared_state
, blue_rect
, blue_rect
, SK_ColorBLUE
, false);
1130 gfx::Rect
yellow_rect(0,
1131 this->device_viewport_size_
.height() / 2,
1132 this->device_viewport_size_
.width(),
1133 this->device_viewport_size_
.height() / 2);
1134 SolidColorDrawQuad
* yellow
=
1135 child_pass
->CreateAndAppendDrawQuad
<SolidColorDrawQuad
>();
1136 yellow
->SetNew(shared_state
, yellow_rect
, yellow_rect
, SK_ColorYELLOW
, false);
1138 gfx::Transform aa_transform
;
1139 aa_transform
.Translate(0.5, 0.0);
1141 SharedQuadState
* pass_shared_state
=
1142 CreateTestSharedQuadState(aa_transform
, pass_rect
, root_pass
.get());
1143 CreateTestRenderPassDrawQuad(
1144 pass_shared_state
, pass_rect
, child_pass_id
, root_pass
.get());
1146 SharedQuadState
* root_shared_state
= CreateTestSharedQuadState(
1147 gfx::Transform(), viewport_rect
, root_pass
.get());
1148 SolidColorDrawQuad
* background
=
1149 root_pass
->CreateAndAppendDrawQuad
<SolidColorDrawQuad
>();
1150 background
->SetNew(root_shared_state
,
1151 gfx::Rect(this->device_viewport_size_
),
1152 gfx::Rect(this->device_viewport_size_
),
1156 RenderPassList pass_list
;
1157 pass_list
.push_back(child_pass
.Pass());
1158 pass_list
.push_back(root_pass
.Pass());
1160 this->renderer_
->SetEnlargePassTextureAmountForTesting(gfx::Vector2d(50, 75));
1162 EXPECT_TRUE(this->RunPixelTest(
1164 base::FilePath(FILE_PATH_LITERAL("blue_yellow_anti_aliasing.png")),
1165 FuzzyPixelOffByOneComparator(true)));
1168 // This tests the case where we have a RenderPass with a mask, but the quad
1169 // for the masked surface does not include the full surface texture.
1170 TYPED_TEST(RendererPixelTest
, RenderPassAndMaskWithPartialQuad
) {
1171 gfx::Rect
viewport_rect(this->device_viewport_size_
);
1173 RenderPassId
root_pass_id(1, 1);
1174 scoped_ptr
<RenderPass
> root_pass
=
1175 CreateTestRootRenderPass(root_pass_id
, viewport_rect
);
1176 SharedQuadState
* root_pass_shared_state
= CreateTestSharedQuadState(
1177 gfx::Transform(), viewport_rect
, root_pass
.get());
1179 RenderPassId
child_pass_id(2, 2);
1180 gfx::Transform transform_to_root
;
1181 scoped_ptr
<RenderPass
> child_pass
=
1182 CreateTestRenderPass(child_pass_id
, viewport_rect
, transform_to_root
);
1183 SharedQuadState
* child_pass_shared_state
= CreateTestSharedQuadState(
1184 gfx::Transform(), viewport_rect
, child_pass
.get());
1186 // The child render pass is just a green box.
1187 static const SkColor kCSSGreen
= 0xff008000;
1188 SolidColorDrawQuad
* green
=
1189 child_pass
->CreateAndAppendDrawQuad
<SolidColorDrawQuad
>();
1191 child_pass_shared_state
, viewport_rect
, viewport_rect
, kCSSGreen
, false);
1194 gfx::Rect mask_rect
= viewport_rect
;
1197 SkImageInfo::MakeN32Premul(mask_rect
.width(), mask_rect
.height()));
1198 SkCanvas
canvas(bitmap
);
1200 paint
.setStyle(SkPaint::kStroke_Style
);
1201 paint
.setStrokeWidth(SkIntToScalar(4));
1202 paint
.setColor(SK_ColorWHITE
);
1203 canvas
.clear(SK_ColorTRANSPARENT
);
1204 gfx::Rect rect
= mask_rect
;
1205 while (!rect
.IsEmpty()) {
1206 rect
.Inset(6, 6, 4, 4);
1208 SkRect::MakeXYWH(rect
.x(), rect
.y(), rect
.width(), rect
.height()),
1210 rect
.Inset(6, 6, 4, 4);
1213 ResourceProvider::ResourceId mask_resource_id
=
1214 this->resource_provider_
->CreateResource(
1217 ResourceProvider::TextureHintImmutable
,
1220 SkAutoLockPixels
lock(bitmap
);
1221 this->resource_provider_
->SetPixels(
1223 reinterpret_cast<uint8_t*>(bitmap
.getPixels()),
1229 // This RenderPassDrawQuad does not include the full |viewport_rect| which is
1230 // the size of the child render pass.
1231 gfx::Rect sub_rect
= gfx::Rect(50, 50, 200, 100);
1232 EXPECT_NE(sub_rect
.x(), child_pass
->output_rect
.x());
1233 EXPECT_NE(sub_rect
.y(), child_pass
->output_rect
.y());
1234 EXPECT_NE(sub_rect
.right(), child_pass
->output_rect
.right());
1235 EXPECT_NE(sub_rect
.bottom(), child_pass
->output_rect
.bottom());
1237 // Set up a mask on the RenderPassDrawQuad.
1238 RenderPassDrawQuad
* mask_quad
=
1239 root_pass
->CreateAndAppendDrawQuad
<RenderPassDrawQuad
>();
1240 mask_quad
->SetNew(root_pass_shared_state
,
1245 gfx::Vector2dF(2.f
, 1.f
), // mask_uv_scale
1246 gfx::Size(mask_rect
.size()), // mask_texture_size
1247 FilterOperations(), // foreground filters
1248 gfx::Vector2dF(), // filters scale
1249 FilterOperations()); // background filters
1251 // White background behind the masked render pass.
1252 SolidColorDrawQuad
* white
=
1253 root_pass
->CreateAndAppendDrawQuad
<SolidColorDrawQuad
>();
1254 white
->SetNew(root_pass_shared_state
,
1260 RenderPassList pass_list
;
1261 pass_list
.push_back(child_pass
.Pass());
1262 pass_list
.push_back(root_pass
.Pass());
1264 EXPECT_TRUE(this->RunPixelTest(
1266 base::FilePath(FILE_PATH_LITERAL("mask_bottom_right.png")),
1267 ExactPixelComparator(true)));
1270 template <typename RendererType
>
1271 class RendererPixelTestWithBackgroundFilter
1272 : public RendererPixelTest
<RendererType
> {
1274 void SetUpRenderPassList() {
1275 gfx::Rect
device_viewport_rect(this->device_viewport_size_
);
1277 RenderPassId
root_id(1, 1);
1278 scoped_ptr
<RenderPass
> root_pass
=
1279 CreateTestRootRenderPass(root_id
, device_viewport_rect
);
1280 root_pass
->has_transparent_background
= false;
1282 gfx::Transform identity_content_to_target_transform
;
1284 RenderPassId
filter_pass_id(2, 1);
1285 gfx::Transform transform_to_root
;
1286 scoped_ptr
<RenderPass
> filter_pass
=
1287 CreateTestRenderPass(filter_pass_id
,
1288 filter_pass_content_rect_
,
1291 // A non-visible quad in the filtering render pass.
1293 SharedQuadState
* shared_state
=
1294 CreateTestSharedQuadState(identity_content_to_target_transform
,
1295 filter_pass_content_rect_
,
1297 SolidColorDrawQuad
* color_quad
=
1298 filter_pass
->CreateAndAppendDrawQuad
<SolidColorDrawQuad
>();
1299 color_quad
->SetNew(shared_state
,
1300 filter_pass_content_rect_
,
1301 filter_pass_content_rect_
,
1302 SK_ColorTRANSPARENT
,
1307 SharedQuadState
* shared_state
=
1308 CreateTestSharedQuadState(filter_pass_to_target_transform_
,
1309 filter_pass_content_rect_
,
1311 RenderPassDrawQuad
* filter_pass_quad
=
1312 root_pass
->CreateAndAppendDrawQuad
<RenderPassDrawQuad
>();
1313 filter_pass_quad
->SetNew(shared_state
,
1314 filter_pass_content_rect_
,
1315 filter_pass_content_rect_
,
1317 0, // mask_resource_id
1318 gfx::Vector2dF(), // mask_uv_scale
1319 gfx::Size(), // mask_texture_size
1320 FilterOperations(), // filters
1321 gfx::Vector2dF(), // filters_scale
1322 this->background_filters_
);
1325 const int kColumnWidth
= device_viewport_rect
.width() / 3;
1327 gfx::Rect left_rect
= gfx::Rect(0, 0, kColumnWidth
, 20);
1328 for (int i
= 0; left_rect
.y() < device_viewport_rect
.height(); ++i
) {
1329 SharedQuadState
* shared_state
= CreateTestSharedQuadState(
1330 identity_content_to_target_transform
, left_rect
, root_pass
.get());
1331 SolidColorDrawQuad
* color_quad
=
1332 root_pass
->CreateAndAppendDrawQuad
<SolidColorDrawQuad
>();
1334 shared_state
, left_rect
, left_rect
, SK_ColorGREEN
, false);
1335 left_rect
+= gfx::Vector2d(0, left_rect
.height() + 1);
1338 gfx::Rect middle_rect
= gfx::Rect(kColumnWidth
+1, 0, kColumnWidth
, 20);
1339 for (int i
= 0; middle_rect
.y() < device_viewport_rect
.height(); ++i
) {
1340 SharedQuadState
* shared_state
= CreateTestSharedQuadState(
1341 identity_content_to_target_transform
, middle_rect
, root_pass
.get());
1342 SolidColorDrawQuad
* color_quad
=
1343 root_pass
->CreateAndAppendDrawQuad
<SolidColorDrawQuad
>();
1345 shared_state
, middle_rect
, middle_rect
, SK_ColorRED
, false);
1346 middle_rect
+= gfx::Vector2d(0, middle_rect
.height() + 1);
1349 gfx::Rect right_rect
= gfx::Rect((kColumnWidth
+1)*2, 0, kColumnWidth
, 20);
1350 for (int i
= 0; right_rect
.y() < device_viewport_rect
.height(); ++i
) {
1351 SharedQuadState
* shared_state
= CreateTestSharedQuadState(
1352 identity_content_to_target_transform
, right_rect
, root_pass
.get());
1353 SolidColorDrawQuad
* color_quad
=
1354 root_pass
->CreateAndAppendDrawQuad
<SolidColorDrawQuad
>();
1356 shared_state
, right_rect
, right_rect
, SK_ColorBLUE
, false);
1357 right_rect
+= gfx::Vector2d(0, right_rect
.height() + 1);
1360 SharedQuadState
* shared_state
=
1361 CreateTestSharedQuadState(identity_content_to_target_transform
,
1362 device_viewport_rect
,
1364 SolidColorDrawQuad
* background_quad
=
1365 root_pass
->CreateAndAppendDrawQuad
<SolidColorDrawQuad
>();
1366 background_quad
->SetNew(shared_state
,
1367 device_viewport_rect
,
1368 device_viewport_rect
,
1372 pass_list_
.push_back(filter_pass
.Pass());
1373 pass_list_
.push_back(root_pass
.Pass());
1376 RenderPassList pass_list_
;
1377 FilterOperations background_filters_
;
1378 gfx::Transform filter_pass_to_target_transform_
;
1379 gfx::Rect filter_pass_content_rect_
;
1382 typedef ::testing::Types
<GLRenderer
, SoftwareRenderer
>
1383 BackgroundFilterRendererTypes
;
1384 TYPED_TEST_CASE(RendererPixelTestWithBackgroundFilter
,
1385 BackgroundFilterRendererTypes
);
1387 typedef RendererPixelTestWithBackgroundFilter
<GLRenderer
>
1388 GLRendererPixelTestWithBackgroundFilter
;
1390 // TODO(skaslev): The software renderer does not support filters yet.
1391 TEST_F(GLRendererPixelTestWithBackgroundFilter
, InvertFilter
) {
1392 this->background_filters_
.Append(
1393 FilterOperation::CreateInvertFilter(1.f
));
1395 this->filter_pass_content_rect_
= gfx::Rect(this->device_viewport_size_
);
1396 this->filter_pass_content_rect_
.Inset(12, 14, 16, 18);
1398 this->SetUpRenderPassList();
1399 EXPECT_TRUE(this->RunPixelTest(
1401 base::FilePath(FILE_PATH_LITERAL("background_filter.png")),
1402 ExactPixelComparator(true)));
1405 class ExternalStencilPixelTest
: public GLRendererPixelTest
{
1407 void ClearBackgroundToGreen() {
1408 GLES2Interface
* gl
= output_surface_
->context_provider()->ContextGL();
1409 output_surface_
->EnsureBackbuffer();
1410 output_surface_
->Reshape(device_viewport_size_
, 1);
1411 gl
->ClearColor(0.f
, 1.f
, 0.f
, 1.f
);
1412 gl
->Clear(GL_COLOR_BUFFER_BIT
);
1415 void PopulateStencilBuffer() {
1416 // Set two quadrants of the stencil buffer to 1.
1417 GLES2Interface
* gl
= output_surface_
->context_provider()->ContextGL();
1418 output_surface_
->EnsureBackbuffer();
1419 output_surface_
->Reshape(device_viewport_size_
, 1);
1420 gl
->ClearStencil(0);
1421 gl
->Clear(GL_STENCIL_BUFFER_BIT
);
1422 gl
->Enable(GL_SCISSOR_TEST
);
1423 gl
->ClearStencil(1);
1426 device_viewport_size_
.width() / 2,
1427 device_viewport_size_
.height() / 2);
1428 gl
->Clear(GL_STENCIL_BUFFER_BIT
);
1429 gl
->Scissor(device_viewport_size_
.width() / 2,
1430 device_viewport_size_
.height() / 2,
1431 device_viewport_size_
.width(),
1432 device_viewport_size_
.height());
1433 gl
->Clear(GL_STENCIL_BUFFER_BIT
);
1437 TEST_F(ExternalStencilPixelTest
, StencilTestEnabled
) {
1438 ClearBackgroundToGreen();
1439 PopulateStencilBuffer();
1440 this->EnableExternalStencilTest();
1442 // Draw a blue quad that covers the entire device viewport. It should be
1443 // clipped to the bottom left and top right corners by the external stencil.
1444 gfx::Rect
rect(this->device_viewport_size_
);
1445 RenderPassId
id(1, 1);
1446 scoped_ptr
<RenderPass
> pass
= CreateTestRootRenderPass(id
, rect
);
1447 SharedQuadState
* blue_shared_state
=
1448 CreateTestSharedQuadState(gfx::Transform(), rect
, pass
.get());
1449 SolidColorDrawQuad
* blue
=
1450 pass
->CreateAndAppendDrawQuad
<SolidColorDrawQuad
>();
1451 blue
->SetNew(blue_shared_state
, rect
, rect
, SK_ColorBLUE
, false);
1452 pass
->has_transparent_background
= false;
1453 RenderPassList pass_list
;
1454 pass_list
.push_back(pass
.Pass());
1456 EXPECT_TRUE(this->RunPixelTest(
1458 base::FilePath(FILE_PATH_LITERAL("four_blue_green_checkers.png")),
1459 ExactPixelComparator(true)));
1462 TEST_F(ExternalStencilPixelTest
, StencilTestDisabled
) {
1463 PopulateStencilBuffer();
1465 // Draw a green quad that covers the entire device viewport. The stencil
1466 // buffer should be ignored.
1467 gfx::Rect
rect(this->device_viewport_size_
);
1468 RenderPassId
id(1, 1);
1469 scoped_ptr
<RenderPass
> pass
= CreateTestRootRenderPass(id
, rect
);
1470 SharedQuadState
* green_shared_state
=
1471 CreateTestSharedQuadState(gfx::Transform(), rect
, pass
.get());
1472 SolidColorDrawQuad
* green
=
1473 pass
->CreateAndAppendDrawQuad
<SolidColorDrawQuad
>();
1474 green
->SetNew(green_shared_state
, rect
, rect
, SK_ColorGREEN
, false);
1475 RenderPassList pass_list
;
1476 pass_list
.push_back(pass
.Pass());
1478 EXPECT_TRUE(this->RunPixelTest(
1480 base::FilePath(FILE_PATH_LITERAL("green.png")),
1481 ExactPixelComparator(true)));
1484 TEST_F(ExternalStencilPixelTest
, RenderSurfacesIgnoreStencil
) {
1485 // The stencil test should apply only to the final render pass.
1486 ClearBackgroundToGreen();
1487 PopulateStencilBuffer();
1488 this->EnableExternalStencilTest();
1490 gfx::Rect
viewport_rect(this->device_viewport_size_
);
1492 RenderPassId
root_pass_id(1, 1);
1493 scoped_ptr
<RenderPass
> root_pass
=
1494 CreateTestRootRenderPass(root_pass_id
, viewport_rect
);
1495 root_pass
->has_transparent_background
= false;
1497 RenderPassId
child_pass_id(2, 2);
1498 gfx::Rect
pass_rect(this->device_viewport_size_
);
1499 gfx::Transform transform_to_root
;
1500 scoped_ptr
<RenderPass
> child_pass
=
1501 CreateTestRenderPass(child_pass_id
, pass_rect
, transform_to_root
);
1503 gfx::Transform content_to_target_transform
;
1504 SharedQuadState
* shared_state
= CreateTestSharedQuadState(
1505 content_to_target_transform
, viewport_rect
, child_pass
.get());
1507 gfx::Rect
blue_rect(0,
1509 this->device_viewport_size_
.width(),
1510 this->device_viewport_size_
.height());
1511 SolidColorDrawQuad
* blue
=
1512 child_pass
->CreateAndAppendDrawQuad
<SolidColorDrawQuad
>();
1513 blue
->SetNew(shared_state
, blue_rect
, blue_rect
, SK_ColorBLUE
, false);
1515 SharedQuadState
* pass_shared_state
=
1516 CreateTestSharedQuadState(gfx::Transform(), pass_rect
, root_pass
.get());
1517 CreateTestRenderPassDrawQuad(
1518 pass_shared_state
, pass_rect
, child_pass_id
, root_pass
.get());
1519 RenderPassList pass_list
;
1520 pass_list
.push_back(child_pass
.Pass());
1521 pass_list
.push_back(root_pass
.Pass());
1523 EXPECT_TRUE(this->RunPixelTest(
1525 base::FilePath(FILE_PATH_LITERAL("four_blue_green_checkers.png")),
1526 ExactPixelComparator(true)));
1529 TEST_F(ExternalStencilPixelTest
, DeviceClip
) {
1530 ClearBackgroundToGreen();
1531 gfx::Rect
clip_rect(gfx::Point(150, 150), gfx::Size(50, 50));
1532 this->ForceDeviceClip(clip_rect
);
1534 // Draw a blue quad that covers the entire device viewport. It should be
1535 // clipped to the bottom right corner by the device clip.
1536 gfx::Rect
rect(this->device_viewport_size_
);
1537 RenderPassId
id(1, 1);
1538 scoped_ptr
<RenderPass
> pass
= CreateTestRootRenderPass(id
, rect
);
1539 SharedQuadState
* blue_shared_state
=
1540 CreateTestSharedQuadState(gfx::Transform(), rect
, pass
.get());
1541 SolidColorDrawQuad
* blue
=
1542 pass
->CreateAndAppendDrawQuad
<SolidColorDrawQuad
>();
1543 blue
->SetNew(blue_shared_state
, rect
, rect
, SK_ColorBLUE
, false);
1544 RenderPassList pass_list
;
1545 pass_list
.push_back(pass
.Pass());
1547 EXPECT_TRUE(this->RunPixelTest(
1549 base::FilePath(FILE_PATH_LITERAL("green_with_blue_corner.png")),
1550 ExactPixelComparator(true)));
1553 // Software renderer does not support anti-aliased edges.
1554 TEST_F(GLRendererPixelTest
, AntiAliasing
) {
1555 gfx::Rect
rect(this->device_viewport_size_
);
1557 RenderPassId
id(1, 1);
1558 scoped_ptr
<RenderPass
> pass
= CreateTestRootRenderPass(id
, rect
);
1560 gfx::Transform red_content_to_target_transform
;
1561 red_content_to_target_transform
.Rotate(10);
1562 SharedQuadState
* red_shared_state
= CreateTestSharedQuadState(
1563 red_content_to_target_transform
, rect
, pass
.get());
1565 SolidColorDrawQuad
* red
= pass
->CreateAndAppendDrawQuad
<SolidColorDrawQuad
>();
1566 red
->SetNew(red_shared_state
, rect
, rect
, SK_ColorRED
, false);
1568 gfx::Transform yellow_content_to_target_transform
;
1569 yellow_content_to_target_transform
.Rotate(5);
1570 SharedQuadState
* yellow_shared_state
= CreateTestSharedQuadState(
1571 yellow_content_to_target_transform
, rect
, pass
.get());
1573 SolidColorDrawQuad
* yellow
=
1574 pass
->CreateAndAppendDrawQuad
<SolidColorDrawQuad
>();
1575 yellow
->SetNew(yellow_shared_state
, rect
, rect
, SK_ColorYELLOW
, false);
1577 gfx::Transform blue_content_to_target_transform
;
1578 SharedQuadState
* blue_shared_state
= CreateTestSharedQuadState(
1579 blue_content_to_target_transform
, rect
, pass
.get());
1581 SolidColorDrawQuad
* blue
=
1582 pass
->CreateAndAppendDrawQuad
<SolidColorDrawQuad
>();
1583 blue
->SetNew(blue_shared_state
, rect
, rect
, SK_ColorBLUE
, false);
1585 RenderPassList pass_list
;
1586 pass_list
.push_back(pass
.Pass());
1588 EXPECT_TRUE(this->RunPixelTest(
1590 base::FilePath(FILE_PATH_LITERAL("anti_aliasing.png")),
1591 FuzzyPixelOffByOneComparator(true)));
1594 // This test tests that anti-aliasing works for axis aligned quads.
1595 // Anti-aliasing is only supported in the gl renderer.
1596 TEST_F(GLRendererPixelTest
, AxisAligned
) {
1597 gfx::Rect
rect(this->device_viewport_size_
);
1599 RenderPassId
id(1, 1);
1600 gfx::Transform transform_to_root
;
1601 scoped_ptr
<RenderPass
> pass
=
1602 CreateTestRenderPass(id
, rect
, transform_to_root
);
1604 gfx::Transform red_content_to_target_transform
;
1605 red_content_to_target_transform
.Translate(50, 50);
1606 red_content_to_target_transform
.Scale(
1607 0.5f
+ 1.0f
/ (rect
.width() * 2.0f
),
1608 0.5f
+ 1.0f
/ (rect
.height() * 2.0f
));
1609 SharedQuadState
* red_shared_state
= CreateTestSharedQuadState(
1610 red_content_to_target_transform
, rect
, pass
.get());
1612 SolidColorDrawQuad
* red
= pass
->CreateAndAppendDrawQuad
<SolidColorDrawQuad
>();
1613 red
->SetNew(red_shared_state
, rect
, rect
, SK_ColorRED
, false);
1615 gfx::Transform yellow_content_to_target_transform
;
1616 yellow_content_to_target_transform
.Translate(25.5f
, 25.5f
);
1617 yellow_content_to_target_transform
.Scale(0.5f
, 0.5f
);
1618 SharedQuadState
* yellow_shared_state
= CreateTestSharedQuadState(
1619 yellow_content_to_target_transform
, rect
, pass
.get());
1621 SolidColorDrawQuad
* yellow
=
1622 pass
->CreateAndAppendDrawQuad
<SolidColorDrawQuad
>();
1623 yellow
->SetNew(yellow_shared_state
, rect
, rect
, SK_ColorYELLOW
, false);
1625 gfx::Transform blue_content_to_target_transform
;
1626 SharedQuadState
* blue_shared_state
= CreateTestSharedQuadState(
1627 blue_content_to_target_transform
, rect
, pass
.get());
1629 SolidColorDrawQuad
* blue
=
1630 pass
->CreateAndAppendDrawQuad
<SolidColorDrawQuad
>();
1631 blue
->SetNew(blue_shared_state
, rect
, rect
, SK_ColorBLUE
, false);
1633 RenderPassList pass_list
;
1634 pass_list
.push_back(pass
.Pass());
1636 EXPECT_TRUE(this->RunPixelTest(
1638 base::FilePath(FILE_PATH_LITERAL("axis_aligned.png")),
1639 ExactPixelComparator(true)));
1642 // This test tests that forcing anti-aliasing off works as expected.
1643 // Anti-aliasing is only supported in the gl renderer.
1644 TEST_F(GLRendererPixelTest
, ForceAntiAliasingOff
) {
1645 gfx::Rect
rect(this->device_viewport_size_
);
1647 RenderPassId
id(1, 1);
1648 gfx::Transform transform_to_root
;
1649 scoped_ptr
<RenderPass
> pass
=
1650 CreateTestRenderPass(id
, rect
, transform_to_root
);
1652 gfx::Transform hole_content_to_target_transform
;
1653 hole_content_to_target_transform
.Translate(50, 50);
1654 hole_content_to_target_transform
.Scale(
1655 0.5f
+ 1.0f
/ (rect
.width() * 2.0f
),
1656 0.5f
+ 1.0f
/ (rect
.height() * 2.0f
));
1657 SharedQuadState
* hole_shared_state
= CreateTestSharedQuadState(
1658 hole_content_to_target_transform
, rect
, pass
.get());
1660 SolidColorDrawQuad
* hole
=
1661 pass
->CreateAndAppendDrawQuad
<SolidColorDrawQuad
>();
1663 hole_shared_state
, rect
, rect
, rect
, false, SK_ColorTRANSPARENT
, true);
1665 gfx::Transform green_content_to_target_transform
;
1666 SharedQuadState
* green_shared_state
= CreateTestSharedQuadState(
1667 green_content_to_target_transform
, rect
, pass
.get());
1669 SolidColorDrawQuad
* green
=
1670 pass
->CreateAndAppendDrawQuad
<SolidColorDrawQuad
>();
1671 green
->SetNew(green_shared_state
, rect
, rect
, SK_ColorGREEN
, false);
1673 RenderPassList pass_list
;
1674 pass_list
.push_back(pass
.Pass());
1676 EXPECT_TRUE(this->RunPixelTest(
1678 base::FilePath(FILE_PATH_LITERAL("force_anti_aliasing_off.png")),
1679 ExactPixelComparator(false)));
1682 TEST_F(GLRendererPixelTest
, AntiAliasingPerspective
) {
1683 gfx::Rect
rect(this->device_viewport_size_
);
1685 scoped_ptr
<RenderPass
> pass
=
1686 CreateTestRootRenderPass(RenderPassId(1, 1), rect
);
1688 gfx::Rect
red_rect(0, 0, 180, 500);
1689 gfx::Transform
red_content_to_target_transform(
1690 1.0f
, 2.4520f
, 10.6206f
, 19.0f
,
1691 0.0f
, 0.3528f
, 5.9737f
, 9.5f
,
1692 0.0f
, -0.2250f
, -0.9744f
, 0.0f
,
1693 0.0f
, 0.0225f
, 0.0974f
, 1.0f
);
1694 SharedQuadState
* red_shared_state
= CreateTestSharedQuadState(
1695 red_content_to_target_transform
, red_rect
, pass
.get());
1696 SolidColorDrawQuad
* red
= pass
->CreateAndAppendDrawQuad
<SolidColorDrawQuad
>();
1697 red
->SetNew(red_shared_state
, red_rect
, red_rect
, SK_ColorRED
, false);
1699 gfx::Rect
green_rect(19, 7, 180, 10);
1700 SharedQuadState
* green_shared_state
=
1701 CreateTestSharedQuadState(gfx::Transform(), green_rect
, pass
.get());
1702 SolidColorDrawQuad
* green
=
1703 pass
->CreateAndAppendDrawQuad
<SolidColorDrawQuad
>();
1705 green_shared_state
, green_rect
, green_rect
, SK_ColorGREEN
, false);
1707 SharedQuadState
* blue_shared_state
=
1708 CreateTestSharedQuadState(gfx::Transform(), rect
, pass
.get());
1709 SolidColorDrawQuad
* blue
=
1710 pass
->CreateAndAppendDrawQuad
<SolidColorDrawQuad
>();
1711 blue
->SetNew(blue_shared_state
, rect
, rect
, SK_ColorBLUE
, false);
1713 RenderPassList pass_list
;
1714 pass_list
.push_back(pass
.Pass());
1716 EXPECT_TRUE(this->RunPixelTest(
1718 base::FilePath(FILE_PATH_LITERAL("anti_aliasing_perspective.png")),
1719 FuzzyPixelOffByOneComparator(true)));
1722 TYPED_TEST(RendererPixelTest
, PictureDrawQuadIdentityScale
) {
1723 gfx::Size
pile_tile_size(1000, 1000);
1724 gfx::Rect
viewport(this->device_viewport_size_
);
1725 // TODO(enne): the renderer should figure this out on its own.
1726 ResourceFormat texture_format
= RGBA_8888
;
1728 RenderPassId
id(1, 1);
1729 gfx::Transform transform_to_root
;
1730 scoped_ptr
<RenderPass
> pass
=
1731 CreateTestRenderPass(id
, viewport
, transform_to_root
);
1733 // One clipped blue quad in the lower right corner. Outside the clip
1734 // is red, which should not appear.
1735 gfx::Rect
blue_rect(gfx::Size(100, 100));
1736 gfx::Rect
blue_clip_rect(gfx::Point(50, 50), gfx::Size(50, 50));
1737 scoped_refptr
<FakePicturePileImpl
> blue_pile
=
1738 FakePicturePileImpl::CreateFilledPile(pile_tile_size
, blue_rect
.size());
1740 red_paint
.setColor(SK_ColorRED
);
1741 blue_pile
->add_draw_rect_with_paint(blue_rect
, red_paint
);
1743 blue_paint
.setColor(SK_ColorBLUE
);
1744 blue_pile
->add_draw_rect_with_paint(blue_clip_rect
, blue_paint
);
1745 blue_pile
->RerecordPile();
1747 gfx::Transform blue_content_to_target_transform
;
1748 gfx::Vector2d
offset(viewport
.bottom_right() - blue_rect
.bottom_right());
1749 blue_content_to_target_transform
.Translate(offset
.x(), offset
.y());
1750 gfx::RectF blue_scissor_rect
= blue_clip_rect
;
1751 blue_content_to_target_transform
.TransformRect(&blue_scissor_rect
);
1752 SharedQuadState
* blue_shared_state
=
1753 CreateTestSharedQuadStateClipped(blue_content_to_target_transform
,
1755 gfx::ToEnclosingRect(blue_scissor_rect
),
1758 PictureDrawQuad
* blue_quad
= pass
->CreateAndAppendDrawQuad
<PictureDrawQuad
>();
1760 blue_quad
->SetNew(blue_shared_state
,
1761 viewport
, // Intentionally bigger than clip.
1762 gfx::Rect(), viewport
, gfx::RectF(viewport
),
1763 viewport
.size(), texture_format
, viewport
, 1.f
,
1766 // One viewport-filling green quad.
1767 scoped_refptr
<FakePicturePileImpl
> green_pile
=
1768 FakePicturePileImpl::CreateFilledPile(pile_tile_size
, viewport
.size());
1769 SkPaint green_paint
;
1770 green_paint
.setColor(SK_ColorGREEN
);
1771 green_pile
->add_draw_rect_with_paint(viewport
, green_paint
);
1772 green_pile
->RerecordPile();
1774 gfx::Transform green_content_to_target_transform
;
1775 SharedQuadState
* green_shared_state
= CreateTestSharedQuadState(
1776 green_content_to_target_transform
, viewport
, pass
.get());
1778 PictureDrawQuad
* green_quad
=
1779 pass
->CreateAndAppendDrawQuad
<PictureDrawQuad
>();
1780 green_quad
->SetNew(green_shared_state
, viewport
, gfx::Rect(), viewport
,
1781 gfx::RectF(0.f
, 0.f
, 1.f
, 1.f
), viewport
.size(),
1782 texture_format
, viewport
, 1.f
, green_pile
.get());
1784 RenderPassList pass_list
;
1785 pass_list
.push_back(pass
.Pass());
1787 EXPECT_TRUE(this->RunPixelTest(
1789 base::FilePath(FILE_PATH_LITERAL("green_with_blue_corner.png")),
1790 ExactPixelComparator(true)));
1793 // Not WithSkiaGPUBackend since that path currently requires tiles for opacity.
1794 TYPED_TEST(RendererPixelTest
, PictureDrawQuadOpacity
) {
1795 gfx::Size
pile_tile_size(1000, 1000);
1796 gfx::Rect
viewport(this->device_viewport_size_
);
1797 ResourceFormat texture_format
= RGBA_8888
;
1799 RenderPassId
id(1, 1);
1800 gfx::Transform transform_to_root
;
1801 scoped_ptr
<RenderPass
> pass
=
1802 CreateTestRenderPass(id
, viewport
, transform_to_root
);
1804 // One viewport-filling 0.5-opacity green quad.
1805 scoped_refptr
<FakePicturePileImpl
> green_pile
=
1806 FakePicturePileImpl::CreateFilledPile(pile_tile_size
, viewport
.size());
1807 SkPaint green_paint
;
1808 green_paint
.setColor(SK_ColorGREEN
);
1809 green_pile
->add_draw_rect_with_paint(viewport
, green_paint
);
1810 green_pile
->RerecordPile();
1812 gfx::Transform green_content_to_target_transform
;
1813 SharedQuadState
* green_shared_state
= CreateTestSharedQuadState(
1814 green_content_to_target_transform
, viewport
, pass
.get());
1815 green_shared_state
->opacity
= 0.5f
;
1817 PictureDrawQuad
* green_quad
=
1818 pass
->CreateAndAppendDrawQuad
<PictureDrawQuad
>();
1819 green_quad
->SetNew(green_shared_state
, viewport
, gfx::Rect(), viewport
,
1820 gfx::RectF(0, 0, 1, 1), viewport
.size(), texture_format
,
1821 viewport
, 1.f
, green_pile
.get());
1823 // One viewport-filling white quad.
1824 scoped_refptr
<FakePicturePileImpl
> white_pile
=
1825 FakePicturePileImpl::CreateFilledPile(pile_tile_size
, viewport
.size());
1826 SkPaint white_paint
;
1827 white_paint
.setColor(SK_ColorWHITE
);
1828 white_pile
->add_draw_rect_with_paint(viewport
, white_paint
);
1829 white_pile
->RerecordPile();
1831 gfx::Transform white_content_to_target_transform
;
1832 SharedQuadState
* white_shared_state
= CreateTestSharedQuadState(
1833 white_content_to_target_transform
, viewport
, pass
.get());
1835 PictureDrawQuad
* white_quad
=
1836 pass
->CreateAndAppendDrawQuad
<PictureDrawQuad
>();
1837 white_quad
->SetNew(white_shared_state
, viewport
, gfx::Rect(), viewport
,
1838 gfx::RectF(0, 0, 1, 1), viewport
.size(), texture_format
,
1839 viewport
, 1.f
, white_pile
.get());
1841 RenderPassList pass_list
;
1842 pass_list
.push_back(pass
.Pass());
1844 EXPECT_TRUE(this->RunPixelTest(
1846 base::FilePath(FILE_PATH_LITERAL("green_alpha.png")),
1847 FuzzyPixelOffByOneComparator(true)));
1850 template<typename TypeParam
> bool IsSoftwareRenderer() {
1855 bool IsSoftwareRenderer
<SoftwareRenderer
>() {
1860 bool IsSoftwareRenderer
<SoftwareRendererWithExpandedViewport
>() {
1864 // If we disable image filtering, then a 2x2 bitmap should appear as four
1865 // huge sharp squares.
1866 TYPED_TEST(RendererPixelTest
, PictureDrawQuadDisableImageFiltering
) {
1867 // We only care about this in software mode since bilinear filtering is
1868 // cheap in hardware.
1869 if (!IsSoftwareRenderer
<TypeParam
>())
1872 gfx::Size
pile_tile_size(1000, 1000);
1873 gfx::Rect
viewport(this->device_viewport_size_
);
1874 ResourceFormat texture_format
= RGBA_8888
;
1876 RenderPassId
id(1, 1);
1877 gfx::Transform transform_to_root
;
1878 scoped_ptr
<RenderPass
> pass
=
1879 CreateTestRenderPass(id
, viewport
, transform_to_root
);
1882 bitmap
.allocN32Pixels(2, 2);
1884 SkAutoLockPixels
lock(bitmap
);
1885 SkCanvas
canvas(bitmap
);
1886 canvas
.drawPoint(0, 0, SK_ColorGREEN
);
1887 canvas
.drawPoint(0, 1, SK_ColorBLUE
);
1888 canvas
.drawPoint(1, 0, SK_ColorBLUE
);
1889 canvas
.drawPoint(1, 1, SK_ColorGREEN
);
1892 scoped_refptr
<FakePicturePileImpl
> pile
=
1893 FakePicturePileImpl::CreateFilledPile(pile_tile_size
, viewport
.size());
1895 paint
.setFilterLevel(SkPaint::kLow_FilterLevel
);
1896 pile
->add_draw_bitmap_with_paint(bitmap
, gfx::Point(), paint
);
1897 pile
->RerecordPile();
1899 gfx::Transform content_to_target_transform
;
1900 SharedQuadState
* shared_state
= CreateTestSharedQuadState(
1901 content_to_target_transform
, viewport
, pass
.get());
1903 PictureDrawQuad
* quad
= pass
->CreateAndAppendDrawQuad
<PictureDrawQuad
>();
1904 quad
->SetNew(shared_state
, viewport
, gfx::Rect(), viewport
,
1905 gfx::RectF(0, 0, 2, 2), viewport
.size(), texture_format
,
1906 viewport
, 1.f
, pile
.get());
1908 RenderPassList pass_list
;
1909 pass_list
.push_back(pass
.Pass());
1911 this->disable_picture_quad_image_filtering_
= true;
1913 EXPECT_TRUE(this->RunPixelTest(
1915 base::FilePath(FILE_PATH_LITERAL("four_blue_green_checkers.png")),
1916 ExactPixelComparator(true)));
1919 TYPED_TEST(RendererPixelTest
, PictureDrawQuadNonIdentityScale
) {
1920 gfx::Size
pile_tile_size(1000, 1000);
1921 gfx::Rect
viewport(this->device_viewport_size_
);
1922 // TODO(enne): the renderer should figure this out on its own.
1923 ResourceFormat texture_format
= RGBA_8888
;
1925 RenderPassId
id(1, 1);
1926 gfx::Transform transform_to_root
;
1927 scoped_ptr
<RenderPass
> pass
=
1928 CreateTestRenderPass(id
, viewport
, transform_to_root
);
1930 // As scaling up the blue checkerboards will cause sampling on the GPU,
1931 // a few extra "cleanup rects" need to be added to clobber the blending
1932 // to make the output image more clean. This will also test subrects
1934 gfx::Transform green_content_to_target_transform
;
1935 gfx::Rect
green_rect1(gfx::Point(80, 0), gfx::Size(20, 100));
1936 gfx::Rect
green_rect2(gfx::Point(0, 80), gfx::Size(100, 20));
1937 scoped_refptr
<FakePicturePileImpl
> green_pile
=
1938 FakePicturePileImpl::CreateFilledPile(pile_tile_size
, viewport
.size());
1940 red_paint
.setColor(SK_ColorRED
);
1941 green_pile
->add_draw_rect_with_paint(viewport
, red_paint
);
1942 SkPaint green_paint
;
1943 green_paint
.setColor(SK_ColorGREEN
);
1944 green_pile
->add_draw_rect_with_paint(green_rect1
, green_paint
);
1945 green_pile
->add_draw_rect_with_paint(green_rect2
, green_paint
);
1946 green_pile
->RerecordPile();
1948 SharedQuadState
* top_right_green_shared_quad_state
=
1949 CreateTestSharedQuadState(
1950 green_content_to_target_transform
, viewport
, pass
.get());
1952 PictureDrawQuad
* green_quad1
=
1953 pass
->CreateAndAppendDrawQuad
<PictureDrawQuad
>();
1954 green_quad1
->SetNew(top_right_green_shared_quad_state
, green_rect1
,
1955 gfx::Rect(), green_rect1
, gfx::RectF(green_rect1
.size()),
1956 green_rect1
.size(), texture_format
, green_rect1
, 1.f
,
1959 PictureDrawQuad
* green_quad2
=
1960 pass
->CreateAndAppendDrawQuad
<PictureDrawQuad
>();
1961 green_quad2
->SetNew(top_right_green_shared_quad_state
, green_rect2
,
1962 gfx::Rect(), green_rect2
, gfx::RectF(green_rect2
.size()),
1963 green_rect2
.size(), texture_format
, green_rect2
, 1.f
,
1966 // Add a green clipped checkerboard in the bottom right to help test
1967 // interleaving picture quad content and solid color content.
1968 gfx::Rect
bottom_right_rect(
1969 gfx::Point(viewport
.width() / 2, viewport
.height() / 2),
1970 gfx::Size(viewport
.width() / 2, viewport
.height() / 2));
1971 SharedQuadState
* bottom_right_green_shared_state
=
1972 CreateTestSharedQuadStateClipped(green_content_to_target_transform
,
1976 SolidColorDrawQuad
* bottom_right_color_quad
=
1977 pass
->CreateAndAppendDrawQuad
<SolidColorDrawQuad
>();
1978 bottom_right_color_quad
->SetNew(bottom_right_green_shared_state
,
1984 // Add two blue checkerboards taking up the bottom left and top right,
1985 // but use content scales as content rects to make this happen.
1986 // The content is at a 4x content scale.
1987 gfx::Rect
layer_rect(gfx::Size(20, 30));
1988 float contents_scale
= 4.f
;
1989 // Two rects that touch at their corners, arbitrarily placed in the layer.
1990 gfx::RectF
blue_layer_rect1(gfx::PointF(5.5f
, 9.0f
), gfx::SizeF(2.5f
, 2.5f
));
1991 gfx::RectF
blue_layer_rect2(gfx::PointF(8.0f
, 6.5f
), gfx::SizeF(2.5f
, 2.5f
));
1992 gfx::RectF union_layer_rect
= blue_layer_rect1
;
1993 union_layer_rect
.Union(blue_layer_rect2
);
1995 // Because scaling up will cause sampling outside the rects, add one extra
1996 // pixel of buffer at the final content scale.
1997 float inset
= -1.f
/ contents_scale
;
1998 blue_layer_rect1
.Inset(inset
, inset
, inset
, inset
);
1999 blue_layer_rect2
.Inset(inset
, inset
, inset
, inset
);
2001 scoped_refptr
<FakePicturePileImpl
> pile
=
2002 FakePicturePileImpl::CreateFilledPile(pile_tile_size
, layer_rect
.size());
2004 Region
outside(layer_rect
);
2005 outside
.Subtract(gfx::ToEnclosingRect(union_layer_rect
));
2006 for (Region::Iterator
iter(outside
); iter
.has_rect(); iter
.next()) {
2007 pile
->add_draw_rect_with_paint(iter
.rect(), red_paint
);
2011 blue_paint
.setColor(SK_ColorBLUE
);
2012 pile
->add_draw_rect_with_paint(blue_layer_rect1
, blue_paint
);
2013 pile
->add_draw_rect_with_paint(blue_layer_rect2
, blue_paint
);
2014 pile
->RerecordPile();
2016 gfx::Rect
content_rect(
2017 gfx::ScaleToEnclosingRect(layer_rect
, contents_scale
));
2018 gfx::Rect
content_union_rect(
2019 gfx::ToEnclosingRect(gfx::ScaleRect(union_layer_rect
, contents_scale
)));
2021 // At a scale of 4x the rectangles with a width of 2.5 will take up 10 pixels,
2022 // so scale an additional 10x to make them 100x100.
2023 gfx::Transform content_to_target_transform
;
2024 content_to_target_transform
.Scale(10.0, 10.0);
2025 gfx::Rect
quad_content_rect(gfx::Size(20, 20));
2026 SharedQuadState
* blue_shared_state
= CreateTestSharedQuadState(
2027 content_to_target_transform
, quad_content_rect
, pass
.get());
2029 PictureDrawQuad
* blue_quad
= pass
->CreateAndAppendDrawQuad
<PictureDrawQuad
>();
2030 blue_quad
->SetNew(blue_shared_state
, quad_content_rect
, gfx::Rect(),
2031 quad_content_rect
, gfx::RectF(quad_content_rect
),
2032 content_union_rect
.size(), texture_format
,
2033 content_union_rect
, contents_scale
, pile
.get());
2035 // Fill left half of viewport with green.
2036 gfx::Transform half_green_content_to_target_transform
;
2037 gfx::Rect
half_green_rect(gfx::Size(viewport
.width() / 2, viewport
.height()));
2038 SharedQuadState
* half_green_shared_state
= CreateTestSharedQuadState(
2039 half_green_content_to_target_transform
, half_green_rect
, pass
.get());
2040 SolidColorDrawQuad
* half_color_quad
=
2041 pass
->CreateAndAppendDrawQuad
<SolidColorDrawQuad
>();
2042 half_color_quad
->SetNew(half_green_shared_state
,
2048 RenderPassList pass_list
;
2049 pass_list
.push_back(pass
.Pass());
2051 EXPECT_TRUE(this->RunPixelTest(
2053 base::FilePath(FILE_PATH_LITERAL("four_blue_green_checkers.png")),
2054 ExactPixelComparator(true)));
2057 typedef RendererPixelTest
<GLRendererWithFlippedSurface
>
2058 GLRendererPixelTestWithFlippedOutputSurface
;
2060 TEST_F(GLRendererPixelTestWithFlippedOutputSurface
, ExplicitFlipTest
) {
2061 // This draws a blue rect above a yellow rect with an inverted output surface.
2062 gfx::Rect
viewport_rect(this->device_viewport_size_
);
2064 RenderPassId
root_pass_id(1, 1);
2065 scoped_ptr
<RenderPass
> root_pass
=
2066 CreateTestRootRenderPass(root_pass_id
, viewport_rect
);
2068 RenderPassId
child_pass_id(2, 2);
2069 gfx::Rect
pass_rect(this->device_viewport_size_
);
2070 gfx::Transform transform_to_root
;
2071 scoped_ptr
<RenderPass
> child_pass
=
2072 CreateTestRenderPass(child_pass_id
, pass_rect
, transform_to_root
);
2074 gfx::Transform content_to_target_transform
;
2075 SharedQuadState
* shared_state
= CreateTestSharedQuadState(
2076 content_to_target_transform
, viewport_rect
, child_pass
.get());
2078 gfx::Rect
blue_rect(0,
2080 this->device_viewport_size_
.width(),
2081 this->device_viewport_size_
.height() / 2);
2082 SolidColorDrawQuad
* blue
=
2083 child_pass
->CreateAndAppendDrawQuad
<SolidColorDrawQuad
>();
2084 blue
->SetNew(shared_state
, blue_rect
, blue_rect
, SK_ColorBLUE
, false);
2085 gfx::Rect
yellow_rect(0,
2086 this->device_viewport_size_
.height() / 2,
2087 this->device_viewport_size_
.width(),
2088 this->device_viewport_size_
.height() / 2);
2089 SolidColorDrawQuad
* yellow
=
2090 child_pass
->CreateAndAppendDrawQuad
<SolidColorDrawQuad
>();
2091 yellow
->SetNew(shared_state
, yellow_rect
, yellow_rect
, SK_ColorYELLOW
, false);
2093 SharedQuadState
* pass_shared_state
=
2094 CreateTestSharedQuadState(gfx::Transform(), pass_rect
, root_pass
.get());
2095 CreateTestRenderPassDrawQuad(
2096 pass_shared_state
, pass_rect
, child_pass_id
, root_pass
.get());
2098 RenderPassList pass_list
;
2099 pass_list
.push_back(child_pass
.Pass());
2100 pass_list
.push_back(root_pass
.Pass());
2102 EXPECT_TRUE(this->RunPixelTest(
2104 base::FilePath(FILE_PATH_LITERAL("blue_yellow_flipped.png")),
2105 ExactPixelComparator(true)));
2108 TEST_F(GLRendererPixelTestWithFlippedOutputSurface
, CheckChildPassUnflipped
) {
2109 // This draws a blue rect above a yellow rect with an inverted output surface.
2110 gfx::Rect
viewport_rect(this->device_viewport_size_
);
2112 RenderPassId
root_pass_id(1, 1);
2113 scoped_ptr
<RenderPass
> root_pass
=
2114 CreateTestRootRenderPass(root_pass_id
, viewport_rect
);
2116 RenderPassId
child_pass_id(2, 2);
2117 gfx::Rect
pass_rect(this->device_viewport_size_
);
2118 gfx::Transform transform_to_root
;
2119 scoped_ptr
<RenderPass
> child_pass
=
2120 CreateTestRenderPass(child_pass_id
, pass_rect
, transform_to_root
);
2122 gfx::Transform content_to_target_transform
;
2123 SharedQuadState
* shared_state
= CreateTestSharedQuadState(
2124 content_to_target_transform
, viewport_rect
, child_pass
.get());
2126 gfx::Rect
blue_rect(0,
2128 this->device_viewport_size_
.width(),
2129 this->device_viewport_size_
.height() / 2);
2130 SolidColorDrawQuad
* blue
=
2131 child_pass
->CreateAndAppendDrawQuad
<SolidColorDrawQuad
>();
2132 blue
->SetNew(shared_state
, blue_rect
, blue_rect
, SK_ColorBLUE
, false);
2133 gfx::Rect
yellow_rect(0,
2134 this->device_viewport_size_
.height() / 2,
2135 this->device_viewport_size_
.width(),
2136 this->device_viewport_size_
.height() / 2);
2137 SolidColorDrawQuad
* yellow
=
2138 child_pass
->CreateAndAppendDrawQuad
<SolidColorDrawQuad
>();
2139 yellow
->SetNew(shared_state
, yellow_rect
, yellow_rect
, SK_ColorYELLOW
, false);
2141 SharedQuadState
* pass_shared_state
=
2142 CreateTestSharedQuadState(gfx::Transform(), pass_rect
, root_pass
.get());
2143 CreateTestRenderPassDrawQuad(
2144 pass_shared_state
, pass_rect
, child_pass_id
, root_pass
.get());
2146 RenderPassList pass_list
;
2147 pass_list
.push_back(child_pass
.Pass());
2148 pass_list
.push_back(root_pass
.Pass());
2150 // Check that the child pass remains unflipped.
2151 EXPECT_TRUE(this->RunPixelTestWithReadbackTarget(
2154 base::FilePath(FILE_PATH_LITERAL("blue_yellow.png")),
2155 ExactPixelComparator(true)));
2158 TEST_F(GLRendererPixelTest
, CheckReadbackSubset
) {
2159 gfx::Rect
viewport_rect(this->device_viewport_size_
);
2161 RenderPassId
root_pass_id(1, 1);
2162 scoped_ptr
<RenderPass
> root_pass
=
2163 CreateTestRootRenderPass(root_pass_id
, viewport_rect
);
2165 RenderPassId
child_pass_id(2, 2);
2166 gfx::Rect
pass_rect(this->device_viewport_size_
);
2167 gfx::Transform transform_to_root
;
2168 scoped_ptr
<RenderPass
> child_pass
=
2169 CreateTestRenderPass(child_pass_id
, pass_rect
, transform_to_root
);
2171 gfx::Transform content_to_target_transform
;
2172 SharedQuadState
* shared_state
= CreateTestSharedQuadState(
2173 content_to_target_transform
, viewport_rect
, child_pass
.get());
2175 // Draw a green quad full-size with a blue quad in the lower-right corner.
2176 gfx::Rect
blue_rect(this->device_viewport_size_
.width() * 3 / 4,
2177 this->device_viewport_size_
.height() * 3 / 4,
2178 this->device_viewport_size_
.width() * 3 / 4,
2179 this->device_viewport_size_
.height() * 3 / 4);
2180 SolidColorDrawQuad
* blue
=
2181 child_pass
->CreateAndAppendDrawQuad
<SolidColorDrawQuad
>();
2182 blue
->SetNew(shared_state
, blue_rect
, blue_rect
, SK_ColorBLUE
, false);
2183 gfx::Rect
green_rect(0,
2185 this->device_viewport_size_
.width(),
2186 this->device_viewport_size_
.height());
2187 SolidColorDrawQuad
* green
=
2188 child_pass
->CreateAndAppendDrawQuad
<SolidColorDrawQuad
>();
2189 green
->SetNew(shared_state
, green_rect
, green_rect
, SK_ColorGREEN
, false);
2191 SharedQuadState
* pass_shared_state
=
2192 CreateTestSharedQuadState(gfx::Transform(), pass_rect
, root_pass
.get());
2193 CreateTestRenderPassDrawQuad(
2194 pass_shared_state
, pass_rect
, child_pass_id
, root_pass
.get());
2196 RenderPassList pass_list
;
2197 pass_list
.push_back(child_pass
.Pass());
2198 pass_list
.push_back(root_pass
.Pass());
2200 // Check that the child pass remains unflipped.
2201 gfx::Rect
capture_rect(this->device_viewport_size_
.width() / 2,
2202 this->device_viewport_size_
.height() / 2,
2203 this->device_viewport_size_
.width() / 2,
2204 this->device_viewport_size_
.height() / 2);
2205 EXPECT_TRUE(this->RunPixelTestWithReadbackTargetAndArea(
2208 base::FilePath(FILE_PATH_LITERAL("green_small_with_blue_corner.png")),
2209 ExactPixelComparator(true),
2213 TEST_F(GLRendererPixelTest
, PictureDrawQuadTexture4444
) {
2214 gfx::Size
pile_tile_size(1000, 1000);
2215 gfx::Rect
viewport(this->device_viewport_size_
);
2216 ResourceFormat texture_format
= RGBA_4444
;
2218 RenderPassId
id(1, 1);
2219 gfx::Transform transform_to_root
;
2220 scoped_ptr
<RenderPass
> pass
=
2221 CreateTestRenderPass(id
, viewport
, transform_to_root
);
2223 // One viewport-filling blue quad
2224 scoped_refptr
<FakePicturePileImpl
> blue_pile
=
2225 FakePicturePileImpl::CreateFilledPile(pile_tile_size
, viewport
.size());
2227 blue_paint
.setColor(SK_ColorBLUE
);
2228 blue_pile
->add_draw_rect_with_paint(viewport
, blue_paint
);
2229 blue_pile
->RerecordPile();
2231 gfx::Transform blue_content_to_target_transform
;
2232 SharedQuadState
* blue_shared_state
= CreateTestSharedQuadState(
2233 blue_content_to_target_transform
, viewport
, pass
.get());
2235 PictureDrawQuad
* blue_quad
= pass
->CreateAndAppendDrawQuad
<PictureDrawQuad
>();
2236 blue_quad
->SetNew(blue_shared_state
, viewport
, gfx::Rect(), viewport
,
2237 gfx::RectF(0.f
, 0.f
, 1.f
, 1.f
), viewport
.size(),
2238 texture_format
, viewport
, 1.f
, blue_pile
.get());
2240 RenderPassList pass_list
;
2241 pass_list
.push_back(pass
.Pass());
2243 EXPECT_TRUE(this->RunPixelTest(&pass_list
,
2244 base::FilePath(FILE_PATH_LITERAL("blue.png")),
2245 ExactPixelComparator(true)));
2248 TYPED_TEST(RendererPixelTest
, WrapModeRepeat
) {
2249 gfx::Rect
rect(this->device_viewport_size_
);
2251 RenderPassId
id(1, 1);
2252 scoped_ptr
<RenderPass
> pass
= CreateTestRootRenderPass(id
, rect
);
2254 SharedQuadState
* shared_state
=
2255 CreateTestSharedQuadState(gfx::Transform(), rect
, pass
.get());
2257 gfx::Rect
texture_rect(4, 4);
2258 SkPMColor colors
[4] = {
2259 SkPreMultiplyColor(SkColorSetARGB(255, 0, 255, 0)),
2260 SkPreMultiplyColor(SkColorSetARGB(255, 0, 128, 0)),
2261 SkPreMultiplyColor(SkColorSetARGB(255, 0, 64, 0)),
2262 SkPreMultiplyColor(SkColorSetARGB(255, 0, 0, 0)),
2264 uint32_t pixels
[16] = {
2265 colors
[0], colors
[0], colors
[1], colors
[1],
2266 colors
[0], colors
[0], colors
[1], colors
[1],
2267 colors
[2], colors
[2], colors
[3], colors
[3],
2268 colors
[2], colors
[2], colors
[3], colors
[3],
2270 ResourceProvider::ResourceId resource
=
2271 this->resource_provider_
->CreateResource(
2272 texture_rect
.size(),
2274 ResourceProvider::TextureHintImmutable
,
2276 this->resource_provider_
->SetPixels(
2278 reinterpret_cast<uint8_t*>(pixels
),
2283 float vertex_opacity
[4] = {1.0f
, 1.0f
, 1.0f
, 1.0f
};
2284 TextureDrawQuad
* texture_quad
=
2285 pass
->CreateAndAppendDrawQuad
<TextureDrawQuad
>();
2286 texture_quad
->SetNew(
2288 gfx::Rect(this->device_viewport_size_
),
2290 gfx::Rect(this->device_viewport_size_
),
2292 true, // premultiplied_alpha
2293 gfx::PointF(0.0f
, 0.0f
), // uv_top_left
2294 gfx::PointF( // uv_bottom_right
2295 this->device_viewport_size_
.width() / texture_rect
.width(),
2296 this->device_viewport_size_
.height() / texture_rect
.height()),
2301 RenderPassList pass_list
;
2302 pass_list
.push_back(pass
.Pass());
2304 EXPECT_TRUE(this->RunPixelTest(
2306 base::FilePath(FILE_PATH_LITERAL("wrap_mode_repeat.png")),
2307 FuzzyPixelOffByOneComparator(true)));
2310 #endif // !defined(OS_ANDROID)