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

Unified Diff: src/gpu/gl/GrGLSL_impl.h

Issue 25023003: Implement color filter as GrGLEffect (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: address review comments Created 7 years, 2 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
« no previous file with comments | « src/gpu/gl/GrGLSL.cpp ('k') | src/gpu/gl/GrGLShaderBuilder.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/gpu/gl/GrGLSL_impl.h
diff --git a/src/gpu/gl/GrGLSL_impl.h b/src/gpu/gl/GrGLSL_impl.h
index 008d512f9c36502646e43b9c0d444f9ff7ef734c..bdd69cc76b37fc47d9747a1427d5043162ba36cf 100644
--- a/src/gpu/gl/GrGLSL_impl.h
+++ b/src/gpu/gl/GrGLSL_impl.h
@@ -8,133 +8,168 @@
#ifndef GrGLSL_impl_DEFINED
#define GrGLSL_impl_DEFINED
-template<>
-inline const char* GrGLSLExpr<4>::ZerosStr() {
- return "vec4(0)";
+template<typename Self>
+template<typename T>
+inline Self GrGLSLExpr<Self>::VectorCastImpl(const T& expr) {
+ if (expr.isZeros()) {
+ return Self(0);
+ }
+ if (expr.isOnes()) {
+ return Self(1);
+ }
+ return Self(Self::CastStr(), expr.c_str());
}
-template<>
-inline const char* GrGLSLExpr<4>::OnesStr() {
- return "vec4(1)";
+template<typename Self>
+template<typename T0, typename T1>
+inline Self GrGLSLExpr<Self>::Mul(T0 in0, T1 in1) {
+ if (in0.isZeros() || in1.isZeros()) {
+ return Self(0);
+ }
+ if (in0.isOnes()) {
+ return Self::VectorCast(in1);
+ }
+ if (in1.isOnes()) {
+ return Self::VectorCast(in0);
+ }
+ return Self("(%s * %s)", in0.c_str(), in1.c_str());
}
-template<>
-inline const char* GrGLSLExpr<4>::ExtractAlphaStr() {
- return "%s.a";
+template<typename Self>
+template<typename T0, typename T1>
+inline Self GrGLSLExpr<Self>::Add(T0 in0, T1 in1) {
+ if (in1.isZeros()) {
+ return Self::VectorCast(in0);
+ }
+ if (in0.isZeros()) {
+ return Self::VectorCast(in1);
+ }
+ if (in0.isOnes() && in1.isOnes()) {
+ return Self(2);
+ }
+ return Self("(%s + %s)", in0.c_str(), in1.c_str());
}
-template<>
-inline const char* GrGLSLExpr<4>::CastStr() {
- return "vec4(%s)";
+template<typename Self>
+template<typename T0, typename T1>
+inline Self GrGLSLExpr<Self>::Sub(T0 in0, T1 in1) {
+ if (in1.isZeros()) {
+ return Self::VectorCast(in0);
+ }
+ if (in1.isOnes()) {
+ if (in0.isOnes()) {
+ return Self(0);
+ }
+ }
+
+ return Self("(%s - %s)", in0.c_str(), in1.c_str());
}
-template<>
-inline const char* GrGLSLExpr<4>::CastIntStr() {
- return "vec4(%d)";
+
+template <typename Self>
+template <typename T>
+T GrGLSLExpr<Self>::extractComponents(const char format[]) const {
+ if (this->isZeros()) {
+ return T(0);
+ }
+ if (this->isOnes()) {
+ return T(1);
+ }
+ return T(format, this->c_str());
+}
+
+inline GrGLSLExpr1 GrGLSLExpr1::VectorCast(const GrGLSLExpr1& expr) {
+ return expr;
}
-template<>
-inline const char* GrGLSLExpr<1>::ZerosStr() {
+inline const char* GrGLSLExpr1::ZerosStr() {
return "0";
}
-template<>
-inline const char* GrGLSLExpr<1>::OnesStr() {
- return "1";
+inline const char* GrGLSLExpr1::OnesStr() {
+ return "1.0";
}
-// GrGLSLExpr<1>::ExtractAlphaStr() and GrGLSLExpr<1>::CastStr() are
-// unimplemented because using them is likely an error. This is now caught
-// compile-time.
+// GrGLSLExpr1::CastStr() is unimplemented because using them is likely an
+// error. This is now caught compile-time.
-template<>
-inline const char* GrGLSLExpr<1>::CastIntStr() {
+inline const char* GrGLSLExpr1::CastIntStr() {
return "%d";
}
-template<>
-template<>
-inline GrGLSLExpr<4> GrGLSLExpr<4>::VectorCast(const GrGLSLExpr<4>& expr) {
- return expr;
+inline GrGLSLExpr1 operator*(const GrGLSLExpr1& in0, const GrGLSLExpr1& in1) {
+ return GrGLSLExpr1::Mul(in0, in1);
+}
+
+inline GrGLSLExpr1 operator+(const GrGLSLExpr1& in0, const GrGLSLExpr1& in1) {
+ return GrGLSLExpr1::Add(in0, in1);
+}
+
+inline GrGLSLExpr1 operator-(const GrGLSLExpr1& in0, const GrGLSLExpr1& in1) {
+ return GrGLSLExpr1::Sub(in0, in1);
}
-template<>
-template<>
-inline GrGLSLExpr<1> GrGLSLExpr<1>::VectorCast(const GrGLSLExpr<1>& expr) {
+inline const char* GrGLSLExpr4::ZerosStr() {
+ return "vec4(0)";
+}
+
+inline const char* GrGLSLExpr4::OnesStr() {
+ return "vec4(1)";
+}
+
+inline const char* GrGLSLExpr4::CastStr() {
+ return "vec4(%s)";
+}
+
+inline const char* GrGLSLExpr4::CastIntStr() {
+ return "vec4(%d)";
+}
+
+inline GrGLSLExpr4 GrGLSLExpr4::VectorCast(const GrGLSLExpr1& expr) {
+ return INHERITED::VectorCastImpl(expr);
+}
+
+inline GrGLSLExpr4 GrGLSLExpr4::VectorCast(const GrGLSLExpr4& expr) {
return expr;
}
-template<int N>
-template<int M>
-inline GrGLSLExpr<N> GrGLSLExpr<N>::VectorCast(const GrGLSLExpr<M>& expr) {
- if (expr.isZeros()) {
- return GrGLSLExpr<N>(0);
- }
- if (expr.isOnes()) {
- return GrGLSLExpr<N>(1);
- }
- return GrGLSLExpr<N>(GrGLSLExpr<N>::CastStr(), expr.c_str());
+inline GrGLSLExpr4::AExpr GrGLSLExpr4::a() const {
+ return this->extractComponents<GrGLSLExpr4::AExpr>("%s.a");
}
-template<int N>
-template<int M>
-inline GrGLSLExpr<N> GrGLSLExpr<N>::Mul(const GrGLSLExpr<N>& in0, const GrGLSLExpr<M>& in1) {
- SK_COMPILE_ASSERT(N == M || M == 1, binary_op_dimensions_incompatible);
- if (in0.isZeros() || in1.isZeros()) {
- return GrGLSLExpr<N>(0);
- }
- if (in0.isOnes()) {
- return VectorCast<M>(in1);
- }
- if (in1.isOnes()) {
- return in0;
- }
- return GrGLSLExpr<N>("(%s * %s)", in0.c_str(), in1.c_str());
+inline GrGLSLExpr4 operator*(const GrGLSLExpr1& in0, const GrGLSLExpr4& in1) {
+ return GrGLSLExpr4::Mul(in0, in1);
}
-template<int N>
-template<int M>
-inline GrGLSLExpr<N> GrGLSLExpr<N>::Add(const GrGLSLExpr<N>& in0, const GrGLSLExpr<M>& in1) {
- SK_COMPILE_ASSERT(N == M || M == 1, binary_op_dimensions_incompatible);
- if (in1.isZeros()) {
- return in0;
- }
- if (in0.isZeros()) {
- return VectorCast<M>(in1);
- }
- if (in0.isOnes() && in1.isOnes()) {
- return GrGLSLExpr<N>(2);
- }
- return GrGLSLExpr<N>("(%s + %s)", in0.c_str(), in1.c_str());
+inline GrGLSLExpr4 operator+(const GrGLSLExpr1& in0, const GrGLSLExpr4& in1) {
+ return GrGLSLExpr4::Add(in0, in1);
}
-template<int N>
-template<int M>
-inline GrGLSLExpr<N> GrGLSLExpr<N>::Sub(const GrGLSLExpr<N>& in0, const GrGLSLExpr<M>& in1) {
- SK_COMPILE_ASSERT(N == M || M == 1, binary_op_dimensions_incompatible);
- if (in1.isZeros()) {
- return in0;
- }
- if (in1.isOnes()) {
- if (in0.isOnes()) {
- return GrGLSLExpr<N>(0);
- }
- }
+inline GrGLSLExpr4 operator-(const GrGLSLExpr1& in0, const GrGLSLExpr4& in1) {
+ return GrGLSLExpr4::Sub(in0, in1);
+}
- return GrGLSLExpr<N>("(%s - %s)", in0.c_str(), in1.c_str());
+inline GrGLSLExpr4 operator*(const GrGLSLExpr4& in0, const GrGLSLExpr1& in1) {
+ return GrGLSLExpr4::Mul(in0, in1);
}
-inline GrGLSLExpr<4> GrGLSLExprCast4(const GrGLSLExpr<1>& expr) {
- return GrGLSLExpr<4>::VectorCast(expr);
+inline GrGLSLExpr4 operator+(const GrGLSLExpr4& in0, const GrGLSLExpr1& in1) {
+ return GrGLSLExpr4::Add(in0, in1);
}
-inline GrGLSLExpr<1> GrGLSLExprExtractAlpha(const GrGLSLExpr<4>& expr) {
- if (expr.isZeros()) {
- return GrGLSLExpr<1>(0);
- }
- if (expr.isOnes()) {
- return GrGLSLExpr<1>(1);
- }
- return GrGLSLExpr<1>(GrGLSLExpr<4>::ExtractAlphaStr(), expr.c_str());
+inline GrGLSLExpr4 operator-(const GrGLSLExpr4& in0, const GrGLSLExpr1& in1) {
+ return GrGLSLExpr4::Sub(in0, in1);
+}
+
+inline GrGLSLExpr4 operator*(const GrGLSLExpr4& in0, const GrGLSLExpr4& in1) {
+ return GrGLSLExpr4::Mul(in0, in1);
+}
+
+inline GrGLSLExpr4 operator+(const GrGLSLExpr4& in0, const GrGLSLExpr4& in1) {
+ return GrGLSLExpr4::Add(in0, in1);
+}
+
+inline GrGLSLExpr4 operator-(const GrGLSLExpr4& in0, const GrGLSLExpr4& in1) {
+ return GrGLSLExpr4::Sub(in0, in1);
}
#endif
« no previous file with comments | « src/gpu/gl/GrGLSL.cpp ('k') | src/gpu/gl/GrGLShaderBuilder.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698