| 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 "GrInOrderDrawBuffer.h" | 8 #include "GrInOrderDrawBuffer.h" | 
| 9 | 9 | 
| 10 #include "GrBufferAllocPool.h" | 10 #include "GrBufferAllocPool.h" | 
| (...skipping 687 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 698                                     &poolState.fPoolStartIndex); | 698                                     &poolState.fPoolStartIndex); | 
| 699     return SkToBool(*indices); | 699     return SkToBool(*indices); | 
| 700 } | 700 } | 
| 701 | 701 | 
| 702 void GrInOrderDrawBuffer::releaseReservedVertexSpace() { | 702 void GrInOrderDrawBuffer::releaseReservedVertexSpace() { | 
| 703     GeometryPoolState& poolState = fGeoPoolStateStack.back(); | 703     GeometryPoolState& poolState = fGeoPoolStateStack.back(); | 
| 704     const GeometrySrcState& geoSrc = this->getGeomSrc(); | 704     const GeometrySrcState& geoSrc = this->getGeomSrc(); | 
| 705 | 705 | 
| 706     // If we get a release vertex space call then our current source should eith
     er be reserved | 706     // If we get a release vertex space call then our current source should eith
     er be reserved | 
| 707     // or array (which we copied into reserved space). | 707     // or array (which we copied into reserved space). | 
| 708     SkASSERT(kReserved_GeometrySrcType == geoSrc.fVertexSrc || | 708     SkASSERT(kReserved_GeometrySrcType == geoSrc.fVertexSrc); | 
| 709              kArray_GeometrySrcType == geoSrc.fVertexSrc); |  | 
| 710 | 709 | 
| 711     // When the caller reserved vertex buffer space we gave it back a pointer | 710     // When the caller reserved vertex buffer space we gave it back a pointer | 
| 712     // provided by the vertex buffer pool. At each draw we tracked the largest | 711     // provided by the vertex buffer pool. At each draw we tracked the largest | 
| 713     // offset into the pool's pointer that was referenced. Now we return to the | 712     // offset into the pool's pointer that was referenced. Now we return to the | 
| 714     // pool any portion at the tail of the allocation that no draw referenced. | 713     // pool any portion at the tail of the allocation that no draw referenced. | 
| 715     size_t reservedVertexBytes = geoSrc.fVertexSize * geoSrc.fVertexCount; | 714     size_t reservedVertexBytes = geoSrc.fVertexSize * geoSrc.fVertexCount; | 
| 716     fVertexPool.putBack(reservedVertexBytes - | 715     fVertexPool.putBack(reservedVertexBytes - | 
| 717                         poolState.fUsedPoolVertexBytes); | 716                         poolState.fUsedPoolVertexBytes); | 
| 718     poolState.fUsedPoolVertexBytes = 0; | 717     poolState.fUsedPoolVertexBytes = 0; | 
| 719     poolState.fPoolVertexBuffer = NULL; | 718     poolState.fPoolVertexBuffer = NULL; | 
| 720     poolState.fPoolStartVertex = 0; | 719     poolState.fPoolStartVertex = 0; | 
| 721 } | 720 } | 
| 722 | 721 | 
| 723 void GrInOrderDrawBuffer::releaseReservedIndexSpace() { | 722 void GrInOrderDrawBuffer::releaseReservedIndexSpace() { | 
| 724     GeometryPoolState& poolState = fGeoPoolStateStack.back(); | 723     GeometryPoolState& poolState = fGeoPoolStateStack.back(); | 
| 725     const GeometrySrcState& geoSrc = this->getGeomSrc(); | 724     const GeometrySrcState& geoSrc = this->getGeomSrc(); | 
| 726 | 725 | 
| 727     // If we get a release index space call then our current source should eithe
     r be reserved | 726     // If we get a release index space call then our current source should eithe
     r be reserved | 
| 728     // or array (which we copied into reserved space). | 727     // or array (which we copied into reserved space). | 
| 729     SkASSERT(kReserved_GeometrySrcType == geoSrc.fIndexSrc || | 728     SkASSERT(kReserved_GeometrySrcType == geoSrc.fIndexSrc); | 
| 730              kArray_GeometrySrcType == geoSrc.fIndexSrc); |  | 
| 731 | 729 | 
| 732     // Similar to releaseReservedVertexSpace we return any unused portion at | 730     // Similar to releaseReservedVertexSpace we return any unused portion at | 
| 733     // the tail | 731     // the tail | 
| 734     size_t reservedIndexBytes = sizeof(uint16_t) * geoSrc.fIndexCount; | 732     size_t reservedIndexBytes = sizeof(uint16_t) * geoSrc.fIndexCount; | 
| 735     fIndexPool.putBack(reservedIndexBytes - poolState.fUsedPoolIndexBytes); | 733     fIndexPool.putBack(reservedIndexBytes - poolState.fUsedPoolIndexBytes); | 
| 736     poolState.fUsedPoolIndexBytes = 0; | 734     poolState.fUsedPoolIndexBytes = 0; | 
| 737     poolState.fPoolIndexBuffer = NULL; | 735     poolState.fPoolIndexBuffer = NULL; | 
| 738     poolState.fPoolStartIndex = 0; | 736     poolState.fPoolStartIndex = 0; | 
| 739 } | 737 } | 
| 740 | 738 | 
| 741 void GrInOrderDrawBuffer::onSetVertexSourceToArray(const void* vertexArray, int 
     vertexCount) { |  | 
| 742     GeometryPoolState& poolState = fGeoPoolStateStack.back(); |  | 
| 743     SkASSERT(0 == poolState.fUsedPoolVertexBytes); |  | 
| 744 #ifdef SK_DEBUG |  | 
| 745     bool success = |  | 
| 746 #endif |  | 
| 747     fVertexPool.appendVertices(this->getVertexSize(), |  | 
| 748                                vertexCount, |  | 
| 749                                vertexArray, |  | 
| 750                                &poolState.fPoolVertexBuffer, |  | 
| 751                                &poolState.fPoolStartVertex); |  | 
| 752     GR_DEBUGASSERT(success); |  | 
| 753 } |  | 
| 754 |  | 
| 755 void GrInOrderDrawBuffer::onSetIndexSourceToArray(const void* indexArray, |  | 
| 756                                                   int indexCount) { |  | 
| 757     GeometryPoolState& poolState = fGeoPoolStateStack.back(); |  | 
| 758     SkASSERT(0 == poolState.fUsedPoolIndexBytes); |  | 
| 759 #ifdef SK_DEBUG |  | 
| 760     bool success = |  | 
| 761 #endif |  | 
| 762     fIndexPool.appendIndices(indexCount, |  | 
| 763                              indexArray, |  | 
| 764                              &poolState.fPoolIndexBuffer, |  | 
| 765                              &poolState.fPoolStartIndex); |  | 
| 766     GR_DEBUGASSERT(success); |  | 
| 767 } |  | 
| 768 |  | 
| 769 void GrInOrderDrawBuffer::releaseVertexArray() { |  | 
| 770     // When the client provides an array as the vertex source we handled it |  | 
| 771     // by copying their array into reserved space. |  | 
| 772     this->GrInOrderDrawBuffer::releaseReservedVertexSpace(); |  | 
| 773 } |  | 
| 774 |  | 
| 775 void GrInOrderDrawBuffer::releaseIndexArray() { |  | 
| 776     // When the client provides an array as the index source we handled it |  | 
| 777     // by copying their array into reserved space. |  | 
| 778     this->GrInOrderDrawBuffer::releaseReservedIndexSpace(); |  | 
| 779 } |  | 
| 780 |  | 
| 781 void GrInOrderDrawBuffer::geometrySourceWillPush() { | 739 void GrInOrderDrawBuffer::geometrySourceWillPush() { | 
| 782     GeometryPoolState& poolState = fGeoPoolStateStack.push_back(); | 740     GeometryPoolState& poolState = fGeoPoolStateStack.push_back(); | 
| 783     poolState.fUsedPoolVertexBytes = 0; | 741     poolState.fUsedPoolVertexBytes = 0; | 
| 784     poolState.fUsedPoolIndexBytes = 0; | 742     poolState.fUsedPoolIndexBytes = 0; | 
| 785 #ifdef SK_DEBUG | 743 #ifdef SK_DEBUG | 
| 786     poolState.fPoolVertexBuffer = (GrVertexBuffer*)~0; | 744     poolState.fPoolVertexBuffer = (GrVertexBuffer*)~0; | 
| 787     poolState.fPoolStartVertex = ~0; | 745     poolState.fPoolStartVertex = ~0; | 
| 788     poolState.fPoolIndexBuffer = (GrIndexBuffer*)~0; | 746     poolState.fPoolIndexBuffer = (GrIndexBuffer*)~0; | 
| 789     poolState.fPoolStartIndex = ~0; | 747     poolState.fPoolStartIndex = ~0; | 
| 790 #endif | 748 #endif | 
| 791 } | 749 } | 
| 792 | 750 | 
| 793 void GrInOrderDrawBuffer::geometrySourceWillPop(const GeometrySrcState& restored
     State) { | 751 void GrInOrderDrawBuffer::geometrySourceWillPop(const GeometrySrcState& restored
     State) { | 
| 794     SkASSERT(fGeoPoolStateStack.count() > 1); | 752     SkASSERT(fGeoPoolStateStack.count() > 1); | 
| 795     fGeoPoolStateStack.pop_back(); | 753     fGeoPoolStateStack.pop_back(); | 
| 796     GeometryPoolState& poolState = fGeoPoolStateStack.back(); | 754     GeometryPoolState& poolState = fGeoPoolStateStack.back(); | 
| 797     // we have to assume that any slack we had in our vertex/index data | 755     // we have to assume that any slack we had in our vertex/index data | 
| 798     // is now unreleasable because data may have been appended later in the | 756     // is now unreleasable because data may have been appended later in the | 
| 799     // pool. | 757     // pool. | 
| 800     if (kReserved_GeometrySrcType == restoredState.fVertexSrc || | 758     if (kReserved_GeometrySrcType == restoredState.fVertexSrc) { | 
| 801         kArray_GeometrySrcType == restoredState.fVertexSrc) { |  | 
| 802         poolState.fUsedPoolVertexBytes = restoredState.fVertexSize * restoredSta
     te.fVertexCount; | 759         poolState.fUsedPoolVertexBytes = restoredState.fVertexSize * restoredSta
     te.fVertexCount; | 
| 803     } | 760     } | 
| 804     if (kReserved_GeometrySrcType == restoredState.fIndexSrc || | 761     if (kReserved_GeometrySrcType == restoredState.fIndexSrc) { | 
| 805         kArray_GeometrySrcType == restoredState.fIndexSrc) { |  | 
| 806         poolState.fUsedPoolIndexBytes = sizeof(uint16_t) * | 762         poolState.fUsedPoolIndexBytes = sizeof(uint16_t) * | 
| 807                                          restoredState.fIndexCount; | 763                                          restoredState.fIndexCount; | 
| 808     } | 764     } | 
| 809 } | 765 } | 
| 810 | 766 | 
| 811 void GrInOrderDrawBuffer::recordStateIfNecessary() { | 767 void GrInOrderDrawBuffer::recordStateIfNecessary() { | 
| 812     if (!fLastState) { | 768     if (!fLastState) { | 
| 813         SetState* ss = GrNEW_APPEND_TO_RECORDER(fCmdBuffer, SetState, (this->get
     DrawState())); | 769         SetState* ss = GrNEW_APPEND_TO_RECORDER(fCmdBuffer, SetState, (this->get
     DrawState())); | 
| 814         fLastState = &ss->fState; | 770         fLastState = &ss->fState; | 
| 815         this->convertDrawStateToPendingExec(fLastState); | 771         this->convertDrawStateToPendingExec(fLastState); | 
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 856         fCmdBuffer.back().fType = add_trace_bit(fCmdBuffer.back().fType); | 812         fCmdBuffer.back().fType = add_trace_bit(fCmdBuffer.back().fType); | 
| 857         fGpuCmdMarkers.push_back(activeTraceMarkers); | 813         fGpuCmdMarkers.push_back(activeTraceMarkers); | 
| 858     } | 814     } | 
| 859 } | 815 } | 
| 860 | 816 | 
| 861 void GrInOrderDrawBuffer::clipWillBeSet(const GrClipData* newClipData) { | 817 void GrInOrderDrawBuffer::clipWillBeSet(const GrClipData* newClipData) { | 
| 862     INHERITED::clipWillBeSet(newClipData); | 818     INHERITED::clipWillBeSet(newClipData); | 
| 863     fClipSet = true; | 819     fClipSet = true; | 
| 864     fClipProxyState = kUnknown_ClipProxyState; | 820     fClipProxyState = kUnknown_ClipProxyState; | 
| 865 } | 821 } | 
| OLD | NEW | 
|---|