| Index: src/core/SkNormalSource.h
|
| diff --git a/src/core/SkNormalSource.h b/src/core/SkNormalSource.h
|
| index a17c4f671a1efcbf697f24e0df602a5b2442758c..64491c484a3172f96c6d77009a3a60f9332d345b 100644
|
| --- a/src/core/SkNormalSource.h
|
| +++ b/src/core/SkNormalSource.h
|
| @@ -15,10 +15,8 @@ class SkMatrix;
|
| class SkPoint3;
|
|
|
| #if SK_SUPPORT_GPU
|
| -class GrFragmentProcessor;
|
| -class GrContext;
|
| -enum SkFilterQuality;
|
| -enum SkSourceGammaTreatment;
|
| +#include "glsl/GrGLSLFragmentProcessor.h"
|
| +#include "glsl/GrGLSLFragmentShaderBuilder.h"
|
| #endif
|
|
|
| /** Abstract class that generates or reads in normals for use by SkLightingShader.
|
| @@ -122,9 +120,8 @@ public:
|
| return straight-up normals only.
|
|
|
| @param type the type of bevel to add
|
| - @param width the width of the bevel, in source space. Must be positive.
|
| - @param height the height of the plateau, in source space. Can be positive, negative,
|
| - or zero. A negative height means the simulated bevels slope downwards.
|
| + @param width the width of the bevel, in source space
|
| + @param height the height of the plateau, in source space
|
| */
|
| static sk_sp<SkNormalSource> MakeBevel(BevelType, SkScalar width, SkScalar height);
|
|
|
| @@ -132,4 +129,47 @@ public:
|
| SK_DECLARE_FLATTENABLE_REGISTRAR_GROUP()
|
| };
|
|
|
| +#if SK_SUPPORT_GPU
|
| +/* GLSLFragmentProcessors for NormalSourceImpls must sub-class this class and override onEmitCode,
|
| + * and setNormalData calls, as well as all other calls FPs normally override, except for the 2
|
| + * defined in this superclass.
|
| + * This class exists to intercept emitCode calls and emit <0, 0, 1> if the FP requires a distance
|
| + * vector but the GP doesn't provide it. onSetData calls need to be intercepted too because
|
| + * uniform handlers will be invalid in subclasses where onEmitCode isn't called.
|
| + * We don't need to adjust the key here since the use of a given GP (through its class ID already in
|
| + * the key), will determine what code gets emitted here.
|
| + */
|
| +class GLSLNormalFP : public GrGLSLFragmentProcessor {
|
| +public:
|
| + GLSLNormalFP()
|
| + : fDidIntercept(false) {}
|
| +
|
| + void emitCode(EmitArgs& args) final override {
|
| + if (args.fFp.usesDistanceVectorField() && !args.fGpImplementsDistanceVector) {
|
| + GrGLSLFPFragmentBuilder* fragBuilder = args.fFragBuilder;
|
| + fragBuilder->codeAppendf("// GLSLNormalFP intercepted emitCode call, GP does not "
|
| + "implement required distance vector feature\n");
|
| + fragBuilder->codeAppendf("%s = vec4(0, 0, 1, 0);", args.fOutputColor);
|
| +
|
| + fDidIntercept = true;
|
| + } else {
|
| + this->onEmitCode(args);
|
| + }
|
| + }
|
| +
|
| + void onSetData(const GrGLSLProgramDataManager& pdman, const GrProcessor& proc) final override {
|
| + if (!fDidIntercept) {
|
| + this->setNormalData(pdman, proc);
|
| + }
|
| + }
|
| +
|
| +protected:
|
| + virtual void onEmitCode(EmitArgs& args) = 0;
|
| + virtual void setNormalData(const GrGLSLProgramDataManager& pdman, const GrProcessor& proc) = 0;
|
| +
|
| +private:
|
| + bool fDidIntercept;
|
| +};
|
| +#endif
|
| +
|
| #endif
|
|
|