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/src/shaders/gradients/SkGradientShader.cpp b/src/shaders/gradients/SkGradientShader.cpp
index 88990c7..87f1910 100644
--- a/src/shaders/gradients/SkGradientShader.cpp
+++ b/src/shaders/gradients/SkGradientShader.cpp
@@ -1697,8 +1697,8 @@
: kCompatibleWithCoverageAsAlpha_OptimizationFlag;
}
-GrGradientEffect::GrGradientEffect(const CreateArgs& args, bool isOpaque)
- : INHERITED(OptFlags(isOpaque)) {
+GrGradientEffect::GrGradientEffect(ClassID classID, const CreateArgs& args, bool isOpaque)
+ : INHERITED(classID, OptFlags(isOpaque)) {
const SkGradientShaderBase& shader(*args.fShader);
fIsOpaque = shader.isOpaque();
@@ -1815,7 +1815,7 @@
}
GrGradientEffect::GrGradientEffect(const GrGradientEffect& that)
- : INHERITED(OptFlags(that.fIsOpaque))
+ : INHERITED(that.classID(), OptFlags(that.fIsOpaque))
, fColors(that.fColors)
, fColors4f(that.fColors4f)
, fColorSpaceXform(that.fColorSpaceXform)
diff --git a/src/shaders/gradients/SkGradientShaderPriv.h b/src/shaders/gradients/SkGradientShaderPriv.h
index c5a9b17..30e9440 100644
--- a/src/shaders/gradients/SkGradientShaderPriv.h
+++ b/src/shaders/gradients/SkGradientShaderPriv.h
@@ -426,7 +426,7 @@
}
protected:
- GrGradientEffect(const CreateArgs&, bool isOpaque);
+ GrGradientEffect(ClassID classID, const CreateArgs&, bool isOpaque);
explicit GrGradientEffect(const GrGradientEffect&); // facilitates clone() implementations
#if GR_TEST_UTILS
diff --git a/src/shaders/gradients/SkLinearGradient.cpp b/src/shaders/gradients/SkLinearGradient.cpp
index 04e8282..8b439ce 100644
--- a/src/shaders/gradients/SkLinearGradient.cpp
+++ b/src/shaders/gradients/SkLinearGradient.cpp
@@ -112,13 +112,10 @@
private:
explicit GrLinearGradient(const CreateArgs& args)
- : INHERITED(args, args.fShader->colorsAreOpaque()) {
- this->initClassID<GrLinearGradient>();
+ : INHERITED(kGrLinearGradient_ClassID, args, args.fShader->colorsAreOpaque()) {
}
- explicit GrLinearGradient(const GrLinearGradient& that) : INHERITED(that) {
- this->initClassID<GrLinearGradient>();
- }
+ explicit GrLinearGradient(const GrLinearGradient& that) : INHERITED(that) {}
GrGLSLFragmentProcessor* onCreateGLSLInstance() const override;
diff --git a/src/shaders/gradients/SkRadialGradient.cpp b/src/shaders/gradients/SkRadialGradient.cpp
index 94d823c..5c31688 100644
--- a/src/shaders/gradients/SkRadialGradient.cpp
+++ b/src/shaders/gradients/SkRadialGradient.cpp
@@ -81,13 +81,9 @@
private:
explicit GrRadialGradient(const CreateArgs& args)
- : INHERITED(args, args.fShader->colorsAreOpaque()) {
- this->initClassID<GrRadialGradient>();
- }
+ : INHERITED(kGrRadialGradient_ClassID, args, args.fShader->colorsAreOpaque()) {}
- explicit GrRadialGradient(const GrRadialGradient& that) : INHERITED(that) {
- this->initClassID<GrRadialGradient>();
- }
+ explicit GrRadialGradient(const GrRadialGradient& that) : INHERITED(that) {}
GrGLSLFragmentProcessor* onCreateGLSLInstance() const override;
diff --git a/src/shaders/gradients/SkSweepGradient.cpp b/src/shaders/gradients/SkSweepGradient.cpp
index 0e2b785a..792024f 100644
--- a/src/shaders/gradients/SkSweepGradient.cpp
+++ b/src/shaders/gradients/SkSweepGradient.cpp
@@ -88,18 +88,14 @@
private:
explicit GrSweepGradient(const CreateArgs& args, SkScalar tBias, SkScalar tScale)
- : INHERITED(args, args.fShader->colorsAreOpaque())
+ : INHERITED(kGrSweepGradient_ClassID, args, args.fShader->colorsAreOpaque())
, fTBias(tBias)
- , fTScale(tScale){
- this->initClassID<GrSweepGradient>();
- }
+ , fTScale(tScale) {}
explicit GrSweepGradient(const GrSweepGradient& that)
: INHERITED(that)
, fTBias(that.fTBias)
- , fTScale(that.fTScale) {
- this->initClassID<GrSweepGradient>();
- }
+ , fTScale(that.fTScale) {}
GrGLSLFragmentProcessor* onCreateGLSLInstance() const override;
diff --git a/src/shaders/gradients/SkTwoPointConicalGradient_gpu.cpp b/src/shaders/gradients/SkTwoPointConicalGradient_gpu.cpp
index 37e0708..a08addb 100644
--- a/src/shaders/gradients/SkTwoPointConicalGradient_gpu.cpp
+++ b/src/shaders/gradients/SkTwoPointConicalGradient_gpu.cpp
@@ -93,13 +93,13 @@
}
explicit Edge2PtConicalEffect(const CreateArgs& args)
- : INHERITED(args, false /* opaque: draws transparent black outside of the cone. */) {
+ : INHERITED(kEdge2PtConicalEffect_ClassID, args,
+ false /* opaque: draws transparent black outside of the cone. */) {
const SkTwoPointConicalGradient& shader =
*static_cast<const SkTwoPointConicalGradient*>(args.fShader);
fCenterX1 = shader.getCenterX1();
fRadius0 = shader.getStartRadius();
fDiffRadius = shader.getDiffRadius();
- this->initClassID<Edge2PtConicalEffect>();
// We should only be calling this shader if we are degenerate case with touching circles
// When deciding if we are in edge case, we scaled by the end radius for cases when the
// start radius was close to zero, otherwise we scaled by the start radius. In addition
@@ -129,7 +129,6 @@
, fCenterX1(that.fCenterX1)
, fRadius0(that.fRadius0)
, fDiffRadius(that.fDiffRadius) {
- this->initClassID<Edge2PtConicalEffect>();
this->addCoordTransform(&fBTransform);
}
@@ -415,15 +414,14 @@
}
FocalOutside2PtConicalEffect(const CreateArgs& args, SkScalar focalX)
- : INHERITED(args, false /* opaque: draws transparent black outside of the cone. */)
+ : INHERITED(kFocalOutside2PtConicalEffect_ClassID, args,
+ false /* opaque: draws transparent black outside of the cone. */)
, fFocalX(focalX)
, fIsFlipped(IsFlipped(args)) {
- this->initClassID<FocalOutside2PtConicalEffect>();
}
explicit FocalOutside2PtConicalEffect(const FocalOutside2PtConicalEffect& that)
: INHERITED(that), fFocalX(that.fFocalX), fIsFlipped(that.fIsFlipped) {
- this->initClassID<FocalOutside2PtConicalEffect>();
}
GR_DECLARE_FRAGMENT_PROCESSOR_TEST
@@ -630,14 +628,11 @@
}
FocalInside2PtConicalEffect(const CreateArgs& args, SkScalar focalX)
- : INHERITED(args, args.fShader->colorsAreOpaque()), fFocalX(focalX) {
- this->initClassID<FocalInside2PtConicalEffect>();
- }
+ : INHERITED(kFocalInside2PtConicalEffect_ClassID, args,
+ args.fShader->colorsAreOpaque()), fFocalX(focalX) {}
explicit FocalInside2PtConicalEffect(const FocalInside2PtConicalEffect& that)
- : INHERITED(that), fFocalX(that.fFocalX) {
- this->initClassID<FocalInside2PtConicalEffect>();
- }
+ : INHERITED(that), fFocalX(that.fFocalX) {}
GR_DECLARE_FRAGMENT_PROCESSOR_TEST
@@ -880,14 +875,12 @@
}
CircleInside2PtConicalEffect(const CreateArgs& args, const CircleConicalInfo& info)
- : INHERITED(args, args.fShader->colorsAreOpaque()), fInfo(info) {
- this->initClassID<CircleInside2PtConicalEffect>();
+ : INHERITED(kCircleInside2PtConicalEffect_ClassID, args,
+ args.fShader->colorsAreOpaque()), fInfo(info) {
}
explicit CircleInside2PtConicalEffect(const CircleInside2PtConicalEffect& that)
- : INHERITED(that), fInfo(that.fInfo) {
- this->initClassID<CircleInside2PtConicalEffect>();
- }
+ : INHERITED(that), fInfo(that.fInfo) {}
GR_DECLARE_FRAGMENT_PROCESSOR_TEST
@@ -1103,9 +1096,9 @@
}
CircleOutside2PtConicalEffect(const CreateArgs& args, const CircleConicalInfo& info)
- : INHERITED(args, false /* opaque: draws transparent black outside of the cone. */)
+ : INHERITED(kCircleOutside2PtConicalEffect_ClassID, args,
+ false /* opaque: draws transparent black outside of the cone. */)
, fInfo(info) {
- this->initClassID<CircleOutside2PtConicalEffect>();
const SkTwoPointConicalGradient& shader =
*static_cast<const SkTwoPointConicalGradient*>(args.fShader);
if (shader.getStartRadius() != shader.getEndRadius()) {
@@ -1121,9 +1114,7 @@
: INHERITED(that)
, fInfo(that.fInfo)
, fTLimit(that.fTLimit)
- , fIsFlipped(that.fIsFlipped) {
- this->initClassID<CircleOutside2PtConicalEffect>();
- }
+ , fIsFlipped(that.fIsFlipped) {}
GR_DECLARE_FRAGMENT_PROCESSOR_TEST