Use more of pathbuilder
Bug: skia:9000 Change-Id: Ia5c16ffbaeebbdd027c692c96095cfa181030d35 Reviewed-on: https://skia-review.googlesource.com/c/skia/+/307702 Reviewed-by: Mike Reed <reed@google.com> Commit-Queue: Mike Reed <reed@google.com>
This commit is contained in:
parent
f37f5d144b
commit
093de4eb2c
@ -75,9 +75,7 @@ SkPath SkSVGLine::onAsPath(const SkSVGRenderContext& ctx) const {
|
||||
SkPoint p0, p1;
|
||||
std::tie(p0, p1) = this->resolve(ctx.lengthContext());
|
||||
|
||||
SkPath path;
|
||||
path.moveTo(p0);
|
||||
path.lineTo(p1);
|
||||
SkPath path = SkPath::Line(p0, p1);
|
||||
this->mapToParent(&path);
|
||||
|
||||
return path;
|
||||
|
@ -8,7 +8,7 @@
|
||||
#include "gm/gm.h"
|
||||
#include "include/core/SkCanvas.h"
|
||||
#include "include/core/SkPaint.h"
|
||||
#include "include/core/SkPath.h"
|
||||
#include "include/core/SkPathBuilder.h"
|
||||
#include "include/core/SkScalar.h"
|
||||
#include "include/core/SkSize.h"
|
||||
#include "include/core/SkString.h"
|
||||
@ -20,28 +20,33 @@
|
||||
|
||||
constexpr SkScalar SH = SkIntToScalar(H);
|
||||
|
||||
static void rnd_quad(SkPath* p, SkPaint* paint, SkRandom& rand) {
|
||||
static SkPath rnd_quad(SkPaint* paint, SkRandom& rand) {
|
||||
auto a = rand.nextRangeScalar(0,W),
|
||||
b = rand.nextRangeScalar(0,H);
|
||||
p->moveTo(a,b);
|
||||
|
||||
SkPathBuilder builder;
|
||||
builder.moveTo(a, b);
|
||||
for (int x = 0; x < 2; ++x) {
|
||||
auto c = rand.nextRangeScalar(W/4, W),
|
||||
d = rand.nextRangeScalar( 0, H),
|
||||
e = rand.nextRangeScalar( 0, W),
|
||||
f = rand.nextRangeScalar(H/4, H);
|
||||
p->quadTo(c,d,e,f);
|
||||
builder.quadTo(c,d,e,f);
|
||||
}
|
||||
paint->setColor(rand.nextU());
|
||||
SkScalar width = rand.nextRangeScalar(1, 5);
|
||||
width *= width;
|
||||
paint->setStrokeWidth(width);
|
||||
paint->setAlphaf(1.0f);
|
||||
return builder.detach();
|
||||
}
|
||||
|
||||
static void rnd_cubic(SkPath* p, SkPaint* paint, SkRandom& rand) {
|
||||
static SkPath rnd_cubic(SkPaint* paint, SkRandom& rand) {
|
||||
auto a = rand.nextRangeScalar(0,W),
|
||||
b = rand.nextRangeScalar(0,H);
|
||||
p->moveTo(a,b);
|
||||
|
||||
SkPathBuilder builder;
|
||||
builder.moveTo(a, b);
|
||||
for (int x = 0; x < 2; ++x) {
|
||||
auto c = rand.nextRangeScalar(W/4, W),
|
||||
d = rand.nextRangeScalar( 0, H),
|
||||
@ -49,13 +54,14 @@ static void rnd_cubic(SkPath* p, SkPaint* paint, SkRandom& rand) {
|
||||
f = rand.nextRangeScalar(H/4, H),
|
||||
g = rand.nextRangeScalar(W/4, W),
|
||||
h = rand.nextRangeScalar(H/4, H);
|
||||
p->cubicTo(c,d,e,f,g,h);
|
||||
builder.cubicTo(c,d,e,f,g,h);
|
||||
}
|
||||
paint->setColor(rand.nextU());
|
||||
SkScalar width = rand.nextRangeScalar(1, 5);
|
||||
width *= width;
|
||||
paint->setStrokeWidth(width);
|
||||
paint->setAlphaf(1.0f);
|
||||
return builder.detach();
|
||||
}
|
||||
|
||||
class BeziersGM : public skiagm::GM {
|
||||
@ -80,15 +86,11 @@ protected:
|
||||
|
||||
SkRandom rand;
|
||||
for (int i = 0; i < N; i++) {
|
||||
SkPath p;
|
||||
rnd_quad(&p, &paint, rand);
|
||||
canvas->drawPath(p, paint);
|
||||
canvas->drawPath(rnd_quad(&paint, rand), paint);
|
||||
}
|
||||
canvas->translate(0, SH);
|
||||
for (int i = 0; i < N; i++) {
|
||||
SkPath p;
|
||||
rnd_cubic(&p, &paint, rand);
|
||||
canvas->drawPath(p, paint);
|
||||
canvas->drawPath(rnd_cubic(&paint, rand), paint);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -19,12 +19,7 @@ static void make_bm(SkBitmap* bm) {
|
||||
|
||||
SkCanvas canvas(*bm);
|
||||
SkPaint paint;
|
||||
|
||||
SkPath path;
|
||||
path.moveTo(6, 6);
|
||||
path.lineTo(6, 54);
|
||||
path.lineTo(30, 54);
|
||||
canvas.drawPath(path, paint);
|
||||
canvas.drawPath(SkPath::Polygon({{6,6}, {6,54}, {30,54}}, false), paint);
|
||||
|
||||
paint.setStyle(SkPaint::kStroke_Style);
|
||||
canvas.drawRect(SkRect::MakeLTRB(0.5f, 0.5f, 59.5f, 59.5f), paint);
|
||||
|
@ -8,134 +8,92 @@
|
||||
#include "gm/gm.h"
|
||||
#include "include/core/SkCanvas.h"
|
||||
#include "include/core/SkPaint.h"
|
||||
#include "include/core/SkPath.h"
|
||||
#include "include/core/SkPathBuilder.h"
|
||||
#include "include/core/SkScalar.h"
|
||||
|
||||
namespace {
|
||||
// Concave test
|
||||
void test_concave(SkCanvas* canvas, const SkPaint& paint) {
|
||||
SkPath path;
|
||||
canvas->translate(0, 0);
|
||||
path.moveTo(SkIntToScalar(20), SkIntToScalar(20))
|
||||
.lineTo(SkIntToScalar(80), SkIntToScalar(20))
|
||||
.lineTo(SkIntToScalar(30), SkIntToScalar(30))
|
||||
.lineTo(SkIntToScalar(20), SkIntToScalar(80));
|
||||
canvas->drawPath(path, paint);
|
||||
canvas->drawPath(SkPath::Polygon({{20,20}, {80,20}, {30,30}, {20,80}}, false), paint);
|
||||
}
|
||||
|
||||
// Reverse concave test
|
||||
void test_reverse_concave(SkCanvas* canvas, const SkPaint& paint) {
|
||||
SkPath path;
|
||||
canvas->save();
|
||||
canvas->translate(100, 0);
|
||||
path.moveTo(SkIntToScalar(20), SkIntToScalar(20))
|
||||
.lineTo(SkIntToScalar(20), SkIntToScalar(80))
|
||||
.lineTo(SkIntToScalar(30), SkIntToScalar(30))
|
||||
.lineTo(SkIntToScalar(80), SkIntToScalar(20));
|
||||
canvas->drawPath(path, paint);
|
||||
canvas->drawPath(SkPath::Polygon({{20,20}, {20,80}, {30,30}, {80,20}}, false), paint);
|
||||
canvas->restore();
|
||||
}
|
||||
|
||||
// Bowtie (intersection)
|
||||
void test_bowtie(SkCanvas* canvas, const SkPaint& paint) {
|
||||
SkPath path;
|
||||
canvas->save();
|
||||
canvas->translate(200, 0);
|
||||
path.moveTo(SkIntToScalar(20), SkIntToScalar(20))
|
||||
.lineTo(SkIntToScalar(80), SkIntToScalar(80))
|
||||
.lineTo(SkIntToScalar(80), SkIntToScalar(20))
|
||||
.lineTo(SkIntToScalar(20), SkIntToScalar(80));
|
||||
canvas->drawPath(path, paint);
|
||||
canvas->drawPath(SkPath::Polygon({{20,20}, {80,80}, {80,20}, {20,80}}, false), paint);
|
||||
canvas->restore();
|
||||
}
|
||||
|
||||
// "fake" bowtie (concave, but no intersection)
|
||||
void test_fake_bowtie(SkCanvas* canvas, const SkPaint& paint) {
|
||||
SkPath path;
|
||||
canvas->save();
|
||||
canvas->translate(300, 0);
|
||||
path.moveTo(SkIntToScalar(20), SkIntToScalar(20))
|
||||
.lineTo(SkIntToScalar(50), SkIntToScalar(40))
|
||||
.lineTo(SkIntToScalar(80), SkIntToScalar(20))
|
||||
.lineTo(SkIntToScalar(80), SkIntToScalar(80))
|
||||
.lineTo(SkIntToScalar(50), SkIntToScalar(60))
|
||||
.lineTo(SkIntToScalar(20), SkIntToScalar(80));
|
||||
canvas->drawPath(path, paint);
|
||||
canvas->drawPath(SkPath::Polygon({{20,20}, {50,40}, {80,20}, {80,80}, {50,60}, {20,80}},
|
||||
false), paint);
|
||||
canvas->restore();
|
||||
}
|
||||
|
||||
// Bowtie with a smaller right hand lobe. The outer vertex of the left hand
|
||||
// lobe intrudes into the interior of the right hand lobe.
|
||||
void test_intruding_vertex(SkCanvas* canvas, const SkPaint& paint) {
|
||||
SkPath path;
|
||||
canvas->save();
|
||||
canvas->translate(400, 0);
|
||||
path.setIsVolatile(true);
|
||||
path.moveTo(20, 20)
|
||||
.lineTo(50, 50)
|
||||
.lineTo(68, 20)
|
||||
.lineTo(68, 80)
|
||||
.lineTo(50, 50)
|
||||
.lineTo(20, 80);
|
||||
canvas->drawPath(path, paint);
|
||||
canvas->drawPath(SkPath::Polygon({{20,20}, {50,50}, {68,20}, {68,80}, {50,50}, {20,80}},
|
||||
false, SkPathFillType::kWinding, true), paint);
|
||||
canvas->restore();
|
||||
}
|
||||
|
||||
// A shape with an edge that becomes inverted on AA stroking and that also contains
|
||||
// a repeated start/end vertex.
|
||||
void test_inversion_repeat_vertex(SkCanvas* canvas, const SkPaint& paint) {
|
||||
SkPath path;
|
||||
canvas->save();
|
||||
canvas->translate(400, 100);
|
||||
path.setIsVolatile(true);
|
||||
path.moveTo(80, 50)
|
||||
.lineTo(40, 80)
|
||||
.lineTo(60, 20)
|
||||
.lineTo(20, 20)
|
||||
.lineTo(39.99f, 80)
|
||||
.lineTo(80, 50);
|
||||
canvas->drawPath(path, paint);
|
||||
const SkPoint pts[] = {
|
||||
{80,50}, {40,80}, {60,20}, {20,20}, {39.99f,80}, {80,50},
|
||||
};
|
||||
canvas->drawPath(SkPath::Polygon(pts, SK_ARRAY_COUNT(pts), false,
|
||||
SkPathFillType::kWinding, true), paint);
|
||||
canvas->restore();
|
||||
}
|
||||
|
||||
// Fish test (intersection/concave)
|
||||
void test_fish(SkCanvas* canvas, const SkPaint& paint) {
|
||||
SkPath path;
|
||||
canvas->save();
|
||||
canvas->translate(0, 100);
|
||||
path.moveTo(SkIntToScalar(20), SkIntToScalar(20))
|
||||
.lineTo(SkIntToScalar(80), SkIntToScalar(80))
|
||||
.lineTo(SkIntToScalar(70), SkIntToScalar(50))
|
||||
.lineTo(SkIntToScalar(80), SkIntToScalar(20))
|
||||
.lineTo(SkIntToScalar(20), SkIntToScalar(80))
|
||||
.lineTo(SkIntToScalar(0), SkIntToScalar(50));
|
||||
canvas->drawPath(path, paint);
|
||||
canvas->drawPath(SkPath::Polygon({{20,20}, {80,80}, {70,50}, {80,20}, {20,80}, {0,50}}, false,
|
||||
SkPathFillType::kWinding, true), paint);
|
||||
canvas->restore();
|
||||
}
|
||||
|
||||
// Overlapping "Fast-forward" icon: tests coincidence of inner and outer
|
||||
// vertices generated by intersection.
|
||||
void test_fast_forward(SkCanvas* canvas, const SkPaint& paint) {
|
||||
SkPath path;
|
||||
canvas->save();
|
||||
canvas->translate(100, 100);
|
||||
path.moveTo(SkIntToScalar(20), SkIntToScalar(20))
|
||||
.lineTo(SkIntToScalar(60), SkIntToScalar(50))
|
||||
.lineTo(SkIntToScalar(20), SkIntToScalar(80))
|
||||
.moveTo(SkIntToScalar(40), SkIntToScalar(20))
|
||||
.lineTo(SkIntToScalar(40), SkIntToScalar(80))
|
||||
.lineTo(SkIntToScalar(80), SkIntToScalar(50));
|
||||
auto path = SkPathBuilder().addPolygon({{20,20}, {60,50}, {20,80}}, false)
|
||||
.addPolygon({{40,20}, {40,80}, {80,50}}, false)
|
||||
.detach();
|
||||
canvas->drawPath(path, paint);
|
||||
canvas->restore();
|
||||
}
|
||||
|
||||
// Square polygon with a square hole.
|
||||
void test_hole(SkCanvas* canvas, const SkPaint& paint) {
|
||||
SkPath path;
|
||||
canvas->save();
|
||||
canvas->translate(200, 100);
|
||||
path.addPoly({{20,20}, {80,20}, {80,80}, {20,80}}, false)
|
||||
.addPoly({{30,30}, {30,70}, {70,70}, {70,30}}, false);
|
||||
auto path = SkPathBuilder().addPolygon({{20,20}, {80,20}, {80,80}, {20,80}}, false)
|
||||
.addPolygon({{30,30}, {30,70}, {70,70}, {70,30}}, false)
|
||||
.detach();
|
||||
canvas->drawPath(path, paint);
|
||||
canvas->restore();
|
||||
}
|
||||
@ -151,75 +109,52 @@ void test_star(SkCanvas* canvas, const SkPaint& paint) {
|
||||
|
||||
// Exercise a case where the intersection is below a bottom edge.
|
||||
void test_twist(SkCanvas* canvas, const SkPaint& paint) {
|
||||
SkPath path;
|
||||
canvas->save();
|
||||
path.moveTo( 0.5, 6);
|
||||
path.lineTo(5.8070392608642578125, 6.4612660408020019531);
|
||||
path.lineTo(-2.9186885356903076172, 2.811046600341796875);
|
||||
path.lineTo(0.49999994039535522461, -1.4124038219451904297);
|
||||
canvas->translate(420, 220);
|
||||
canvas->scale(10, 10);
|
||||
canvas->drawPath(path, paint);
|
||||
const SkPoint pts[] = {
|
||||
{0.5f, 6},
|
||||
{5.8070392608642578125f, 6.4612660408020019531f},
|
||||
{-2.9186885356903076172f, 2.811046600341796875f},
|
||||
{0.49999994039535522461f, -1.4124038219451904297f},
|
||||
};
|
||||
canvas->drawPath(SkPath::Polygon(pts, SK_ARRAY_COUNT(pts), false), paint);
|
||||
canvas->restore();
|
||||
}
|
||||
|
||||
// Stairstep with repeated vert (intersection)
|
||||
void test_stairstep(SkCanvas* canvas, const SkPaint& paint) {
|
||||
SkPath path;
|
||||
canvas->save();
|
||||
canvas->translate(0, 200);
|
||||
path.moveTo(SkIntToScalar(50), SkIntToScalar(50));
|
||||
path.lineTo(SkIntToScalar(50), SkIntToScalar(20));
|
||||
path.lineTo(SkIntToScalar(80), SkIntToScalar(20));
|
||||
path.lineTo(SkIntToScalar(50), SkIntToScalar(50));
|
||||
path.lineTo(SkIntToScalar(20), SkIntToScalar(50));
|
||||
path.lineTo(SkIntToScalar(20), SkIntToScalar(80));
|
||||
canvas->drawPath(path, paint);
|
||||
canvas->drawPath(SkPath::Polygon({{50,50}, {50,20}, {80,20}, {50,50}, {20,50}, {20,80}}, false),
|
||||
paint);
|
||||
canvas->restore();
|
||||
}
|
||||
|
||||
void test_stairstep2(SkCanvas* canvas, const SkPaint& paint) {
|
||||
SkPath path;
|
||||
canvas->save();
|
||||
canvas->translate(100, 200);
|
||||
path.moveTo(20, 60);
|
||||
path.lineTo(35, 80);
|
||||
path.lineTo(50, 60);
|
||||
path.lineTo(65, 80);
|
||||
path.lineTo(80, 60);
|
||||
canvas->drawPath(path, paint);
|
||||
canvas->drawPath(SkPath::Polygon({{20,60}, {35,80}, {50,60}, {65,80}, {80,60}}, false), paint);
|
||||
canvas->restore();
|
||||
}
|
||||
|
||||
// Overlapping segments
|
||||
void test_overlapping(SkCanvas* canvas, const SkPaint& paint) {
|
||||
SkPath path;
|
||||
canvas->save();
|
||||
canvas->translate(200, 200);
|
||||
path.moveTo(SkIntToScalar(20), SkIntToScalar(80));
|
||||
path.lineTo(SkIntToScalar(80), SkIntToScalar(80));
|
||||
path.lineTo(SkIntToScalar(80), SkIntToScalar(20));
|
||||
path.lineTo(SkIntToScalar(80), SkIntToScalar(30));
|
||||
canvas->drawPath(path, paint);
|
||||
canvas->drawPath(SkPath::Polygon({{20,80}, {80,80}, {80,20}, {80,30}}, false), paint);
|
||||
canvas->restore();
|
||||
}
|
||||
|
||||
// Two "island" triangles inside a containing rect.
|
||||
// This exercises the partnering code in the tessellator.
|
||||
void test_partners(SkCanvas* canvas, const SkPaint& paint) {
|
||||
SkPath path;
|
||||
canvas->save();
|
||||
canvas->translate(300, 200);
|
||||
path.moveTo(20, 80);
|
||||
path.lineTo(80, 80);
|
||||
path.lineTo(80, 20);
|
||||
path.lineTo(20, 20);
|
||||
path.moveTo(30, 30);
|
||||
path.lineTo(45, 50);
|
||||
path.lineTo(30, 70);
|
||||
path.moveTo(70, 30);
|
||||
path.lineTo(70, 70);
|
||||
path.lineTo(55, 50);
|
||||
auto path = SkPathBuilder().addPolygon({{20,80}, {80,80}, {80,20}, {20,20}}, false)
|
||||
.addPolygon({{30,30}, {45,50}, {30,70}}, false)
|
||||
.addPolygon({{70,30}, {70,70}, {55,50}}, false)
|
||||
.detach();
|
||||
canvas->drawPath(path, paint);
|
||||
canvas->restore();
|
||||
}
|
||||
@ -227,7 +162,7 @@ void test_partners(SkCanvas* canvas, const SkPaint& paint) {
|
||||
// A split edge causes one half to be merged to zero winding (destroyed).
|
||||
// Test that the other half of the split doesn't also get zero winding.
|
||||
void test_winding_merged_to_zero(SkCanvas* canvas, const SkPaint& paint) {
|
||||
SkPath path;
|
||||
SkPathBuilder path;
|
||||
canvas->save();
|
||||
canvas->translate(400, 350);
|
||||
path.moveTo(20, 80);
|
||||
@ -238,53 +173,49 @@ void test_winding_merged_to_zero(SkCanvas* canvas, const SkPaint& paint) {
|
||||
path.moveTo(50, 50.0);
|
||||
path.lineTo(50, -50.0);
|
||||
path.lineTo(10, 50.0);
|
||||
canvas->drawPath(path, paint);
|
||||
canvas->drawPath(path.detach(), paint);
|
||||
canvas->restore();
|
||||
}
|
||||
|
||||
// Monotone test 1 (point in the middle)
|
||||
void test_monotone_1(SkCanvas* canvas, const SkPaint& paint) {
|
||||
SkPath path;
|
||||
SkPathBuilder path;
|
||||
canvas->save();
|
||||
canvas->translate(0, 300);
|
||||
path.moveTo(SkIntToScalar(20), SkIntToScalar(20));
|
||||
path.quadTo(SkIntToScalar(20), SkIntToScalar(50),
|
||||
SkIntToScalar(80), SkIntToScalar(50));
|
||||
path.quadTo(SkIntToScalar(20), SkIntToScalar(50),
|
||||
SkIntToScalar(20), SkIntToScalar(80));
|
||||
canvas->drawPath(path, paint);
|
||||
path.moveTo(20, 20);
|
||||
path.quadTo(20, 50, 80, 50);
|
||||
path.quadTo(20, 50, 20, 80);
|
||||
canvas->drawPath(path.detach(), paint);
|
||||
canvas->restore();
|
||||
}
|
||||
|
||||
// Monotone test 2 (point at the top)
|
||||
void test_monotone_2(SkCanvas* canvas, const SkPaint& paint) {
|
||||
SkPath path;
|
||||
SkPathBuilder path;
|
||||
canvas->save();
|
||||
canvas->translate(100, 300);
|
||||
path.moveTo(SkIntToScalar(20), SkIntToScalar(20));
|
||||
path.lineTo(SkIntToScalar(80), SkIntToScalar(30));
|
||||
path.quadTo(SkIntToScalar(20), SkIntToScalar(20),
|
||||
SkIntToScalar(20), SkIntToScalar(80));
|
||||
canvas->drawPath(path, paint);
|
||||
path.moveTo(20, 20);
|
||||
path.lineTo(80, 30);
|
||||
path.quadTo(20, 20, 20, 80);
|
||||
canvas->drawPath(path.detach(), paint);
|
||||
canvas->restore();
|
||||
}
|
||||
|
||||
// Monotone test 3 (point at the bottom)
|
||||
void test_monotone_3(SkCanvas* canvas, const SkPaint& paint) {
|
||||
SkPath path;
|
||||
SkPathBuilder path;
|
||||
canvas->save();
|
||||
canvas->translate(200, 300);
|
||||
path.moveTo(SkIntToScalar(20), SkIntToScalar(80));
|
||||
path.lineTo(SkIntToScalar(80), SkIntToScalar(70));
|
||||
path.quadTo(SkIntToScalar(20), SkIntToScalar(80),
|
||||
SkIntToScalar(20), SkIntToScalar(20));
|
||||
canvas->drawPath(path, paint);
|
||||
path.moveTo(20, 80);
|
||||
path.lineTo(80, 70);
|
||||
path.quadTo(20, 80, 20, 20);
|
||||
canvas->drawPath(path.detach(), paint);
|
||||
canvas->restore();
|
||||
}
|
||||
|
||||
// Monotone test 4 (merging of two monotones)
|
||||
void test_monotone_4(SkCanvas* canvas, const SkPaint& paint) {
|
||||
SkPath path;
|
||||
SkPathBuilder path;
|
||||
canvas->save();
|
||||
canvas->translate(300, 300);
|
||||
path.moveTo(80, 25);
|
||||
@ -293,25 +224,25 @@ void test_monotone_4(SkCanvas* canvas, const SkPaint& paint) {
|
||||
path.lineTo(40, 45);
|
||||
path.lineTo(70, 50);
|
||||
path.lineTo(80, 80);
|
||||
canvas->drawPath(path, paint);
|
||||
canvas->drawPath(path.detach(), paint);
|
||||
canvas->restore();
|
||||
}
|
||||
|
||||
// Monotone test 5 (aborted merging of two monotones)
|
||||
void test_monotone_5(SkCanvas* canvas, const SkPaint& paint) {
|
||||
SkPath path;
|
||||
SkPathBuilder path;
|
||||
canvas->save();
|
||||
canvas->translate(0, 400);
|
||||
path.moveTo(50, 20);
|
||||
path.lineTo(80, 80);
|
||||
path.lineTo(50, 50);
|
||||
path.lineTo(20, 80);
|
||||
canvas->drawPath(path, paint);
|
||||
canvas->drawPath(path.detach(), paint);
|
||||
canvas->restore();
|
||||
}
|
||||
// Degenerate intersection test
|
||||
void test_degenerate(SkCanvas* canvas, const SkPaint& paint) {
|
||||
SkPath path;
|
||||
SkPathBuilder path;
|
||||
canvas->save();
|
||||
canvas->translate(100, 400);
|
||||
path.moveTo(50, 20);
|
||||
@ -320,12 +251,12 @@ void test_degenerate(SkCanvas* canvas, const SkPaint& paint) {
|
||||
path.moveTo(50, 20);
|
||||
path.lineTo(80, 80);
|
||||
path.lineTo(50, 80);
|
||||
canvas->drawPath(path, paint);
|
||||
canvas->drawPath(path.detach(), paint);
|
||||
canvas->restore();
|
||||
}
|
||||
// Two triangles with a coincident edge.
|
||||
void test_coincident_edge(SkCanvas* canvas, const SkPaint& paint) {
|
||||
SkPath path;
|
||||
SkPathBuilder path;
|
||||
canvas->save();
|
||||
canvas->translate(200, 400);
|
||||
|
||||
@ -337,30 +268,30 @@ void test_coincident_edge(SkCanvas* canvas, const SkPaint& paint) {
|
||||
path.lineTo(80, 80);
|
||||
path.lineTo(20, 80);
|
||||
|
||||
canvas->drawPath(path, paint);
|
||||
canvas->drawPath(path.detach(), paint);
|
||||
canvas->restore();
|
||||
}
|
||||
// Bowtie with a coincident triangle (one triangle vertex coincident with the
|
||||
// bowtie's intersection).
|
||||
void test_bowtie_coincident_triangle(SkCanvas* canvas, const SkPaint& paint) {
|
||||
SkPath path;
|
||||
SkPathBuilder path;
|
||||
canvas->save();
|
||||
canvas->translate(300, 400);
|
||||
path.moveTo(SkIntToScalar(20), SkIntToScalar(20));
|
||||
path.lineTo(SkIntToScalar(80), SkIntToScalar(80));
|
||||
path.lineTo(SkIntToScalar(80), SkIntToScalar(20));
|
||||
path.lineTo(SkIntToScalar(20), SkIntToScalar(80));
|
||||
path.moveTo(SkIntToScalar(50), SkIntToScalar(50));
|
||||
path.lineTo(SkIntToScalar(80), SkIntToScalar(20));
|
||||
path.lineTo(SkIntToScalar(80), SkIntToScalar(80));
|
||||
canvas->drawPath(path, paint);
|
||||
path.moveTo(20, 20);
|
||||
path.lineTo(80, 80);
|
||||
path.lineTo(80, 20);
|
||||
path.lineTo(20, 80);
|
||||
path.moveTo(50, 50);
|
||||
path.lineTo(80, 20);
|
||||
path.lineTo(80, 80);
|
||||
canvas->drawPath(path.detach(), paint);
|
||||
canvas->restore();
|
||||
}
|
||||
|
||||
// Collinear outer boundary edges. In the edge-AA codepath, this creates an overlap region
|
||||
// which contains a boundary edge. It can't be removed, but it must have the correct winding.
|
||||
void test_collinear_outer_boundary_edge(SkCanvas* canvas, const SkPaint& paint) {
|
||||
SkPath path;
|
||||
SkPathBuilder path;
|
||||
canvas->save();
|
||||
canvas->translate(400, 400);
|
||||
path.moveTo(20, 20);
|
||||
@ -369,36 +300,36 @@ void test_collinear_outer_boundary_edge(SkCanvas* canvas, const SkPaint& paint)
|
||||
path.moveTo(80, 50);
|
||||
path.lineTo(50, 50);
|
||||
path.lineTo(80, 20);
|
||||
canvas->drawPath(path, paint);
|
||||
canvas->drawPath(path.detach(), paint);
|
||||
canvas->restore();
|
||||
}
|
||||
|
||||
// Coincident edges (big ones first, coincident vert on top).
|
||||
void test_coincident_edges_1(SkCanvas* canvas, const SkPaint& paint) {
|
||||
SkPath path;
|
||||
SkPathBuilder path;
|
||||
canvas->save();
|
||||
canvas->translate(0, 500);
|
||||
path.moveTo(SkIntToScalar(20), SkIntToScalar(20));
|
||||
path.lineTo(SkIntToScalar(80), SkIntToScalar(80));
|
||||
path.lineTo(SkIntToScalar(20), SkIntToScalar(80));
|
||||
path.moveTo(SkIntToScalar(20), SkIntToScalar(20));
|
||||
path.lineTo(SkIntToScalar(50), SkIntToScalar(50));
|
||||
path.lineTo(SkIntToScalar(20), SkIntToScalar(50));
|
||||
canvas->drawPath(path, paint);
|
||||
path.moveTo(20, 20);
|
||||
path.lineTo(80, 80);
|
||||
path.lineTo(20, 80);
|
||||
path.moveTo(20, 20);
|
||||
path.lineTo(50, 50);
|
||||
path.lineTo(20, 50);
|
||||
canvas->drawPath(path.detach(), paint);
|
||||
canvas->restore();
|
||||
}
|
||||
// Coincident edges (small ones first, coincident vert on top).
|
||||
void test_coincident_edges_2(SkCanvas* canvas, const SkPaint& paint) {
|
||||
SkPath path;
|
||||
SkPathBuilder path;
|
||||
canvas->save();
|
||||
canvas->translate(100, 500);
|
||||
path.moveTo(SkIntToScalar(20), SkIntToScalar(20));
|
||||
path.lineTo(SkIntToScalar(50), SkIntToScalar(50));
|
||||
path.lineTo(SkIntToScalar(20), SkIntToScalar(50));
|
||||
path.moveTo(SkIntToScalar(20), SkIntToScalar(20));
|
||||
path.lineTo(SkIntToScalar(80), SkIntToScalar(80));
|
||||
path.lineTo(SkIntToScalar(20), SkIntToScalar(80));
|
||||
canvas->drawPath(path, paint);
|
||||
path.moveTo(20, 20);
|
||||
path.lineTo(50, 50);
|
||||
path.lineTo(20, 50);
|
||||
path.moveTo(20, 20);
|
||||
path.lineTo(80, 80);
|
||||
path.lineTo(20, 80);
|
||||
canvas->drawPath(path.detach(), paint);
|
||||
canvas->restore();
|
||||
}
|
||||
// Coincident edges (small ones first, coincident vert on bottom).
|
||||
@ -406,12 +337,12 @@ void test_coincident_edges_3(SkCanvas* canvas, const SkPaint& paint) {
|
||||
SkPath path;
|
||||
canvas->save();
|
||||
canvas->translate(200, 500);
|
||||
path.moveTo(SkIntToScalar(20), SkIntToScalar(80));
|
||||
path.lineTo(SkIntToScalar(20), SkIntToScalar(50));
|
||||
path.lineTo(SkIntToScalar(50), SkIntToScalar(50));
|
||||
path.moveTo(SkIntToScalar(20), SkIntToScalar(80));
|
||||
path.lineTo(SkIntToScalar(20), SkIntToScalar(20));
|
||||
path.lineTo(SkIntToScalar(80), SkIntToScalar(20));
|
||||
path.moveTo(20, 80);
|
||||
path.lineTo(20, 50);
|
||||
path.lineTo(50, 50);
|
||||
path.moveTo(20, 80);
|
||||
path.lineTo(20, 20);
|
||||
path.lineTo(80, 20);
|
||||
canvas->drawPath(path, paint);
|
||||
canvas->restore();
|
||||
}
|
||||
@ -420,12 +351,12 @@ void test_coincident_edges_4(SkCanvas* canvas, const SkPaint& paint) {
|
||||
SkPath path;
|
||||
canvas->save();
|
||||
canvas->translate(300, 500);
|
||||
path.moveTo(SkIntToScalar(20), SkIntToScalar(80));
|
||||
path.lineTo(SkIntToScalar(20), SkIntToScalar(20));
|
||||
path.lineTo(SkIntToScalar(80), SkIntToScalar(20));
|
||||
path.moveTo(SkIntToScalar(20), SkIntToScalar(80));
|
||||
path.lineTo(SkIntToScalar(20), SkIntToScalar(50));
|
||||
path.lineTo(SkIntToScalar(50), SkIntToScalar(50));
|
||||
path.moveTo(20, 80);
|
||||
path.lineTo(20, 20);
|
||||
path.lineTo(80, 20);
|
||||
path.moveTo(20, 80);
|
||||
path.lineTo(20, 50);
|
||||
path.lineTo(50, 50);
|
||||
canvas->drawPath(path, paint);
|
||||
canvas->restore();
|
||||
}
|
||||
|
@ -72,11 +72,19 @@ public:
|
||||
static SkPath Circle(SkScalar center_x, SkScalar center_y, SkScalar radius,
|
||||
SkPathDirection dir = SkPathDirection::kCW);
|
||||
static SkPath RRect(const SkRRect&, SkPathDirection dir = SkPathDirection::kCW);
|
||||
static SkPath Polygon(const SkPoint pts[], int count, bool isClosed);
|
||||
|
||||
static SkPath Polygon(const SkPoint pts[], int count, bool isClosed,
|
||||
SkPathFillType = SkPathFillType::kWinding,
|
||||
bool isVolatile = false);
|
||||
|
||||
static SkPath Polygon(const std::initializer_list<SkPoint>& list, bool isClosed,
|
||||
SkPathFillType fillType = SkPathFillType::kWinding,
|
||||
bool isVolatile = false) {
|
||||
return Polygon(list.begin(), SkToInt(list.size()), isClosed, fillType, isVolatile);
|
||||
}
|
||||
|
||||
static SkPath Line(const SkPoint a, const SkPoint b) {
|
||||
SkPoint pts[] = { a, b };
|
||||
return Polygon(pts, 2, false);
|
||||
return Polygon({a, b}, false);
|
||||
}
|
||||
|
||||
/** Constructs an empty SkPath. By default, SkPath has no verbs, no SkPoint, and no weights.
|
||||
|
@ -21,8 +21,8 @@ public:
|
||||
SkPath snapshot(); // the builder is unchanged after returning this path
|
||||
SkPath detach(); // the builder is reset to empty after returning this path
|
||||
|
||||
void setFillType(SkPathFillType ft) { fFillType = ft; }
|
||||
void setIsVolatile(bool isVolatile) { fIsVolatile = isVolatile; }
|
||||
SkPathBuilder& setFillType(SkPathFillType ft) { fFillType = ft; return *this; }
|
||||
SkPathBuilder& setIsVolatile(bool isVolatile) { fIsVolatile = isVolatile; return *this; }
|
||||
|
||||
SkPathBuilder& reset();
|
||||
|
||||
@ -181,7 +181,11 @@ public:
|
||||
|
||||
SkPathBuilder& addCircle(SkScalar center_x, SkScalar center_y, SkScalar radius,
|
||||
SkPathDirection dir = SkPathDirection::kCW);
|
||||
|
||||
SkPathBuilder& addPolygon(const SkPoint pts[], int count, bool isClosed);
|
||||
SkPathBuilder& addPolygon(const std::initializer_list<SkPoint>& list, bool isClosed) {
|
||||
return this->addPolygon(list.begin(), SkToInt(list.size()), isClosed);
|
||||
}
|
||||
|
||||
// Performance hint, to reserve extra storage for subsequent calls to lineTo, quadTo, etc.
|
||||
|
||||
|
@ -5,6 +5,7 @@
|
||||
* found in the LICENSE file.
|
||||
*/
|
||||
|
||||
#include "include/core/SkPathBuilder.h"
|
||||
#include "modules/skottie/src/SkottieJson.h"
|
||||
#include "modules/skottie/src/SkottieValue.h"
|
||||
#include "modules/skottie/src/animator/Animator.h"
|
||||
@ -115,7 +116,7 @@ static bool parse_encoding_data(const skjson::Value& jv, size_t data_len, float
|
||||
ShapeValue::operator SkPath() const {
|
||||
const auto vertex_count = this->size() / kFloatsPerVertex;
|
||||
|
||||
SkPath path;
|
||||
SkPathBuilder path;
|
||||
|
||||
if (vertex_count) {
|
||||
// conservatively assume all cubics
|
||||
@ -158,9 +159,7 @@ ShapeValue::operator SkPath() const {
|
||||
path.close();
|
||||
}
|
||||
|
||||
path.shrinkToFit();
|
||||
|
||||
return path;
|
||||
return path.detach();
|
||||
}
|
||||
|
||||
namespace internal {
|
||||
|
@ -3415,8 +3415,12 @@ SkPath SkPath::RRect(const SkRRect& rr, SkPathDirection dir) {
|
||||
return SkPathBuilder().addRRect(rr, dir).detach();
|
||||
}
|
||||
|
||||
SkPath SkPath::Polygon(const SkPoint pts[], int count, bool isClosed) {
|
||||
return SkPathBuilder().addPolygon(pts, count, isClosed).detach();
|
||||
SkPath SkPath::Polygon(const SkPoint pts[], int count, bool isClosed,
|
||||
SkPathFillType ft, bool isVolatile) {
|
||||
return SkPathBuilder().addPolygon(pts, count, isClosed)
|
||||
.setFillType(ft)
|
||||
.setIsVolatile(isVolatile)
|
||||
.detach();
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
@ -1886,19 +1886,11 @@ DEF_TEST(GrStyledShape_lines, r) {
|
||||
static constexpr SkPoint kB { 5, -9};
|
||||
static constexpr SkPoint kC {-3, 17};
|
||||
|
||||
SkPath lineAB;
|
||||
lineAB.moveTo(kA);
|
||||
lineAB.lineTo(kB);
|
||||
|
||||
SkPath lineBA;
|
||||
lineBA.moveTo(kB);
|
||||
lineBA.lineTo(kA);
|
||||
|
||||
SkPath lineAC;
|
||||
lineAC.moveTo(kB);
|
||||
lineAC.lineTo(kC);
|
||||
|
||||
SkPath lineAB = SkPath::Line(kA, kB);
|
||||
SkPath lineBA = SkPath::Line(kB, kA);
|
||||
SkPath lineAC = SkPath::Line(kB, kC);
|
||||
SkPath invLineAB = lineAB;
|
||||
|
||||
invLineAB.setFillType(SkPathFillType::kInverseEvenOdd);
|
||||
|
||||
SkPaint fill;
|
||||
|
Loading…
Reference in New Issue
Block a user