Skip to content

Commit 86d4cfd

Browse files
csmartdalton86Skia Commit-Bot
authored andcommitted
Revert "Update GrTriangulator to count curves"
This reverts commit 8e2b694. Bug: chromium:1075428 Change-Id: I0be8570193783981a995265d0446db219bc73a87 Reviewed-on: https://skia-review.googlesource.com/c/skia/+/330576 Reviewed-by: Robert Phillips <robertphillips@google.com> Commit-Queue: Chris Dalton <csmartdalton@google.com>
1 parent d7b59c0 commit 86d4cfd

File tree

5 files changed

+38
-40
lines changed

5 files changed

+38
-40
lines changed

src/gpu/GrTriangulator.cpp

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -818,12 +818,12 @@ void generate_cubic_points(const SkPoint& p0,
818818
// Stage 1: convert the input path to a set of linear contours (linked list of Vertices).
819819

820820
void path_to_contours(const SkPath& path, SkScalar tolerance, const SkRect& clipBounds,
821-
VertexList* contours, SkArenaAlloc& alloc, Mode mode, int* numCountedCurves) {
821+
VertexList* contours, SkArenaAlloc& alloc, Mode mode, bool *isLinear) {
822822
SkScalar toleranceSqd = tolerance * tolerance;
823823
bool innerPolygons = (Mode::kSimpleInnerPolygons == mode);
824824

825825
SkPoint pts[4];
826-
int localCurveCount = 0;
826+
*isLinear = true;
827827
VertexList* contour = contours;
828828
SkPath::Iter iter(path, false);
829829
if (path.isInverseFillType()) {
@@ -839,7 +839,7 @@ void path_to_contours(const SkPath& path, SkScalar tolerance, const SkRect& clip
839839
while ((verb = iter.next(pts)) != SkPath::kDone_Verb) {
840840
switch (verb) {
841841
case SkPath::kConic_Verb: {
842-
++localCurveCount;
842+
*isLinear = false;
843843
if (innerPolygons) {
844844
append_point_to_contour(pts[2], contour, alloc);
845845
break;
@@ -863,7 +863,7 @@ void path_to_contours(const SkPath& path, SkScalar tolerance, const SkRect& clip
863863
break;
864864
}
865865
case SkPath::kQuad_Verb: {
866-
++localCurveCount;
866+
*isLinear = false;
867867
if (innerPolygons) {
868868
append_point_to_contour(pts[2], contour, alloc);
869869
break;
@@ -872,7 +872,7 @@ void path_to_contours(const SkPath& path, SkScalar tolerance, const SkRect& clip
872872
break;
873873
}
874874
case SkPath::kCubic_Verb: {
875-
++localCurveCount;
875+
*isLinear = false;
876876
if (innerPolygons) {
877877
append_point_to_contour(pts[3], contour, alloc);
878878
break;
@@ -887,7 +887,6 @@ void path_to_contours(const SkPath& path, SkScalar tolerance, const SkRect& clip
887887
break;
888888
}
889889
}
890-
*numCountedCurves = localCurveCount;
891890
}
892891

893892
inline bool apply_fill_type(SkPathFillType fillType, int winding) {
@@ -2371,15 +2370,15 @@ void* polys_to_triangles(Poly* polys, SkPathFillType fillType, Mode mode, void*
23712370
}
23722371

23732372
Poly* path_to_polys(const SkPath& path, SkScalar tolerance, const SkRect& clipBounds,
2374-
int contourCnt, SkArenaAlloc& alloc, Mode mode, int* numCountedCurves,
2373+
int contourCnt, SkArenaAlloc& alloc, Mode mode, bool* isLinear,
23752374
VertexList* outerMesh) {
23762375
SkPathFillType fillType = path.getFillType();
23772376
if (SkPathFillType_IsInverse(fillType)) {
23782377
contourCnt++;
23792378
}
23802379
std::unique_ptr<VertexList[]> contours(new VertexList[contourCnt]);
23812380

2382-
path_to_contours(path, tolerance, clipBounds, contours.get(), alloc, mode, numCountedCurves);
2381+
path_to_contours(path, tolerance, clipBounds, contours.get(), alloc, mode, isLinear);
23832382
return contours_to_polys(contours.get(), contourCnt, path.getFillType(), path.getBounds(),
23842383
mode, outerMesh, alloc);
23852384
}
@@ -2459,16 +2458,16 @@ namespace GrTriangulator {
24592458
// Stage 6: Triangulate the monotone polygons into a vertex buffer.
24602459

24612460
int PathToTriangles(const SkPath& path, SkScalar tolerance, const SkRect& clipBounds,
2462-
GrEagerVertexAllocator* vertexAllocator, Mode mode, int* numCountedCurves) {
2461+
GrEagerVertexAllocator* vertexAllocator, Mode mode, bool* isLinear) {
24632462
int contourCnt = get_contour_count(path, tolerance);
24642463
if (contourCnt <= 0) {
2465-
*numCountedCurves = 0;
2464+
*isLinear = true;
24662465
return 0;
24672466
}
24682467
SkArenaAlloc alloc(kArenaChunkSize);
24692468
VertexList outerMesh;
24702469
Poly* polys = path_to_polys(path, tolerance, clipBounds, contourCnt, alloc, mode,
2471-
numCountedCurves, &outerMesh);
2470+
isLinear, &outerMesh);
24722471
SkPathFillType fillType = (Mode::kEdgeAntialias == mode) ?
24732472
SkPathFillType::kWinding : path.getFillType();
24742473
int64_t count64 = count_points(polys, fillType);
@@ -2506,9 +2505,9 @@ int PathToVertices(const SkPath& path, SkScalar tolerance, const SkRect& clipBou
25062505
return 0;
25072506
}
25082507
SkArenaAlloc alloc(kArenaChunkSize);
2509-
int numCountedCurves;
2508+
bool isLinear;
25102509
Poly* polys = path_to_polys(path, tolerance, clipBounds, contourCnt, alloc, Mode::kNormal,
2511-
&numCountedCurves, nullptr);
2510+
&isLinear, nullptr);
25122511
SkPathFillType fillType = path.getFillType();
25132512
int64_t count64 = count_points(polys, fillType);
25142513
if (0 == count64 || count64 > SK_MaxS32) {

src/gpu/GrTriangulator.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ constexpr size_t GetVertexStride(Mode mode) {
5656
}
5757

5858
int PathToTriangles(const SkPath& path, SkScalar tolerance, const SkRect& clipBounds,
59-
GrEagerVertexAllocator*, Mode, int* numCountedCurves);
59+
GrEagerVertexAllocator*, Mode, bool *isLinear);
6060
} // namespace GrTriangulator
6161

6262
#endif

src/gpu/ops/GrTriangulatingPathRenderer.cpp

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -50,12 +50,12 @@ namespace {
5050
// value.
5151
struct TessInfo {
5252
int fNumVertices;
53-
int fNumCountedCurves;
53+
bool fIsLinear;
5454
SkScalar fTolerance;
5555
};
5656

57-
static sk_sp<SkData> create_data(int numVertices, int numCountedCurves, SkScalar tol) {
58-
TessInfo info { numVertices, numCountedCurves, tol };
57+
static sk_sp<SkData> create_data(int numVertices, bool isLinear, SkScalar tol) {
58+
TessInfo info { numVertices, isLinear, tol };
5959
return SkData::MakeWithCopy(&info, sizeof(info));
6060
}
6161

@@ -64,15 +64,15 @@ bool cache_match(const SkData* data, SkScalar tol) {
6464

6565
const TessInfo* info = static_cast<const TessInfo*>(data->data());
6666

67-
return info->fNumCountedCurves == 0 || info->fTolerance < 3.0f * tol;
67+
return info->fIsLinear || info->fTolerance < 3.0f * tol;
6868
}
6969

7070
// Should 'challenger' replace 'incumbent' in the cache if there is a collision?
7171
bool is_newer_better(SkData* incumbent, SkData* challenger) {
7272
const TessInfo* i = static_cast<const TessInfo*>(incumbent->data());
7373
const TessInfo* c = static_cast<const TessInfo*>(challenger->data());
7474

75-
if (i->fNumCountedCurves == 0 || i->fTolerance <= c->fTolerance) {
75+
if (i->fIsLinear || i->fTolerance <= c->fTolerance) {
7676
return false; // prefer the incumbent
7777
}
7878

@@ -343,7 +343,7 @@ class TriangulatingPathOp final : public GrMeshDrawOp {
343343
const GrStyledShape& shape,
344344
const SkIRect& devClipBounds,
345345
SkScalar tol,
346-
int* numCountedCurves) {
346+
bool* isLinear) {
347347
SkRect clipBounds = SkRect::Make(devClipBounds);
348348

349349
SkMatrix vmi;
@@ -357,7 +357,7 @@ class TriangulatingPathOp final : public GrMeshDrawOp {
357357
shape.asPath(&path);
358358

359359
return GrTriangulator::PathToTriangles(path, tol, clipBounds, allocator,
360-
GrTriangulator::Mode::kNormal, numCountedCurves);
360+
GrTriangulator::Mode::kNormal, isLinear);
361361
}
362362

363363
void createNonAAMesh(Target* target) {
@@ -400,16 +400,16 @@ class TriangulatingPathOp final : public GrMeshDrawOp {
400400
bool canMapVB = GrCaps::kNone_MapFlags != target->caps().mapBufferFlags();
401401
StaticVertexAllocator allocator(rp, canMapVB);
402402

403-
int numCountedCurves;
403+
bool isLinear;
404404
int vertexCount = Triangulate(&allocator, fViewMatrix, fShape, fDevClipBounds, tol,
405-
&numCountedCurves);
405+
&isLinear);
406406
if (vertexCount == 0) {
407407
return;
408408
}
409409

410410
fVertexData = allocator.detachVertexData();
411411

412-
key.setCustomData(create_data(vertexCount, numCountedCurves, tol));
412+
key.setCustomData(create_data(vertexCount, isLinear, tol));
413413

414414
auto [tmpV, tmpD] = threadSafeCache->addVertsWithData(key, fVertexData, is_newer_better);
415415
if (tmpV != fVertexData) {
@@ -439,11 +439,11 @@ class TriangulatingPathOp final : public GrMeshDrawOp {
439439
SkScalar tol = GrPathUtils::kDefaultTolerance;
440440
sk_sp<const GrBuffer> vertexBuffer;
441441
int firstVertex;
442-
int numCountedCurves;
442+
bool isLinear;
443443
GrEagerDynamicVertexAllocator allocator(target, &vertexBuffer, &firstVertex);
444444
int vertexCount = GrTriangulator::PathToTriangles(path, tol, clipBounds, &allocator,
445445
GrTriangulator::Mode::kEdgeAntialias,
446-
&numCountedCurves);
446+
&isLinear);
447447
if (vertexCount == 0) {
448448
return;
449449
}
@@ -535,16 +535,16 @@ class TriangulatingPathOp final : public GrMeshDrawOp {
535535

536536
CpuVertexAllocator allocator;
537537

538-
int numCountedCurves;
538+
bool isLinear;
539539
int vertexCount = Triangulate(&allocator, fViewMatrix, fShape, fDevClipBounds, tol,
540-
&numCountedCurves);
540+
&isLinear);
541541
if (vertexCount == 0) {
542542
return;
543543
}
544544

545545
fVertexData = allocator.detachVertexData();
546546

547-
key.setCustomData(create_data(vertexCount, numCountedCurves, tol));
547+
key.setCustomData(create_data(vertexCount, isLinear, tol));
548548

549549
// If some other thread created and cached its own triangulation, the 'is_newer_better'
550550
// predicate will replace the version in the cache if 'fVertexData' is a more accurate

src/gpu/tessellate/GrPathTessellateOp.cpp

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -102,11 +102,11 @@ void GrPathTessellateOp::prePreparePrograms(const PrePrepareArgs& args) {
102102
float gpuFragmentWork = bounds.height() * scales[0] * bounds.width() * scales[1];
103103
float cpuTessellationWork = (float)numVerbs * SkNextLog2(numVerbs); // N log N.
104104
if (cpuTessellationWork * 500 + (256 * 256) < gpuFragmentWork) { // Don't try below 256x256.
105-
int numCountedCubics;
105+
bool isLinear;
106106
// This will fail if the inner triangles do not form a simple polygon (e.g., self
107107
// intersection, double winding).
108-
if (this->prePrepareInnerPolygonTriangulation(args, &numCountedCubics)) {
109-
if (numCountedCubics > 0) {
108+
if (this->prePrepareInnerPolygonTriangulation(args, &isLinear)) {
109+
if (!isLinear) {
110110
// Always use indirect draws for cubics instead of tessellation here. Our goal in
111111
// this mode is to maximize GPU performance, and the middle-out topology used by our
112112
// indirect draws is easier on the rasterizer than a tessellated fan. There also
@@ -155,7 +155,7 @@ void GrPathTessellateOp::prePreparePrograms(const PrePrepareArgs& args) {
155155
}
156156

157157
bool GrPathTessellateOp::prePrepareInnerPolygonTriangulation(const PrePrepareArgs& args,
158-
int* numCountedCurves) {
158+
bool* isLinear) {
159159
SkASSERT(!fTriangleBuffer);
160160
SkASSERT(fTriangleVertexCount == 0);
161161
SkASSERT(!fStencilTrianglesProgram);
@@ -166,7 +166,7 @@ bool GrPathTessellateOp::prePrepareInnerPolygonTriangulation(const PrePrepareArg
166166
fTriangleVertexCount = GrTriangulator::PathToTriangles(fPath, 0, SkRect::MakeEmpty(),
167167
args.fInnerTriangleAllocator,
168168
Mode::kSimpleInnerPolygons,
169-
numCountedCurves);
169+
isLinear);
170170
if (fTriangleVertexCount == 0) {
171171
// Mode::kSimpleInnerPolygons causes PathToTriangles to fail if the inner polygon(s) are not
172172
// simple.
@@ -180,7 +180,7 @@ bool GrPathTessellateOp::prePrepareInnerPolygonTriangulation(const PrePrepareArg
180180
// stencilled.
181181
this->prePrepareStencilTrianglesProgram(args);
182182
}
183-
this->prePrepareFillTrianglesProgram(args, *numCountedCurves);
183+
this->prePrepareFillTrianglesProgram(args, *isLinear);
184184
return true;
185185
}
186186

@@ -263,8 +263,7 @@ constexpr static GrUserStencilSettings kTestAndResetStencil(
263263
GrUserStencilOp::kKeep,
264264
0xffff>());
265265

266-
void GrPathTessellateOp::prePrepareFillTrianglesProgram(const PrePrepareArgs& args,
267-
int numCountedCurves) {
266+
void GrPathTessellateOp::prePrepareFillTrianglesProgram(const PrePrepareArgs& args, bool isLinear) {
268267
SkASSERT(!fFillTrianglesProgram);
269268

270269
if (fOpFlags & OpFlags::kStencilOnly) {
@@ -302,7 +301,7 @@ void GrPathTessellateOp::prePrepareFillTrianglesProgram(const PrePrepareArgs& ar
302301
if (fStencilTrianglesProgram) {
303302
// The path was already stencilled. Here we just need to do a cover pass.
304303
stencil = &kTestAndResetStencil;
305-
} else if (numCountedCurves == 0) {
304+
} else if (isLinear) {
306305
// There are no stencilled curves. We can ignore stencil and fill the path directly.
307306
stencil = &GrUserStencilSettings::kUnused;
308307
} else if (SkPathFillType::kWinding == fPath.getFillType()) {

src/gpu/tessellate/GrPathTessellateOp.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,13 +75,13 @@ class GrPathTessellateOp : public GrDrawOp {
7575
// Returns false if the inner triangles do not form a simple polygon (e.g., self intersection,
7676
// double winding). Non-simple polygons would need to split edges in order to avoid overlap,
7777
// and this is not an option as it would introduce T-junctions with the outer cubics.
78-
bool prePrepareInnerPolygonTriangulation(const PrePrepareArgs&, int* numCountedCurves);
78+
bool prePrepareInnerPolygonTriangulation(const PrePrepareArgs&, bool* isLinear);
7979

8080
void prePrepareStencilTrianglesProgram(const PrePrepareArgs&);
8181
template<typename ShaderType> void prePrepareStencilCubicsProgram(const PrePrepareArgs&);
8282
void prePreparePipelineForStencils(const PrePrepareArgs&);
8383

84-
void prePrepareFillTrianglesProgram(const PrePrepareArgs&, int numCountedCurves);
84+
void prePrepareFillTrianglesProgram(const PrePrepareArgs&, bool isLinear);
8585
void prePrepareFillCubicHullsProgram(const PrePrepareArgs&);
8686
void prePrepareFillBoundingBoxProgram(const PrePrepareArgs&);
8787
void prePreparePipelineForFills(const PrePrepareArgs&);

0 commit comments

Comments
 (0)