Consistency among GrFP::ProgramImpl subclasses
Remove GL or GLSL from names of subclasses. Make nearly all subclasses
nested either in FP class or its onMakeProgramImpl() function.
Make onSetData private rather than protected.
Remove unused INHERITED typedefs.
Embrace idea that Impl is part of FP private implementation:
direct member access rather than getters and no GenKey pattern.
Other random consistency updates, modernatizations, stylistic changes.
Bug: skia:11358
Change-Id: I0d94e00a146abdd38e094ca550fc3b9608bd433d
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/438056
Reviewed-by: Michael Ludwig <michaelludwig@google.com>
Commit-Queue: Brian Salomon <bsalomon@google.com>
diff --git a/gm/destcolor.cpp b/gm/destcolor.cpp
index 096bf8f..83b22c0 100644
--- a/gm/destcolor.cpp
+++ b/gm/destcolor.cpp
@@ -48,17 +48,15 @@
void onAddToKey(const GrShaderCaps&, GrProcessorKeyBuilder*) const override {}
bool onIsEqual(const GrFragmentProcessor&) const override { return true; }
- class Impl : public ProgramImpl {
- void emitCode(EmitArgs& args) override {
- SkString result = this->invokeChild(0, args);
- args.fFragBuilder->codeAppendf("return (half4(1) - (%s)).rgb1;", result.c_str());
- }
- void onSetData(const GrGLSLProgramDataManager& pdman,
- const GrFragmentProcessor& processor) override {
- }
- };
-
std::unique_ptr<ProgramImpl> onMakeProgramImpl() const override {
+ class Impl : public ProgramImpl {
+ public:
+ void emitCode(EmitArgs& args) override {
+ SkString result = this->invokeChild(0, args);
+ args.fFragBuilder->codeAppendf("return (half4(1) - (%s)).rgb1;", result.c_str());
+ }
+ };
+
return std::make_unique<Impl>();
}
diff --git a/gm/dsl_processor_test.cpp b/gm/dsl_processor_test.cpp
index 258362c..b14fe08 100644
--- a/gm/dsl_processor_test.cpp
+++ b/gm/dsl_processor_test.cpp
@@ -28,6 +28,7 @@
std::unique_ptr<ProgramImpl> onMakeProgramImpl() const override {
class Impl : public ProgramImpl {
+ public:
void emitCode(EmitArgs& args) override {
using namespace SkSL::dsl;
StartFragmentProcessor(this, &args);
@@ -46,6 +47,7 @@
EndFragmentProcessor();
}
+ private:
void onSetData(const GrGLSLProgramDataManager& pdman,
const GrFragmentProcessor& effect) override {
pdman.set2f(fBlueAlphaUniform, 0.0, 1.0);
diff --git a/gm/fp_sample_chaining.cpp b/gm/fp_sample_chaining.cpp
index c3a8537..10ea191 100644
--- a/gm/fp_sample_chaining.cpp
+++ b/gm/fp_sample_chaining.cpp
@@ -38,6 +38,7 @@
std::unique_ptr<ProgramImpl> onMakeProgramImpl() const override {
class Impl : public ProgramImpl {
+ public:
void emitCode(EmitArgs& args) override {
fMatrixVar =
args.fUniformHandler->addUniform(&args.fFp,
@@ -47,6 +48,8 @@
SkString sample = this->invokeChildWithMatrix(0, args);
args.fFragBuilder->codeAppendf("return %s;\n", sample.c_str());
}
+
+ private:
void onSetData(const GrGLSLProgramDataManager& pdman,
const GrFragmentProcessor& proc) override {
pdman.setSkMatrix(fMatrixVar, SkMatrix::Scale(1, 0.5f));
@@ -76,6 +79,7 @@
std::unique_ptr<ProgramImpl> onMakeProgramImpl() const override {
class Impl : public ProgramImpl {
+ public:
void emitCode(EmitArgs& args) override {
args.fFragBuilder->codeAppendf("float2 coord = %s + float2(0, 8);",
args.fSampleCoord);
@@ -83,6 +87,7 @@
args.fFragBuilder->codeAppendf("return %s;\n", sample.c_str());
}
};
+
return std::make_unique<Impl>();
}
};
@@ -103,6 +108,7 @@
std::unique_ptr<ProgramImpl> onMakeProgramImpl() const override {
class Impl : public ProgramImpl {
+ public:
void emitCode(EmitArgs& args) override {
auto fb = args.fFragBuilder;
fb->codeAppendf("float2 coord = %s / 64.0;", args.fSampleCoord);
@@ -110,6 +116,7 @@
fb->codeAppendf("return half2(coord).rg01;\n");
}
};
+
return std::make_unique<Impl>();
}
};
diff --git a/gm/fpcoordinateoverride.cpp b/gm/fpcoordinateoverride.cpp
index 74ee7c1..dfec939 100644
--- a/gm/fpcoordinateoverride.cpp
+++ b/gm/fpcoordinateoverride.cpp
@@ -58,17 +58,18 @@
using INHERITED = GrFragmentProcessor;
};
-class GLSLSampleCoordEffect : public GrFragmentProcessor::ProgramImpl {
- void emitCode(EmitArgs& args) override {
- GrGLSLFPFragmentBuilder* fragBuilder = args.fFragBuilder;
- SkString sample1 = this->invokeChild(0, args, "float2(sk_FragCoord.x, sk_FragCoord.y)");
- SkString sample2 = this->invokeChild(0, args, "float2(sk_FragCoord.x, 512-sk_FragCoord.y)");
- fragBuilder->codeAppendf("return (%s + %s) / 2;\n", sample1.c_str(), sample2.c_str());
- }
-};
-
std::unique_ptr<GrFragmentProcessor::ProgramImpl> SampleCoordEffect::onMakeProgramImpl() const {
- return std::make_unique<GLSLSampleCoordEffect>();
+ class Impl : public ProgramImpl {
+ public:
+ void emitCode(EmitArgs& args) override {
+ GrGLSLFPFragmentBuilder* fragBuilder = args.fFragBuilder;
+ SkString s1 = this->invokeChild(0, args, "float2(sk_FragCoord.x, sk_FragCoord.y)");
+ SkString s2 = this->invokeChild(0, args, "float2(sk_FragCoord.x, 512-sk_FragCoord.y)");
+ fragBuilder->codeAppendf("return (%s + %s) / 2;\n", s1.c_str(), s2.c_str());
+ }
+ };
+
+ return std::make_unique<Impl>();
}
DEF_SIMPLE_GPU_GM_BG(fpcoordinateoverride, rContext, canvas, 512, 512,
diff --git a/src/effects/SkTableColorFilter.cpp b/src/effects/SkTableColorFilter.cpp
index 92ab569..3876f7f 100644
--- a/src/effects/SkTableColorFilter.cpp
+++ b/src/effects/SkTableColorFilter.cpp
@@ -173,6 +173,7 @@
inputColor.c_str(), r.c_str(), g.c_str(), b.c_str(), a.c_str());
}
};
+
return std::make_unique<Impl>();
}
diff --git a/src/effects/imagefilters/SkDisplacementMapImageFilter.cpp b/src/effects/imagefilters/SkDisplacementMapImageFilter.cpp
index 8c17bd1..0d11c989f 100644
--- a/src/effects/imagefilters/SkDisplacementMapImageFilter.cpp
+++ b/src/effects/imagefilters/SkDisplacementMapImageFilter.cpp
@@ -164,10 +164,6 @@
~GrDisplacementMapEffect() override;
- SkColorChannel xChannelSelector() const { return fXChannelSelector; }
- SkColorChannel yChannelSelector() const { return fYChannelSelector; }
- const SkVector& scale() const { return fScale; }
-
const char* name() const override { return "DisplacementMap"; }
std::unique_ptr<GrFragmentProcessor> clone() const override;
@@ -402,21 +398,16 @@
///////////////////////////////////////////////////////////////////////////////
#if SK_SUPPORT_GPU
-class GrDisplacementMapEffect::Impl : public GrFragmentProcessor::ProgramImpl {
+class GrDisplacementMapEffect::Impl : public ProgramImpl {
public:
void emitCode(EmitArgs&) override;
- static inline void GenKey(const GrProcessor&, const GrShaderCaps&, GrProcessorKeyBuilder*);
-
-protected:
+private:
void onSetData(const GrGLSLProgramDataManager&, const GrFragmentProcessor&) override;
-private:
typedef GrGLSLProgramDataManager::UniformHandle UniformHandle;
UniformHandle fScaleUni;
-
- using INHERITED = ProgramImpl;
};
///////////////////////////////////////////////////////////////////////////////
@@ -459,7 +450,12 @@
}
void GrDisplacementMapEffect::onAddToKey(const GrShaderCaps& caps, GrProcessorKeyBuilder* b) const {
- Impl::GenKey(*this, caps, b);
+ static constexpr int kChannelSelectorKeyBits = 2; // Max value is 3, so 2 bits are required
+
+ uint32_t xKey = static_cast<uint32_t>(fXChannelSelector);
+ uint32_t yKey = static_cast<uint32_t>(fYChannelSelector) << kChannelSelectorKeyBits;
+
+ b->add32(xKey | yKey);
}
GrDisplacementMapEffect::GrDisplacementMapEffect(SkColorChannel xChannelSelector,
@@ -552,9 +548,10 @@
}
};
fragBuilder->codeAppendf("float2 cCoords = %s + %s * (dColor.%c%c - half2(0.5));",
- args.fSampleCoord, scaleUni,
- chanChar(displacementMap.xChannelSelector()),
- chanChar(displacementMap.yChannelSelector()));
+ args.fSampleCoord,
+ scaleUni,
+ chanChar(displacementMap.fXChannelSelector),
+ chanChar(displacementMap.fYChannelSelector));
SkString colorSample = this->invokeChild(/*childIndex=*/1, args, "cCoords");
@@ -564,21 +561,6 @@
void GrDisplacementMapEffect::Impl::onSetData(const GrGLSLProgramDataManager& pdman,
const GrFragmentProcessor& proc) {
const auto& displacementMap = proc.cast<GrDisplacementMapEffect>();
- const SkVector& scale = displacementMap.scale();
- pdman.set2f(fScaleUni, scale.x(), scale.y());
-}
-
-void GrDisplacementMapEffect::Impl::GenKey(const GrProcessor& proc,
- const GrShaderCaps&,
- GrProcessorKeyBuilder* b) {
- const GrDisplacementMapEffect& displacementMap = proc.cast<GrDisplacementMapEffect>();
-
- static constexpr int kChannelSelectorKeyBits = 2; // Max value is 3, so 2 bits are required
-
- uint32_t xKey = static_cast<uint32_t>(displacementMap.xChannelSelector());
- uint32_t yKey = static_cast<uint32_t>(displacementMap.yChannelSelector())
- << kChannelSelectorKeyBits;
-
- b->add32(xKey | yKey);
+ pdman.set2f(fScaleUni, displacementMap.fScale.x(), displacementMap.fScale.y());
}
#endif
diff --git a/src/effects/imagefilters/SkLightingImageFilter.cpp b/src/effects/imagefilters/SkLightingImageFilter.cpp
index 463e8cc..a05e4a4 100644
--- a/src/effects/imagefilters/SkLightingImageFilter.cpp
+++ b/src/effects/imagefilters/SkLightingImageFilter.cpp
@@ -32,9 +32,6 @@
#include "src/gpu/glsl/GrGLSLProgramDataManager.h"
#include "src/gpu/glsl/GrGLSLUniformHandler.h"
-class GrGLDiffuseLightingEffect;
-class GrGLSpecularLightingEffect;
-
// For brevity
typedef GrGLSLProgramDataManager::UniformHandle UniformHandle;
#endif
@@ -101,7 +98,8 @@
buffer.writeScalar(point.fZ);
};
-class GrGLLight;
+namespace {
+class GpuLight;
class SkImageFilterLight : public SkRefCnt {
public:
enum LightType {
@@ -113,7 +111,7 @@
};
virtual LightType type() const = 0;
const SkPoint3& color() const { return fColor; }
- virtual GrGLLight* createGLLight() const = 0;
+ virtual std::unique_ptr<GpuLight> createGpuLight() const = 0;
virtual bool isEqual(const SkImageFilterLight& other) const {
return fColor == other.fColor;
}
@@ -196,6 +194,7 @@
SkScalar fKS;
SkScalar fShininess;
};
+} // anonymous namespace
static inline SkScalar sobel(int a, int b, int c, int d, int e, int f, SkScalar scale) {
return (-a + b - 2 * c + 2 * d -e + f) * scale;
@@ -262,7 +261,7 @@
surfaceScale);
}
-
+namespace {
class UncheckedPixelFetcher {
public:
static inline uint32_t Fetch(const SkBitmap& src, int x, int y, const SkIRect& bounds) {
@@ -281,6 +280,7 @@
}
}
};
+} // anonymous namespace
template <class PixelFetcher>
static void lightBitmap(const BaseLightingType& lightingType,
@@ -388,6 +388,7 @@
}
}
+namespace {
enum BoundaryMode {
kTopLeft_BoundaryMode,
kTop_BoundaryMode,
@@ -452,6 +453,7 @@
using INHERITED = SkImageFilter_Base;
};
+} // anonymous namespace
#if SK_SUPPORT_GPU
void SkLightingImageFilterInternal::drawRect(skgpu::SurfaceFillContext* sfc,
@@ -537,6 +539,7 @@
}
#endif
+namespace {
class SkDiffuseLightingImageFilter : public SkLightingImageFilterInternal {
public:
static sk_sp<SkImageFilter> Make(sk_sp<SkImageFilterLight> light,
@@ -610,7 +613,7 @@
#if SK_SUPPORT_GPU
-class GrLightingEffect : public GrFragmentProcessor {
+class LightingEffect : public GrFragmentProcessor {
public:
const SkImageFilterLight* light() const { return fLight.get(); }
SkScalar surfaceScale() const { return fSurfaceScale; }
@@ -618,20 +621,26 @@
BoundaryMode boundaryMode() const { return fBoundaryMode; }
protected:
- GrLightingEffect(ClassID classID,
- GrSurfaceProxyView,
- sk_sp<const SkImageFilterLight> light,
- SkScalar surfaceScale,
- const SkMatrix& matrix,
- BoundaryMode boundaryMode,
- const SkIRect* srcBounds,
- const GrCaps& caps);
+ class ImplBase;
- explicit GrLightingEffect(const GrLightingEffect& that);
+ LightingEffect(ClassID classID,
+ GrSurfaceProxyView,
+ sk_sp<const SkImageFilterLight> light,
+ SkScalar surfaceScale,
+ const SkMatrix& matrix,
+ BoundaryMode boundaryMode,
+ const SkIRect* srcBounds,
+ const GrCaps& caps);
+
+ explicit LightingEffect(const LightingEffect& that);
bool onIsEqual(const GrFragmentProcessor&) const override;
private:
+ void onAddToKey(const GrShaderCaps& caps, GrProcessorKeyBuilder* b) const override {
+ b->add32(fBoundaryMode << 2 | fLight->type());
+ }
+
sk_sp<const SkImageFilterLight> fLight;
SkScalar fSurfaceScale;
SkMatrix fFilterMatrix;
@@ -640,7 +649,7 @@
using INHERITED = GrFragmentProcessor;
};
-class GrDiffuseLightingEffect : public GrLightingEffect {
+class DiffuseLightingEffect : public LightingEffect {
public:
static std::unique_ptr<GrFragmentProcessor> Make(GrSurfaceProxyView view,
sk_sp<const SkImageFilterLight> light,
@@ -650,44 +659,47 @@
BoundaryMode boundaryMode,
const SkIRect* srcBounds,
const GrCaps& caps) {
- return std::unique_ptr<GrFragmentProcessor>(
- new GrDiffuseLightingEffect(std::move(view), std::move(light), surfaceScale, matrix,
- kd, boundaryMode, srcBounds, caps));
+ return std::unique_ptr<GrFragmentProcessor>(new DiffuseLightingEffect(std::move(view),
+ std::move(light),
+ surfaceScale,
+ matrix,
+ kd,
+ boundaryMode,
+ srcBounds,
+ caps));
}
const char* name() const override { return "DiffuseLighting"; }
std::unique_ptr<GrFragmentProcessor> clone() const override {
- return std::unique_ptr<GrFragmentProcessor>(new GrDiffuseLightingEffect(*this));
+ return std::unique_ptr<GrFragmentProcessor>(new DiffuseLightingEffect(*this));
}
- SkScalar kd() const { return fKD; }
-
private:
- std::unique_ptr<ProgramImpl> onMakeProgramImpl() const override;
+ class Impl;
- void onAddToKey(const GrShaderCaps&, GrProcessorKeyBuilder*) const override;
+ std::unique_ptr<ProgramImpl> onMakeProgramImpl() const override;
bool onIsEqual(const GrFragmentProcessor&) const override;
- GrDiffuseLightingEffect(GrSurfaceProxyView view,
- sk_sp<const SkImageFilterLight> light,
- SkScalar surfaceScale,
- const SkMatrix& matrix,
- SkScalar kd,
- BoundaryMode boundaryMode,
- const SkIRect* srcBounds,
- const GrCaps& caps);
+ DiffuseLightingEffect(GrSurfaceProxyView view,
+ sk_sp<const SkImageFilterLight> light,
+ SkScalar surfaceScale,
+ const SkMatrix& matrix,
+ SkScalar kd,
+ BoundaryMode boundaryMode,
+ const SkIRect* srcBounds,
+ const GrCaps& caps);
- explicit GrDiffuseLightingEffect(const GrDiffuseLightingEffect& that);
+ explicit DiffuseLightingEffect(const DiffuseLightingEffect& that);
GR_DECLARE_FRAGMENT_PROCESSOR_TEST
SkScalar fKD;
- using INHERITED = GrLightingEffect;
+ using INHERITED = LightingEffect;
};
-class GrSpecularLightingEffect : public GrLightingEffect {
+class SpecularLightingEffect : public LightingEffect {
public:
static std::unique_ptr<GrFragmentProcessor> Make(GrSurfaceProxyView view,
sk_sp<const SkImageFilterLight> light,
@@ -698,51 +710,54 @@
BoundaryMode boundaryMode,
const SkIRect* srcBounds,
const GrCaps& caps) {
- return std::unique_ptr<GrFragmentProcessor>(
- new GrSpecularLightingEffect(std::move(view), std::move(light), surfaceScale,
- matrix, ks, shininess, boundaryMode, srcBounds, caps));
+ return std::unique_ptr<GrFragmentProcessor>(new SpecularLightingEffect(std::move(view),
+ std::move(light),
+ surfaceScale,
+ matrix,
+ ks,
+ shininess,
+ boundaryMode,
+ srcBounds,
+ caps));
}
const char* name() const override { return "SpecularLighting"; }
std::unique_ptr<GrFragmentProcessor> clone() const override {
- return std::unique_ptr<GrFragmentProcessor>(new GrSpecularLightingEffect(*this));
+ return std::unique_ptr<GrFragmentProcessor>(new SpecularLightingEffect(*this));
}
std::unique_ptr<ProgramImpl> onMakeProgramImpl() const override;
- SkScalar ks() const { return fKS; }
- SkScalar shininess() const { return fShininess; }
-
private:
- void onAddToKey(const GrShaderCaps&, GrProcessorKeyBuilder*) const override;
+ class Impl;
bool onIsEqual(const GrFragmentProcessor&) const override;
- GrSpecularLightingEffect(GrSurfaceProxyView,
- sk_sp<const SkImageFilterLight> light,
- SkScalar surfaceScale,
- const SkMatrix& matrix,
- SkScalar ks,
- SkScalar shininess,
- BoundaryMode boundaryMode,
- const SkIRect* srcBounds,
- const GrCaps&);
+ SpecularLightingEffect(GrSurfaceProxyView,
+ sk_sp<const SkImageFilterLight> light,
+ SkScalar surfaceScale,
+ const SkMatrix& matrix,
+ SkScalar ks,
+ SkScalar shininess,
+ BoundaryMode boundaryMode,
+ const SkIRect* srcBounds,
+ const GrCaps&);
- explicit GrSpecularLightingEffect(const GrSpecularLightingEffect&);
+ explicit SpecularLightingEffect(const SpecularLightingEffect&);
GR_DECLARE_FRAGMENT_PROCESSOR_TEST
SkScalar fKS;
SkScalar fShininess;
- using INHERITED = GrLightingEffect;
+ using INHERITED = LightingEffect;
};
///////////////////////////////////////////////////////////////////////////////
-class GrGLLight {
+class GpuLight {
public:
- virtual ~GrGLLight() {}
+ virtual ~GpuLight() = default;
/**
* This is called by GrGLLightingEffect::emitCode() before either of the two virtual functions
@@ -786,37 +801,34 @@
///////////////////////////////////////////////////////////////////////////////
-class GrGLDistantLight : public GrGLLight {
+class GpuDistantLight : public GpuLight {
public:
- ~GrGLDistantLight() override {}
void setData(const GrGLSLProgramDataManager&, const SkImageFilterLight* light) const override;
void emitSurfaceToLight(const GrFragmentProcessor*, GrGLSLUniformHandler*,
GrGLSLFPFragmentBuilder*, const char* z) override;
private:
- using INHERITED = GrGLLight;
+ using INHERITED = GpuLight;
UniformHandle fDirectionUni;
};
///////////////////////////////////////////////////////////////////////////////
-class GrGLPointLight : public GrGLLight {
+class GpuPointLight : public GpuLight {
public:
- ~GrGLPointLight() override {}
void setData(const GrGLSLProgramDataManager&, const SkImageFilterLight* light) const override;
void emitSurfaceToLight(const GrFragmentProcessor*, GrGLSLUniformHandler*,
GrGLSLFPFragmentBuilder*, const char* z) override;
private:
- using INHERITED = GrGLLight;
+ using INHERITED = GpuLight;
UniformHandle fLocationUni;
};
///////////////////////////////////////////////////////////////////////////////
-class GrGLSpotLight : public GrGLLight {
+class GpuSpotLight : public GpuLight {
public:
- ~GrGLSpotLight() override {}
void setData(const GrGLSLProgramDataManager&, const SkImageFilterLight* light) const override;
void emitSurfaceToLight(const GrFragmentProcessor*, GrGLSLUniformHandler*,
GrGLSLFPFragmentBuilder*, const char* z) override;
@@ -826,7 +838,7 @@
const char *surfaceToLight) override;
private:
- using INHERITED = GrGLLight;
+ using INHERITED = GpuLight;
SkString fLightColorFunc;
UniformHandle fLocationUni;
@@ -836,16 +848,15 @@
UniformHandle fConeScaleUni;
UniformHandle fSUni;
};
+
#else
-class GrGLLight;
+class GpuLight {};
#endif
///////////////////////////////////////////////////////////////////////////////
-///////////////////////////////////////////////////////////////////////////////
-
class SkDistantLight : public SkImageFilterLight {
public:
SkDistantLight(const SkPoint3& direction, SkColor color)
@@ -858,9 +869,9 @@
SkPoint3 lightColor(const SkPoint3&) const override { return this->color(); }
LightType type() const override { return kDistant_LightType; }
const SkPoint3& direction() const { return fDirection; }
- GrGLLight* createGLLight() const override {
+ std::unique_ptr<GpuLight> createGpuLight() const override {
#if SK_SUPPORT_GPU
- return new GrGLDistantLight;
+ return std::make_unique<GpuDistantLight>();
#else
SkDEBUGFAIL("Should not call in GPU-less build");
return nullptr;
@@ -915,9 +926,9 @@
SkPoint3 lightColor(const SkPoint3&) const override { return this->color(); }
LightType type() const override { return kPoint_LightType; }
const SkPoint3& location() const { return fLocation; }
- GrGLLight* createGLLight() const override {
+ std::unique_ptr<GpuLight> createGpuLight() const override {
#if SK_SUPPORT_GPU
- return new GrGLPointLight;
+ return std::make_unique<GpuPointLight>();
#else
SkDEBUGFAIL("Should not call in GPU-less build");
return nullptr;
@@ -1027,9 +1038,9 @@
}
return this->color().makeScale(scale);
}
- GrGLLight* createGLLight() const override {
+ std::unique_ptr<GpuLight> createGpuLight() const override {
#if SK_SUPPORT_GPU
- return new GrGLSpotLight;
+ return std::make_unique<GpuSpotLight>();
#else
SkDEBUGFAIL("Should not call in GPU-less build");
return nullptr;
@@ -1110,6 +1121,7 @@
using INHERITED = SkImageFilterLight;
};
+} // anonymous namespace
///////////////////////////////////////////////////////////////////////////////
@@ -1321,8 +1333,14 @@
BoundaryMode boundaryMode,
const GrCaps& caps) const {
SkScalar scale = this->surfaceScale() * 255;
- return GrDiffuseLightingEffect::Make(std::move(view), this->refLight(), scale, matrix,
- this->kd(), boundaryMode, srcBounds, caps);
+ return DiffuseLightingEffect::Make(std::move(view),
+ this->refLight(),
+ scale,
+ matrix,
+ this->kd(),
+ boundaryMode,
+ srcBounds,
+ caps);
}
#endif
@@ -1457,9 +1475,15 @@
BoundaryMode boundaryMode,
const GrCaps& caps) const {
SkScalar scale = this->surfaceScale() * 255;
- return GrSpecularLightingEffect::Make(std::move(view), this->refLight(), scale, matrix,
- this->ks(), this->shininess(), boundaryMode, srcBounds,
- caps);
+ return SpecularLightingEffect::Make(std::move(view),
+ this->refLight(),
+ scale,
+ matrix,
+ this->ks(),
+ this->shininess(),
+ boundaryMode,
+ srcBounds,
+ caps);
}
#endif
@@ -1542,18 +1566,14 @@
return result;
}
-class GrGLLightingEffect : public GrFragmentProcessor::ProgramImpl {
+namespace {
+class LightingEffect::ImplBase : public ProgramImpl {
public:
- GrGLLightingEffect() : fLight(nullptr) { }
- ~GrGLLightingEffect() override { delete fLight; }
-
void emitCode(EmitArgs&) override;
- static inline void GenKey(const GrProcessor&, const GrShaderCaps&, GrProcessorKeyBuilder* b);
-
protected:
/**
- * Subclasses of GrGLLightingEffect must call INHERITED::onSetData();
+ * Subclasses of LightingImpl must call INHERITED::onSetData();
*/
void onSetData(const GrGLSLProgramDataManager&, const GrFragmentProcessor&) override;
@@ -1563,55 +1583,56 @@
SkString* funcName) = 0;
private:
- using INHERITED = ProgramImpl;
-
- UniformHandle fSurfaceScaleUni;
- GrGLLight* fLight;
+ UniformHandle fSurfaceScaleUni;
+ std::unique_ptr<GpuLight> fLight;
};
///////////////////////////////////////////////////////////////////////////////
-class GrGLDiffuseLightingEffect : public GrGLLightingEffect {
+class DiffuseLightingEffect::Impl : public ImplBase {
public:
- void emitLightFunc(const GrFragmentProcessor*, GrGLSLUniformHandler*, GrGLSLFPFragmentBuilder*,
+ void emitLightFunc(const GrFragmentProcessor*,
+ GrGLSLUniformHandler*,
+ GrGLSLFPFragmentBuilder*,
SkString* funcName) override;
-protected:
+private:
void onSetData(const GrGLSLProgramDataManager&, const GrFragmentProcessor&) override;
-private:
- using INHERITED = GrGLLightingEffect;
+ using INHERITED = ImplBase;
UniformHandle fKDUni;
};
///////////////////////////////////////////////////////////////////////////////
-class GrGLSpecularLightingEffect : public GrGLLightingEffect {
+class SpecularLightingEffect::Impl : public ImplBase {
public:
- void emitLightFunc(const GrFragmentProcessor*, GrGLSLUniformHandler*, GrGLSLFPFragmentBuilder*,
+ void emitLightFunc(const GrFragmentProcessor*,
+ GrGLSLUniformHandler*,
+ GrGLSLFPFragmentBuilder*,
SkString* funcName) override;
-protected:
+private:
void onSetData(const GrGLSLProgramDataManager&, const GrFragmentProcessor&) override;
-private:
- using INHERITED = GrGLLightingEffect;
+ using INHERITED = ImplBase;
UniformHandle fKSUni;
UniformHandle fShininessUni;
};
+} // anonymous namespace
///////////////////////////////////////////////////////////////////////////////
-GrLightingEffect::GrLightingEffect(ClassID classID,
- GrSurfaceProxyView view,
- sk_sp<const SkImageFilterLight> light,
- SkScalar surfaceScale,
- const SkMatrix& matrix,
- BoundaryMode boundaryMode,
- const SkIRect* srcBounds,
- const GrCaps& caps)
+LightingEffect::LightingEffect(ClassID classID,
+ GrSurfaceProxyView view,
+ sk_sp<const SkImageFilterLight> light,
+ SkScalar surfaceScale,
+ const SkMatrix& matrix,
+ BoundaryMode boundaryMode,
+ const SkIRect* srcBounds,
+ const GrCaps& caps)
// Perhaps this could advertise the opaque or coverage-as-alpha optimizations?
: INHERITED(classID, kNone_OptimizationFlags)
, fLight(std::move(light))
@@ -1632,15 +1653,15 @@
this->setUsesSampleCoordsDirectly();
}
-GrLightingEffect::GrLightingEffect(const GrLightingEffect& that)
+LightingEffect::LightingEffect(const LightingEffect& that)
: INHERITED(that)
, fLight(that.fLight)
, fSurfaceScale(that.fSurfaceScale)
, fFilterMatrix(that.fFilterMatrix)
, fBoundaryMode(that.fBoundaryMode) {}
-bool GrLightingEffect::onIsEqual(const GrFragmentProcessor& sBase) const {
- const GrLightingEffect& s = sBase.cast<GrLightingEffect>();
+bool LightingEffect::onIsEqual(const GrFragmentProcessor& sBase) const {
+ const LightingEffect& s = sBase.cast<LightingEffect>();
return fLight->isEqual(*s.fLight) &&
fSurfaceScale == s.fSurfaceScale &&
fBoundaryMode == s.fBoundaryMode;
@@ -1648,14 +1669,14 @@
///////////////////////////////////////////////////////////////////////////////
-GrDiffuseLightingEffect::GrDiffuseLightingEffect(GrSurfaceProxyView view,
- sk_sp<const SkImageFilterLight> light,
- SkScalar surfaceScale,
- const SkMatrix& matrix,
- SkScalar kd,
- BoundaryMode boundaryMode,
- const SkIRect* srcBounds,
- const GrCaps& caps)
+DiffuseLightingEffect::DiffuseLightingEffect(GrSurfaceProxyView view,
+ sk_sp<const SkImageFilterLight> light,
+ SkScalar surfaceScale,
+ const SkMatrix& matrix,
+ SkScalar kd,
+ BoundaryMode boundaryMode,
+ const SkIRect* srcBounds,
+ const GrCaps& caps)
: INHERITED(kGrDiffuseLightingEffect_ClassID,
std::move(view),
std::move(light),
@@ -1666,24 +1687,19 @@
caps)
, fKD(kd) {}
-GrDiffuseLightingEffect::GrDiffuseLightingEffect(const GrDiffuseLightingEffect& that)
+DiffuseLightingEffect::DiffuseLightingEffect(const DiffuseLightingEffect& that)
: INHERITED(that), fKD(that.fKD) {}
-bool GrDiffuseLightingEffect::onIsEqual(const GrFragmentProcessor& sBase) const {
- const GrDiffuseLightingEffect& s = sBase.cast<GrDiffuseLightingEffect>();
- return INHERITED::onIsEqual(sBase) && this->kd() == s.kd();
+bool DiffuseLightingEffect::onIsEqual(const GrFragmentProcessor& sBase) const {
+ const DiffuseLightingEffect& s = sBase.cast<DiffuseLightingEffect>();
+ return INHERITED::onIsEqual(sBase) && fKD == s.fKD;
}
-void GrDiffuseLightingEffect::onAddToKey(const GrShaderCaps& caps, GrProcessorKeyBuilder* b) const {
- GrGLDiffuseLightingEffect::GenKey(*this, caps, b);
+std::unique_ptr<GrFragmentProcessor::ProgramImpl> DiffuseLightingEffect::onMakeProgramImpl() const {
+ return std::make_unique<Impl>();
}
-std::unique_ptr<GrFragmentProcessor::ProgramImpl>
-GrDiffuseLightingEffect::onMakeProgramImpl() const {
- return std::make_unique<GrGLDiffuseLightingEffect>();
-}
-
-GR_DEFINE_FRAGMENT_PROCESSOR_TEST(GrDiffuseLightingEffect);
+GR_DEFINE_FRAGMENT_PROCESSOR_TEST(DiffuseLightingEffect);
#if GR_TEST_UTILS
@@ -1711,7 +1727,7 @@
}
}
-std::unique_ptr<GrFragmentProcessor> GrDiffuseLightingEffect::TestCreate(GrProcessorTestData* d) {
+std::unique_ptr<GrFragmentProcessor> DiffuseLightingEffect::TestCreate(GrProcessorTestData* d) {
auto [view, ct, at] = d->randomView();
SkScalar surfaceScale = d->fRandom->nextSScalar1();
SkScalar kd = d->fRandom->nextUScalar1();
@@ -1728,18 +1744,24 @@
SkIRect srcBounds = SkIRect::MakeXYWH(boundsX, boundsY, boundsW, boundsH);
BoundaryMode mode = static_cast<BoundaryMode>(d->fRandom->nextU() % kBoundaryModeCount);
- return GrDiffuseLightingEffect::Make(std::move(view), std::move(light), surfaceScale, matrix,
- kd, mode, &srcBounds, *d->caps());
+ return DiffuseLightingEffect::Make(std::move(view),
+ std::move(light),
+ surfaceScale,
+ matrix,
+ kd,
+ mode,
+ &srcBounds,
+ *d->caps());
}
#endif
///////////////////////////////////////////////////////////////////////////////
-void GrGLLightingEffect::emitCode(EmitArgs& args) {
- const GrLightingEffect& le = args.fFp.cast<GrLightingEffect>();
+void LightingEffect::ImplBase::emitCode(EmitArgs& args) {
+ const LightingEffect& le = args.fFp.cast<LightingEffect>();
if (!fLight) {
- fLight = le.light()->createGLLight();
+ fLight = le.light()->createGpuLight();
}
GrGLSLUniformHandler* uniformHandler = args.fUniformHandler;
@@ -1815,17 +1837,11 @@
fragBuilder->codeAppend(");");
}
-void GrGLLightingEffect::GenKey(const GrProcessor& proc,
- const GrShaderCaps& caps, GrProcessorKeyBuilder* b) {
- const GrLightingEffect& lighting = proc.cast<GrLightingEffect>();
- b->add32(lighting.boundaryMode() << 2 | lighting.light()->type());
-}
-
-void GrGLLightingEffect::onSetData(const GrGLSLProgramDataManager& pdman,
- const GrFragmentProcessor& proc) {
- const GrLightingEffect& lighting = proc.cast<GrLightingEffect>();
+void LightingEffect::ImplBase::onSetData(const GrGLSLProgramDataManager& pdman,
+ const GrFragmentProcessor& proc) {
+ const LightingEffect& lighting = proc.cast<LightingEffect>();
if (!fLight) {
- fLight = lighting.light()->createGLLight();
+ fLight = lighting.light()->createGpuLight();
}
pdman.set1f(fSurfaceScaleUni, lighting.surfaceScale());
@@ -1838,10 +1854,10 @@
///////////////////////////////////////////////////////////////////////////////
-void GrGLDiffuseLightingEffect::emitLightFunc(const GrFragmentProcessor* owner,
- GrGLSLUniformHandler* uniformHandler,
- GrGLSLFPFragmentBuilder* fragBuilder,
- SkString* funcName) {
+void DiffuseLightingEffect::Impl::emitLightFunc(const GrFragmentProcessor* owner,
+ GrGLSLUniformHandler* uniformHandler,
+ GrGLSLFPFragmentBuilder* fragBuilder,
+ SkString* funcName) {
const char* kd;
fKDUni = uniformHandler->addUniform(owner, kFragment_GrShaderFlag, kHalf_GrSLType, "KD", &kd);
@@ -1860,24 +1876,24 @@
lightBody.c_str());
}
-void GrGLDiffuseLightingEffect::onSetData(const GrGLSLProgramDataManager& pdman,
- const GrFragmentProcessor& proc) {
+void DiffuseLightingEffect::Impl::onSetData(const GrGLSLProgramDataManager& pdman,
+ const GrFragmentProcessor& proc) {
INHERITED::onSetData(pdman, proc);
- const GrDiffuseLightingEffect& diffuse = proc.cast<GrDiffuseLightingEffect>();
- pdman.set1f(fKDUni, diffuse.kd());
+ const DiffuseLightingEffect& diffuse = proc.cast<DiffuseLightingEffect>();
+ pdman.set1f(fKDUni, diffuse.fKD);
}
///////////////////////////////////////////////////////////////////////////////
-GrSpecularLightingEffect::GrSpecularLightingEffect(GrSurfaceProxyView view,
- sk_sp<const SkImageFilterLight> light,
- SkScalar surfaceScale,
- const SkMatrix& matrix,
- SkScalar ks,
- SkScalar shininess,
- BoundaryMode boundaryMode,
- const SkIRect* srcBounds,
- const GrCaps& caps)
+SpecularLightingEffect::SpecularLightingEffect(GrSurfaceProxyView view,
+ sk_sp<const SkImageFilterLight> light,
+ SkScalar surfaceScale,
+ const SkMatrix& matrix,
+ SkScalar ks,
+ SkScalar shininess,
+ BoundaryMode boundaryMode,
+ const SkIRect* srcBounds,
+ const GrCaps& caps)
: INHERITED(kGrSpecularLightingEffect_ClassID,
std::move(view),
std::move(light),
@@ -1889,30 +1905,21 @@
, fKS(ks)
, fShininess(shininess) {}
-GrSpecularLightingEffect::GrSpecularLightingEffect(const GrSpecularLightingEffect& that)
+SpecularLightingEffect::SpecularLightingEffect(const SpecularLightingEffect& that)
: INHERITED(that), fKS(that.fKS), fShininess(that.fShininess) {}
-bool GrSpecularLightingEffect::onIsEqual(const GrFragmentProcessor& sBase) const {
- const GrSpecularLightingEffect& s = sBase.cast<GrSpecularLightingEffect>();
- return INHERITED::onIsEqual(sBase) &&
- this->ks() == s.ks() &&
- this->shininess() == s.shininess();
-}
-
-void GrSpecularLightingEffect::onAddToKey(const GrShaderCaps& caps,
- GrProcessorKeyBuilder* b) const {
- GrGLSpecularLightingEffect::GenKey(*this, caps, b);
+bool SpecularLightingEffect::onIsEqual(const GrFragmentProcessor& sBase) const {
+ const SpecularLightingEffect& s = sBase.cast<SpecularLightingEffect>();
+ return INHERITED::onIsEqual(sBase) && this->fKS == s.fKS && this->fShininess == s.fShininess;
}
std::unique_ptr<GrFragmentProcessor::ProgramImpl>
-GrSpecularLightingEffect::onMakeProgramImpl() const {
- return std::make_unique<GrGLSpecularLightingEffect>();
-}
+SpecularLightingEffect::onMakeProgramImpl() const { return std::make_unique<Impl>(); }
-GR_DEFINE_FRAGMENT_PROCESSOR_TEST(GrSpecularLightingEffect);
+GR_DEFINE_FRAGMENT_PROCESSOR_TEST(SpecularLightingEffect);
#if GR_TEST_UTILS
-std::unique_ptr<GrFragmentProcessor> GrSpecularLightingEffect::TestCreate(GrProcessorTestData* d) {
+std::unique_ptr<GrFragmentProcessor> SpecularLightingEffect::TestCreate(GrProcessorTestData* d) {
auto [view, ct, at] = d->randomView();
SkScalar surfaceScale = d->fRandom->nextSScalar1();
SkScalar ks = d->fRandom->nextUScalar1();
@@ -1930,17 +1937,24 @@
uint32_t boundsH = d->fRandom->nextRangeU(0, view.height());
SkIRect srcBounds = SkIRect::MakeXYWH(boundsX, boundsY, boundsW, boundsH);
- return GrSpecularLightingEffect::Make(std::move(view), std::move(light), surfaceScale, matrix,
- ks, shininess, mode, &srcBounds, *d->caps());
+ return SpecularLightingEffect::Make(std::move(view),
+ std::move(light),
+ surfaceScale,
+ matrix,
+ ks,
+ shininess,
+ mode,
+ &srcBounds,
+ *d->caps());
}
#endif
///////////////////////////////////////////////////////////////////////////////
-void GrGLSpecularLightingEffect::emitLightFunc(const GrFragmentProcessor* owner,
- GrGLSLUniformHandler* uniformHandler,
- GrGLSLFPFragmentBuilder* fragBuilder,
- SkString* funcName) {
+void SpecularLightingEffect::Impl::emitLightFunc(const GrFragmentProcessor* owner,
+ GrGLSLUniformHandler* uniformHandler,
+ GrGLSLFPFragmentBuilder* fragBuilder,
+ SkString* funcName) {
const char* ks;
const char* shininess;
@@ -1969,48 +1983,48 @@
lightBody.c_str());
}
-void GrGLSpecularLightingEffect::onSetData(const GrGLSLProgramDataManager& pdman,
- const GrFragmentProcessor& effect) {
+void SpecularLightingEffect::Impl::onSetData(const GrGLSLProgramDataManager& pdman,
+ const GrFragmentProcessor& effect) {
INHERITED::onSetData(pdman, effect);
- const GrSpecularLightingEffect& spec = effect.cast<GrSpecularLightingEffect>();
- pdman.set1f(fKSUni, spec.ks());
- pdman.set1f(fShininessUni, spec.shininess());
+ const SpecularLightingEffect& spec = effect.cast<SpecularLightingEffect>();
+ pdman.set1f(fKSUni, spec.fKS);
+ pdman.set1f(fShininessUni, spec.fShininess);
}
///////////////////////////////////////////////////////////////////////////////
-void GrGLLight::emitLightColorUniform(const GrFragmentProcessor* owner,
- GrGLSLUniformHandler* uniformHandler) {
+void GpuLight::emitLightColorUniform(const GrFragmentProcessor* owner,
+ GrGLSLUniformHandler* uniformHandler) {
fColorUni = uniformHandler->addUniform(owner, kFragment_GrShaderFlag, kHalf3_GrSLType,
"LightColor");
}
-void GrGLLight::emitLightColor(const GrFragmentProcessor* owner,
- GrGLSLUniformHandler* uniformHandler,
- GrGLSLFPFragmentBuilder* fragBuilder,
- const char *surfaceToLight) {
+void GpuLight::emitLightColor(const GrFragmentProcessor* owner,
+ GrGLSLUniformHandler* uniformHandler,
+ GrGLSLFPFragmentBuilder* fragBuilder,
+ const char* surfaceToLight) {
fragBuilder->codeAppend(uniformHandler->getUniformCStr(this->lightColorUni()));
}
-void GrGLLight::setData(const GrGLSLProgramDataManager& pdman,
- const SkImageFilterLight* light) const {
+void GpuLight::setData(const GrGLSLProgramDataManager& pdman,
+ const SkImageFilterLight* light) const {
setUniformPoint3(pdman, fColorUni,
light->color().makeScale(SkScalarInvert(SkIntToScalar(255))));
}
///////////////////////////////////////////////////////////////////////////////
-void GrGLDistantLight::setData(const GrGLSLProgramDataManager& pdman,
- const SkImageFilterLight* light) const {
+void GpuDistantLight::setData(const GrGLSLProgramDataManager& pdman,
+ const SkImageFilterLight* light) const {
INHERITED::setData(pdman, light);
SkASSERT(light->type() == SkImageFilterLight::kDistant_LightType);
const SkDistantLight* distantLight = static_cast<const SkDistantLight*>(light);
setUniformNormal3(pdman, fDirectionUni, distantLight->direction());
}
-void GrGLDistantLight::emitSurfaceToLight(const GrFragmentProcessor* owner,
- GrGLSLUniformHandler* uniformHandler,
- GrGLSLFPFragmentBuilder* fragBuilder,
- const char* z) {
+void GpuDistantLight::emitSurfaceToLight(const GrFragmentProcessor* owner,
+ GrGLSLUniformHandler* uniformHandler,
+ GrGLSLFPFragmentBuilder* fragBuilder,
+ const char* z) {
const char* dir;
fDirectionUni = uniformHandler->addUniform(owner, kFragment_GrShaderFlag, kHalf3_GrSLType,
"LightDirection", &dir);
@@ -2019,18 +2033,18 @@
///////////////////////////////////////////////////////////////////////////////
-void GrGLPointLight::setData(const GrGLSLProgramDataManager& pdman,
- const SkImageFilterLight* light) const {
+void GpuPointLight::setData(const GrGLSLProgramDataManager& pdman,
+ const SkImageFilterLight* light) const {
INHERITED::setData(pdman, light);
SkASSERT(light->type() == SkImageFilterLight::kPoint_LightType);
const SkPointLight* pointLight = static_cast<const SkPointLight*>(light);
setUniformPoint3(pdman, fLocationUni, pointLight->location());
}
-void GrGLPointLight::emitSurfaceToLight(const GrFragmentProcessor* owner,
- GrGLSLUniformHandler* uniformHandler,
- GrGLSLFPFragmentBuilder* fragBuilder,
- const char* z) {
+void GpuPointLight::emitSurfaceToLight(const GrFragmentProcessor* owner,
+ GrGLSLUniformHandler* uniformHandler,
+ GrGLSLFPFragmentBuilder* fragBuilder,
+ const char* z) {
const char* loc;
fLocationUni = uniformHandler->addUniform(owner, kFragment_GrShaderFlag, kHalf3_GrSLType,
"LightLocation", &loc);
@@ -2040,8 +2054,8 @@
///////////////////////////////////////////////////////////////////////////////
-void GrGLSpotLight::setData(const GrGLSLProgramDataManager& pdman,
- const SkImageFilterLight* light) const {
+void GpuSpotLight::setData(const GrGLSLProgramDataManager& pdman,
+ const SkImageFilterLight* light) const {
INHERITED::setData(pdman, light);
SkASSERT(light->type() == SkImageFilterLight::kSpot_LightType);
const SkSpotLight* spotLight = static_cast<const SkSpotLight *>(light);
@@ -2053,10 +2067,10 @@
setUniformNormal3(pdman, fSUni, spotLight->s());
}
-void GrGLSpotLight::emitSurfaceToLight(const GrFragmentProcessor* owner,
- GrGLSLUniformHandler* uniformHandler,
- GrGLSLFPFragmentBuilder* fragBuilder,
- const char* z) {
+void GpuSpotLight::emitSurfaceToLight(const GrFragmentProcessor* owner,
+ GrGLSLUniformHandler* uniformHandler,
+ GrGLSLFPFragmentBuilder* fragBuilder,
+ const char* z) {
const char* location;
fLocationUni = uniformHandler->addUniform(owner, kFragment_GrShaderFlag, kHalf3_GrSLType,
"LightLocation", &location);
@@ -2065,11 +2079,10 @@
location, z);
}
-void GrGLSpotLight::emitLightColor(const GrFragmentProcessor* owner,
- GrGLSLUniformHandler* uniformHandler,
- GrGLSLFPFragmentBuilder* fragBuilder,
- const char *surfaceToLight) {
-
+void GpuSpotLight::emitLightColor(const GrFragmentProcessor* owner,
+ GrGLSLUniformHandler* uniformHandler,
+ GrGLSLFPFragmentBuilder* fragBuilder,
+ const char* surfaceToLight) {
const char* color = uniformHandler->getUniformCStr(this->lightColorUni()); // created by parent class.
const char* exponent;
diff --git a/src/effects/imagefilters/SkMorphologyImageFilter.cpp b/src/effects/imagefilters/SkMorphologyImageFilter.cpp
index 95cd5df..ca3c55d 100644
--- a/src/effects/imagefilters/SkMorphologyImageFilter.cpp
+++ b/src/effects/imagefilters/SkMorphologyImageFilter.cpp
@@ -271,7 +271,7 @@
fragBuilder->codeAppendf("return color * %s;", inputColor.c_str());
}
- protected:
+ private:
void onSetData(const GrGLSLProgramDataManager& pdman,
const GrFragmentProcessor& proc) override {
const GrMorphologyEffect& m = proc.cast<GrMorphologyEffect>();
@@ -280,9 +280,9 @@
}
}
- private:
GrGLSLProgramDataManager::UniformHandle fRangeUni;
};
+
return std::make_unique<Impl>();
}
diff --git a/src/gpu/GrColorSpaceXform.cpp b/src/gpu/GrColorSpaceXform.cpp
index 21af870..e1af8fa 100644
--- a/src/gpu/GrColorSpaceXform.cpp
+++ b/src/gpu/GrColorSpaceXform.cpp
@@ -63,36 +63,6 @@
//////////////////////////////////////////////////////////////////////////////
-class GrGLColorSpaceXformEffect : public GrFragmentProcessor::ProgramImpl {
-public:
- void emitCode(EmitArgs& args) override {
- const GrColorSpaceXformEffect& proc = args.fFp.cast<GrColorSpaceXformEffect>();
- GrGLSLFPFragmentBuilder* fragBuilder = args.fFragBuilder;
- GrGLSLUniformHandler* uniformHandler = args.fUniformHandler;
-
- fColorSpaceHelper.emitCode(uniformHandler, proc.colorXform());
-
- SkString childColor = this->invokeChild(0, args);
-
- SkString xformedColor;
- fragBuilder->appendColorGamutXform(&xformedColor, childColor.c_str(), &fColorSpaceHelper);
- fragBuilder->codeAppendf("return %s;", xformedColor.c_str());
- }
-
-private:
- void onSetData(const GrGLSLProgramDataManager& pdman,
- const GrFragmentProcessor& fp) override {
- const GrColorSpaceXformEffect& proc = fp.cast<GrColorSpaceXformEffect>();
- fColorSpaceHelper.setData(pdman, proc.colorXform());
- }
-
- GrGLSLColorSpaceXformHelper fColorSpaceHelper;
-
- using INHERITED = ProgramImpl;
-};
-
-//////////////////////////////////////////////////////////////////////////////
-
GrColorSpaceXformEffect::GrColorSpaceXformEffect(std::unique_ptr<GrFragmentProcessor> child,
sk_sp<GrColorSpaceXform> colorXform)
: INHERITED(kGrColorSpaceXformEffect_ClassID, OptFlags(child.get()))
@@ -119,7 +89,34 @@
std::unique_ptr<GrFragmentProcessor::ProgramImpl>
GrColorSpaceXformEffect::onMakeProgramImpl() const {
- return std::make_unique<GrGLColorSpaceXformEffect>();
+ class Impl : public ProgramImpl {
+ public:
+ void emitCode(EmitArgs& args) override {
+ const GrColorSpaceXformEffect& proc = args.fFp.cast<GrColorSpaceXformEffect>();
+ GrGLSLFPFragmentBuilder* fragBuilder = args.fFragBuilder;
+ GrGLSLUniformHandler* uniformHandler = args.fUniformHandler;
+
+ fColorSpaceHelper.emitCode(uniformHandler, proc.colorXform());
+
+ SkString childColor = this->invokeChild(0, args);
+
+ SkString xformedColor;
+ fragBuilder->appendColorGamutXform(
+ &xformedColor, childColor.c_str(), &fColorSpaceHelper);
+ fragBuilder->codeAppendf("return %s;", xformedColor.c_str());
+ }
+
+ private:
+ void onSetData(const GrGLSLProgramDataManager& pdman,
+ const GrFragmentProcessor& fp) override {
+ const GrColorSpaceXformEffect& proc = fp.cast<GrColorSpaceXformEffect>();
+ fColorSpaceHelper.setData(pdman, proc.colorXform());
+ }
+
+ GrGLSLColorSpaceXformHelper fColorSpaceHelper;
+ };
+
+ return std::make_unique<Impl>();
}
GrFragmentProcessor::OptimizationFlags GrColorSpaceXformEffect::OptFlags(
diff --git a/src/gpu/GrFragmentProcessor.cpp b/src/gpu/GrFragmentProcessor.cpp
index bdec6d0..edc5850 100644
--- a/src/gpu/GrFragmentProcessor.cpp
+++ b/src/gpu/GrFragmentProcessor.cpp
@@ -272,7 +272,6 @@
}
const char* name() const override { return "Swizzle"; }
- const GrSwizzle& swizzle() const { return fSwizzle; }
std::unique_ptr<GrFragmentProcessor> clone() const override {
return Make(this->childProcessor(0)->clone(), fSwizzle);
@@ -286,20 +285,20 @@
}
std::unique_ptr<ProgramImpl> onMakeProgramImpl() const override {
- class GLFP : public ProgramImpl {
+ class Impl : public ProgramImpl {
public:
void emitCode(EmitArgs& args) override {
SkString childColor = this->invokeChild(0, args);
const SwizzleFragmentProcessor& sfp = args.fFp.cast<SwizzleFragmentProcessor>();
- const GrSwizzle& swizzle = sfp.swizzle();
+ const GrSwizzle& swizzle = sfp.fSwizzle;
GrGLSLFPFragmentBuilder* fragBuilder = args.fFragBuilder;
fragBuilder->codeAppendf("return %s.%s;",
childColor.c_str(), swizzle.asString().c_str());
}
};
- return std::make_unique<GLFP>();
+ return std::make_unique<Impl>();
}
void onAddToKey(const GrShaderCaps&, GrProcessorKeyBuilder* b) const override {
@@ -352,7 +351,7 @@
}
std::unique_ptr<ProgramImpl> onMakeProgramImpl() const override {
- class GLFP : public ProgramImpl {
+ class Impl : public ProgramImpl {
public:
void emitCode(EmitArgs& args) override {
GrGLSLFPFragmentBuilder* fragBuilder = args.fFragBuilder;
@@ -362,7 +361,7 @@
fragBuilder->codeAppendf("return color * %s.a;", args.fInputColor);
}
};
- return std::make_unique<GLFP>();
+ return std::make_unique<Impl>();
}
void onAddToKey(const GrShaderCaps&, GrProcessorKeyBuilder*) const override {}
@@ -471,7 +470,7 @@
private:
std::unique_ptr<ProgramImpl> onMakeProgramImpl() const override {
- class GLFP : public ProgramImpl {
+ class Impl : public ProgramImpl {
public:
void emitCode(EmitArgs& args) override {
SkString result = this->invokeChild(1, args); // g(x)
@@ -479,7 +478,7 @@
args.fFragBuilder->codeAppendf("return %s;", result.c_str());
}
};
- return std::make_unique<GLFP>();
+ return std::make_unique<Impl>();
}
ComposeProcessor(std::unique_ptr<GrFragmentProcessor> f,
@@ -601,14 +600,14 @@
private:
std::unique_ptr<ProgramImpl> onMakeProgramImpl() const override {
- class GLFP : public ProgramImpl {
+ class Impl : public ProgramImpl {
public:
void emitCode(EmitArgs& args) override {
const char* dstColor = args.fFragBuilder->dstColor();
args.fFragBuilder->codeAppendf("return %s;", dstColor);
}
};
- return std::make_unique<GLFP>();
+ return std::make_unique<Impl>();
}
SurfaceColorProcessor()
@@ -902,7 +901,7 @@
}
std::unique_ptr<ProgramImpl> onMakeProgramImpl() const override {
- class GLFP : public ProgramImpl {
+ class Impl : public ProgramImpl {
public:
void emitCode(EmitArgs& args) override {
SkString childColor = this->invokeChild(0, args);
@@ -911,7 +910,7 @@
args.fFragBuilder->codeAppendf("return %s;", childColor.c_str());
}
};
- return std::make_unique<GLFP>();
+ return std::make_unique<Impl>();
}
void onAddToKey(const GrShaderCaps&, GrProcessorKeyBuilder*) const override {}
diff --git a/src/gpu/effects/GrBicubicEffect.cpp b/src/gpu/effects/GrBicubicEffect.cpp
index 5585ea0..609ca73 100644
--- a/src/gpu/effects/GrBicubicEffect.cpp
+++ b/src/gpu/effects/GrBicubicEffect.cpp
@@ -16,18 +16,15 @@
#include "src/gpu/glsl/GrGLSLUniformHandler.h"
#include <cmath>
-class GrBicubicEffect::Impl : public GrFragmentProcessor::ProgramImpl {
+class GrBicubicEffect::Impl : public ProgramImpl {
public:
- Impl() : fKernel{-1, -1} {}
void emitCode(EmitArgs&) override;
-protected:
+private:
void onSetData(const GrGLSLProgramDataManager&, const GrFragmentProcessor&) override;
-private:
- SkImage::CubicResampler fKernel;
+ SkImage::CubicResampler fKernel = {-1, -1};
UniformHandle fCoefficientUni;
- using INHERITED = ProgramImpl;
};
void GrBicubicEffect::Impl::emitCode(EmitArgs& args) {
diff --git a/src/gpu/effects/GrBlendFragmentProcessor.cpp b/src/gpu/effects/GrBlendFragmentProcessor.cpp
index 8604bba..833ade4 100644
--- a/src/gpu/effects/GrBlendFragmentProcessor.cpp
+++ b/src/gpu/effects/GrBlendFragmentProcessor.cpp
@@ -38,8 +38,6 @@
std::unique_ptr<GrFragmentProcessor> clone() const override;
- SkBlendMode getMode() const { return fMode; }
-
private:
BlendFragmentProcessor(std::unique_ptr<GrFragmentProcessor> src,
std::unique_ptr<GrFragmentProcessor> dst,
@@ -171,15 +169,6 @@
/////////////////////////////////////////////////////////////////////
-class GLBlendFragmentProcessor : public GrFragmentProcessor::ProgramImpl {
-public:
- void emitCode(EmitArgs&) override;
-
-private:
- using INHERITED = ProgramImpl;
-};
-
-/////////////////////////////////////////////////////////////////////
GR_DEFINE_FRAGMENT_PROCESSOR_TEST(BlendFragmentProcessor);
@@ -206,25 +195,28 @@
}
std::unique_ptr<GrFragmentProcessor::ProgramImpl> BlendFragmentProcessor::onMakeProgramImpl() const {
- return std::make_unique<GLBlendFragmentProcessor>();
-}
+ class Impl : public ProgramImpl {
+ public:
+ void emitCode(EmitArgs& args) override {
+ GrGLSLFPFragmentBuilder* fragBuilder = args.fFragBuilder;
+ const BlendFragmentProcessor& bfp = args.fFp.cast<BlendFragmentProcessor>();
+ SkBlendMode mode = bfp.fMode;
-/////////////////////////////////////////////////////////////////////
+ fragBuilder->codeAppendf("// Blend mode: %s\n", SkBlendMode_Name(mode));
-void GLBlendFragmentProcessor::emitCode(EmitArgs& args) {
- GrGLSLFPFragmentBuilder* fragBuilder = args.fFragBuilder;
- const BlendFragmentProcessor& cs = args.fFp.cast<BlendFragmentProcessor>();
- SkBlendMode mode = cs.getMode();
+ // Invoke src/dst with our input color (or substitute input color if no child FP)
+ SkString srcColor = this->invokeChild(0, args);
+ SkString dstColor = this->invokeChild(1, args);
- fragBuilder->codeAppendf("// Blend mode: %s\n", SkBlendMode_Name(mode));
+ // Blend src and dst colors together.
+ fragBuilder->codeAppendf("return %s(%s, %s);",
+ GrGLSLBlend::BlendFuncName(mode),
+ srcColor.c_str(),
+ dstColor.c_str());
+ }
+ };
- // Invoke src/dst with our input color (or substitute input color if no child FP)
- SkString srcColor = this->invokeChild(0, args);
- SkString dstColor = this->invokeChild(1, args);
-
- // Blend src and dst colors together.
- fragBuilder->codeAppendf("return %s(%s, %s);", GrGLSLBlend::BlendFuncName(mode),
- srcColor.c_str(), dstColor.c_str());
+ return std::make_unique<Impl>();
}
//////////////////////////////////////////////////////////////////////////////
diff --git a/src/gpu/effects/GrConvexPolyEffect.cpp b/src/gpu/effects/GrConvexPolyEffect.cpp
index 1b4acae..9e1a44f 100644
--- a/src/gpu/effects/GrConvexPolyEffect.cpp
+++ b/src/gpu/effects/GrConvexPolyEffect.cpp
@@ -15,77 +15,6 @@
//////////////////////////////////////////////////////////////////////////////
-class GrGLConvexPolyEffect : public GrFragmentProcessor::ProgramImpl {
-public:
- GrGLConvexPolyEffect() {
- for (size_t i = 0; i < SK_ARRAY_COUNT(fPrevEdges); ++i) {
- fPrevEdges[i] = SK_ScalarNaN;
- }
- }
-
- void emitCode(EmitArgs&) override;
-
- static inline void GenKey(const GrProcessor&, const GrShaderCaps&, GrProcessorKeyBuilder*);
-
-protected:
- void onSetData(const GrGLSLProgramDataManager&, const GrFragmentProcessor&) override;
-
-private:
- GrGLSLProgramDataManager::UniformHandle fEdgeUniform;
- SkScalar fPrevEdges[3 * GrConvexPolyEffect::kMaxEdges];
- using INHERITED = ProgramImpl;
-};
-
-void GrGLConvexPolyEffect::emitCode(EmitArgs& args) {
- const GrConvexPolyEffect& cpe = args.fFp.cast<GrConvexPolyEffect>();
-
- using namespace SkSL::dsl;
- StartFragmentProcessor(this, &args);
- GlobalVar edgeArray(kUniform_Modifier, Array(kHalf3_Type, cpe.getEdgeCount()), "edgeArray");
- Declare(edgeArray);
- fEdgeUniform = VarUniformHandle(edgeArray);
- Var alpha(kHalf_Type, "alpha", 1);
- Declare(alpha);
- Var edge(kHalf_Type, "edge");
- Declare(edge);
- for (int i = 0; i < cpe.getEdgeCount(); ++i) {
- edge = Dot(edgeArray[i], Half3(Swizzle(sk_FragCoord(), X, Y, ONE)));
- if (GrClipEdgeTypeIsAA(cpe.getEdgeType())) {
- edge = Saturate(edge);
- } else {
- edge = Select(edge >= 0.5, 1.0, 0.0);
- }
- alpha *= edge;
- }
-
- if (GrClipEdgeTypeIsInverseFill(cpe.getEdgeType())) {
- alpha = 1.0 - alpha;
- }
-
- Return(SampleChild(0) * alpha);
- EndFragmentProcessor();
-}
-
-void GrGLConvexPolyEffect::onSetData(const GrGLSLProgramDataManager& pdman,
- const GrFragmentProcessor& effect) {
- const GrConvexPolyEffect& cpe = effect.cast<GrConvexPolyEffect>();
- size_t byteSize = 3 * cpe.getEdgeCount() * sizeof(SkScalar);
- if (0 != memcmp(fPrevEdges, cpe.getEdges(), byteSize)) {
- pdman.set3fv(fEdgeUniform, cpe.getEdgeCount(), cpe.getEdges());
- memcpy(fPrevEdges, cpe.getEdges(), byteSize);
- }
-}
-
-void GrGLConvexPolyEffect::GenKey(const GrProcessor& processor, const GrShaderCaps&,
- GrProcessorKeyBuilder* b) {
- const GrConvexPolyEffect& cpe = processor.cast<GrConvexPolyEffect>();
- static_assert(kGrClipEdgeTypeCnt <= 8);
- uint32_t key = (cpe.getEdgeCount() << 3) | (int) cpe.getEdgeType();
- b->add32(key);
-}
-
-//////////////////////////////////////////////////////////////////////////////
-
GrFPResult GrConvexPolyEffect::Make(std::unique_ptr<GrFragmentProcessor> inputFP,
GrClipEdgeType type, const SkPath& path) {
if (path.getSegmentMasks() != SkPath::kLine_SegmentMask || !path.isConvex()) {
@@ -158,17 +87,66 @@
GrConvexPolyEffect::~GrConvexPolyEffect() {}
void GrConvexPolyEffect::onAddToKey(const GrShaderCaps& caps, GrProcessorKeyBuilder* b) const {
- GrGLConvexPolyEffect::GenKey(*this, caps, b);
+ static_assert(kGrClipEdgeTypeCnt <= 8);
+ uint32_t key = (fEdgeCount << 3) | static_cast<int>(fEdgeType);
+ b->add32(key);
}
std::unique_ptr<GrFragmentProcessor::ProgramImpl> GrConvexPolyEffect::onMakeProgramImpl() const {
- return std::make_unique<GrGLConvexPolyEffect>();
+ class Impl : public ProgramImpl {
+ public:
+ void emitCode(EmitArgs& args) override {
+ const GrConvexPolyEffect& cpe = args.fFp.cast<GrConvexPolyEffect>();
+
+ using namespace SkSL::dsl;
+ StartFragmentProcessor(this, &args);
+ GlobalVar edgeArray(kUniform_Modifier, Array(kHalf3_Type, cpe.fEdgeCount), "edgeArray");
+ Declare(edgeArray);
+ fEdgeUniform = VarUniformHandle(edgeArray);
+ Var alpha(kHalf_Type, "alpha", 1);
+ Declare(alpha);
+ Var edge(kHalf_Type, "edge");
+ Declare(edge);
+ for (int i = 0; i < cpe.fEdgeCount; ++i) {
+ edge = Dot(edgeArray[i], Half3(Swizzle(sk_FragCoord(), X, Y, ONE)));
+ if (GrClipEdgeTypeIsAA(cpe.fEdgeType)) {
+ edge = Saturate(edge);
+ } else {
+ edge = Select(edge >= 0.5, 1.0, 0.0);
+ }
+ alpha *= edge;
+ }
+
+ if (GrClipEdgeTypeIsInverseFill(cpe.fEdgeType)) {
+ alpha = 1.0 - alpha;
+ }
+
+ Return(SampleChild(0) * alpha);
+ EndFragmentProcessor();
+ }
+
+ private:
+ void onSetData(const GrGLSLProgramDataManager& pdman,
+ const GrFragmentProcessor& fp) override {
+ const GrConvexPolyEffect& cpe = fp.cast<GrConvexPolyEffect>();
+ size_t n = 3*cpe.fEdgeCount;
+ if (!std::equal(fPrevEdges.begin(), fPrevEdges.begin() + n, cpe.fEdges.begin())) {
+ pdman.set3fv(fEdgeUniform, cpe.fEdgeCount, cpe.fEdges.data());
+ std::copy_n(cpe.fEdges.begin(), n, fPrevEdges.begin());
+ }
+ }
+
+ GrGLSLProgramDataManager::UniformHandle fEdgeUniform;
+ std::array<float, 3 * GrConvexPolyEffect::kMaxEdges> fPrevEdges = {SK_FloatNaN};
+ };
+
+ return std::make_unique<Impl>();
}
GrConvexPolyEffect::GrConvexPolyEffect(std::unique_ptr<GrFragmentProcessor> inputFP,
GrClipEdgeType edgeType,
int n,
- const SkScalar edges[])
+ const float edges[])
: INHERITED(kGrConvexPolyEffect_ClassID,
ProcessorOptimizationFlags(inputFP.get()) &
kCompatibleWithCoverageAsAlpha_OptimizationFlag)
@@ -176,7 +154,7 @@
, fEdgeCount(n) {
// Factory function should have already ensured this.
SkASSERT(n <= kMaxEdges);
- memcpy(fEdges, edges, 3 * n * sizeof(SkScalar));
+ std::copy_n(edges, 3*n, fEdges.begin());
// Outset the edges by 0.5 so that a pixel with center on an edge is 50% covered in the AA case
// and 100% covered in the non-AA case.
for (int i = 0; i < n; ++i) {
@@ -190,7 +168,7 @@
: INHERITED(that)
, fEdgeType(that.fEdgeType)
, fEdgeCount(that.fEdgeCount) {
- memcpy(fEdges, that.fEdges, 3 * that.fEdgeCount * sizeof(SkScalar));
+ std::copy_n(that.fEdges.begin(), 3*that.fEdgeCount, fEdges.begin());
}
std::unique_ptr<GrFragmentProcessor> GrConvexPolyEffect::clone() const {
@@ -199,9 +177,10 @@
bool GrConvexPolyEffect::onIsEqual(const GrFragmentProcessor& other) const {
const GrConvexPolyEffect& cpe = other.cast<GrConvexPolyEffect>();
- // ignore the fact that 0 == -0 and just use memcmp.
- return (cpe.fEdgeType == fEdgeType && cpe.fEdgeCount == fEdgeCount &&
- 0 == memcmp(cpe.fEdges, fEdges, 3 * fEdgeCount * sizeof(SkScalar)));
+ int n = 3*cpe.fEdgeCount;
+ return cpe.fEdgeType == fEdgeType &&
+ cpe.fEdgeCount == fEdgeCount &&
+ std::equal(cpe.fEdges.begin(), cpe.fEdges.begin() + n, fEdges.begin());
}
//////////////////////////////////////////////////////////////////////////////
diff --git a/src/gpu/effects/GrConvexPolyEffect.h b/src/gpu/effects/GrConvexPolyEffect.h
index bdc7a4f..e2bcc94 100644
--- a/src/gpu/effects/GrConvexPolyEffect.h
+++ b/src/gpu/effects/GrConvexPolyEffect.h
@@ -37,7 +37,9 @@
* to the view matrix or untransformed positions in the fragment shader).
*/
static GrFPResult Make(std::unique_ptr<GrFragmentProcessor> inputFP,
- GrClipEdgeType edgeType, int n, const SkScalar edges[]) {
+ GrClipEdgeType edgeType,
+ int n,
+ const float edges[]) {
if (n <= 0 || n > kMaxEdges) {
return GrFPFailure(std::move(inputFP));
}
@@ -57,12 +59,6 @@
const char* name() const override { return "ConvexPoly"; }
std::unique_ptr<GrFragmentProcessor> clone() const override;
- GrClipEdgeType getEdgeType() const { return fEdgeType; }
-
- int getEdgeCount() const { return fEdgeCount; }
-
- const SkScalar* getEdges() const { return fEdges; }
-
private:
GrConvexPolyEffect(std::unique_ptr<GrFragmentProcessor> inputFP,
GrClipEdgeType edgeType,
@@ -75,9 +71,9 @@
bool onIsEqual(const GrFragmentProcessor& other) const override;
- GrClipEdgeType fEdgeType;
- int fEdgeCount;
- SkScalar fEdges[3 * kMaxEdges];
+ GrClipEdgeType fEdgeType;
+ int fEdgeCount;
+ std::array<float, 3*kMaxEdges> fEdges;
GR_DECLARE_FRAGMENT_PROCESSOR_TEST
diff --git a/src/gpu/effects/GrGaussianConvolutionFragmentProcessor.cpp b/src/gpu/effects/GrGaussianConvolutionFragmentProcessor.cpp
index d03e9ef..755b372 100644
--- a/src/gpu/effects/GrGaussianConvolutionFragmentProcessor.cpp
+++ b/src/gpu/effects/GrGaussianConvolutionFragmentProcessor.cpp
@@ -21,22 +21,17 @@
using UniformHandle = GrGLSLProgramDataManager::UniformHandle;
using Direction = GrGaussianConvolutionFragmentProcessor::Direction;
-class GrGaussianConvolutionFragmentProcessor::Impl : public GrFragmentProcessor::ProgramImpl {
+class GrGaussianConvolutionFragmentProcessor::Impl : public ProgramImpl {
public:
void emitCode(EmitArgs&) override;
- static inline void GenKey(const GrProcessor&, const GrShaderCaps&, GrProcessorKeyBuilder*);
-
-protected:
+private:
void onSetData(const GrGLSLProgramDataManager&, const GrFragmentProcessor&) override;
-private:
UniformHandle fKernelUni;
UniformHandle fOffsetsUni;
UniformHandle fKernelWidthUni;
UniformHandle fIncrementUni;
-
- using INHERITED = ProgramImpl;
};
enum class LoopType {
@@ -143,15 +138,6 @@
}
}
-void GrGaussianConvolutionFragmentProcessor::Impl::GenKey(const GrProcessor& processor,
- const GrShaderCaps& shaderCaps,
- GrProcessorKeyBuilder* b) {
- const auto& conv = processor.cast<GrGaussianConvolutionFragmentProcessor>();
- if (loop_type(shaderCaps) != LoopType::kVariableLength) {
- b->add32(conv.fRadius);
- }
-}
-
///////////////////////////////////////////////////////////////////////////////
std::unique_ptr<GrFragmentProcessor> GrGaussianConvolutionFragmentProcessor::Make(
@@ -234,9 +220,11 @@
memcpy(fOffsets, that.fOffsets, SkGpuBlurUtils::LinearKernelWidth(fRadius) * sizeof(float));
}
-void GrGaussianConvolutionFragmentProcessor::onAddToKey(const GrShaderCaps& caps,
+void GrGaussianConvolutionFragmentProcessor::onAddToKey(const GrShaderCaps& shaderCaps,
GrProcessorKeyBuilder* b) const {
- Impl::GenKey(*this, caps, b);
+ if (loop_type(shaderCaps) != LoopType::kVariableLength) {
+ b->add32(fRadius);
+ }
}
std::unique_ptr<GrFragmentProcessor::ProgramImpl>
diff --git a/src/gpu/effects/GrGaussianConvolutionFragmentProcessor.h b/src/gpu/effects/GrGaussianConvolutionFragmentProcessor.h
index 5eff228..8bb67b2 100644
--- a/src/gpu/effects/GrGaussianConvolutionFragmentProcessor.h
+++ b/src/gpu/effects/GrGaussianConvolutionFragmentProcessor.h
@@ -52,6 +52,8 @@
static constexpr int kMaxKernelRadius = 12;
private:
+ class Impl;
+
GrGaussianConvolutionFragmentProcessor(std::unique_ptr<GrFragmentProcessor>,
Direction,
int halfWidth,
@@ -83,8 +85,6 @@
int fRadius;
Direction fDirection;
- class Impl;
-
using INHERITED = GrFragmentProcessor;
};
diff --git a/src/gpu/effects/GrMatrixConvolutionEffect.cpp b/src/gpu/effects/GrMatrixConvolutionEffect.cpp
index 82239c3..ae16a49 100644
--- a/src/gpu/effects/GrMatrixConvolutionEffect.cpp
+++ b/src/gpu/effects/GrMatrixConvolutionEffect.cpp
@@ -20,16 +20,13 @@
#include "src/gpu/glsl/GrGLSLProgramDataManager.h"
#include "src/gpu/glsl/GrGLSLUniformHandler.h"
-class GrGLMatrixConvolutionEffect : public GrFragmentProcessor::ProgramImpl {
+class GrMatrixConvolutionEffect::Impl : public ProgramImpl {
public:
void emitCode(EmitArgs&) override;
- static inline void GenKey(const GrProcessor&, const GrShaderCaps&, GrProcessorKeyBuilder*);
-
-protected:
+private:
void onSetData(const GrGLSLProgramDataManager&, const GrFragmentProcessor&) override;
-private:
typedef GrGLSLProgramDataManager::UniformHandle UniformHandle;
void emitKernelBlock(EmitArgs&, SkIPoint);
@@ -160,15 +157,15 @@
// For sampled kernels, emit a for loop that does all the kernel accumulation.
// For uniform kernels, emit a single iteration. Function is called repeatedly in a for loop.
// loc is ignored for sampled kernels.
-void GrGLMatrixConvolutionEffect::emitKernelBlock(EmitArgs& args, SkIPoint loc) {
+void GrMatrixConvolutionEffect::Impl::emitKernelBlock(EmitArgs& args, SkIPoint loc) {
const GrMatrixConvolutionEffect& mce = args.fFp.cast<GrMatrixConvolutionEffect>();
GrGLSLFPFragmentBuilder* fragBuilder = args.fFragBuilder;
GrGLSLUniformHandler* uniformHandler = args.fUniformHandler;
- int kernelWidth = mce.kernelSize().width();
- int kernelHeight = mce.kernelSize().height();
+ int kernelWidth = mce.fKernel.size().width();
+ int kernelHeight = mce.fKernel.size().height();
int kernelArea = kernelWidth * kernelHeight;
- if (mce.kernelIsSampled()) {
+ if (mce.fKernel.isSampled()) {
fragBuilder->codeAppendf("for (int i = 0; i < %d; ++i)", (int)kernelArea);
}
@@ -176,7 +173,7 @@
fragBuilder->codeAppend("half k;");
fragBuilder->codeAppend("half2 sourceOffset;");
- if (mce.kernelIsSampled()) {
+ if (mce.fKernel.isSampled()) {
const char* kernelBias = uniformHandler->getUniformCStr(fKernelBiasUni);
SkString kernelSample = this->invokeChild(1, args, "float2(float(i) + 0.5, 0.5)");
fragBuilder->codeAppendf("k = %s.w + %s;", kernelSample.c_str(), kernelBias);
@@ -191,24 +188,24 @@
auto sample = this->invokeChild(0, args, "coord + sourceOffset");
fragBuilder->codeAppendf("half4 c = %s;", sample.c_str());
- if (!mce.convolveAlpha()) {
+ if (!mce.fConvolveAlpha) {
fragBuilder->codeAppend("c = unpremul(c);");
fragBuilder->codeAppend("c.rgb = saturate(c.rgb);");
}
fragBuilder->codeAppend("sum += c * k;");
}
-void GrGLMatrixConvolutionEffect::emitCode(EmitArgs& args) {
+void GrMatrixConvolutionEffect::Impl::emitCode(EmitArgs& args) {
const GrMatrixConvolutionEffect& mce = args.fFp.cast<GrMatrixConvolutionEffect>();
- int kernelWidth = mce.kernelSize().width();
- int kernelHeight = mce.kernelSize().height();
+ int kernelWidth = mce.fKernel.size().width();
+ int kernelHeight = mce.fKernel.size().height();
int arrayCount = (kernelWidth * kernelHeight + 3) / 4;
SkASSERT(4 * arrayCount >= kernelWidth * kernelHeight);
GrGLSLUniformHandler* uniformHandler = args.fUniformHandler;
- if (mce.kernelIsSampled()) {
+ if (mce.fKernel.isSampled()) {
fKernelBiasUni = uniformHandler->addUniform(&mce, kFragment_GrShaderFlag,
kHalf_GrSLType, "KernelBias");
} else {
@@ -228,7 +225,7 @@
fragBuilder->codeAppend("half4 sum = half4(0);");
fragBuilder->codeAppendf("float2 coord = %s - %s;", args.fSampleCoord, kernelOffset);
- if (mce.kernelIsSampled()) {
+ if (mce.fKernel.isSampled()) {
this->emitKernelBlock(args, {});
} else {
for (int x = 0; x < kernelWidth; ++x) {
@@ -239,7 +236,7 @@
}
fragBuilder->codeAppendf("half4 color;");
- if (mce.convolveAlpha()) {
+ if (mce.fConvolveAlpha) {
fragBuilder->codeAppendf("color = sum * %s + %s;", gain, bias);
fragBuilder->codeAppendf("color.a = saturate(color.a);");
fragBuilder->codeAppendf("color.rgb = clamp(color.rgb, 0.0, color.a);");
@@ -253,30 +250,21 @@
fragBuilder->codeAppendf("return color;");
}
-void GrGLMatrixConvolutionEffect::GenKey(const GrProcessor& processor,
- const GrShaderCaps&, GrProcessorKeyBuilder* b) {
- const GrMatrixConvolutionEffect& m = processor.cast<GrMatrixConvolutionEffect>();
- SkASSERT(m.kernelSize().width() <= 0x7FFF && m.kernelSize().height() <= 0xFFFF);
- uint32_t key = m.kernelSize().width() << 16 | m.kernelSize().height();
- key |= m.convolveAlpha() ? 1U << 31 : 0;
- b->add32(key);
-}
-
-void GrGLMatrixConvolutionEffect::onSetData(const GrGLSLProgramDataManager& pdman,
- const GrFragmentProcessor& processor) {
+void GrMatrixConvolutionEffect::Impl::onSetData(const GrGLSLProgramDataManager& pdman,
+ const GrFragmentProcessor& processor) {
const GrMatrixConvolutionEffect& conv = processor.cast<GrMatrixConvolutionEffect>();
- pdman.set2f(fKernelOffsetUni, conv.kernelOffset().fX, conv.kernelOffset().fY);
- float totalGain = conv.gain();
- if (conv.kernelIsSampled()) {
- totalGain *= conv.kernelSampleGain();
- pdman.set1f(fKernelBiasUni, conv.kernelSampleBias());
+ pdman.set2f(fKernelOffsetUni, conv.fKernelOffset.fX, conv.fKernelOffset.fY);
+ float totalGain = conv.fGain;
+ if (conv.fKernel.isSampled()) {
+ totalGain *= conv.fKernel.biasAndGain().fGain;
+ pdman.set1f(fKernelBiasUni, conv.fKernel.biasAndGain().fBias);
} else {
- int kernelCount = conv.kernelSize().area();
+ int kernelCount = conv.fKernel.size().area();
int arrayCount = (kernelCount + 3) / 4;
SkASSERT(4 * arrayCount >= kernelCount);
- pdman.set4fv(fKernelUni, arrayCount, conv.kernel());
+ pdman.set4fv(fKernelUni, arrayCount, conv.fKernel.array().data());
}
- pdman.set1f(fBiasUni, conv.bias());
+ pdman.set1f(fBiasUni, conv.fBias);
pdman.set1f(fGainUni, totalGain);
}
@@ -315,21 +303,24 @@
void GrMatrixConvolutionEffect::onAddToKey(const GrShaderCaps& caps,
GrProcessorKeyBuilder* b) const {
- GrGLMatrixConvolutionEffect::GenKey(*this, caps, b);
+ SkASSERT(this->fKernel.size().width() <= 0x7FFF && this->fKernel.size().height() <= 0xFFFF);
+ uint32_t key = this->fKernel.size().width() << 16 | this->fKernel.size().height();
+ key |= fConvolveAlpha ? 1U << 31 : 0;
+ b->add32(key);
}
std::unique_ptr<GrFragmentProcessor::ProgramImpl>
GrMatrixConvolutionEffect::onMakeProgramImpl() const {
- return std::make_unique<GrGLMatrixConvolutionEffect>();
+ return std::make_unique<Impl>();
}
bool GrMatrixConvolutionEffect::onIsEqual(const GrFragmentProcessor& sBase) const {
const GrMatrixConvolutionEffect& s = sBase.cast<GrMatrixConvolutionEffect>();
- return fKernel == s.fKernel &&
- fGain == s.gain() &&
- fBias == s.bias() &&
- fKernelOffset == s.kernelOffset() &&
- fConvolveAlpha == s.convolveAlpha();
+ return fKernel == s.fKernel &&
+ fGain == s.fGain &&
+ fBias == s.fBias &&
+ fKernelOffset == s.fKernelOffset &&
+ fConvolveAlpha == s.fConvolveAlpha;
}
std::unique_ptr<GrFragmentProcessor> GrMatrixConvolutionEffect::Make(GrRecordingContext* context,
diff --git a/src/gpu/effects/GrMatrixConvolutionEffect.h b/src/gpu/effects/GrMatrixConvolutionEffect.h
index 2e29c2e..eb09746 100644
--- a/src/gpu/effects/GrMatrixConvolutionEffect.h
+++ b/src/gpu/effects/GrMatrixConvolutionEffect.h
@@ -31,22 +31,13 @@
bool convolveAlpha,
const GrCaps&);
- const SkIRect& bounds() const { return fBounds; }
- SkISize kernelSize() const { return fKernel.size(); }
- SkVector kernelOffset() const { return fKernelOffset; }
- bool kernelIsSampled() const { return fKernel.isSampled(); }
- const float *kernel() const { return fKernel.array().data(); }
- float kernelSampleGain() const { return fKernel.biasAndGain().fGain; }
- float kernelSampleBias() const { return fKernel.biasAndGain().fBias; }
- float gain() const { return fGain; }
- float bias() const { return fBias; }
- bool convolveAlpha() const { return fConvolveAlpha; }
-
const char* name() const override { return "MatrixConvolution"; }
std::unique_ptr<GrFragmentProcessor> clone() const override;
private:
+ class Impl;
+
/**
* Small kernels are represented as float-arrays and uploaded as uniforms.
* Large kernels go over the uniform limit and are uploaded as textures and sampled.
@@ -116,7 +107,6 @@
bool onIsEqual(const GrFragmentProcessor&) const override;
- SkIRect fBounds;
KernelWrapper fKernel;
float fGain;
float fBias;
diff --git a/src/gpu/effects/GrMatrixEffect.cpp b/src/gpu/effects/GrMatrixEffect.cpp
index 3411930..8d2ad7b 100644
--- a/src/gpu/effects/GrMatrixEffect.cpp
+++ b/src/gpu/effects/GrMatrixEffect.cpp
@@ -14,42 +14,13 @@
#include "src/gpu/glsl/GrGLSLProgramBuilder.h"
#include "src/sksl/SkSLUtil.h"
-class GrGLSLMatrixEffect : public GrFragmentProcessor::ProgramImpl {
-public:
- GrGLSLMatrixEffect() {}
-
- void emitCode(EmitArgs& args) override {
- fMatrixVar = args.fUniformHandler->addUniform(&args.fFp,
- kFragment_GrShaderFlag,
- kFloat3x3_GrSLType,
- SkSL::SampleUsage::MatrixUniformName());
- args.fFragBuilder->codeAppendf("return %s;\n",
- this->invokeChildWithMatrix(0, args).c_str());
- }
-
-private:
- void onSetData(const GrGLSLProgramDataManager& pdman,
- const GrFragmentProcessor& proc) override {
- const GrMatrixEffect& mtx = proc.cast<GrMatrixEffect>();
- if (auto te = mtx.childProcessor(0)->asTextureEffect()) {
- SkMatrix m = te->coordAdjustmentMatrix();
- m.preConcat(mtx.matrix());
- pdman.setSkMatrix(fMatrixVar, m);
- } else {
- pdman.setSkMatrix(fMatrixVar, mtx.matrix());
- }
- }
-
- UniformHandle fMatrixVar;
-};
-
std::unique_ptr<GrFragmentProcessor> GrMatrixEffect::Make(
const SkMatrix& matrix, std::unique_ptr<GrFragmentProcessor> child) {
if (child->classID() == kGrMatrixEffect_ClassID) {
auto me = static_cast<GrMatrixEffect*>(child.get());
// registerChild's sample usage records whether the matrix used has perspective or not,
// so we can't add perspective to 'me' if it doesn't already have it.
- if (me->matrix().hasPerspective() || !matrix.hasPerspective()) {
+ if (me->fMatrix.hasPerspective() || !matrix.hasPerspective()) {
me->fMatrix.preConcat(matrix);
return child;
}
@@ -58,7 +29,34 @@
}
std::unique_ptr<GrFragmentProcessor::ProgramImpl> GrMatrixEffect::onMakeProgramImpl() const {
- return std::make_unique<GrGLSLMatrixEffect>();
+ class Impl : public ProgramImpl {
+ public:
+ void emitCode(EmitArgs& args) override {
+ fMatrixVar = args.fUniformHandler->addUniform(&args.fFp,
+ kFragment_GrShaderFlag,
+ kFloat3x3_GrSLType,
+ SkSL::SampleUsage::MatrixUniformName());
+ args.fFragBuilder->codeAppendf("return %s;\n",
+ this->invokeChildWithMatrix(0, args).c_str());
+ }
+
+ private:
+ void onSetData(const GrGLSLProgramDataManager& pdman,
+ const GrFragmentProcessor& proc) override {
+ const GrMatrixEffect& mtx = proc.cast<GrMatrixEffect>();
+ if (auto te = mtx.childProcessor(0)->asTextureEffect()) {
+ SkMatrix m = te->coordAdjustmentMatrix();
+ m.preConcat(mtx.fMatrix);
+ pdman.setSkMatrix(fMatrixVar, m);
+ } else {
+ pdman.setSkMatrix(fMatrixVar, mtx.fMatrix);
+ }
+ }
+
+ UniformHandle fMatrixVar;
+ };
+
+ return std::make_unique<Impl>();
}
void GrMatrixEffect::onAddToKey(const GrShaderCaps& caps, GrProcessorKeyBuilder* b) const {}
diff --git a/src/gpu/effects/GrMatrixEffect.h b/src/gpu/effects/GrMatrixEffect.h
index 8016b4f..b738d70 100644
--- a/src/gpu/effects/GrMatrixEffect.h
+++ b/src/gpu/effects/GrMatrixEffect.h
@@ -20,7 +20,6 @@
std::unique_ptr<GrFragmentProcessor> clone() const override;
const char* name() const override { return "MatrixEffect"; }
- const SkMatrix& matrix() const { return fMatrix; }
private:
GrMatrixEffect(const GrMatrixEffect& src);
diff --git a/src/gpu/effects/GrModulateAtlasCoverageEffect.cpp b/src/gpu/effects/GrModulateAtlasCoverageEffect.cpp
index e42fc8f..815d8b8 100644
--- a/src/gpu/effects/GrModulateAtlasCoverageEffect.cpp
+++ b/src/gpu/effects/GrModulateAtlasCoverageEffect.cpp
@@ -63,6 +63,8 @@
coverageMaybeInvertName, coverageMaybeInvertName);
f->codeAppendf("return %s * coverage;", inputColor.c_str());
}
+
+ private:
void onSetData(const GrGLSLProgramDataManager& pdman,
const GrFragmentProcessor& processor) override {
auto fp = processor.cast<GrModulateAtlasCoverageEffect>();
@@ -78,5 +80,6 @@
UniformHandle fBoundsUniform;
UniformHandle fCoverageMaybeInvertUniform;
};
+
return std::make_unique<Impl>();
}
diff --git a/src/gpu/effects/GrModulateAtlasCoverageEffect.h b/src/gpu/effects/GrModulateAtlasCoverageEffect.h
index 5a12b28..ef8e26d 100644
--- a/src/gpu/effects/GrModulateAtlasCoverageEffect.h
+++ b/src/gpu/effects/GrModulateAtlasCoverageEffect.h
@@ -30,19 +30,21 @@
const char* name() const override {
return "GrModulateAtlasCoverageFP";
}
- void onAddToKey(const GrShaderCaps&, GrProcessorKeyBuilder* b) const override {
- b->add32(fFlags & Flags::kCheckBounds);
- }
+
std::unique_ptr<GrFragmentProcessor> clone() const override {
return std::make_unique<GrModulateAtlasCoverageEffect>(*this);
}
+
+private:
+ void onAddToKey(const GrShaderCaps&, GrProcessorKeyBuilder* b) const override {
+ b->add32(fFlags & Flags::kCheckBounds);
+ }
bool onIsEqual(const GrFragmentProcessor& that) const override {
auto fp = that.cast<GrModulateAtlasCoverageEffect>();
return fFlags == fp.fFlags && fBounds == fp.fBounds;
}
std::unique_ptr<ProgramImpl> onMakeProgramImpl() const override;
-private:
const Flags fFlags;
const SkIRect fBounds;
};
diff --git a/src/gpu/effects/GrRRectEffect.cpp b/src/gpu/effects/GrRRectEffect.cpp
index 09dd82f..03a651b 100644
--- a/src/gpu/effects/GrRRectEffect.cpp
+++ b/src/gpu/effects/GrRRectEffect.cpp
@@ -23,9 +23,9 @@
//////////////////////////////////////////////////////////////////////////////
+namespace {
class CircularRRectEffect : public GrFragmentProcessor {
public:
-
enum CornerFlags {
kTopLeft_CornerFlag = (1 << SkRRect::kUpperLeft_Corner),
kTopRight_CornerFlag = (1 << SkRRect::kUpperRight_Corner),
@@ -54,13 +54,9 @@
std::unique_ptr<GrFragmentProcessor> clone() const override;
- const SkRRect& getRRect() const { return fRRect; }
-
- uint32_t getCircularCornerFlags() const { return fCircularCornerFlags; }
-
- GrClipEdgeType getEdgeType() const { return fEdgeType; }
-
private:
+ class Impl;
+
CircularRRectEffect(std::unique_ptr<GrFragmentProcessor> inputFP,
GrClipEdgeType, uint32_t circularCornerFlags, const SkRRect&);
CircularRRectEffect(const CircularRRectEffect& that);
@@ -79,6 +75,7 @@
using INHERITED = GrFragmentProcessor;
};
+} // anonymous namespace
GrFPResult CircularRRectEffect::Make(std::unique_ptr<GrFragmentProcessor> inputFP,
GrClipEdgeType edgeType,
@@ -144,25 +141,19 @@
//////////////////////////////////////////////////////////////////////////////
-class GLCircularRRectEffect : public GrFragmentProcessor::ProgramImpl {
+class CircularRRectEffect::Impl : public ProgramImpl {
public:
- GLCircularRRectEffect() = default;
-
void emitCode(EmitArgs&) override;
- static inline void GenKey(const GrProcessor&, const GrShaderCaps&, GrProcessorKeyBuilder*);
-
-protected:
+private:
void onSetData(const GrGLSLProgramDataManager&, const GrFragmentProcessor&) override;
-private:
GrGLSLProgramDataManager::UniformHandle fInnerRectUniform;
GrGLSLProgramDataManager::UniformHandle fRadiusPlusHalfUniform;
SkRRect fPrevRRect;
- using INHERITED = ProgramImpl;
};
-void GLCircularRRectEffect::emitCode(EmitArgs& args) {
+void CircularRRectEffect::Impl::emitCode(EmitArgs& args) {
const CircularRRectEffect& crre = args.fFp.cast<CircularRRectEffect>();
GrGLSLUniformHandler* uniformHandler = args.fUniformHandler;
const char *rectName;
@@ -203,7 +194,7 @@
// For the cases where one half of the rrect is rectangular we drop one of the x or y
// computations, compute a separate rect edge alpha for the rect side, and mul the two computed
// alphas together.
- switch (crre.getCircularCornerFlags()) {
+ switch (crre.fCircularCornerFlags) {
case CircularRRectEffect::kAll_CornerFlags:
fragBuilder->codeAppendf("float2 dxy0 = %s.LT - sk_FragCoord.xy;", rectName);
fragBuilder->codeAppendf("float2 dxy1 = sk_FragCoord.xy - %s.RB;", rectName);
@@ -290,7 +281,7 @@
break;
}
- if (GrClipEdgeType::kInverseFillAA == crre.getEdgeType()) {
+ if (GrClipEdgeType::kInverseFillAA == crre.fEdgeType) {
fragBuilder->codeAppend("alpha = 1.0 - alpha;");
}
@@ -299,21 +290,14 @@
fragBuilder->codeAppendf("return %s * alpha;", inputSample.c_str());
}
-void GLCircularRRectEffect::GenKey(const GrProcessor& processor, const GrShaderCaps&,
- GrProcessorKeyBuilder* b) {
+void CircularRRectEffect::Impl::onSetData(const GrGLSLProgramDataManager& pdman,
+ const GrFragmentProcessor& processor) {
const CircularRRectEffect& crre = processor.cast<CircularRRectEffect>();
- static_assert(kGrClipEdgeTypeCnt <= 8);
- b->add32((crre.getCircularCornerFlags() << 3) | (int) crre.getEdgeType());
-}
-
-void GLCircularRRectEffect::onSetData(const GrGLSLProgramDataManager& pdman,
- const GrFragmentProcessor& processor) {
- const CircularRRectEffect& crre = processor.cast<CircularRRectEffect>();
- const SkRRect& rrect = crre.getRRect();
+ const SkRRect& rrect = crre.fRRect;
if (rrect != fPrevRRect) {
SkRect rect = rrect.getBounds();
SkScalar radius = 0;
- switch (crre.getCircularCornerFlags()) {
+ switch (crre.fCircularCornerFlags) {
case CircularRRectEffect::kAll_CornerFlags:
SkASSERT(SkRRectPriv::IsSimpleCircular(rrect));
radius = SkRRectPriv::GetSimpleRadii(rrect).fX;
@@ -389,15 +373,17 @@
////////////////////////////////////////////////////////////////////////////////////////////////////
void CircularRRectEffect::onAddToKey(const GrShaderCaps& caps, GrProcessorKeyBuilder* b) const {
- GLCircularRRectEffect::GenKey(*this, caps, b);
+ static_assert(kGrClipEdgeTypeCnt <= 8);
+ b->add32((fCircularCornerFlags << 3) | static_cast<int>(fEdgeType));
}
std::unique_ptr<GrFragmentProcessor::ProgramImpl> CircularRRectEffect::onMakeProgramImpl() const {
- return std::make_unique<GLCircularRRectEffect>();
+ return std::make_unique<Impl>();
}
//////////////////////////////////////////////////////////////////////////////
+namespace {
class EllipticalRRectEffect : public GrFragmentProcessor {
public:
static GrFPResult Make(std::unique_ptr<GrFragmentProcessor>, GrClipEdgeType, const SkRRect&);
@@ -408,11 +394,9 @@
std::unique_ptr<GrFragmentProcessor> clone() const override;
- const SkRRect& getRRect() const { return fRRect; }
-
- GrClipEdgeType getEdgeType() const { return fEdgeType; }
-
private:
+ class Impl;
+
EllipticalRRectEffect(std::unique_ptr<GrFragmentProcessor>, GrClipEdgeType, const SkRRect&);
EllipticalRRectEffect(const EllipticalRRectEffect& that);
@@ -431,12 +415,13 @@
};
GrFPResult EllipticalRRectEffect::Make(std::unique_ptr<GrFragmentProcessor> inputFP,
- GrClipEdgeType edgeType, const SkRRect& rrect) {
+ GrClipEdgeType edgeType,
+ const SkRRect& rrect) {
if (GrClipEdgeType::kFillAA != edgeType && GrClipEdgeType::kInverseFillAA != edgeType) {
return GrFPFailure(std::move(inputFP));
}
return GrFPSuccess(std::unique_ptr<GrFragmentProcessor>(
- new EllipticalRRectEffect(std::move(inputFP), edgeType, rrect)));
+ new EllipticalRRectEffect(std::move(inputFP), edgeType, rrect)));
}
EllipticalRRectEffect::EllipticalRRectEffect(std::unique_ptr<GrFragmentProcessor> inputFP,
@@ -463,6 +448,7 @@
const EllipticalRRectEffect& erre = other.cast<EllipticalRRectEffect>();
return fEdgeType == erre.fEdgeType && fRRect == erre.fRRect;
}
+} // anonymous namespace
//////////////////////////////////////////////////////////////////////////////
@@ -509,26 +495,20 @@
//////////////////////////////////////////////////////////////////////////////
-class GLEllipticalRRectEffect : public GrFragmentProcessor::ProgramImpl {
+class EllipticalRRectEffect::Impl : public ProgramImpl {
public:
- GLEllipticalRRectEffect() = default;
-
void emitCode(EmitArgs&) override;
- static inline void GenKey(const GrProcessor&, const GrShaderCaps&, GrProcessorKeyBuilder*);
-
-protected:
+private:
void onSetData(const GrGLSLProgramDataManager&, const GrFragmentProcessor&) override;
-private:
GrGLSLProgramDataManager::UniformHandle fInnerRectUniform;
GrGLSLProgramDataManager::UniformHandle fInvRadiiSqdUniform;
GrGLSLProgramDataManager::UniformHandle fScaleUniform;
SkRRect fPrevRRect;
- using INHERITED = ProgramImpl;
};
-void GLEllipticalRRectEffect::emitCode(EmitArgs& args) {
+void EllipticalRRectEffect::Impl::emitCode(EmitArgs& args) {
const EllipticalRRectEffect& erre = args.fFp.cast<EllipticalRRectEffect>();
GrGLSLUniformHandler* uniformHandler = args.fUniformHandler;
const char *rectName;
@@ -562,7 +542,7 @@
}
// The uniforms with the inv squared radii are highp to prevent underflow.
- switch (erre.getRRect().getType()) {
+ switch (erre.fRRect.getType()) {
case SkRRect::kSimple_Type: {
const char *invRadiiXYSqdName;
fInvRadiiSqdUniform = uniformHandler->addUniform(&erre,
@@ -612,7 +592,7 @@
fragBuilder->codeAppendf("approx_dist *= %s.x;", scaleName);
}
- if (GrClipEdgeType::kFillAA == erre.getEdgeType()) {
+ if (erre.fEdgeType == GrClipEdgeType::kFillAA) {
fragBuilder->codeAppend("half alpha = clamp(0.5 - approx_dist, 0.0, 1.0);");
} else {
fragBuilder->codeAppend("half alpha = clamp(0.5 + approx_dist, 0.0, 1.0);");
@@ -623,17 +603,10 @@
fragBuilder->codeAppendf("return %s * alpha;", inputSample.c_str());
}
-void GLEllipticalRRectEffect::GenKey(const GrProcessor& effect, const GrShaderCaps&,
- GrProcessorKeyBuilder* b) {
+void EllipticalRRectEffect::Impl::onSetData(const GrGLSLProgramDataManager& pdman,
+ const GrFragmentProcessor& effect) {
const EllipticalRRectEffect& erre = effect.cast<EllipticalRRectEffect>();
- static_assert((int)GrClipEdgeType::kLast < (1 << 3));
- b->add32(erre.getRRect().getType() | (int) erre.getEdgeType() << 3);
-}
-
-void GLEllipticalRRectEffect::onSetData(const GrGLSLProgramDataManager& pdman,
- const GrFragmentProcessor& effect) {
- const EllipticalRRectEffect& erre = effect.cast<EllipticalRRectEffect>();
- const SkRRect& rrect = erre.getRRect();
+ const SkRRect& rrect = erre.fRRect;
// If we're using a scale factor to work around precision issues, choose the largest radius
// as the scale factor. The inv radii need to be pre-adjusted by the scale factor.
if (rrect != fPrevRRect) {
@@ -641,7 +614,7 @@
const SkVector& r0 = rrect.radii(SkRRect::kUpperLeft_Corner);
SkASSERT(r0.fX >= kRadiusMin);
SkASSERT(r0.fY >= kRadiusMin);
- switch (erre.getRRect().getType()) {
+ switch (rrect.getType()) {
case SkRRect::kSimple_Type:
rect.inset(r0.fX, r0.fY);
if (fScaleUniform.isValid()) {
@@ -692,11 +665,12 @@
////////////////////////////////////////////////////////////////////////////////////////////////////
void EllipticalRRectEffect::onAddToKey(const GrShaderCaps& caps, GrProcessorKeyBuilder* b) const {
- GLEllipticalRRectEffect::GenKey(*this, caps, b);
+ static_assert((int)GrClipEdgeType::kLast < (1 << 3));
+ b->add32(fRRect.getType() | static_cast<int>(fEdgeType) << 3);
}
std::unique_ptr<GrFragmentProcessor::ProgramImpl> EllipticalRRectEffect::onMakeProgramImpl() const {
- return std::make_unique<GLEllipticalRRectEffect>();
+ return std::make_unique<Impl>();
}
//////////////////////////////////////////////////////////////////////////////
diff --git a/src/gpu/effects/GrSkSLFP.cpp b/src/gpu/effects/GrSkSLFP.cpp
index e6b1f26..3db9740 100644
--- a/src/gpu/effects/GrSkSLFP.cpp
+++ b/src/gpu/effects/GrSkSLFP.cpp
@@ -23,7 +23,7 @@
#include "src/gpu/glsl/GrGLSLFragmentShaderBuilder.h"
#include "src/gpu/glsl/GrGLSLProgramBuilder.h"
-class GrGLSLSkSLFP : public GrFragmentProcessor::ProgramImpl {
+class GrSkSLFP::Impl : public ProgramImpl {
public:
void emitCode(EmitArgs& args) override {
const GrSkSLFP& fp = args.fFp.cast<GrSkSLFP>();
@@ -31,7 +31,7 @@
class FPCallbacks : public SkSL::PipelineStage::Callbacks {
public:
- FPCallbacks(GrGLSLSkSLFP* self,
+ FPCallbacks(Impl* self,
EmitArgs& args,
const char* inputColor,
const SkSL::Context& context,
@@ -152,7 +152,7 @@
return String(fSelf->invokeChild(index, src.c_str(), dst.c_str(), fArgs).c_str());
}
- GrGLSLSkSLFP* fSelf;
+ Impl* fSelf;
EmitArgs& fArgs;
const char* fInputColor;
const SkSL::Context& fContext;
@@ -220,6 +220,7 @@
program, coords, args.fInputColor, args.fDestColor, &callbacks);
}
+private:
void onSetData(const GrGLSLProgramDataManager& pdman,
const GrFragmentProcessor& _proc) override {
using Type = SkRuntimeEffect::Uniform::Type;
@@ -345,7 +346,7 @@
}
std::unique_ptr<GrFragmentProcessor::ProgramImpl> GrSkSLFP::onMakeProgramImpl() const {
- return std::make_unique<GrGLSLSkSLFP>();
+ return std::make_unique<Impl>();
}
void GrSkSLFP::onAddToKey(const GrShaderCaps& caps, GrProcessorKeyBuilder* b) const {
diff --git a/src/gpu/effects/GrSkSLFP.h b/src/gpu/effects/GrSkSLFP.h
index 31b6769..24f3987 100644
--- a/src/gpu/effects/GrSkSLFP.h
+++ b/src/gpu/effects/GrSkSLFP.h
@@ -160,6 +160,8 @@
std::unique_ptr<GrFragmentProcessor> clone() const override;
private:
+ class Impl;
+
GrSkSLFP(sk_sp<SkRuntimeEffect> effect, const char* name, OptFlags optFlags);
GrSkSLFP(const GrSkSLFP& other);
@@ -373,8 +375,6 @@
using INHERITED = GrFragmentProcessor;
- friend class GrGLSLSkSLFP;
-
friend class GrSkSLFPFactory;
};
diff --git a/src/gpu/effects/GrTextureEffect.h b/src/gpu/effects/GrTextureEffect.h
index 072f22c..5b1c2d5 100644
--- a/src/gpu/effects/GrTextureEffect.h
+++ b/src/gpu/effects/GrTextureEffect.h
@@ -113,13 +113,14 @@
class Impl : public ProgramImpl {
public:
void emitCode(EmitArgs&) override;
- void onSetData(const GrGLSLProgramDataManager&, const GrFragmentProcessor&) override;
void setSamplerHandle(GrGLSLShaderBuilder::SamplerHandle handle) {
fSamplerHandle = handle;
}
private:
+ void onSetData(const GrGLSLProgramDataManager&, const GrFragmentProcessor&) override;
+
UniformHandle fSubsetUni;
UniformHandle fClampUni;
UniformHandle fIDimsUni;
diff --git a/src/gpu/effects/GrYUVtoRGBEffect.cpp b/src/gpu/effects/GrYUVtoRGBEffect.cpp
index 16aff67..69bb1ec 100644
--- a/src/gpu/effects/GrYUVtoRGBEffect.cpp
+++ b/src/gpu/effects/GrYUVtoRGBEffect.cpp
@@ -239,10 +239,8 @@
#endif
std::unique_ptr<GrFragmentProcessor::ProgramImpl> GrYUVtoRGBEffect::onMakeProgramImpl() const {
- class GrGLSLYUVtoRGBEffect : public ProgramImpl {
+ class Impl : public ProgramImpl {
public:
- GrGLSLYUVtoRGBEffect() {}
-
void emitCode(EmitArgs& args) override {
GrGLSLFPFragmentBuilder* fragBuilder = args.fFragBuilder;
const GrYUVtoRGBEffect& yuvEffect = args.fFp.cast<GrYUVtoRGBEffect>();
@@ -336,8 +334,9 @@
UniformHandle fColorSpaceTranslateVar;
};
- return std::make_unique<GrGLSLYUVtoRGBEffect>();
+ return std::make_unique<Impl>();
}
+
void GrYUVtoRGBEffect::onAddToKey(const GrShaderCaps& caps, GrProcessorKeyBuilder* b) const {
uint32_t packed = 0;
int i = 0;
diff --git a/src/gpu/glsl/GrGLSLFragmentProcessor.h b/src/gpu/glsl/GrGLSLFragmentProcessor.h
index 56f9e67..8839702 100644
--- a/src/gpu/glsl/GrGLSLFragmentProcessor.h
+++ b/src/gpu/glsl/GrGLSLFragmentProcessor.h
@@ -163,7 +163,7 @@
SkSTArray<4, ProgramImpl*, true> fFPStack;
};
-protected:
+private:
/**
* A ProgramImpl instance can be reused with any GrFragmentProcessor that produces the same
* the same key; this function reads data from a GrFragmentProcessor and uploads any
@@ -173,7 +173,6 @@
*/
virtual void onSetData(const GrGLSLProgramDataManager&, const GrFragmentProcessor&) {}
-private:
// The (mangled) name of our entry-point function
SkString fFunctionName;
diff --git a/src/shaders/SkPerlinNoiseShader.cpp b/src/shaders/SkPerlinNoiseShader.cpp
index 796802a..516d185 100644
--- a/src/shaders/SkPerlinNoiseShader.cpp
+++ b/src/shaders/SkPerlinNoiseShader.cpp
@@ -569,24 +569,6 @@
#if SK_SUPPORT_GPU
-class GrGLPerlinNoise : public GrFragmentProcessor::ProgramImpl {
-public:
- void emitCode(EmitArgs&) override;
-
- static inline void GenKey(const GrProcessor&, const GrShaderCaps&, GrProcessorKeyBuilder* b);
-
-protected:
- void onSetData(const GrGLSLProgramDataManager&, const GrFragmentProcessor&) override;
-
-private:
- GrGLSLProgramDataManager::UniformHandle fStitchDataUni;
- GrGLSLProgramDataManager::UniformHandle fBaseFrequencyUni;
-
- using INHERITED = GrFragmentProcessor::ProgramImpl;
-};
-
-/////////////////////////////////////////////////////////////////////
-
class GrPerlinNoise2Effect : public GrFragmentProcessor {
public:
static std::unique_ptr<GrFragmentProcessor> Make(
@@ -626,13 +608,22 @@
int numOctaves() const { return fNumOctaves; }
private:
+ class Impl : public ProgramImpl {
+ public:
+ void emitCode(EmitArgs&) override;
+
+ private:
+ void onSetData(const GrGLSLProgramDataManager&, const GrFragmentProcessor&) override;
+
+ GrGLSLProgramDataManager::UniformHandle fStitchDataUni;
+ GrGLSLProgramDataManager::UniformHandle fBaseFrequencyUni;
+ };
+
std::unique_ptr<ProgramImpl> onMakeProgramImpl() const override {
- return std::make_unique<GrGLPerlinNoise>();
+ return std::make_unique<Impl>();
}
- void onAddToKey(const GrShaderCaps& caps, GrProcessorKeyBuilder* b) const override {
- GrGLPerlinNoise::GenKey(*this, caps, b);
- }
+ void onAddToKey(const GrShaderCaps& caps, GrProcessorKeyBuilder* b) const override;
bool onIsEqual(const GrFragmentProcessor& sBase) const override {
const GrPerlinNoise2Effect& s = sBase.cast<GrPerlinNoise2Effect>();
@@ -702,7 +693,7 @@
}
#endif
-void GrGLPerlinNoise::emitCode(EmitArgs& args) {
+void GrPerlinNoise2Effect::Impl::emitCode(EmitArgs& args) {
const GrPerlinNoise2Effect& pne = args.fFp.cast<GrPerlinNoise2Effect>();
GrGLSLFPFragmentBuilder* fragBuilder = args.fFragBuilder;
@@ -888,15 +879,25 @@
fragBuilder->codeAppendf("return half4(color.rgb * color.aaa, color.a);");
}
-void GrGLPerlinNoise::GenKey(const GrProcessor& processor, const GrShaderCaps&,
- GrProcessorKeyBuilder* b) {
+void GrPerlinNoise2Effect::Impl::onSetData(const GrGLSLProgramDataManager& pdman,
+ const GrFragmentProcessor& processor) {
const GrPerlinNoise2Effect& turbulence = processor.cast<GrPerlinNoise2Effect>();
- uint32_t key = turbulence.numOctaves();
+ const SkVector& baseFrequency = turbulence.baseFrequency();
+ pdman.set2f(fBaseFrequencyUni, baseFrequency.fX, baseFrequency.fY);
- key = key << 3; // Make room for next 3 bits
+ if (turbulence.stitchTiles()) {
+ const SkPerlinNoiseShaderImpl::StitchData& stitchData = turbulence.stitchData();
+ pdman.set2f(fStitchDataUni,
+ SkIntToScalar(stitchData.fWidth),
+ SkIntToScalar(stitchData.fHeight));
+ }
+}
- switch (turbulence.type()) {
+void GrPerlinNoise2Effect::onAddToKey(const GrShaderCaps& caps, GrProcessorKeyBuilder* b) const {
+ uint32_t key = fNumOctaves;
+ key = key << 3; // Make room for next 3 bits
+ switch (fType) {
case SkPerlinNoiseShaderImpl::kFractalNoise_Type:
key |= 0x1;
break;
@@ -907,30 +908,12 @@
// leave key at 0
break;
}
-
- if (turbulence.stitchTiles()) {
+ if (fStitchTiles) {
key |= 0x4; // Flip the 3rd bit if tile stitching is on
}
-
b->add32(key);
}
-void GrGLPerlinNoise::onSetData(const GrGLSLProgramDataManager& pdman,
- const GrFragmentProcessor& processor) {
- INHERITED::onSetData(pdman, processor);
-
- const GrPerlinNoise2Effect& turbulence = processor.cast<GrPerlinNoise2Effect>();
-
- const SkVector& baseFrequency = turbulence.baseFrequency();
- pdman.set2f(fBaseFrequencyUni, baseFrequency.fX, baseFrequency.fY);
-
- if (turbulence.stitchTiles()) {
- const SkPerlinNoiseShaderImpl::StitchData& stitchData = turbulence.stitchData();
- pdman.set2f(fStitchDataUni, SkIntToScalar(stitchData.fWidth),
- SkIntToScalar(stitchData.fHeight));
- }
-}
-
/////////////////////////////////////////////////////////////////////
std::unique_ptr<GrFragmentProcessor> SkPerlinNoiseShaderImpl::asFragmentProcessor(
diff --git a/tests/ProcessorTest.cpp b/tests/ProcessorTest.cpp
index 809bee1..2014a6a 100644
--- a/tests/ProcessorTest.cpp
+++ b/tests/ProcessorTest.cpp
@@ -123,16 +123,15 @@
explicit TestFP(const TestFP& that) : INHERITED(that) {}
std::unique_ptr<ProgramImpl> onMakeProgramImpl() const override {
- class TestGLSLFP : public ProgramImpl {
+ class Impl : public ProgramImpl {
public:
- TestGLSLFP() {}
void emitCode(EmitArgs& args) override {
args.fFragBuilder->codeAppendf("return half4(1);");
}
private:
};
- return std::make_unique<TestGLSLFP>();
+ return std::make_unique<Impl>();
}
bool onIsEqual(const GrFragmentProcessor&) const override { return false; }
diff --git a/tests/ProgramsTest.cpp b/tests/ProgramsTest.cpp
index 9593367..efa6d48 100644
--- a/tests/ProgramsTest.cpp
+++ b/tests/ProgramsTest.cpp
@@ -39,22 +39,7 @@
*/
static const uint32_t kMaxKeySize = 1024;
-class GLBigKeyProcessor : public GrFragmentProcessor::ProgramImpl {
-public:
- void emitCode(EmitArgs& args) override {
- args.fFragBuilder->codeAppendf("return half4(1);\n");
- }
-
- static void GenKey(const GrProcessor&, const GrShaderCaps&, GrProcessorKeyBuilder* b) {
- for (uint32_t i = 0; i < kMaxKeySize; i++) {
- b->add32(i);
- }
- }
-
-private:
- using INHERITED = ProgramImpl;
-};
-
+namespace {
class BigKeyProcessor : public GrFragmentProcessor {
public:
static std::unique_ptr<GrFragmentProcessor> Make() {
@@ -64,15 +49,24 @@
const char* name() const override { return "Big_Ole_Key"; }
std::unique_ptr<ProgramImpl> onMakeProgramImpl() const override {
- return std::make_unique<GLBigKeyProcessor>();
+ class Impl : public ProgramImpl {
+ public:
+ void emitCode(EmitArgs& args) override {
+ args.fFragBuilder->codeAppendf("return half4(1);\n");
+ }
+ };
+
+ return std::make_unique<Impl>();
}
std::unique_ptr<GrFragmentProcessor> clone() const override { return Make(); }
private:
- BigKeyProcessor() : INHERITED(kBigKeyProcessor_ClassID, kNone_OptimizationFlags) { }
+ BigKeyProcessor() : INHERITED(kBigKeyProcessor_ClassID, kNone_OptimizationFlags) {}
void onAddToKey(const GrShaderCaps& caps, GrProcessorKeyBuilder* b) const override {
- GLBigKeyProcessor::GenKey(*this, caps, b);
+ for (uint32_t i = 0; i < kMaxKeySize; i++) {
+ b->add32(i);
+ }
}
bool onIsEqual(const GrFragmentProcessor&) const override { return true; }
@@ -80,6 +74,7 @@
using INHERITED = GrFragmentProcessor;
};
+} // anonymous namespace
GR_DEFINE_FRAGMENT_PROCESSOR_TEST(BigKeyProcessor);
diff --git a/tests/SkSLCross.cpp b/tests/SkSLCross.cpp
index a0b5680..afd3bf8 100644
--- a/tests/SkSLCross.cpp
+++ b/tests/SkSLCross.cpp
@@ -44,39 +44,44 @@
, fA(a), fB(b) {
}
-private:
const char* name() const override { return "VisualizeCrossProductSignFP"; }
+
std::unique_ptr<GrFragmentProcessor> clone() const override {
return std::unique_ptr<GrFragmentProcessor>(new VisualizeCrossProductSignFP(fA, fB));
}
+
+private:
void onAddToKey(const GrShaderCaps&, GrProcessorKeyBuilder*) const override {}
bool onIsEqual(const GrFragmentProcessor&) const override { return true; }
- class Impl : public ProgramImpl {
- void emitCode(EmitArgs& args) override {
- auto& fp = args.fFp.cast<VisualizeCrossProductSignFP>();
- const char* a, *b;
- fAUniform = args.fUniformHandler->addUniform(&fp, kFragment_GrShaderFlag,
- GrSLType::kFloat2_GrSLType, "a", &a);
- fBUniform = args.fUniformHandler->addUniform(&fp, kFragment_GrShaderFlag,
- GrSLType::kFloat2_GrSLType, "b", &b);
- args.fFragBuilder->codeAppendf(R"(
+ std::unique_ptr<ProgramImpl> onMakeProgramImpl() const override {
+ class Impl : public ProgramImpl {
+ public:
+ void emitCode(EmitArgs& args) override {
+ auto& fp = args.fFp.cast<VisualizeCrossProductSignFP>();
+ const char *a, *b;
+ fAUniform = args.fUniformHandler->addUniform(&fp, kFragment_GrShaderFlag,
+ GrSLType::kFloat2_GrSLType, "a", &a);
+ fBUniform = args.fUniformHandler->addUniform(&fp, kFragment_GrShaderFlag,
+ GrSLType::kFloat2_GrSLType, "b", &b);
+ args.fFragBuilder->codeAppendf(R"(
float crossProduct = cross(%s, %s);
float2 visualization = clamp(float2(-sign(crossProduct), sign(crossProduct)),
float2(0), float2(1));
- return half2(visualization).xy01;)", a, b);
- }
- void onSetData(const GrGLSLProgramDataManager& pdman,
- const GrFragmentProcessor& processor) override {
- const auto& fp = processor.cast<VisualizeCrossProductSignFP>();
- pdman.set2f(fAUniform, fp.fA.x(), fp.fA.y());
- pdman.set2f(fBUniform, fp.fB.x(), fp.fB.y());
- }
- GrGLSLUniformHandler::UniformHandle fAUniform;
- GrGLSLUniformHandler::UniformHandle fBUniform;
- };
+ return half2(visualization).xy01;)", a, b);
+ }
- std::unique_ptr<ProgramImpl> onMakeProgramImpl() const override {
+ private:
+ void onSetData(const GrGLSLProgramDataManager& pdman,
+ const GrFragmentProcessor& processor) override {
+ const auto& fp = processor.cast<VisualizeCrossProductSignFP>();
+ pdman.set2f(fAUniform, fp.fA.x(), fp.fA.y());
+ pdman.set2f(fBUniform, fp.fB.x(), fp.fB.y());
+ }
+ GrGLSLUniformHandler::UniformHandle fAUniform;
+ GrGLSLUniformHandler::UniformHandle fBUniform;
+ };
+
return std::make_unique<Impl>();
}
const SkVector fA, fB;