aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/gpu/glsl
diff options
context:
space:
mode:
authorGravatar Brian Osman <brianosman@google.com>2017-03-08 11:42:02 -0500
committerGravatar Skia Commit-Bot <skia-commit-bot@chromium.org>2017-03-08 18:52:51 +0000
commitc624d9d212c4168fc6c202a8535ddff8a3bfb16a (patch)
tree51606298f16184f05b2f5414e547d1291f5ccca7 /src/gpu/glsl
parente353e81a6fdf401310e0643280ec34d9de0019a3 (diff)
Refactor GrColorSpaceXformHelper
Nonlinear blending mode is going to (sometimes) require additional uniforms and shader code for color space transformation. This change just alters the usage of the helper struct so that we can hide any new logic (without having to change all the FPs that use it). BUG=skia: Change-Id: I913478a387973f5bad5aa09a29f85d21daacab94 Reviewed-on: https://skia-review.googlesource.com/9414 Reviewed-by: Robert Phillips <robertphillips@google.com> Commit-Queue: Brian Osman <brianosman@google.com>
Diffstat (limited to 'src/gpu/glsl')
-rw-r--r--src/gpu/glsl/GrGLSLColorSpaceXformHelper.h32
-rw-r--r--src/gpu/glsl/GrGLSLShaderBuilder.cpp7
2 files changed, 22 insertions, 17 deletions
diff --git a/src/gpu/glsl/GrGLSLColorSpaceXformHelper.h b/src/gpu/glsl/GrGLSLColorSpaceXformHelper.h
index 5e112f9f91..1571b06231 100644
--- a/src/gpu/glsl/GrGLSLColorSpaceXformHelper.h
+++ b/src/gpu/glsl/GrGLSLColorSpaceXformHelper.h
@@ -12,29 +12,33 @@
#include "GrGLSLUniformHandler.h"
/**
- * Stack helper class to assist with using GrColorSpaceXform within an FP's emitCode function.
- * This injects the uniform declaration, and stores the information needed to generate correct
- * gamut-transformation shader code.
+ * Helper class to assist with using GrColorSpaceXform within an FP. This manages all of the
+ * uniforms needed, and can be passed to shader builder functions to automatically generate the
+ * correct color space transformation code.
*/
class GrGLSLColorSpaceXformHelper : public SkNoncopyable {
public:
- GrGLSLColorSpaceXformHelper(GrGLSLUniformHandler* uniformHandler,
- GrColorSpaceXform* colorSpaceXform,
- GrGLSLProgramDataManager::UniformHandle* handle) {
- SkASSERT(uniformHandler && handle);
+ GrGLSLColorSpaceXformHelper() : fValid(false) {}
+
+ void emitCode(GrGLSLUniformHandler* uniformHandler, GrColorSpaceXform* colorSpaceXform) {
+ SkASSERT(uniformHandler);
if (colorSpaceXform) {
- *handle = uniformHandler->addUniform(kFragment_GrShaderFlag, kMat44f_GrSLType,
- kDefault_GrSLPrecision, "ColorXform",
- &fXformMatrix);
- } else {
- fXformMatrix = nullptr;
+ fGamutXformVar = uniformHandler->addUniform(kFragment_GrShaderFlag, kMat44f_GrSLType,
+ kDefault_GrSLPrecision, "ColorXform");
+ fValid = true;
}
}
- const char* getXformMatrix() const { return fXformMatrix; }
+ void setData(const GrGLSLProgramDataManager& pdman, GrColorSpaceXform* colorSpaceXform) {
+ pdman.setSkMatrix44(fGamutXformVar, colorSpaceXform->srcToDst());
+ }
+
+ bool isValid() const { return fValid; }
+ GrGLSLProgramDataManager::UniformHandle const gamutXformUniform() { return fGamutXformVar; }
private:
- const char* fXformMatrix;
+ GrGLSLProgramDataManager::UniformHandle fGamutXformVar;
+ bool fValid;
};
#endif
diff --git a/src/gpu/glsl/GrGLSLShaderBuilder.cpp b/src/gpu/glsl/GrGLSLShaderBuilder.cpp
index 17f7f10287..865876611a 100644
--- a/src/gpu/glsl/GrGLSLShaderBuilder.cpp
+++ b/src/gpu/glsl/GrGLSLShaderBuilder.cpp
@@ -91,7 +91,7 @@ void GrGLSLShaderBuilder::appendTextureLookup(SamplerHandle samplerHandle,
const char* coordName,
GrSLType varyingType,
GrGLSLColorSpaceXformHelper* colorXformHelper) {
- if (colorXformHelper && colorXformHelper->getXformMatrix()) {
+ if (colorXformHelper && colorXformHelper->isValid()) {
// With a color gamut transform, we need to wrap the lookup in another function call
SkString lookup;
this->appendTextureLookup(&lookup, samplerHandle, coordName, varyingType);
@@ -109,7 +109,7 @@ void GrGLSLShaderBuilder::appendTextureLookupAndModulate(
GrGLSLColorSpaceXformHelper* colorXformHelper) {
SkString lookup;
this->appendTextureLookup(&lookup, samplerHandle, coordName, varyingType);
- if (colorXformHelper && colorXformHelper->getXformMatrix()) {
+ if (colorXformHelper && colorXformHelper->isValid()) {
SkString xform;
this->appendColorGamutXform(&xform, lookup.c_str(), colorXformHelper);
this->codeAppend((GrGLSLExpr4(modulation) * GrGLSLExpr4(xform)).c_str());
@@ -141,8 +141,9 @@ void GrGLSLShaderBuilder::appendColorGamutXform(SkString* out,
functionBody.c_str(),
&colorGamutXformFuncName);
+ GrGLSLUniformHandler* uniformHandler = fProgramBuilder->uniformHandler();
out->appendf("%s(%s, %s)", colorGamutXformFuncName.c_str(), srcColor,
- colorXformHelper->getXformMatrix());
+ uniformHandler->getUniformCStr(colorXformHelper->gamutXformUniform()));
}
void GrGLSLShaderBuilder::appendColorGamutXform(const char* srcColor,