OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2014 Google Inc. | 2 * Copyright 2014 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 #include "GrConvexPolyEffect.h" | 8 #include "GrConvexPolyEffect.h" |
9 #include "GrInvariantOutput.h" | 9 #include "GrInvariantOutput.h" |
10 #include "SkPath.h" | 10 #include "SkPath.h" |
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
130 fsBuilder->codeAppend("\t\tfloat xSub, ySub;\n"); | 130 fsBuilder->codeAppend("\t\tfloat xSub, ySub;\n"); |
131 fsBuilder->codeAppendf("\t\txSub = min(%s.x - %s.x, 0.0);\n", fragmentPo
s, rectName); | 131 fsBuilder->codeAppendf("\t\txSub = min(%s.x - %s.x, 0.0);\n", fragmentPo
s, rectName); |
132 fsBuilder->codeAppendf("\t\txSub += min(%s.z - %s.x, 0.0);\n", rectName,
fragmentPos); | 132 fsBuilder->codeAppendf("\t\txSub += min(%s.z - %s.x, 0.0);\n", rectName,
fragmentPos); |
133 fsBuilder->codeAppendf("\t\tySub = min(%s.y - %s.y, 0.0);\n", fragmentPo
s, rectName); | 133 fsBuilder->codeAppendf("\t\tySub = min(%s.y - %s.y, 0.0);\n", fragmentPo
s, rectName); |
134 fsBuilder->codeAppendf("\t\tySub += min(%s.w - %s.y, 0.0);\n", rectName,
fragmentPos); | 134 fsBuilder->codeAppendf("\t\tySub += min(%s.w - %s.y, 0.0);\n", rectName,
fragmentPos); |
135 // Now compute coverage in x and y and multiply them to get the fraction
of the pixel | 135 // Now compute coverage in x and y and multiply them to get the fraction
of the pixel |
136 // covered. | 136 // covered. |
137 fsBuilder->codeAppendf("\t\tfloat alpha = (1.0 + max(xSub, -1.0)) * (1.0
+ max(ySub, -1.0));\n"); | 137 fsBuilder->codeAppendf("\t\tfloat alpha = (1.0 + max(xSub, -1.0)) * (1.0
+ max(ySub, -1.0));\n"); |
138 } else { | 138 } else { |
139 fsBuilder->codeAppendf("\t\tfloat alpha = 1.0;\n"); | 139 fsBuilder->codeAppendf("\t\tfloat alpha = 1.0;\n"); |
140 fsBuilder->codeAppendf("\t\talpha *= (%s.x - %s.x) > -0.5 ? 1.0 : 0.0;\n
", fragmentPos, rectName); | 140 fsBuilder->codeAppendf("\t\talpha *= (%s.x - %s.x) > -0.5 ? 1.0 : 0.0;\n
", |
141 fsBuilder->codeAppendf("\t\talpha *= (%s.z - %s.x) > -0.5 ? 1.0 : 0.0;\n
", rectName, fragmentPos); | 141 fragmentPos, rectName); |
142 fsBuilder->codeAppendf("\t\talpha *= (%s.y - %s.y) > -0.5 ? 1.0 : 0.0;\n
", fragmentPos, rectName); | 142 fsBuilder->codeAppendf("\t\talpha *= (%s.z - %s.x) > -0.5 ? 1.0 : 0.0;\n
", |
143 fsBuilder->codeAppendf("\t\talpha *= (%s.w - %s.y) > -0.5 ? 1.0 : 0.0;\n
", rectName, fragmentPos); | 143 rectName, fragmentPos); |
| 144 fsBuilder->codeAppendf("\t\talpha *= (%s.y - %s.y) > -0.5 ? 1.0 : 0.0;\n
", |
| 145 fragmentPos, rectName); |
| 146 fsBuilder->codeAppendf("\t\talpha *= (%s.w - %s.y) > -0.5 ? 1.0 : 0.0;\n
", |
| 147 rectName, fragmentPos); |
144 } | 148 } |
145 | 149 |
146 if (GrProcessorEdgeTypeIsInverseFill(aare.getEdgeType())) { | 150 if (GrProcessorEdgeTypeIsInverseFill(aare.getEdgeType())) { |
147 fsBuilder->codeAppend("\t\talpha = 1.0 - alpha;\n"); | 151 fsBuilder->codeAppend("\t\talpha = 1.0 - alpha;\n"); |
148 } | 152 } |
149 fsBuilder->codeAppendf("\t\t%s = %s;\n", outputColor, | 153 fsBuilder->codeAppendf("\t\t%s = %s;\n", outputColor, |
150 (GrGLSLExpr4(inputColor) * GrGLSLExpr1("alpha")).c_st
r()); | 154 (GrGLSLExpr4(inputColor) * GrGLSLExpr1("alpha")).c_st
r()); |
151 } | 155 } |
152 | 156 |
153 void GLAARectEffect::setData(const GrGLProgramDataManager& pdman, const GrProces
sor& processor) { | 157 void GLAARectEffect::setData(const GrGLProgramDataManager& pdman, const GrProces
sor& processor) { |
154 const AARectEffect& aare = processor.cast<AARectEffect>(); | 158 const AARectEffect& aare = processor.cast<AARectEffect>(); |
155 const SkRect& rect = aare.getRect(); | 159 const SkRect& rect = aare.getRect(); |
156 if (rect != fPrevRect) { | 160 if (rect != fPrevRect) { |
157 pdman.set4f(fRectUniform, rect.fLeft + 0.5f, rect.fTop + 0.5f, | 161 // Add a device space "nudge" of 0.003f, 0.003f to match raster's roundi
ng behavior for |
158 rect.fRight - 0.5f, rect.fBottom - 0.5f); | 162 // BW clipping/drawing |
| 163 pdman.set4f(fRectUniform, rect.fLeft + 0.503f, rect.fTop + 0.503f, |
| 164 rect.fRight - 0.497f, rect.fBottom - 0.497f); |
159 fPrevRect = rect; | 165 fPrevRect = rect; |
160 } | 166 } |
161 } | 167 } |
162 | 168 |
163 void GLAARectEffect::GenKey(const GrProcessor& processor, const GrGLCaps&, | 169 void GLAARectEffect::GenKey(const GrProcessor& processor, const GrGLCaps&, |
164 GrProcessorKeyBuilder* b) { | 170 GrProcessorKeyBuilder* b) { |
165 const AARectEffect& aare = processor.cast<AARectEffect>(); | 171 const AARectEffect& aare = processor.cast<AARectEffect>(); |
166 b->add32(aare.getEdgeType()); | 172 b->add32(aare.getEdgeType()); |
167 } | 173 } |
168 | 174 |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
214 kVec3f_GrSLType, | 220 kVec3f_GrSLType, |
215 kDefault_GrSLPrecision, | 221 kDefault_GrSLPrecision, |
216 "edges", | 222 "edges", |
217 cpe.getEdgeCount(), | 223 cpe.getEdgeCount(), |
218 &edgeArrayName); | 224 &edgeArrayName); |
219 GrGLFPFragmentBuilder* fsBuilder = builder->getFragmentShaderBuilder(); | 225 GrGLFPFragmentBuilder* fsBuilder = builder->getFragmentShaderBuilder(); |
220 fsBuilder->codeAppend("\t\tfloat alpha = 1.0;\n"); | 226 fsBuilder->codeAppend("\t\tfloat alpha = 1.0;\n"); |
221 fsBuilder->codeAppend("\t\tfloat edge;\n"); | 227 fsBuilder->codeAppend("\t\tfloat edge;\n"); |
222 const char* fragmentPos = fsBuilder->fragmentPosition(); | 228 const char* fragmentPos = fsBuilder->fragmentPosition(); |
223 for (int i = 0; i < cpe.getEdgeCount(); ++i) { | 229 for (int i = 0; i < cpe.getEdgeCount(); ++i) { |
224 fsBuilder->codeAppendf("\t\tedge = dot(%s[%d], vec3(%s.x, %s.y, 1));\n", | 230 // Add a device space "nudge" of 0.003f, 0.003f to match raster's roundi
ng behavior for |
| 231 // BW clipping/drawing. Since we are "nudging" fragment positions we hav
e to go in |
| 232 // the opposite direction. |
| 233 fsBuilder->codeAppendf("\t\tedge = dot(%s[%d], vec3(%s.x - 0.003, %s.y -
0.003, 1));\n", |
225 edgeArrayName, i, fragmentPos, fragmentPos); | 234 edgeArrayName, i, fragmentPos, fragmentPos); |
226 if (GrProcessorEdgeTypeIsAA(cpe.getEdgeType())) { | 235 if (GrProcessorEdgeTypeIsAA(cpe.getEdgeType())) { |
227 fsBuilder->codeAppend("\t\tedge = clamp(edge, 0.0, 1.0);\n"); | 236 fsBuilder->codeAppend("\t\tedge = clamp(edge, 0.0, 1.0);\n"); |
228 } else { | 237 } else { |
229 fsBuilder->codeAppend("\t\tedge = edge >= 0.5 ? 1.0 : 0.0;\n"); | 238 fsBuilder->codeAppend("\t\tedge = edge >= 0.5 ? 1.0 : 0.0;\n"); |
230 } | 239 } |
231 fsBuilder->codeAppend("\t\talpha *= edge;\n"); | 240 fsBuilder->codeAppend("\t\talpha *= edge;\n"); |
232 } | 241 } |
233 | 242 |
234 // Woe is me. See skbug.com/2149. | 243 // Woe is me. See skbug.com/2149. |
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
372 } | 381 } |
373 | 382 |
374 GrFragmentProcessor* fp; | 383 GrFragmentProcessor* fp; |
375 do { | 384 do { |
376 GrPrimitiveEdgeType edgeType = static_cast<GrPrimitiveEdgeType>( | 385 GrPrimitiveEdgeType edgeType = static_cast<GrPrimitiveEdgeType>( |
377 random->nextULessThan(kGrProcessorEdgeTy
peCnt)); | 386 random->nextULessThan(kGrProcessorEdgeTy
peCnt)); |
378 fp = GrConvexPolyEffect::Create(edgeType, count, edges); | 387 fp = GrConvexPolyEffect::Create(edgeType, count, edges); |
379 } while (NULL == fp); | 388 } while (NULL == fp); |
380 return fp; | 389 return fp; |
381 } | 390 } |
OLD | NEW |