OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2016 Google Inc. | 2 * Copyright 2016 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 "InstanceProcessor.h" | 8 #include "InstanceProcessor.h" |
9 | 9 |
10 #include "GrContext.h" | 10 #include "GrContext.h" |
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
140 }; | 140 }; |
141 | 141 |
142 class GLSLInstanceProcessor::Backend { | 142 class GLSLInstanceProcessor::Backend { |
143 public: | 143 public: |
144 static Backend* SK_WARN_UNUSED_RESULT Create(const GrPipeline&, BatchInfo, c
onst VertexInputs&); | 144 static Backend* SK_WARN_UNUSED_RESULT Create(const GrPipeline&, BatchInfo, c
onst VertexInputs&); |
145 virtual ~Backend() {} | 145 virtual ~Backend() {} |
146 | 146 |
147 void init(GrGLSLVaryingHandler*, GrGLSLVertexBuilder*); | 147 void init(GrGLSLVaryingHandler*, GrGLSLVertexBuilder*); |
148 virtual void setupRect(GrGLSLVertexBuilder*) = 0; | 148 virtual void setupRect(GrGLSLVertexBuilder*) = 0; |
149 virtual void setupOval(GrGLSLVertexBuilder*) = 0; | 149 virtual void setupOval(GrGLSLVertexBuilder*) = 0; |
150 void setupRRect(GrGLSLVertexBuilder*); | 150 void setupRRect(GrGLSLVertexBuilder*, int* usedShapeDefinitions); |
151 | 151 |
152 void initInnerShape(GrGLSLVaryingHandler*, GrGLSLVertexBuilder*); | 152 void initInnerShape(GrGLSLVaryingHandler*, GrGLSLVertexBuilder*); |
153 virtual void setupInnerRect(GrGLSLVertexBuilder*) = 0; | 153 virtual void setupInnerRect(GrGLSLVertexBuilder*) = 0; |
154 virtual void setupInnerOval(GrGLSLVertexBuilder*) = 0; | 154 virtual void setupInnerOval(GrGLSLVertexBuilder*) = 0; |
155 void setupInnerRRect(GrGLSLVertexBuilder*); | 155 void setupInnerSimpleRRect(GrGLSLVertexBuilder*); |
156 | 156 |
157 const char* outShapeCoords() { | 157 const char* outShapeCoords() { |
158 return fModifiedShapeCoords ? fModifiedShapeCoords : fInputs.attr(Attrib
::kShapeCoords); | 158 return fModifiedShapeCoords ? fModifiedShapeCoords : fInputs.attr(Attrib
::kShapeCoords); |
159 } | 159 } |
160 | 160 |
161 void emitCode(GrGLSLVertexBuilder*, GrGLSLPPFragmentBuilder*, const char* ou
tCoverage, | 161 void emitCode(GrGLSLVertexBuilder*, GrGLSLPPFragmentBuilder*, const char* ou
tCoverage, |
162 const char* outColor); | 162 const char* outColor); |
163 | 163 |
164 protected: | 164 protected: |
165 Backend(BatchInfo batchInfo, const VertexInputs& inputs) | 165 Backend(BatchInfo batchInfo, const VertexInputs& inputs) |
(...skipping 11 matching lines...) Expand all Loading... |
177 if (fBatchInfo.fShapeTypes & kRRect_ShapesMask) { | 177 if (fBatchInfo.fShapeTypes & kRRect_ShapesMask) { |
178 fModifiedShapeCoords = "adjustedShapeCoords"; | 178 fModifiedShapeCoords = "adjustedShapeCoords"; |
179 } | 179 } |
180 } | 180 } |
181 | 181 |
182 virtual void onInit(GrGLSLVaryingHandler*, GrGLSLVertexBuilder*) = 0; | 182 virtual void onInit(GrGLSLVaryingHandler*, GrGLSLVertexBuilder*) = 0; |
183 virtual void adjustRRectVertices(GrGLSLVertexBuilder*); | 183 virtual void adjustRRectVertices(GrGLSLVertexBuilder*); |
184 virtual void onSetupRRect(GrGLSLVertexBuilder*) {} | 184 virtual void onSetupRRect(GrGLSLVertexBuilder*) {} |
185 | 185 |
186 virtual void onInitInnerShape(GrGLSLVaryingHandler*, GrGLSLVertexBuilder*) =
0; | 186 virtual void onInitInnerShape(GrGLSLVaryingHandler*, GrGLSLVertexBuilder*) =
0; |
187 virtual void onSetupInnerRRect(GrGLSLVertexBuilder*) = 0; | 187 virtual void onSetupInnerSimpleRRect(GrGLSLVertexBuilder*) = 0; |
188 | 188 |
189 virtual void onEmitCode(GrGLSLVertexBuilder*, GrGLSLPPFragmentBuilder*, | 189 virtual void onEmitCode(GrGLSLVertexBuilder*, GrGLSLPPFragmentBuilder*, |
190 const char* outCoverage, const char* outColor) = 0; | 190 const char* outCoverage, const char* outColor) = 0; |
191 | 191 |
192 void setupSimpleRadii(GrGLSLVertexBuilder*); | 192 void setupSimpleRadii(GrGLSLVertexBuilder*); |
193 void setupNinePatchRadii(GrGLSLVertexBuilder*); | 193 void setupNinePatchRadii(GrGLSLVertexBuilder*); |
194 void setupComplexRadii(GrGLSLVertexBuilder*); | 194 void setupComplexRadii(GrGLSLVertexBuilder*); |
195 | 195 |
196 const BatchInfo fBatchInfo; | 196 const BatchInfo fBatchInfo; |
197 const VertexInputs& fInputs; | 197 const VertexInputs& fInputs; |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
230 v->codeAppendf("mat3 shapeMatrix = mat3(%s, %s, vec3(0, 0, 1));", | 230 v->codeAppendf("mat3 shapeMatrix = mat3(%s, %s, vec3(0, 0, 1));", |
231 inputs.attr(Attrib::kShapeMatrixX), inputs.attr(Attrib::k
ShapeMatrixY)); | 231 inputs.attr(Attrib::kShapeMatrixX), inputs.attr(Attrib::k
ShapeMatrixY)); |
232 v->codeAppendf("if (0u != (%s & PERSPECTIVE_FLAG)) {", | 232 v->codeAppendf("if (0u != (%s & PERSPECTIVE_FLAG)) {", |
233 inputs.attr(Attrib::kInstanceInfo)); | 233 inputs.attr(Attrib::kInstanceInfo)); |
234 v->codeAppend ( "shapeMatrix[2] = "); | 234 v->codeAppend ( "shapeMatrix[2] = "); |
235 inputs.fetchNextParam(kVec3f_GrSLType); | 235 inputs.fetchNextParam(kVec3f_GrSLType); |
236 v->codeAppend ( ";"); | 236 v->codeAppend ( ";"); |
237 v->codeAppend ("}"); | 237 v->codeAppend ("}"); |
238 } | 238 } |
239 | 239 |
240 int usedShapeTypes = 0; | |
241 | |
242 bool hasSingleShapeType = SkIsPow2(ip.batchInfo().fShapeTypes); | 240 bool hasSingleShapeType = SkIsPow2(ip.batchInfo().fShapeTypes); |
243 if (!hasSingleShapeType) { | 241 if (!hasSingleShapeType) { |
244 usedShapeTypes |= ip.batchInfo().fShapeTypes; | |
245 v->define("SHAPE_TYPE_BIT", kShapeType_InfoBit); | 242 v->define("SHAPE_TYPE_BIT", kShapeType_InfoBit); |
246 v->codeAppendf("uint shapeType = %s >> SHAPE_TYPE_BIT;", | 243 v->codeAppendf("uint shapeType = %s >> SHAPE_TYPE_BIT;", |
247 inputs.attr(Attrib::kInstanceInfo)); | 244 inputs.attr(Attrib::kInstanceInfo)); |
248 } | 245 } |
249 | 246 |
250 SkAutoTDelete<Backend> backend(Backend::Create(pipeline, ip.batchInfo(), inp
uts)); | 247 SkAutoTDelete<Backend> backend(Backend::Create(pipeline, ip.batchInfo(), inp
uts)); |
251 backend->init(varyingHandler, v); | 248 backend->init(varyingHandler, v); |
252 | 249 |
253 if (hasSingleShapeType) { | 250 int usedShapeDefinitions = 0; |
| 251 |
| 252 if (hasSingleShapeType || !(ip.batchInfo().fShapeTypes & ~kRRect_ShapesMask)
) { |
254 if (kRect_ShapeFlag == ip.batchInfo().fShapeTypes) { | 253 if (kRect_ShapeFlag == ip.batchInfo().fShapeTypes) { |
255 backend->setupRect(v); | 254 backend->setupRect(v); |
256 } else if (kOval_ShapeFlag == ip.batchInfo().fShapeTypes) { | 255 } else if (kOval_ShapeFlag == ip.batchInfo().fShapeTypes) { |
257 backend->setupOval(v); | 256 backend->setupOval(v); |
258 } else { | 257 } else { |
259 backend->setupRRect(v); | 258 backend->setupRRect(v, &usedShapeDefinitions); |
260 } | 259 } |
261 } else { | 260 } else { |
262 v->codeAppend ("switch (shapeType) {"); | 261 if (ip.batchInfo().fShapeTypes & kRRect_ShapesMask) { |
263 if (ip.batchInfo().fShapeTypes & kRect_ShapeFlag) { | 262 v->codeAppend ("if (shapeType >= SIMPLE_R_RECT_SHAPE_TYPE) {"); |
264 v->codeAppend ("case RECT_SHAPE_TYPE: {"); | 263 backend->setupRRect(v, &usedShapeDefinitions); |
265 backend->setupRect(v); | 264 v->codeAppend ("}"); |
266 v->codeAppend ("} break;"); | 265 usedShapeDefinitions |= kSimpleRRect_ShapeFlag; |
267 } | 266 } |
268 if (ip.batchInfo().fShapeTypes & kOval_ShapeFlag) { | 267 if (ip.batchInfo().fShapeTypes & kOval_ShapeFlag) { |
269 v->codeAppend ("case OVAL_SHAPE_TYPE: {"); | 268 if (ip.batchInfo().fShapeTypes & kRect_ShapeFlag) { |
| 269 if (ip.batchInfo().fShapeTypes & kRRect_ShapesMask) { |
| 270 v->codeAppend ("else "); |
| 271 } |
| 272 v->codeAppend ("if (OVAL_SHAPE_TYPE == shapeType) {"); |
| 273 usedShapeDefinitions |= kOval_ShapeFlag; |
| 274 } else { |
| 275 v->codeAppend ("else {"); |
| 276 } |
270 backend->setupOval(v); | 277 backend->setupOval(v); |
271 v->codeAppend ("} break;"); | 278 v->codeAppend ("}"); |
272 } | 279 } |
273 if (ip.batchInfo().fShapeTypes & kRRect_ShapesMask) { | 280 if (ip.batchInfo().fShapeTypes & kRect_ShapeFlag) { |
274 v->codeAppend ("default: {"); | 281 v->codeAppend ("else {"); |
275 backend->setupRRect(v); | 282 backend->setupRect(v); |
276 v->codeAppend ("} break;"); | 283 v->codeAppend ("}"); |
277 } | 284 } |
278 v->codeAppend ("}"); | |
279 } | 285 } |
280 | 286 |
281 if (ip.batchInfo().fInnerShapeTypes) { | 287 if (ip.batchInfo().fInnerShapeTypes) { |
282 bool hasSingleInnerShapeType = SkIsPow2(ip.batchInfo().fInnerShapeTypes)
; | 288 bool hasSingleInnerShapeType = SkIsPow2(ip.batchInfo().fInnerShapeTypes)
; |
283 if (!hasSingleInnerShapeType) { | 289 if (!hasSingleInnerShapeType) { |
284 usedShapeTypes |= ip.batchInfo().fInnerShapeTypes; | |
285 v->definef("INNER_SHAPE_TYPE_MASK", "0x%xu", kInnerShapeType_InfoMas
k); | 290 v->definef("INNER_SHAPE_TYPE_MASK", "0x%xu", kInnerShapeType_InfoMas
k); |
286 v->define("INNER_SHAPE_TYPE_BIT", kInnerShapeType_InfoBit); | 291 v->define("INNER_SHAPE_TYPE_BIT", kInnerShapeType_InfoBit); |
287 v->codeAppendf("uint innerShapeType = ((%s & INNER_SHAPE_TYPE_MASK)
>> " | 292 v->codeAppendf("uint innerShapeType = ((%s & INNER_SHAPE_TYPE_MASK)
>> " |
288 "INNER_SHAPE_TYPE_BIT);", | 293 "INNER_SHAPE_TYPE_BIT);", |
289 inputs.attr(Attrib::kInstanceInfo)); | 294 inputs.attr(Attrib::kInstanceInfo)); |
290 } | 295 } |
291 // Here we take advantage of the fact that outerRect == localRect in rec
ordDRRect. | 296 // Here we take advantage of the fact that outerRect == localRect in rec
ordDRRect. |
292 v->codeAppendf("vec4 outer = %s;", inputs.attr(Attrib::kLocalRect)); | 297 v->codeAppendf("vec4 outer = %s;", inputs.attr(Attrib::kLocalRect)); |
293 v->codeAppend ("vec4 inner = "); | 298 v->codeAppend ("vec4 inner = "); |
294 inputs.fetchNextParam(); | 299 inputs.fetchNextParam(); |
295 v->codeAppend (";"); | 300 v->codeAppend (";"); |
296 // outer2Inner is a transform from shape coords to inner shape coords: | 301 // outer2Inner is a transform from shape coords to inner shape coords: |
297 // e.g. innerShapeCoords = shapeCoords * outer2Inner.xy + outer2Inner.zw | 302 // e.g. innerShapeCoords = shapeCoords * outer2Inner.xy + outer2Inner.zw |
298 v->codeAppend ("vec4 outer2Inner = vec4(outer.zw - outer.xy, " | 303 v->codeAppend ("vec4 outer2Inner = vec4(outer.zw - outer.xy, " |
299 "outer.xy + outer.zw - inner.xy -
inner.zw) / " | 304 "outer.xy + outer.zw - inner.xy -
inner.zw) / " |
300 "(inner.zw - inner.xy).xyxy;"); | 305 "(inner.zw - inner.xy).xyxy;"); |
301 v->codeAppendf("vec2 innerShapeCoords = %s * outer2Inner.xy + outer2Inne
r.zw;", | 306 v->codeAppendf("vec2 innerShapeCoords = %s * outer2Inner.xy + outer2Inne
r.zw;", |
302 backend->outShapeCoords()); | 307 backend->outShapeCoords()); |
303 | 308 |
304 backend->initInnerShape(varyingHandler, v); | 309 backend->initInnerShape(varyingHandler, v); |
305 | 310 |
| 311 SkASSERT(0 == (ip.batchInfo().fInnerShapeTypes & kRRect_ShapesMask) || |
| 312 kSimpleRRect_ShapeFlag == (ip.batchInfo().fInnerShapeTypes & kR
Rect_ShapesMask)); |
| 313 |
306 if (hasSingleInnerShapeType) { | 314 if (hasSingleInnerShapeType) { |
307 if (kRect_ShapeFlag == ip.batchInfo().fInnerShapeTypes) { | 315 if (kRect_ShapeFlag == ip.batchInfo().fInnerShapeTypes) { |
308 backend->setupInnerRect(v); | 316 backend->setupInnerRect(v); |
309 } else if (kOval_ShapeFlag == ip.batchInfo().fInnerShapeTypes) { | 317 } else if (kOval_ShapeFlag == ip.batchInfo().fInnerShapeTypes) { |
310 backend->setupInnerOval(v); | 318 backend->setupInnerOval(v); |
311 } else { | 319 } else { |
312 backend->setupInnerRRect(v); | 320 backend->setupInnerSimpleRRect(v); |
313 } | 321 } |
314 } else { | 322 } else { |
315 v->codeAppend("switch (innerShapeType) {"); | 323 if (ip.batchInfo().fInnerShapeTypes & kSimpleRRect_ShapeFlag) { |
316 if (ip.batchInfo().fInnerShapeTypes & kRect_ShapeFlag) { | 324 v->codeAppend ("if (SIMPLE_R_RECT_SHAPE_TYPE == innerShapeType)
{"); |
317 v->codeAppend("case RECT_SHAPE_TYPE: {"); | 325 backend->setupInnerSimpleRRect(v); |
318 backend->setupInnerRect(v); | 326 v->codeAppend("}"); |
319 v->codeAppend("} break;"); | 327 usedShapeDefinitions |= kSimpleRRect_ShapeFlag; |
320 } | 328 } |
321 if (ip.batchInfo().fInnerShapeTypes & kOval_ShapeFlag) { | 329 if (ip.batchInfo().fInnerShapeTypes & kOval_ShapeFlag) { |
322 v->codeAppend("case OVAL_SHAPE_TYPE: {"); | 330 if (ip.batchInfo().fInnerShapeTypes & kRect_ShapeFlag) { |
| 331 if (ip.batchInfo().fInnerShapeTypes & kSimpleRRect_ShapeFlag
) { |
| 332 v->codeAppend ("else "); |
| 333 } |
| 334 v->codeAppend ("if (OVAL_SHAPE_TYPE == innerShapeType) {"); |
| 335 usedShapeDefinitions |= kOval_ShapeFlag; |
| 336 } else { |
| 337 v->codeAppend ("else {"); |
| 338 } |
323 backend->setupInnerOval(v); | 339 backend->setupInnerOval(v); |
324 v->codeAppend("} break;"); | 340 v->codeAppend("}"); |
325 } | 341 } |
326 if (ip.batchInfo().fInnerShapeTypes & kRRect_ShapesMask) { | 342 if (ip.batchInfo().fInnerShapeTypes & kRect_ShapeFlag) { |
327 v->codeAppend("default: {"); | 343 v->codeAppend("else {"); |
328 backend->setupInnerRRect(v); | 344 backend->setupInnerRect(v); |
329 v->codeAppend("} break;"); | 345 v->codeAppend("}"); |
330 } | 346 } |
331 v->codeAppend("}"); | |
332 } | 347 } |
333 } | 348 } |
334 | 349 |
335 if (usedShapeTypes & kRect_ShapeFlag) { | 350 if (usedShapeDefinitions & kOval_ShapeFlag) { |
336 v->definef("RECT_SHAPE_TYPE", "%du", (int)ShapeType::kRect); | |
337 } | |
338 if (usedShapeTypes & kOval_ShapeFlag) { | |
339 v->definef("OVAL_SHAPE_TYPE", "%du", (int)ShapeType::kOval); | 351 v->definef("OVAL_SHAPE_TYPE", "%du", (int)ShapeType::kOval); |
340 } | 352 } |
| 353 if (usedShapeDefinitions & kSimpleRRect_ShapeFlag) { |
| 354 v->definef("SIMPLE_R_RECT_SHAPE_TYPE", "%du", (int)ShapeType::kSimpleRRe
ct); |
| 355 } |
| 356 if (usedShapeDefinitions & kNinePatch_ShapeFlag) { |
| 357 v->definef("NINE_PATCH_SHAPE_TYPE", "%du", (int)ShapeType::kNinePatch); |
| 358 } |
| 359 SkASSERT(!(usedShapeDefinitions & (kRect_ShapeFlag | kComplexRRect_ShapeFlag
))); |
341 | 360 |
342 backend->emitCode(v, f, pipeline.ignoresCoverage() ? nullptr : args.fOutputC
overage, | 361 backend->emitCode(v, f, pipeline.ignoresCoverage() ? nullptr : args.fOutputC
overage, |
343 args.fOutputColor); | 362 args.fOutputColor); |
344 | 363 |
345 const char* localCoords = nullptr; | 364 const char* localCoords = nullptr; |
346 if (ip.batchInfo().fUsesLocalCoords) { | 365 if (ip.batchInfo().fUsesLocalCoords) { |
347 localCoords = "localCoords"; | 366 localCoords = "localCoords"; |
348 v->codeAppendf("vec2 t = 0.5 * (%s + vec2(1));", backend->outShapeCoords
()); | 367 v->codeAppendf("vec2 t = 0.5 * (%s + vec2(1));", backend->outShapeCoords
()); |
349 v->codeAppendf("vec2 localCoords = (1.0 - t) * %s.xy + t * %s.zw;", | 368 v->codeAppendf("vec2 localCoords = (1.0 - t) * %s.xy + t * %s.zw;", |
350 inputs.attr(Attrib::kLocalRect), inputs.attr(Attrib::kLoc
alRect)); | 369 inputs.attr(Attrib::kLocalRect), inputs.attr(Attrib::kLoc
alRect)); |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
386 } | 405 } |
387 | 406 |
388 this->onInit(varyingHandler, v); | 407 this->onInit(varyingHandler, v); |
389 | 408 |
390 if (!fColor.vsOut()) { | 409 if (!fColor.vsOut()) { |
391 varyingHandler->addFlatVarying("color", &fColor, kLow_GrSLPrecision); | 410 varyingHandler->addFlatVarying("color", &fColor, kLow_GrSLPrecision); |
392 v->codeAppendf("%s = %s;", fColor.vsOut(), fInputs.attr(Attrib::kColor))
; | 411 v->codeAppendf("%s = %s;", fColor.vsOut(), fInputs.attr(Attrib::kColor))
; |
393 } | 412 } |
394 } | 413 } |
395 | 414 |
396 void GLSLInstanceProcessor::Backend::setupRRect(GrGLSLVertexBuilder* v) { | 415 void GLSLInstanceProcessor::Backend::setupRRect(GrGLSLVertexBuilder* v, int* use
dShapeDefinitions) { |
397 v->codeAppendf("uvec2 corner = uvec2(%s & 1, (%s >> 1) & 1);", | 416 v->codeAppendf("uvec2 corner = uvec2(%s & 1, (%s >> 1) & 1);", |
398 fInputs.attr(Attrib::kVertexAttrs), fInputs.attr(Attrib::kVer
texAttrs)); | 417 fInputs.attr(Attrib::kVertexAttrs), fInputs.attr(Attrib::kVer
texAttrs)); |
399 v->codeAppend ("vec2 cornerSign = vec2(corner) * 2.0 - 1.0;"); | 418 v->codeAppend ("vec2 cornerSign = vec2(corner) * 2.0 - 1.0;"); |
400 v->codeAppendf("vec2 radii%s;", fNeedsNeighborRadii ? ", neighborRadii" : ""
); | 419 v->codeAppendf("vec2 radii%s;", fNeedsNeighborRadii ? ", neighborRadii" : ""
); |
401 v->codeAppend ("mat2 p = "); | 420 v->codeAppend ("mat2 p = "); |
402 fInputs.fetchNextParam(kMat22f_GrSLType); | 421 fInputs.fetchNextParam(kMat22f_GrSLType); |
403 v->codeAppend (";"); | 422 v->codeAppend (";"); |
404 uint8_t types = fBatchInfo.fShapeTypes & kRRect_ShapesMask; | 423 uint8_t types = fBatchInfo.fShapeTypes & kRRect_ShapesMask; |
405 if (0 == (types & (types - 1))) { | 424 if (0 == (types & (types - 1))) { |
406 if (kSimpleRRect_ShapeFlag == types) { | 425 if (kSimpleRRect_ShapeFlag == types) { |
407 this->setupSimpleRadii(v); | 426 this->setupSimpleRadii(v); |
408 } else if (kNinePatch_ShapeFlag == types) { | 427 } else if (kNinePatch_ShapeFlag == types) { |
409 this->setupNinePatchRadii(v); | 428 this->setupNinePatchRadii(v); |
410 } else if (kComplexRRect_ShapeFlag == types) { | 429 } else if (kComplexRRect_ShapeFlag == types) { |
411 this->setupComplexRadii(v); | 430 this->setupComplexRadii(v); |
412 } | 431 } |
413 } else { | 432 } else { |
414 v->codeAppend("switch (shapeType) {"); | |
415 if (types & kSimpleRRect_ShapeFlag) { | 433 if (types & kSimpleRRect_ShapeFlag) { |
416 v->definef("SIMPLE_R_RECT_SHAPE_TYPE", "%du", (int)ShapeType::kSimpl
eRRect); | 434 v->codeAppend ("if (SIMPLE_R_RECT_SHAPE_TYPE == shapeType) {"); |
417 v->codeAppend ("case SIMPLE_R_RECT_SHAPE_TYPE: {"); | |
418 this->setupSimpleRadii(v); | 435 this->setupSimpleRadii(v); |
419 v->codeAppend ("} break;"); | 436 v->codeAppend ("}"); |
| 437 *usedShapeDefinitions |= kSimpleRRect_ShapeFlag; |
420 } | 438 } |
421 if (types & kNinePatch_ShapeFlag) { | 439 if (types & kNinePatch_ShapeFlag) { |
422 v->definef("NINE_PATCH_SHAPE_TYPE", "%du", (int)ShapeType::kNinePatc
h); | 440 if (types & kComplexRRect_ShapeFlag) { |
423 v->codeAppend ("case NINE_PATCH_SHAPE_TYPE: {"); | 441 if (types & kSimpleRRect_ShapeFlag) { |
| 442 v->codeAppend ("else "); |
| 443 } |
| 444 v->codeAppend ("if (NINE_PATCH_SHAPE_TYPE == shapeType) {"); |
| 445 *usedShapeDefinitions |= kNinePatch_ShapeFlag; |
| 446 } else { |
| 447 v->codeAppend ("else {"); |
| 448 } |
424 this->setupNinePatchRadii(v); | 449 this->setupNinePatchRadii(v); |
425 v->codeAppend ("} break;"); | 450 v->codeAppend ("}"); |
426 } | 451 } |
427 if (types & kComplexRRect_ShapeFlag) { | 452 if (types & kComplexRRect_ShapeFlag) { |
428 v->codeAppend ("default: {"); | 453 v->codeAppend ("else {"); |
429 this->setupComplexRadii(v); | 454 this->setupComplexRadii(v); |
430 v->codeAppend ("} break;"); | 455 v->codeAppend ("}"); |
431 } | 456 } |
432 v->codeAppend("}"); | |
433 } | 457 } |
434 | 458 |
435 this->adjustRRectVertices(v); | 459 this->adjustRRectVertices(v); |
436 | 460 |
437 if (fArcCoords.vsOut()) { | 461 if (fArcCoords.vsOut()) { |
438 v->codeAppendf("%s = (cornerSign * %s + radii - vec2(1)) / radii;", | 462 v->codeAppendf("%s = (cornerSign * %s + radii - vec2(1)) / radii;", |
439 fArcCoords.vsOut(), fModifiedShapeCoords); | 463 fArcCoords.vsOut(), fModifiedShapeCoords); |
440 } | 464 } |
441 if (fTriangleIsArc.vsOut()) { | 465 if (fTriangleIsArc.vsOut()) { |
442 v->codeAppendf("%s = int(all(equal(vec2(1), abs(%s))));", | 466 v->codeAppendf("%s = int(all(equal(vec2(1), abs(%s))));", |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
500 GrGLSLVertexBuilder* v) { | 524 GrGLSLVertexBuilder* v) { |
501 SkASSERT(!(fBatchInfo.fInnerShapeTypes & (kNinePatch_ShapeFlag | kComplexRRe
ct_ShapeFlag))); | 525 SkASSERT(!(fBatchInfo.fInnerShapeTypes & (kNinePatch_ShapeFlag | kComplexRRe
ct_ShapeFlag))); |
502 | 526 |
503 this->onInitInnerShape(varyingHandler, v); | 527 this->onInitInnerShape(varyingHandler, v); |
504 | 528 |
505 if (fInnerShapeCoords.vsOut()) { | 529 if (fInnerShapeCoords.vsOut()) { |
506 v->codeAppendf("%s = innerShapeCoords;", fInnerShapeCoords.vsOut()); | 530 v->codeAppendf("%s = innerShapeCoords;", fInnerShapeCoords.vsOut()); |
507 } | 531 } |
508 } | 532 } |
509 | 533 |
510 void GLSLInstanceProcessor::Backend::setupInnerRRect(GrGLSLVertexBuilder* v) { | 534 void GLSLInstanceProcessor::Backend::setupInnerSimpleRRect(GrGLSLVertexBuilder*
v) { |
511 v->codeAppend("mat2 innerP = "); | 535 v->codeAppend("mat2 innerP = "); |
512 fInputs.fetchNextParam(kMat22f_GrSLType); | 536 fInputs.fetchNextParam(kMat22f_GrSLType); |
513 v->codeAppend(";"); | 537 v->codeAppend(";"); |
514 v->codeAppend("vec2 innerRadii = innerP[0] * 2.0 / innerP[1];"); | 538 v->codeAppend("vec2 innerRadii = innerP[0] * 2.0 / innerP[1];"); |
515 this->onSetupInnerRRect(v); | 539 this->onSetupInnerSimpleRRect(v); |
516 } | 540 } |
517 | 541 |
518 void GLSLInstanceProcessor::Backend::emitCode(GrGLSLVertexBuilder* v, GrGLSLPPFr
agmentBuilder* f, | 542 void GLSLInstanceProcessor::Backend::emitCode(GrGLSLVertexBuilder* v, GrGLSLPPFr
agmentBuilder* f, |
519 const char* outCoverage, const cha
r* outColor) { | 543 const char* outCoverage, const cha
r* outColor) { |
520 SkASSERT(!fModifiesCoverage || outCoverage); | 544 SkASSERT(!fModifiesCoverage || outCoverage); |
521 this->onEmitCode(v, f, fModifiesCoverage ? outCoverage : nullptr, | 545 this->onEmitCode(v, f, fModifiesCoverage ? outCoverage : nullptr, |
522 fModifiesColor ? outColor : nullptr); | 546 fModifiesColor ? outColor : nullptr); |
523 if (outCoverage && !fModifiesCoverage) { | 547 if (outCoverage && !fModifiesCoverage) { |
524 // Even though the subclass doesn't use coverage, we are expected to ass
ign some value. | 548 // Even though the subclass doesn't use coverage, we are expected to ass
ign some value. |
525 f->codeAppendf("%s = vec4(1);", outCoverage); | 549 f->codeAppendf("%s = vec4(1);", outCoverage); |
(...skipping 17 matching lines...) Expand all Loading... |
543 } | 567 } |
544 | 568 |
545 private: | 569 private: |
546 void onInit(GrGLSLVaryingHandler*, GrGLSLVertexBuilder*) override; | 570 void onInit(GrGLSLVaryingHandler*, GrGLSLVertexBuilder*) override; |
547 void setupRect(GrGLSLVertexBuilder*) override; | 571 void setupRect(GrGLSLVertexBuilder*) override; |
548 void setupOval(GrGLSLVertexBuilder*) override; | 572 void setupOval(GrGLSLVertexBuilder*) override; |
549 | 573 |
550 void onInitInnerShape(GrGLSLVaryingHandler*, GrGLSLVertexBuilder*) override; | 574 void onInitInnerShape(GrGLSLVaryingHandler*, GrGLSLVertexBuilder*) override; |
551 void setupInnerRect(GrGLSLVertexBuilder*) override; | 575 void setupInnerRect(GrGLSLVertexBuilder*) override; |
552 void setupInnerOval(GrGLSLVertexBuilder*) override; | 576 void setupInnerOval(GrGLSLVertexBuilder*) override; |
553 void onSetupInnerRRect(GrGLSLVertexBuilder*) override; | 577 void onSetupInnerSimpleRRect(GrGLSLVertexBuilder*) override; |
554 | 578 |
555 void onEmitCode(GrGLSLVertexBuilder*, GrGLSLPPFragmentBuilder*, const char*, | 579 void onEmitCode(GrGLSLVertexBuilder*, GrGLSLPPFragmentBuilder*, const char*, |
556 const char*) override; | 580 const char*) override; |
557 | 581 |
558 typedef Backend INHERITED; | 582 typedef Backend INHERITED; |
559 }; | 583 }; |
560 | 584 |
561 void GLSLInstanceProcessor::BackendNonAA::onInit(GrGLSLVaryingHandler* varyingHa
ndler, | 585 void GLSLInstanceProcessor::BackendNonAA::onInit(GrGLSLVaryingHandler* varyingHa
ndler, |
562 GrGLSLVertexBuilder*) { | 586 GrGLSLVertexBuilder*) { |
563 if (kRect_ShapeFlag != fBatchInfo.fShapeTypes) { | 587 if (kRect_ShapeFlag != fBatchInfo.fShapeTypes) { |
(...skipping 29 matching lines...) Expand all Loading... |
593 v->codeAppendf("%s = vec4(1);", fInnerRRect.vsOut()); | 617 v->codeAppendf("%s = vec4(1);", fInnerRRect.vsOut()); |
594 } | 618 } |
595 } | 619 } |
596 | 620 |
597 void GLSLInstanceProcessor::BackendNonAA::setupInnerOval(GrGLSLVertexBuilder* v)
{ | 621 void GLSLInstanceProcessor::BackendNonAA::setupInnerOval(GrGLSLVertexBuilder* v)
{ |
598 if (fInnerRRect.vsOut()) { | 622 if (fInnerRRect.vsOut()) { |
599 v->codeAppendf("%s = vec4(0, 0, 1, 1);", fInnerRRect.vsOut()); | 623 v->codeAppendf("%s = vec4(0, 0, 1, 1);", fInnerRRect.vsOut()); |
600 } | 624 } |
601 } | 625 } |
602 | 626 |
603 void GLSLInstanceProcessor::BackendNonAA::onSetupInnerRRect(GrGLSLVertexBuilder*
v) { | 627 void GLSLInstanceProcessor::BackendNonAA::onSetupInnerSimpleRRect(GrGLSLVertexBu
ilder* v) { |
604 v->codeAppendf("%s = vec4(1.0 - innerRadii, 1.0 / innerRadii);", fInnerRRect
.vsOut()); | 628 v->codeAppendf("%s = vec4(1.0 - innerRadii, 1.0 / innerRadii);", fInnerRRect
.vsOut()); |
605 } | 629 } |
606 | 630 |
607 void GLSLInstanceProcessor::BackendNonAA::onEmitCode(GrGLSLVertexBuilder*, | 631 void GLSLInstanceProcessor::BackendNonAA::onEmitCode(GrGLSLVertexBuilder*, |
608 GrGLSLPPFragmentBuilder* f, | 632 GrGLSLPPFragmentBuilder* f, |
609 const char* outCoverage, | 633 const char* outCoverage, |
610 const char* outColor) { | 634 const char* outColor) { |
611 const char* dropFragment = nullptr; | 635 const char* dropFragment = nullptr; |
612 if (!fBatchInfo.fCannotDiscard) { | 636 if (!fBatchInfo.fCannotDiscard) { |
613 dropFragment = "discard"; | 637 dropFragment = "discard"; |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
683 private: | 707 private: |
684 void onInit(GrGLSLVaryingHandler*, GrGLSLVertexBuilder*) override; | 708 void onInit(GrGLSLVaryingHandler*, GrGLSLVertexBuilder*) override; |
685 void setupRect(GrGLSLVertexBuilder*) override; | 709 void setupRect(GrGLSLVertexBuilder*) override; |
686 void setupOval(GrGLSLVertexBuilder*) override; | 710 void setupOval(GrGLSLVertexBuilder*) override; |
687 void adjustRRectVertices(GrGLSLVertexBuilder*) override; | 711 void adjustRRectVertices(GrGLSLVertexBuilder*) override; |
688 void onSetupRRect(GrGLSLVertexBuilder*) override; | 712 void onSetupRRect(GrGLSLVertexBuilder*) override; |
689 | 713 |
690 void onInitInnerShape(GrGLSLVaryingHandler*, GrGLSLVertexBuilder*) override; | 714 void onInitInnerShape(GrGLSLVaryingHandler*, GrGLSLVertexBuilder*) override; |
691 void setupInnerRect(GrGLSLVertexBuilder*) override; | 715 void setupInnerRect(GrGLSLVertexBuilder*) override; |
692 void setupInnerOval(GrGLSLVertexBuilder*) override; | 716 void setupInnerOval(GrGLSLVertexBuilder*) override; |
693 void onSetupInnerRRect(GrGLSLVertexBuilder*) override; | 717 void onSetupInnerSimpleRRect(GrGLSLVertexBuilder*) override; |
694 | 718 |
695 void onEmitCode(GrGLSLVertexBuilder*, GrGLSLPPFragmentBuilder*, const char*
outCoverage, | 719 void onEmitCode(GrGLSLVertexBuilder*, GrGLSLPPFragmentBuilder*, const char*
outCoverage, |
696 const char* outColor) override; | 720 const char* outColor) override; |
697 | 721 |
698 void emitRect(GrGLSLPPFragmentBuilder*, const char* outCoverage, const char*
outColor); | 722 void emitRect(GrGLSLPPFragmentBuilder*, const char* outCoverage, const char*
outColor); |
699 void emitCircle(GrGLSLPPFragmentBuilder*, const char* outCoverage); | 723 void emitCircle(GrGLSLPPFragmentBuilder*, const char* outCoverage); |
700 void emitArc(GrGLSLPPFragmentBuilder* f, const char* ellipseCoords, const ch
ar* ellipseName, | 724 void emitArc(GrGLSLPPFragmentBuilder* f, const char* ellipseCoords, const ch
ar* ellipseName, |
701 bool ellipseCoordsNeedClamp, bool ellipseCoordsMayBeNegative, | 725 bool ellipseCoordsNeedClamp, bool ellipseCoordsMayBeNegative, |
702 const char* outCoverage); | 726 const char* outCoverage); |
703 void emitInnerRect(GrGLSLPPFragmentBuilder*, const char* outCoverage); | 727 void emitInnerRect(GrGLSLPPFragmentBuilder*, const char* outCoverage); |
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
875 v->codeAppendf("%s = 1.0 / (innerShapeHalfSize * innerShapeHalfSize);", | 899 v->codeAppendf("%s = 1.0 / (innerShapeHalfSize * innerShapeHalfSize);", |
876 fInnerEllipseName.vsOut()); | 900 fInnerEllipseName.vsOut()); |
877 if (fInnerEllipseCoords.vsOut()) { | 901 if (fInnerEllipseCoords.vsOut()) { |
878 v->codeAppendf("%s = innerShapeCoords * innerShapeHalfSize;", fInnerElli
pseCoords.vsOut()); | 902 v->codeAppendf("%s = innerShapeCoords * innerShapeHalfSize;", fInnerElli
pseCoords.vsOut()); |
879 } | 903 } |
880 if (fInnerRRect.vsOut()) { | 904 if (fInnerRRect.vsOut()) { |
881 v->codeAppendf("%s = vec4(0, 0, innerShapeHalfSize);", fInnerRRect.vsOut
()); | 905 v->codeAppendf("%s = vec4(0, 0, innerShapeHalfSize);", fInnerRRect.vsOut
()); |
882 } | 906 } |
883 } | 907 } |
884 | 908 |
885 void GLSLInstanceProcessor::BackendCoverage::onSetupInnerRRect(GrGLSLVertexBuild
er* v) { | 909 void GLSLInstanceProcessor::BackendCoverage::onSetupInnerSimpleRRect(GrGLSLVerte
xBuilder* v) { |
886 // The distance to ellipse formula doesn't work well when the radii are less
than half a pixel. | 910 // The distance to ellipse formula doesn't work well when the radii are less
than half a pixel. |
887 v->codeAppend ("innerRadii = max(innerRadii, bloat);"); | 911 v->codeAppend ("innerRadii = max(innerRadii, bloat);"); |
888 v->codeAppendf("%s = 1.0 / (innerRadii * innerRadii * innerShapeHalfSize * " | 912 v->codeAppendf("%s = 1.0 / (innerRadii * innerRadii * innerShapeHalfSize * " |
889 "innerShapeHalfSize);", | 913 "innerShapeHalfSize);", |
890 fInnerEllipseName.vsOut()); | 914 fInnerEllipseName.vsOut()); |
891 v->codeAppendf("%s = vec4(1.0 - innerRadii, innerShapeHalfSize);", fInnerRRe
ct.vsOut()); | 915 v->codeAppendf("%s = vec4(1.0 - innerRadii, innerShapeHalfSize);", fInnerRRe
ct.vsOut()); |
892 } | 916 } |
893 | 917 |
894 void GLSLInstanceProcessor::BackendCoverage::onEmitCode(GrGLSLVertexBuilder* v, | 918 void GLSLInstanceProcessor::BackendCoverage::onEmitCode(GrGLSLVertexBuilder* v, |
895 GrGLSLPPFragmentBuilder*
f, | 919 GrGLSLPPFragmentBuilder*
f, |
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1057 | 1081 |
1058 void onInit(GrGLSLVaryingHandler*, GrGLSLVertexBuilder*) override; | 1082 void onInit(GrGLSLVaryingHandler*, GrGLSLVertexBuilder*) override; |
1059 void setupRect(GrGLSLVertexBuilder*) override; | 1083 void setupRect(GrGLSLVertexBuilder*) override; |
1060 void setupOval(GrGLSLVertexBuilder*) override; | 1084 void setupOval(GrGLSLVertexBuilder*) override; |
1061 void adjustRRectVertices(GrGLSLVertexBuilder*) override; | 1085 void adjustRRectVertices(GrGLSLVertexBuilder*) override; |
1062 void onSetupRRect(GrGLSLVertexBuilder*) override; | 1086 void onSetupRRect(GrGLSLVertexBuilder*) override; |
1063 | 1087 |
1064 void onInitInnerShape(GrGLSLVaryingHandler*, GrGLSLVertexBuilder*) override; | 1088 void onInitInnerShape(GrGLSLVaryingHandler*, GrGLSLVertexBuilder*) override; |
1065 void setupInnerRect(GrGLSLVertexBuilder*) override; | 1089 void setupInnerRect(GrGLSLVertexBuilder*) override; |
1066 void setupInnerOval(GrGLSLVertexBuilder*) override; | 1090 void setupInnerOval(GrGLSLVertexBuilder*) override; |
1067 void onSetupInnerRRect(GrGLSLVertexBuilder*) override; | 1091 void onSetupInnerSimpleRRect(GrGLSLVertexBuilder*) override; |
1068 | 1092 |
1069 void onEmitCode(GrGLSLVertexBuilder*, GrGLSLPPFragmentBuilder*, const char*, | 1093 void onEmitCode(GrGLSLVertexBuilder*, GrGLSLPPFragmentBuilder*, const char*, |
1070 const char*) override; | 1094 const char*) override; |
1071 | 1095 |
1072 struct EmitShapeCoords { | 1096 struct EmitShapeCoords { |
1073 const GrGLSLVarying* fVarying; | 1097 const GrGLSLVarying* fVarying; |
1074 const char* fInverseMatrix; | 1098 const char* fInverseMatrix; |
1075 const char* fFragHalfSpan; | 1099 const char* fFragHalfSpan; |
1076 }; | 1100 }; |
1077 | 1101 |
(...skipping 234 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1312 fInnerRRect.vsOut()); | 1336 fInnerRRect.vsOut()); |
1313 } | 1337 } |
1314 } | 1338 } |
1315 | 1339 |
1316 void GLSLInstanceProcessor::BackendMultisample::setupInnerOval(GrGLSLVertexBuild
er* v) { | 1340 void GLSLInstanceProcessor::BackendMultisample::setupInnerOval(GrGLSLVertexBuild
er* v) { |
1317 if (fInnerRRect.vsOut()) { | 1341 if (fInnerRRect.vsOut()) { |
1318 v->codeAppendf("%s = vec4(0, 0, 1, 1);", fInnerRRect.vsOut()); | 1342 v->codeAppendf("%s = vec4(0, 0, 1, 1);", fInnerRRect.vsOut()); |
1319 } | 1343 } |
1320 } | 1344 } |
1321 | 1345 |
1322 void GLSLInstanceProcessor::BackendMultisample::onSetupInnerRRect(GrGLSLVertexBu
ilder* v) { | 1346 void GLSLInstanceProcessor::BackendMultisample::onSetupInnerSimpleRRect(GrGLSLVe
rtexBuilder* v) { |
1323 // Avoid numeric instability by not allowing the inner radii to get smaller
than 1/10th pixel. | 1347 // Avoid numeric instability by not allowing the inner radii to get smaller
than 1/10th pixel. |
1324 if (fFragInnerShapeHalfSpan.vsOut()) { | 1348 if (fFragInnerShapeHalfSpan.vsOut()) { |
1325 v->codeAppendf("innerRadii = max(innerRadii, 2e-1 * %s);", fFragInnerSha
peHalfSpan.vsOut()); | 1349 v->codeAppendf("innerRadii = max(innerRadii, 2e-1 * %s);", fFragInnerSha
peHalfSpan.vsOut()); |
1326 } else { | 1350 } else { |
1327 v->codeAppend ("innerRadii = max(innerRadii, vec2(1e-4));"); | 1351 v->codeAppend ("innerRadii = max(innerRadii, vec2(1e-4));"); |
1328 } | 1352 } |
1329 v->codeAppendf("%s = vec4(1.0 - innerRadii, 1.0 / innerRadii);", fInnerRRect
.vsOut()); | 1353 v->codeAppendf("%s = vec4(1.0 - innerRadii, 1.0 / innerRadii);", fInnerRRect
.vsOut()); |
1330 } | 1354 } |
1331 | 1355 |
1332 void GLSLInstanceProcessor::BackendMultisample::onEmitCode(GrGLSLVertexBuilder*, | 1356 void GLSLInstanceProcessor::BackendMultisample::onEmitCode(GrGLSLVertexBuilder*, |
(...skipping 754 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2087 | 2111 |
2088 case kCorneredRect_FirstIndex: return "basic_round_rect"; | 2112 case kCorneredRect_FirstIndex: return "basic_round_rect"; |
2089 case kCorneredFramedRect_FirstIndex: return "coverage_round_rect"; | 2113 case kCorneredFramedRect_FirstIndex: return "coverage_round_rect"; |
2090 case kCorneredRectFanned_FirstIndex: return "mixed_samples_round_rect"; | 2114 case kCorneredRectFanned_FirstIndex: return "mixed_samples_round_rect"; |
2091 | 2115 |
2092 default: return "unknown"; | 2116 default: return "unknown"; |
2093 } | 2117 } |
2094 } | 2118 } |
2095 | 2119 |
2096 } | 2120 } |
OLD | NEW |