Move more classes to skgpu::v1 namespace
Bug: skia:11837
Change-Id: If0bfb3009693b203b2080a1d43cc3b1865c3ab9e
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/448274
Reviewed-by: Michael Ludwig <michaelludwig@google.com>
Reviewed-by: Brian Salomon <bsalomon@google.com>
Commit-Queue: Robert Phillips <robertphillips@google.com>
diff --git a/src/gpu/GrDirectContext.cpp b/src/gpu/GrDirectContext.cpp
index 4ada100..cc410a3 100644
--- a/src/gpu/GrDirectContext.cpp
+++ b/src/gpu/GrDirectContext.cpp
@@ -29,14 +29,16 @@
#include "src/gpu/text/GrStrikeCache.h"
#include "src/image/SkImage_GpuBase.h"
#if SK_GPU_V1
-#include "src/gpu/ops/GrSmallPathAtlasMgr.h"
+#include "src/gpu/ops/SmallPathAtlasMgr.h"
#else
// A vestigial definition for v2 that will never be instantiated
-class GrSmallPathAtlasMgr {
+namespace skgpu::v1 {
+class SmallPathAtlasMgr {
public:
- GrSmallPathAtlasMgr() { SkASSERT(0); }
+ SmallPathAtlasMgr() { SkASSERT(0); }
void reset() { SkASSERT(0); }
};
+}
#endif
#ifdef SK_METAL
#include "include/gpu/mtl/GrMtlBackendContext.h"
@@ -374,10 +376,10 @@
return true;
}
-GrSmallPathAtlasMgr* GrDirectContext::onGetSmallPathAtlasMgr() {
+skgpu::v1::SmallPathAtlasMgr* GrDirectContext::onGetSmallPathAtlasMgr() {
#if SK_GPU_V1
if (!fSmallPathAtlasMgr) {
- fSmallPathAtlasMgr = std::make_unique<GrSmallPathAtlasMgr>();
+ fSmallPathAtlasMgr = std::make_unique<skgpu::v1::SmallPathAtlasMgr>();
this->priv().addOnFlushCallbackObject(fSmallPathAtlasMgr.get());
}
diff --git a/src/gpu/GrDirectContextPriv.h b/src/gpu/GrDirectContextPriv.h
index 45c0e5b..5764310 100644
--- a/src/gpu/GrDirectContextPriv.h
+++ b/src/gpu/GrDirectContextPriv.h
@@ -93,7 +93,7 @@
}
// This accessor should only ever be called by the GrOpFlushState.
- GrSmallPathAtlasMgr* getSmallPathAtlasMgr() {
+ skgpu::v1::SmallPathAtlasMgr* getSmallPathAtlasMgr() {
return this->context()->onGetSmallPathAtlasMgr();
}
diff --git a/src/gpu/GrMeshDrawTarget.h b/src/gpu/GrMeshDrawTarget.h
index 54fac0b..ff7c9df 100644
--- a/src/gpu/GrMeshDrawTarget.h
+++ b/src/gpu/GrMeshDrawTarget.h
@@ -12,10 +12,11 @@
#include "src/gpu/GrSimpleMesh.h"
class GrAtlasManager;
-class GrSmallPathAtlasMgr;
class GrStrikeCache;
class GrThreadSafeCache;
+namespace skgpu { namespace v1 { class SmallPathAtlasMgr; }}
+
/*
* Abstract interface that supports creating vertices, indices, and meshes, as well as
* invoking GPU draw operations.
@@ -124,7 +125,7 @@
virtual GrStrikeCache* strikeCache() const = 0;
virtual GrAtlasManager* atlasManager() const = 0;
- virtual GrSmallPathAtlasMgr* smallPathAtlasManager() const = 0;
+ virtual skgpu::v1::SmallPathAtlasMgr* smallPathAtlasManager() const = 0;
// This should be called during onPrepare of a GrOp. The caller should add any proxies to the
// array it will use that it did not access during a call to visitProxies. This is usually the
diff --git a/src/gpu/GrOpFlushState.cpp b/src/gpu/GrOpFlushState.cpp
index 4ce2094..ee1a7eb 100644
--- a/src/gpu/GrOpFlushState.cpp
+++ b/src/gpu/GrOpFlushState.cpp
@@ -221,7 +221,7 @@
return fGpu->getContext()->priv().getAtlasManager();
}
-GrSmallPathAtlasMgr* GrOpFlushState::smallPathAtlasManager() const {
+skgpu::v1::SmallPathAtlasMgr* GrOpFlushState::smallPathAtlasManager() const {
return fGpu->getContext()->priv().getSmallPathAtlasMgr();
}
diff --git a/src/gpu/GrOpFlushState.h b/src/gpu/GrOpFlushState.h
index eb5d81b..5a0dc29 100644
--- a/src/gpu/GrOpFlushState.h
+++ b/src/gpu/GrOpFlushState.h
@@ -182,9 +182,9 @@
GrStrikeCache* strikeCache() const final;
// At this point we know we're flushing so full access to the GrAtlasManager and
- // GrSmallPathAtlasMgr is required (and permissible).
+ // SmallPathAtlasMgr is required (and permissible).
GrAtlasManager* atlasManager() const final;
- GrSmallPathAtlasMgr* smallPathAtlasManager() const final;
+ skgpu::v1::SmallPathAtlasMgr* smallPathAtlasManager() const final;
/** GrMeshDrawTarget override. */
SkArenaAlloc* allocator() override { return &fArena; }
diff --git a/src/gpu/mock/GrMockOpTarget.h b/src/gpu/mock/GrMockOpTarget.h
index f9ff83b..be9cd23 100644
--- a/src/gpu/mock/GrMockOpTarget.h
+++ b/src/gpu/mock/GrMockOpTarget.h
@@ -34,7 +34,7 @@
GrResourceProvider* resourceProvider() const override {
return fMockContext->priv().resourceProvider();
}
- GrSmallPathAtlasMgr* smallPathAtlasManager() const override { return nullptr; }
+ skgpu::v1::SmallPathAtlasMgr* smallPathAtlasManager() const override { return nullptr; }
void resetAllocator() { fAllocator.reset(); }
SkArenaAlloc* allocator() override { return &fAllocator; }
void putBackVertices(int vertices, size_t vertexStride) override { /* no-op */ }
diff --git a/src/gpu/ops/GrSmallPathShapeData.h b/src/gpu/ops/GrSmallPathShapeData.h
deleted file mode 100644
index 472b4cf..0000000
--- a/src/gpu/ops/GrSmallPathShapeData.h
+++ /dev/null
@@ -1,66 +0,0 @@
-/*
- * Copyright 2020 Google Inc.
- *
- * Use of this source code is governed by a BSD-style license that can be
- * found in the LICENSE file.
- */
-
-#ifndef GrSmallPathShapeData_DEFINED
-#define GrSmallPathShapeData_DEFINED
-
-#include "src/core/SkOpts.h"
-#include "src/gpu/GrDrawOpAtlas.h"
-
-class GrStyledShape;
-
-class GrSmallPathShapeDataKey {
-public:
- // TODO: add a move variant
- GrSmallPathShapeDataKey(const GrSmallPathShapeDataKey& that) {
- fKey.reset(that.fKey.count());
- memcpy(fKey.get(), that.fKey.get(), fKey.count() * sizeof(uint32_t));
- }
-
- GrSmallPathShapeDataKey& operator=(const GrSmallPathShapeDataKey&) = delete;
-
- // for SDF paths
- GrSmallPathShapeDataKey(const GrStyledShape&, uint32_t dim);
-
- // for bitmap paths
- GrSmallPathShapeDataKey(const GrStyledShape&, const SkMatrix& ctm);
-
- bool operator==(const GrSmallPathShapeDataKey & that) const {
- return fKey.count() == that.fKey.count() &&
- 0 == memcmp(fKey.get(), that.fKey.get(), sizeof(uint32_t) * fKey.count());
- }
-
- int count32() const { return fKey.count(); }
- const uint32_t* data() const { return fKey.get(); }
-
-private:
- // The key is composed of the GrStyledShape's key, and either the dimensions of the DF
- // generated for the path (32x32 max, 64x64 max, 128x128 max) if an SDF image or
- // the matrix for the path with only fractional translation.
- SkAutoSTArray<24, uint32_t> fKey;
-};
-
-class GrSmallPathShapeData {
-public:
- GrSmallPathShapeData(const GrSmallPathShapeDataKey& key) : fKey(key) {}
-
- const GrSmallPathShapeDataKey fKey;
- SkRect fBounds;
- GrDrawOpAtlas::AtlasLocator fAtlasLocator;
-
- SK_DECLARE_INTERNAL_LLIST_INTERFACE(GrSmallPathShapeData);
-
- static inline const GrSmallPathShapeDataKey& GetKey(const GrSmallPathShapeData& data) {
- return data.fKey;
- }
-
- static inline uint32_t Hash(const GrSmallPathShapeDataKey& key) {
- return SkOpts::hash(key.data(), sizeof(uint32_t) * key.count32());
- }
-};
-
-#endif
diff --git a/src/gpu/ops/GrSmallPathAtlasMgr.cpp b/src/gpu/ops/SmallPathAtlasMgr.cpp
similarity index 64%
rename from src/gpu/ops/GrSmallPathAtlasMgr.cpp
rename to src/gpu/ops/SmallPathAtlasMgr.cpp
index 633e411..bdd8027 100644
--- a/src/gpu/ops/GrSmallPathAtlasMgr.cpp
+++ b/src/gpu/ops/SmallPathAtlasMgr.cpp
@@ -5,26 +5,28 @@
* found in the LICENSE file.
*/
-#include "src/gpu/ops/GrSmallPathAtlasMgr.h"
+#include "src/gpu/ops/SmallPathAtlasMgr.h"
#include "src/gpu/geometry/GrStyledShape.h"
-#include "src/gpu/ops/GrSmallPathShapeData.h"
+#include "src/gpu/ops/SmallPathShapeData.h"
#ifdef DF_PATH_TRACKING
static int g_NumCachedShapes = 0;
static int g_NumFreedShapes = 0;
#endif
-GrSmallPathAtlasMgr::GrSmallPathAtlasMgr() {}
+namespace skgpu::v1 {
-GrSmallPathAtlasMgr::~GrSmallPathAtlasMgr() {
+SmallPathAtlasMgr::SmallPathAtlasMgr() {}
+
+SmallPathAtlasMgr::~SmallPathAtlasMgr() {
this->reset();
}
-void GrSmallPathAtlasMgr::reset() {
+void SmallPathAtlasMgr::reset() {
ShapeDataList::Iter iter;
iter.init(fShapeList, ShapeDataList::Iter::kHead_IterStart);
- GrSmallPathShapeData* shapeData;
+ SmallPathShapeData* shapeData;
while ((shapeData = iter.get())) {
iter.next();
delete shapeData;
@@ -40,7 +42,7 @@
fAtlas = nullptr;
}
-bool GrSmallPathAtlasMgr::initAtlas(GrProxyProvider* proxyProvider, const GrCaps* caps) {
+bool SmallPathAtlasMgr::initAtlas(GrProxyProvider* proxyProvider, const GrCaps* caps) {
if (fAtlas) {
return true;
}
@@ -62,17 +64,17 @@
return SkToBool(fAtlas);
}
-void GrSmallPathAtlasMgr::deleteCacheEntry(GrSmallPathShapeData* shapeData) {
+void SmallPathAtlasMgr::deleteCacheEntry(SmallPathShapeData* shapeData) {
fShapeCache.remove(shapeData->fKey);
fShapeList.remove(shapeData);
delete shapeData;
}
-GrSmallPathShapeData* GrSmallPathAtlasMgr::findOrCreate(const GrSmallPathShapeDataKey& key) {
+SmallPathShapeData* SmallPathAtlasMgr::findOrCreate(const SmallPathShapeDataKey& key) {
auto shapeData = fShapeCache.find(key);
if (!shapeData) {
// TODO: move the key into the ctor
- shapeData = new GrSmallPathShapeData(key);
+ shapeData = new SmallPathShapeData(key);
fShapeCache.add(shapeData);
fShapeList.addToTail(shapeData);
#ifdef DF_PATH_TRACKING
@@ -85,40 +87,40 @@
return shapeData;
}
-GrSmallPathShapeData* GrSmallPathAtlasMgr::findOrCreate(const GrStyledShape& shape,
- int desiredDimension) {
- GrSmallPathShapeDataKey key(shape, desiredDimension);
+SmallPathShapeData* SmallPathAtlasMgr::findOrCreate(const GrStyledShape& shape,
+ int desiredDimension) {
+ SmallPathShapeDataKey key(shape, desiredDimension);
// TODO: move the key into 'findOrCreate'
return this->findOrCreate(key);
}
-GrSmallPathShapeData* GrSmallPathAtlasMgr::findOrCreate(const GrStyledShape& shape,
- const SkMatrix& ctm) {
- GrSmallPathShapeDataKey key(shape, ctm);
+SmallPathShapeData* SmallPathAtlasMgr::findOrCreate(const GrStyledShape& shape,
+ const SkMatrix& ctm) {
+ SmallPathShapeDataKey key(shape, ctm);
// TODO: move the key into 'findOrCreate'
return this->findOrCreate(key);
}
-GrDrawOpAtlas::ErrorCode GrSmallPathAtlasMgr::addToAtlas(GrResourceProvider* resourceProvider,
- GrDeferredUploadTarget* target,
- int width, int height, const void* image,
- GrDrawOpAtlas::AtlasLocator* locator) {
+GrDrawOpAtlas::ErrorCode SmallPathAtlasMgr::addToAtlas(GrResourceProvider* resourceProvider,
+ GrDeferredUploadTarget* target,
+ int width, int height, const void* image,
+ GrDrawOpAtlas::AtlasLocator* locator) {
return fAtlas->addToAtlas(resourceProvider, target, width, height, image, locator);
}
-void GrSmallPathAtlasMgr::setUseToken(GrSmallPathShapeData* shapeData,
- GrDeferredUploadToken token) {
+void SmallPathAtlasMgr::setUseToken(SmallPathShapeData* shapeData,
+ GrDeferredUploadToken token) {
fAtlas->setLastUseToken(shapeData->fAtlasLocator, token);
}
// Callback to clear out internal path cache when eviction occurs
-void GrSmallPathAtlasMgr::evict(GrDrawOpAtlas::PlotLocator plotLocator) {
+void SmallPathAtlasMgr::evict(GrDrawOpAtlas::PlotLocator plotLocator) {
// remove any paths that use this plot
ShapeDataList::Iter iter;
iter.init(fShapeList, ShapeDataList::Iter::kHead_IterStart);
- GrSmallPathShapeData* shapeData;
+ SmallPathShapeData* shapeData;
while ((shapeData = iter.get())) {
iter.next();
if (plotLocator == shapeData->fAtlasLocator.plotLocator()) {
@@ -131,3 +133,5 @@
}
}
}
+
+} // namespace skgpu::v1
diff --git a/src/gpu/ops/GrSmallPathAtlasMgr.h b/src/gpu/ops/SmallPathAtlasMgr.h
similarity index 68%
rename from src/gpu/ops/GrSmallPathAtlasMgr.h
rename to src/gpu/ops/SmallPathAtlasMgr.h
index 3b8f403..ec229ae 100644
--- a/src/gpu/ops/GrSmallPathAtlasMgr.h
+++ b/src/gpu/ops/SmallPathAtlasMgr.h
@@ -5,18 +5,21 @@
* found in the LICENSE file.
*/
-#ifndef GrSmallPathAtlasMgr_DEFINED
-#define GrSmallPathAtlasMgr_DEFINED
+#ifndef SmallPathAtlasMgr_DEFINED
+#define SmallPathAtlasMgr_DEFINED
#include "src/core/SkTDynamicHash.h"
#include "src/core/SkTInternalLList.h"
#include "src/gpu/GrDrawOpAtlas.h"
#include "src/gpu/GrOnFlushResourceProvider.h"
-class GrSmallPathShapeData;
-class GrSmallPathShapeDataKey;
class GrStyledShape;
+namespace skgpu::v1 {
+
+class SmallPathShapeData;
+class SmallPathShapeDataKey;
+
/**
* This class manages the small path renderer's atlas. It solely operates at flush time. Thus
* the small path renderer will generate ops at record time but the location of the ops' source
@@ -25,26 +28,26 @@
*
* TODO: investigate fusing this class and the GrAtlasManager.
*/
-class GrSmallPathAtlasMgr : public GrOnFlushCallbackObject,
- public GrDrawOpAtlas::EvictionCallback,
- public GrDrawOpAtlas::GenerationCounter {
+class SmallPathAtlasMgr final : public GrOnFlushCallbackObject,
+ public GrDrawOpAtlas::EvictionCallback,
+ public GrDrawOpAtlas::GenerationCounter {
public:
- GrSmallPathAtlasMgr();
- ~GrSmallPathAtlasMgr() override;
+ SmallPathAtlasMgr();
+ ~SmallPathAtlasMgr() override;
void reset();
bool initAtlas(GrProxyProvider*, const GrCaps*);
- GrSmallPathShapeData* findOrCreate(const GrStyledShape&, int desiredDimension);
- GrSmallPathShapeData* findOrCreate(const GrStyledShape&, const SkMatrix& ctm);
+ SmallPathShapeData* findOrCreate(const GrStyledShape&, int desiredDimension);
+ SmallPathShapeData* findOrCreate(const GrStyledShape&, const SkMatrix& ctm);
GrDrawOpAtlas::ErrorCode addToAtlas(GrResourceProvider*,
GrDeferredUploadTarget*,
int width, int height, const void* image,
GrDrawOpAtlas::AtlasLocator*);
- void setUseToken(GrSmallPathShapeData*, GrDeferredUploadToken);
+ void setUseToken(SmallPathShapeData*, GrDeferredUploadToken);
// GrOnFlushCallbackObject overrides
void preFlush(GrOnFlushResourceProvider* onFlushRP,
@@ -70,19 +73,21 @@
return fAtlas->getViews();
}
- void deleteCacheEntry(GrSmallPathShapeData*);
+ void deleteCacheEntry(SmallPathShapeData*);
private:
- GrSmallPathShapeData* findOrCreate(const GrSmallPathShapeDataKey&);
+ SmallPathShapeData* findOrCreate(const SmallPathShapeDataKey&);
void evict(GrDrawOpAtlas::PlotLocator) override;
- using ShapeCache = SkTDynamicHash<GrSmallPathShapeData, GrSmallPathShapeDataKey>;
- typedef SkTInternalLList<GrSmallPathShapeData> ShapeDataList;
+ using ShapeCache = SkTDynamicHash<SmallPathShapeData, SmallPathShapeDataKey>;
+ typedef SkTInternalLList<SmallPathShapeData> ShapeDataList;
std::unique_ptr<GrDrawOpAtlas> fAtlas;
ShapeCache fShapeCache;
ShapeDataList fShapeList;
};
-#endif // GrSmallPathAtlasMgr_DEFINED
+} // namespace skgpu::v1
+
+#endif // SmallPathAtlasMgr_DEFINED
diff --git a/src/gpu/ops/SmallPathRenderer.cpp b/src/gpu/ops/SmallPathRenderer.cpp
index b6663a0..b3eb017 100644
--- a/src/gpu/ops/SmallPathRenderer.cpp
+++ b/src/gpu/ops/SmallPathRenderer.cpp
@@ -28,8 +28,8 @@
#include "src/gpu/geometry/GrStyledShape.h"
#include "src/gpu/ops/GrMeshDrawOp.h"
#include "src/gpu/ops/GrSimpleMeshDrawOpHelperWithStencil.h"
-#include "src/gpu/ops/GrSmallPathAtlasMgr.h"
-#include "src/gpu/ops/GrSmallPathShapeData.h"
+#include "src/gpu/ops/SmallPathAtlasMgr.h"
+#include "src/gpu/ops/SmallPathShapeData.h"
#include "src/gpu/v1/SurfaceDrawContext_v1.h"
namespace {
@@ -142,7 +142,7 @@
void onPrepareDraws(GrMeshDrawTarget* target) override {
int instanceCount = fShapes.count();
- GrSmallPathAtlasMgr* atlasMgr = target->smallPathAtlasManager();
+ auto atlasMgr = target->smallPathAtlasManager();
if (!atlasMgr) {
return;
}
@@ -223,7 +223,7 @@
for (int i = 0; i < instanceCount; i++) {
const Entry& args = fShapes[i];
- GrSmallPathShapeData* shapeData;
+ skgpu::v1::SmallPathShapeData* shapeData;
if (fUsesDistanceField) {
// get mip level
SkScalar maxScale;
@@ -318,10 +318,10 @@
bool addToAtlasWithRetry(GrMeshDrawTarget* target,
FlushInfo* flushInfo,
- GrSmallPathAtlasMgr* atlasMgr,
+ skgpu::v1::SmallPathAtlasMgr* atlasMgr,
int width, int height, const void* image,
const SkRect& bounds, int srcInset,
- GrSmallPathShapeData* shapeData) const {
+ skgpu::v1::SmallPathShapeData* shapeData) const {
auto resourceProvider = target->resourceProvider();
auto uploadTarget = target->deferredUploadTarget();
@@ -344,9 +344,13 @@
return GrDrawOpAtlas::ErrorCode::kSucceeded == code;
}
- bool addDFPathToAtlas(GrMeshDrawTarget* target, FlushInfo* flushInfo,
- GrSmallPathAtlasMgr* atlasMgr, GrSmallPathShapeData* shapeData,
- const GrStyledShape& shape, uint32_t dimension, SkScalar scale) const {
+ bool addDFPathToAtlas(GrMeshDrawTarget* target,
+ FlushInfo* flushInfo,
+ skgpu::v1::SmallPathAtlasMgr* atlasMgr,
+ skgpu::v1::SmallPathShapeData* shapeData,
+ const GrStyledShape& shape,
+ uint32_t dimension,
+ SkScalar scale) const {
const SkRect& bounds = shape.bounds();
@@ -436,9 +440,12 @@
drawBounds, SK_DistanceFieldPad, shapeData);
}
- bool addBMPathToAtlas(GrMeshDrawTarget* target, FlushInfo* flushInfo,
- GrSmallPathAtlasMgr* atlasMgr, GrSmallPathShapeData* shapeData,
- const GrStyledShape& shape, const SkMatrix& ctm) const {
+ bool addBMPathToAtlas(GrMeshDrawTarget* target,
+ FlushInfo* flushInfo,
+ skgpu::v1::SmallPathAtlasMgr* atlasMgr,
+ skgpu::v1::SmallPathShapeData* shapeData,
+ const GrStyledShape& shape,
+ const SkMatrix& ctm) const {
const SkRect& bounds = shape.bounds();
if (bounds.isEmpty()) {
return false;
@@ -506,7 +513,7 @@
void writePathVertices(GrVertexWriter& vertices,
const GrVertexColor& color,
const SkMatrix& ctm,
- const GrSmallPathShapeData* shapeData) const {
+ const skgpu::v1::SmallPathShapeData* shapeData) const {
SkRect translatedBounds(shapeData->fBounds);
if (!fUsesDistanceField) {
translatedBounds.offset(SkScalarFloorToScalar(ctm.get(SkMatrix::kMTransX)),
@@ -528,7 +535,7 @@
}
void flush(GrMeshDrawTarget* target, FlushInfo* flushInfo) const {
- GrSmallPathAtlasMgr* atlasMgr = target->smallPathAtlasManager();
+ auto atlasMgr = target->smallPathAtlasManager();
if (!atlasMgr) {
return;
}
diff --git a/src/gpu/ops/GrSmallPathShapeData.cpp b/src/gpu/ops/SmallPathShapeData.cpp
similarity index 85%
rename from src/gpu/ops/GrSmallPathShapeData.cpp
rename to src/gpu/ops/SmallPathShapeData.cpp
index 5356569..1f8ed0b 100644
--- a/src/gpu/ops/GrSmallPathShapeData.cpp
+++ b/src/gpu/ops/SmallPathShapeData.cpp
@@ -5,11 +5,13 @@
* found in the LICENSE file.
*/
-#include "src/gpu/ops/GrSmallPathShapeData.h"
+#include "src/gpu/ops/SmallPathShapeData.h"
#include "src/gpu/geometry/GrStyledShape.h"
-GrSmallPathShapeDataKey::GrSmallPathShapeDataKey(const GrStyledShape& shape, uint32_t dim) {
+namespace skgpu::v1 {
+
+SmallPathShapeDataKey::SmallPathShapeDataKey(const GrStyledShape& shape, uint32_t dim) {
// Shapes' keys are for their pre-style geometry, but by now we shouldn't have any
// relevant styling information.
SkASSERT(shape.style().isSimpleFill());
@@ -20,7 +22,7 @@
shape.writeUnstyledKey(&fKey[1]);
}
-GrSmallPathShapeDataKey::GrSmallPathShapeDataKey(const GrStyledShape& shape, const SkMatrix& ctm) {
+SmallPathShapeDataKey::SmallPathShapeDataKey(const GrStyledShape& shape, const SkMatrix& ctm) {
// Shapes' keys are for their pre-style geometry, but by now we shouldn't have any
// relevant styling information.
SkASSERT(shape.style().isSimpleFill());
@@ -46,3 +48,5 @@
fKey[4] = fracX | (fracY >> 8);
shape.writeUnstyledKey(&fKey[5]);
}
+
+} // namespace skgpu::v1
diff --git a/src/gpu/ops/SmallPathShapeData.h b/src/gpu/ops/SmallPathShapeData.h
new file mode 100644
index 0000000..1bf5bef
--- /dev/null
+++ b/src/gpu/ops/SmallPathShapeData.h
@@ -0,0 +1,70 @@
+/*
+ * Copyright 2020 Google Inc.
+ *
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+#ifndef SmallPathShapeData_DEFINED
+#define SmallPathShapeData_DEFINED
+
+#include "src/core/SkOpts.h"
+#include "src/gpu/GrDrawOpAtlas.h"
+
+class GrStyledShape;
+
+namespace skgpu::v1 {
+
+class SmallPathShapeDataKey {
+public:
+ // TODO: add a move variant
+ SmallPathShapeDataKey(const SmallPathShapeDataKey& that) {
+ fKey.reset(that.fKey.count());
+ memcpy(fKey.get(), that.fKey.get(), fKey.count() * sizeof(uint32_t));
+ }
+
+ SmallPathShapeDataKey& operator=(const SmallPathShapeDataKey&) = delete;
+
+ // for SDF paths
+ SmallPathShapeDataKey(const GrStyledShape&, uint32_t dim);
+
+ // for bitmap paths
+ SmallPathShapeDataKey(const GrStyledShape&, const SkMatrix& ctm);
+
+ bool operator==(const SmallPathShapeDataKey & that) const {
+ return fKey.count() == that.fKey.count() &&
+ 0 == memcmp(fKey.get(), that.fKey.get(), sizeof(uint32_t) * fKey.count());
+ }
+
+ int count32() const { return fKey.count(); }
+ const uint32_t* data() const { return fKey.get(); }
+
+private:
+ // The key is composed of the GrStyledShape's key, and either the dimensions of the DF
+ // generated for the path (32x32 max, 64x64 max, 128x128 max) if an SDF image or
+ // the matrix for the path with only fractional translation.
+ SkAutoSTArray<24, uint32_t> fKey;
+};
+
+class SmallPathShapeData {
+public:
+ SmallPathShapeData(const SmallPathShapeDataKey& key) : fKey(key) {}
+
+ const SmallPathShapeDataKey fKey;
+ SkRect fBounds;
+ GrDrawOpAtlas::AtlasLocator fAtlasLocator;
+
+ SK_DECLARE_INTERNAL_LLIST_INTERFACE(SmallPathShapeData);
+
+ static inline const SmallPathShapeDataKey& GetKey(const SmallPathShapeData& data) {
+ return data.fKey;
+ }
+
+ static inline uint32_t Hash(const SmallPathShapeDataKey& key) {
+ return SkOpts::hash(key.data(), sizeof(uint32_t) * key.count32());
+ }
+};
+
+} // namespace skgpu::v1
+
+#endif // SmallPathShapeData_DEFINED