Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(13)

Unified Diff: gm/subpixelpaths.cpp

Issue 796573002: fix for chrome bug with sub pixel hairlines (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 6 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | gyp/gmslides.gypi » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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);
+
+}
« no previous file with comments | « no previous file | gyp/gmslides.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698