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
->endRecordingAsPicture();
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
=
119 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
=
173 skia::AdoptRef(StopRecording(&recorder
, canvas
));
175 std::vector
<skia::PixelRefUtils::PositionPixelRef
> pixel_refs
;
176 skia::PixelRefUtils::GatherDiscardablePixelRefs(picture
.get(), &pixel_refs
);
178 EXPECT_EQ(3u, pixel_refs
.size());
179 EXPECT_FLOAT_RECT_EQ(gfx::RectF(10, 10, 90, 90),
180 gfx::SkRectToRectF(pixel_refs
[0].pixel_ref_rect
));
181 EXPECT_FLOAT_RECT_EQ(gfx::RectF(10, 10, 40, 40),
182 gfx::SkRectToRectF(pixel_refs
[1].pixel_ref_rect
));
183 EXPECT_FLOAT_RECT_EQ(gfx::RectF(50, 55, 150, 145),
184 gfx::SkRectToRectF(pixel_refs
[2].pixel_ref_rect
));
187 TEST(PixelRefUtilsTest
, DrawRect
) {
188 gfx::Rect
layer_rect(0, 0, 256, 256);
190 SkPictureRecorder recorder
;
191 SkCanvas
* canvas
= StartRecording(&recorder
, layer_rect
);
193 TestDiscardableShader first_shader
;
195 first_paint
.setShader(&first_shader
);
197 TestDiscardableShader second_shader
;
198 SkPaint second_paint
;
199 second_paint
.setShader(&second_shader
);
201 TestDiscardableShader third_shader
;
203 third_paint
.setShader(&third_shader
);
206 canvas
->drawRect(SkRect::MakeXYWH(10, 20, 30, 40), first_paint
);
210 canvas
->translate(5, 17);
212 canvas
->drawRect(SkRect::MakeXYWH(0, 33, 25, 35), second_paint
);
216 canvas
->clipRect(SkRect::MakeXYWH(50, 50, 50, 50));
217 canvas
->translate(20, 20);
219 canvas
->drawRect(SkRect::MakeXYWH(0, 0, 100, 100), third_paint
);
221 skia::RefPtr
<SkPicture
> picture
=
222 skia::AdoptRef(StopRecording(&recorder
, canvas
));
224 std::vector
<skia::PixelRefUtils::PositionPixelRef
> pixel_refs
;
225 skia::PixelRefUtils::GatherDiscardablePixelRefs(picture
.get(), &pixel_refs
);
227 EXPECT_EQ(3u, pixel_refs
.size());
228 EXPECT_FLOAT_RECT_EQ(gfx::RectF(10, 20, 30, 40),
229 gfx::SkRectToRectF(pixel_refs
[0].pixel_ref_rect
));
230 EXPECT_FLOAT_RECT_EQ(gfx::RectF(5, 50, 25, 35),
231 gfx::SkRectToRectF(pixel_refs
[1].pixel_ref_rect
));
232 EXPECT_FLOAT_RECT_EQ(gfx::RectF(50, 50, 50, 50),
233 gfx::SkRectToRectF(pixel_refs
[2].pixel_ref_rect
));
236 TEST(PixelRefUtilsTest
, DrawRRect
) {
237 gfx::Rect
layer_rect(0, 0, 256, 256);
239 SkPictureRecorder recorder
;
240 SkCanvas
* canvas
= StartRecording(&recorder
, layer_rect
);
242 TestDiscardableShader first_shader
;
244 first_paint
.setShader(&first_shader
);
246 TestDiscardableShader second_shader
;
247 SkPaint second_paint
;
248 second_paint
.setShader(&second_shader
);
250 TestDiscardableShader third_shader
;
252 third_paint
.setShader(&third_shader
);
255 rrect
.setRect(SkRect::MakeXYWH(10, 20, 30, 40));
258 canvas
->drawRRect(rrect
, first_paint
);
262 canvas
->translate(5, 17);
263 rrect
.setRect(SkRect::MakeXYWH(0, 33, 25, 35));
265 canvas
->drawRRect(rrect
, second_paint
);
269 canvas
->clipRect(SkRect::MakeXYWH(50, 50, 50, 50));
270 canvas
->translate(20, 20);
271 rrect
.setRect(SkRect::MakeXYWH(0, 0, 100, 100));
273 canvas
->drawRRect(rrect
, third_paint
);
275 skia::RefPtr
<SkPicture
> picture
=
276 skia::AdoptRef(StopRecording(&recorder
, canvas
));
278 std::vector
<skia::PixelRefUtils::PositionPixelRef
> pixel_refs
;
279 skia::PixelRefUtils::GatherDiscardablePixelRefs(picture
.get(), &pixel_refs
);
281 EXPECT_EQ(3u, pixel_refs
.size());
282 EXPECT_FLOAT_RECT_EQ(gfx::RectF(10, 20, 30, 40),
283 gfx::SkRectToRectF(pixel_refs
[0].pixel_ref_rect
));
284 EXPECT_FLOAT_RECT_EQ(gfx::RectF(5, 50, 25, 35),
285 gfx::SkRectToRectF(pixel_refs
[1].pixel_ref_rect
));
286 EXPECT_FLOAT_RECT_EQ(gfx::RectF(50, 50, 50, 50),
287 gfx::SkRectToRectF(pixel_refs
[2].pixel_ref_rect
));
290 TEST(PixelRefUtilsTest
, DrawOval
) {
291 gfx::Rect
layer_rect(0, 0, 256, 256);
293 SkPictureRecorder recorder
;
294 SkCanvas
* canvas
= StartRecording(&recorder
, layer_rect
);
296 TestDiscardableShader first_shader
;
298 first_paint
.setShader(&first_shader
);
300 TestDiscardableShader second_shader
;
301 SkPaint second_paint
;
302 second_paint
.setShader(&second_shader
);
304 TestDiscardableShader third_shader
;
306 third_paint
.setShader(&third_shader
);
310 canvas
->scale(2, 0.5);
312 canvas
->drawOval(SkRect::MakeXYWH(10, 20, 30, 40), first_paint
);
317 canvas
->translate(1, 2);
319 canvas
->drawRect(SkRect::MakeXYWH(0, 33, 25, 35), second_paint
);
323 canvas
->clipRect(SkRect::MakeXYWH(50, 50, 50, 50));
324 canvas
->translate(20, 20);
326 canvas
->drawRect(SkRect::MakeXYWH(0, 0, 100, 100), third_paint
);
328 skia::RefPtr
<SkPicture
> picture
=
329 skia::AdoptRef(StopRecording(&recorder
, canvas
));
331 std::vector
<skia::PixelRefUtils::PositionPixelRef
> pixel_refs
;
332 skia::PixelRefUtils::GatherDiscardablePixelRefs(picture
.get(), &pixel_refs
);
334 EXPECT_EQ(3u, pixel_refs
.size());
335 EXPECT_FLOAT_RECT_EQ(gfx::RectF(20, 10, 60, 20),
336 gfx::SkRectToRectF(pixel_refs
[0].pixel_ref_rect
));
337 EXPECT_FLOAT_RECT_EQ(gfx::RectF(1, 35, 25, 35),
338 gfx::SkRectToRectF(pixel_refs
[1].pixel_ref_rect
));
339 EXPECT_FLOAT_RECT_EQ(gfx::RectF(50, 50, 50, 50),
340 gfx::SkRectToRectF(pixel_refs
[2].pixel_ref_rect
));
343 TEST(PixelRefUtilsTest
, DrawPath
) {
344 gfx::Rect
layer_rect(0, 0, 256, 256);
346 SkPictureRecorder recorder
;
347 SkCanvas
* canvas
= StartRecording(&recorder
, layer_rect
);
349 TestDiscardableShader first_shader
;
351 first_paint
.setShader(&first_shader
);
353 TestDiscardableShader second_shader
;
354 SkPaint second_paint
;
355 second_paint
.setShader(&second_shader
);
360 path
.lineTo(22, 101);
363 canvas
->drawPath(path
, first_paint
);
366 canvas
->clipRect(SkRect::MakeWH(50, 50));
369 canvas
->drawPath(path
, second_paint
);
373 skia::RefPtr
<SkPicture
> picture
=
374 skia::AdoptRef(StopRecording(&recorder
, canvas
));
376 std::vector
<skia::PixelRefUtils::PositionPixelRef
> pixel_refs
;
377 skia::PixelRefUtils::GatherDiscardablePixelRefs(picture
.get(), &pixel_refs
);
379 EXPECT_EQ(2u, pixel_refs
.size());
380 EXPECT_FLOAT_RECT_EQ(gfx::RectF(12, 13, 38, 88),
381 gfx::SkRectToRectF(pixel_refs
[0].pixel_ref_rect
));
382 EXPECT_FLOAT_RECT_EQ(gfx::RectF(12, 13, 38, 37),
383 gfx::SkRectToRectF(pixel_refs
[1].pixel_ref_rect
));
386 TEST(PixelRefUtilsTest
, DrawBitmap
) {
387 gfx::Rect
layer_rect(0, 0, 256, 256);
389 SkPictureRecorder recorder
;
390 SkCanvas
* canvas
= StartRecording(&recorder
, layer_rect
);
393 CreateBitmap(gfx::Size(50, 50), "discardable", &first
);
395 CreateBitmap(gfx::Size(50, 50), "discardable", &second
);
397 CreateBitmap(gfx::Size(50, 50), "discardable", &third
);
399 CreateBitmap(gfx::Size(50, 1), "discardable", &fourth
);
401 CreateBitmap(gfx::Size(10, 10), "discardable", &fifth
);
406 canvas
->drawBitmap(first
, 0, 0);
407 canvas
->translate(25, 0);
409 canvas
->drawBitmap(second
, 0, 0);
410 canvas
->translate(0, 50);
412 canvas
->drawBitmap(third
, 25, 0);
417 canvas
->translate(1, 0);
419 // At (1, 0), rotated 90 degrees
420 canvas
->drawBitmap(fourth
, 0, 0);
425 // At (0, 0), scaled by 5 and 6
426 canvas
->drawBitmap(fifth
, 0, 0);
428 skia::RefPtr
<SkPicture
> picture
=
429 skia::AdoptRef(StopRecording(&recorder
, canvas
));
431 std::vector
<skia::PixelRefUtils::PositionPixelRef
> pixel_refs
;
432 skia::PixelRefUtils::GatherDiscardablePixelRefs(picture
.get(), &pixel_refs
);
434 EXPECT_EQ(5u, pixel_refs
.size());
435 EXPECT_FLOAT_RECT_EQ(gfx::RectF(0, 0, 50, 50),
436 gfx::SkRectToRectF(pixel_refs
[0].pixel_ref_rect
));
437 EXPECT_FLOAT_RECT_EQ(gfx::RectF(25, 0, 50, 50),
438 gfx::SkRectToRectF(pixel_refs
[1].pixel_ref_rect
));
439 EXPECT_FLOAT_RECT_EQ(gfx::RectF(50, 50, 50, 50),
440 gfx::SkRectToRectF(pixel_refs
[2].pixel_ref_rect
));
441 EXPECT_FLOAT_RECT_EQ(gfx::RectF(0, 0, 1, 50),
442 gfx::SkRectToRectF(pixel_refs
[3].pixel_ref_rect
));
443 EXPECT_FLOAT_RECT_EQ(gfx::RectF(0, 0, 50, 60),
444 gfx::SkRectToRectF(pixel_refs
[4].pixel_ref_rect
));
447 TEST(PixelRefUtilsTest
, DrawBitmapRect
) {
448 gfx::Rect
layer_rect(0, 0, 256, 256);
450 SkPictureRecorder recorder
;
451 SkCanvas
* canvas
= StartRecording(&recorder
, layer_rect
);
454 CreateBitmap(gfx::Size(50, 50), "discardable", &first
);
456 CreateBitmap(gfx::Size(50, 50), "discardable", &second
);
458 CreateBitmap(gfx::Size(50, 50), "discardable", &third
);
460 TestDiscardableShader first_shader
;
462 first_paint
.setShader(&first_shader
);
464 SkPaint non_discardable_paint
;
469 canvas
->drawBitmapRect(
470 first
, SkRect::MakeWH(100, 100), &non_discardable_paint
);
471 canvas
->translate(25, 0);
473 canvas
->drawBitmapRect(
474 second
, SkRect::MakeXYWH(50, 50, 10, 10), &non_discardable_paint
);
475 canvas
->translate(5, 50);
476 // (0, 30, 100, 100). One from bitmap, one from paint.
477 canvas
->drawBitmapRect(
478 third
, SkRect::MakeXYWH(-30, -20, 100, 100), &first_paint
);
482 skia::RefPtr
<SkPicture
> picture
=
483 skia::AdoptRef(StopRecording(&recorder
, canvas
));
485 std::vector
<skia::PixelRefUtils::PositionPixelRef
> pixel_refs
;
486 skia::PixelRefUtils::GatherDiscardablePixelRefs(picture
.get(), &pixel_refs
);
488 EXPECT_EQ(4u, pixel_refs
.size());
489 EXPECT_FLOAT_RECT_EQ(gfx::RectF(0, 0, 100, 100),
490 gfx::SkRectToRectF(pixel_refs
[0].pixel_ref_rect
));
491 EXPECT_FLOAT_RECT_EQ(gfx::RectF(75, 50, 10, 10),
492 gfx::SkRectToRectF(pixel_refs
[1].pixel_ref_rect
));
493 EXPECT_FLOAT_RECT_EQ(gfx::RectF(0, 30, 100, 100),
494 gfx::SkRectToRectF(pixel_refs
[2].pixel_ref_rect
));
495 EXPECT_FLOAT_RECT_EQ(gfx::RectF(0, 30, 100, 100),
496 gfx::SkRectToRectF(pixel_refs
[3].pixel_ref_rect
));
499 TEST(PixelRefUtilsTest
, DrawSprite
) {
500 gfx::Rect
layer_rect(0, 0, 256, 256);
502 SkPictureRecorder recorder
;
503 SkCanvas
* canvas
= StartRecording(&recorder
, layer_rect
);
506 CreateBitmap(gfx::Size(50, 50), "discardable", &first
);
508 CreateBitmap(gfx::Size(50, 50), "discardable", &second
);
510 CreateBitmap(gfx::Size(50, 50), "discardable", &third
);
512 CreateBitmap(gfx::Size(50, 50), "discardable", &fourth
);
514 CreateBitmap(gfx::Size(50, 50), "discardable", &fifth
);
518 // Sprites aren't affected by the current matrix.
521 canvas
->drawSprite(first
, 0, 0);
522 canvas
->translate(25, 0);
524 canvas
->drawSprite(second
, 10, 0);
525 canvas
->translate(0, 50);
527 canvas
->drawSprite(third
, 25, 0);
534 canvas
->drawSprite(fourth
, 0, 0);
538 TestDiscardableShader first_shader
;
540 first_paint
.setShader(&first_shader
);
543 // (100, 100, 50, 50).
544 canvas
->drawSprite(fifth
, 100, 100, &first_paint
);
546 skia::RefPtr
<SkPicture
> picture
=
547 skia::AdoptRef(StopRecording(&recorder
, canvas
));
549 std::vector
<skia::PixelRefUtils::PositionPixelRef
> pixel_refs
;
550 skia::PixelRefUtils::GatherDiscardablePixelRefs(picture
.get(), &pixel_refs
);
552 EXPECT_EQ(6u, pixel_refs
.size());
553 EXPECT_FLOAT_RECT_EQ(gfx::RectF(0, 0, 50, 50),
554 gfx::SkRectToRectF(pixel_refs
[0].pixel_ref_rect
));
555 EXPECT_FLOAT_RECT_EQ(gfx::RectF(10, 0, 50, 50),
556 gfx::SkRectToRectF(pixel_refs
[1].pixel_ref_rect
));
557 EXPECT_FLOAT_RECT_EQ(gfx::RectF(25, 0, 50, 50),
558 gfx::SkRectToRectF(pixel_refs
[2].pixel_ref_rect
));
559 EXPECT_FLOAT_RECT_EQ(gfx::RectF(0, 0, 50, 50),
560 gfx::SkRectToRectF(pixel_refs
[3].pixel_ref_rect
));
561 EXPECT_FLOAT_RECT_EQ(gfx::RectF(100, 100, 50, 50),
562 gfx::SkRectToRectF(pixel_refs
[4].pixel_ref_rect
));
563 EXPECT_FLOAT_RECT_EQ(gfx::RectF(100, 100, 50, 50),
564 gfx::SkRectToRectF(pixel_refs
[5].pixel_ref_rect
));
567 TEST(PixelRefUtilsTest
, DrawText
) {
568 gfx::Rect
layer_rect(0, 0, 256, 256);
570 SkPictureRecorder recorder
;
571 SkCanvas
* canvas
= StartRecording(&recorder
, layer_rect
);
573 TestDiscardableShader first_shader
;
575 first_paint
.setShader(&first_shader
);
578 points
[0].set(10, 50);
579 points
[1].set(20, 50);
580 points
[2].set(30, 50);
581 points
[3].set(40, 50);
590 canvas
->drawText("text", 4, 50, 50, first_paint
);
591 canvas
->drawPosText("text", 4, points
, first_paint
);
592 canvas
->drawTextOnPath("text", 4, path
, NULL
, first_paint
);
594 skia::RefPtr
<SkPicture
> picture
=
595 skia::AdoptRef(StopRecording(&recorder
, canvas
));
597 std::vector
<skia::PixelRefUtils::PositionPixelRef
> pixel_refs
;
598 skia::PixelRefUtils::GatherDiscardablePixelRefs(picture
.get(), &pixel_refs
);
600 EXPECT_EQ(3u, pixel_refs
.size());
603 TEST(PixelRefUtilsTest
, DrawVertices
) {
604 gfx::Rect
layer_rect(0, 0, 256, 256);
606 SkPictureRecorder recorder
;
607 SkCanvas
* canvas
= StartRecording(&recorder
, layer_rect
);
609 TestDiscardableShader first_shader
;
611 first_paint
.setShader(&first_shader
);
613 TestDiscardableShader second_shader
;
614 SkPaint second_paint
;
615 second_paint
.setShader(&second_shader
);
617 TestDiscardableShader third_shader
;
619 third_paint
.setShader(&third_shader
);
623 uint16_t indecies
[3] = {0, 1, 2};
624 points
[0].set(10, 10);
625 points
[1].set(100, 20);
626 points
[2].set(50, 100);
628 canvas
->drawVertices(SkCanvas::kTriangles_VertexMode
,
640 canvas
->clipRect(SkRect::MakeWH(50, 50));
642 canvas
->drawVertices(SkCanvas::kTriangles_VertexMode
,
654 points
[0].set(50, 55);
655 points
[1].set(50, 55);
656 points
[2].set(200, 200);
657 // (50, 55, 150, 145).
658 canvas
->drawVertices(SkCanvas::kTriangles_VertexMode
,
668 skia::RefPtr
<SkPicture
> picture
=
669 skia::AdoptRef(StopRecording(&recorder
, canvas
));
671 std::vector
<skia::PixelRefUtils::PositionPixelRef
> pixel_refs
;
672 skia::PixelRefUtils::GatherDiscardablePixelRefs(picture
.get(), &pixel_refs
);
674 EXPECT_EQ(3u, pixel_refs
.size());
675 EXPECT_FLOAT_RECT_EQ(gfx::RectF(10, 10, 90, 90),
676 gfx::SkRectToRectF(pixel_refs
[0].pixel_ref_rect
));
677 EXPECT_FLOAT_RECT_EQ(gfx::RectF(10, 10, 40, 40),
678 gfx::SkRectToRectF(pixel_refs
[1].pixel_ref_rect
));
679 EXPECT_FLOAT_RECT_EQ(gfx::RectF(50, 55, 150, 145),
680 gfx::SkRectToRectF(pixel_refs
[2].pixel_ref_rect
));