blob: eda31210a3e1e56254554457b496d0c61b7359d7 [file] [log] [blame]
epoger@google.comec3ed6a2011-07-28 14:26:00 +00001
2/*
3 * Copyright 2011 Google Inc.
4 *
5 * Use of this source code is governed by a BSD-style license that can be
6 * found in the LICENSE file.
7 */
reed@google.coma965a152011-02-17 15:06:52 +00008#include "gm.h"
9#include "SkRandom.h"
10
11namespace skiagm {
12
13class PointsGM : public GM {
14public:
rmistry@google.comae933ce2012-08-23 18:19:56 +000015 PointsGM() {}
reed@google.coma965a152011-02-17 15:06:52 +000016
17protected:
commit-bot@chromium.orga90c6802014-04-30 13:20:45 +000018
mtklein36352bf2015-03-25 18:17:31 -070019 SkString onShortName() override {
reed@google.coma965a152011-02-17 15:06:52 +000020 return SkString("points");
21 }
22
mtklein36352bf2015-03-25 18:17:31 -070023 SkISize onISize() override {
tfarinaf5393182014-06-09 23:59:03 -070024 return SkISize::Make(640, 490);
reed@google.coma965a152011-02-17 15:06:52 +000025 }
26
scroggof9d61012014-12-15 12:54:51 -080027 static void fill_pts(SkPoint pts[], size_t n, SkRandom* rand) {
epoger@google.com17b78942011-08-26 14:40:38 +000028 for (size_t i = 0; i < n; i++) {
29 // Compute these independently and store in variables, rather
30 // than in the parameter-passing expression, to get consistent
31 // evaluation order across compilers.
bsalomon@google.com72e49b82011-10-27 21:47:03 +000032 SkScalar y = rand->nextUScalar1() * 480;
33 SkScalar x = rand->nextUScalar1() * 640;
epoger@google.com17b78942011-08-26 14:40:38 +000034 pts[i].set(x, y);
35 }
reed@google.coma965a152011-02-17 15:06:52 +000036 }
37
mtklein36352bf2015-03-25 18:17:31 -070038 void onDraw(SkCanvas* canvas) override {
reed@google.coma965a152011-02-17 15:06:52 +000039 canvas->translate(SK_Scalar1, SK_Scalar1);
40
scroggof9d61012014-12-15 12:54:51 -080041 SkRandom rand;
reed@google.coma965a152011-02-17 15:06:52 +000042 SkPaint p0, p1, p2, p3;
43 const size_t n = 99;
44
45 p0.setColor(SK_ColorRED);
46 p1.setColor(SK_ColorGREEN);
47 p2.setColor(SK_ColorBLUE);
48 p3.setColor(SK_ColorWHITE);
49
50 p0.setStrokeWidth(SkIntToScalar(4));
51 p2.setStrokeCap(SkPaint::kRound_Cap);
52 p2.setStrokeWidth(SkIntToScalar(6));
53
54 SkPoint* pts = new SkPoint[n];
55 fill_pts(pts, n, &rand);
56
57 canvas->drawPoints(SkCanvas::kPolygon_PointMode, n, pts, p0);
58 canvas->drawPoints(SkCanvas::kLines_PointMode, n, pts, p1);
59 canvas->drawPoints(SkCanvas::kPoints_PointMode, n, pts, p2);
60 canvas->drawPoints(SkCanvas::kPoints_PointMode, n, pts, p3);
61
62 delete[] pts;
63 }
64
65private:
66 typedef GM INHERITED;
67};
68
69//////////////////////////////////////////////////////////////////////////////
70
71static GM* MyFactory(void*) { return new PointsGM; }
72static GMRegistry reg(MyFactory);
73
74}