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