blob: 999028c7ec81ddfdf58d99fc0c74863324dad361 [file] [log] [blame]
robertphillips@google.comdd3f3652013-05-14 16:37:31 +00001/*
2 * Copyright 2013 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
10namespace skiagm {
11
12// Draw various width thin rects at 1/8 horizontal pixel increments
13class ThinRectsGM : public GM {
14public:
15 ThinRectsGM() {
16 this->setBGColor(0xFF000000);
17 }
18
19protected:
mtklein36352bf2015-03-25 18:17:31 -070020 SkString onShortName() override {
robertphillips@google.comdd3f3652013-05-14 16:37:31 +000021 return SkString("thinrects");
22 }
23
mtklein36352bf2015-03-25 18:17:31 -070024 SkISize onISize() override {
tfarinaf5393182014-06-09 23:59:03 -070025 return SkISize::Make(240, 320);
robertphillips@google.comdd3f3652013-05-14 16:37:31 +000026 }
27
mtklein36352bf2015-03-25 18:17:31 -070028 void onDraw(SkCanvas* canvas) override {
robertphillips@google.comdd3f3652013-05-14 16:37:31 +000029
30 SkPaint white;
31 white.setColor(SK_ColorWHITE);
32 white.setAntiAlias(true);
33
34 SkPaint green;
35 green.setColor(SK_ColorGREEN);
36 green.setAntiAlias(true);
37
38 for (int i = 0; i < 8; ++i) {
39 canvas->save();
40 canvas->translate(i*0.125f, i*40.0f);
41 DrawVertRects(canvas, white);
42
43 canvas->translate(40.0f, 0.0f);
44 DrawVertRects(canvas, green);
45 canvas->restore();
46
47 canvas->save();
48 canvas->translate(80.0f, i*40.0f + i*0.125f);
49 DrawHorizRects(canvas, white);
50
51 canvas->translate(40.0f, 0.0f);
52 DrawHorizRects(canvas, green);
53 canvas->restore();
54
55 canvas->save();
skia.committer@gmail.comeafdf122013-05-15 07:01:09 +000056 canvas->translate(160.0f + i*0.125f,
robertphillips@google.comdd3f3652013-05-14 16:37:31 +000057 i*40.0f + i*0.125f);
58 DrawSquares(canvas, white);
59
60 canvas->translate(40.0f, 0.0f);
61 DrawSquares(canvas, green);
62 canvas->restore();
63 }
64 }
65
66private:
67 static void DrawVertRects(SkCanvas* canvas, const SkPaint& p) {
mtkleindbfd7ab2016-09-01 11:24:54 -070068 constexpr SkRect vertRects[] = {
robertphillips@google.comdd3f3652013-05-14 16:37:31 +000069 { 1, 1, 5.0f, 21 }, // 4 pix wide
70 { 8, 1, 10.0f, 21 }, // 2 pix wide
71 { 13, 1, 14.0f, 21 }, // 1 pix wide
72 { 17, 1, 17.5f, 21 }, // 1/2 pix wide
73 { 21, 1, 21.25f, 21 }, // 1/4 pix wide
74 { 25, 1, 25.125f, 21 }, // 1/8 pix wide
75 { 29, 1, 29.0f, 21 } // 0 pix wide
76 };
77
robertphillips@google.com1a095192013-05-14 16:43:02 +000078 for (size_t j = 0; j < SK_ARRAY_COUNT(vertRects); ++j) {
robertphillips@google.comdd3f3652013-05-14 16:37:31 +000079 canvas->drawRect(vertRects[j], p);
80 }
81 }
82
83 static void DrawHorizRects(SkCanvas* canvas, const SkPaint& p) {
mtkleindbfd7ab2016-09-01 11:24:54 -070084 constexpr SkRect horizRects[] = {
robertphillips@google.comdd3f3652013-05-14 16:37:31 +000085 { 1, 1, 21, 5.0f }, // 4 pix high
86 { 1, 8, 21, 10.0f }, // 2 pix high
87 { 1, 13, 21, 14.0f }, // 1 pix high
88 { 1, 17, 21, 17.5f }, // 1/2 pix high
89 { 1, 21, 21, 21.25f }, // 1/4 pix high
90 { 1, 25, 21, 25.125f }, // 1/8 pix high
91 { 1, 29, 21, 29.0f } // 0 pix high
92 };
93
robertphillips@google.com1a095192013-05-14 16:43:02 +000094 for (size_t j = 0; j < SK_ARRAY_COUNT(horizRects); ++j) {
robertphillips@google.comdd3f3652013-05-14 16:37:31 +000095 canvas->drawRect(horizRects[j], p);
96 }
97 }
98
99 static void DrawSquares(SkCanvas* canvas, const SkPaint& p) {
mtkleindbfd7ab2016-09-01 11:24:54 -0700100 constexpr SkRect squares[] = {
robertphillips@google.comdd3f3652013-05-14 16:37:31 +0000101 { 1, 1, 5.0f, 5.0f }, // 4 pix
102 { 8, 8, 10.0f, 10.0f }, // 2 pix
103 { 13, 13, 14.0f, 14.0f }, // 1 pix
104 { 17, 17, 17.5f, 17.5f }, // 1/2 pix
105 { 21, 21, 21.25f, 21.25f }, // 1/4 pix
106 { 25, 25, 25.125f, 25.125f }, // 1/8 pix
107 { 29, 29, 29.0f, 29.0f } // 0 pix
108 };
109
robertphillips@google.com1a095192013-05-14 16:43:02 +0000110 for (size_t j = 0; j < SK_ARRAY_COUNT(squares); ++j) {
robertphillips@google.comdd3f3652013-05-14 16:37:31 +0000111 canvas->drawRect(squares[j], p);
112 }
113 }
114
115 typedef GM INHERITED;
116};
117
118//////////////////////////////////////////////////////////////////////////////
119
120static GM* MyFactory(void*) { return new ThinRectsGM; }
121static GMRegistry reg(MyFactory);
122
123}