Reland "Remove gpu buffer reads from default path renderer."

This reverts commit 30b355a49e.

Reason for revert: relanding with fix

Original change's description:
> Revert "Remove gpu buffer reads from default path renderer."
>
> This reverts commit 64241b8edb.
>
> Reason for revert: hitting new assert on starting point
>
> Original change's description:
> > Remove gpu buffer reads from default path renderer.
> >
> > I don't actually expect to see much perf gain from this one because the
> > reads happen when we've run out of space in our vertex buffer and need
> > a new allocation. So they happen pretty rarely.
> >
> > Change-Id: Iabe2e7cebf363659180409075a1a7fc6c03d0a22
> > Reviewed-on: https://skia-review.googlesource.com/c/skia/+/364618
> > Commit-Queue: Greg Daniel <egdaniel@google.com>
> > Reviewed-by: Chris Dalton <csmartdalton@google.com>
>
> TBR=egdaniel@google.com,csmartdalton@google.com
>
> Change-Id: I4c160ee692222f7c64cc63db2044fdc958eae551
> No-Presubmit: true
> No-Tree-Checks: true
> No-Try: true
> Reviewed-on: https://skia-review.googlesource.com/c/skia/+/365482
> Reviewed-by: Greg Daniel <egdaniel@google.com>
> Commit-Queue: Greg Daniel <egdaniel@google.com>

TBR=egdaniel@google.com,csmartdalton@google.com

# Not skipping CQ checks because this is a reland.

Change-Id: I97d613ca9adef0d425cc5ab22923d95297ca0afe
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/365486
Reviewed-by: Greg Daniel <egdaniel@google.com>
Commit-Queue: Greg Daniel <egdaniel@google.com>
This commit is contained in:
Greg Daniel 2021-02-03 12:16:32 -05:00 committed by Skia Commit-Bot
parent e2c0504c27
commit 733ab11058

View File

@ -87,25 +87,29 @@ public:
* Path verbs
*/
void moveTo(const SkPoint& p) {
needSpace(1);
this->needSpace(1);
fSubpathIndexStart = this->currentIndex();
*(fCurVert++) = p;
}
void addLine(const SkPoint& p) {
needSpace(1, this->indexScale());
if (this->isIndexed()) {
uint16_t prevIdx = this->currentIndex() - 1;
appendCountourEdgeIndices(prevIdx);
if (!this->isHairline()) {
fSubpathIndexStart = this->currentIndex();
fSubpathStartPoint = p;
}
*(fCurVert++) = p;
}
void addLine(const SkPoint pts[]) {
this->needSpace(1, this->indexScale(), &pts[0]);
if (this->isIndexed()) {
uint16_t prevIdx = this->currentIndex() - 1;
this->appendCountourEdgeIndices(prevIdx);
}
*(fCurVert++) = pts[1];
}
void addQuad(const SkPoint pts[], SkScalar srcSpaceTolSqd, SkScalar srcSpaceTol) {
this->needSpace(GrPathUtils::kMaxPointsPerCurve,
GrPathUtils::kMaxPointsPerCurve * this->indexScale());
GrPathUtils::kMaxPointsPerCurve * this->indexScale(),
&pts[0]);
// First pt of quad is the pt we ended on in previous step
uint16_t firstQPtIdx = this->currentIndex() - 1;
@ -114,7 +118,7 @@ public:
GrPathUtils::quadraticPointCount(pts, srcSpaceTol));
if (this->isIndexed()) {
for (uint16_t i = 0; i < numPts; ++i) {
appendCountourEdgeIndices(firstQPtIdx + i);
this->appendCountourEdgeIndices(firstQPtIdx + i);
}
}
}
@ -130,7 +134,8 @@ public:
void addCubic(const SkPoint pts[], SkScalar srcSpaceTolSqd, SkScalar srcSpaceTol) {
this->needSpace(GrPathUtils::kMaxPointsPerCurve,
GrPathUtils::kMaxPointsPerCurve * this->indexScale());
GrPathUtils::kMaxPointsPerCurve * this->indexScale(),
&pts[0]);
// First pt of cubic is the pt we ended on in previous step
uint16_t firstCPtIdx = this->currentIndex() - 1;
@ -139,7 +144,7 @@ public:
GrPathUtils::cubicPointCount(pts, srcSpaceTol));
if (this->isIndexed()) {
for (uint16_t i = 0; i < numPts; ++i) {
appendCountourEdgeIndices(firstCPtIdx + i);
this->appendCountourEdgeIndices(firstCPtIdx + i);
}
}
}
@ -158,7 +163,7 @@ public:
this->moveTo(pts[0]);
break;
case SkPath::kLine_Verb:
this->addLine(pts[1]);
this->addLine(pts);
break;
case SkPath::kConic_Verb:
this->addConic(iter.conicWeight(), pts, srcSpaceTolSqd, srcSpaceTol);
@ -289,17 +294,25 @@ private:
}
}
void needSpace(int vertsNeeded, int indicesNeeded = 0) {
void needSpace(int vertsNeeded, int indicesNeeded = 0, const SkPoint* lastPoint = nullptr) {
if (fCurVert + vertsNeeded > fVertices + fVerticesInChunk ||
fCurIdx + indicesNeeded > fIndices + fIndicesInChunk) {
// We are about to run out of space (possibly)
#ifdef SK_DEBUG
// To maintain continuity, we need to remember one or two points from the current mesh.
// Lines only need the last point, fills need the first point from the current contour.
// We always grab both here, and append the ones we need at the end of this process.
SkPoint lastPt = *(fCurVert - 1);
SkASSERT(fSubpathIndexStart < fVerticesInChunk);
SkPoint subpathStartPt = fVertices[fSubpathIndexStart];
// This assert is reading from the gpu buffer fVertices and will be slow, but for debug
// that is okay.
if (!this->isHairline()) {
SkASSERT(fSubpathStartPoint == fVertices[fSubpathIndexStart]);
}
if (lastPoint) {
SkASSERT(*(fCurVert - 1) == *lastPoint);
}
#endif
// Draw the mesh we've accumulated, and put back any unused space
this->createMeshAndPutBackReserve();
@ -307,11 +320,15 @@ private:
// Get new buffers
this->allocNewBuffers();
// Append copies of the points we saved so the two meshes will weld properly
if (!this->isHairline()) {
*(fCurVert++) = subpathStartPt;
// On moves we don't need to copy over any points to the new buffer and we pass in a
// null lastPoint.
if (lastPoint) {
// Append copies of the points we saved so the two meshes will weld properly
if (!this->isHairline()) {
*(fCurVert++) = fSubpathStartPoint;
}
*(fCurVert++) = *lastPoint;
}
*(fCurVert++) = lastPt;
}
}
@ -331,6 +348,7 @@ private:
uint16_t* fIndices;
uint16_t* fCurIdx;
uint16_t fSubpathIndexStart;
SkPoint fSubpathStartPoint;
SkTDArray<GrSimpleMesh*>* fMeshes;
};