Chromium Code Reviews| Index: gm/subpixelpaths.cpp |
| diff --git a/gm/subpixelpaths.cpp b/gm/subpixelpaths.cpp |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..fcf0defc07736e5083239ce037eb79fc1b09600e |
| --- /dev/null |
| +++ b/gm/subpixelpaths.cpp |
| @@ -0,0 +1,115 @@ |
| +/* |
| + * Copyright 2013 Google Inc. |
|
bsalomon
2014/12/10 21:29:35
copyright date
|
| + * |
| + * Use of this source code is governed by a BSD-style license that can be |
| + * found in the LICENSE file. |
| + */ |
| + |
| +#include "gm.h" |
| +#include "SkCanvas.h" |
| +#include "SkTArray.h" |
| + |
| +namespace skiagm { |
| + |
| +class SubpixelPathsGM : public GM { |
|
bsalomon
2014/12/10 21:29:35
I'd call it thinstrokes or subpixelstrokes rather
|
| +protected: |
| + virtual uint32_t onGetFlags() const SK_OVERRIDE { |
| + return kSkipTiled_Flag; |
| + } |
| + |
| + |
| + virtual SkString onShortName() SK_OVERRIDE { |
| + return SkString("subpixelpaths"); |
| + } |
| + |
| + virtual SkISize onISize() { return SkISize::Make(800, 600); } |
| + |
| + virtual void onOnceBeforeDraw() SK_OVERRIDE { |
| + { |
| + // Arc example to test imperfect truncation bug (crbug.com/295626) |
|
bsalomon
2014/12/10 21:29:35
??
|
| + static const SkScalar kRad = SkIntToScalar(2000); |
| + static const SkScalar kStartAngle = 262.59717f; |
| + static const SkScalar kSweepAngle = SkScalarHalf(17.188717f); |
| + |
| + SkPath* bug = &fPaths.push_back(); |
| + |
| + // Add a circular arc |
| + SkRect circle = SkRect::MakeLTRB(-kRad, -kRad, kRad, kRad); |
| + bug->addArc(circle, kStartAngle, kSweepAngle); |
| + |
| + // Now add the chord that should cap the circular arc |
| + SkScalar cosV, sinV = SkScalarSinCos(SkDegreesToRadians(kStartAngle), &cosV); |
| + |
| + SkPoint p0 = SkPoint::Make(kRad * cosV, kRad * sinV); |
| + |
| + sinV = SkScalarSinCos(SkDegreesToRadians(kStartAngle + kSweepAngle), &cosV); |
| + |
| + SkPoint p1 = SkPoint::Make(kRad * cosV, kRad * sinV); |
| + |
| + bug->moveTo(p0); |
| + bug->lineTo(p1); |
| + } |
| + } |
| + |
| + virtual void onDraw(SkCanvas* canvas) SK_OVERRIDE { |
| + static const SkAlpha kAlphaValue[] = { 0xFF, 0x40 }; |
| + static const SkScalar kWidths[] = { 0.5f, 0.9f, 1.5f }; |
| + |
| + enum { |
| + kMargin = 5, |
| + }; |
| + int wrapX = canvas->getDeviceSize().fWidth - kMargin; |
| + |
| + SkScalar maxH = 0; |
| + canvas->translate(SkIntToScalar(kMargin), SkIntToScalar(kMargin)); |
| + canvas->save(); |
| + |
| + SkScalar x = SkIntToScalar(kMargin); |
| + for (int p = 0; p < fPaths.count(); ++p) { |
| + for (size_t a = 0; a < SK_ARRAY_COUNT(kAlphaValue); ++a) { |
| + for (int aa = 0; aa < 2; ++aa) { |
| + for (size_t w = 0; w < SK_ARRAY_COUNT(kWidths); ++w) { |
| + const SkRect& bounds = fPaths[p].getBounds(); |
| + |
| + if (x + bounds.width() > wrapX) { |
| + canvas->restore(); |
| + canvas->translate(0, maxH + SkIntToScalar(kMargin)); |
| + canvas->save(); |
| + maxH = 0; |
| + x = SkIntToScalar(kMargin); |
| + } |
| + |
| + SkPaint paint; |
| + paint.setARGB(kAlphaValue[a], 0, 0, 0); |
| + paint.setAntiAlias(SkToBool(aa)); |
| + paint.setStyle(SkPaint::kStroke_Style); |
| + paint.setStrokeWidth(kWidths[w]); |
| + |
| + canvas->save(); |
| + canvas->translate(-bounds.fLeft, -bounds.fTop); |
| + canvas->drawPath(fPaths[p], paint); |
| + canvas->restore(); |
| + |
| + maxH = SkMaxScalar(maxH, bounds.height()); |
| + |
| + SkScalar dx = bounds.width() + SkIntToScalar(kMargin); |
| + x += dx; |
| + canvas->translate(dx, 0); |
| + } |
| + } |
| + } |
| + } |
| + canvas->restore(); |
| + } |
| + |
| +private: |
| + SkTArray<SkPath> fPaths; |
| + typedef GM INHERITED; |
| +}; |
| + |
| +////////////////////////////////////////////////////////////////////////////// |
| + |
| +static GM* MyFactory(void*) { return new SubpixelPathsGM; } |
| +static GMRegistry reg(MyFactory); |
| + |
| +} |