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

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: Removed DVF from prog builder key, not necessary 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..41c3da3995b1a1124409e988ad7935a52045316f 100644
--- a/src/core/SkNormalSource.cpp
+++ b/src/core/SkNormalSource.cpp
@@ -14,9 +14,41 @@
#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.
egdaniel 2016/07/13 19:27:26 Add to this comment that we don't need to adjust t
dvonbeck 2016/07/13 21:28:14 Done.
+class GLSLNormalFP : public GrGLSLFragmentProcessor {
+public:
+ void emitCode(EmitArgs& args) override {
+ 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);
+ } else {
+ this->onEmitCode(args);
+ }
+ }
+protected:
+ virtual void onEmitCode(EmitArgs& args) = 0;
+};
+
+#endif
+
///////////////////////////////////////////////////////////////////////////////
class NormalMapSourceImpl : public SkNormalSource {
@@ -75,13 +107,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 +116,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;
@@ -382,13 +407,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);
}
@@ -530,10 +554,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 +567,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&,

Powered by Google App Engine
This is Rietveld 408576698