aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorGravatar joshualitt <joshualitt@chromium.org>2015-02-19 10:25:21 -0800
committerGravatar Commit bot <commit-bot@chromium.org>2015-02-19 10:25:21 -0800
commit6364807151ddf51c4197603aa185b3336f325357 (patch)
tree92394f730a2a2515b06b2d7c76729e14170df141
parent02a44a488605112aa6683c9d919e13b188112ce1 (diff)
gm to test hairlines which fill RenderTarget
-rw-r--r--gm/stlouisarch.cpp97
-rw-r--r--gyp/gmslides.gypi3
-rw-r--r--src/gpu/GrAAHairLinePathRenderer.cpp28
3 files changed, 109 insertions, 19 deletions
diff --git a/gm/stlouisarch.cpp b/gm/stlouisarch.cpp
new file mode 100644
index 0000000000..06f607803a
--- /dev/null
+++ b/gm/stlouisarch.cpp
@@ -0,0 +1,97 @@
+/*
+ * Copyright 2015 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 "SkCanvas.h"
+#include "SkTArray.h"
+
+namespace skiagm {
+
+// this GM tests hairlines which fill nearly the entire render target
+class StLouisArchGM : public GM {
+protected:
+ SkString onShortName() SK_OVERRIDE {
+ return SkString("stlouisarch");
+ }
+
+ SkISize onISize() SK_OVERRIDE { return SkISize::Make((int)kWidth, (int)kHeight); }
+
+ void onOnceBeforeDraw() SK_OVERRIDE {
+ {
+ SkPath* bigQuad = &fPaths.push_back();
+ bigQuad->moveTo(0, 0);
+ bigQuad->quadTo(kWidth/2, kHeight, kWidth, 0);
+ }
+
+ {
+ SkPath* degenBigQuad = &fPaths.push_back();
+ SkScalar yPos = kHeight / 2 + 10;
+ degenBigQuad->moveTo(0, yPos);
+ degenBigQuad->quadTo(0, yPos, kWidth, yPos);
+ }
+
+
+ {
+ SkPath* bigCubic = &fPaths.push_back();
+ bigCubic->moveTo(0, 0);
+ bigCubic->cubicTo(0, kHeight,
+ kWidth, kHeight,
+ kWidth, 0);
+ }
+
+ {
+ SkPath* degenBigCubic = &fPaths.push_back();
+ SkScalar yPos = kHeight / 2;
+ degenBigCubic->moveTo(0, yPos);
+ degenBigCubic->cubicTo(0, yPos,
+ 0, yPos,
+ kWidth, yPos);
+ }
+
+ {
+ SkPath* bigConic = &fPaths.push_back();
+ bigConic->moveTo(0, 0);
+ bigConic->conicTo(kWidth/2, kHeight, kWidth, 0, .5);
+ }
+
+ {
+ SkPath* degenBigConic = &fPaths.push_back();
+ SkScalar yPos = kHeight / 2 - 10;
+ degenBigConic->moveTo(0, yPos);
+ degenBigConic->conicTo(0, yPos, kWidth, yPos, .5);
+ }
+ }
+
+ void onDraw(SkCanvas* canvas) SK_OVERRIDE {
+ canvas->save();
+ canvas->scale(1, -1);
+ canvas->translate(0, -kHeight);
+ for (int p = 0; p < fPaths.count(); ++p) {
+ SkPaint paint;
+ paint.setARGB(0xff, 0, 0, 0);
+ paint.setAntiAlias(true);
+ paint.setStyle(SkPaint::kStroke_Style);
+ paint.setStrokeWidth(0);
+ canvas->drawPath(fPaths[p], paint);
+ }
+ canvas->restore();
+ }
+
+ const SkScalar kWidth = 256;
+ const SkScalar kHeight = 256;
+
+private:
+ SkTArray<SkPath> fPaths;
+ typedef GM INHERITED;
+};
+
+//////////////////////////////////////////////////////////////////////////////
+
+static GM* MyFactory(void*) { return new StLouisArchGM; }
+static GMRegistry reg(MyFactory);
+
+}
diff --git a/gyp/gmslides.gypi b/gyp/gmslides.gypi
index 1ce729148c..41ec8ce6e9 100644
--- a/gyp/gmslides.gypi
+++ b/gyp/gmslides.gypi
@@ -179,9 +179,10 @@
'../gm/skbug1719.cpp',
'../gm/smallarc.cpp',
'../gm/smallimage.cpp',
- '../gm/stringart.cpp',
'../gm/spritebitmap.cpp',
'../gm/srcmode.cpp',
+ '../gm/stlouisarch.cpp',
+ '../gm/stringart.cpp',
'../gm/strokefill.cpp',
'../gm/strokerect.cpp',
'../gm/strokerects.cpp',
diff --git a/src/gpu/GrAAHairLinePathRenderer.cpp b/src/gpu/GrAAHairLinePathRenderer.cpp
index fe89b887bd..c1d1291469 100644
--- a/src/gpu/GrAAHairLinePathRenderer.cpp
+++ b/src/gpu/GrAAHairLinePathRenderer.cpp
@@ -184,7 +184,7 @@ int chop_conic(const SkPoint src[3], SkConic dst[4], const SkScalar weight) {
// returns 0 if quad/conic is degen or close to it
// in this case approx the path with lines
// otherwise returns 1
-int is_degen_quad_or_conic(const SkPoint p[3]) {
+int is_degen_quad_or_conic(const SkPoint p[3], SkScalar* dsqd) {
static const SkScalar gDegenerateToLineTol = SK_Scalar1;
static const SkScalar gDegenerateToLineTolSqd =
SkScalarMul(gDegenerateToLineTol, gDegenerateToLineTol);
@@ -194,8 +194,8 @@ int is_degen_quad_or_conic(const SkPoint p[3]) {
return 1;
}
- SkScalar dsqd = p[1].distanceToLineBetweenSqd(p[0], p[2]);
- if (dsqd < gDegenerateToLineTolSqd) {
+ *dsqd = p[1].distanceToLineBetweenSqd(p[0], p[2]);
+ if (*dsqd < gDegenerateToLineTolSqd) {
return 1;
}
@@ -205,24 +205,16 @@ int is_degen_quad_or_conic(const SkPoint p[3]) {
return 0;
}
+int is_degen_quad_or_conic(const SkPoint p[3]) {
+ SkScalar dsqd;
+ return is_degen_quad_or_conic(p, &dsqd);
+}
+
// we subdivide the quads to avoid huge overfill
// if it returns -1 then should be drawn as lines
int num_quad_subdivs(const SkPoint p[3]) {
- static const SkScalar gDegenerateToLineTol = SK_Scalar1;
- static const SkScalar gDegenerateToLineTolSqd =
- SkScalarMul(gDegenerateToLineTol, gDegenerateToLineTol);
-
- if (p[0].distanceToSqd(p[1]) < gDegenerateToLineTolSqd ||
- p[1].distanceToSqd(p[2]) < gDegenerateToLineTolSqd) {
- return -1;
- }
-
- SkScalar dsqd = p[1].distanceToLineBetweenSqd(p[0], p[2]);
- if (dsqd < gDegenerateToLineTolSqd) {
- return -1;
- }
-
- if (p[2].distanceToLineBetweenSqd(p[1], p[0]) < gDegenerateToLineTolSqd) {
+ SkScalar dsqd;
+ if (is_degen_quad_or_conic(p, &dsqd)) {
return -1;
}