diff options
author | 2016-08-01 11:01:56 -0700 | |
---|---|---|
committer | 2016-08-01 11:01:56 -0700 | |
commit | 9b03e7b29d963ea333a66dc5353e94f6391eb899 (patch) | |
tree | 8d888df5a95d0859e7748d53ad580d9e0bc1d2cf /src/core/SkNormalSourcePriv.h | |
parent | 6be452c80072b5ce4011126a27471ceaec72cfcb (diff) |
GrFP can express distance vector field req., program builder declares variable for it
This update allows fragment processors to require a field of vectors to the nearest edge. This requirement propagates:
- from child FPs to their parent
- from parent FPs to the GrPaint
- from GrPaint through the PipelineBuilder into GrPipeline
- acessed from GrPipeline by GrGLSLProgramBuilder
GrGLSL generates a variable for the distance vector and passes it down to the GeometryProcessor->emitCode() method.
This CL's base is the CL for adding the BevelNormalSource API: https://codereview.chromium.org/2080993002
BUG=skia:
GOLD_TRYBOT_URL= https://gold.skia.org/search?issue=2114993002
Committed: https://skia.googlesource.com/skia/+/4ef6dfa7089c092c67b0d5ec34e89c1e319af196
Review-Url: https://codereview.chromium.org/2114993002
Diffstat (limited to 'src/core/SkNormalSourcePriv.h')
-rw-r--r-- | src/core/SkNormalSourcePriv.h | 57 |
1 files changed, 57 insertions, 0 deletions
diff --git a/src/core/SkNormalSourcePriv.h b/src/core/SkNormalSourcePriv.h new file mode 100644 index 0000000000..ce8baf61e4 --- /dev/null +++ b/src/core/SkNormalSourcePriv.h @@ -0,0 +1,57 @@ +/* + * Copyright 2016 Google Inc. + * + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ + +#ifndef SkNormalSourcePriv_DEFINED +#define SkNormalSourcePriv_DEFINED + +#if SK_SUPPORT_GPU +#include "glsl/GrGLSLFragmentProcessor.h" +#include "glsl/GrGLSLFragmentShaderBuilder.h" + +/* 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 |