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

Commit 109ff20

Browse files
rphilliSkia Commit-Bot
authored andcommitted
Tweak GrSmallPathAtlasMgr's cached path discovery methods
In an ideal world we wouldn't keep re-allocating the memory for the keys Change-Id: I3b7954e131d483166d0bf0ce95510365869b134c Reviewed-on: https://skia-review.googlesource.com/c/skia/+/309123 Reviewed-by: Adlai Holler <[email protected]> Commit-Queue: Robert Phillips <[email protected]>
1 parent bb67d54 commit 109ff20

File tree

5 files changed

+46
-29
lines changed

5 files changed

+46
-29
lines changed

src/gpu/ops/GrSmallPathAtlasMgr.cpp

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ bool GrSmallPathAtlasMgr::initAtlas(GrProxyProvider* proxyProvider, const GrCaps
4141
static constexpr size_t kPlotHeight = 256;
4242

4343
const GrBackendFormat format = caps->getDefaultBackendFormat(GrColorType::kAlpha_8,
44-
GrRenderable::kNo);
44+
GrRenderable::kNo);
4545

4646
GrDrawOpAtlasConfig atlasConfig(caps->maxTextureSize(), kMaxAtlasTextureBytes);
4747
SkISize size = atlasConfig.atlasDimensions(kA8_GrMaskFormat);
@@ -62,6 +62,7 @@ void GrSmallPathAtlasMgr::deleteCacheEntry(GrSmallPathShapeData* shapeData) {
6262
GrSmallPathShapeData* GrSmallPathAtlasMgr::findOrCreate(const GrSmallPathShapeDataKey& key) {
6363
auto shapeData = fShapeCache.find(key);
6464
if (!shapeData) {
65+
// TODO: move the key into the ctor
6566
shapeData = new GrSmallPathShapeData(key);
6667
fShapeCache.add(shapeData);
6768
fShapeList.addToTail(shapeData);
@@ -75,6 +76,22 @@ GrSmallPathShapeData* GrSmallPathAtlasMgr::findOrCreate(const GrSmallPathShapeDa
7576
return shapeData;
7677
}
7778

79+
GrSmallPathShapeData* GrSmallPathAtlasMgr::findOrCreate(const GrStyledShape& shape,
80+
int desiredDimension) {
81+
GrSmallPathShapeDataKey key(shape, desiredDimension);
82+
83+
// TODO: move the key into 'findOrCreate'
84+
return this->findOrCreate(key);
85+
}
86+
87+
GrSmallPathShapeData* GrSmallPathAtlasMgr::findOrCreate(const GrStyledShape& shape,
88+
const SkMatrix& ctm) {
89+
GrSmallPathShapeDataKey key(shape, ctm);
90+
91+
// TODO: move the key into 'findOrCreate'
92+
return this->findOrCreate(key);
93+
}
94+
7895
void GrSmallPathAtlasMgr::setUseToken(GrSmallPathShapeData* shapeData,
7996
GrDeferredUploadToken token) {
8097
fAtlas->setLastUseToken(shapeData->fAtlasLocator, token);

src/gpu/ops/GrSmallPathAtlasMgr.h

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515

1616
class GrSmallPathShapeData;
1717
class GrSmallPathShapeDataKey;
18+
class GrStyledShape;
1819

1920
/**
2021
* This class manages the small path renderer's atlas.
@@ -30,6 +31,9 @@ class GrSmallPathAtlasMgr : public GrOnFlushCallbackObject,
3031

3132
GrDrawOpAtlas* atlas() { return fAtlas.get(); }
3233

34+
GrSmallPathShapeData* findOrCreate(const GrStyledShape&, int desiredDimension);
35+
GrSmallPathShapeData* findOrCreate(const GrStyledShape&, const SkMatrix& ctm);
36+
3337
const GrSurfaceProxyView* getViews(int* numActiveProxies) {
3438
*numActiveProxies = fAtlas->numActivePages();
3539
return fAtlas->getViews();
@@ -40,32 +44,34 @@ class GrSmallPathAtlasMgr : public GrOnFlushCallbackObject,
4044
// GrOnFlushCallbackObject overrides
4145
//
4246
// Note: because this class is associated with a path renderer we want it to be removed from
43-
// the list of active OnFlushBackkbackObjects in an freeGpuResources call (i.e., we accept the
47+
// the list of active OnFlushCallbackObjects in an freeGpuResources call (i.e., we accept the
4448
// default retainOnFreeGpuResources implementation).
4549
void preFlush(GrOnFlushResourceProvider* onFlushRP,
46-
const uint32_t* /*opsTaskIDs*/, int /*numOpsTaskIDs*/) override {
50+
const uint32_t* /* opsTaskIDs */,
51+
int /* numOpsTaskIDs */) override {
4752
if (fAtlas) {
4853
fAtlas->instantiate(onFlushRP);
4954
}
5055
}
5156

5257
void postFlush(GrDeferredUploadToken startTokenForNextFlush,
53-
const uint32_t* /*opsTaskIDs*/, int /*numOpsTaskIDs*/) override {
58+
const uint32_t* /* opsTaskIDs */,
59+
int /* numOpsTaskIDs */) override {
5460
if (fAtlas) {
5561
fAtlas->compact(startTokenForNextFlush);
5662
}
5763
}
5864

59-
GrSmallPathShapeData* findOrCreate(const GrSmallPathShapeDataKey& key);
60-
6165
void deleteCacheEntry(GrSmallPathShapeData*);
6266

6367
private:
68+
GrSmallPathShapeData* findOrCreate(const GrSmallPathShapeDataKey&);
69+
70+
void evict(GrDrawOpAtlas::PlotLocator) override;
71+
6472
using ShapeCache = SkTDynamicHash<GrSmallPathShapeData, GrSmallPathShapeDataKey>;
6573
typedef SkTInternalLList<GrSmallPathShapeData> ShapeDataList;
6674

67-
void evict(GrDrawOpAtlas::PlotLocator plotLocator) override;
68-
6975
std::unique_ptr<GrDrawOpAtlas> fAtlas;
7076
ShapeCache fShapeCache;
7177
ShapeDataList fShapeList;

src/gpu/ops/GrSmallPathRenderer.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -320,11 +320,12 @@ class GrSmallPathRenderer::SmallPathOp final : public GrMeshDrawOp {
320320
}
321321
mipSize = newMipSize;
322322
}
323+
323324
SkScalar desiredDimension = std::min(mipSize, kMaxMIP);
325+
int ceilDesiredDimension = SkScalarCeilToInt(desiredDimension);
324326

325327
// check to see if df path is cached
326-
GrSmallPathShapeDataKey key(args.fShape, SkScalarCeilToInt(desiredDimension));
327-
shapeData = fAtlasMgr->findOrCreate(key);
328+
shapeData = fAtlasMgr->findOrCreate(args.fShape, ceilDesiredDimension);
328329
if (!shapeData->fAtlasLocator.plotLocator().isValid()) {
329330
SkScalar scale = desiredDimension / maxDim;
330331

@@ -333,16 +334,15 @@ class GrSmallPathRenderer::SmallPathOp final : public GrMeshDrawOp {
333334
fAtlasMgr->atlas(),
334335
shapeData,
335336
args.fShape,
336-
SkScalarCeilToInt(desiredDimension),
337+
ceilDesiredDimension,
337338
scale)) {
338339
fAtlasMgr->deleteCacheEntry(shapeData);
339340
continue;
340341
}
341342
}
342343
} else {
343344
// check to see if bitmap path is cached
344-
GrSmallPathShapeDataKey key(args.fShape, args.fViewMatrix);
345-
shapeData = fAtlasMgr->findOrCreate(key);
345+
shapeData = fAtlasMgr->findOrCreate(args.fShape, args.fViewMatrix);
346346
if (!shapeData->fAtlasLocator.plotLocator().isValid()) {
347347
if (!this->addBMPathToAtlas(target,
348348
&flushInfo,

src/gpu/ops/GrSmallPathShapeData.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
#include "src/gpu/geometry/GrStyledShape.h"
1111

12-
void GrSmallPathShapeDataKey::set(const GrStyledShape& shape, uint32_t dim) {
12+
GrSmallPathShapeDataKey::GrSmallPathShapeDataKey(const GrStyledShape& shape, uint32_t dim) {
1313
// Shapes' keys are for their pre-style geometry, but by now we shouldn't have any
1414
// relevant styling information.
1515
SkASSERT(shape.style().isSimpleFill());
@@ -20,7 +20,7 @@ void GrSmallPathShapeDataKey::set(const GrStyledShape& shape, uint32_t dim) {
2020
shape.writeUnstyledKey(&fKey[1]);
2121
}
2222

23-
void GrSmallPathShapeDataKey::set(const GrStyledShape& shape, const SkMatrix& ctm) {
23+
GrSmallPathShapeDataKey::GrSmallPathShapeDataKey(const GrStyledShape& shape, const SkMatrix& ctm) {
2424
// Shapes' keys are for their pre-style geometry, but by now we shouldn't have any
2525
// relevant styling information.
2626
SkASSERT(shape.style().isSimpleFill());

src/gpu/ops/GrSmallPathShapeData.h

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
/*
32
* Copyright 2020 Google Inc.
43
*
@@ -16,24 +15,19 @@ class GrStyledShape;
1615

1716
class GrSmallPathShapeDataKey {
1817
public:
19-
GrSmallPathShapeDataKey () {}
20-
GrSmallPathShapeDataKey (const GrSmallPathShapeDataKey & that) { *this = that; }
21-
GrSmallPathShapeDataKey (const GrStyledShape& shape, uint32_t dim) { this->set(shape, dim); }
22-
GrSmallPathShapeDataKey (const GrStyledShape& shape, const SkMatrix& ctm) {
23-
this->set(shape, ctm);
24-
}
25-
26-
GrSmallPathShapeDataKey & operator=(const GrSmallPathShapeDataKey & that) {
18+
// TODO: add a move variant
19+
GrSmallPathShapeDataKey(const GrSmallPathShapeDataKey& that) {
2720
fKey.reset(that.fKey.count());
2821
memcpy(fKey.get(), that.fKey.get(), fKey.count() * sizeof(uint32_t));
29-
return *this;
3022
}
3123

24+
GrSmallPathShapeDataKey& operator=(const GrSmallPathShapeDataKey&) = delete;
25+
3226
// for SDF paths
33-
void set(const GrStyledShape&, uint32_t dim);
27+
GrSmallPathShapeDataKey(const GrStyledShape&, uint32_t dim);
3428

3529
// for bitmap paths
36-
void set(const GrStyledShape&, const SkMatrix& ctm);
30+
GrSmallPathShapeDataKey(const GrStyledShape&, const SkMatrix& ctm);
3731

3832
bool operator==(const GrSmallPathShapeDataKey & that) const {
3933
return fKey.count() == that.fKey.count() &&
@@ -50,9 +44,9 @@ class GrSmallPathShapeDataKey {
5044
SkAutoSTArray<24, uint32_t> fKey;
5145
};
5246

53-
class GrSmallPathShapeData {
47+
class GrSmallPathShapeData {
5448
public:
55-
GrSmallPathShapeData(const GrSmallPathShapeDataKey &key) : fKey(key) {}
49+
GrSmallPathShapeData(const GrSmallPathShapeDataKey& key) : fKey(key) {}
5650

5751
const GrSmallPathShapeDataKey fKey;
5852
SkRect fBounds;

0 commit comments

Comments
 (0)