blob: c583d64a45935ebb3801eca6e7ea5559b4a5b9de [file] [log] [blame]
reed@google.com4117a242012-10-30 20:26:58 +00001/*
2 * Copyright 2012 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
8#include "gm.h"
9#include "SkCanvas.h"
10#include "SkPath.h"
11#include "SkSurface.h"
12
13#define ZOOM 32
14#define SMALL_W 9
15#define SMALL_H 3
16#define REPEAT_LOOP 5
17
18static SkSurface* new_surface(int width, int height) {
19 SkImage::Info info = {
20 width,
21 height,
22 SkImage::kPMColor_ColorType,
23 SkImage::kPremul_AlphaType
24 };
mike@reedtribe.orgb9476252012-11-15 02:37:45 +000025 return SkSurface::NewRaster(info);
reed@google.com4117a242012-10-30 20:26:58 +000026}
27
28static void draw_pixel_centers(SkCanvas* canvas) {
29 SkPaint paint;
30 paint.setColor(0xFF0088FF);
31 paint.setAntiAlias(true);
skia.committer@gmail.come862d162012-10-31 02:01:18 +000032
reed@google.com4117a242012-10-30 20:26:58 +000033 for (int y = 0; y < SMALL_H; ++y) {
34 for (int x = 0; x < SMALL_W; ++x) {
35 canvas->drawCircle(x + 0.5f, y + 0.5f, 1.5f / ZOOM, paint);
36 }
37 }
38}
39
40static void draw_fatpath(SkCanvas* canvas, SkSurface* surface,
41 const SkPath paths[], int count) {
42 SkPaint paint;
43
44 surface->getCanvas()->clear(0);
45 for (int i = 0; i < count; ++i) {
46 surface->getCanvas()->drawPath(paths[i], paint);
47 }
48 surface->draw(canvas, 0, 0, NULL);
49
50 paint.setAntiAlias(true);
51 paint.setColor(SK_ColorRED);
52 paint.setStyle(SkPaint::kStroke_Style);
53 for (int j = 0; j < count; ++j) {
54 canvas->drawPath(paths[j], paint);
55 }
56
57 draw_pixel_centers(canvas);
58}
59
60class FatPathFillGM : public skiagm::GM {
61public:
62 FatPathFillGM() {}
63
64protected:
65 virtual SkString onShortName() {
66 return SkString("fatpathfill");
67 }
68
69 virtual SkISize onISize() {
70 return SkISize::Make(SMALL_W * ZOOM, SMALL_H * ZOOM * REPEAT_LOOP);
71 }
72
73 virtual void onDraw(SkCanvas* canvas) {
74 SkAutoTUnref<SkSurface> surface(new_surface(SMALL_W, SMALL_H));
75
76 canvas->scale(ZOOM, ZOOM);
77
78 SkPaint paint;
79 paint.setStyle(SkPaint::kStroke_Style);
80 paint.setStrokeWidth(SK_Scalar1);
81
82 for (int i = 0; i < REPEAT_LOOP; ++i) {
83 SkPath line, path;
robertphillips@google.com93f03322012-12-03 17:35:19 +000084 line.moveTo(SkIntToScalar(1), SkIntToScalar(2));
85 line.lineTo(SkIntToScalar(4 + i), SkIntToScalar(1));
reed@google.com4117a242012-10-30 20:26:58 +000086 paint.getFillPath(line, &path);
87 draw_fatpath(canvas, surface, &path, 1);
skia.committer@gmail.come862d162012-10-31 02:01:18 +000088
reed@google.com4117a242012-10-30 20:26:58 +000089 canvas->translate(0, SMALL_H);
90 }
91 }
92
93private:
94 typedef skiagm::GM INHERITED;
95};
96
97///////////////////////////////////////////////////////////////////////////////
98
99DEF_GM(return new FatPathFillGM;)
100