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/SkFlattenableBuffers.h"
14 #include "third_party/skia/include/core/SkPictureRecorder.h"
15 #include "third_party/skia/include/core/SkPixelRef.h"
16 #include "third_party/skia/include/core/SkPoint.h"
17 #include "third_party/skia/include/core/SkShader.h"
18 #include "third_party/skia/src/core/SkOrderedReadBuffer.h"
19 #include "ui/gfx/rect.h"
20 #include "ui/gfx/skia_util.h"
26 void CreateBitmap(gfx::Size size
, const char* uri
, SkBitmap
* bitmap
);
28 class TestDiscardableShader
: public SkShader
{
30 TestDiscardableShader() {
31 CreateBitmap(gfx::Size(50, 50), "discardable", &bitmap_
);
34 TestDiscardableShader(SkFlattenableReadBuffer
& flattenable_buffer
) {
35 SkOrderedReadBuffer
& buffer
=
36 static_cast<SkOrderedReadBuffer
&>(flattenable_buffer
);
37 SkReader32
* reader
= buffer
.getReader32();
40 uint32_t toSkip
= reader
->readU32();
43 CreateBitmap(gfx::Size(50, 50), "discardable", &bitmap_
);
46 virtual SkShader::BitmapType
asABitmap(SkBitmap
* bitmap
,
48 TileMode xy
[2]) const OVERRIDE
{
51 return SkShader::kDefault_BitmapType
;
54 // not indended to return an actual context. Just need to supply this.
55 virtual size_t contextSize() const OVERRIDE
{
56 return sizeof(SkShader::Context
);
59 SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(TestDiscardableShader
);
65 void CreateBitmap(gfx::Size size
, const char* uri
, SkBitmap
* bitmap
) {
66 const SkImageInfo info
= {
67 size
.width(), size
.height(), kPMColor_SkColorType
, kPremul_SkAlphaType
70 bitmap
->allocPixels(info
);
71 bitmap
->pixelRef()->setImmutable();
72 bitmap
->pixelRef()->setURI(uri
);
75 SkCanvas
* StartRecording(SkPictureRecorder
* recorder
, gfx::Rect layer_rect
) {
77 recorder
->beginRecording(layer_rect
.width(), layer_rect
.height());
80 canvas
->translate(-layer_rect
.x(), -layer_rect
.y());
81 canvas
->clipRect(SkRect::MakeXYWH(
82 layer_rect
.x(), layer_rect
.y(), layer_rect
.width(), layer_rect
.height()));
87 SkPicture
* StopRecording(SkPictureRecorder
* recorder
, SkCanvas
* canvas
) {
89 return recorder
->endRecording();
94 TEST(PixelRefUtilsTest
, DrawPaint
) {
95 gfx::Rect
layer_rect(0, 0, 256, 256);
97 SkPictureRecorder recorder
;
98 SkCanvas
* canvas
= StartRecording(&recorder
, layer_rect
);
100 TestDiscardableShader first_shader
;
102 first_paint
.setShader(&first_shader
);
104 TestDiscardableShader second_shader
;
105 SkPaint second_paint
;
106 second_paint
.setShader(&second_shader
);
108 TestDiscardableShader third_shader
;
110 third_paint
.setShader(&third_shader
);
112 canvas
->drawPaint(first_paint
);
113 canvas
->clipRect(SkRect::MakeXYWH(34, 45, 56, 67));
114 canvas
->drawPaint(second_paint
);
115 // Total clip is now (34, 45, 56, 55)
116 canvas
->clipRect(SkRect::MakeWH(100, 100));
117 canvas
->drawPaint(third_paint
);
119 skia::RefPtr
<SkPicture
> picture
= skia::AdoptRef(StopRecording(&recorder
, canvas
));
121 std::vector
<skia::PixelRefUtils::PositionPixelRef
> pixel_refs
;
122 skia::PixelRefUtils::GatherDiscardablePixelRefs(picture
.get(), &pixel_refs
);
124 EXPECT_EQ(3u, pixel_refs
.size());
125 EXPECT_FLOAT_RECT_EQ(gfx::RectF(0, 0, 256, 256),
126 gfx::SkRectToRectF(pixel_refs
[0].pixel_ref_rect
));
127 EXPECT_FLOAT_RECT_EQ(gfx::RectF(34, 45, 56, 67),
128 gfx::SkRectToRectF(pixel_refs
[1].pixel_ref_rect
));
129 EXPECT_FLOAT_RECT_EQ(gfx::RectF(34, 45, 56, 55),
130 gfx::SkRectToRectF(pixel_refs
[2].pixel_ref_rect
));
133 TEST(PixelRefUtilsTest
, DrawPoints
) {
134 gfx::Rect
layer_rect(0, 0, 256, 256);
136 SkPictureRecorder recorder
;
137 SkCanvas
* canvas
= StartRecording(&recorder
, layer_rect
);
139 TestDiscardableShader first_shader
;
141 first_paint
.setShader(&first_shader
);
143 TestDiscardableShader second_shader
;
144 SkPaint second_paint
;
145 second_paint
.setShader(&second_shader
);
147 TestDiscardableShader third_shader
;
149 third_paint
.setShader(&third_shader
);
152 points
[0].set(10, 10);
153 points
[1].set(100, 20);
154 points
[2].set(50, 100);
156 canvas
->drawPoints(SkCanvas::kPolygon_PointMode
, 3, points
, first_paint
);
160 canvas
->clipRect(SkRect::MakeWH(50, 50));
162 canvas
->drawPoints(SkCanvas::kPolygon_PointMode
, 3, points
, second_paint
);
166 points
[0].set(50, 55);
167 points
[1].set(50, 55);
168 points
[2].set(200, 200);
169 // (50, 55, 150, 145).
170 canvas
->drawPoints(SkCanvas::kPolygon_PointMode
, 3, points
, third_paint
);
172 skia::RefPtr
<SkPicture
> picture
= skia::AdoptRef(StopRecording(&recorder
, canvas
));
174 std::vector
<skia::PixelRefUtils::PositionPixelRef
> pixel_refs
;
175 skia::PixelRefUtils::GatherDiscardablePixelRefs(picture
.get(), &pixel_refs
);
177 EXPECT_EQ(3u, pixel_refs
.size());
178 EXPECT_FLOAT_RECT_EQ(gfx::RectF(10, 10, 90, 90),
179 gfx::SkRectToRectF(pixel_refs
[0].pixel_ref_rect
));
180 EXPECT_FLOAT_RECT_EQ(gfx::RectF(10, 10, 40, 40),
181 gfx::SkRectToRectF(pixel_refs
[1].pixel_ref_rect
));
182 EXPECT_FLOAT_RECT_EQ(gfx::RectF(50, 55, 150, 145),
183 gfx::SkRectToRectF(pixel_refs
[2].pixel_ref_rect
));
186 TEST(PixelRefUtilsTest
, DrawRect
) {
187 gfx::Rect
layer_rect(0, 0, 256, 256);
189 SkPictureRecorder recorder
;
190 SkCanvas
* canvas
= StartRecording(&recorder
, layer_rect
);
192 TestDiscardableShader first_shader
;
194 first_paint
.setShader(&first_shader
);
196 TestDiscardableShader second_shader
;
197 SkPaint second_paint
;
198 second_paint
.setShader(&second_shader
);
200 TestDiscardableShader third_shader
;
202 third_paint
.setShader(&third_shader
);
205 canvas
->drawRect(SkRect::MakeXYWH(10, 20, 30, 40), first_paint
);
209 canvas
->translate(5, 17);
211 canvas
->drawRect(SkRect::MakeXYWH(0, 33, 25, 35), second_paint
);
215 canvas
->clipRect(SkRect::MakeXYWH(50, 50, 50, 50));
216 canvas
->translate(20, 20);
218 canvas
->drawRect(SkRect::MakeXYWH(0, 0, 100, 100), third_paint
);
220 skia::RefPtr
<SkPicture
> picture
= skia::AdoptRef(StopRecording(&recorder
, canvas
));
222 std::vector
<skia::PixelRefUtils::PositionPixelRef
> pixel_refs
;
223 skia::PixelRefUtils::GatherDiscardablePixelRefs(picture
.get(), &pixel_refs
);
225 EXPECT_EQ(3u, pixel_refs
.size());
226 EXPECT_FLOAT_RECT_EQ(gfx::RectF(10, 20, 30, 40),
227 gfx::SkRectToRectF(pixel_refs
[0].pixel_ref_rect
));
228 EXPECT_FLOAT_RECT_EQ(gfx::RectF(5, 50, 25, 35),
229 gfx::SkRectToRectF(pixel_refs
[1].pixel_ref_rect
));
230 EXPECT_FLOAT_RECT_EQ(gfx::RectF(50, 50, 50, 50),
231 gfx::SkRectToRectF(pixel_refs
[2].pixel_ref_rect
));
234 TEST(PixelRefUtilsTest
, DrawRRect
) {
235 gfx::Rect
layer_rect(0, 0, 256, 256);
237 SkPictureRecorder recorder
;
238 SkCanvas
* canvas
= StartRecording(&recorder
, layer_rect
);
240 TestDiscardableShader first_shader
;
242 first_paint
.setShader(&first_shader
);
244 TestDiscardableShader second_shader
;
245 SkPaint second_paint
;
246 second_paint
.setShader(&second_shader
);
248 TestDiscardableShader third_shader
;
250 third_paint
.setShader(&third_shader
);
253 rrect
.setRect(SkRect::MakeXYWH(10, 20, 30, 40));
256 canvas
->drawRRect(rrect
, first_paint
);
260 canvas
->translate(5, 17);
261 rrect
.setRect(SkRect::MakeXYWH(0, 33, 25, 35));
263 canvas
->drawRRect(rrect
, second_paint
);
267 canvas
->clipRect(SkRect::MakeXYWH(50, 50, 50, 50));
268 canvas
->translate(20, 20);
269 rrect
.setRect(SkRect::MakeXYWH(0, 0, 100, 100));
271 canvas
->drawRRect(rrect
, third_paint
);
273 skia::RefPtr
<SkPicture
> picture
= skia::AdoptRef(StopRecording(&recorder
, canvas
));
275 std::vector
<skia::PixelRefUtils::PositionPixelRef
> pixel_refs
;
276 skia::PixelRefUtils::GatherDiscardablePixelRefs(picture
.get(), &pixel_refs
);
278 EXPECT_EQ(3u, pixel_refs
.size());
279 EXPECT_FLOAT_RECT_EQ(gfx::RectF(10, 20, 30, 40),
280 gfx::SkRectToRectF(pixel_refs
[0].pixel_ref_rect
));
281 EXPECT_FLOAT_RECT_EQ(gfx::RectF(5, 50, 25, 35),
282 gfx::SkRectToRectF(pixel_refs
[1].pixel_ref_rect
));
283 EXPECT_FLOAT_RECT_EQ(gfx::RectF(50, 50, 50, 50),
284 gfx::SkRectToRectF(pixel_refs
[2].pixel_ref_rect
));
287 TEST(PixelRefUtilsTest
, DrawOval
) {
288 gfx::Rect
layer_rect(0, 0, 256, 256);
290 SkPictureRecorder recorder
;
291 SkCanvas
* canvas
= StartRecording(&recorder
, layer_rect
);
293 TestDiscardableShader first_shader
;
295 first_paint
.setShader(&first_shader
);
297 TestDiscardableShader second_shader
;
298 SkPaint second_paint
;
299 second_paint
.setShader(&second_shader
);
301 TestDiscardableShader third_shader
;
303 third_paint
.setShader(&third_shader
);
307 canvas
->scale(2, 0.5);
309 canvas
->drawOval(SkRect::MakeXYWH(10, 20, 30, 40), first_paint
);
314 canvas
->translate(1, 2);
316 canvas
->drawRect(SkRect::MakeXYWH(0, 33, 25, 35), second_paint
);
320 canvas
->clipRect(SkRect::MakeXYWH(50, 50, 50, 50));
321 canvas
->translate(20, 20);
323 canvas
->drawRect(SkRect::MakeXYWH(0, 0, 100, 100), third_paint
);
325 skia::RefPtr
<SkPicture
> picture
= skia::AdoptRef(StopRecording(&recorder
, canvas
));
327 std::vector
<skia::PixelRefUtils::PositionPixelRef
> pixel_refs
;
328 skia::PixelRefUtils::GatherDiscardablePixelRefs(picture
.get(), &pixel_refs
);
330 EXPECT_EQ(3u, pixel_refs
.size());
331 EXPECT_FLOAT_RECT_EQ(gfx::RectF(20, 10, 60, 20),
332 gfx::SkRectToRectF(pixel_refs
[0].pixel_ref_rect
));
333 EXPECT_FLOAT_RECT_EQ(gfx::RectF(1, 35, 25, 35),
334 gfx::SkRectToRectF(pixel_refs
[1].pixel_ref_rect
));
335 EXPECT_FLOAT_RECT_EQ(gfx::RectF(50, 50, 50, 50),
336 gfx::SkRectToRectF(pixel_refs
[2].pixel_ref_rect
));
339 TEST(PixelRefUtilsTest
, DrawPath
) {
340 gfx::Rect
layer_rect(0, 0, 256, 256);
342 SkPictureRecorder recorder
;
343 SkCanvas
* canvas
= StartRecording(&recorder
, layer_rect
);
345 TestDiscardableShader first_shader
;
347 first_paint
.setShader(&first_shader
);
349 TestDiscardableShader second_shader
;
350 SkPaint second_paint
;
351 second_paint
.setShader(&second_shader
);
356 path
.lineTo(22, 101);
359 canvas
->drawPath(path
, first_paint
);
362 canvas
->clipRect(SkRect::MakeWH(50, 50));
365 canvas
->drawPath(path
, second_paint
);
369 skia::RefPtr
<SkPicture
> picture
= skia::AdoptRef(StopRecording(&recorder
, canvas
));
371 std::vector
<skia::PixelRefUtils::PositionPixelRef
> pixel_refs
;
372 skia::PixelRefUtils::GatherDiscardablePixelRefs(picture
.get(), &pixel_refs
);
374 EXPECT_EQ(2u, pixel_refs
.size());
375 EXPECT_FLOAT_RECT_EQ(gfx::RectF(12, 13, 38, 88),
376 gfx::SkRectToRectF(pixel_refs
[0].pixel_ref_rect
));
377 EXPECT_FLOAT_RECT_EQ(gfx::RectF(12, 13, 38, 37),
378 gfx::SkRectToRectF(pixel_refs
[1].pixel_ref_rect
));
381 TEST(PixelRefUtilsTest
, DrawBitmap
) {
382 gfx::Rect
layer_rect(0, 0, 256, 256);
384 SkPictureRecorder recorder
;
385 SkCanvas
* canvas
= StartRecording(&recorder
, layer_rect
);
388 CreateBitmap(gfx::Size(50, 50), "discardable", &first
);
390 CreateBitmap(gfx::Size(50, 50), "discardable", &second
);
392 CreateBitmap(gfx::Size(50, 50), "discardable", &third
);
394 CreateBitmap(gfx::Size(50, 1), "discardable", &fourth
);
396 CreateBitmap(gfx::Size(10, 10), "discardable", &fifth
);
401 canvas
->drawBitmap(first
, 0, 0);
402 canvas
->translate(25, 0);
404 canvas
->drawBitmap(second
, 0, 0);
405 canvas
->translate(0, 50);
407 canvas
->drawBitmap(third
, 25, 0);
412 canvas
->translate(1, 0);
414 // At (1, 0), rotated 90 degrees
415 canvas
->drawBitmap(fourth
, 0, 0);
420 // At (0, 0), scaled by 5 and 6
421 canvas
->drawBitmap(fifth
, 0, 0);
423 skia::RefPtr
<SkPicture
> picture
= skia::AdoptRef(StopRecording(&recorder
, canvas
));
425 std::vector
<skia::PixelRefUtils::PositionPixelRef
> pixel_refs
;
426 skia::PixelRefUtils::GatherDiscardablePixelRefs(picture
.get(), &pixel_refs
);
428 EXPECT_EQ(5u, pixel_refs
.size());
429 EXPECT_FLOAT_RECT_EQ(gfx::RectF(0, 0, 50, 50),
430 gfx::SkRectToRectF(pixel_refs
[0].pixel_ref_rect
));
431 EXPECT_FLOAT_RECT_EQ(gfx::RectF(25, 0, 50, 50),
432 gfx::SkRectToRectF(pixel_refs
[1].pixel_ref_rect
));
433 EXPECT_FLOAT_RECT_EQ(gfx::RectF(50, 50, 50, 50),
434 gfx::SkRectToRectF(pixel_refs
[2].pixel_ref_rect
));
435 EXPECT_FLOAT_RECT_EQ(gfx::RectF(0, 0, 1, 50),
436 gfx::SkRectToRectF(pixel_refs
[3].pixel_ref_rect
));
437 EXPECT_FLOAT_RECT_EQ(gfx::RectF(0, 0, 50, 60),
438 gfx::SkRectToRectF(pixel_refs
[4].pixel_ref_rect
));
442 TEST(PixelRefUtilsTest
, DrawBitmapRect
) {
443 gfx::Rect
layer_rect(0, 0, 256, 256);
445 SkPictureRecorder recorder
;
446 SkCanvas
* canvas
= StartRecording(&recorder
, layer_rect
);
449 CreateBitmap(gfx::Size(50, 50), "discardable", &first
);
451 CreateBitmap(gfx::Size(50, 50), "discardable", &second
);
453 CreateBitmap(gfx::Size(50, 50), "discardable", &third
);
455 TestDiscardableShader first_shader
;
457 first_paint
.setShader(&first_shader
);
459 SkPaint non_discardable_paint
;
464 canvas
->drawBitmapRect(
465 first
, SkRect::MakeWH(100, 100), &non_discardable_paint
);
466 canvas
->translate(25, 0);
468 canvas
->drawBitmapRect(
469 second
, SkRect::MakeXYWH(50, 50, 10, 10), &non_discardable_paint
);
470 canvas
->translate(5, 50);
471 // (0, 30, 100, 100). One from bitmap, one from paint.
472 canvas
->drawBitmapRect(
473 third
, SkRect::MakeXYWH(-30, -20, 100, 100), &first_paint
);
477 skia::RefPtr
<SkPicture
> picture
= skia::AdoptRef(StopRecording(&recorder
, canvas
));
479 std::vector
<skia::PixelRefUtils::PositionPixelRef
> pixel_refs
;
480 skia::PixelRefUtils::GatherDiscardablePixelRefs(picture
.get(), &pixel_refs
);
482 EXPECT_EQ(4u, pixel_refs
.size());
483 EXPECT_FLOAT_RECT_EQ(gfx::RectF(0, 0, 100, 100),
484 gfx::SkRectToRectF(pixel_refs
[0].pixel_ref_rect
));
485 EXPECT_FLOAT_RECT_EQ(gfx::RectF(75, 50, 10, 10),
486 gfx::SkRectToRectF(pixel_refs
[1].pixel_ref_rect
));
487 EXPECT_FLOAT_RECT_EQ(gfx::RectF(0, 30, 100, 100),
488 gfx::SkRectToRectF(pixel_refs
[2].pixel_ref_rect
));
489 EXPECT_FLOAT_RECT_EQ(gfx::RectF(0, 30, 100, 100),
490 gfx::SkRectToRectF(pixel_refs
[3].pixel_ref_rect
));
493 TEST(PixelRefUtilsTest
, DrawSprite
) {
494 gfx::Rect
layer_rect(0, 0, 256, 256);
496 SkPictureRecorder recorder
;
497 SkCanvas
* canvas
= StartRecording(&recorder
, layer_rect
);
500 CreateBitmap(gfx::Size(50, 50), "discardable", &first
);
502 CreateBitmap(gfx::Size(50, 50), "discardable", &second
);
504 CreateBitmap(gfx::Size(50, 50), "discardable", &third
);
506 CreateBitmap(gfx::Size(50, 50), "discardable", &fourth
);
508 CreateBitmap(gfx::Size(50, 50), "discardable", &fifth
);
512 // Sprites aren't affected by the current matrix.
515 canvas
->drawSprite(first
, 0, 0);
516 canvas
->translate(25, 0);
518 canvas
->drawSprite(second
, 10, 0);
519 canvas
->translate(0, 50);
521 canvas
->drawSprite(third
, 25, 0);
528 canvas
->drawSprite(fourth
, 0, 0);
532 TestDiscardableShader first_shader
;
534 first_paint
.setShader(&first_shader
);
537 // (100, 100, 50, 50).
538 canvas
->drawSprite(fifth
, 100, 100, &first_paint
);
540 skia::RefPtr
<SkPicture
> picture
= skia::AdoptRef(StopRecording(&recorder
, canvas
));
542 std::vector
<skia::PixelRefUtils::PositionPixelRef
> pixel_refs
;
543 skia::PixelRefUtils::GatherDiscardablePixelRefs(picture
.get(), &pixel_refs
);
545 EXPECT_EQ(6u, pixel_refs
.size());
546 EXPECT_FLOAT_RECT_EQ(gfx::RectF(0, 0, 50, 50),
547 gfx::SkRectToRectF(pixel_refs
[0].pixel_ref_rect
));
548 EXPECT_FLOAT_RECT_EQ(gfx::RectF(10, 0, 50, 50),
549 gfx::SkRectToRectF(pixel_refs
[1].pixel_ref_rect
));
550 EXPECT_FLOAT_RECT_EQ(gfx::RectF(25, 0, 50, 50),
551 gfx::SkRectToRectF(pixel_refs
[2].pixel_ref_rect
));
552 EXPECT_FLOAT_RECT_EQ(gfx::RectF(0, 0, 50, 50),
553 gfx::SkRectToRectF(pixel_refs
[3].pixel_ref_rect
));
554 EXPECT_FLOAT_RECT_EQ(gfx::RectF(100, 100, 50, 50),
555 gfx::SkRectToRectF(pixel_refs
[4].pixel_ref_rect
));
556 EXPECT_FLOAT_RECT_EQ(gfx::RectF(100, 100, 50, 50),
557 gfx::SkRectToRectF(pixel_refs
[5].pixel_ref_rect
));
560 TEST(PixelRefUtilsTest
, DrawText
) {
561 gfx::Rect
layer_rect(0, 0, 256, 256);
563 SkPictureRecorder recorder
;
564 SkCanvas
* canvas
= StartRecording(&recorder
, layer_rect
);
566 TestDiscardableShader first_shader
;
568 first_paint
.setShader(&first_shader
);
571 points
[0].set(10, 50);
572 points
[1].set(20, 50);
573 points
[2].set(30, 50);
574 points
[3].set(40, 50);
583 canvas
->drawText("text", 4, 50, 50, first_paint
);
584 canvas
->drawPosText("text", 4, points
, first_paint
);
585 canvas
->drawTextOnPath("text", 4, path
, NULL
, first_paint
);
587 skia::RefPtr
<SkPicture
> picture
= skia::AdoptRef(StopRecording(&recorder
, canvas
));
589 std::vector
<skia::PixelRefUtils::PositionPixelRef
> pixel_refs
;
590 skia::PixelRefUtils::GatherDiscardablePixelRefs(picture
.get(), &pixel_refs
);
592 EXPECT_EQ(3u, pixel_refs
.size());
595 TEST(PixelRefUtilsTest
, DrawVertices
) {
596 gfx::Rect
layer_rect(0, 0, 256, 256);
598 SkPictureRecorder recorder
;
599 SkCanvas
* canvas
= StartRecording(&recorder
, layer_rect
);
601 TestDiscardableShader first_shader
;
603 first_paint
.setShader(&first_shader
);
605 TestDiscardableShader second_shader
;
606 SkPaint second_paint
;
607 second_paint
.setShader(&second_shader
);
609 TestDiscardableShader third_shader
;
611 third_paint
.setShader(&third_shader
);
615 uint16_t indecies
[3] = {0, 1, 2};
616 points
[0].set(10, 10);
617 points
[1].set(100, 20);
618 points
[2].set(50, 100);
620 canvas
->drawVertices(SkCanvas::kTriangles_VertexMode
,
632 canvas
->clipRect(SkRect::MakeWH(50, 50));
634 canvas
->drawVertices(SkCanvas::kTriangles_VertexMode
,
646 points
[0].set(50, 55);
647 points
[1].set(50, 55);
648 points
[2].set(200, 200);
649 // (50, 55, 150, 145).
650 canvas
->drawVertices(SkCanvas::kTriangles_VertexMode
,
660 skia::RefPtr
<SkPicture
> picture
= skia::AdoptRef(StopRecording(&recorder
, canvas
));
662 std::vector
<skia::PixelRefUtils::PositionPixelRef
> pixel_refs
;
663 skia::PixelRefUtils::GatherDiscardablePixelRefs(picture
.get(), &pixel_refs
);
665 EXPECT_EQ(3u, pixel_refs
.size());
666 EXPECT_FLOAT_RECT_EQ(gfx::RectF(10, 10, 90, 90),
667 gfx::SkRectToRectF(pixel_refs
[0].pixel_ref_rect
));
668 EXPECT_FLOAT_RECT_EQ(gfx::RectF(10, 10, 40, 40),
669 gfx::SkRectToRectF(pixel_refs
[1].pixel_ref_rect
));
670 EXPECT_FLOAT_RECT_EQ(gfx::RectF(50, 55, 150, 145),
671 gfx::SkRectToRectF(pixel_refs
[2].pixel_ref_rect
));