initClassID no longer auto-allocates ids
Auto-allocated IDs mean that the IDs depend upon the order in which
classes happen to get initialized and are therefore not consistent
from run to run. This change paves the way for a persistent shader
cache by fixing the IDs in an enum.
Bug: skia:
Change-Id: I3e923c6c54f41b3b3eb616458abee83e0909c09f
Reviewed-on: https://skia-review.googlesource.com/56401
Commit-Queue: Ethan Nicholas <ethannicholas@google.com>
Reviewed-by: Brian Salomon <bsalomon@google.com>
diff --git a/tests/GLProgramsTest.cpp b/tests/GLProgramsTest.cpp
index 522bb71..55ffca9 100644
--- a/tests/GLProgramsTest.cpp
+++ b/tests/GLProgramsTest.cpp
@@ -78,7 +78,7 @@
std::unique_ptr<GrFragmentProcessor> clone() const override { return Make(); }
private:
- BigKeyProcessor() : INHERITED(kNone_OptimizationFlags) { this->initClassID<BigKeyProcessor>(); }
+ BigKeyProcessor() : INHERITED(kBigKeyProcessor_ClassID, kNone_OptimizationFlags) { }
virtual void onGetGLSLProcessorKey(const GrShaderCaps& caps,
GrProcessorKeyBuilder* b) const override {
GLBigKeyProcessor::GenKey(*this, caps, b);
@@ -126,8 +126,7 @@
};
BlockInputFragmentProcessor(std::unique_ptr<GrFragmentProcessor> child)
- : INHERITED(kNone_OptimizationFlags) {
- this->initClassID<BlockInputFragmentProcessor>();
+ : INHERITED(kBlockInputFragmentProcessor_ClassID, kNone_OptimizationFlags) {
this->registerChildProcessor(std::move(child));
}
diff --git a/tests/GrMeshTest.cpp b/tests/GrMeshTest.cpp
index 1ae3926..c2b1f2d 100644
--- a/tests/GrMeshTest.cpp
+++ b/tests/GrMeshTest.cpp
@@ -281,7 +281,8 @@
class GrMeshTestProcessor : public GrGeometryProcessor {
public:
GrMeshTestProcessor(bool instanced, bool hasVertexBuffer)
- : fInstanceLocation(nullptr)
+ : INHERITED(kGrMeshTestProcessor_ClassID)
+ , fInstanceLocation(nullptr)
, fVertex(nullptr)
, fColor(nullptr) {
if (instanced) {
@@ -294,7 +295,6 @@
fVertex = &this->addVertexAttrib("vertex", kHalf2_GrVertexAttribType);
fColor = &this->addVertexAttrib("color", kUByte4_norm_GrVertexAttribType);
}
- this->initClassID<GrMeshTestProcessor>();
}
const char* name() const override { return "GrMeshTest Processor"; }
diff --git a/tests/GrPipelineDynamicStateTest.cpp b/tests/GrPipelineDynamicStateTest.cpp
index 4b8621d..6b518ab 100644
--- a/tests/GrPipelineDynamicStateTest.cpp
+++ b/tests/GrPipelineDynamicStateTest.cpp
@@ -59,10 +59,9 @@
class GrPipelineDynamicStateTestProcessor : public GrGeometryProcessor {
public:
GrPipelineDynamicStateTestProcessor()
- : fVertex(this->addVertexAttrib("vertex", kHalf2_GrVertexAttribType))
- , fColor(this->addVertexAttrib("color", kUByte4_norm_GrVertexAttribType)) {
- this->initClassID<GrPipelineDynamicStateTestProcessor>();
- }
+ : INHERITED(kGrPipelineDynamicStateTestProcessor_ClassID)
+ , fVertex(this->addVertexAttrib("vertex", kHalf2_GrVertexAttribType))
+ , fColor(this->addVertexAttrib("color", kUByte4_norm_GrVertexAttribType)) {}
const char* name() const override { return "GrPipelineDynamicStateTest Processor"; }
diff --git a/tests/ImageStorageTest.cpp b/tests/ImageStorageTest.cpp
index 445a72f..a8704c6 100644
--- a/tests/ImageStorageTest.cpp
+++ b/tests/ImageStorageTest.cpp
@@ -33,16 +33,14 @@
private:
TestFP(sk_sp<GrTextureProxy> proxy, GrSLMemoryModel mm, GrSLRestrict restrict)
- : INHERITED(kNone_OptimizationFlags)
+ : INHERITED(kTestFP_ClassID, kNone_OptimizationFlags)
, fImageStorageAccess(std::move(proxy), kRead_GrIOType, mm, restrict) {
- this->initClassID<TestFP>();
this->addImageStorageAccess(&fImageStorageAccess);
}
explicit TestFP(const TestFP& that)
- : INHERITED(that.optimizationFlags())
+ : INHERITED(kTestFP_ClassID, that.optimizationFlags())
, fImageStorageAccess(that.fImageStorageAccess) {
- this->initClassID<TestFP>();
this->addImageStorageAccess(&fImageStorageAccess);
}
diff --git a/tests/PrimitiveProcessorTest.cpp b/tests/PrimitiveProcessorTest.cpp
index 8898e35..004ec88 100644
--- a/tests/PrimitiveProcessorTest.cpp
+++ b/tests/PrimitiveProcessorTest.cpp
@@ -53,8 +53,8 @@
void onPrepareDraws(Target* target) override {
class GP : public GrGeometryProcessor {
public:
- GP(int numAttribs) {
- this->initClassID<GP>();
+ GP(int numAttribs)
+ : INHERITED(kGP_ClassID) {
SkASSERT(numAttribs > 1);
for (auto i = 0; i < numAttribs; ++i) {
fAttribNames.push_back().printf("attr%d", i);
@@ -89,6 +89,8 @@
private:
SkTArray<SkString> fAttribNames;
+
+ typedef GrGeometryProcessor INHERITED;
};
sk_sp<GrGeometryProcessor> gp(new GP(fNumAttribs));
QuadHelper helper;
diff --git a/tests/ProcessorTest.cpp b/tests/ProcessorTest.cpp
index 056302e..ba90dc2 100644
--- a/tests/ProcessorTest.cpp
+++ b/tests/ProcessorTest.cpp
@@ -97,8 +97,8 @@
TestFP(const SkTArray<sk_sp<GrTextureProxy>>& proxies,
const SkTArray<sk_sp<GrBuffer>>& buffers,
const SkTArray<Image>& images)
- : INHERITED(kNone_OptimizationFlags), fSamplers(4), fBuffers(4), fImages(4) {
- this->initClassID<TestFP>();
+ : INHERITED(kTestFP_ClassID, kNone_OptimizationFlags), fSamplers(4), fBuffers(4),
+ fImages(4) {
for (const auto& proxy : proxies) {
this->addTextureSampler(&fSamplers.emplace_back(proxy));
}
@@ -113,14 +113,14 @@
}
TestFP(std::unique_ptr<GrFragmentProcessor> child)
- : INHERITED(kNone_OptimizationFlags), fSamplers(4), fBuffers(4), fImages(4) {
- this->initClassID<TestFP>();
+ : INHERITED(kTestFP_ClassID, kNone_OptimizationFlags), fSamplers(4), fBuffers(4),
+ fImages(4) {
this->registerChildProcessor(std::move(child));
}
explicit TestFP(const TestFP& that)
- : INHERITED(that.optimizationFlags()), fSamplers(4), fBuffers(4), fImages(4) {
- this->initClassID<TestFP>();
+ : INHERITED(kTestFP_ClassID, that.optimizationFlags()), fSamplers(4), fBuffers(4),
+ fImages(4) {
for (int i = 0; i < that.fSamplers.count(); ++i) {
fSamplers.emplace_back(that.fSamplers[i]);
this->addTextureSampler(&fSamplers.back());
diff --git a/tests/SkSLFPTest.cpp b/tests/SkSLFPTest.cpp
index dc92795..3e95d99 100644
--- a/tests/SkSLFPTest.cpp
+++ b/tests/SkSLFPTest.cpp
@@ -93,8 +93,7 @@
" const char* name() const override { return \"Test\"; }\n"
"private:\n"
" GrTest()\n"
- " : INHERITED(kNone_OptimizationFlags) {\n"
- " this->initClassID<GrTest>();\n"
+ " : INHERITED(kGrTest_ClassID, kNone_OptimizationFlags) {\n"
" }\n"
" GrGLSLFragmentProcessor* onCreateGLSLInstance() const override;\n"
" void onGetGLSLProcessorKey(const GrShaderCaps&,GrProcessorKeyBuilder*) "
@@ -151,8 +150,7 @@
" return true;\n"
"}\n"
"GrTest::GrTest(const GrTest& src)\n"
- ": INHERITED(src.optimizationFlags()) {\n"
- " this->initClassID<GrTest>();\n"
+ ": INHERITED(kGrTest_ClassID, src.optimizationFlags()) {\n"
"}\n"
"std::unique_ptr<GrFragmentProcessor> GrTest::clone() const {\n"
" return std::unique_ptr<GrFragmentProcessor>(new GrTest(*this));\n"
@@ -279,7 +277,7 @@
"}",
*SkSL::ShaderCapsFactory::Default(),
{
- ": INHERITED(kNone_OptimizationFlags)\n , initializers section"
+ ": INHERITED(kGrTest_ClassID, kNone_OptimizationFlags)\n , initializers section"
},
{});
test(r,