OLD | NEW |
1 | 1 |
2 /* | 2 /* |
3 * Copyright 2011 Google Inc. | 3 * Copyright 2011 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 #include "GrContext.h" | 9 #include "GrContext.h" |
10 | 10 |
(...skipping 420 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
431 fBatch.fColorIgnored = init.fColorIgnored; | 431 fBatch.fColorIgnored = init.fColorIgnored; |
432 fBatch.fColor = fGeoData[0].fColor; | 432 fBatch.fColor = fGeoData[0].fColor; |
433 fBatch.fUsesLocalCoords = init.fUsesLocalCoords; | 433 fBatch.fUsesLocalCoords = init.fUsesLocalCoords; |
434 fBatch.fCoverageIgnored = init.fCoverageIgnored; | 434 fBatch.fCoverageIgnored = init.fCoverageIgnored; |
435 } | 435 } |
436 | 436 |
437 void generateGeometry(GrBatchTarget* batchTarget, const GrPipeline* pipeline
) override { | 437 void generateGeometry(GrBatchTarget* batchTarget, const GrPipeline* pipeline
) override { |
438 SkAutoTUnref<const GrGeometryProcessor> gp( | 438 SkAutoTUnref<const GrGeometryProcessor> gp( |
439 GrDefaultGeoProcFactory::Create(GrDefaultGeoProcFactory::kPositi
on_GPType, | 439 GrDefaultGeoProcFactory::Create(GrDefaultGeoProcFactory::kPositi
on_GPType, |
440 this->color(), | 440 this->color(), |
441 this->usesLocalCoords(), | |
442 this->coverageIgnored(), | |
443 this->viewMatrix(), | 441 this->viewMatrix(), |
444 SkMatrix::I())); | 442 SkMatrix::I())); |
445 | 443 |
446 batchTarget->initDraw(gp, pipeline); | 444 batchTarget->initDraw(gp, pipeline); |
447 | 445 |
| 446 // TODO this is hacky, but the only way we have to initialize the GP is
to use the |
| 447 // GrPipelineInfo struct so we can generate the correct shader. Once we
have GrBatch |
| 448 // everywhere we can remove this nastiness |
| 449 GrPipelineInfo init; |
| 450 init.fColorIgnored = fBatch.fColorIgnored; |
| 451 init.fOverrideColor = GrColor_ILLEGAL; |
| 452 init.fCoverageIgnored = fBatch.fCoverageIgnored; |
| 453 init.fUsesLocalCoords = this->usesLocalCoords(); |
| 454 gp->initBatchTracker(batchTarget->currentBatchTracker(), init); |
| 455 |
448 size_t vertexStride = gp->getVertexStride(); | 456 size_t vertexStride = gp->getVertexStride(); |
449 | 457 |
450 SkASSERT(vertexStride == sizeof(GrDefaultGeoProcFactory::PositionAttr)); | 458 SkASSERT(vertexStride == sizeof(GrDefaultGeoProcFactory::PositionAttr)); |
451 | 459 |
452 Geometry& args = fGeoData[0]; | 460 Geometry& args = fGeoData[0]; |
453 | 461 |
454 int vertexCount = kVertsPerHairlineRect; | 462 int vertexCount = kVertsPerHairlineRect; |
455 if (args.fStrokeWidth > 0) { | 463 if (args.fStrokeWidth > 0) { |
456 vertexCount = kVertsPerStrokeRect; | 464 vertexCount = kVertsPerStrokeRect; |
457 } | 465 } |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
534 verts[8] = verts[0]; | 542 verts[8] = verts[0]; |
535 verts[9] = verts[1]; | 543 verts[9] = verts[1]; |
536 } | 544 } |
537 | 545 |
538 | 546 |
539 GrColor color() const { return fBatch.fColor; } | 547 GrColor color() const { return fBatch.fColor; } |
540 bool usesLocalCoords() const { return fBatch.fUsesLocalCoords; } | 548 bool usesLocalCoords() const { return fBatch.fUsesLocalCoords; } |
541 bool colorIgnored() const { return fBatch.fColorIgnored; } | 549 bool colorIgnored() const { return fBatch.fColorIgnored; } |
542 const SkMatrix& viewMatrix() const { return fGeoData[0].fViewMatrix; } | 550 const SkMatrix& viewMatrix() const { return fGeoData[0].fViewMatrix; } |
543 bool hairline() const { return fBatch.fHairline; } | 551 bool hairline() const { return fBatch.fHairline; } |
544 bool coverageIgnored() const { return fBatch.fCoverageIgnored; } | |
545 | 552 |
546 bool onCombineIfPossible(GrBatch* t) override { | 553 bool onCombineIfPossible(GrBatch* t) override { |
547 // StrokeRectBatch* that = t->cast<StrokeRectBatch>(); | 554 // StrokeRectBatch* that = t->cast<StrokeRectBatch>(); |
548 | 555 |
549 // NonAA stroke rects cannot batch right now | 556 // NonAA stroke rects cannot batch right now |
550 // TODO make these batchable | 557 // TODO make these batchable |
551 return false; | 558 return false; |
552 } | 559 } |
553 | 560 |
554 struct BatchTracker { | 561 struct BatchTracker { |
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
698 rectToDraw, | 705 rectToDraw, |
699 &localRect, | 706 &localRect, |
700 localMatrix); | 707 localMatrix); |
701 } | 708 } |
702 | 709 |
703 static const GrGeometryProcessor* set_vertex_attributes(bool hasLocalCoords, | 710 static const GrGeometryProcessor* set_vertex_attributes(bool hasLocalCoords, |
704 bool hasColors, | 711 bool hasColors, |
705 int* colorOffset, | 712 int* colorOffset, |
706 int* texOffset, | 713 int* texOffset, |
707 GrColor color, | 714 GrColor color, |
708 const SkMatrix& viewMatr
ix, | 715 const SkMatrix& viewMatr
ix) { |
709 bool coverageIgnored) { | |
710 *texOffset = -1; | 716 *texOffset = -1; |
711 *colorOffset = -1; | 717 *colorOffset = -1; |
712 uint32_t flags = GrDefaultGeoProcFactory::kPosition_GPType; | 718 uint32_t flags = GrDefaultGeoProcFactory::kPosition_GPType; |
713 if (hasLocalCoords && hasColors) { | 719 if (hasLocalCoords && hasColors) { |
714 *colorOffset = sizeof(SkPoint); | 720 *colorOffset = sizeof(SkPoint); |
715 *texOffset = sizeof(SkPoint) + sizeof(GrColor); | 721 *texOffset = sizeof(SkPoint) + sizeof(GrColor); |
716 flags |= GrDefaultGeoProcFactory::kColor_GPType | | 722 flags |= GrDefaultGeoProcFactory::kColor_GPType | |
717 GrDefaultGeoProcFactory::kLocalCoord_GPType; | 723 GrDefaultGeoProcFactory::kLocalCoord_GPType; |
718 } else if (hasLocalCoords) { | 724 } else if (hasLocalCoords) { |
719 *texOffset = sizeof(SkPoint); | 725 *texOffset = sizeof(SkPoint); |
720 flags |= GrDefaultGeoProcFactory::kLocalCoord_GPType; | 726 flags |= GrDefaultGeoProcFactory::kLocalCoord_GPType; |
721 } else if (hasColors) { | 727 } else if (hasColors) { |
722 *colorOffset = sizeof(SkPoint); | 728 *colorOffset = sizeof(SkPoint); |
723 flags |= GrDefaultGeoProcFactory::kColor_GPType; | 729 flags |= GrDefaultGeoProcFactory::kColor_GPType; |
724 } | 730 } |
725 return GrDefaultGeoProcFactory::Create(flags, color, hasLocalCoords, coverag
eIgnored, | 731 return GrDefaultGeoProcFactory::Create(flags, color, viewMatrix, SkMatrix::I
()); |
726 viewMatrix, SkMatrix::I()); | |
727 } | 732 } |
728 | 733 |
729 class DrawVerticesBatch : public GrBatch { | 734 class DrawVerticesBatch : public GrBatch { |
730 public: | 735 public: |
731 struct Geometry { | 736 struct Geometry { |
732 GrColor fColor; | 737 GrColor fColor; |
733 SkTDArray<SkPoint> fPositions; | 738 SkTDArray<SkPoint> fPositions; |
734 SkTDArray<uint16_t> fIndices; | 739 SkTDArray<uint16_t> fIndices; |
735 SkTDArray<GrColor> fColors; | 740 SkTDArray<GrColor> fColors; |
736 SkTDArray<SkPoint> fLocalCoords; | 741 SkTDArray<SkPoint> fLocalCoords; |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
774 fBatch.fColorIgnored = init.fColorIgnored; | 779 fBatch.fColorIgnored = init.fColorIgnored; |
775 fBatch.fColor = fGeoData[0].fColor; | 780 fBatch.fColor = fGeoData[0].fColor; |
776 fBatch.fUsesLocalCoords = init.fUsesLocalCoords; | 781 fBatch.fUsesLocalCoords = init.fUsesLocalCoords; |
777 fBatch.fCoverageIgnored = init.fCoverageIgnored; | 782 fBatch.fCoverageIgnored = init.fCoverageIgnored; |
778 } | 783 } |
779 | 784 |
780 void generateGeometry(GrBatchTarget* batchTarget, const GrPipeline* pipeline
) override { | 785 void generateGeometry(GrBatchTarget* batchTarget, const GrPipeline* pipeline
) override { |
781 int colorOffset = -1, texOffset = -1; | 786 int colorOffset = -1, texOffset = -1; |
782 SkAutoTUnref<const GrGeometryProcessor> gp( | 787 SkAutoTUnref<const GrGeometryProcessor> gp( |
783 set_vertex_attributes(this->hasLocalCoords(), this->hasColors(),
&colorOffset, | 788 set_vertex_attributes(this->hasLocalCoords(), this->hasColors(),
&colorOffset, |
784 &texOffset, this->color(), this->viewMatri
x(), | 789 &texOffset, this->color(), this->viewMatri
x())); |
785 this->coverageIgnored())); | |
786 | 790 |
787 batchTarget->initDraw(gp, pipeline); | 791 batchTarget->initDraw(gp, pipeline); |
788 | 792 |
| 793 // TODO this is hacky, but the only way we have to initialize the GP is
to use the |
| 794 // GrPipelineInfo struct so we can generate the correct shader. Once we
have GrBatch |
| 795 // everywhere we can remove this nastiness |
| 796 GrPipelineInfo init; |
| 797 init.fColorIgnored = fBatch.fColorIgnored; |
| 798 init.fOverrideColor = GrColor_ILLEGAL; |
| 799 init.fCoverageIgnored = fBatch.fCoverageIgnored; |
| 800 init.fUsesLocalCoords = this->usesLocalCoords(); |
| 801 gp->initBatchTracker(batchTarget->currentBatchTracker(), init); |
| 802 |
789 size_t vertexStride = gp->getVertexStride(); | 803 size_t vertexStride = gp->getVertexStride(); |
790 | 804 |
791 SkASSERT(vertexStride == sizeof(SkPoint) + (this->hasLocalCoords() ? siz
eof(SkPoint) : 0) | 805 SkASSERT(vertexStride == sizeof(SkPoint) + (this->hasLocalCoords() ? siz
eof(SkPoint) : 0) |
792 + (this->hasColors() ? sizeof(G
rColor) : 0)); | 806 + (this->hasColors() ? sizeof(G
rColor) : 0)); |
793 | 807 |
794 int instanceCount = fGeoData.count(); | 808 int instanceCount = fGeoData.count(); |
795 | 809 |
796 const GrVertexBuffer* vertexBuffer; | 810 const GrVertexBuffer* vertexBuffer; |
797 int firstVertex; | 811 int firstVertex; |
798 | 812 |
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
903 } | 917 } |
904 GrColor color() const { return fBatch.fColor; } | 918 GrColor color() const { return fBatch.fColor; } |
905 bool usesLocalCoords() const { return fBatch.fUsesLocalCoords; } | 919 bool usesLocalCoords() const { return fBatch.fUsesLocalCoords; } |
906 bool colorIgnored() const { return fBatch.fColorIgnored; } | 920 bool colorIgnored() const { return fBatch.fColorIgnored; } |
907 const SkMatrix& viewMatrix() const { return fBatch.fViewMatrix; } | 921 const SkMatrix& viewMatrix() const { return fBatch.fViewMatrix; } |
908 bool hasColors() const { return fBatch.fHasColors; } | 922 bool hasColors() const { return fBatch.fHasColors; } |
909 bool hasIndices() const { return fBatch.fHasIndices; } | 923 bool hasIndices() const { return fBatch.fHasIndices; } |
910 bool hasLocalCoords() const { return fBatch.fHasLocalCoords; } | 924 bool hasLocalCoords() const { return fBatch.fHasLocalCoords; } |
911 int vertexCount() const { return fBatch.fVertexCount; } | 925 int vertexCount() const { return fBatch.fVertexCount; } |
912 int indexCount() const { return fBatch.fIndexCount; } | 926 int indexCount() const { return fBatch.fIndexCount; } |
913 bool coverageIgnored() const { return fBatch.fCoverageIgnored; } | |
914 | 927 |
915 bool onCombineIfPossible(GrBatch* t) override { | 928 bool onCombineIfPossible(GrBatch* t) override { |
916 DrawVerticesBatch* that = t->cast<DrawVerticesBatch>(); | 929 DrawVerticesBatch* that = t->cast<DrawVerticesBatch>(); |
917 | 930 |
918 if (!this->batchablePrimitiveType() || this->primitiveType() != that->pr
imitiveType()) { | 931 if (!this->batchablePrimitiveType() || this->primitiveType() != that->pr
imitiveType()) { |
919 return false; | 932 return false; |
920 } | 933 } |
921 | 934 |
922 SkASSERT(this->usesLocalCoords() == that->usesLocalCoords()); | 935 SkASSERT(this->usesLocalCoords() == that->usesLocalCoords()); |
923 | 936 |
(...skipping 1063 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1987 geometry.fColor = GrRandomColor(random); | 2000 geometry.fColor = GrRandomColor(random); |
1988 return DrawVerticesBatch::Create(geometry, type, viewMatrix, | 2001 return DrawVerticesBatch::Create(geometry, type, viewMatrix, |
1989 positions.begin(), vertexCount, | 2002 positions.begin(), vertexCount, |
1990 indices.begin(), hasIndices ? vertexCount :
0, | 2003 indices.begin(), hasIndices ? vertexCount :
0, |
1991 colors.begin(), | 2004 colors.begin(), |
1992 texCoords.begin(), | 2005 texCoords.begin(), |
1993 bounds); | 2006 bounds); |
1994 } | 2007 } |
1995 | 2008 |
1996 #endif | 2009 #endif |
OLD | NEW |