aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/gpu/glsl
diff options
context:
space:
mode:
authorGravatar brianosman <brianosman@google.com>2016-09-12 08:50:19 -0700
committerGravatar Commit bot <commit-bot@chromium.org>2016-09-12 08:50:19 -0700
commit5192475bd8cb98e8e0c1192ab5ece7b8595701d6 (patch)
tree29461e55053726c93c8c612e6fe65dc89fc1a431 /src/gpu/glsl
parent9b0fe3d125f237d9884732a48414fa85fc71b4e3 (diff)
Two changes:
1. Remove special premul handling from gamut xform code Alpha is a constant, so the gamut transformation results remain unchanged (it distributes across the linear matrix multiply). 2. Use SkMatrix44 rather than array of floats Preserves semantic intention, and makes upcoming code (where we transform colors on the CPU by that matrix) simpler. BUG=skia: GOLD_TRYBOT_URL= https://gold.skia.org/search?issue=2329553002 Review-Url: https://codereview.chromium.org/2329553002
Diffstat (limited to 'src/gpu/glsl')
-rw-r--r--src/gpu/glsl/GrGLSLColorSpaceXformHelper.h3
-rw-r--r--src/gpu/glsl/GrGLSLProgramDataManager.cpp8
-rw-r--r--src/gpu/glsl/GrGLSLProgramDataManager.h4
-rw-r--r--src/gpu/glsl/GrGLSLShaderBuilder.cpp15
4 files changed, 13 insertions, 17 deletions
diff --git a/src/gpu/glsl/GrGLSLColorSpaceXformHelper.h b/src/gpu/glsl/GrGLSLColorSpaceXformHelper.h
index cd516e8c89..5e112f9f91 100644
--- a/src/gpu/glsl/GrGLSLColorSpaceXformHelper.h
+++ b/src/gpu/glsl/GrGLSLColorSpaceXformHelper.h
@@ -26,18 +26,15 @@ public:
*handle = uniformHandler->addUniform(kFragment_GrShaderFlag, kMat44f_GrSLType,
kDefault_GrSLPrecision, "ColorXform",
&fXformMatrix);
- fAlphaType = colorSpaceXform->alphaType();
} else {
fXformMatrix = nullptr;
}
}
const char* getXformMatrix() const { return fXformMatrix; }
- SkAlphaType alphaType() const { return fAlphaType; }
private:
const char* fXformMatrix;
- SkAlphaType fAlphaType;
};
#endif
diff --git a/src/gpu/glsl/GrGLSLProgramDataManager.cpp b/src/gpu/glsl/GrGLSLProgramDataManager.cpp
index 0c98e08edd..0803f7af69 100644
--- a/src/gpu/glsl/GrGLSLProgramDataManager.cpp
+++ b/src/gpu/glsl/GrGLSLProgramDataManager.cpp
@@ -8,6 +8,7 @@
#include "glsl/GrGLSLProgramDataManager.h"
#include "SkMatrix.h"
+#include "SkMatrix44.h"
void GrGLSLProgramDataManager::setSkMatrix(UniformHandle u, const SkMatrix& matrix) const {
float mt[] = {
@@ -23,3 +24,10 @@ void GrGLSLProgramDataManager::setSkMatrix(UniformHandle u, const SkMatrix& matr
};
this->setMatrix3f(u, mt);
}
+
+void GrGLSLProgramDataManager::setSkMatrix44(UniformHandle u, const SkMatrix44& matrix) const {
+ // TODO: We could skip this temporary buffer if we had direct access to the matrix storage
+ float m[16];
+ matrix.asColMajorf(m);
+ this->setMatrix4f(u, m);
+}
diff --git a/src/gpu/glsl/GrGLSLProgramDataManager.h b/src/gpu/glsl/GrGLSLProgramDataManager.h
index 442a1e5bc6..8d58fc8b9d 100644
--- a/src/gpu/glsl/GrGLSLProgramDataManager.h
+++ b/src/gpu/glsl/GrGLSLProgramDataManager.h
@@ -12,6 +12,7 @@
#include "SkTypes.h"
class SkMatrix;
+class SkMatrix44;
/** Manages the resources used by a shader program.
* The resources are objects the program uses to communicate with the
@@ -48,6 +49,9 @@ public:
// convenience method for uploading a SkMatrix to a 3x3 matrix uniform
void setSkMatrix(UniformHandle, const SkMatrix&) const;
+ // convenience method for uploading a SkMatrix44 to a 4x4 matrix uniform
+ void setSkMatrix44(UniformHandle, const SkMatrix44&) const;
+
// for nvpr only
GR_DEFINE_RESOURCE_HANDLE_CLASS(VaryingHandle);
virtual void setPathFragmentInputTransform(VaryingHandle u, int components,
diff --git a/src/gpu/glsl/GrGLSLShaderBuilder.cpp b/src/gpu/glsl/GrGLSLShaderBuilder.cpp
index 26a7761f32..6d77bdbf9a 100644
--- a/src/gpu/glsl/GrGLSLShaderBuilder.cpp
+++ b/src/gpu/glsl/GrGLSLShaderBuilder.cpp
@@ -133,27 +133,14 @@ void GrGLSLShaderBuilder::appendColorGamutXform(SkString* out,
GrGLSLColorSpaceXformHelper* colorXformHelper) {
// Our color is (r, g, b, a), but we want to multiply (r, g, b, 1) by our matrix, then
// re-insert the original alpha. The supplied srcColor is likely to be of the form
- // "texture(...)", and we don't want to evaluate that twice.
- //
- // Worse: We can't do the transformation on premultiplied colors, so if the source is premul,
- // we need to unpremul, transform, then multiply again. Anyways, we wrap all of the work in a
- // function.
+ // "texture(...)", and we don't want to evaluate that twice, so wrap everything in a function.
static const GrGLSLShaderVar gColorGamutXformArgs[] = {
GrGLSLShaderVar("color", kVec4f_GrSLType),
GrGLSLShaderVar("xform", kMat44f_GrSLType),
};
SkString functionBody;
- if (kPremul_SkAlphaType == colorXformHelper->alphaType()) {
- // Unpremultiply
- functionBody.append("\tfloat nonZeroAlpha = max(color.a, 0.00001);\n"
- "\tcolor.rgb = color.rgb / nonZeroAlpha;\n");
- }
// Gamut xform, clamp to destination gamut
functionBody.append("\tcolor.rgb = clamp((xform * vec4(color.rgb, 1.0)).rgb, 0.0, 1.0);\n");
- if (kPremul_SkAlphaType == colorXformHelper->alphaType()) {
- // Re-multiply by alpha
- functionBody.append("\tcolor.rgb = color.rgb * nonZeroAlpha;\n");
- }
functionBody.append("\treturn color;");
SkString colorGamutXformFuncName;
this->emitFunction(kVec4f_GrSLType,