1 // Copyright 2013 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/lazy_pixel_ref.h"
9 #include "skia/ext/lazy_pixel_ref_utils.h"
10 #include "skia/ext/refptr.h"
11 #include "testing/gtest/include/gtest/gtest.h"
12 #include "third_party/skia/include/core/SkBitmap.h"
13 #include "third_party/skia/include/core/SkCanvas.h"
14 #include "third_party/skia/include/core/SkFlattenableBuffers.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/rect.h"
19 #include "ui/gfx/skia_util.h"
25 void CreateBitmap(gfx::Size size, const char* uri, SkBitmap* bitmap);
27 class TestPixelRef : public SkPixelRef {
29 TestPixelRef(int width, int height);
30 virtual ~TestPixelRef();
32 virtual SkFlattenable::Factory getFactory() const OVERRIDE;
33 virtual void* onLockPixels(SkColorTable** color_table) OVERRIDE;
34 virtual void onUnlockPixels() OVERRIDE {}
35 virtual SkPixelRef* deepCopy(SkBitmap::Config config, const SkIRect* subset)
39 scoped_ptr<char[]> pixels_;
42 class TestLazyPixelRef : public skia::LazyPixelRef {
44 TestLazyPixelRef(int width, int height);
45 virtual ~TestLazyPixelRef();
47 virtual SkFlattenable::Factory getFactory() const OVERRIDE;
48 virtual void* onLockPixels(SkColorTable** color_table) OVERRIDE;
49 virtual void onUnlockPixels() OVERRIDE {}
50 virtual bool PrepareToDecode(const PrepareParams& params) OVERRIDE;
51 virtual bool MaybeDecoded() OVERRIDE;
52 virtual SkPixelRef* deepCopy(SkBitmap::Config config, const SkIRect* subset)
54 virtual void Decode() OVERRIDE {}
57 scoped_ptr<char[]> pixels_;
60 class TestLazyShader : public SkShader {
62 TestLazyShader() { CreateBitmap(gfx::Size(50, 50), "lazy", &bitmap_); }
64 TestLazyShader(SkFlattenableReadBuffer& flattenable_buffer) {
65 SkOrderedReadBuffer& buffer =
66 static_cast<SkOrderedReadBuffer&>(flattenable_buffer);
67 SkReader32* reader = buffer.getReader32();
70 uint32_t toSkip = reader->readU32();
73 CreateBitmap(gfx::Size(50, 50), "lazy", &bitmap_);
76 virtual SkShader::BitmapType asABitmap(SkBitmap* bitmap,
78 TileMode xy[2]) const OVERRIDE {
81 return SkShader::kDefault_BitmapType;
84 // Pure virtual implementaiton.
85 virtual void shadeSpan(int x, int y, SkPMColor[], int count) OVERRIDE {}
86 SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(TestLazyShader);
92 TestPixelRef::TestPixelRef(int width, int height)
93 : pixels_(new char[4 * width * height]) {}
95 TestPixelRef::~TestPixelRef() {}
97 SkFlattenable::Factory TestPixelRef::getFactory() const { return NULL; }
99 void* TestPixelRef::onLockPixels(SkColorTable** color_table) {
100 return pixels_.get();
103 SkPixelRef* TestPixelRef::deepCopy(SkBitmap::Config config,
104 const SkIRect* subset) {
109 TestLazyPixelRef::TestLazyPixelRef(int width, int height)
110 : pixels_(new char[4 * width * height]) {}
112 TestLazyPixelRef::~TestLazyPixelRef() {}
114 SkFlattenable::Factory TestLazyPixelRef::getFactory() const { return NULL; }
116 void* TestLazyPixelRef::onLockPixels(SkColorTable** color_table) {
117 return pixels_.get();
120 bool TestLazyPixelRef::PrepareToDecode(const PrepareParams& params) {
124 bool TestLazyPixelRef::MaybeDecoded() {
128 SkPixelRef* TestLazyPixelRef::deepCopy(SkBitmap::Config config,
129 const SkIRect* subset) {
134 void CreateBitmap(gfx::Size size, const char* uri, SkBitmap* bitmap) {
135 skia::RefPtr<TestLazyPixelRef> lazy_pixel_ref =
136 skia::AdoptRef(new TestLazyPixelRef(size.width(), size.height()));
137 lazy_pixel_ref->setURI(uri);
139 bitmap->setConfig(SkBitmap::kARGB_8888_Config, size.width(), size.height());
140 bitmap->setPixelRef(lazy_pixel_ref.get());
143 SkCanvas* StartRecording(SkPicture* picture, gfx::Rect layer_rect) {
144 SkCanvas* canvas = picture->beginRecording(
147 SkPicture::kUsePathBoundsForClip_RecordingFlag |
148 SkPicture::kOptimizeForClippedPlayback_RecordingFlag);
151 canvas->translate(-layer_rect.x(), -layer_rect.y());
152 canvas->clipRect(SkRect::MakeXYWH(
153 layer_rect.x(), layer_rect.y(), layer_rect.width(), layer_rect.height()));
158 void StopRecording(SkPicture* picture, SkCanvas* canvas) {
160 picture->endRecording();
165 TEST(LazyPixelRefUtilsTest, DrawPaint) {
166 gfx::Rect layer_rect(0, 0, 256, 256);
168 skia::RefPtr<SkPicture> picture = skia::AdoptRef(new SkPicture);
169 SkCanvas* canvas = StartRecording(picture.get(), layer_rect);
171 TestLazyShader first_shader;
173 first_paint.setShader(&first_shader);
175 TestLazyShader second_shader;
176 SkPaint second_paint;
177 second_paint.setShader(&second_shader);
179 TestLazyShader third_shader;
181 third_paint.setShader(&third_shader);
183 canvas->drawPaint(first_paint);
184 canvas->clipRect(SkRect::MakeXYWH(34, 45, 56, 67));
185 canvas->drawPaint(second_paint);
186 // Total clip is now (34, 45, 56, 55)
187 canvas->clipRect(SkRect::MakeWH(100, 100));
188 canvas->drawPaint(third_paint);
190 StopRecording(picture.get(), canvas);
192 std::vector<skia::LazyPixelRefUtils::PositionLazyPixelRef> pixel_refs;
193 skia::LazyPixelRefUtils::GatherPixelRefs(picture.get(), &pixel_refs);
195 EXPECT_EQ(3u, pixel_refs.size());
196 EXPECT_FLOAT_RECT_EQ(gfx::RectF(0, 0, 256, 256),
197 gfx::SkRectToRectF(pixel_refs[0].pixel_ref_rect));
198 EXPECT_FLOAT_RECT_EQ(gfx::RectF(34, 45, 56, 67),
199 gfx::SkRectToRectF(pixel_refs[1].pixel_ref_rect));
200 EXPECT_FLOAT_RECT_EQ(gfx::RectF(34, 45, 56, 55),
201 gfx::SkRectToRectF(pixel_refs[2].pixel_ref_rect));
204 TEST(LazyPixelRefUtilsTest, DrawPoints) {
205 gfx::Rect layer_rect(0, 0, 256, 256);
207 skia::RefPtr<SkPicture> picture = skia::AdoptRef(new SkPicture);
208 SkCanvas* canvas = StartRecording(picture.get(), layer_rect);
210 TestLazyShader first_shader;
212 first_paint.setShader(&first_shader);
214 TestLazyShader second_shader;
215 SkPaint second_paint;
216 second_paint.setShader(&second_shader);
218 TestLazyShader third_shader;
220 third_paint.setShader(&third_shader);
223 points[0].set(10, 10);
224 points[1].set(100, 20);
225 points[2].set(50, 100);
227 canvas->drawPoints(SkCanvas::kPolygon_PointMode, 3, points, first_paint);
231 canvas->clipRect(SkRect::MakeWH(50, 50));
233 canvas->drawPoints(SkCanvas::kPolygon_PointMode, 3, points, second_paint);
237 points[0].set(50, 55);
238 points[1].set(50, 55);
239 points[2].set(200, 200);
240 // (50, 55, 150, 145).
241 canvas->drawPoints(SkCanvas::kPolygon_PointMode, 3, points, third_paint);
243 StopRecording(picture.get(), canvas);
245 std::vector<skia::LazyPixelRefUtils::PositionLazyPixelRef> pixel_refs;
246 skia::LazyPixelRefUtils::GatherPixelRefs(picture.get(), &pixel_refs);
248 EXPECT_EQ(3u, pixel_refs.size());
249 EXPECT_FLOAT_RECT_EQ(gfx::RectF(10, 10, 90, 90),
250 gfx::SkRectToRectF(pixel_refs[0].pixel_ref_rect));
251 EXPECT_FLOAT_RECT_EQ(gfx::RectF(10, 10, 40, 40),
252 gfx::SkRectToRectF(pixel_refs[1].pixel_ref_rect));
253 EXPECT_FLOAT_RECT_EQ(gfx::RectF(50, 55, 150, 145),
254 gfx::SkRectToRectF(pixel_refs[2].pixel_ref_rect));
257 TEST(LazyPixelRefUtilsTest, DrawRect) {
258 gfx::Rect layer_rect(0, 0, 256, 256);
260 skia::RefPtr<SkPicture> picture = skia::AdoptRef(new SkPicture);
261 SkCanvas* canvas = StartRecording(picture.get(), layer_rect);
263 TestLazyShader first_shader;
265 first_paint.setShader(&first_shader);
267 TestLazyShader second_shader;
268 SkPaint second_paint;
269 second_paint.setShader(&second_shader);
271 TestLazyShader third_shader;
273 third_paint.setShader(&third_shader);
276 canvas->drawRect(SkRect::MakeXYWH(10, 20, 30, 40), first_paint);
280 canvas->translate(5, 17);
282 canvas->drawRect(SkRect::MakeXYWH(0, 33, 25, 35), second_paint);
286 canvas->clipRect(SkRect::MakeXYWH(50, 50, 50, 50));
287 canvas->translate(20, 20);
289 canvas->drawRect(SkRect::MakeXYWH(0, 0, 100, 100), third_paint);
291 std::vector<skia::LazyPixelRefUtils::PositionLazyPixelRef> pixel_refs;
292 skia::LazyPixelRefUtils::GatherPixelRefs(picture.get(), &pixel_refs);
294 EXPECT_EQ(3u, pixel_refs.size());
295 EXPECT_FLOAT_RECT_EQ(gfx::RectF(10, 20, 30, 40),
296 gfx::SkRectToRectF(pixel_refs[0].pixel_ref_rect));
297 EXPECT_FLOAT_RECT_EQ(gfx::RectF(5, 50, 25, 35),
298 gfx::SkRectToRectF(pixel_refs[1].pixel_ref_rect));
299 EXPECT_FLOAT_RECT_EQ(gfx::RectF(50, 50, 50, 50),
300 gfx::SkRectToRectF(pixel_refs[2].pixel_ref_rect));
303 TEST(LazyPixelRefUtilsTest, DrawRRect) {
304 gfx::Rect layer_rect(0, 0, 256, 256);
306 skia::RefPtr<SkPicture> picture = skia::AdoptRef(new SkPicture);
307 SkCanvas* canvas = StartRecording(picture.get(), layer_rect);
309 TestLazyShader first_shader;
311 first_paint.setShader(&first_shader);
313 TestLazyShader second_shader;
314 SkPaint second_paint;
315 second_paint.setShader(&second_shader);
317 TestLazyShader third_shader;
319 third_paint.setShader(&third_shader);
322 rrect.setRect(SkRect::MakeXYWH(10, 20, 30, 40));
325 canvas->drawRRect(rrect, first_paint);
329 canvas->translate(5, 17);
330 rrect.setRect(SkRect::MakeXYWH(0, 33, 25, 35));
332 canvas->drawRRect(rrect, second_paint);
336 canvas->clipRect(SkRect::MakeXYWH(50, 50, 50, 50));
337 canvas->translate(20, 20);
338 rrect.setRect(SkRect::MakeXYWH(0, 0, 100, 100));
340 canvas->drawRRect(rrect, third_paint);
342 std::vector<skia::LazyPixelRefUtils::PositionLazyPixelRef> pixel_refs;
343 skia::LazyPixelRefUtils::GatherPixelRefs(picture.get(), &pixel_refs);
345 EXPECT_EQ(3u, pixel_refs.size());
346 EXPECT_FLOAT_RECT_EQ(gfx::RectF(10, 20, 30, 40),
347 gfx::SkRectToRectF(pixel_refs[0].pixel_ref_rect));
348 EXPECT_FLOAT_RECT_EQ(gfx::RectF(5, 50, 25, 35),
349 gfx::SkRectToRectF(pixel_refs[1].pixel_ref_rect));
350 EXPECT_FLOAT_RECT_EQ(gfx::RectF(50, 50, 50, 50),
351 gfx::SkRectToRectF(pixel_refs[2].pixel_ref_rect));
354 TEST(LazyPixelRefUtilsTest, DrawOval) {
355 gfx::Rect layer_rect(0, 0, 256, 256);
357 skia::RefPtr<SkPicture> picture = skia::AdoptRef(new SkPicture);
358 SkCanvas* canvas = StartRecording(picture.get(), layer_rect);
360 TestLazyShader first_shader;
362 first_paint.setShader(&first_shader);
364 TestLazyShader second_shader;
365 SkPaint second_paint;
366 second_paint.setShader(&second_shader);
368 TestLazyShader third_shader;
370 third_paint.setShader(&third_shader);
374 canvas->scale(2, 0.5);
376 canvas->drawOval(SkRect::MakeXYWH(10, 20, 30, 40), first_paint);
381 canvas->translate(1, 2);
383 canvas->drawRect(SkRect::MakeXYWH(0, 33, 25, 35), second_paint);
387 canvas->clipRect(SkRect::MakeXYWH(50, 50, 50, 50));
388 canvas->translate(20, 20);
390 canvas->drawRect(SkRect::MakeXYWH(0, 0, 100, 100), third_paint);
392 std::vector<skia::LazyPixelRefUtils::PositionLazyPixelRef> pixel_refs;
393 skia::LazyPixelRefUtils::GatherPixelRefs(picture.get(), &pixel_refs);
395 EXPECT_EQ(3u, pixel_refs.size());
396 EXPECT_FLOAT_RECT_EQ(gfx::RectF(20, 10, 60, 20),
397 gfx::SkRectToRectF(pixel_refs[0].pixel_ref_rect));
398 EXPECT_FLOAT_RECT_EQ(gfx::RectF(1, 35, 25, 35),
399 gfx::SkRectToRectF(pixel_refs[1].pixel_ref_rect));
400 EXPECT_FLOAT_RECT_EQ(gfx::RectF(50, 50, 50, 50),
401 gfx::SkRectToRectF(pixel_refs[2].pixel_ref_rect));
404 TEST(LazyPixelRefUtilsTest, DrawPath) {
405 gfx::Rect layer_rect(0, 0, 256, 256);
407 skia::RefPtr<SkPicture> picture = skia::AdoptRef(new SkPicture);
408 SkCanvas* canvas = StartRecording(picture.get(), layer_rect);
410 TestLazyShader first_shader;
412 first_paint.setShader(&first_shader);
414 TestLazyShader second_shader;
415 SkPaint second_paint;
416 second_paint.setShader(&second_shader);
421 path.lineTo(22, 101);
424 canvas->drawPath(path, first_paint);
427 canvas->clipRect(SkRect::MakeWH(50, 50));
430 canvas->drawPath(path, second_paint);
434 StopRecording(picture.get(), canvas);
436 std::vector<skia::LazyPixelRefUtils::PositionLazyPixelRef> pixel_refs;
437 skia::LazyPixelRefUtils::GatherPixelRefs(picture.get(), &pixel_refs);
439 EXPECT_EQ(2u, pixel_refs.size());
440 EXPECT_FLOAT_RECT_EQ(gfx::RectF(12, 13, 38, 88),
441 gfx::SkRectToRectF(pixel_refs[0].pixel_ref_rect));
442 EXPECT_FLOAT_RECT_EQ(gfx::RectF(12, 13, 38, 37),
443 gfx::SkRectToRectF(pixel_refs[1].pixel_ref_rect));
446 TEST(LazyPixelRefUtilsTest, DrawBitmap) {
447 gfx::Rect layer_rect(0, 0, 256, 256);
449 skia::RefPtr<SkPicture> picture = skia::AdoptRef(new SkPicture);
450 SkCanvas* canvas = StartRecording(picture.get(), layer_rect);
453 CreateBitmap(gfx::Size(50, 50), "lazy", &first);
455 CreateBitmap(gfx::Size(50, 50), "lazy", &second);
457 CreateBitmap(gfx::Size(50, 50), "lazy", &third);
459 CreateBitmap(gfx::Size(50, 1), "lazy", &fourth);
461 CreateBitmap(gfx::Size(10, 10), "lazy", &fifth);
466 canvas->drawBitmap(first, 0, 0);
467 canvas->translate(25, 0);
469 canvas->drawBitmap(second, 0, 0);
470 canvas->translate(0, 50);
472 canvas->drawBitmap(third, 25, 0);
477 canvas->translate(1, 0);
479 // At (1, 0), rotated 90 degrees
480 canvas->drawBitmap(fourth, 0, 0);
485 // At (0, 0), scaled by 5 and 6
486 canvas->drawBitmap(fifth, 0, 0);
488 StopRecording(picture.get(), canvas);
490 std::vector<skia::LazyPixelRefUtils::PositionLazyPixelRef> pixel_refs;
491 skia::LazyPixelRefUtils::GatherPixelRefs(picture.get(), &pixel_refs);
493 EXPECT_EQ(5u, pixel_refs.size());
494 EXPECT_FLOAT_RECT_EQ(gfx::RectF(0, 0, 50, 50),
495 gfx::SkRectToRectF(pixel_refs[0].pixel_ref_rect));
496 EXPECT_FLOAT_RECT_EQ(gfx::RectF(25, 0, 50, 50),
497 gfx::SkRectToRectF(pixel_refs[1].pixel_ref_rect));
498 EXPECT_FLOAT_RECT_EQ(gfx::RectF(50, 50, 50, 50),
499 gfx::SkRectToRectF(pixel_refs[2].pixel_ref_rect));
500 EXPECT_FLOAT_RECT_EQ(gfx::RectF(0, 0, 1, 50),
501 gfx::SkRectToRectF(pixel_refs[3].pixel_ref_rect));
502 EXPECT_FLOAT_RECT_EQ(gfx::RectF(0, 0, 50, 60),
503 gfx::SkRectToRectF(pixel_refs[4].pixel_ref_rect));
507 TEST(LazyPixelRefUtilsTest, DrawBitmapRect) {
508 gfx::Rect layer_rect(0, 0, 256, 256);
510 skia::RefPtr<SkPicture> picture = skia::AdoptRef(new SkPicture);
511 SkCanvas* canvas = StartRecording(picture.get(), layer_rect);
514 CreateBitmap(gfx::Size(50, 50), "lazy", &first);
516 CreateBitmap(gfx::Size(50, 50), "lazy", &second);
518 CreateBitmap(gfx::Size(50, 50), "lazy", &third);
520 TestLazyShader first_shader;
522 first_paint.setShader(&first_shader);
524 SkPaint non_lazy_paint;
529 canvas->drawBitmapRect(first, SkRect::MakeWH(100, 100), &non_lazy_paint);
530 canvas->translate(25, 0);
532 canvas->drawBitmapRect(
533 second, SkRect::MakeXYWH(50, 50, 10, 10), &non_lazy_paint);
534 canvas->translate(5, 50);
535 // (0, 30, 100, 100). One from bitmap, one from paint.
536 canvas->drawBitmapRect(
537 third, SkRect::MakeXYWH(-30, -20, 100, 100), &first_paint);
541 StopRecording(picture.get(), canvas);
543 std::vector<skia::LazyPixelRefUtils::PositionLazyPixelRef> pixel_refs;
544 skia::LazyPixelRefUtils::GatherPixelRefs(picture.get(), &pixel_refs);
546 EXPECT_EQ(4u, pixel_refs.size());
547 EXPECT_FLOAT_RECT_EQ(gfx::RectF(0, 0, 100, 100),
548 gfx::SkRectToRectF(pixel_refs[0].pixel_ref_rect));
549 EXPECT_FLOAT_RECT_EQ(gfx::RectF(75, 50, 10, 10),
550 gfx::SkRectToRectF(pixel_refs[1].pixel_ref_rect));
551 EXPECT_FLOAT_RECT_EQ(gfx::RectF(0, 30, 100, 100),
552 gfx::SkRectToRectF(pixel_refs[2].pixel_ref_rect));
553 EXPECT_FLOAT_RECT_EQ(gfx::RectF(0, 30, 100, 100),
554 gfx::SkRectToRectF(pixel_refs[3].pixel_ref_rect));
557 TEST(LazyPixelRefUtilsTest, DrawSprite) {
558 gfx::Rect layer_rect(0, 0, 256, 256);
560 skia::RefPtr<SkPicture> picture = skia::AdoptRef(new SkPicture);
561 SkCanvas* canvas = StartRecording(picture.get(), layer_rect);
564 CreateBitmap(gfx::Size(50, 50), "lazy", &first);
566 CreateBitmap(gfx::Size(50, 50), "lazy", &second);
568 CreateBitmap(gfx::Size(50, 50), "lazy", &third);
570 CreateBitmap(gfx::Size(50, 50), "lazy", &fourth);
572 CreateBitmap(gfx::Size(50, 50), "lazy", &fifth);
576 // Sprites aren't affected by the current matrix.
579 canvas->drawSprite(first, 0, 0);
580 canvas->translate(25, 0);
582 canvas->drawSprite(second, 10, 0);
583 canvas->translate(0, 50);
585 canvas->drawSprite(third, 25, 0);
592 canvas->drawSprite(fourth, 0, 0);
596 TestLazyShader first_shader;
598 first_paint.setShader(&first_shader);
601 // (100, 100, 50, 50).
602 canvas->drawSprite(fifth, 100, 100, &first_paint);
604 StopRecording(picture.get(), canvas);
606 std::vector<skia::LazyPixelRefUtils::PositionLazyPixelRef> pixel_refs;
607 skia::LazyPixelRefUtils::GatherPixelRefs(picture.get(), &pixel_refs);
609 EXPECT_EQ(6u, pixel_refs.size());
610 EXPECT_FLOAT_RECT_EQ(gfx::RectF(0, 0, 50, 50),
611 gfx::SkRectToRectF(pixel_refs[0].pixel_ref_rect));
612 EXPECT_FLOAT_RECT_EQ(gfx::RectF(10, 0, 50, 50),
613 gfx::SkRectToRectF(pixel_refs[1].pixel_ref_rect));
614 EXPECT_FLOAT_RECT_EQ(gfx::RectF(25, 0, 50, 50),
615 gfx::SkRectToRectF(pixel_refs[2].pixel_ref_rect));
616 EXPECT_FLOAT_RECT_EQ(gfx::RectF(0, 0, 50, 50),
617 gfx::SkRectToRectF(pixel_refs[3].pixel_ref_rect));
618 EXPECT_FLOAT_RECT_EQ(gfx::RectF(100, 100, 50, 50),
619 gfx::SkRectToRectF(pixel_refs[4].pixel_ref_rect));
620 EXPECT_FLOAT_RECT_EQ(gfx::RectF(100, 100, 50, 50),
621 gfx::SkRectToRectF(pixel_refs[5].pixel_ref_rect));
624 TEST(LazyPixelRefUtilsTest, DrawText) {
625 gfx::Rect layer_rect(0, 0, 256, 256);
627 skia::RefPtr<SkPicture> picture = skia::AdoptRef(new SkPicture);
628 SkCanvas* canvas = StartRecording(picture.get(), layer_rect);
630 TestLazyShader first_shader;
632 first_paint.setShader(&first_shader);
635 points[0].set(10, 50);
636 points[1].set(20, 50);
637 points[2].set(30, 50);
638 points[3].set(40, 50);
647 canvas->drawText("text", 4, 50, 50, first_paint);
648 canvas->drawPosText("text", 4, points, first_paint);
649 canvas->drawTextOnPath("text", 4, path, NULL, first_paint);
651 std::vector<skia::LazyPixelRefUtils::PositionLazyPixelRef> pixel_refs;
652 skia::LazyPixelRefUtils::GatherPixelRefs(picture.get(), &pixel_refs);
654 EXPECT_EQ(3u, pixel_refs.size());
657 TEST(LazyPixelRefUtilsTest, DrawVertices) {
658 gfx::Rect layer_rect(0, 0, 256, 256);
660 skia::RefPtr<SkPicture> picture = skia::AdoptRef(new SkPicture);
661 SkCanvas* canvas = StartRecording(picture.get(), layer_rect);
663 TestLazyShader first_shader;
665 first_paint.setShader(&first_shader);
667 TestLazyShader second_shader;
668 SkPaint second_paint;
669 second_paint.setShader(&second_shader);
671 TestLazyShader third_shader;
673 third_paint.setShader(&third_shader);
677 uint16_t indecies[3] = {0, 1, 2};
678 points[0].set(10, 10);
679 points[1].set(100, 20);
680 points[2].set(50, 100);
682 canvas->drawVertices(SkCanvas::kTriangles_VertexMode,
694 canvas->clipRect(SkRect::MakeWH(50, 50));
696 canvas->drawVertices(SkCanvas::kTriangles_VertexMode,
708 points[0].set(50, 55);
709 points[1].set(50, 55);
710 points[2].set(200, 200);
711 // (50, 55, 150, 145).
712 canvas->drawVertices(SkCanvas::kTriangles_VertexMode,
722 StopRecording(picture.get(), canvas);
724 std::vector<skia::LazyPixelRefUtils::PositionLazyPixelRef> pixel_refs;
725 skia::LazyPixelRefUtils::GatherPixelRefs(picture.get(), &pixel_refs);
727 EXPECT_EQ(3u, pixel_refs.size());
728 EXPECT_FLOAT_RECT_EQ(gfx::RectF(10, 10, 90, 90),
729 gfx::SkRectToRectF(pixel_refs[0].pixel_ref_rect));
730 EXPECT_FLOAT_RECT_EQ(gfx::RectF(10, 10, 40, 40),
731 gfx::SkRectToRectF(pixel_refs[1].pixel_ref_rect));
732 EXPECT_FLOAT_RECT_EQ(gfx::RectF(50, 55, 150, 145),
733 gfx::SkRectToRectF(pixel_refs[2].pixel_ref_rect));