OLD | NEW |
1 | 1 |
2 /* | 2 /* |
3 * Copyright 2010 Google Inc. | 3 * Copyright 2010 Google Inc. |
4 * | 4 * |
5 * Use of this source code is governed by a BSD-style license that can be | 5 * Use of this source code is governed by a BSD-style license that can be |
6 * found in the LICENSE file. | 6 * found in the LICENSE file. |
7 */ | 7 */ |
8 | 8 |
9 | 9 |
10 | 10 |
(...skipping 289 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
300 | 300 |
301 this->geometrySourceWillPop(fGeoSrcStateStack.fromBack(1)); | 301 this->geometrySourceWillPop(fGeoSrcStateStack.fromBack(1)); |
302 this->releasePreviousVertexSource(); | 302 this->releasePreviousVertexSource(); |
303 this->releasePreviousIndexSource(); | 303 this->releasePreviousIndexSource(); |
304 fGeoSrcStateStack.pop_back(); | 304 fGeoSrcStateStack.pop_back(); |
305 } | 305 } |
306 | 306 |
307 //////////////////////////////////////////////////////////////////////////////// | 307 //////////////////////////////////////////////////////////////////////////////// |
308 | 308 |
309 bool GrDrawTarget::checkDraw(const GrDrawState& drawState, | 309 bool GrDrawTarget::checkDraw(const GrDrawState& drawState, |
| 310 const GrGeometryProcessor* gp, |
310 GrPrimitiveType type, | 311 GrPrimitiveType type, |
311 int startVertex, | 312 int startVertex, |
312 int startIndex, | 313 int startIndex, |
313 int vertexCount, | 314 int vertexCount, |
314 int indexCount) const { | 315 int indexCount) const { |
315 #ifdef SK_DEBUG | 316 #ifdef SK_DEBUG |
316 const GeometrySrcState& geoSrc = fGeoSrcStateStack.back(); | 317 const GeometrySrcState& geoSrc = fGeoSrcStateStack.back(); |
317 int maxVertex = startVertex + vertexCount; | 318 int maxVertex = startVertex + vertexCount; |
318 int maxValidVertex; | 319 int maxValidVertex; |
319 switch (geoSrc.fVertexSrc) { | 320 switch (geoSrc.fVertexSrc) { |
(...skipping 22 matching lines...) Expand all Loading... |
342 maxValidIndex = static_cast<int>(geoSrc.fIndexBuffer->gpuMemoryS
ize() / sizeof(uint16_t)); | 343 maxValidIndex = static_cast<int>(geoSrc.fIndexBuffer->gpuMemoryS
ize() / sizeof(uint16_t)); |
343 break; | 344 break; |
344 } | 345 } |
345 if (maxIndex > maxValidIndex) { | 346 if (maxIndex > maxValidIndex) { |
346 SkFAIL("Index reads outside valid index range."); | 347 SkFAIL("Index reads outside valid index range."); |
347 } | 348 } |
348 } | 349 } |
349 | 350 |
350 SkASSERT(drawState.getRenderTarget()); | 351 SkASSERT(drawState.getRenderTarget()); |
351 | 352 |
352 if (drawState.hasGeometryProcessor()) { | 353 if (gp) { |
353 const GrGeometryProcessor* gp = drawState.getGeometryProcessor(); | |
354 int numTextures = gp->numTextures(); | 354 int numTextures = gp->numTextures(); |
355 for (int t = 0; t < numTextures; ++t) { | 355 for (int t = 0; t < numTextures; ++t) { |
356 GrTexture* texture = gp->texture(t); | 356 GrTexture* texture = gp->texture(t); |
357 SkASSERT(texture->asRenderTarget() != drawState.getRenderTarget()); | 357 SkASSERT(texture->asRenderTarget() != drawState.getRenderTarget()); |
358 } | 358 } |
359 } | 359 } |
360 | 360 |
361 for (int s = 0; s < drawState.numColorStages(); ++s) { | 361 for (int s = 0; s < drawState.numColorStages(); ++s) { |
362 const GrProcessor* effect = drawState.getColorStage(s).getProcessor(); | 362 const GrProcessor* effect = drawState.getColorStage(s).getProcessor(); |
363 int numTextures = effect->numTextures(); | 363 int numTextures = effect->numTextures(); |
(...skipping 12 matching lines...) Expand all Loading... |
376 } | 376 } |
377 | 377 |
378 #endif | 378 #endif |
379 if (NULL == drawState.getRenderTarget()) { | 379 if (NULL == drawState.getRenderTarget()) { |
380 return false; | 380 return false; |
381 } | 381 } |
382 return true; | 382 return true; |
383 } | 383 } |
384 | 384 |
385 bool GrDrawTarget::setupDstReadIfNecessary(GrDrawState* ds, | 385 bool GrDrawTarget::setupDstReadIfNecessary(GrDrawState* ds, |
| 386 const GrPrimitiveProcessor* pp, |
386 GrColor color, | 387 GrColor color, |
387 uint8_t coverage, | 388 uint8_t coverage, |
388 GrDeviceCoordTexture* dstCopy, | 389 GrDeviceCoordTexture* dstCopy, |
389 const SkRect* drawBounds) { | 390 const SkRect* drawBounds) { |
390 GrColor c = GrColorPackRGBA(coverage, coverage, coverage, coverage); | 391 GrColor c = GrColorPackRGBA(coverage, coverage, coverage, coverage); |
391 if (this->caps()->dstReadInShaderSupport() || !ds->willEffectReadDstColor(co
lor, c)) { | 392 if (this->caps()->dstReadInShaderSupport() || !ds->willEffectReadDstColor(pp
, color, c)) { |
392 return true; | 393 return true; |
393 } | 394 } |
394 SkIRect copyRect; | 395 SkIRect copyRect; |
395 const GrClipData* clip = this->getClip(); | 396 const GrClipData* clip = this->getClip(); |
396 GrRenderTarget* rt = ds->getRenderTarget(); | 397 GrRenderTarget* rt = ds->getRenderTarget(); |
397 clip->getConservativeBounds(rt, ©Rect); | 398 clip->getConservativeBounds(rt, ©Rect); |
398 | 399 |
399 if (drawBounds) { | 400 if (drawBounds) { |
400 SkIRect drawIBounds; | 401 SkIRect drawIBounds; |
401 drawBounds->roundOut(&drawIBounds); | 402 drawBounds->roundOut(&drawIBounds); |
(...skipping 27 matching lines...) Expand all Loading... |
429 if (this->copySurface(copy, rt, copyRect, dstPoint)) { | 430 if (this->copySurface(copy, rt, copyRect, dstPoint)) { |
430 dstCopy->setTexture(copy); | 431 dstCopy->setTexture(copy); |
431 dstCopy->setOffset(copyRect.fLeft, copyRect.fTop); | 432 dstCopy->setOffset(copyRect.fLeft, copyRect.fTop); |
432 return true; | 433 return true; |
433 } else { | 434 } else { |
434 return false; | 435 return false; |
435 } | 436 } |
436 } | 437 } |
437 | 438 |
438 void GrDrawTarget::drawIndexed(GrDrawState* ds, | 439 void GrDrawTarget::drawIndexed(GrDrawState* ds, |
| 440 const GrGeometryProcessor* gp, |
439 GrPrimitiveType type, | 441 GrPrimitiveType type, |
440 int startVertex, | 442 int startVertex, |
441 int startIndex, | 443 int startIndex, |
442 int vertexCount, | 444 int vertexCount, |
443 int indexCount, | 445 int indexCount, |
444 const SkRect* devBounds) { | 446 const SkRect* devBounds) { |
445 SkASSERT(ds); | 447 SkASSERT(ds); |
446 if (indexCount > 0 && | 448 if (indexCount > 0 && |
447 this->checkDraw(*ds, type, startVertex, startIndex, vertexCount, indexCo
unt)) { | 449 this->checkDraw(*ds, gp, type, startVertex, startIndex, vertexCount, ind
exCount)) { |
448 | 450 |
449 // Setup clip | 451 // Setup clip |
450 GrClipMaskManager::ScissorState scissorState; | 452 GrClipMaskManager::ScissorState scissorState; |
451 GrDrawState::AutoRestoreEffects are; | 453 GrDrawState::AutoRestoreEffects are; |
452 GrDrawState::AutoRestoreStencil ars; | 454 GrDrawState::AutoRestoreStencil ars; |
453 if (!this->setupClip(devBounds, &are, &ars, ds, &scissorState)) { | 455 if (!this->setupClip(devBounds, &are, &ars, ds, &scissorState)) { |
454 return; | 456 return; |
455 } | 457 } |
456 | 458 |
457 DrawInfo info; | 459 DrawInfo info; |
458 info.fPrimitiveType = type; | 460 info.fPrimitiveType = type; |
459 info.fStartVertex = startVertex; | 461 info.fStartVertex = startVertex; |
460 info.fStartIndex = startIndex; | 462 info.fStartIndex = startIndex; |
461 info.fVertexCount = vertexCount; | 463 info.fVertexCount = vertexCount; |
462 info.fIndexCount = indexCount; | 464 info.fIndexCount = indexCount; |
463 | 465 |
464 info.fInstanceCount = 0; | 466 info.fInstanceCount = 0; |
465 info.fVerticesPerInstance = 0; | 467 info.fVerticesPerInstance = 0; |
466 info.fIndicesPerInstance = 0; | 468 info.fIndicesPerInstance = 0; |
467 | 469 |
468 if (devBounds) { | 470 if (devBounds) { |
469 info.setDevBounds(*devBounds); | 471 info.setDevBounds(*devBounds); |
470 } | 472 } |
471 | 473 |
472 // TODO: We should continue with incorrect blending. | 474 // TODO: We should continue with incorrect blending. |
473 GrDeviceCoordTexture dstCopy; | 475 GrDeviceCoordTexture dstCopy; |
474 const GrGeometryProcessor* gp = ds->getGeometryProcessor(); | 476 if (!this->setupDstReadIfNecessary(ds, gp, gp->getColor(), gp->getCovera
ge(), &dstCopy, |
475 if (!this->setupDstReadIfNecessary(ds, gp->getColor(), gp->getCoverage()
, &dstCopy, | |
476 devBounds)) { | 477 devBounds)) { |
477 return; | 478 return; |
478 } | 479 } |
479 this->setDrawBuffers(&info, gp->getVertexStride()); | 480 this->setDrawBuffers(&info, gp->getVertexStride()); |
480 | 481 |
481 this->onDraw(*ds, info, scissorState, dstCopy.texture() ? &dstCopy : NUL
L); | 482 this->onDraw(*ds, gp, info, scissorState, dstCopy.texture() ? &dstCopy :
NULL); |
482 } | 483 } |
483 } | 484 } |
484 | 485 |
485 void GrDrawTarget::drawNonIndexed(GrDrawState* ds, | 486 void GrDrawTarget::drawNonIndexed(GrDrawState* ds, |
| 487 const GrGeometryProcessor* gp, |
486 GrPrimitiveType type, | 488 GrPrimitiveType type, |
487 int startVertex, | 489 int startVertex, |
488 int vertexCount, | 490 int vertexCount, |
489 const SkRect* devBounds) { | 491 const SkRect* devBounds) { |
490 SkASSERT(ds); | 492 SkASSERT(ds); |
491 if (vertexCount > 0 && this->checkDraw(*ds, type, startVertex, -1, vertexCou
nt, -1)) { | 493 if (vertexCount > 0 && this->checkDraw(*ds, gp, type, startVertex, -1, verte
xCount, -1)) { |
492 | 494 |
493 // Setup clip | 495 // Setup clip |
494 GrClipMaskManager::ScissorState scissorState; | 496 GrClipMaskManager::ScissorState scissorState; |
495 GrDrawState::AutoRestoreEffects are; | 497 GrDrawState::AutoRestoreEffects are; |
496 GrDrawState::AutoRestoreStencil ars; | 498 GrDrawState::AutoRestoreStencil ars; |
497 if (!this->setupClip(devBounds, &are, &ars, ds, &scissorState)) { | 499 if (!this->setupClip(devBounds, &are, &ars, ds, &scissorState)) { |
498 return; | 500 return; |
499 } | 501 } |
500 | 502 |
501 DrawInfo info; | 503 DrawInfo info; |
502 info.fPrimitiveType = type; | 504 info.fPrimitiveType = type; |
503 info.fStartVertex = startVertex; | 505 info.fStartVertex = startVertex; |
504 info.fStartIndex = 0; | 506 info.fStartIndex = 0; |
505 info.fVertexCount = vertexCount; | 507 info.fVertexCount = vertexCount; |
506 info.fIndexCount = 0; | 508 info.fIndexCount = 0; |
507 | 509 |
508 info.fInstanceCount = 0; | 510 info.fInstanceCount = 0; |
509 info.fVerticesPerInstance = 0; | 511 info.fVerticesPerInstance = 0; |
510 info.fIndicesPerInstance = 0; | 512 info.fIndicesPerInstance = 0; |
511 | 513 |
512 if (devBounds) { | 514 if (devBounds) { |
513 info.setDevBounds(*devBounds); | 515 info.setDevBounds(*devBounds); |
514 } | 516 } |
515 | 517 |
516 // TODO: We should continue with incorrect blending. | 518 // TODO: We should continue with incorrect blending. |
517 GrDeviceCoordTexture dstCopy; | 519 GrDeviceCoordTexture dstCopy; |
518 const GrGeometryProcessor* gp = ds->getGeometryProcessor(); | 520 if (!this->setupDstReadIfNecessary(ds, gp, gp->getColor(), gp->getCovera
ge(), &dstCopy, |
519 if (!this->setupDstReadIfNecessary(ds, gp->getColor(), gp->getCoverage()
, &dstCopy, | |
520 devBounds)) { | 521 devBounds)) { |
521 return; | 522 return; |
522 } | 523 } |
523 | 524 |
524 this->setDrawBuffers(&info, gp->getVertexStride()); | 525 this->setDrawBuffers(&info, gp->getVertexStride()); |
525 | 526 |
526 this->onDraw(*ds, info, scissorState, dstCopy.texture() ? &dstCopy : NUL
L); | 527 this->onDraw(*ds, gp, info, scissorState, dstCopy.texture() ? &dstCopy :
NULL); |
527 } | 528 } |
528 } | 529 } |
529 | 530 |
530 static const GrStencilSettings& winding_path_stencil_settings() { | 531 static const GrStencilSettings& winding_path_stencil_settings() { |
531 GR_STATIC_CONST_SAME_STENCIL_STRUCT(gSettings, | 532 GR_STATIC_CONST_SAME_STENCIL_STRUCT(gSettings, |
532 kIncClamp_StencilOp, | 533 kIncClamp_StencilOp, |
533 kIncClamp_StencilOp, | 534 kIncClamp_StencilOp, |
534 kAlwaysIfInClip_StencilFunc, | 535 kAlwaysIfInClip_StencilFunc, |
535 0xFFFF, 0xFFFF, 0xFFFF); | 536 0xFFFF, 0xFFFF, 0xFFFF); |
536 return *GR_CONST_STENCIL_SETTINGS_PTR_FROM_STRUCT_PTR(&gSettings); | 537 return *GR_CONST_STENCIL_SETTINGS_PTR_FROM_STRUCT_PTR(&gSettings); |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
608 return; | 609 return; |
609 } | 610 } |
610 | 611 |
611 // set stencil settings for path | 612 // set stencil settings for path |
612 GrStencilSettings stencilSettings; | 613 GrStencilSettings stencilSettings; |
613 this->getPathStencilSettingsForFilltype(fill, | 614 this->getPathStencilSettingsForFilltype(fill, |
614 ds->getRenderTarget()->getStencilBuf
fer(), | 615 ds->getRenderTarget()->getStencilBuf
fer(), |
615 &stencilSettings); | 616 &stencilSettings); |
616 | 617 |
617 GrDeviceCoordTexture dstCopy; | 618 GrDeviceCoordTexture dstCopy; |
618 if (!this->setupDstReadIfNecessary(ds, color, 0xff, &dstCopy, &devBounds)) { | 619 if (!this->setupDstReadIfNecessary(ds, NULL, color, 0xff, &dstCopy, &devBoun
ds)) { |
619 return; | 620 return; |
620 } | 621 } |
621 | 622 |
622 this->onDrawPath(*ds, color, path, scissorState, stencilSettings, dstCopy.te
xture() ? &dstCopy : | 623 this->onDrawPath(*ds, color, path, scissorState, stencilSettings, dstCopy.te
xture() ? &dstCopy : |
623
NULL); | 624
NULL); |
624 } | 625 } |
625 | 626 |
626 void GrDrawTarget::drawPaths(GrDrawState* ds, | 627 void GrDrawTarget::drawPaths(GrDrawState* ds, |
627 GrColor color, | 628 GrColor color, |
628 const GrPathRange* pathRange, | 629 const GrPathRange* pathRange, |
(...skipping 23 matching lines...) Expand all Loading... |
652 GrStencilSettings stencilSettings; | 653 GrStencilSettings stencilSettings; |
653 this->getPathStencilSettingsForFilltype(fill, | 654 this->getPathStencilSettingsForFilltype(fill, |
654 ds->getRenderTarget()->getStencilBuf
fer(), | 655 ds->getRenderTarget()->getStencilBuf
fer(), |
655 &stencilSettings); | 656 &stencilSettings); |
656 | 657 |
657 // Don't compute a bounding box for setupDstReadIfNecessary(), we'll opt | 658 // Don't compute a bounding box for setupDstReadIfNecessary(), we'll opt |
658 // instead for it to just copy the entire dst. Realistically this is a moot | 659 // instead for it to just copy the entire dst. Realistically this is a moot |
659 // point, because any context that supports NV_path_rendering will also | 660 // point, because any context that supports NV_path_rendering will also |
660 // support NV_blend_equation_advanced. | 661 // support NV_blend_equation_advanced. |
661 GrDeviceCoordTexture dstCopy; | 662 GrDeviceCoordTexture dstCopy; |
662 if (!this->setupDstReadIfNecessary(ds, color, 0xff, &dstCopy, NULL)) { | 663 if (!this->setupDstReadIfNecessary(ds, NULL, color, 0xff, &dstCopy, NULL)) { |
663 return; | 664 return; |
664 } | 665 } |
665 | 666 |
666 this->onDrawPaths(*ds, color, pathRange, indices, indexType, transformValues
, transformType, | 667 this->onDrawPaths(*ds, color, pathRange, indices, indexType, transformValues
, transformType, |
667 count, scissorState, stencilSettings, dstCopy.texture() ?
&dstCopy : NULL); | 668 count, scissorState, stencilSettings, dstCopy.texture() ?
&dstCopy : NULL); |
668 } | 669 } |
669 | 670 |
670 void GrDrawTarget::clear(const SkIRect* rect, | 671 void GrDrawTarget::clear(const SkIRect* rect, |
671 GrColor color, | 672 GrColor color, |
672 bool canIgnoreRect, | 673 bool canIgnoreRect, |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
726 if (this->caps()->gpuTracingSupport()) { | 727 if (this->caps()->gpuTracingSupport()) { |
727 SkASSERT(fGpuTraceMarkerCount >= 1); | 728 SkASSERT(fGpuTraceMarkerCount >= 1); |
728 this->fActiveTraceMarkers.remove(*marker); | 729 this->fActiveTraceMarkers.remove(*marker); |
729 --fGpuTraceMarkerCount; | 730 --fGpuTraceMarkerCount; |
730 } | 731 } |
731 } | 732 } |
732 | 733 |
733 //////////////////////////////////////////////////////////////////////////////// | 734 //////////////////////////////////////////////////////////////////////////////// |
734 | 735 |
735 void GrDrawTarget::drawIndexedInstances(GrDrawState* ds, | 736 void GrDrawTarget::drawIndexedInstances(GrDrawState* ds, |
| 737 const GrGeometryProcessor* gp, |
736 GrPrimitiveType type, | 738 GrPrimitiveType type, |
737 int instanceCount, | 739 int instanceCount, |
738 int verticesPerInstance, | 740 int verticesPerInstance, |
739 int indicesPerInstance, | 741 int indicesPerInstance, |
740 const SkRect* devBounds) { | 742 const SkRect* devBounds) { |
741 SkASSERT(ds); | 743 SkASSERT(ds); |
742 | 744 |
743 if (!verticesPerInstance || !indicesPerInstance) { | 745 if (!verticesPerInstance || !indicesPerInstance) { |
744 return; | 746 return; |
745 } | 747 } |
(...skipping 18 matching lines...) Expand all Loading... |
764 info.fIndicesPerInstance = indicesPerInstance; | 766 info.fIndicesPerInstance = indicesPerInstance; |
765 info.fVerticesPerInstance = verticesPerInstance; | 767 info.fVerticesPerInstance = verticesPerInstance; |
766 | 768 |
767 // Set the same bounds for all the draws. | 769 // Set the same bounds for all the draws. |
768 if (devBounds) { | 770 if (devBounds) { |
769 info.setDevBounds(*devBounds); | 771 info.setDevBounds(*devBounds); |
770 } | 772 } |
771 | 773 |
772 // TODO: We should continue with incorrect blending. | 774 // TODO: We should continue with incorrect blending. |
773 GrDeviceCoordTexture dstCopy; | 775 GrDeviceCoordTexture dstCopy; |
774 const GrGeometryProcessor* gp = ds->getGeometryProcessor(); | 776 if (!this->setupDstReadIfNecessary(ds, gp, gp->getColor(), gp->getCoverage()
, |
775 if (!this->setupDstReadIfNecessary(ds, gp->getColor(), gp->getCoverage(), &d
stCopy,devBounds)) { | 777 &dstCopy,devBounds)) { |
776 return; | 778 return; |
777 } | 779 } |
778 | 780 |
779 while (instanceCount) { | 781 while (instanceCount) { |
780 info.fInstanceCount = SkTMin(instanceCount, maxInstancesPerDraw); | 782 info.fInstanceCount = SkTMin(instanceCount, maxInstancesPerDraw); |
781 info.fVertexCount = info.fInstanceCount * verticesPerInstance; | 783 info.fVertexCount = info.fInstanceCount * verticesPerInstance; |
782 info.fIndexCount = info.fInstanceCount * indicesPerInstance; | 784 info.fIndexCount = info.fInstanceCount * indicesPerInstance; |
783 | 785 |
784 if (this->checkDraw(*ds, | 786 if (this->checkDraw(*ds, |
| 787 gp, |
785 type, | 788 type, |
786 info.fStartVertex, | 789 info.fStartVertex, |
787 info.fStartIndex, | 790 info.fStartIndex, |
788 info.fVertexCount, | 791 info.fVertexCount, |
789 info.fIndexCount)) { | 792 info.fIndexCount)) { |
790 this->setDrawBuffers(&info, gp->getVertexStride()); | 793 this->setDrawBuffers(&info, gp->getVertexStride()); |
791 this->onDraw(*ds, info, scissorState, dstCopy.texture() ? &dstCopy :
NULL); | 794 this->onDraw(*ds, gp, info, scissorState, dstCopy.texture() ? &dstCo
py : NULL); |
792 } | 795 } |
793 info.fStartVertex += info.fVertexCount; | 796 info.fStartVertex += info.fVertexCount; |
794 instanceCount -= info.fInstanceCount; | 797 instanceCount -= info.fInstanceCount; |
795 } | 798 } |
796 } | 799 } |
797 | 800 |
798 //////////////////////////////////////////////////////////////////////////////// | 801 //////////////////////////////////////////////////////////////////////////////// |
799 | 802 |
800 GrDrawTarget::AutoReleaseGeometry::AutoReleaseGeometry( | 803 GrDrawTarget::AutoReleaseGeometry::AutoReleaseGeometry( |
801 GrDrawTarget* target, | 804 GrDrawTarget* target, |
(...skipping 415 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1217 GrDrawState::AutoRestoreStencil* ars, | 1220 GrDrawState::AutoRestoreStencil* ars, |
1218 GrDrawState* ds, | 1221 GrDrawState* ds, |
1219 GrClipMaskManager::ScissorState* scissorState) { | 1222 GrClipMaskManager::ScissorState* scissorState) { |
1220 return fClipMaskManager.setupClipping(ds, | 1223 return fClipMaskManager.setupClipping(ds, |
1221 are, | 1224 are, |
1222 ars, | 1225 ars, |
1223 scissorState, | 1226 scissorState, |
1224 this->getClip(), | 1227 this->getClip(), |
1225 devBounds); | 1228 devBounds); |
1226 } | 1229 } |
OLD | NEW |