1 // Copyright 2014 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/compiler_specific.h"
6 #include "base/memory/scoped_ptr.h"
7 #include "cc/test/geometry_test_utils.h"
8 #include "skia/ext/pixel_ref_utils.h"
9 #include "skia/ext/refptr.h"
10 #include "testing/gtest/include/gtest/gtest.h"
11 #include "third_party/skia/include/core/SkBitmap.h"
12 #include "third_party/skia/include/core/SkCanvas.h"
13 #include "third_party/skia/include/core/SkPictureRecorder.h"
14 #include "third_party/skia/include/core/SkPixelRef.h"
15 #include "third_party/skia/include/core/SkPoint.h"
16 #include "third_party/skia/include/core/SkShader.h"
17 #include "third_party/skia/src/core/SkOrderedReadBuffer.h"
18 #include "ui/gfx/geometry/rect.h"
19 #include "ui/gfx/skia_util.h"
25 void CreateBitmap(gfx::Size size
, const char* uri
, SkBitmap
* bitmap
);
27 class TestDiscardableShader
: public SkShader
{
29 TestDiscardableShader() {
30 CreateBitmap(gfx::Size(50, 50), "discardable", &bitmap_
);
33 TestDiscardableShader(SkReadBuffer
& buffer
) {
34 CreateBitmap(gfx::Size(50, 50), "discardable", &bitmap_
);
37 SkShader::BitmapType
asABitmap(SkBitmap
* bitmap
,
39 TileMode xy
[2]) const override
{
42 return SkShader::kDefault_BitmapType
;
45 // not indended to return an actual context. Just need to supply this.
46 size_t contextSize() const override
{ return sizeof(SkShader::Context
); }
48 void flatten(SkWriteBuffer
&) const override
{}
50 // Manual expansion of SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS to
51 // satisfy Chrome's style checker, since Skia isn't ready to make the C++11
54 static SkFlattenable
* CreateProc(SkReadBuffer
&);
55 friend class SkPrivateEffectInitializer
;
58 Factory
getFactory() const override
{ return CreateProc
; }
64 SkFlattenable
* TestDiscardableShader::CreateProc(SkReadBuffer
&) {
65 return new TestDiscardableShader
;
68 void CreateBitmap(gfx::Size size
, const char* uri
, SkBitmap
* bitmap
) {
69 bitmap
->allocN32Pixels(size
.width(), size
.height());
70 bitmap
->pixelRef()->setImmutable();
71 bitmap
->pixelRef()->setURI(uri
);
74 SkCanvas
* StartRecording(SkPictureRecorder
* recorder
, gfx::Rect layer_rect
) {
76 recorder
->beginRecording(layer_rect
.width(), layer_rect
.height());
79 canvas
->translate(-layer_rect
.x(), -layer_rect
.y());
80 canvas
->clipRect(SkRect::MakeXYWH(
81 layer_rect
.x(), layer_rect
.y(), layer_rect
.width(), layer_rect
.height()));
86 SkPicture
* StopRecording(SkPictureRecorder
* recorder
, SkCanvas
* canvas
) {
88 return recorder
->endRecording();
93 TEST(PixelRefUtilsTest
, DrawPaint
) {
94 gfx::Rect
layer_rect(0, 0, 256, 256);
96 SkPictureRecorder recorder
;
97 SkCanvas
* canvas
= StartRecording(&recorder
, layer_rect
);
99 TestDiscardableShader first_shader
;
101 first_paint
.setShader(&first_shader
);
103 TestDiscardableShader second_shader
;
104 SkPaint second_paint
;
105 second_paint
.setShader(&second_shader
);
107 TestDiscardableShader third_shader
;
109 third_paint
.setShader(&third_shader
);
111 canvas
->drawPaint(first_paint
);
112 canvas
->clipRect(SkRect::MakeXYWH(34, 45, 56, 67));
113 canvas
->drawPaint(second_paint
);
114 // Total clip is now (34, 45, 56, 55)
115 canvas
->clipRect(SkRect::MakeWH(100, 100));
116 canvas
->drawPaint(third_paint
);
118 skia::RefPtr
<SkPicture
> picture
= skia::AdoptRef(StopRecording(&recorder
, canvas
));
120 std::vector
<skia::PixelRefUtils::PositionPixelRef
> pixel_refs
;
121 skia::PixelRefUtils::GatherDiscardablePixelRefs(picture
.get(), &pixel_refs
);
123 EXPECT_EQ(3u, pixel_refs
.size());
124 EXPECT_FLOAT_RECT_EQ(gfx::RectF(0, 0, 256, 256),
125 gfx::SkRectToRectF(pixel_refs
[0].pixel_ref_rect
));
126 EXPECT_FLOAT_RECT_EQ(gfx::RectF(34, 45, 56, 67),
127 gfx::SkRectToRectF(pixel_refs
[1].pixel_ref_rect
));
128 EXPECT_FLOAT_RECT_EQ(gfx::RectF(34, 45, 56, 55),
129 gfx::SkRectToRectF(pixel_refs
[2].pixel_ref_rect
));
132 TEST(PixelRefUtilsTest
, DrawPoints
) {
133 gfx::Rect
layer_rect(0, 0, 256, 256);
135 SkPictureRecorder recorder
;
136 SkCanvas
* canvas
= StartRecording(&recorder
, layer_rect
);
138 TestDiscardableShader first_shader
;
140 first_paint
.setShader(&first_shader
);
142 TestDiscardableShader second_shader
;
143 SkPaint second_paint
;
144 second_paint
.setShader(&second_shader
);
146 TestDiscardableShader third_shader
;
148 third_paint
.setShader(&third_shader
);
151 points
[0].set(10, 10);
152 points
[1].set(100, 20);
153 points
[2].set(50, 100);
155 canvas
->drawPoints(SkCanvas::kPolygon_PointMode
, 3, points
, first_paint
);
159 canvas
->clipRect(SkRect::MakeWH(50, 50));
161 canvas
->drawPoints(SkCanvas::kPolygon_PointMode
, 3, points
, second_paint
);
165 points
[0].set(50, 55);
166 points
[1].set(50, 55);
167 points
[2].set(200, 200);
168 // (50, 55, 150, 145).
169 canvas
->drawPoints(SkCanvas::kPolygon_PointMode
, 3, points
, third_paint
);
171 skia::RefPtr
<SkPicture
> picture
= skia::AdoptRef(StopRecording(&recorder
, canvas
));
173 std::vector
<skia::PixelRefUtils::PositionPixelRef
> pixel_refs
;
174 skia::PixelRefUtils::GatherDiscardablePixelRefs(picture
.get(), &pixel_refs
);
176 EXPECT_EQ(3u, pixel_refs
.size());
177 EXPECT_FLOAT_RECT_EQ(gfx::RectF(10, 10, 90, 90),
178 gfx::SkRectToRectF(pixel_refs
[0].pixel_ref_rect
));
179 EXPECT_FLOAT_RECT_EQ(gfx::RectF(10, 10, 40, 40),
180 gfx::SkRectToRectF(pixel_refs
[1].pixel_ref_rect
));
181 EXPECT_FLOAT_RECT_EQ(gfx::RectF(50, 55, 150, 145),
182 gfx::SkRectToRectF(pixel_refs
[2].pixel_ref_rect
));
185 TEST(PixelRefUtilsTest
, DrawRect
) {
186 gfx::Rect
layer_rect(0, 0, 256, 256);
188 SkPictureRecorder recorder
;
189 SkCanvas
* canvas
= StartRecording(&recorder
, layer_rect
);
191 TestDiscardableShader first_shader
;
193 first_paint
.setShader(&first_shader
);
195 TestDiscardableShader second_shader
;
196 SkPaint second_paint
;
197 second_paint
.setShader(&second_shader
);
199 TestDiscardableShader third_shader
;
201 third_paint
.setShader(&third_shader
);
204 canvas
->drawRect(SkRect::MakeXYWH(10, 20, 30, 40), first_paint
);
208 canvas
->translate(5, 17);
210 canvas
->drawRect(SkRect::MakeXYWH(0, 33, 25, 35), second_paint
);
214 canvas
->clipRect(SkRect::MakeXYWH(50, 50, 50, 50));
215 canvas
->translate(20, 20);
217 canvas
->drawRect(SkRect::MakeXYWH(0, 0, 100, 100), third_paint
);
219 skia::RefPtr
<SkPicture
> picture
= skia::AdoptRef(StopRecording(&recorder
, canvas
));
221 std::vector
<skia::PixelRefUtils::PositionPixelRef
> pixel_refs
;
222 skia::PixelRefUtils::GatherDiscardablePixelRefs(picture
.get(), &pixel_refs
);
224 EXPECT_EQ(3u, pixel_refs
.size());
225 EXPECT_FLOAT_RECT_EQ(gfx::RectF(10, 20, 30, 40),
226 gfx::SkRectToRectF(pixel_refs
[0].pixel_ref_rect
));
227 EXPECT_FLOAT_RECT_EQ(gfx::RectF(5, 50, 25, 35),
228 gfx::SkRectToRectF(pixel_refs
[1].pixel_ref_rect
));
229 EXPECT_FLOAT_RECT_EQ(gfx::RectF(50, 50, 50, 50),
230 gfx::SkRectToRectF(pixel_refs
[2].pixel_ref_rect
));
233 TEST(PixelRefUtilsTest
, DrawRRect
) {
234 gfx::Rect
layer_rect(0, 0, 256, 256);
236 SkPictureRecorder recorder
;
237 SkCanvas
* canvas
= StartRecording(&recorder
, layer_rect
);
239 TestDiscardableShader first_shader
;
241 first_paint
.setShader(&first_shader
);
243 TestDiscardableShader second_shader
;
244 SkPaint second_paint
;
245 second_paint
.setShader(&second_shader
);
247 TestDiscardableShader third_shader
;
249 third_paint
.setShader(&third_shader
);
252 rrect
.setRect(SkRect::MakeXYWH(10, 20, 30, 40));
255 canvas
->drawRRect(rrect
, first_paint
);
259 canvas
->translate(5, 17);
260 rrect
.setRect(SkRect::MakeXYWH(0, 33, 25, 35));
262 canvas
->drawRRect(rrect
, second_paint
);
266 canvas
->clipRect(SkRect::MakeXYWH(50, 50, 50, 50));
267 canvas
->translate(20, 20);
268 rrect
.setRect(SkRect::MakeXYWH(0, 0, 100, 100));
270 canvas
->drawRRect(rrect
, third_paint
);
272 skia::RefPtr
<SkPicture
> picture
= skia::AdoptRef(StopRecording(&recorder
, canvas
));
274 std::vector
<skia::PixelRefUtils::PositionPixelRef
> pixel_refs
;
275 skia::PixelRefUtils::GatherDiscardablePixelRefs(picture
.get(), &pixel_refs
);
277 EXPECT_EQ(3u, pixel_refs
.size());
278 EXPECT_FLOAT_RECT_EQ(gfx::RectF(10, 20, 30, 40),
279 gfx::SkRectToRectF(pixel_refs
[0].pixel_ref_rect
));
280 EXPECT_FLOAT_RECT_EQ(gfx::RectF(5, 50, 25, 35),
281 gfx::SkRectToRectF(pixel_refs
[1].pixel_ref_rect
));
282 EXPECT_FLOAT_RECT_EQ(gfx::RectF(50, 50, 50, 50),
283 gfx::SkRectToRectF(pixel_refs
[2].pixel_ref_rect
));
286 TEST(PixelRefUtilsTest
, DrawOval
) {
287 gfx::Rect
layer_rect(0, 0, 256, 256);
289 SkPictureRecorder recorder
;
290 SkCanvas
* canvas
= StartRecording(&recorder
, layer_rect
);
292 TestDiscardableShader first_shader
;
294 first_paint
.setShader(&first_shader
);
296 TestDiscardableShader second_shader
;
297 SkPaint second_paint
;
298 second_paint
.setShader(&second_shader
);
300 TestDiscardableShader third_shader
;
302 third_paint
.setShader(&third_shader
);
306 canvas
->scale(2, 0.5);
308 canvas
->drawOval(SkRect::MakeXYWH(10, 20, 30, 40), first_paint
);
313 canvas
->translate(1, 2);
315 canvas
->drawRect(SkRect::MakeXYWH(0, 33, 25, 35), second_paint
);
319 canvas
->clipRect(SkRect::MakeXYWH(50, 50, 50, 50));
320 canvas
->translate(20, 20);
322 canvas
->drawRect(SkRect::MakeXYWH(0, 0, 100, 100), third_paint
);
324 skia::RefPtr
<SkPicture
> picture
= skia::AdoptRef(StopRecording(&recorder
, canvas
));
326 std::vector
<skia::PixelRefUtils::PositionPixelRef
> pixel_refs
;
327 skia::PixelRefUtils::GatherDiscardablePixelRefs(picture
.get(), &pixel_refs
);
329 EXPECT_EQ(3u, pixel_refs
.size());
330 EXPECT_FLOAT_RECT_EQ(gfx::RectF(20, 10, 60, 20),
331 gfx::SkRectToRectF(pixel_refs
[0].pixel_ref_rect
));
332 EXPECT_FLOAT_RECT_EQ(gfx::RectF(1, 35, 25, 35),
333 gfx::SkRectToRectF(pixel_refs
[1].pixel_ref_rect
));
334 EXPECT_FLOAT_RECT_EQ(gfx::RectF(50, 50, 50, 50),
335 gfx::SkRectToRectF(pixel_refs
[2].pixel_ref_rect
));
338 TEST(PixelRefUtilsTest
, DrawPath
) {
339 gfx::Rect
layer_rect(0, 0, 256, 256);
341 SkPictureRecorder recorder
;
342 SkCanvas
* canvas
= StartRecording(&recorder
, layer_rect
);
344 TestDiscardableShader first_shader
;
346 first_paint
.setShader(&first_shader
);
348 TestDiscardableShader second_shader
;
349 SkPaint second_paint
;
350 second_paint
.setShader(&second_shader
);
355 path
.lineTo(22, 101);
358 canvas
->drawPath(path
, first_paint
);
361 canvas
->clipRect(SkRect::MakeWH(50, 50));
364 canvas
->drawPath(path
, second_paint
);
368 skia::RefPtr
<SkPicture
> picture
= skia::AdoptRef(StopRecording(&recorder
, canvas
));
370 std::vector
<skia::PixelRefUtils::PositionPixelRef
> pixel_refs
;
371 skia::PixelRefUtils::GatherDiscardablePixelRefs(picture
.get(), &pixel_refs
);
373 EXPECT_EQ(2u, pixel_refs
.size());
374 EXPECT_FLOAT_RECT_EQ(gfx::RectF(12, 13, 38, 88),
375 gfx::SkRectToRectF(pixel_refs
[0].pixel_ref_rect
));
376 EXPECT_FLOAT_RECT_EQ(gfx::RectF(12, 13, 38, 37),
377 gfx::SkRectToRectF(pixel_refs
[1].pixel_ref_rect
));
380 TEST(PixelRefUtilsTest
, DrawBitmap
) {
381 gfx::Rect
layer_rect(0, 0, 256, 256);
383 SkPictureRecorder recorder
;
384 SkCanvas
* canvas
= StartRecording(&recorder
, layer_rect
);
387 CreateBitmap(gfx::Size(50, 50), "discardable", &first
);
389 CreateBitmap(gfx::Size(50, 50), "discardable", &second
);
391 CreateBitmap(gfx::Size(50, 50), "discardable", &third
);
393 CreateBitmap(gfx::Size(50, 1), "discardable", &fourth
);
395 CreateBitmap(gfx::Size(10, 10), "discardable", &fifth
);
400 canvas
->drawBitmap(first
, 0, 0);
401 canvas
->translate(25, 0);
403 canvas
->drawBitmap(second
, 0, 0);
404 canvas
->translate(0, 50);
406 canvas
->drawBitmap(third
, 25, 0);
411 canvas
->translate(1, 0);
413 // At (1, 0), rotated 90 degrees
414 canvas
->drawBitmap(fourth
, 0, 0);
419 // At (0, 0), scaled by 5 and 6
420 canvas
->drawBitmap(fifth
, 0, 0);
422 skia::RefPtr
<SkPicture
> picture
= skia::AdoptRef(StopRecording(&recorder
, canvas
));
424 std::vector
<skia::PixelRefUtils::PositionPixelRef
> pixel_refs
;
425 skia::PixelRefUtils::GatherDiscardablePixelRefs(picture
.get(), &pixel_refs
);
427 EXPECT_EQ(5u, pixel_refs
.size());
428 EXPECT_FLOAT_RECT_EQ(gfx::RectF(0, 0, 50, 50),
429 gfx::SkRectToRectF(pixel_refs
[0].pixel_ref_rect
));
430 EXPECT_FLOAT_RECT_EQ(gfx::RectF(25, 0, 50, 50),
431 gfx::SkRectToRectF(pixel_refs
[1].pixel_ref_rect
));
432 EXPECT_FLOAT_RECT_EQ(gfx::RectF(50, 50, 50, 50),
433 gfx::SkRectToRectF(pixel_refs
[2].pixel_ref_rect
));
434 EXPECT_FLOAT_RECT_EQ(gfx::RectF(0, 0, 1, 50),
435 gfx::SkRectToRectF(pixel_refs
[3].pixel_ref_rect
));
436 EXPECT_FLOAT_RECT_EQ(gfx::RectF(0, 0, 50, 60),
437 gfx::SkRectToRectF(pixel_refs
[4].pixel_ref_rect
));
441 TEST(PixelRefUtilsTest
, DrawBitmapRect
) {
442 gfx::Rect
layer_rect(0, 0, 256, 256);
444 SkPictureRecorder recorder
;
445 SkCanvas
* canvas
= StartRecording(&recorder
, layer_rect
);
448 CreateBitmap(gfx::Size(50, 50), "discardable", &first
);
450 CreateBitmap(gfx::Size(50, 50), "discardable", &second
);
452 CreateBitmap(gfx::Size(50, 50), "discardable", &third
);
454 TestDiscardableShader first_shader
;
456 first_paint
.setShader(&first_shader
);
458 SkPaint non_discardable_paint
;
463 canvas
->drawBitmapRect(
464 first
, SkRect::MakeWH(100, 100), &non_discardable_paint
);
465 canvas
->translate(25, 0);
467 canvas
->drawBitmapRect(
468 second
, SkRect::MakeXYWH(50, 50, 10, 10), &non_discardable_paint
);
469 canvas
->translate(5, 50);
470 // (0, 30, 100, 100). One from bitmap, one from paint.
471 canvas
->drawBitmapRect(
472 third
, SkRect::MakeXYWH(-30, -20, 100, 100), &first_paint
);
476 skia::RefPtr
<SkPicture
> picture
= skia::AdoptRef(StopRecording(&recorder
, canvas
));
478 std::vector
<skia::PixelRefUtils::PositionPixelRef
> pixel_refs
;
479 skia::PixelRefUtils::GatherDiscardablePixelRefs(picture
.get(), &pixel_refs
);
481 EXPECT_EQ(4u, pixel_refs
.size());
482 EXPECT_FLOAT_RECT_EQ(gfx::RectF(0, 0, 100, 100),
483 gfx::SkRectToRectF(pixel_refs
[0].pixel_ref_rect
));
484 EXPECT_FLOAT_RECT_EQ(gfx::RectF(75, 50, 10, 10),
485 gfx::SkRectToRectF(pixel_refs
[1].pixel_ref_rect
));
486 EXPECT_FLOAT_RECT_EQ(gfx::RectF(0, 30, 100, 100),
487 gfx::SkRectToRectF(pixel_refs
[2].pixel_ref_rect
));
488 EXPECT_FLOAT_RECT_EQ(gfx::RectF(0, 30, 100, 100),
489 gfx::SkRectToRectF(pixel_refs
[3].pixel_ref_rect
));
492 TEST(PixelRefUtilsTest
, DrawSprite
) {
493 gfx::Rect
layer_rect(0, 0, 256, 256);
495 SkPictureRecorder recorder
;
496 SkCanvas
* canvas
= StartRecording(&recorder
, layer_rect
);
499 CreateBitmap(gfx::Size(50, 50), "discardable", &first
);
501 CreateBitmap(gfx::Size(50, 50), "discardable", &second
);
503 CreateBitmap(gfx::Size(50, 50), "discardable", &third
);
505 CreateBitmap(gfx::Size(50, 50), "discardable", &fourth
);
507 CreateBitmap(gfx::Size(50, 50), "discardable", &fifth
);
511 // Sprites aren't affected by the current matrix.
514 canvas
->drawSprite(first
, 0, 0);
515 canvas
->translate(25, 0);
517 canvas
->drawSprite(second
, 10, 0);
518 canvas
->translate(0, 50);
520 canvas
->drawSprite(third
, 25, 0);
527 canvas
->drawSprite(fourth
, 0, 0);
531 TestDiscardableShader first_shader
;
533 first_paint
.setShader(&first_shader
);
536 // (100, 100, 50, 50).
537 canvas
->drawSprite(fifth
, 100, 100, &first_paint
);
539 skia::RefPtr
<SkPicture
> picture
= skia::AdoptRef(StopRecording(&recorder
, canvas
));
541 std::vector
<skia::PixelRefUtils::PositionPixelRef
> pixel_refs
;
542 skia::PixelRefUtils::GatherDiscardablePixelRefs(picture
.get(), &pixel_refs
);
544 EXPECT_EQ(6u, pixel_refs
.size());
545 EXPECT_FLOAT_RECT_EQ(gfx::RectF(0, 0, 50, 50),
546 gfx::SkRectToRectF(pixel_refs
[0].pixel_ref_rect
));
547 EXPECT_FLOAT_RECT_EQ(gfx::RectF(10, 0, 50, 50),
548 gfx::SkRectToRectF(pixel_refs
[1].pixel_ref_rect
));
549 EXPECT_FLOAT_RECT_EQ(gfx::RectF(25, 0, 50, 50),
550 gfx::SkRectToRectF(pixel_refs
[2].pixel_ref_rect
));
551 EXPECT_FLOAT_RECT_EQ(gfx::RectF(0, 0, 50, 50),
552 gfx::SkRectToRectF(pixel_refs
[3].pixel_ref_rect
));
553 EXPECT_FLOAT_RECT_EQ(gfx::RectF(100, 100, 50, 50),
554 gfx::SkRectToRectF(pixel_refs
[4].pixel_ref_rect
));
555 EXPECT_FLOAT_RECT_EQ(gfx::RectF(100, 100, 50, 50),
556 gfx::SkRectToRectF(pixel_refs
[5].pixel_ref_rect
));
559 TEST(PixelRefUtilsTest
, DrawText
) {
560 gfx::Rect
layer_rect(0, 0, 256, 256);
562 SkPictureRecorder recorder
;
563 SkCanvas
* canvas
= StartRecording(&recorder
, layer_rect
);
565 TestDiscardableShader first_shader
;
567 first_paint
.setShader(&first_shader
);
570 points
[0].set(10, 50);
571 points
[1].set(20, 50);
572 points
[2].set(30, 50);
573 points
[3].set(40, 50);
582 canvas
->drawText("text", 4, 50, 50, first_paint
);
583 canvas
->drawPosText("text", 4, points
, first_paint
);
584 canvas
->drawTextOnPath("text", 4, path
, NULL
, first_paint
);
586 skia::RefPtr
<SkPicture
> picture
= skia::AdoptRef(StopRecording(&recorder
, canvas
));
588 std::vector
<skia::PixelRefUtils::PositionPixelRef
> pixel_refs
;
589 skia::PixelRefUtils::GatherDiscardablePixelRefs(picture
.get(), &pixel_refs
);
591 EXPECT_EQ(3u, pixel_refs
.size());
594 TEST(PixelRefUtilsTest
, DrawVertices
) {
595 gfx::Rect
layer_rect(0, 0, 256, 256);
597 SkPictureRecorder recorder
;
598 SkCanvas
* canvas
= StartRecording(&recorder
, layer_rect
);
600 TestDiscardableShader first_shader
;
602 first_paint
.setShader(&first_shader
);
604 TestDiscardableShader second_shader
;
605 SkPaint second_paint
;
606 second_paint
.setShader(&second_shader
);
608 TestDiscardableShader third_shader
;
610 third_paint
.setShader(&third_shader
);
614 uint16_t indecies
[3] = {0, 1, 2};
615 points
[0].set(10, 10);
616 points
[1].set(100, 20);
617 points
[2].set(50, 100);
619 canvas
->drawVertices(SkCanvas::kTriangles_VertexMode
,
631 canvas
->clipRect(SkRect::MakeWH(50, 50));
633 canvas
->drawVertices(SkCanvas::kTriangles_VertexMode
,
645 points
[0].set(50, 55);
646 points
[1].set(50, 55);
647 points
[2].set(200, 200);
648 // (50, 55, 150, 145).
649 canvas
->drawVertices(SkCanvas::kTriangles_VertexMode
,
659 skia::RefPtr
<SkPicture
> picture
= skia::AdoptRef(StopRecording(&recorder
, canvas
));
661 std::vector
<skia::PixelRefUtils::PositionPixelRef
> pixel_refs
;
662 skia::PixelRefUtils::GatherDiscardablePixelRefs(picture
.get(), &pixel_refs
);
664 EXPECT_EQ(3u, pixel_refs
.size());
665 EXPECT_FLOAT_RECT_EQ(gfx::RectF(10, 10, 90, 90),
666 gfx::SkRectToRectF(pixel_refs
[0].pixel_ref_rect
));
667 EXPECT_FLOAT_RECT_EQ(gfx::RectF(10, 10, 40, 40),
668 gfx::SkRectToRectF(pixel_refs
[1].pixel_ref_rect
));
669 EXPECT_FLOAT_RECT_EQ(gfx::RectF(50, 55, 150, 145),
670 gfx::SkRectToRectF(pixel_refs
[2].pixel_ref_rect
));