Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(149)

Unified Diff: src/core/SkNormalSource.cpp

Issue 2114993002: GrFP can express distance vector field req., program builder declares variable for it (Closed) Base URL: https://skia.googlesource.com/skia@dvonbeck-bevel-api-change
Patch Set: Addressed patch 9 comments, guarded onSetData from invalid calls Created 4 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: src/core/SkNormalSource.cpp
diff --git a/src/core/SkNormalSource.cpp b/src/core/SkNormalSource.cpp
index 394ce8fe45eab79934790050fbeb34f9bf750955..bc738f86a0f209532fc76df85ea5be3c4d327fc9 100644
--- a/src/core/SkNormalSource.cpp
+++ b/src/core/SkNormalSource.cpp
@@ -14,9 +14,60 @@
#include "SkReadBuffer.h"
#include "SkWriteBuffer.h"
-// Genretating vtable
+#if SK_SUPPORT_GPU
+ #include "GrCoordTransform.h"
+ #include "GrInvariantOutput.h"
+ #include "GrTextureParams.h"
+ #include "glsl/GrGLSLFragmentProcessor.h"
+ #include "glsl/GrGLSLFragmentShaderBuilder.h"
+ #include "SkGr.h"
+#endif
+
+// Generating vtable
SkNormalSource::~SkNormalSource() {}
+#if SK_SUPPORT_GPU
+
+// GLSLFragmentProcessors for NormalSourceImpls must sub-class this class and override onEmitCode.
+// 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) override {
egdaniel 2016/07/14 02:47:46 lets mark emitCode and onSetData here as final so
dvonbeck 2016/07/14 13:40:34 Done.
+ if (args.fFp.usesDistanceVectorField() && !args.fGpImplementsDistanceVector) {
+ GrGLSLFragmentBuilder* 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) {
+ if (!fDidIntercept) {
+ this->onOnSetData(pdman, proc);
+ }
+ }
+
+protected:
+ virtual void onEmitCode(EmitArgs& args) = 0;
+ virtual void onOnSetData(const GrGLSLProgramDataManager& pdman, const GrProcessor& proc) = 0;
egdaniel 2016/07/14 02:47:46 hmm this looks ugly. Maybe make it setNormalData?
dvonbeck 2016/07/14 13:40:34 Done.
+
+private:
+ bool fDidIntercept;
+};
+
+#endif
+
///////////////////////////////////////////////////////////////////////////////
class NormalMapSourceImpl : public SkNormalSource {
@@ -75,13 +126,6 @@ private:
#if SK_SUPPORT_GPU
-#include "GrCoordTransform.h"
-#include "GrInvariantOutput.h"
-#include "GrTextureParams.h"
-#include "glsl/GrGLSLFragmentProcessor.h"
-#include "glsl/GrGLSLFragmentShaderBuilder.h"
-#include "SkGr.h"
-
class NormalMapFP : public GrFragmentProcessor {
public:
NormalMapFP(sk_sp<GrFragmentProcessor> mapFP, const SkMatrix& invCTM)
@@ -91,12 +135,12 @@ public:
this->initClassID<NormalMapFP>();
}
- class GLSLNormalMapFP : public GrGLSLFragmentProcessor {
+ class GLSLNormalMapFP : public GLSLNormalFP {
public:
GLSLNormalMapFP()
: fColumnMajorInvCTM22{0.0f} {}
- void emitCode(EmitArgs& args) override {
+ void onEmitCode(EmitArgs& args) override {
GrGLSLFragmentBuilder* fragBuilder = args.fFragBuilder;
GrGLSLUniformHandler* uniformHandler = args.fUniformHandler;
@@ -138,7 +182,7 @@ public:
}
protected:
- void onSetData(const GrGLSLProgramDataManager& pdman, const GrProcessor& proc) override {
+ void onOnSetData(const GrGLSLProgramDataManager& pdman, const GrProcessor& proc) override {
const NormalMapFP& normalMapFP = proc.cast<NormalMapFP>();
const SkMatrix& invCTM = normalMapFP.invCTM();
@@ -382,13 +426,12 @@ public:
this->initClassID<NormalFlatFP>();
}
- class GLSLNormalFlatFP : public GrGLSLFragmentProcessor {
+ class GLSLNormalFlatFP : public GLSLNormalFP {
public:
GLSLNormalFlatFP() {}
- void emitCode(EmitArgs& args) override {
+ void onEmitCode(EmitArgs& args) override {
GrGLSLFragmentBuilder* fragBuilder = args.fFragBuilder;
-
fragBuilder->codeAppendf("%s = vec4(0, 0, 1, 0);", args.fOutputColor);
}
@@ -398,7 +441,7 @@ public:
}
protected:
- void onSetData(const GrGLSLProgramDataManager& pdman, const GrProcessor& proc) override {}
+ void onOnSetData(const GrGLSLProgramDataManager& pdman, const GrProcessor& proc) override {}
};
void onGetGLSLProcessorKey(const GrGLSLCaps& caps, GrProcessorKeyBuilder* b) const override {
@@ -530,10 +573,12 @@ public:
: fType(type)
, fWidth(width)
, fHeight(height) {
+ fUsesDistanceVectorField = true;
+
this->initClassID<NormalBevelFP>();
}
- class GLSLNormalBevelFP : public GrGLSLFragmentProcessor {
+ class GLSLNormalBevelFP : public GLSLNormalFP {
public:
GLSLNormalBevelFP() {
fPrevType = SkNormalSource::BevelType::kLinear;
@@ -541,10 +586,10 @@ public:
fPrevHeight = SkFloatToScalar(0.0f);
}
- void emitCode(EmitArgs& args) override {
+ void onEmitCode(EmitArgs& args) override {
GrGLSLFragmentBuilder* fragBuilder = args.fFragBuilder;
-
- fragBuilder->codeAppendf("%s = vec4(0, 0, 1, 0);", args.fOutputColor);
+ fragBuilder->codeAppendf("%s = normalize(vec4(0.0, 0.0, 1.0, 0.0));",
+ args.fOutputColor);
}
static void GenKey(const GrProcessor& proc, const GrGLSLCaps&,
@@ -553,7 +598,7 @@ public:
}
protected:
- void onSetData(const GrGLSLProgramDataManager& pdman, const GrProcessor& proc) override {
+ void onOnSetData(const GrGLSLProgramDataManager& pdman, const GrProcessor& proc) override {
const NormalBevelFP& normalBevelFP = proc.cast<NormalBevelFP>();
fPrevType = normalBevelFP.fType;

Powered by Google App Engine
This is Rietveld 408576698