Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit 6cc9d8d

Browse files
rphilliSkia Commit-Bot
authored andcommitted
Better encapsulate creation & usage of triangulating path renderer's key data
We will need this functionality in TriangulatingPathOp::onPrePrepareDraws as well as at the current locations Bug: 1108408 Change-Id: I2a65f07f47a549531d84dbf2afd82ad9d9b35225 Reviewed-on: https://skia-review.googlesource.com/c/skia/+/328536 Reviewed-by: Adlai Holler <adlai@google.com> Commit-Queue: Robert Phillips <robertphillips@google.com>
1 parent 607d36b commit 6cc9d8d

File tree

1 file changed

+32
-24
lines changed

1 file changed

+32
-24
lines changed

src/gpu/ops/GrTriangulatingPathRenderer.cpp

Lines changed: 32 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,24 @@ struct TessInfo {
4545
int fCount;
4646
};
4747

48+
static sk_sp<SkData> create_data(int vertexCount, int numCountedCurves, SkScalar tol) {
49+
TessInfo info;
50+
info.fTolerance = (numCountedCurves == 0) ? 0 : tol;
51+
info.fCount = vertexCount;
52+
return SkData::MakeWithCopy(&info, sizeof(info));
53+
}
54+
55+
bool cache_match(const SkData* data, SkScalar tol, int* actualCount) {
56+
SkASSERT(data);
57+
58+
const TessInfo* info = static_cast<const TessInfo*>(data->data());
59+
if (info->fTolerance == 0 || info->fTolerance < 3.0f * tol) {
60+
*actualCount = info->fCount;
61+
return true;
62+
}
63+
return false;
64+
}
65+
4866
// When the SkPathRef genID changes, invalidate a corresponding GrResource described by key.
4967
class UniqueKeyInvalidator : public SkIDChangeListener {
5068
public:
@@ -57,20 +75,6 @@ class UniqueKeyInvalidator : public SkIDChangeListener {
5775
void changed() override { SkMessageBus<GrUniqueKeyInvalidatedMessage>::Post(fMsg); }
5876
};
5977

60-
bool cache_match(GrGpuBuffer* vertexBuffer, SkScalar tol, int* actualCount) {
61-
if (!vertexBuffer) {
62-
return false;
63-
}
64-
const SkData* data = vertexBuffer->getUniqueKey().getCustomData();
65-
SkASSERT(data);
66-
const TessInfo* info = static_cast<const TessInfo*>(data->data());
67-
if (info->fTolerance == 0 || info->fTolerance < 3.0f * tol) {
68-
*actualCount = info->fCount;
69-
return true;
70-
}
71-
return false;
72-
}
73-
7478
class StaticVertexAllocator : public GrEagerVertexAllocator {
7579
public:
7680
StaticVertexAllocator(GrResourceProvider* resourceProvider, bool canMapVB)
@@ -265,13 +269,18 @@ class TriangulatingPathOp final : public GrMeshDrawOp {
265269
GrUniqueKey key;
266270
CreateKey(&key, fShape, fDevClipBounds);
267271

272+
SkScalar tol = GrPathUtils::scaleToleranceToSrc(GrPathUtils::kDefaultTolerance,
273+
fViewMatrix, fShape.bounds());
274+
268275
sk_sp<GrGpuBuffer> cachedVertexBuffer(rp->findByUniqueKey<GrGpuBuffer>(key));
269-
int actualCount;
270-
SkScalar tol = GrPathUtils::kDefaultTolerance;
271-
tol = GrPathUtils::scaleToleranceToSrc(tol, fViewMatrix, fShape.bounds());
272-
if (cache_match(cachedVertexBuffer.get(), tol, &actualCount)) {
273-
this->createMesh(target, std::move(cachedVertexBuffer), 0, actualCount);
274-
return;
276+
if (cachedVertexBuffer) {
277+
int actualCount;
278+
279+
if (cache_match(cachedVertexBuffer->getUniqueKey().getCustomData(), tol,
280+
&actualCount)) {
281+
this->createMesh(target, std::move(cachedVertexBuffer), 0, actualCount);
282+
return;
283+
}
275284
}
276285

277286
SkRect clipBounds = SkRect::Make(fDevClipBounds);
@@ -291,12 +300,11 @@ class TriangulatingPathOp final : public GrMeshDrawOp {
291300
return;
292301
}
293302
sk_sp<GrGpuBuffer> vb = allocator.detachVertexBuffer();
294-
TessInfo info;
295-
info.fTolerance = (numCountedCurves == 0) ? 0 : tol;
296-
info.fCount = vertexCount;
303+
304+
key.setCustomData(create_data(vertexCount, numCountedCurves, tol));
305+
297306
fShape.addGenIDChangeListener(
298307
sk_make_sp<UniqueKeyInvalidator>(key, target->contextUniqueID()));
299-
key.setCustomData(SkData::MakeWithCopy(&info, sizeof(info)));
300308
rp->assignUniqueKeyToResource(key, vb.get());
301309

302310
this->createMesh(target, std::move(vb), 0, vertexCount);

0 commit comments

Comments
 (0)