Chromium Code Reviews| Index: gm/smallpaths.cpp |
| diff --git a/gm/smallpaths.cpp b/gm/smallpaths.cpp |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..2cbef3c09eef5e407fbbbc9a1616b2682d40d2a8 |
| --- /dev/null |
| +++ b/gm/smallpaths.cpp |
| @@ -0,0 +1,263 @@ |
| +/* |
|
robertphillips
2015/11/18 21:06:51
date ?
jvanverth1
2015/11/18 21:15:51
Done.
|
| + * Copyright 2011 Google Inc. |
| + * |
| + * Use of this source code is governed by a BSD-style license that can be |
| + * found in the LICENSE file. |
| + */ |
| + |
| +#include "gm.h" |
| +#include "SkPath.h" |
| + |
| +typedef SkScalar (*MakePathProc)(SkPath*); |
| + |
| +static SkScalar make_triangle(SkPath* path) { |
| + static const int gCoord[] = { |
| + 10, 20, 15, 5, 30, 30 |
| + }; |
| + path->moveTo(SkIntToScalar(gCoord[0]), SkIntToScalar(gCoord[1])); |
| + path->lineTo(SkIntToScalar(gCoord[2]), SkIntToScalar(gCoord[3])); |
| + path->lineTo(SkIntToScalar(gCoord[4]), SkIntToScalar(gCoord[5])); |
| + path->close(); |
| + path->offset(SkIntToScalar(10), SkIntToScalar(0)); |
| + return SkIntToScalar(30); |
| +} |
| + |
| +static SkScalar make_rect(SkPath* path) { |
| + SkRect r = { SkIntToScalar(10), SkIntToScalar(10), |
| + SkIntToScalar(30), SkIntToScalar(30) }; |
| + path->addRect(r); |
| + path->offset(SkIntToScalar(10), SkIntToScalar(0)); |
| + return SkIntToScalar(30); |
| +} |
| + |
| +static SkScalar make_oval(SkPath* path) { |
| + SkRect r = { SkIntToScalar(10), SkIntToScalar(10), |
| + SkIntToScalar(30), SkIntToScalar(30) }; |
| + path->addOval(r); |
| + path->offset(SkIntToScalar(10), SkIntToScalar(0)); |
| + return SkIntToScalar(30); |
| +} |
| + |
| +static SkScalar make_star(SkPath* path, int n) { |
| + const SkScalar c = SkIntToScalar(45); |
| + const SkScalar r = SkIntToScalar(20); |
| + |
| + SkScalar rad = -SK_ScalarPI / 2; |
| + const SkScalar drad = (n >> 1) * SK_ScalarPI * 2 / n; |
| + |
| + path->moveTo(c, c - r); |
| + for (int i = 1; i < n; i++) { |
| + rad += drad; |
| + SkScalar cosV, sinV = SkScalarSinCos(rad, &cosV); |
| + path->lineTo(c + SkScalarMul(cosV, r), c + SkScalarMul(sinV, r)); |
| + } |
| + path->close(); |
| + return r * 2 * 6 / 5; |
| +} |
| + |
| +static SkScalar make_star_5(SkPath* path) { return make_star(path, 5); } |
| +static SkScalar make_star_13(SkPath* path) { return make_star(path, 13); } |
| + |
| +static SkScalar make_three_line(SkPath* path) { |
| + static SkScalar xOffset = 34.f; |
| + static SkScalar yOffset = 50.f; |
| + path->moveTo(-32.5f + xOffset, 0.0f + yOffset); |
| + path->lineTo(32.5f + xOffset, 0.0f + yOffset); |
| + |
| + path->moveTo(-32.5f + xOffset, 19 + yOffset); |
| + path->lineTo(32.5f + xOffset, 19 + yOffset); |
| + |
| + path->moveTo(-32.5f + xOffset, -19 + yOffset); |
| + path->lineTo(32.5f + xOffset, -19 + yOffset); |
| + path->lineTo(-32.5f + xOffset, -19 + yOffset); |
| + |
| + path->close(); |
| + |
| + return SkIntToScalar(70); |
| +} |
| + |
| +static SkScalar make_arrow(SkPath* path) { |
| + static SkScalar xOffset = 34.f; |
| + static SkScalar yOffset = 40.f; |
| + path->moveTo(-26.f + xOffset, 0.0f + yOffset); |
| + path->lineTo(26.f + xOffset, 0.0f + yOffset); |
| + |
| + path->moveTo(-28.f + xOffset, -2.4748745f + yOffset); |
| + path->lineTo(0 + xOffset, 25.525126f + yOffset); |
| + |
| + path->moveTo(-28.f + xOffset, 2.4748745f + yOffset); |
| + path->lineTo(0 + xOffset, -25.525126f + yOffset); |
| + path->lineTo(-28.f + xOffset, 2.4748745f + yOffset); |
| + |
| + path->close(); |
| + |
| + return SkIntToScalar(70); |
| +} |
| + |
| +static SkScalar make_curve(SkPath* path) { |
| + static SkScalar xOffset = -382.f; |
| + static SkScalar yOffset = -50.f; |
| + path->moveTo(491 + xOffset, 56 + yOffset); |
| + path->conicTo(435.93292f + xOffset, 56.000031f + yOffset, |
| + 382.61078f + xOffset, 69.752716f + yOffset, |
| + 0.9920463f); |
| + |
| + return SkIntToScalar(40); |
| +} |
| + |
| +static SkScalar make_battery(SkPath* path) { |
| + static SkScalar xOffset = 5.f; |
|
robertphillips
2015/11/18 21:06:51
kill this ?
jvanverth1
2015/11/18 21:15:51
Done.
|
| +// static SkScalar yOffset = -0.f; |
| + |
| + path->moveTo(24.67 + xOffset, 0.33000004); |
| + path->lineTo(8.3299999 + xOffset, 0.33000004); |
| + path->lineTo(8.3299999 + xOffset, 5.3299999); |
| + path->lineTo(0.33000004 + xOffset, 5.3299999); |
| + path->lineTo(0.33000004 + xOffset, 50.669998); |
| + path->lineTo(32.669998 + xOffset, 50.669998); |
| + path->lineTo(32.669998 + xOffset, 5.3299999); |
| + path->lineTo(24.67 + xOffset, 5.3299999); |
| + path->lineTo(24.67 + xOffset, 0.33000004); |
| + path->close(); |
| + |
| + path->moveTo(25.727224 + xOffset, 12.886665); |
| + path->lineTo(10.907918 + xOffset, 12.886665); |
| + path->lineTo(7.5166659 + xOffset, 28.683645); |
| + path->lineTo(14.810181 + xOffset, 28.683645); |
| + path->lineTo(7.7024879 + xOffset, 46.135998); |
| + path->lineTo(28.049999 + xOffset, 25.136419); |
| + path->lineTo(16.854223 + xOffset, 25.136419); |
| + path->lineTo(25.727224 + xOffset, 12.886665); |
| + path->close(); |
| + return SkIntToScalar(70); |
| +} |
| + |
|
robertphillips
2015/11/18 21:06:51
make_charging_icon ?
jvanverth1
2015/11/18 21:15:51
Done.
|
| +static SkScalar make_whatever(SkPath* path) { |
| + static SkScalar xOffset = 5.f; |
| + |
| + path->moveTo(32.669998 + xOffset, 9.8640003); |
| + path->lineTo(0.33000004 + xOffset, 9.8640003); |
| + path->lineTo(0.33000004 + xOffset, 50.669998); |
| + path->lineTo(32.669998 + xOffset, 50.669998); |
| + path->lineTo(32.669998 + xOffset, 9.8640003); |
| + path->close(); |
| + |
| + path->moveTo(10.907918 + xOffset, 12.886665); |
| + path->lineTo(25.727224 + xOffset, 12.886665); |
| + path->lineTo(16.854223 + xOffset, 25.136419); |
| + path->lineTo(28.049999 + xOffset, 25.136419); |
| + path->lineTo(7.7024879 + xOffset, 46.135998); |
| + path->lineTo(14.810181 + xOffset, 28.683645); |
| + path->lineTo(7.5166659 + xOffset, 28.683645); |
| + path->lineTo(10.907918 + xOffset, 12.886665); |
| + path->close(); |
| + |
| + return SkIntToScalar(70); |
| +} |
| + |
| +static const MakePathProc gProcs[] = { |
| + make_triangle, |
| + make_rect, |
| + make_oval, |
| + make_star_5, |
| + make_star_13, |
| + make_three_line, |
| + make_arrow, |
| + make_curve, |
| + make_battery, |
| + make_whatever |
| +}; |
| + |
| +static const SkScalar gWidths[] = { |
| + 2.0f, |
| + 3.0f, |
| + 4.0f, |
| + 5.0f, |
| + 6.0f, |
| + 7.0f, |
| + 7.0f, |
| + 14.0f, |
| + 0.0f, |
| + 0.0f, |
| +}; |
| + |
| +static const SkScalar gMiters[] = { |
| + 2.0f, |
| + 3.0f, |
| + 3.0f, |
| + 3.0f, |
| + 4.0f, |
| + 4.0f, |
| + 4.0f, |
| + 4.0f, |
| + 4.0f, |
| + 4.0f, |
| +}; |
| + |
| +#define N SK_ARRAY_COUNT(gProcs) |
| + |
|
robertphillips
2015/11/18 21:06:51
// This GM tests out drawing small paths (i.e., fo
jvanverth1
2015/11/18 21:15:51
Done.
|
| +class SmallPathsGM : public skiagm::GM { |
| + SkPath fPath[N]; |
| + SkScalar fDY[N]; |
| +protected: |
| + void onOnceBeforeDraw() override { |
| + for (size_t i = 0; i < N; i++) { |
| + fDY[i] = gProcs[i](&fPath[i]); |
| + } |
| + } |
| + |
| + SkString onShortName() override { |
| + return SkString("smallpaths"); |
| + } |
| + |
| + SkISize onISize() override { |
| + return SkISize::Make(640, 480); |
| + } |
| + |
| + void onDraw(SkCanvas* canvas) override { |
| + SkPaint paint; |
| + paint.setAntiAlias(true); |
| + |
|
robertphillips
2015/11/18 21:06:51
// First column is just filled
?
jvanverth1
2015/11/18 21:15:51
Done.
|
| + canvas->save(); |
| + for (size_t i = 0; i < N; i++) { |
| + canvas->drawPath(fPath[i], paint); |
| + canvas->translate(SkIntToScalar(0), fDY[i]); |
| + } |
| + |
| + canvas->restore(); |
| + canvas->translate(SkIntToScalar(120), SkIntToScalar(0)); |
| + |
|
robertphillips
2015/11/18 21:06:51
// Second column is stroked
?
jvanverth1
2015/11/18 21:15:51
Done.
|
| + // now stroke them |
| + canvas->save(); |
| + paint.setStyle(SkPaint::kStroke_Style); |
| + paint.setStrokeCap(SkPaint::kButt_Cap); |
| + for (size_t i = 0; i < N; i++) { |
| + paint.setStrokeWidth(gWidths[i]); |
| + paint.setStrokeMiter(gMiters[i]); |
| + canvas->drawPath(fPath[i], paint); |
| + canvas->translate(SkIntToScalar(0), fDY[i]); |
| + } |
| + canvas->restore(); |
| + |
| + // now stroke and fill |
| + canvas->translate(SkIntToScalar(120), SkIntToScalar(0)); |
| + paint.setStyle(SkPaint::kStrokeAndFill_Style); |
| + paint.setStrokeCap(SkPaint::kButt_Cap); |
| + for (size_t i = 0; i < N; i++) { |
| + paint.setStrokeWidth(gWidths[i]); |
| + paint.setStrokeMiter(gMiters[i]); |
| + canvas->drawPath(fPath[i], paint); |
| + canvas->translate(SkIntToScalar(0), fDY[i]); |
| + } |
| + |
| + } |
| + |
| +private: |
| + typedef skiagm::GM INHERITED; |
| +}; |
| + |
| +/////////////////////////////////////////////////////////////////////////////// |
| + |
|
robertphillips
2015/11/18 21:06:51
DEF_GM ?
jvanverth1
2015/11/18 21:15:51
Done.
|
| +static skiagm::GM* MyFactory(void*) { return new SmallPathsGM; } |
| +static skiagm::GMRegistry reg(MyFactory); |
| + |