Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(341)

Side by Side Diff: src/gpu/GrDefaultPathRenderer.cpp

Issue 23926019: Stateful PathRenderer implementation (Closed) Base URL: http://skia.googlecode.com/svn/trunk/
Patch Set: add assert & patch for missing AutoPathClear Created 6 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « src/gpu/GrDefaultPathRenderer.h ('k') | src/gpu/GrPathRenderer.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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,
167 const SkStrokeRec& s troke, 166 const SkStrokeRec& s troke,
168 const GrDrawTarget*) const { 167 const GrDrawTarget*) const {
169 if (single_pass_path(path, stroke)) { 168 if (single_pass_path(this->path(), stroke)) {
170 return GrPathRenderer::kNoRestriction_StencilSupport; 169 return GrPathRenderer::kNoRestriction_StencilSupport;
171 } else { 170 } else {
172 return GrPathRenderer::kStencilOnly_StencilSupport; 171 return GrPathRenderer::kStencilOnly_StencilSupport;
173 } 172 }
174 } 173 }
175 174
176 static inline void append_countour_edge_indices(bool hairLine, 175 static inline void append_countour_edge_indices(bool hairLine,
177 uint16_t fanCenterIdx, 176 uint16_t fanCenterIdx,
178 uint16_t edgeV0Idx, 177 uint16_t edgeV0Idx,
179 uint16_t** indices) { 178 uint16_t** indices) {
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after
318 SkASSERT((vert - base) <= maxPts); 317 SkASSERT((vert - base) <= maxPts);
319 SkASSERT((idx - idxBase) <= maxIdxs); 318 SkASSERT((idx - idxBase) <= maxIdxs);
320 319
321 *vertexCnt = static_cast<int>(vert - base); 320 *vertexCnt = static_cast<int>(vert - base);
322 *indexCnt = static_cast<int>(idx - idxBase); 321 *indexCnt = static_cast<int>(idx - idxBase);
323 322
324 } 323 }
325 return true; 324 return true;
326 } 325 }
327 326
328 bool GrDefaultPathRenderer::internalDrawPath(const SkPath& path, 327 bool GrDefaultPathRenderer::internalDrawPath(const SkStrokeRec& origStroke,
329 const SkStrokeRec& origStroke,
330 GrDrawTarget* target, 328 GrDrawTarget* target,
331 bool stencilOnly) { 329 bool stencilOnly) {
332 330
333 SkMatrix viewM = target->getDrawState().getViewMatrix(); 331 SkMatrix viewM = target->getDrawState().getViewMatrix();
334 SkTCopyOnFirstWrite<SkStrokeRec> stroke(origStroke); 332 SkTCopyOnFirstWrite<SkStrokeRec> stroke(origStroke);
335 333
336 SkScalar hairlineCoverage; 334 SkScalar hairlineCoverage;
337 if (IsStrokeHairlineOrEquivalent(*stroke, target->getDrawState().getViewMatr ix(), 335 if (IsStrokeHairlineOrEquivalent(*stroke, target->getDrawState().getViewMatr ix(),
338 &hairlineCoverage)) { 336 &hairlineCoverage)) {
339 uint8_t newCoverage = SkScalarRoundToInt(hairlineCoverage * 337 uint8_t newCoverage = SkScalarRoundToInt(hairlineCoverage *
340 target->getDrawState().getCover age()); 338 target->getDrawState().getCover age());
341 target->drawState()->setCoverage(newCoverage); 339 target->drawState()->setCoverage(newCoverage);
342 340
343 if (!stroke->isHairlineStyle()) { 341 if (!stroke->isHairlineStyle()) {
344 stroke.writable()->setHairlineStyle(); 342 stroke.writable()->setHairlineStyle();
345 } 343 }
346 } 344 }
347 345
348 SkScalar tol = SK_Scalar1; 346 SkScalar tol = SK_Scalar1;
349 tol = GrPathUtils::scaleToleranceToSrc(tol, viewM, path.getBounds()); 347 tol = GrPathUtils::scaleToleranceToSrc(tol, viewM, this->path().getBounds()) ;
350 348
351 int vertexCnt; 349 int vertexCnt;
352 int indexCnt; 350 int indexCnt;
353 GrPrimitiveType primType; 351 GrPrimitiveType primType;
354 GrDrawTarget::AutoReleaseGeometry arg; 352 GrDrawTarget::AutoReleaseGeometry arg;
355 if (!this->createGeom(path, 353 if (!this->createGeom(this->path(),
356 *stroke, 354 *stroke,
357 tol, 355 tol,
358 target, 356 target,
359 &primType, 357 &primType,
360 &vertexCnt, 358 &vertexCnt,
361 &indexCnt, 359 &indexCnt,
362 &arg)) { 360 &arg)) {
363 return false; 361 return false;
364 } 362 }
365 363
(...skipping 13 matching lines...) Expand all
379 if (stroke->isHairlineStyle()) { 377 if (stroke->isHairlineStyle()) {
380 passCount = 1; 378 passCount = 1;
381 if (stencilOnly) { 379 if (stencilOnly) {
382 passes[0] = &gDirectToStencil; 380 passes[0] = &gDirectToStencil;
383 } else { 381 } else {
384 passes[0] = NULL; 382 passes[0] = NULL;
385 } 383 }
386 lastPassIsBounds = false; 384 lastPassIsBounds = false;
387 drawFace[0] = GrDrawState::kBoth_DrawFace; 385 drawFace[0] = GrDrawState::kBoth_DrawFace;
388 } else { 386 } else {
389 if (single_pass_path(path, *stroke)) { 387 if (single_pass_path(this->path(), *stroke)) {
390 passCount = 1; 388 passCount = 1;
391 if (stencilOnly) { 389 if (stencilOnly) {
392 passes[0] = &gDirectToStencil; 390 passes[0] = &gDirectToStencil;
393 } else { 391 } else {
394 passes[0] = NULL; 392 passes[0] = NULL;
395 } 393 }
396 drawFace[0] = GrDrawState::kBoth_DrawFace; 394 drawFace[0] = GrDrawState::kBoth_DrawFace;
397 lastPassIsBounds = false; 395 lastPassIsBounds = false;
398 } else { 396 } else {
399 switch (path.getFillType()) { 397 switch (this->path().getFillType()) {
400 case SkPath::kInverseEvenOdd_FillType: 398 case SkPath::kInverseEvenOdd_FillType:
401 reverse = true; 399 reverse = true;
402 // fallthrough 400 // fallthrough
403 case SkPath::kEvenOdd_FillType: 401 case SkPath::kEvenOdd_FillType:
404 passes[0] = &gEOStencilPass; 402 passes[0] = &gEOStencilPass;
405 if (stencilOnly) { 403 if (stencilOnly) {
406 passCount = 1; 404 passCount = 1;
407 lastPassIsBounds = false; 405 lastPassIsBounds = false;
408 } else { 406 } else {
409 passCount = 2; 407 passCount = 2;
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
456 } 454 }
457 break; 455 break;
458 default: 456 default:
459 SkDEBUGFAIL("Unknown path fFill!"); 457 SkDEBUGFAIL("Unknown path fFill!");
460 return false; 458 return false;
461 } 459 }
462 } 460 }
463 } 461 }
464 462
465 SkRect devBounds; 463 SkRect devBounds;
466 GetPathDevBounds(path, drawState->getRenderTarget(), viewM, &devBounds); 464 GetPathDevBounds(this->path(), drawState->getRenderTarget(), viewM, &devBoun ds);
467 465
468 for (int p = 0; p < passCount; ++p) { 466 for (int p = 0; p < passCount; ++p) {
469 drawState->setDrawFace(drawFace[p]); 467 drawState->setDrawFace(drawFace[p]);
470 if (NULL != passes[p]) { 468 if (NULL != passes[p]) {
471 *drawState->stencil() = *passes[p]; 469 *drawState->stencil() = *passes[p];
472 } 470 }
473 471
474 if (lastPassIsBounds && (p == passCount-1)) { 472 if (lastPassIsBounds && (p == passCount-1)) {
475 if (!colorWritesWereDisabled) { 473 if (!colorWritesWereDisabled) {
476 drawState->disableState(GrDrawState::kNoColorWrites_StateBit); 474 drawState->disableState(GrDrawState::kNoColorWrites_StateBit);
477 } 475 }
478 SkRect bounds; 476 SkRect bounds;
479 GrDrawState::AutoViewMatrixRestore avmr; 477 GrDrawState::AutoViewMatrixRestore avmr;
480 if (reverse) { 478 if (reverse) {
481 SkASSERT(NULL != drawState->getRenderTarget()); 479 SkASSERT(NULL != drawState->getRenderTarget());
482 // draw over the dev bounds (which will be the whole dst surface for inv fill). 480 // draw over the dev bounds (which will be the whole dst surface for inv fill).
483 bounds = devBounds; 481 bounds = devBounds;
484 SkMatrix vmi; 482 SkMatrix vmi;
485 // mapRect through persp matrix may not be correct 483 // mapRect through persp matrix may not be correct
486 if (!drawState->getViewMatrix().hasPerspective() && 484 if (!drawState->getViewMatrix().hasPerspective() &&
487 drawState->getViewInverse(&vmi)) { 485 drawState->getViewInverse(&vmi)) {
488 vmi.mapRect(&bounds); 486 vmi.mapRect(&bounds);
489 } else { 487 } else {
490 avmr.setIdentity(drawState); 488 avmr.setIdentity(drawState);
491 } 489 }
492 } else { 490 } else {
493 bounds = path.getBounds(); 491 bounds = this->path().getBounds();
494 } 492 }
495 GrDrawTarget::AutoGeometryAndStatePush agasp(target, GrDrawTarget::k Preserve_ASRInit); 493 GrDrawTarget::AutoGeometryAndStatePush agasp(target, GrDrawTarget::k Preserve_ASRInit);
496 target->drawSimpleRect(bounds, NULL); 494 target->drawSimpleRect(bounds, NULL);
497 } else { 495 } else {
498 if (passCount > 1) { 496 if (passCount > 1) {
499 drawState->enableState(GrDrawState::kNoColorWrites_StateBit); 497 drawState->enableState(GrDrawState::kNoColorWrites_StateBit);
500 } 498 }
501 if (indexCnt) { 499 if (indexCnt) {
502 target->drawIndexed(primType, 0, 0, 500 target->drawIndexed(primType, 0, 0,
503 vertexCnt, indexCnt, &devBounds); 501 vertexCnt, indexCnt, &devBounds);
504 } else { 502 } else {
505 target->drawNonIndexed(primType, 0, vertexCnt, &devBounds); 503 target->drawNonIndexed(primType, 0, vertexCnt, &devBounds);
506 } 504 }
507 } 505 }
508 } 506 }
509 return true; 507 return true;
510 } 508 }
511 509
512 bool GrDefaultPathRenderer::canDrawPath(const SkPath& path, 510 bool GrDefaultPathRenderer::canDrawPath(const SkStrokeRec& stroke,
513 const SkStrokeRec& stroke,
514 const GrDrawTarget* target, 511 const GrDrawTarget* target,
515 bool antiAlias) const { 512 bool antiAlias) const {
516 // this class can draw any path with any fill but doesn't do any anti-aliasi ng. 513 // this class can draw any path with any fill but doesn't do any anti-aliasi ng.
517 514
518 return !antiAlias && 515 return !antiAlias &&
519 (stroke.isFillStyle() || 516 (stroke.isFillStyle() ||
520 IsStrokeHairlineOrEquivalent(stroke, target->getDrawState().getViewMatr ix(), NULL)); 517 IsStrokeHairlineOrEquivalent(stroke, target->getDrawState().getViewMatr ix(), NULL));
521 } 518 }
522 519
523 bool GrDefaultPathRenderer::onDrawPath(const SkPath& path, 520 bool GrDefaultPathRenderer::onDrawPath(const SkStrokeRec& stroke,
524 const SkStrokeRec& stroke,
525 GrDrawTarget* target, 521 GrDrawTarget* target,
526 bool antiAlias) { 522 bool antiAlias) {
527 return this->internalDrawPath(path, 523 return this->internalDrawPath(stroke, target, false);
528 stroke,
529 target,
530 false);
531 } 524 }
532 525
533 void GrDefaultPathRenderer::onStencilPath(const SkPath& path, 526 void GrDefaultPathRenderer::onStencilPath(const SkStrokeRec& stroke,
534 const SkStrokeRec& stroke,
535 GrDrawTarget* target) { 527 GrDrawTarget* target) {
536 SkASSERT(SkPath::kInverseEvenOdd_FillType != path.getFillType()); 528 SkASSERT(SkPath::kInverseEvenOdd_FillType != this->path().getFillType());
537 SkASSERT(SkPath::kInverseWinding_FillType != path.getFillType()); 529 SkASSERT(SkPath::kInverseWinding_FillType != this->path().getFillType());
538 this->internalDrawPath(path, stroke, target, true); 530 this->internalDrawPath(stroke, target, true);
539 } 531 }
OLDNEW
« no previous file with comments | « src/gpu/GrDefaultPathRenderer.h ('k') | src/gpu/GrPathRenderer.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698