| 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 215 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 226 } | 226 } |
| 227 } else { | 227 } else { |
| 228 if (indexed) { | 228 if (indexed) { |
| 229 maxIdxs = 3 * maxPts; | 229 maxIdxs = 3 * maxPts; |
| 230 *primType = kTriangles_GrPrimitiveType; | 230 *primType = kTriangles_GrPrimitiveType; |
| 231 } else { | 231 } else { |
| 232 *primType = kTriangleFan_GrPrimitiveType; | 232 *primType = kTriangleFan_GrPrimitiveType; |
| 233 } | 233 } |
| 234 } | 234 } |
| 235 | 235 |
| 236 // TODO this is really wierd, I just need default vertex stride, can I think
of a better way? | 236 if (!arg->set(target, maxPts, GrDefaultGeoProcFactory::DefaultVertexStride()
, maxIdxs)) { |
| 237 SkAutoTUnref<const GrGeometryProcessor> gp(GrDefaultGeoProcFactory::Create()
); | |
| 238 if (!arg->set(target, maxPts, gp->getVertexStride(), maxIdxs)) { | |
| 239 return false; | 237 return false; |
| 240 } | 238 } |
| 241 SkASSERT(gp->getVertexStride() == sizeof(SkPoint)); | 239 SkASSERT(GrDefaultGeoProcFactory::DefaultVertexStride() == sizeof(SkPoint)); |
| 242 | 240 |
| 243 uint16_t* idxBase = reinterpret_cast<uint16_t*>(arg->indices()); | 241 uint16_t* idxBase = reinterpret_cast<uint16_t*>(arg->indices()); |
| 244 uint16_t* idx = idxBase; | 242 uint16_t* idx = idxBase; |
| 245 uint16_t subpathIdxStart = 0; | 243 uint16_t subpathIdxStart = 0; |
| 246 | 244 |
| 247 SkPoint* base = reinterpret_cast<SkPoint*>(arg->vertices()); | 245 SkPoint* base = reinterpret_cast<SkPoint*>(arg->vertices()); |
| 248 SkASSERT(base); | 246 SkASSERT(base); |
| 249 SkPoint* vert = base; | 247 SkPoint* vert = base; |
| 250 | 248 |
| 251 SkPoint pts[4]; | 249 SkPoint pts[4]; |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 323 | 321 |
| 324 *vertexCnt = static_cast<int>(vert - base); | 322 *vertexCnt = static_cast<int>(vert - base); |
| 325 *indexCnt = static_cast<int>(idx - idxBase); | 323 *indexCnt = static_cast<int>(idx - idxBase); |
| 326 | 324 |
| 327 } | 325 } |
| 328 return true; | 326 return true; |
| 329 } | 327 } |
| 330 | 328 |
| 331 bool GrDefaultPathRenderer::internalDrawPath(GrDrawTarget* target, | 329 bool GrDefaultPathRenderer::internalDrawPath(GrDrawTarget* target, |
| 332 GrDrawState* drawState, | 330 GrDrawState* drawState, |
| 331 GrColor color, |
| 333 const SkPath& path, | 332 const SkPath& path, |
| 334 const SkStrokeRec& origStroke, | 333 const SkStrokeRec& origStroke, |
| 335 bool stencilOnly) { | 334 bool stencilOnly) { |
| 336 SkMatrix viewM = drawState->getViewMatrix(); | 335 SkMatrix viewM = drawState->getViewMatrix(); |
| 337 SkTCopyOnFirstWrite<SkStrokeRec> stroke(origStroke); | 336 SkTCopyOnFirstWrite<SkStrokeRec> stroke(origStroke); |
| 338 | 337 |
| 339 SkScalar hairlineCoverage; | 338 SkScalar hairlineCoverage; |
| 339 uint8_t newCoverage = 0xff; |
| 340 if (IsStrokeHairlineOrEquivalent(*stroke, drawState->getViewMatrix(), | 340 if (IsStrokeHairlineOrEquivalent(*stroke, drawState->getViewMatrix(), |
| 341 &hairlineCoverage)) { | 341 &hairlineCoverage)) { |
| 342 uint8_t newCoverage = SkScalarRoundToInt(hairlineCoverage * drawState->g
etCoverage()); | 342 newCoverage = SkScalarRoundToInt(hairlineCoverage * 0xff); |
| 343 drawState->setCoverage(newCoverage); | |
| 344 | 343 |
| 345 if (!stroke->isHairlineStyle()) { | 344 if (!stroke->isHairlineStyle()) { |
| 346 stroke.writable()->setHairlineStyle(); | 345 stroke.writable()->setHairlineStyle(); |
| 347 } | 346 } |
| 348 } | 347 } |
| 349 | 348 |
| 350 SkScalar tol = SK_Scalar1; | 349 SkScalar tol = SK_Scalar1; |
| 351 tol = GrPathUtils::scaleToleranceToSrc(tol, viewM, path.getBounds()); | 350 tol = GrPathUtils::scaleToleranceToSrc(tol, viewM, path.getBounds()); |
| 352 | 351 |
| 353 int vertexCnt; | 352 int vertexCnt; |
| (...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 486 if (!drawState->getViewMatrix().hasPerspective() && | 485 if (!drawState->getViewMatrix().hasPerspective() && |
| 487 drawState->getViewInverse(&vmi)) { | 486 drawState->getViewInverse(&vmi)) { |
| 488 vmi.mapRect(&bounds); | 487 vmi.mapRect(&bounds); |
| 489 } else { | 488 } else { |
| 490 avmr.setIdentity(drawState); | 489 avmr.setIdentity(drawState); |
| 491 } | 490 } |
| 492 } else { | 491 } else { |
| 493 bounds = path.getBounds(); | 492 bounds = path.getBounds(); |
| 494 } | 493 } |
| 495 GrDrawTarget::AutoGeometryPush agp(target); | 494 GrDrawTarget::AutoGeometryPush agp(target); |
| 496 target->drawSimpleRect(drawState, bounds); | 495 target->drawSimpleRect(drawState, color, bounds); |
| 497 } else { | 496 } else { |
| 498 if (passCount > 1) { | 497 if (passCount > 1) { |
| 499 drawState->enableState(GrDrawState::kNoColorWrites_StateBit); | 498 drawState->enableState(GrDrawState::kNoColorWrites_StateBit); |
| 500 } | 499 } |
| 501 GrDrawState::AutoRestoreEffects are(drawState); | 500 GrDrawState::AutoRestoreEffects are(drawState); |
| 502 drawState->setGeometryProcessor(GrDefaultGeoProcFactory::Create())->
unref(); | 501 drawState->setGeometryProcessor( |
| 502 GrDefaultGeoProcFactory::Create(color, |
| 503 GrDefaultGeoProcFactory::kPo
sition_GPType, |
| 504 newCoverage))->unref(); |
| 503 if (indexCnt) { | 505 if (indexCnt) { |
| 504 target->drawIndexed(drawState, | 506 target->drawIndexed(drawState, |
| 505 primType, | 507 primType, |
| 506 0, | 508 0, |
| 507 0, | 509 0, |
| 508 vertexCnt, | 510 vertexCnt, |
| 509 indexCnt, | 511 indexCnt, |
| 510 &devBounds); | 512 &devBounds); |
| 511 } else { | 513 } else { |
| 512 target->drawNonIndexed(drawState, primType, 0, vertexCnt, &devBo
unds); | 514 target->drawNonIndexed(drawState, primType, 0, vertexCnt, &devBo
unds); |
| (...skipping 10 matching lines...) Expand all Loading... |
| 523 bool antiAlias) const { | 525 bool antiAlias) const { |
| 524 // this class can draw any path with any fill but doesn't do any anti-aliasi
ng. | 526 // this class can draw any path with any fill but doesn't do any anti-aliasi
ng. |
| 525 | 527 |
| 526 return !antiAlias && !(SkPath::kConic_SegmentMask & path.getSegmentMasks())
&& | 528 return !antiAlias && !(SkPath::kConic_SegmentMask & path.getSegmentMasks())
&& |
| 527 (stroke.isFillStyle() || | 529 (stroke.isFillStyle() || |
| 528 IsStrokeHairlineOrEquivalent(stroke, drawState->getViewMatrix(), NULL))
; | 530 IsStrokeHairlineOrEquivalent(stroke, drawState->getViewMatrix(), NULL))
; |
| 529 } | 531 } |
| 530 | 532 |
| 531 bool GrDefaultPathRenderer::onDrawPath(GrDrawTarget* target, | 533 bool GrDefaultPathRenderer::onDrawPath(GrDrawTarget* target, |
| 532 GrDrawState* drawState, | 534 GrDrawState* drawState, |
| 535 GrColor color, |
| 533 const SkPath& path, | 536 const SkPath& path, |
| 534 const SkStrokeRec& stroke, | 537 const SkStrokeRec& stroke, |
| 535 bool antiAlias) { | 538 bool antiAlias) { |
| 536 return this->internalDrawPath(target, | 539 return this->internalDrawPath(target, |
| 537 drawState, | 540 drawState, |
| 541 color, |
| 538 path, | 542 path, |
| 539 stroke, | 543 stroke, |
| 540 false); | 544 false); |
| 541 } | 545 } |
| 542 | 546 |
| 543 void GrDefaultPathRenderer::onStencilPath(GrDrawTarget* target, | 547 void GrDefaultPathRenderer::onStencilPath(GrDrawTarget* target, |
| 544 GrDrawState* drawState, | 548 GrDrawState* drawState, |
| 545 const SkPath& path, | 549 const SkPath& path, |
| 546 const SkStrokeRec& stroke) { | 550 const SkStrokeRec& stroke) { |
| 547 SkASSERT(SkPath::kInverseEvenOdd_FillType != path.getFillType()); | 551 SkASSERT(SkPath::kInverseEvenOdd_FillType != path.getFillType()); |
| 548 SkASSERT(SkPath::kInverseWinding_FillType != path.getFillType()); | 552 SkASSERT(SkPath::kInverseWinding_FillType != path.getFillType()); |
| 549 this->internalDrawPath(target, drawState, path, stroke, true); | 553 this->internalDrawPath(target, drawState, GrColor_WHITE, path, stroke, true)
; |
| 550 } | 554 } |
| OLD | NEW |