| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2013 Google Inc. | 2 * Copyright 2013 Google Inc. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
| 5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
| 6 */ | 6 */ |
| 7 | 7 |
| 8 #ifndef GrGLSL_impl_DEFINED | 8 #ifndef GrGLSL_impl_DEFINED |
| 9 #define GrGLSL_impl_DEFINED | 9 #define GrGLSL_impl_DEFINED |
| 10 | 10 |
| 11 #include "SkString.h" | 11 #include "SkString.h" |
| 12 | 12 |
| 13 namespace { | 13 namespace { |
| 14 template<int N> | 14 template<int N> |
| 15 GrSLConstantVec return_const_vecf(GrSLConstantVec constVec, SkString* outAppend,
bool omitAppend) { | 15 GrSLConstantVec return_const_vecf(GrSLConstantVec constVec, SkString* outAppend,
bool omitAppend) { |
| 16 GrAssert(kNone_GrSLConstantVec != constVec); | 16 SkASSERT(kNone_GrSLConstantVec != constVec); |
| 17 if (!omitAppend) { | 17 if (!omitAppend) { |
| 18 if (kZeros_GrSLConstantVec == constVec) { | 18 if (kZeros_GrSLConstantVec == constVec) { |
| 19 outAppend->append(GrGLSLZerosVecf(N)); | 19 outAppend->append(GrGLSLZerosVecf(N)); |
| 20 } else { | 20 } else { |
| 21 outAppend->append(GrGLSLOnesVecf(N)); | 21 outAppend->append(GrGLSLOnesVecf(N)); |
| 22 } | 22 } |
| 23 } | 23 } |
| 24 return constVec; | 24 return constVec; |
| 25 } | 25 } |
| 26 } | 26 } |
| 27 | 27 |
| 28 template <int N> | 28 template <int N> |
| 29 GrSLConstantVec GrGLSLModulatef(SkString* outAppend, | 29 GrSLConstantVec GrGLSLModulatef(SkString* outAppend, |
| 30 const char* in0, | 30 const char* in0, |
| 31 const char* in1, | 31 const char* in1, |
| 32 GrSLConstantVec default0, | 32 GrSLConstantVec default0, |
| 33 GrSLConstantVec default1, | 33 GrSLConstantVec default1, |
| 34 bool omitIfConstVec) { | 34 bool omitIfConstVec) { |
| 35 GrAssert(N > 0 && N <= 4); | 35 SkASSERT(N > 0 && N <= 4); |
| 36 GrAssert(NULL != outAppend); | 36 SkASSERT(NULL != outAppend); |
| 37 | 37 |
| 38 bool has0 = NULL != in0 && '\0' != *in0; | 38 bool has0 = NULL != in0 && '\0' != *in0; |
| 39 bool has1 = NULL != in1 && '\0' != *in1; | 39 bool has1 = NULL != in1 && '\0' != *in1; |
| 40 | 40 |
| 41 GrAssert(has0 || kNone_GrSLConstantVec != default0); | 41 SkASSERT(has0 || kNone_GrSLConstantVec != default0); |
| 42 GrAssert(has1 || kNone_GrSLConstantVec != default1); | 42 SkASSERT(has1 || kNone_GrSLConstantVec != default1); |
| 43 | 43 |
| 44 if (!has0 && !has1) { | 44 if (!has0 && !has1) { |
| 45 GrAssert(kZeros_GrSLConstantVec == default0 || kOnes_GrSLConstantVec ==
default0); | 45 SkASSERT(kZeros_GrSLConstantVec == default0 || kOnes_GrSLConstantVec ==
default0); |
| 46 GrAssert(kZeros_GrSLConstantVec == default1 || kOnes_GrSLConstantVec ==
default1); | 46 SkASSERT(kZeros_GrSLConstantVec == default1 || kOnes_GrSLConstantVec ==
default1); |
| 47 if (kZeros_GrSLConstantVec == default0 || kZeros_GrSLConstantVec == defa
ult1) { | 47 if (kZeros_GrSLConstantVec == default0 || kZeros_GrSLConstantVec == defa
ult1) { |
| 48 return return_const_vecf<N>(kZeros_GrSLConstantVec, outAppend, omitI
fConstVec); | 48 return return_const_vecf<N>(kZeros_GrSLConstantVec, outAppend, omitI
fConstVec); |
| 49 } else { | 49 } else { |
| 50 // both inputs are ones vectors | 50 // both inputs are ones vectors |
| 51 return return_const_vecf<N>(kOnes_GrSLConstantVec, outAppend, omitIf
ConstVec); | 51 return return_const_vecf<N>(kOnes_GrSLConstantVec, outAppend, omitIf
ConstVec); |
| 52 } | 52 } |
| 53 } else if (!has0) { | 53 } else if (!has0) { |
| 54 GrAssert(kZeros_GrSLConstantVec == default0 || kOnes_GrSLConstantVec ==
default0); | 54 SkASSERT(kZeros_GrSLConstantVec == default0 || kOnes_GrSLConstantVec ==
default0); |
| 55 if (kZeros_GrSLConstantVec == default0) { | 55 if (kZeros_GrSLConstantVec == default0) { |
| 56 return return_const_vecf<N>(kZeros_GrSLConstantVec, outAppend, omitI
fConstVec); | 56 return return_const_vecf<N>(kZeros_GrSLConstantVec, outAppend, omitI
fConstVec); |
| 57 } else { | 57 } else { |
| 58 outAppend->appendf("%s(%s)", GrGLSLFloatVectorTypeString(N), in1); | 58 outAppend->appendf("%s(%s)", GrGLSLFloatVectorTypeString(N), in1); |
| 59 return kNone_GrSLConstantVec; | 59 return kNone_GrSLConstantVec; |
| 60 } | 60 } |
| 61 } else if (!has1) { | 61 } else if (!has1) { |
| 62 GrAssert(kZeros_GrSLConstantVec == default1 || kOnes_GrSLConstantVec ==
default1); | 62 SkASSERT(kZeros_GrSLConstantVec == default1 || kOnes_GrSLConstantVec ==
default1); |
| 63 if (kZeros_GrSLConstantVec == default1) { | 63 if (kZeros_GrSLConstantVec == default1) { |
| 64 return return_const_vecf<N>(kZeros_GrSLConstantVec, outAppend, omitI
fConstVec); | 64 return return_const_vecf<N>(kZeros_GrSLConstantVec, outAppend, omitI
fConstVec); |
| 65 } else { | 65 } else { |
| 66 outAppend->appendf("%s(%s)", GrGLSLFloatVectorTypeString(N), in0); | 66 outAppend->appendf("%s(%s)", GrGLSLFloatVectorTypeString(N), in0); |
| 67 return kNone_GrSLConstantVec; | 67 return kNone_GrSLConstantVec; |
| 68 } | 68 } |
| 69 } else { | 69 } else { |
| 70 outAppend->appendf("%s((%s) * (%s))", GrGLSLFloatVectorTypeString(N), in
0, in1); | 70 outAppend->appendf("%s((%s) * (%s))", GrGLSLFloatVectorTypeString(N), in
0, in1); |
| 71 return kNone_GrSLConstantVec; | 71 return kNone_GrSLConstantVec; |
| 72 } | 72 } |
| 73 } | 73 } |
| 74 | 74 |
| 75 template <int N> | 75 template <int N> |
| 76 GrSLConstantVec GrGLSLAddf(SkString* outAppend, | 76 GrSLConstantVec GrGLSLAddf(SkString* outAppend, |
| 77 const char* in0, | 77 const char* in0, |
| 78 const char* in1, | 78 const char* in1, |
| 79 GrSLConstantVec default0, | 79 GrSLConstantVec default0, |
| 80 GrSLConstantVec default1, | 80 GrSLConstantVec default1, |
| 81 bool omitIfConstVec) { | 81 bool omitIfConstVec) { |
| 82 GrAssert(N > 0 && N <= 4); | 82 SkASSERT(N > 0 && N <= 4); |
| 83 GrAssert(NULL != outAppend); | 83 SkASSERT(NULL != outAppend); |
| 84 | 84 |
| 85 bool has0 = NULL != in0 && '\0' != *in0; | 85 bool has0 = NULL != in0 && '\0' != *in0; |
| 86 bool has1 = NULL != in1 && '\0' != *in1; | 86 bool has1 = NULL != in1 && '\0' != *in1; |
| 87 | 87 |
| 88 if (!has0 && !has1) { | 88 if (!has0 && !has1) { |
| 89 GrAssert(kNone_GrSLConstantVec != default0); | 89 SkASSERT(kNone_GrSLConstantVec != default0); |
| 90 GrAssert(kNone_GrSLConstantVec != default1); | 90 SkASSERT(kNone_GrSLConstantVec != default1); |
| 91 int sum = (kOnes_GrSLConstantVec == default0) + (kOnes_GrSLConstantVec =
= default1); | 91 int sum = (kOnes_GrSLConstantVec == default0) + (kOnes_GrSLConstantVec =
= default1); |
| 92 if (0 == sum) { | 92 if (0 == sum) { |
| 93 return return_const_vecf<N>(kZeros_GrSLConstantVec, outAppend, omitI
fConstVec); | 93 return return_const_vecf<N>(kZeros_GrSLConstantVec, outAppend, omitI
fConstVec); |
| 94 } else if (1 == sum) { | 94 } else if (1 == sum) { |
| 95 outAppend->append(GrGLSLOnesVecf(N)); | 95 outAppend->append(GrGLSLOnesVecf(N)); |
| 96 return return_const_vecf<N>(kOnes_GrSLConstantVec, outAppend, omitIf
ConstVec); | 96 return return_const_vecf<N>(kOnes_GrSLConstantVec, outAppend, omitIf
ConstVec); |
| 97 } else { | 97 } else { |
| 98 GrAssert(2 == sum); | 98 SkASSERT(2 == sum); |
| 99 outAppend->appendf("%s(2)", GrGLSLFloatVectorTypeString(N)); | 99 outAppend->appendf("%s(2)", GrGLSLFloatVectorTypeString(N)); |
| 100 return kNone_GrSLConstantVec; | 100 return kNone_GrSLConstantVec; |
| 101 } | 101 } |
| 102 } else if (!has0) { | 102 } else if (!has0) { |
| 103 GrAssert(kNone_GrSLConstantVec != default0); | 103 SkASSERT(kNone_GrSLConstantVec != default0); |
| 104 if (kZeros_GrSLConstantVec == default0) { | 104 if (kZeros_GrSLConstantVec == default0) { |
| 105 outAppend->appendf("%s(%s)", GrGLSLFloatVectorTypeString(N), in1); | 105 outAppend->appendf("%s(%s)", GrGLSLFloatVectorTypeString(N), in1); |
| 106 } else { | 106 } else { |
| 107 outAppend->appendf("%s(%s) + %s", | 107 outAppend->appendf("%s(%s) + %s", |
| 108 GrGLSLFloatVectorTypeString(N), | 108 GrGLSLFloatVectorTypeString(N), |
| 109 in1, | 109 in1, |
| 110 GrGLSLOnesVecf(N)); | 110 GrGLSLOnesVecf(N)); |
| 111 } | 111 } |
| 112 return kNone_GrSLConstantVec; | 112 return kNone_GrSLConstantVec; |
| 113 } else if (!has1) { | 113 } else if (!has1) { |
| 114 GrAssert(kNone_GrSLConstantVec != default1); | 114 SkASSERT(kNone_GrSLConstantVec != default1); |
| 115 if (kZeros_GrSLConstantVec == default1) { | 115 if (kZeros_GrSLConstantVec == default1) { |
| 116 outAppend->appendf("%s(%s)", GrGLSLFloatVectorTypeString(N), in0); | 116 outAppend->appendf("%s(%s)", GrGLSLFloatVectorTypeString(N), in0); |
| 117 } else { | 117 } else { |
| 118 outAppend->appendf("%s(%s) + %s", | 118 outAppend->appendf("%s(%s) + %s", |
| 119 GrGLSLFloatVectorTypeString(N), | 119 GrGLSLFloatVectorTypeString(N), |
| 120 in0, | 120 in0, |
| 121 GrGLSLOnesVecf(N)); | 121 GrGLSLOnesVecf(N)); |
| 122 } | 122 } |
| 123 return kNone_GrSLConstantVec; | 123 return kNone_GrSLConstantVec; |
| 124 } else { | 124 } else { |
| 125 outAppend->appendf("(%s(%s) + %s(%s))", | 125 outAppend->appendf("(%s(%s) + %s(%s))", |
| 126 GrGLSLFloatVectorTypeString(N), | 126 GrGLSLFloatVectorTypeString(N), |
| 127 in0, | 127 in0, |
| 128 GrGLSLFloatVectorTypeString(N), | 128 GrGLSLFloatVectorTypeString(N), |
| 129 in1); | 129 in1); |
| 130 return kNone_GrSLConstantVec; | 130 return kNone_GrSLConstantVec; |
| 131 } | 131 } |
| 132 } | 132 } |
| 133 | 133 |
| 134 template <int N> | 134 template <int N> |
| 135 GrSLConstantVec GrGLSLSubtractf(SkString* outAppend, | 135 GrSLConstantVec GrGLSLSubtractf(SkString* outAppend, |
| 136 const char* in0, | 136 const char* in0, |
| 137 const char* in1, | 137 const char* in1, |
| 138 GrSLConstantVec default0, | 138 GrSLConstantVec default0, |
| 139 GrSLConstantVec default1, | 139 GrSLConstantVec default1, |
| 140 bool omitIfConstVec) { | 140 bool omitIfConstVec) { |
| 141 GrAssert(N > 0 && N <= 4); | 141 SkASSERT(N > 0 && N <= 4); |
| 142 GrAssert(NULL != outAppend); | 142 SkASSERT(NULL != outAppend); |
| 143 | 143 |
| 144 bool has0 = NULL != in0 && '\0' != *in0; | 144 bool has0 = NULL != in0 && '\0' != *in0; |
| 145 bool has1 = NULL != in1 && '\0' != *in1; | 145 bool has1 = NULL != in1 && '\0' != *in1; |
| 146 | 146 |
| 147 if (!has0 && !has1) { | 147 if (!has0 && !has1) { |
| 148 GrAssert(kNone_GrSLConstantVec != default0); | 148 SkASSERT(kNone_GrSLConstantVec != default0); |
| 149 GrAssert(kNone_GrSLConstantVec != default1); | 149 SkASSERT(kNone_GrSLConstantVec != default1); |
| 150 int diff = (kOnes_GrSLConstantVec == default0) - (kOnes_GrSLConstantVec
== default1); | 150 int diff = (kOnes_GrSLConstantVec == default0) - (kOnes_GrSLConstantVec
== default1); |
| 151 if (-1 == diff) { | 151 if (-1 == diff) { |
| 152 outAppend->appendf("%s(-1)", GrGLSLFloatVectorTypeString(N)); | 152 outAppend->appendf("%s(-1)", GrGLSLFloatVectorTypeString(N)); |
| 153 return kNone_GrSLConstantVec; | 153 return kNone_GrSLConstantVec; |
| 154 } else if (0 == diff) { | 154 } else if (0 == diff) { |
| 155 return return_const_vecf<N>(kZeros_GrSLConstantVec, outAppend, omitI
fConstVec); | 155 return return_const_vecf<N>(kZeros_GrSLConstantVec, outAppend, omitI
fConstVec); |
| 156 } else { | 156 } else { |
| 157 GrAssert(1 == diff); | 157 SkASSERT(1 == diff); |
| 158 return return_const_vecf<N>(kOnes_GrSLConstantVec, outAppend, omitIf
ConstVec); | 158 return return_const_vecf<N>(kOnes_GrSLConstantVec, outAppend, omitIf
ConstVec); |
| 159 } | 159 } |
| 160 } else if (!has0) { | 160 } else if (!has0) { |
| 161 GrAssert(kNone_GrSLConstantVec != default0); | 161 SkASSERT(kNone_GrSLConstantVec != default0); |
| 162 if (kZeros_GrSLConstantVec == default0) { | 162 if (kZeros_GrSLConstantVec == default0) { |
| 163 outAppend->appendf("-%s(%s)", GrGLSLFloatVectorTypeString(N), in1); | 163 outAppend->appendf("-%s(%s)", GrGLSLFloatVectorTypeString(N), in1); |
| 164 } else { | 164 } else { |
| 165 outAppend->appendf("%s - %s(%s)", | 165 outAppend->appendf("%s - %s(%s)", |
| 166 GrGLSLOnesVecf(N), | 166 GrGLSLOnesVecf(N), |
| 167 GrGLSLFloatVectorTypeString(N), | 167 GrGLSLFloatVectorTypeString(N), |
| 168 in1); | 168 in1); |
| 169 } | 169 } |
| 170 return kNone_GrSLConstantVec; | 170 return kNone_GrSLConstantVec; |
| 171 } else if (!has1) { | 171 } else if (!has1) { |
| 172 GrAssert(kNone_GrSLConstantVec != default1); | 172 SkASSERT(kNone_GrSLConstantVec != default1); |
| 173 if (kZeros_GrSLConstantVec == default1) { | 173 if (kZeros_GrSLConstantVec == default1) { |
| 174 outAppend->appendf("%s(%s)", GrGLSLFloatVectorTypeString(N), in0); | 174 outAppend->appendf("%s(%s)", GrGLSLFloatVectorTypeString(N), in0); |
| 175 } else { | 175 } else { |
| 176 outAppend->appendf("%s(%s) - %s", | 176 outAppend->appendf("%s(%s) - %s", |
| 177 GrGLSLFloatVectorTypeString(N), | 177 GrGLSLFloatVectorTypeString(N), |
| 178 in0, | 178 in0, |
| 179 GrGLSLOnesVecf(N)); | 179 GrGLSLOnesVecf(N)); |
| 180 } | 180 } |
| 181 return kNone_GrSLConstantVec; | 181 return kNone_GrSLConstantVec; |
| 182 } else { | 182 } else { |
| 183 outAppend->appendf("(%s(%s) - %s(%s))", | 183 outAppend->appendf("(%s(%s) - %s(%s))", |
| 184 GrGLSLFloatVectorTypeString(N), | 184 GrGLSLFloatVectorTypeString(N), |
| 185 in0, | 185 in0, |
| 186 GrGLSLFloatVectorTypeString(N), | 186 GrGLSLFloatVectorTypeString(N), |
| 187 in1); | 187 in1); |
| 188 return kNone_GrSLConstantVec; | 188 return kNone_GrSLConstantVec; |
| 189 } | 189 } |
| 190 } | 190 } |
| 191 | 191 |
| 192 #endif | 192 #endif |
| OLD | NEW |