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

Side by Side 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 unified diff | Download patch
« no previous file with comments | « no previous file | gyp/gmslides.gypi » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 /*
2 * Copyright 2013 Google Inc.
bsalomon 2014/12/10 21:29:35 copyright date
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 #include "SkCanvas.h"
10 #include "SkTArray.h"
11
12 namespace skiagm {
13
14 class SubpixelPathsGM : public GM {
bsalomon 2014/12/10 21:29:35 I'd call it thinstrokes or subpixelstrokes rather
15 protected:
16 virtual uint32_t onGetFlags() const SK_OVERRIDE {
17 return kSkipTiled_Flag;
18 }
19
20
21 virtual SkString onShortName() SK_OVERRIDE {
22 return SkString("subpixelpaths");
23 }
24
25 virtual SkISize onISize() { return SkISize::Make(800, 600); }
26
27 virtual void onOnceBeforeDraw() SK_OVERRIDE {
28 {
29 // Arc example to test imperfect truncation bug (crbug.com/295626)
bsalomon 2014/12/10 21:29:35 ??
30 static const SkScalar kRad = SkIntToScalar(2000);
31 static const SkScalar kStartAngle = 262.59717f;
32 static const SkScalar kSweepAngle = SkScalarHalf(17.188717f);
33
34 SkPath* bug = &fPaths.push_back();
35
36 // Add a circular arc
37 SkRect circle = SkRect::MakeLTRB(-kRad, -kRad, kRad, kRad);
38 bug->addArc(circle, kStartAngle, kSweepAngle);
39
40 // Now add the chord that should cap the circular arc
41 SkScalar cosV, sinV = SkScalarSinCos(SkDegreesToRadians(kStartAngle) , &cosV);
42
43 SkPoint p0 = SkPoint::Make(kRad * cosV, kRad * sinV);
44
45 sinV = SkScalarSinCos(SkDegreesToRadians(kStartAngle + kSweepAngle), &cosV);
46
47 SkPoint p1 = SkPoint::Make(kRad * cosV, kRad * sinV);
48
49 bug->moveTo(p0);
50 bug->lineTo(p1);
51 }
52 }
53
54 virtual void onDraw(SkCanvas* canvas) SK_OVERRIDE {
55 static const SkAlpha kAlphaValue[] = { 0xFF, 0x40 };
56 static const SkScalar kWidths[] = { 0.5f, 0.9f, 1.5f };
57
58 enum {
59 kMargin = 5,
60 };
61 int wrapX = canvas->getDeviceSize().fWidth - kMargin;
62
63 SkScalar maxH = 0;
64 canvas->translate(SkIntToScalar(kMargin), SkIntToScalar(kMargin));
65 canvas->save();
66
67 SkScalar x = SkIntToScalar(kMargin);
68 for (int p = 0; p < fPaths.count(); ++p) {
69 for (size_t a = 0; a < SK_ARRAY_COUNT(kAlphaValue); ++a) {
70 for (int aa = 0; aa < 2; ++aa) {
71 for (size_t w = 0; w < SK_ARRAY_COUNT(kWidths); ++w) {
72 const SkRect& bounds = fPaths[p].getBounds();
73
74 if (x + bounds.width() > wrapX) {
75 canvas->restore();
76 canvas->translate(0, maxH + SkIntToScalar(kMargin));
77 canvas->save();
78 maxH = 0;
79 x = SkIntToScalar(kMargin);
80 }
81
82 SkPaint paint;
83 paint.setARGB(kAlphaValue[a], 0, 0, 0);
84 paint.setAntiAlias(SkToBool(aa));
85 paint.setStyle(SkPaint::kStroke_Style);
86 paint.setStrokeWidth(kWidths[w]);
87
88 canvas->save();
89 canvas->translate(-bounds.fLeft, -bounds.fTop);
90 canvas->drawPath(fPaths[p], paint);
91 canvas->restore();
92
93 maxH = SkMaxScalar(maxH, bounds.height());
94
95 SkScalar dx = bounds.width() + SkIntToScalar(kMargin);
96 x += dx;
97 canvas->translate(dx, 0);
98 }
99 }
100 }
101 }
102 canvas->restore();
103 }
104
105 private:
106 SkTArray<SkPath> fPaths;
107 typedef GM INHERITED;
108 };
109
110 //////////////////////////////////////////////////////////////////////////////
111
112 static GM* MyFactory(void*) { return new SubpixelPathsGM; }
113 static GMRegistry reg(MyFactory);
114
115 }
OLDNEW
« 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