Move action_runner.py out of actions folder prior to moving actions to internal.
[chromium-blink-merge.git] / skia / ext / pixel_ref_utils_unittest.cc
blob50aa40d5619300eb23439fa46d524ff38c9ea7cf
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"
21 namespace skia {
23 namespace {
25 void CreateBitmap(gfx::Size size, const char* uri, SkBitmap* bitmap);
27 class TestDiscardableShader : public SkShader {
28 public:
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,
38 SkMatrix* matrix,
39 TileMode xy[2]) const override {
40 if (bitmap)
41 *bitmap = bitmap_;
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
52 // leap yet.
53 private:
54 static SkFlattenable* CreateProc(SkReadBuffer&);
55 friend class SkPrivateEffectInitializer;
57 public:
58 Factory getFactory() const override { return CreateProc; }
60 private:
61 SkBitmap bitmap_;
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) {
75 SkCanvas* canvas =
76 recorder->beginRecording(layer_rect.width(), layer_rect.height());
78 canvas->save();
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()));
83 return canvas;
86 SkPicture* StopRecording(SkPictureRecorder* recorder, SkCanvas* canvas) {
87 canvas->restore();
88 return recorder->endRecording();
91 } // namespace
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;
100 SkPaint first_paint;
101 first_paint.setShader(&first_shader);
103 TestDiscardableShader second_shader;
104 SkPaint second_paint;
105 second_paint.setShader(&second_shader);
107 TestDiscardableShader third_shader;
108 SkPaint third_paint;
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;
139 SkPaint first_paint;
140 first_paint.setShader(&first_shader);
142 TestDiscardableShader second_shader;
143 SkPaint second_paint;
144 second_paint.setShader(&second_shader);
146 TestDiscardableShader third_shader;
147 SkPaint third_paint;
148 third_paint.setShader(&third_shader);
150 SkPoint points[3];
151 points[0].set(10, 10);
152 points[1].set(100, 20);
153 points[2].set(50, 100);
154 // (10, 10, 90, 90).
155 canvas->drawPoints(SkCanvas::kPolygon_PointMode, 3, points, first_paint);
157 canvas->save();
159 canvas->clipRect(SkRect::MakeWH(50, 50));
160 // (10, 10, 40, 40).
161 canvas->drawPoints(SkCanvas::kPolygon_PointMode, 3, points, second_paint);
163 canvas->restore();
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;
192 SkPaint first_paint;
193 first_paint.setShader(&first_shader);
195 TestDiscardableShader second_shader;
196 SkPaint second_paint;
197 second_paint.setShader(&second_shader);
199 TestDiscardableShader third_shader;
200 SkPaint third_paint;
201 third_paint.setShader(&third_shader);
203 // (10, 20, 30, 40).
204 canvas->drawRect(SkRect::MakeXYWH(10, 20, 30, 40), first_paint);
206 canvas->save();
208 canvas->translate(5, 17);
209 // (5, 50, 25, 35)
210 canvas->drawRect(SkRect::MakeXYWH(0, 33, 25, 35), second_paint);
212 canvas->restore();
214 canvas->clipRect(SkRect::MakeXYWH(50, 50, 50, 50));
215 canvas->translate(20, 20);
216 // (50, 50, 50, 50)
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;
240 SkPaint first_paint;
241 first_paint.setShader(&first_shader);
243 TestDiscardableShader second_shader;
244 SkPaint second_paint;
245 second_paint.setShader(&second_shader);
247 TestDiscardableShader third_shader;
248 SkPaint third_paint;
249 third_paint.setShader(&third_shader);
251 SkRRect rrect;
252 rrect.setRect(SkRect::MakeXYWH(10, 20, 30, 40));
254 // (10, 20, 30, 40).
255 canvas->drawRRect(rrect, first_paint);
257 canvas->save();
259 canvas->translate(5, 17);
260 rrect.setRect(SkRect::MakeXYWH(0, 33, 25, 35));
261 // (5, 50, 25, 35)
262 canvas->drawRRect(rrect, second_paint);
264 canvas->restore();
266 canvas->clipRect(SkRect::MakeXYWH(50, 50, 50, 50));
267 canvas->translate(20, 20);
268 rrect.setRect(SkRect::MakeXYWH(0, 0, 100, 100));
269 // (50, 50, 50, 50)
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;
293 SkPaint first_paint;
294 first_paint.setShader(&first_shader);
296 TestDiscardableShader second_shader;
297 SkPaint second_paint;
298 second_paint.setShader(&second_shader);
300 TestDiscardableShader third_shader;
301 SkPaint third_paint;
302 third_paint.setShader(&third_shader);
304 canvas->save();
306 canvas->scale(2, 0.5);
307 // (20, 10, 60, 20).
308 canvas->drawOval(SkRect::MakeXYWH(10, 20, 30, 40), first_paint);
310 canvas->restore();
311 canvas->save();
313 canvas->translate(1, 2);
314 // (1, 35, 25, 35)
315 canvas->drawRect(SkRect::MakeXYWH(0, 33, 25, 35), second_paint);
317 canvas->restore();
319 canvas->clipRect(SkRect::MakeXYWH(50, 50, 50, 50));
320 canvas->translate(20, 20);
321 // (50, 50, 50, 50)
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;
345 SkPaint first_paint;
346 first_paint.setShader(&first_shader);
348 TestDiscardableShader second_shader;
349 SkPaint second_paint;
350 second_paint.setShader(&second_shader);
352 SkPath path;
353 path.moveTo(12, 13);
354 path.lineTo(50, 50);
355 path.lineTo(22, 101);
357 // (12, 13, 38, 88).
358 canvas->drawPath(path, first_paint);
360 canvas->save();
361 canvas->clipRect(SkRect::MakeWH(50, 50));
363 // (12, 13, 38, 37).
364 canvas->drawPath(path, second_paint);
366 canvas->restore();
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);
386 SkBitmap first;
387 CreateBitmap(gfx::Size(50, 50), "discardable", &first);
388 SkBitmap second;
389 CreateBitmap(gfx::Size(50, 50), "discardable", &second);
390 SkBitmap third;
391 CreateBitmap(gfx::Size(50, 50), "discardable", &third);
392 SkBitmap fourth;
393 CreateBitmap(gfx::Size(50, 1), "discardable", &fourth);
394 SkBitmap fifth;
395 CreateBitmap(gfx::Size(10, 10), "discardable", &fifth);
397 canvas->save();
399 // At (0, 0).
400 canvas->drawBitmap(first, 0, 0);
401 canvas->translate(25, 0);
402 // At (25, 0).
403 canvas->drawBitmap(second, 0, 0);
404 canvas->translate(0, 50);
405 // At (50, 50).
406 canvas->drawBitmap(third, 25, 0);
408 canvas->restore();
409 canvas->save();
411 canvas->translate(1, 0);
412 canvas->rotate(90);
413 // At (1, 0), rotated 90 degrees
414 canvas->drawBitmap(fourth, 0, 0);
416 canvas->restore();
418 canvas->scale(5, 6);
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);
447 SkBitmap first;
448 CreateBitmap(gfx::Size(50, 50), "discardable", &first);
449 SkBitmap second;
450 CreateBitmap(gfx::Size(50, 50), "discardable", &second);
451 SkBitmap third;
452 CreateBitmap(gfx::Size(50, 50), "discardable", &third);
454 TestDiscardableShader first_shader;
455 SkPaint first_paint;
456 first_paint.setShader(&first_shader);
458 SkPaint non_discardable_paint;
460 canvas->save();
462 // (0, 0, 100, 100).
463 canvas->drawBitmapRect(
464 first, SkRect::MakeWH(100, 100), &non_discardable_paint);
465 canvas->translate(25, 0);
466 // (75, 50, 10, 10).
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);
474 canvas->restore();
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);
498 SkBitmap first;
499 CreateBitmap(gfx::Size(50, 50), "discardable", &first);
500 SkBitmap second;
501 CreateBitmap(gfx::Size(50, 50), "discardable", &second);
502 SkBitmap third;
503 CreateBitmap(gfx::Size(50, 50), "discardable", &third);
504 SkBitmap fourth;
505 CreateBitmap(gfx::Size(50, 50), "discardable", &fourth);
506 SkBitmap fifth;
507 CreateBitmap(gfx::Size(50, 50), "discardable", &fifth);
509 canvas->save();
511 // Sprites aren't affected by the current matrix.
513 // (0, 0, 50, 50).
514 canvas->drawSprite(first, 0, 0);
515 canvas->translate(25, 0);
516 // (10, 0, 50, 50).
517 canvas->drawSprite(second, 10, 0);
518 canvas->translate(0, 50);
519 // (25, 0, 50, 50).
520 canvas->drawSprite(third, 25, 0);
522 canvas->restore();
523 canvas->save();
525 canvas->rotate(90);
526 // (0, 0, 50, 50).
527 canvas->drawSprite(fourth, 0, 0);
529 canvas->restore();
531 TestDiscardableShader first_shader;
532 SkPaint first_paint;
533 first_paint.setShader(&first_shader);
535 canvas->scale(5, 6);
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;
566 SkPaint first_paint;
567 first_paint.setShader(&first_shader);
569 SkPoint points[4];
570 points[0].set(10, 50);
571 points[1].set(20, 50);
572 points[2].set(30, 50);
573 points[3].set(40, 50);
575 SkPath path;
576 path.moveTo(10, 50);
577 path.lineTo(20, 50);
578 path.lineTo(30, 50);
579 path.lineTo(40, 50);
580 path.lineTo(50, 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;
601 SkPaint first_paint;
602 first_paint.setShader(&first_shader);
604 TestDiscardableShader second_shader;
605 SkPaint second_paint;
606 second_paint.setShader(&second_shader);
608 TestDiscardableShader third_shader;
609 SkPaint third_paint;
610 third_paint.setShader(&third_shader);
612 SkPoint points[3];
613 SkColor colors[3];
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);
618 // (10, 10, 90, 90).
619 canvas->drawVertices(SkCanvas::kTriangles_VertexMode,
621 points,
622 points,
623 colors,
624 NULL,
625 indecies,
627 first_paint);
629 canvas->save();
631 canvas->clipRect(SkRect::MakeWH(50, 50));
632 // (10, 10, 40, 40).
633 canvas->drawVertices(SkCanvas::kTriangles_VertexMode,
635 points,
636 points,
637 colors,
638 NULL,
639 indecies,
641 second_paint);
643 canvas->restore();
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,
651 points,
652 points,
653 colors,
654 NULL,
655 indecies,
657 third_paint);
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));
673 } // namespace skia