Switch over to SkPathBuilder
Bug: skia:9000 Change-Id: If7192dfb8df01db9acb83a3c331fbbde981e5e2e Reviewed-on: https://skia-review.googlesource.com/c/skia/+/307017 Reviewed-by: Mike Reed <reed@google.com> Commit-Queue: Mike Reed <reed@google.com>
This commit is contained in:
parent
bfbe71252a
commit
d5b51a0b97
@ -7,7 +7,7 @@
|
|||||||
|
|
||||||
#include "include/core/SkCanvas.h"
|
#include "include/core/SkCanvas.h"
|
||||||
#include "include/core/SkPaint.h"
|
#include "include/core/SkPaint.h"
|
||||||
#include "include/core/SkPath.h"
|
#include "include/core/SkPathBuilder.h"
|
||||||
#include "include/utils/SkRandom.h"
|
#include "include/utils/SkRandom.h"
|
||||||
#include "samplecode/Sample.h"
|
#include "samplecode/Sample.h"
|
||||||
|
|
||||||
@ -30,9 +30,7 @@ static void gen_paths(const SkTDArray<SkScalar>& topData,
|
|||||||
SkScalar yBase,
|
SkScalar yBase,
|
||||||
SkScalar xLeft, SkScalar xDelta,
|
SkScalar xLeft, SkScalar xDelta,
|
||||||
int leftShift,
|
int leftShift,
|
||||||
SkPath* plot, SkPath* fill) {
|
SkPathBuilder* plot, SkPathBuilder* fill) {
|
||||||
plot->rewind();
|
|
||||||
fill->rewind();
|
|
||||||
plot->incReserve(topData.count());
|
plot->incReserve(topData.count());
|
||||||
if (nullptr == bottomData) {
|
if (nullptr == bottomData) {
|
||||||
fill->incReserve(topData.count() + 2);
|
fill->incReserve(topData.count() + 2);
|
||||||
@ -121,9 +119,6 @@ class ChartView : public Sample {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
SkPath plotPath;
|
|
||||||
SkPath fillPath;
|
|
||||||
|
|
||||||
static const SkScalar kStrokeWidth = SkIntToScalar(2);
|
static const SkScalar kStrokeWidth = SkIntToScalar(2);
|
||||||
SkPaint plotPaint;
|
SkPaint plotPaint;
|
||||||
SkPaint fillPaint;
|
SkPaint fillPaint;
|
||||||
@ -135,7 +130,9 @@ class ChartView : public Sample {
|
|||||||
fillPaint.setAntiAlias(true);
|
fillPaint.setAntiAlias(true);
|
||||||
fillPaint.setStyle(SkPaint::kFill_Style);
|
fillPaint.setStyle(SkPaint::kFill_Style);
|
||||||
|
|
||||||
|
SkPathBuilder plotPath, fillPath;
|
||||||
SkTDArray<SkScalar>* prevData = nullptr;
|
SkTDArray<SkScalar>* prevData = nullptr;
|
||||||
|
|
||||||
for (int i = 0; i < kNumGraphs; ++i) {
|
for (int i = 0; i < kNumGraphs; ++i) {
|
||||||
gen_paths(fData[i],
|
gen_paths(fData[i],
|
||||||
prevData,
|
prevData,
|
||||||
@ -148,10 +145,10 @@ class ChartView : public Sample {
|
|||||||
|
|
||||||
// Make the fills partially transparent
|
// Make the fills partially transparent
|
||||||
fillPaint.setColor((gColors[i] & 0x00ffffff) | 0x80000000);
|
fillPaint.setColor((gColors[i] & 0x00ffffff) | 0x80000000);
|
||||||
canvas->drawPath(fillPath, fillPaint);
|
canvas->drawPath(fillPath.detach(), fillPaint);
|
||||||
|
|
||||||
plotPaint.setColor(gColors[i]);
|
plotPaint.setColor(gColors[i]);
|
||||||
canvas->drawPath(plotPath, plotPaint);
|
canvas->drawPath(plotPath.detach(), plotPaint);
|
||||||
|
|
||||||
prevData = fData + i;
|
prevData = fData + i;
|
||||||
}
|
}
|
||||||
|
@ -9,7 +9,7 @@
|
|||||||
#include "include/core/SkColorPriv.h"
|
#include "include/core/SkColorPriv.h"
|
||||||
#include "include/core/SkFont.h"
|
#include "include/core/SkFont.h"
|
||||||
#include "include/core/SkPaint.h"
|
#include "include/core/SkPaint.h"
|
||||||
#include "include/core/SkPath.h"
|
#include "include/core/SkPathBuilder.h"
|
||||||
#include "include/utils/SkRandom.h"
|
#include "include/utils/SkRandom.h"
|
||||||
#include "samplecode/Sample.h"
|
#include "samplecode/Sample.h"
|
||||||
#include "src/core/SkClipOpPriv.h"
|
#include "src/core/SkClipOpPriv.h"
|
||||||
@ -39,7 +39,6 @@ static void show_fill(SkCanvas* canvas, bool doAA) {
|
|||||||
|
|
||||||
for (int i = 0; i < 50; ++i) {
|
for (int i = 0; i < 50; ++i) {
|
||||||
SkRect r;
|
SkRect r;
|
||||||
SkPath p;
|
|
||||||
|
|
||||||
r.setXYWH(rand.nextSScalar1() * W, rand.nextSScalar1() * H,
|
r.setXYWH(rand.nextSScalar1() * W, rand.nextSScalar1() * H,
|
||||||
rand.nextUScalar1() * W, rand.nextUScalar1() * H);
|
rand.nextUScalar1() * W, rand.nextUScalar1() * H);
|
||||||
@ -49,8 +48,7 @@ static void show_fill(SkCanvas* canvas, bool doAA) {
|
|||||||
r.setXYWH(rand.nextSScalar1() * W, rand.nextSScalar1() * H,
|
r.setXYWH(rand.nextSScalar1() * W, rand.nextSScalar1() * H,
|
||||||
rand.nextUScalar1() * W, rand.nextUScalar1() * H);
|
rand.nextUScalar1() * W, rand.nextUScalar1() * H);
|
||||||
paint.setColor(rand.nextU());
|
paint.setColor(rand.nextU());
|
||||||
p.addOval(r);
|
canvas->drawOval(r, paint);
|
||||||
canvas->drawPath(p, paint);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -68,7 +66,6 @@ static void show_stroke(SkCanvas* canvas, bool doAA, SkScalar strokeWidth, int n
|
|||||||
|
|
||||||
for (int i = 0; i < n; ++i) {
|
for (int i = 0; i < n; ++i) {
|
||||||
SkRect r;
|
SkRect r;
|
||||||
SkPath p;
|
|
||||||
|
|
||||||
r.setXYWH(rand.nextSScalar1() * W, rand.nextSScalar1() * H,
|
r.setXYWH(rand.nextSScalar1() * W, rand.nextSScalar1() * H,
|
||||||
rand.nextUScalar1() * W, rand.nextUScalar1() * H);
|
rand.nextUScalar1() * W, rand.nextUScalar1() * H);
|
||||||
@ -78,8 +75,7 @@ static void show_stroke(SkCanvas* canvas, bool doAA, SkScalar strokeWidth, int n
|
|||||||
r.setXYWH(rand.nextSScalar1() * W, rand.nextSScalar1() * H,
|
r.setXYWH(rand.nextSScalar1() * W, rand.nextSScalar1() * H,
|
||||||
rand.nextUScalar1() * W, rand.nextUScalar1() * H);
|
rand.nextUScalar1() * W, rand.nextUScalar1() * H);
|
||||||
paint.setColor(rand.nextU());
|
paint.setColor(rand.nextU());
|
||||||
p.addOval(r);
|
canvas->drawOval(r, paint);
|
||||||
canvas->drawPath(p, paint);
|
|
||||||
|
|
||||||
const SkScalar minx = -SkIntToScalar(W)/4;
|
const SkScalar minx = -SkIntToScalar(W)/4;
|
||||||
const SkScalar maxx = 5*SkIntToScalar(W)/4;
|
const SkScalar maxx = 5*SkIntToScalar(W)/4;
|
||||||
@ -114,9 +110,8 @@ class ClipView : public Sample {
|
|||||||
};
|
};
|
||||||
|
|
||||||
SkRect r = { 0, 0, SkIntToScalar(W), SkIntToScalar(H) };
|
SkRect r = { 0, 0, SkIntToScalar(W), SkIntToScalar(H) };
|
||||||
SkPath clipPath;
|
|
||||||
r.inset(SK_Scalar1 / 4, SK_Scalar1 / 4);
|
r.inset(SK_Scalar1 / 4, SK_Scalar1 / 4);
|
||||||
clipPath.addRoundRect(r, SkIntToScalar(20), SkIntToScalar(20));
|
SkPath clipPath = SkPathBuilder().addRRect(SkRRect::MakeRectXY(r, 20, 20)).detach();
|
||||||
|
|
||||||
// clipPath.toggleInverseFillType();
|
// clipPath.toggleInverseFillType();
|
||||||
|
|
||||||
@ -213,7 +208,7 @@ struct SkHalfPlane {
|
|||||||
|
|
||||||
#include "src/core/SkEdgeClipper.h"
|
#include "src/core/SkEdgeClipper.h"
|
||||||
|
|
||||||
static void clip(const SkPath& path, SkPoint p0, SkPoint p1, SkPath* clippedPath) {
|
static SkPath clip(const SkPath& path, SkPoint p0, SkPoint p1) {
|
||||||
SkMatrix mx, inv;
|
SkMatrix mx, inv;
|
||||||
SkVector v = p1 - p0;
|
SkVector v = p1 - p0;
|
||||||
mx.setAll(v.fX, -v.fY, p0.fX,
|
mx.setAll(v.fX, -v.fY, p0.fX,
|
||||||
@ -228,9 +223,9 @@ static void clip(const SkPath& path, SkPoint p0, SkPoint p1, SkPath* clippedPath
|
|||||||
SkRect clip = {-big, 0, big, big };
|
SkRect clip = {-big, 0, big, big };
|
||||||
|
|
||||||
struct Rec {
|
struct Rec {
|
||||||
SkPath* fResult;
|
SkPathBuilder fResult;
|
||||||
SkPoint fPrev;
|
SkPoint fPrev = {0, 0};
|
||||||
} rec = { clippedPath, {0, 0} };
|
} rec;
|
||||||
|
|
||||||
SkEdgeClipper::ClipPath(rotated, clip, false,
|
SkEdgeClipper::ClipPath(rotated, clip, false,
|
||||||
[](SkEdgeClipper* clipper, bool newCtr, void* ctx) {
|
[](SkEdgeClipper* clipper, bool newCtr, void* ctx) {
|
||||||
@ -241,26 +236,26 @@ static void clip(const SkPath& path, SkPoint p0, SkPoint p1, SkPath* clippedPath
|
|||||||
SkPath::Verb verb;
|
SkPath::Verb verb;
|
||||||
while ((verb = clipper->next(pts)) != SkPath::kDone_Verb) {
|
while ((verb = clipper->next(pts)) != SkPath::kDone_Verb) {
|
||||||
if (newCtr) {
|
if (newCtr) {
|
||||||
rec->fResult->moveTo(pts[0]);
|
rec->fResult.moveTo(pts[0]);
|
||||||
rec->fPrev = pts[0];
|
rec->fPrev = pts[0];
|
||||||
newCtr = false;
|
newCtr = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (addLineTo || pts[0] != rec->fPrev) {
|
if (addLineTo || pts[0] != rec->fPrev) {
|
||||||
rec->fResult->lineTo(pts[0]);
|
rec->fResult.lineTo(pts[0]);
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (verb) {
|
switch (verb) {
|
||||||
case SkPath::kLine_Verb:
|
case SkPath::kLine_Verb:
|
||||||
rec->fResult->lineTo(pts[1]);
|
rec->fResult.lineTo(pts[1]);
|
||||||
rec->fPrev = pts[1];
|
rec->fPrev = pts[1];
|
||||||
break;
|
break;
|
||||||
case SkPath::kQuad_Verb:
|
case SkPath::kQuad_Verb:
|
||||||
rec->fResult->quadTo(pts[1], pts[2]);
|
rec->fResult.quadTo(pts[1], pts[2]);
|
||||||
rec->fPrev = pts[2];
|
rec->fPrev = pts[2];
|
||||||
break;
|
break;
|
||||||
case SkPath::kCubic_Verb:
|
case SkPath::kCubic_Verb:
|
||||||
rec->fResult->cubicTo(pts[1], pts[2], pts[3]);
|
rec->fResult.cubicTo(pts[1], pts[2], pts[3]);
|
||||||
rec->fPrev = pts[3];
|
rec->fPrev = pts[3];
|
||||||
break;
|
break;
|
||||||
default: break;
|
default: break;
|
||||||
@ -269,7 +264,7 @@ static void clip(const SkPath& path, SkPoint p0, SkPoint p1, SkPath* clippedPath
|
|||||||
}
|
}
|
||||||
}, &rec);
|
}, &rec);
|
||||||
|
|
||||||
rec.fResult->transform(mx);
|
return rec.fResult.detach().makeTransform(mx);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void draw_halfplane(SkCanvas* canvas, SkPoint p0, SkPoint p1, SkColor c) {
|
static void draw_halfplane(SkCanvas* canvas, SkPoint p0, SkPoint p1, SkColor c) {
|
||||||
@ -290,7 +285,7 @@ static SkPath make_path() {
|
|||||||
return SkPoint{x * 400, y * 400};
|
return SkPoint{x * 400, y * 400};
|
||||||
};
|
};
|
||||||
|
|
||||||
SkPath path;
|
SkPathBuilder path;
|
||||||
for (int i = 0; i < 4; ++i) {
|
for (int i = 0; i < 4; ++i) {
|
||||||
SkPoint pts[6];
|
SkPoint pts[6];
|
||||||
for (auto& p : pts) {
|
for (auto& p : pts) {
|
||||||
@ -298,7 +293,7 @@ static SkPath make_path() {
|
|||||||
}
|
}
|
||||||
path.moveTo(pts[0]).quadTo(pts[1], pts[2]).quadTo(pts[3], pts[4]).lineTo(pts[5]);
|
path.moveTo(pts[0]).quadTo(pts[1], pts[2]).quadTo(pts[3], pts[4]).lineTo(pts[5]);
|
||||||
}
|
}
|
||||||
return path;
|
return path.detach();
|
||||||
}
|
}
|
||||||
|
|
||||||
class HalfPlaneView : public Sample {
|
class HalfPlaneView : public Sample {
|
||||||
@ -321,9 +316,7 @@ class HalfPlaneView : public Sample {
|
|||||||
|
|
||||||
paint.setColor({0, 0, 0, 1}, nullptr);
|
paint.setColor({0, 0, 0, 1}, nullptr);
|
||||||
|
|
||||||
SkPath clippedPath;
|
canvas->drawPath(clip(fPath, fPts[0], fPts[1]), paint);
|
||||||
clip(fPath, fPts[0], fPts[1], &clippedPath);
|
|
||||||
canvas->drawPath(clippedPath, paint);
|
|
||||||
|
|
||||||
draw_halfplane(canvas, fPts[0], fPts[1], SK_ColorRED);
|
draw_halfplane(canvas, fPts[0], fPts[1], SK_ColorRED);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user