OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2011 Google Inc. | 2 * Copyright 2011 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 "GrDefaultPathRenderer.h" | 8 #include "GrDefaultPathRenderer.h" |
9 | 9 |
10 #include "GrContext.h" | 10 #include "GrContext.h" |
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
156 return true; | 156 return true; |
157 #else | 157 #else |
158 if (!stroke.isHairlineStyle() && !path.isInverseFillType()) { | 158 if (!stroke.isHairlineStyle() && !path.isInverseFillType()) { |
159 return path.isConvex(); | 159 return path.isConvex(); |
160 } | 160 } |
161 return false; | 161 return false; |
162 #endif | 162 #endif |
163 } | 163 } |
164 | 164 |
165 GrPathRenderer::StencilSupport GrDefaultPathRenderer::onGetStencilSupport( | 165 GrPathRenderer::StencilSupport GrDefaultPathRenderer::onGetStencilSupport( |
| 166 const SkPath& path, |
166 const SkStrokeRec& s
troke, | 167 const SkStrokeRec& s
troke, |
167 const GrDrawTarget*)
const { | 168 const GrDrawTarget*)
const { |
168 if (single_pass_path(this->path(), stroke)) { | 169 if (single_pass_path(path, stroke)) { |
169 return GrPathRenderer::kNoRestriction_StencilSupport; | 170 return GrPathRenderer::kNoRestriction_StencilSupport; |
170 } else { | 171 } else { |
171 return GrPathRenderer::kStencilOnly_StencilSupport; | 172 return GrPathRenderer::kStencilOnly_StencilSupport; |
172 } | 173 } |
173 } | 174 } |
174 | 175 |
175 static inline void append_countour_edge_indices(bool hairLine, | 176 static inline void append_countour_edge_indices(bool hairLine, |
176 uint16_t fanCenterIdx, | 177 uint16_t fanCenterIdx, |
177 uint16_t edgeV0Idx, | 178 uint16_t edgeV0Idx, |
178 uint16_t** indices) { | 179 uint16_t** indices) { |
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
317 SkASSERT((vert - base) <= maxPts); | 318 SkASSERT((vert - base) <= maxPts); |
318 SkASSERT((idx - idxBase) <= maxIdxs); | 319 SkASSERT((idx - idxBase) <= maxIdxs); |
319 | 320 |
320 *vertexCnt = static_cast<int>(vert - base); | 321 *vertexCnt = static_cast<int>(vert - base); |
321 *indexCnt = static_cast<int>(idx - idxBase); | 322 *indexCnt = static_cast<int>(idx - idxBase); |
322 | 323 |
323 } | 324 } |
324 return true; | 325 return true; |
325 } | 326 } |
326 | 327 |
327 bool GrDefaultPathRenderer::internalDrawPath(const SkStrokeRec& origStroke, | 328 bool GrDefaultPathRenderer::internalDrawPath(const SkPath& path, |
| 329 const SkStrokeRec& origStroke, |
328 GrDrawTarget* target, | 330 GrDrawTarget* target, |
329 bool stencilOnly) { | 331 bool stencilOnly) { |
330 | 332 |
331 SkMatrix viewM = target->getDrawState().getViewMatrix(); | 333 SkMatrix viewM = target->getDrawState().getViewMatrix(); |
332 SkTCopyOnFirstWrite<SkStrokeRec> stroke(origStroke); | 334 SkTCopyOnFirstWrite<SkStrokeRec> stroke(origStroke); |
333 | 335 |
334 SkScalar hairlineCoverage; | 336 SkScalar hairlineCoverage; |
335 if (IsStrokeHairlineOrEquivalent(*stroke, target->getDrawState().getViewMatr
ix(), | 337 if (IsStrokeHairlineOrEquivalent(*stroke, target->getDrawState().getViewMatr
ix(), |
336 &hairlineCoverage)) { | 338 &hairlineCoverage)) { |
337 uint8_t newCoverage = SkScalarRoundToInt(hairlineCoverage * | 339 uint8_t newCoverage = SkScalarRoundToInt(hairlineCoverage * |
338 target->getDrawState().getCover
age()); | 340 target->getDrawState().getCover
age()); |
339 target->drawState()->setCoverage(newCoverage); | 341 target->drawState()->setCoverage(newCoverage); |
340 | 342 |
341 if (!stroke->isHairlineStyle()) { | 343 if (!stroke->isHairlineStyle()) { |
342 stroke.writable()->setHairlineStyle(); | 344 stroke.writable()->setHairlineStyle(); |
343 } | 345 } |
344 } | 346 } |
345 | 347 |
346 SkScalar tol = SK_Scalar1; | 348 SkScalar tol = SK_Scalar1; |
347 tol = GrPathUtils::scaleToleranceToSrc(tol, viewM, this->path().getBounds())
; | 349 tol = GrPathUtils::scaleToleranceToSrc(tol, viewM, path.getBounds()); |
348 | 350 |
349 int vertexCnt; | 351 int vertexCnt; |
350 int indexCnt; | 352 int indexCnt; |
351 GrPrimitiveType primType; | 353 GrPrimitiveType primType; |
352 GrDrawTarget::AutoReleaseGeometry arg; | 354 GrDrawTarget::AutoReleaseGeometry arg; |
353 if (!this->createGeom(this->path(), | 355 if (!this->createGeom(path, |
354 *stroke, | 356 *stroke, |
355 tol, | 357 tol, |
356 target, | 358 target, |
357 &primType, | 359 &primType, |
358 &vertexCnt, | 360 &vertexCnt, |
359 &indexCnt, | 361 &indexCnt, |
360 &arg)) { | 362 &arg)) { |
361 return false; | 363 return false; |
362 } | 364 } |
363 | 365 |
(...skipping 13 matching lines...) Expand all Loading... |
377 if (stroke->isHairlineStyle()) { | 379 if (stroke->isHairlineStyle()) { |
378 passCount = 1; | 380 passCount = 1; |
379 if (stencilOnly) { | 381 if (stencilOnly) { |
380 passes[0] = &gDirectToStencil; | 382 passes[0] = &gDirectToStencil; |
381 } else { | 383 } else { |
382 passes[0] = NULL; | 384 passes[0] = NULL; |
383 } | 385 } |
384 lastPassIsBounds = false; | 386 lastPassIsBounds = false; |
385 drawFace[0] = GrDrawState::kBoth_DrawFace; | 387 drawFace[0] = GrDrawState::kBoth_DrawFace; |
386 } else { | 388 } else { |
387 if (single_pass_path(this->path(), *stroke)) { | 389 if (single_pass_path(path, *stroke)) { |
388 passCount = 1; | 390 passCount = 1; |
389 if (stencilOnly) { | 391 if (stencilOnly) { |
390 passes[0] = &gDirectToStencil; | 392 passes[0] = &gDirectToStencil; |
391 } else { | 393 } else { |
392 passes[0] = NULL; | 394 passes[0] = NULL; |
393 } | 395 } |
394 drawFace[0] = GrDrawState::kBoth_DrawFace; | 396 drawFace[0] = GrDrawState::kBoth_DrawFace; |
395 lastPassIsBounds = false; | 397 lastPassIsBounds = false; |
396 } else { | 398 } else { |
397 switch (this->path().getFillType()) { | 399 switch (path.getFillType()) { |
398 case SkPath::kInverseEvenOdd_FillType: | 400 case SkPath::kInverseEvenOdd_FillType: |
399 reverse = true; | 401 reverse = true; |
400 // fallthrough | 402 // fallthrough |
401 case SkPath::kEvenOdd_FillType: | 403 case SkPath::kEvenOdd_FillType: |
402 passes[0] = &gEOStencilPass; | 404 passes[0] = &gEOStencilPass; |
403 if (stencilOnly) { | 405 if (stencilOnly) { |
404 passCount = 1; | 406 passCount = 1; |
405 lastPassIsBounds = false; | 407 lastPassIsBounds = false; |
406 } else { | 408 } else { |
407 passCount = 2; | 409 passCount = 2; |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
454 } | 456 } |
455 break; | 457 break; |
456 default: | 458 default: |
457 SkDEBUGFAIL("Unknown path fFill!"); | 459 SkDEBUGFAIL("Unknown path fFill!"); |
458 return false; | 460 return false; |
459 } | 461 } |
460 } | 462 } |
461 } | 463 } |
462 | 464 |
463 SkRect devBounds; | 465 SkRect devBounds; |
464 GetPathDevBounds(this->path(), drawState->getRenderTarget(), viewM, &devBoun
ds); | 466 GetPathDevBounds(path, drawState->getRenderTarget(), viewM, &devBounds); |
465 | 467 |
466 for (int p = 0; p < passCount; ++p) { | 468 for (int p = 0; p < passCount; ++p) { |
467 drawState->setDrawFace(drawFace[p]); | 469 drawState->setDrawFace(drawFace[p]); |
468 if (NULL != passes[p]) { | 470 if (NULL != passes[p]) { |
469 *drawState->stencil() = *passes[p]; | 471 *drawState->stencil() = *passes[p]; |
470 } | 472 } |
471 | 473 |
472 if (lastPassIsBounds && (p == passCount-1)) { | 474 if (lastPassIsBounds && (p == passCount-1)) { |
473 if (!colorWritesWereDisabled) { | 475 if (!colorWritesWereDisabled) { |
474 drawState->disableState(GrDrawState::kNoColorWrites_StateBit); | 476 drawState->disableState(GrDrawState::kNoColorWrites_StateBit); |
475 } | 477 } |
476 SkRect bounds; | 478 SkRect bounds; |
477 GrDrawState::AutoViewMatrixRestore avmr; | 479 GrDrawState::AutoViewMatrixRestore avmr; |
478 if (reverse) { | 480 if (reverse) { |
479 SkASSERT(NULL != drawState->getRenderTarget()); | 481 SkASSERT(NULL != drawState->getRenderTarget()); |
480 // draw over the dev bounds (which will be the whole dst surface
for inv fill). | 482 // draw over the dev bounds (which will be the whole dst surface
for inv fill). |
481 bounds = devBounds; | 483 bounds = devBounds; |
482 SkMatrix vmi; | 484 SkMatrix vmi; |
483 // mapRect through persp matrix may not be correct | 485 // mapRect through persp matrix may not be correct |
484 if (!drawState->getViewMatrix().hasPerspective() && | 486 if (!drawState->getViewMatrix().hasPerspective() && |
485 drawState->getViewInverse(&vmi)) { | 487 drawState->getViewInverse(&vmi)) { |
486 vmi.mapRect(&bounds); | 488 vmi.mapRect(&bounds); |
487 } else { | 489 } else { |
488 avmr.setIdentity(drawState); | 490 avmr.setIdentity(drawState); |
489 } | 491 } |
490 } else { | 492 } else { |
491 bounds = this->path().getBounds(); | 493 bounds = path.getBounds(); |
492 } | 494 } |
493 GrDrawTarget::AutoGeometryAndStatePush agasp(target, GrDrawTarget::k
Preserve_ASRInit); | 495 GrDrawTarget::AutoGeometryAndStatePush agasp(target, GrDrawTarget::k
Preserve_ASRInit); |
494 target->drawSimpleRect(bounds, NULL); | 496 target->drawSimpleRect(bounds, NULL); |
495 } else { | 497 } else { |
496 if (passCount > 1) { | 498 if (passCount > 1) { |
497 drawState->enableState(GrDrawState::kNoColorWrites_StateBit); | 499 drawState->enableState(GrDrawState::kNoColorWrites_StateBit); |
498 } | 500 } |
499 if (indexCnt) { | 501 if (indexCnt) { |
500 target->drawIndexed(primType, 0, 0, | 502 target->drawIndexed(primType, 0, 0, |
501 vertexCnt, indexCnt, &devBounds); | 503 vertexCnt, indexCnt, &devBounds); |
502 } else { | 504 } else { |
503 target->drawNonIndexed(primType, 0, vertexCnt, &devBounds); | 505 target->drawNonIndexed(primType, 0, vertexCnt, &devBounds); |
504 } | 506 } |
505 } | 507 } |
506 } | 508 } |
507 return true; | 509 return true; |
508 } | 510 } |
509 | 511 |
510 bool GrDefaultPathRenderer::canDrawPath(const SkStrokeRec& stroke, | 512 bool GrDefaultPathRenderer::canDrawPath(const SkPath& path, |
| 513 const SkStrokeRec& stroke, |
511 const GrDrawTarget* target, | 514 const GrDrawTarget* target, |
512 bool antiAlias) const { | 515 bool antiAlias) const { |
513 // this class can draw any path with any fill but doesn't do any anti-aliasi
ng. | 516 // this class can draw any path with any fill but doesn't do any anti-aliasi
ng. |
514 | 517 |
515 return !antiAlias && | 518 return !antiAlias && |
516 (stroke.isFillStyle() || | 519 (stroke.isFillStyle() || |
517 IsStrokeHairlineOrEquivalent(stroke, target->getDrawState().getViewMatr
ix(), NULL)); | 520 IsStrokeHairlineOrEquivalent(stroke, target->getDrawState().getViewMatr
ix(), NULL)); |
518 } | 521 } |
519 | 522 |
520 bool GrDefaultPathRenderer::onDrawPath(const SkStrokeRec& stroke, | 523 bool GrDefaultPathRenderer::onDrawPath(const SkPath& path, |
| 524 const SkStrokeRec& stroke, |
521 GrDrawTarget* target, | 525 GrDrawTarget* target, |
522 bool antiAlias) { | 526 bool antiAlias) { |
523 return this->internalDrawPath(stroke, target, false); | 527 return this->internalDrawPath(path, |
| 528 stroke, |
| 529 target, |
| 530 false); |
524 } | 531 } |
525 | 532 |
526 void GrDefaultPathRenderer::onStencilPath(const SkStrokeRec& stroke, | 533 void GrDefaultPathRenderer::onStencilPath(const SkPath& path, |
| 534 const SkStrokeRec& stroke, |
527 GrDrawTarget* target) { | 535 GrDrawTarget* target) { |
528 SkASSERT(SkPath::kInverseEvenOdd_FillType != this->path().getFillType()); | 536 SkASSERT(SkPath::kInverseEvenOdd_FillType != path.getFillType()); |
529 SkASSERT(SkPath::kInverseWinding_FillType != this->path().getFillType()); | 537 SkASSERT(SkPath::kInverseWinding_FillType != path.getFillType()); |
530 this->internalDrawPath(stroke, target, true); | 538 this->internalDrawPath(path, stroke, target, true); |
531 } | 539 } |
OLD | NEW |