epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 1 | |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 2 | /* |
epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 3 | * Copyright 2011 Google Inc. |
| 4 | * |
| 5 | * Use of this source code is governed by a BSD-style license that can be |
| 6 | * found in the LICENSE file. |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 7 | */ |
| 8 | |
| 9 | |
epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 10 | |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 11 | #include "GrInOrderDrawBuffer.h" |
| 12 | #include "GrTexture.h" |
bsalomon@google.com | 1c13c96 | 2011-02-14 16:51:21 +0000 | [diff] [blame] | 13 | #include "GrBufferAllocPool.h" |
bsalomon@google.com | 86afc2a | 2011-02-16 16:12:19 +0000 | [diff] [blame] | 14 | #include "GrIndexBuffer.h" |
| 15 | #include "GrVertexBuffer.h" |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 16 | #include "GrGpu.h" |
| 17 | |
bsalomon@google.com | 471d471 | 2011-08-23 15:45:25 +0000 | [diff] [blame] | 18 | GrInOrderDrawBuffer::GrInOrderDrawBuffer(const GrGpu* gpu, |
| 19 | GrVertexBufferAllocPool* vertexPool, |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 20 | GrIndexBufferAllocPool* indexPool) |
bsalomon@google.com | 18c9c19 | 2011-09-22 21:01:31 +0000 | [diff] [blame] | 21 | : fDraws(&fDrawStorage) |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 22 | , fStates(&fStateStorage) |
| 23 | , fClears(&fClearStorage) |
| 24 | , fClips(&fClipStorage) |
| 25 | , fClipSet(true) |
bsalomon@google.com | 86afc2a | 2011-02-16 16:12:19 +0000 | [diff] [blame] | 26 | |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 27 | , fLastRectVertexLayout(0) |
| 28 | , fQuadIndexBuffer(NULL) |
| 29 | , fMaxQuads(0) |
| 30 | , fCurrQuad(0) |
bsalomon@google.com | 86afc2a | 2011-02-16 16:12:19 +0000 | [diff] [blame] | 31 | |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 32 | , fVertexPool(*vertexPool) |
bsalomon@google.com | 9266901 | 2011-09-27 19:10:05 +0000 | [diff] [blame] | 33 | , fIndexPool(*indexPool) { |
bsalomon@google.com | 18c9c19 | 2011-09-22 21:01:31 +0000 | [diff] [blame] | 34 | |
| 35 | fCaps = gpu->getCaps(); |
| 36 | |
bsalomon@google.com | 1c13c96 | 2011-02-14 16:51:21 +0000 | [diff] [blame] | 37 | GrAssert(NULL != vertexPool); |
| 38 | GrAssert(NULL != indexPool); |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 39 | |
| 40 | GeometryPoolState& poolState = fGeoPoolStateStack.push_back(); |
| 41 | poolState.fUsedPoolVertexBytes = 0; |
| 42 | poolState.fUsedPoolIndexBytes = 0; |
| 43 | #if GR_DEBUG |
| 44 | poolState.fPoolVertexBuffer = (GrVertexBuffer*)~0; |
| 45 | poolState.fPoolStartVertex = ~0; |
| 46 | poolState.fPoolIndexBuffer = (GrIndexBuffer*)~0; |
| 47 | poolState.fPoolStartIndex = ~0; |
| 48 | #endif |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 49 | } |
| 50 | |
| 51 | GrInOrderDrawBuffer::~GrInOrderDrawBuffer() { |
bsalomon@google.com | 86afc2a | 2011-02-16 16:12:19 +0000 | [diff] [blame] | 52 | this->reset(); |
| 53 | GrSafeUnref(fQuadIndexBuffer); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 54 | } |
| 55 | |
| 56 | void GrInOrderDrawBuffer::initializeDrawStateAndClip(const GrDrawTarget& target) { |
| 57 | this->copyDrawState(target); |
| 58 | this->setClip(target.getClip()); |
| 59 | } |
| 60 | |
bsalomon@google.com | 86afc2a | 2011-02-16 16:12:19 +0000 | [diff] [blame] | 61 | void GrInOrderDrawBuffer::setQuadIndexBuffer(const GrIndexBuffer* indexBuffer) { |
| 62 | bool newIdxBuffer = fQuadIndexBuffer != indexBuffer; |
| 63 | if (newIdxBuffer) { |
| 64 | GrSafeUnref(fQuadIndexBuffer); |
| 65 | fQuadIndexBuffer = indexBuffer; |
| 66 | GrSafeRef(fQuadIndexBuffer); |
| 67 | fCurrQuad = 0; |
| 68 | fMaxQuads = (NULL == indexBuffer) ? 0 : indexBuffer->maxQuads(); |
| 69 | } else { |
bsalomon@google.com | d302f14 | 2011-03-03 13:54:13 +0000 | [diff] [blame] | 70 | GrAssert((NULL == indexBuffer && 0 == fMaxQuads) || |
bsalomon@google.com | 86afc2a | 2011-02-16 16:12:19 +0000 | [diff] [blame] | 71 | (indexBuffer->maxQuads() == fMaxQuads)); |
| 72 | } |
| 73 | } |
| 74 | |
bsalomon@google.com | d302f14 | 2011-03-03 13:54:13 +0000 | [diff] [blame] | 75 | void GrInOrderDrawBuffer::drawRect(const GrRect& rect, |
bsalomon@google.com | 86afc2a | 2011-02-16 16:12:19 +0000 | [diff] [blame] | 76 | const GrMatrix* matrix, |
bsalomon@google.com | ffca400 | 2011-02-22 20:34:01 +0000 | [diff] [blame] | 77 | StageBitfield stageEnableBitfield, |
bsalomon@google.com | 86afc2a | 2011-02-16 16:12:19 +0000 | [diff] [blame] | 78 | const GrRect* srcRects[], |
| 79 | const GrMatrix* srcMatrices[]) { |
bsalomon@google.com | d302f14 | 2011-03-03 13:54:13 +0000 | [diff] [blame] | 80 | |
bsalomon@google.com | 86afc2a | 2011-02-16 16:12:19 +0000 | [diff] [blame] | 81 | GrAssert(!(NULL == fQuadIndexBuffer && fCurrQuad)); |
| 82 | GrAssert(!(fDraws.empty() && fCurrQuad)); |
| 83 | GrAssert(!(0 != fMaxQuads && NULL == fQuadIndexBuffer)); |
| 84 | |
| 85 | // if we have a quad IB then either append to the previous run of |
| 86 | // rects or start a new run |
| 87 | if (fMaxQuads) { |
bsalomon@google.com | d302f14 | 2011-03-03 13:54:13 +0000 | [diff] [blame] | 88 | |
bsalomon@google.com | 86afc2a | 2011-02-16 16:12:19 +0000 | [diff] [blame] | 89 | bool appendToPreviousDraw = false; |
bsalomon@google.com | ffca400 | 2011-02-22 20:34:01 +0000 | [diff] [blame] | 90 | GrVertexLayout layout = GetRectVertexLayout(stageEnableBitfield, srcRects); |
bsalomon@google.com | 86afc2a | 2011-02-16 16:12:19 +0000 | [diff] [blame] | 91 | AutoReleaseGeometry geo(this, layout, 4, 0); |
bsalomon@google.com | 6513cd0 | 2011-08-05 20:12:30 +0000 | [diff] [blame] | 92 | if (!geo.succeeded()) { |
| 93 | GrPrintf("Failed to get space for vertices!\n"); |
| 94 | return; |
| 95 | } |
bsalomon@google.com | 86afc2a | 2011-02-16 16:12:19 +0000 | [diff] [blame] | 96 | AutoViewMatrixRestore avmr(this); |
| 97 | GrMatrix combinedMatrix = this->getViewMatrix(); |
| 98 | this->setViewMatrix(GrMatrix::I()); |
| 99 | if (NULL != matrix) { |
| 100 | combinedMatrix.preConcat(*matrix); |
| 101 | } |
| 102 | |
| 103 | SetRectVertices(rect, &combinedMatrix, srcRects, srcMatrices, layout, geo.vertices()); |
| 104 | |
| 105 | // we don't want to miss an opportunity to batch rects together |
| 106 | // simply because the clip has changed if the clip doesn't affect |
| 107 | // the rect. |
| 108 | bool disabledClip = false; |
| 109 | if (this->isClipState() && fClip.isRect()) { |
bsalomon@google.com | d302f14 | 2011-03-03 13:54:13 +0000 | [diff] [blame] | 110 | |
bsalomon@google.com | 0b50b2e | 2011-03-08 21:07:21 +0000 | [diff] [blame] | 111 | GrRect clipRect = fClip.getRect(0); |
bsalomon@google.com | 86afc2a | 2011-02-16 16:12:19 +0000 | [diff] [blame] | 112 | // If the clip rect touches the edge of the viewport, extended it |
| 113 | // out (close) to infinity to avoid bogus intersections. |
bsalomon@google.com | d302f14 | 2011-03-03 13:54:13 +0000 | [diff] [blame] | 114 | // We might consider a more exact clip to viewport if this |
bsalomon@google.com | 86afc2a | 2011-02-16 16:12:19 +0000 | [diff] [blame] | 115 | // conservative test fails. |
| 116 | const GrRenderTarget* target = this->getRenderTarget(); |
| 117 | if (0 >= clipRect.fLeft) { |
| 118 | clipRect.fLeft = GR_ScalarMin; |
| 119 | } |
| 120 | if (target->width() <= clipRect.fRight) { |
| 121 | clipRect.fRight = GR_ScalarMax; |
| 122 | } |
| 123 | if (0 >= clipRect.top()) { |
| 124 | clipRect.fTop = GR_ScalarMin; |
| 125 | } |
| 126 | if (target->height() <= clipRect.fBottom) { |
| 127 | clipRect.fBottom = GR_ScalarMax; |
| 128 | } |
| 129 | int stride = VertexSize(layout); |
| 130 | bool insideClip = true; |
| 131 | for (int v = 0; v < 4; ++v) { |
| 132 | const GrPoint& p = *GetVertexPoint(geo.vertices(), v, stride); |
| 133 | if (!clipRect.contains(p)) { |
| 134 | insideClip = false; |
| 135 | break; |
| 136 | } |
| 137 | } |
| 138 | if (insideClip) { |
| 139 | this->disableState(kClip_StateBit); |
| 140 | disabledClip = true; |
| 141 | } |
| 142 | } |
bsalomon@google.com | d302f14 | 2011-03-03 13:54:13 +0000 | [diff] [blame] | 143 | if (!needsNewClip() && !needsNewState() && fCurrQuad > 0 && |
bsalomon@google.com | 86afc2a | 2011-02-16 16:12:19 +0000 | [diff] [blame] | 144 | fCurrQuad < fMaxQuads && layout == fLastRectVertexLayout) { |
| 145 | |
| 146 | int vsize = VertexSize(layout); |
bsalomon@google.com | d302f14 | 2011-03-03 13:54:13 +0000 | [diff] [blame] | 147 | |
bsalomon@google.com | 86afc2a | 2011-02-16 16:12:19 +0000 | [diff] [blame] | 148 | Draw& lastDraw = fDraws.back(); |
| 149 | |
| 150 | GrAssert(lastDraw.fIndexBuffer == fQuadIndexBuffer); |
| 151 | GrAssert(kTriangles_PrimitiveType == lastDraw.fPrimitiveType); |
| 152 | GrAssert(0 == lastDraw.fVertexCount % 4); |
| 153 | GrAssert(0 == lastDraw.fIndexCount % 6); |
| 154 | GrAssert(0 == lastDraw.fStartIndex); |
| 155 | |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 156 | GeometryPoolState& poolState = fGeoPoolStateStack.back(); |
bsalomon@google.com | 6aa25c3 | 2011-04-27 19:55:29 +0000 | [diff] [blame] | 157 | bool clearSinceLastDraw = |
| 158 | fClears.count() && |
| 159 | fClears.back().fBeforeDrawIdx == fDraws.count(); |
| 160 | |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 161 | appendToPreviousDraw = |
| 162 | !clearSinceLastDraw && |
| 163 | lastDraw.fVertexBuffer == poolState.fPoolVertexBuffer && |
| 164 | (fCurrQuad * 4 + lastDraw.fStartVertex) == poolState.fPoolStartVertex; |
| 165 | |
bsalomon@google.com | 86afc2a | 2011-02-16 16:12:19 +0000 | [diff] [blame] | 166 | if (appendToPreviousDraw) { |
| 167 | lastDraw.fVertexCount += 4; |
| 168 | lastDraw.fIndexCount += 6; |
| 169 | fCurrQuad += 1; |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 170 | // we reserved above, so we should be the first |
| 171 | // use of this vertex reserveation. |
| 172 | GrAssert(0 == poolState.fUsedPoolVertexBytes); |
| 173 | poolState.fUsedPoolVertexBytes = 4 * vsize; |
bsalomon@google.com | 86afc2a | 2011-02-16 16:12:19 +0000 | [diff] [blame] | 174 | } |
| 175 | } |
| 176 | if (!appendToPreviousDraw) { |
| 177 | this->setIndexSourceToBuffer(fQuadIndexBuffer); |
| 178 | drawIndexed(kTriangles_PrimitiveType, 0, 0, 4, 6); |
| 179 | fCurrQuad = 1; |
| 180 | fLastRectVertexLayout = layout; |
| 181 | } |
| 182 | if (disabledClip) { |
| 183 | this->enableState(kClip_StateBit); |
| 184 | } |
bsalomon@google.com | 86afc2a | 2011-02-16 16:12:19 +0000 | [diff] [blame] | 185 | } else { |
bsalomon@google.com | ffca400 | 2011-02-22 20:34:01 +0000 | [diff] [blame] | 186 | INHERITED::drawRect(rect, matrix, stageEnableBitfield, srcRects, srcMatrices); |
bsalomon@google.com | 86afc2a | 2011-02-16 16:12:19 +0000 | [diff] [blame] | 187 | } |
| 188 | } |
| 189 | |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 190 | void GrInOrderDrawBuffer::onDrawIndexed(GrPrimitiveType primitiveType, |
| 191 | int startVertex, |
| 192 | int startIndex, |
| 193 | int vertexCount, |
| 194 | int indexCount) { |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 195 | |
| 196 | if (!vertexCount || !indexCount) { |
| 197 | return; |
| 198 | } |
| 199 | |
bsalomon@google.com | 86afc2a | 2011-02-16 16:12:19 +0000 | [diff] [blame] | 200 | fCurrQuad = 0; |
| 201 | |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 202 | GeometryPoolState& poolState = fGeoPoolStateStack.back(); |
| 203 | |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 204 | Draw& draw = fDraws.push_back(); |
bsalomon@google.com | 1c13c96 | 2011-02-14 16:51:21 +0000 | [diff] [blame] | 205 | draw.fPrimitiveType = primitiveType; |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 206 | draw.fStartVertex = startVertex; |
| 207 | draw.fStartIndex = startIndex; |
| 208 | draw.fVertexCount = vertexCount; |
| 209 | draw.fIndexCount = indexCount; |
bsalomon@google.com | 86afc2a | 2011-02-16 16:12:19 +0000 | [diff] [blame] | 210 | |
| 211 | draw.fClipChanged = this->needsNewClip(); |
| 212 | if (draw.fClipChanged) { |
| 213 | this->pushClip(); |
| 214 | } |
| 215 | |
| 216 | draw.fStateChanged = this->needsNewState(); |
| 217 | if (draw.fStateChanged) { |
| 218 | this->pushState(); |
| 219 | } |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 220 | |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 221 | draw.fVertexLayout = this->getGeomSrc().fVertexLayout; |
| 222 | switch (this->getGeomSrc().fVertexSrc) { |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 223 | case kBuffer_GeometrySrcType: |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 224 | draw.fVertexBuffer = this->getGeomSrc().fVertexBuffer; |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 225 | break; |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 226 | case kReserved_GeometrySrcType: // fallthrough |
| 227 | case kArray_GeometrySrcType: { |
bsalomon@google.com | 1c13c96 | 2011-02-14 16:51:21 +0000 | [diff] [blame] | 228 | size_t vertexBytes = (vertexCount + startVertex) * |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 229 | VertexSize(this->getGeomSrc().fVertexLayout); |
| 230 | poolState.fUsedPoolVertexBytes = |
| 231 | GrMax(poolState.fUsedPoolVertexBytes, vertexBytes); |
| 232 | draw.fVertexBuffer = poolState.fPoolVertexBuffer; |
| 233 | draw.fStartVertex += poolState.fPoolStartVertex; |
bsalomon@google.com | 1c13c96 | 2011-02-14 16:51:21 +0000 | [diff] [blame] | 234 | break; |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 235 | } |
bsalomon@google.com | 1c13c96 | 2011-02-14 16:51:21 +0000 | [diff] [blame] | 236 | default: |
| 237 | GrCrash("unknown geom src type"); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 238 | } |
bsalomon@google.com | 86afc2a | 2011-02-16 16:12:19 +0000 | [diff] [blame] | 239 | draw.fVertexBuffer->ref(); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 240 | |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 241 | switch (this->getGeomSrc().fIndexSrc) { |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 242 | case kBuffer_GeometrySrcType: |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 243 | draw.fIndexBuffer = this->getGeomSrc().fIndexBuffer; |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 244 | break; |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 245 | case kReserved_GeometrySrcType: // fallthrough |
| 246 | case kArray_GeometrySrcType: { |
bsalomon@google.com | 1c13c96 | 2011-02-14 16:51:21 +0000 | [diff] [blame] | 247 | size_t indexBytes = (indexCount + startIndex) * sizeof(uint16_t); |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 248 | poolState.fUsedPoolIndexBytes = |
| 249 | GrMax(poolState.fUsedPoolIndexBytes, indexBytes); |
| 250 | draw.fIndexBuffer = poolState.fPoolIndexBuffer; |
| 251 | draw.fStartIndex += poolState.fPoolStartVertex; |
bsalomon@google.com | 1c13c96 | 2011-02-14 16:51:21 +0000 | [diff] [blame] | 252 | break; |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 253 | } |
bsalomon@google.com | 1c13c96 | 2011-02-14 16:51:21 +0000 | [diff] [blame] | 254 | default: |
| 255 | GrCrash("unknown geom src type"); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 256 | } |
bsalomon@google.com | 86afc2a | 2011-02-16 16:12:19 +0000 | [diff] [blame] | 257 | draw.fIndexBuffer->ref(); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 258 | } |
| 259 | |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 260 | void GrInOrderDrawBuffer::onDrawNonIndexed(GrPrimitiveType primitiveType, |
| 261 | int startVertex, |
| 262 | int vertexCount) { |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 263 | if (!vertexCount) { |
| 264 | return; |
| 265 | } |
| 266 | |
bsalomon@google.com | 86afc2a | 2011-02-16 16:12:19 +0000 | [diff] [blame] | 267 | fCurrQuad = 0; |
| 268 | |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 269 | GeometryPoolState& poolState = fGeoPoolStateStack.back(); |
| 270 | |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 271 | Draw& draw = fDraws.push_back(); |
bsalomon@google.com | 1c13c96 | 2011-02-14 16:51:21 +0000 | [diff] [blame] | 272 | draw.fPrimitiveType = primitiveType; |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 273 | draw.fStartVertex = startVertex; |
| 274 | draw.fStartIndex = 0; |
| 275 | draw.fVertexCount = vertexCount; |
| 276 | draw.fIndexCount = 0; |
| 277 | |
bsalomon@google.com | 86afc2a | 2011-02-16 16:12:19 +0000 | [diff] [blame] | 278 | draw.fClipChanged = this->needsNewClip(); |
| 279 | if (draw.fClipChanged) { |
| 280 | this->pushClip(); |
| 281 | } |
| 282 | |
| 283 | draw.fStateChanged = this->needsNewState(); |
| 284 | if (draw.fStateChanged) { |
| 285 | this->pushState(); |
| 286 | } |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 287 | |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 288 | draw.fVertexLayout = this->getGeomSrc().fVertexLayout; |
| 289 | switch (this->getGeomSrc().fVertexSrc) { |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 290 | case kBuffer_GeometrySrcType: |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 291 | draw.fVertexBuffer = this->getGeomSrc().fVertexBuffer; |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 292 | break; |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 293 | case kReserved_GeometrySrcType: // fallthrough |
| 294 | case kArray_GeometrySrcType: { |
bsalomon@google.com | 1c13c96 | 2011-02-14 16:51:21 +0000 | [diff] [blame] | 295 | size_t vertexBytes = (vertexCount + startVertex) * |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 296 | VertexSize(this->getGeomSrc().fVertexLayout); |
| 297 | poolState.fUsedPoolVertexBytes = |
| 298 | GrMax(poolState.fUsedPoolVertexBytes, vertexBytes); |
| 299 | draw.fVertexBuffer = poolState.fPoolVertexBuffer; |
| 300 | draw.fStartVertex += poolState.fPoolStartVertex; |
bsalomon@google.com | 1c13c96 | 2011-02-14 16:51:21 +0000 | [diff] [blame] | 301 | break; |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 302 | } |
bsalomon@google.com | 1c13c96 | 2011-02-14 16:51:21 +0000 | [diff] [blame] | 303 | default: |
| 304 | GrCrash("unknown geom src type"); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 305 | } |
bsalomon@google.com | 86afc2a | 2011-02-16 16:12:19 +0000 | [diff] [blame] | 306 | draw.fVertexBuffer->ref(); |
| 307 | draw.fIndexBuffer = NULL; |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 308 | } |
| 309 | |
bsalomon@google.com | 6aa25c3 | 2011-04-27 19:55:29 +0000 | [diff] [blame] | 310 | void GrInOrderDrawBuffer::clear(const GrIRect* rect, GrColor color) { |
| 311 | GrIRect r; |
| 312 | if (NULL == rect) { |
| 313 | // We could do something smart and remove previous draws and clears to |
| 314 | // the current render target. If we get that smart we have to make sure |
| 315 | // those draws aren't read before this clear (render-to-texture). |
| 316 | r.setLTRB(0, 0, |
| 317 | this->getRenderTarget()->width(), |
| 318 | this->getRenderTarget()->height()); |
| 319 | rect = &r; |
| 320 | } |
bsalomon@google.com | 0b335c1 | 2011-04-25 19:17:44 +0000 | [diff] [blame] | 321 | Clear& clr = fClears.push_back(); |
| 322 | clr.fColor = color; |
| 323 | clr.fBeforeDrawIdx = fDraws.count(); |
bsalomon@google.com | 6aa25c3 | 2011-04-27 19:55:29 +0000 | [diff] [blame] | 324 | clr.fRect = *rect; |
bsalomon@google.com | 0b335c1 | 2011-04-25 19:17:44 +0000 | [diff] [blame] | 325 | } |
| 326 | |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 327 | void GrInOrderDrawBuffer::reset() { |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 328 | GrAssert(1 == fGeoPoolStateStack.count()); |
| 329 | this->resetVertexSource(); |
| 330 | this->resetIndexSource(); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 331 | uint32_t numStates = fStates.count(); |
| 332 | for (uint32_t i = 0; i < numStates; ++i) { |
bsalomon@google.com | 1da0746 | 2011-03-10 14:51:57 +0000 | [diff] [blame] | 333 | const DrState& dstate = this->accessSavedDrawState(fStates[i]); |
bsalomon@google.com | 8531c1c | 2011-01-13 19:52:45 +0000 | [diff] [blame] | 334 | for (int s = 0; s < kNumStages; ++s) { |
bsalomon@google.com | 1da0746 | 2011-03-10 14:51:57 +0000 | [diff] [blame] | 335 | GrSafeUnref(dstate.fTextures[s]); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 336 | } |
bsalomon@google.com | 1da0746 | 2011-03-10 14:51:57 +0000 | [diff] [blame] | 337 | GrSafeUnref(dstate.fRenderTarget); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 338 | } |
bsalomon@google.com | 86afc2a | 2011-02-16 16:12:19 +0000 | [diff] [blame] | 339 | int numDraws = fDraws.count(); |
| 340 | for (int d = 0; d < numDraws; ++d) { |
| 341 | // we always have a VB, but not always an IB |
| 342 | GrAssert(NULL != fDraws[d].fVertexBuffer); |
| 343 | fDraws[d].fVertexBuffer->unref(); |
| 344 | GrSafeUnref(fDraws[d].fIndexBuffer); |
| 345 | } |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 346 | fDraws.reset(); |
| 347 | fStates.reset(); |
bsalomon@google.com | 1c13c96 | 2011-02-14 16:51:21 +0000 | [diff] [blame] | 348 | |
bsalomon@google.com | 0b335c1 | 2011-04-25 19:17:44 +0000 | [diff] [blame] | 349 | fClears.reset(); |
| 350 | |
bsalomon@google.com | 1c13c96 | 2011-02-14 16:51:21 +0000 | [diff] [blame] | 351 | fVertexPool.reset(); |
| 352 | fIndexPool.reset(); |
| 353 | |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 354 | fClips.reset(); |
bsalomon@google.com | 86afc2a | 2011-02-16 16:12:19 +0000 | [diff] [blame] | 355 | |
| 356 | fCurrQuad = 0; |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 357 | } |
| 358 | |
| 359 | void GrInOrderDrawBuffer::playback(GrDrawTarget* target) { |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 360 | GrAssert(kReserved_GeometrySrcType != this->getGeomSrc().fVertexSrc); |
| 361 | GrAssert(kReserved_GeometrySrcType != this->getGeomSrc().fIndexSrc); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 362 | GrAssert(NULL != target); |
| 363 | GrAssert(target != this); // not considered and why? |
| 364 | |
bsalomon@google.com | 898d9e5 | 2011-04-26 13:22:33 +0000 | [diff] [blame] | 365 | int numDraws = fDraws.count(); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 366 | if (!numDraws) { |
| 367 | return; |
| 368 | } |
| 369 | |
bsalomon@google.com | 1c13c96 | 2011-02-14 16:51:21 +0000 | [diff] [blame] | 370 | fVertexPool.unlock(); |
| 371 | fIndexPool.unlock(); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 372 | |
| 373 | GrDrawTarget::AutoStateRestore asr(target); |
| 374 | GrDrawTarget::AutoClipRestore acr(target); |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 375 | AutoGeometryPush agp(target); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 376 | |
bsalomon@google.com | 6a77cc5 | 2011-04-28 17:33:34 +0000 | [diff] [blame] | 377 | int currState = ~0; |
| 378 | int currClip = ~0; |
| 379 | int currClear = 0; |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 380 | |
bsalomon@google.com | 898d9e5 | 2011-04-26 13:22:33 +0000 | [diff] [blame] | 381 | for (int i = 0; i < numDraws; ++i) { |
bsalomon@google.com | 0b335c1 | 2011-04-25 19:17:44 +0000 | [diff] [blame] | 382 | while (currClear < fClears.count() && |
| 383 | i == fClears[currClear].fBeforeDrawIdx) { |
bsalomon@google.com | 6aa25c3 | 2011-04-27 19:55:29 +0000 | [diff] [blame] | 384 | target->clear(&fClears[currClear].fRect, fClears[currClear].fColor); |
bsalomon@google.com | 0b335c1 | 2011-04-25 19:17:44 +0000 | [diff] [blame] | 385 | ++currClear; |
| 386 | } |
| 387 | |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 388 | const Draw& draw = fDraws[i]; |
bsalomon@google.com | 1c13c96 | 2011-02-14 16:51:21 +0000 | [diff] [blame] | 389 | if (draw.fStateChanged) { |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 390 | ++currState; |
| 391 | target->restoreDrawState(fStates[currState]); |
| 392 | } |
| 393 | if (draw.fClipChanged) { |
| 394 | ++currClip; |
| 395 | target->setClip(fClips[currClip]); |
| 396 | } |
bsalomon@google.com | 1c13c96 | 2011-02-14 16:51:21 +0000 | [diff] [blame] | 397 | |
| 398 | target->setVertexSourceToBuffer(draw.fVertexLayout, draw.fVertexBuffer); |
| 399 | |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 400 | if (draw.fIndexCount) { |
bsalomon@google.com | 1c13c96 | 2011-02-14 16:51:21 +0000 | [diff] [blame] | 401 | target->setIndexSourceToBuffer(draw.fIndexBuffer); |
| 402 | } |
| 403 | |
| 404 | if (draw.fIndexCount) { |
| 405 | target->drawIndexed(draw.fPrimitiveType, |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 406 | draw.fStartVertex, |
| 407 | draw.fStartIndex, |
| 408 | draw.fVertexCount, |
| 409 | draw.fIndexCount); |
| 410 | } else { |
bsalomon@google.com | 1c13c96 | 2011-02-14 16:51:21 +0000 | [diff] [blame] | 411 | target->drawNonIndexed(draw.fPrimitiveType, |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 412 | draw.fStartVertex, |
| 413 | draw.fVertexCount); |
| 414 | } |
| 415 | } |
bsalomon@google.com | 0b335c1 | 2011-04-25 19:17:44 +0000 | [diff] [blame] | 416 | while (currClear < fClears.count()) { |
| 417 | GrAssert(fDraws.count() == fClears[currClear].fBeforeDrawIdx); |
bsalomon@google.com | 6aa25c3 | 2011-04-27 19:55:29 +0000 | [diff] [blame] | 418 | target->clear(&fClears[currClear].fRect, fClears[currClear].fColor); |
bsalomon@google.com | 0b335c1 | 2011-04-25 19:17:44 +0000 | [diff] [blame] | 419 | ++currClear; |
| 420 | } |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 421 | } |
| 422 | |
| 423 | bool GrInOrderDrawBuffer::geometryHints(GrVertexLayout vertexLayout, |
bsalomon@google.com | 1c13c96 | 2011-02-14 16:51:21 +0000 | [diff] [blame] | 424 | int* vertexCount, |
| 425 | int* indexCount) const { |
| 426 | // we will recommend a flush if the data could fit in a single |
| 427 | // preallocated buffer but none are left and it can't fit |
| 428 | // in the current buffer (which may not be prealloced). |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 429 | bool flush = false; |
| 430 | if (NULL != indexCount) { |
bsalomon@google.com | 1c13c96 | 2011-02-14 16:51:21 +0000 | [diff] [blame] | 431 | int32_t currIndices = fIndexPool.currentBufferIndices(); |
| 432 | if (*indexCount > currIndices && |
| 433 | (!fIndexPool.preallocatedBuffersRemaining() && |
| 434 | *indexCount <= fIndexPool.preallocatedBufferIndices())) { |
| 435 | |
| 436 | flush = true; |
| 437 | } |
| 438 | *indexCount = currIndices; |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 439 | } |
| 440 | if (NULL != vertexCount) { |
bsalomon@google.com | 1c13c96 | 2011-02-14 16:51:21 +0000 | [diff] [blame] | 441 | int32_t currVertices = fVertexPool.currentBufferVertices(vertexLayout); |
| 442 | if (*vertexCount > currVertices && |
| 443 | (!fVertexPool.preallocatedBuffersRemaining() && |
| 444 | *vertexCount <= fVertexPool.preallocatedBufferVertices(vertexLayout))) { |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 445 | |
bsalomon@google.com | 1c13c96 | 2011-02-14 16:51:21 +0000 | [diff] [blame] | 446 | flush = true; |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 447 | } |
bsalomon@google.com | 1c13c96 | 2011-02-14 16:51:21 +0000 | [diff] [blame] | 448 | *vertexCount = currVertices; |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 449 | } |
| 450 | return flush; |
| 451 | } |
| 452 | |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 453 | bool GrInOrderDrawBuffer::onReserveVertexSpace(GrVertexLayout vertexLayout, |
| 454 | int vertexCount, |
| 455 | void** vertices) { |
| 456 | GeometryPoolState& poolState = fGeoPoolStateStack.back(); |
| 457 | GrAssert(vertexCount > 0); |
| 458 | GrAssert(NULL != vertices); |
| 459 | GrAssert(0 == poolState.fUsedPoolVertexBytes); |
| 460 | |
| 461 | *vertices = fVertexPool.makeSpace(vertexLayout, |
| 462 | vertexCount, |
| 463 | &poolState.fPoolVertexBuffer, |
| 464 | &poolState.fPoolStartVertex); |
| 465 | return NULL != *vertices; |
| 466 | } |
| 467 | |
| 468 | bool GrInOrderDrawBuffer::onReserveIndexSpace(int indexCount, void** indices) { |
| 469 | GeometryPoolState& poolState = fGeoPoolStateStack.back(); |
| 470 | GrAssert(indexCount > 0); |
| 471 | GrAssert(NULL != indices); |
| 472 | GrAssert(0 == poolState.fUsedPoolIndexBytes); |
bsalomon@google.com | 1c13c96 | 2011-02-14 16:51:21 +0000 | [diff] [blame] | 473 | |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 474 | *indices = fIndexPool.makeSpace(indexCount, |
| 475 | &poolState.fPoolIndexBuffer, |
| 476 | &poolState.fPoolStartIndex); |
| 477 | return NULL != *indices; |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 478 | } |
| 479 | |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 480 | void GrInOrderDrawBuffer::releaseReservedVertexSpace() { |
| 481 | GeometryPoolState& poolState = fGeoPoolStateStack.back(); |
| 482 | const GeometrySrcState& geoSrc = this->getGeomSrc(); |
| 483 | |
| 484 | GrAssert(kReserved_GeometrySrcType == geoSrc.fVertexSrc); |
| 485 | |
| 486 | size_t reservedVertexBytes = VertexSize(geoSrc.fVertexLayout) * |
| 487 | geoSrc.fVertexCount; |
| 488 | fVertexPool.putBack(reservedVertexBytes - |
| 489 | poolState.fUsedPoolVertexBytes); |
| 490 | poolState.fUsedPoolVertexBytes = 0; |
| 491 | poolState.fPoolVertexBuffer = 0; |
bsalomon@google.com | 1c13c96 | 2011-02-14 16:51:21 +0000 | [diff] [blame] | 492 | } |
| 493 | |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 494 | void GrInOrderDrawBuffer::releaseReservedIndexSpace() { |
| 495 | GeometryPoolState& poolState = fGeoPoolStateStack.back(); |
| 496 | const GeometrySrcState& geoSrc = this->getGeomSrc(); |
| 497 | |
| 498 | GrAssert(kReserved_GeometrySrcType == geoSrc.fIndexSrc); |
| 499 | |
| 500 | size_t reservedIndexBytes = sizeof(uint16_t) * geoSrc.fIndexCount; |
| 501 | fIndexPool.putBack(reservedIndexBytes - poolState.fUsedPoolIndexBytes); |
| 502 | poolState.fUsedPoolIndexBytes = 0; |
| 503 | poolState.fPoolStartVertex = 0; |
| 504 | } |
| 505 | |
bsalomon@google.com | bcdbbe6 | 2011-04-12 15:40:00 +0000 | [diff] [blame] | 506 | void GrInOrderDrawBuffer::onSetVertexSourceToArray(const void* vertexArray, |
| 507 | int vertexCount) { |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 508 | |
| 509 | GeometryPoolState& poolState = fGeoPoolStateStack.back(); |
| 510 | GrAssert(0 == poolState.fUsedPoolVertexBytes); |
bsalomon@google.com | 1c13c96 | 2011-02-14 16:51:21 +0000 | [diff] [blame] | 511 | #if GR_DEBUG |
| 512 | bool success = |
| 513 | #endif |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 514 | fVertexPool.appendVertices(this->getGeomSrc().fVertexLayout, |
bsalomon@google.com | 1c13c96 | 2011-02-14 16:51:21 +0000 | [diff] [blame] | 515 | vertexCount, |
| 516 | vertexArray, |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 517 | &poolState.fPoolVertexBuffer, |
| 518 | &poolState.fPoolStartVertex); |
bsalomon@google.com | 1c13c96 | 2011-02-14 16:51:21 +0000 | [diff] [blame] | 519 | GR_DEBUGASSERT(success); |
| 520 | } |
| 521 | |
bsalomon@google.com | bcdbbe6 | 2011-04-12 15:40:00 +0000 | [diff] [blame] | 522 | void GrInOrderDrawBuffer::onSetIndexSourceToArray(const void* indexArray, |
| 523 | int indexCount) { |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 524 | GeometryPoolState& poolState = fGeoPoolStateStack.back(); |
| 525 | GrAssert(0 == poolState.fUsedPoolIndexBytes); |
bsalomon@google.com | 1c13c96 | 2011-02-14 16:51:21 +0000 | [diff] [blame] | 526 | #if GR_DEBUG |
| 527 | bool success = |
| 528 | #endif |
| 529 | fIndexPool.appendIndices(indexCount, |
| 530 | indexArray, |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 531 | &poolState.fPoolIndexBuffer, |
| 532 | &poolState.fPoolStartIndex); |
bsalomon@google.com | 1c13c96 | 2011-02-14 16:51:21 +0000 | [diff] [blame] | 533 | GR_DEBUGASSERT(success); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 534 | } |
| 535 | |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 536 | void GrInOrderDrawBuffer::geometrySourceWillPush() { |
| 537 | GeometryPoolState& poolState = fGeoPoolStateStack.push_back(); |
| 538 | poolState.fUsedPoolVertexBytes = 0; |
| 539 | poolState.fUsedPoolIndexBytes = 0; |
| 540 | #if GR_DEBUG |
| 541 | poolState.fPoolVertexBuffer = (GrVertexBuffer*)~0; |
| 542 | poolState.fPoolStartVertex = ~0; |
| 543 | poolState.fPoolIndexBuffer = (GrIndexBuffer*)~0; |
| 544 | poolState.fPoolStartIndex = ~0; |
| 545 | #endif |
| 546 | } |
| 547 | |
| 548 | void GrInOrderDrawBuffer::releaseVertexArray() { |
| 549 | GeometryPoolState& poolState = fGeoPoolStateStack.back(); |
| 550 | const GeometrySrcState& geoSrc = this->getGeomSrc(); |
| 551 | |
| 552 | size_t reservedVertexBytes = VertexSize(geoSrc.fVertexLayout) * |
| 553 | geoSrc.fVertexCount; |
| 554 | fVertexPool.putBack(reservedVertexBytes - poolState.fUsedPoolVertexBytes); |
| 555 | |
| 556 | poolState.fUsedPoolVertexBytes = 0; |
| 557 | } |
| 558 | |
| 559 | void GrInOrderDrawBuffer::releaseIndexArray() { |
| 560 | GeometryPoolState& poolState = fGeoPoolStateStack.back(); |
| 561 | const GeometrySrcState& geoSrc = this->getGeomSrc(); |
| 562 | |
| 563 | size_t reservedIndexBytes = sizeof(uint16_t) * geoSrc.fIndexCount; |
| 564 | fIndexPool.putBack(reservedIndexBytes - poolState.fUsedPoolIndexBytes); |
| 565 | |
| 566 | poolState.fUsedPoolIndexBytes = 0; |
| 567 | } |
| 568 | |
| 569 | void GrInOrderDrawBuffer::geometrySourceWillPop( |
| 570 | const GeometrySrcState& restoredState) { |
| 571 | GrAssert(fGeoPoolStateStack.count() > 1); |
| 572 | fGeoPoolStateStack.pop_back(); |
| 573 | GeometryPoolState& poolState = fGeoPoolStateStack.back(); |
| 574 | // we have to assume that any slack we had in our vertex/index data |
| 575 | // is now unreleasable because data may have been appended later in the |
| 576 | // pool. |
| 577 | if (kReserved_GeometrySrcType == restoredState.fVertexSrc || |
| 578 | kArray_GeometrySrcType == restoredState.fVertexSrc) { |
| 579 | poolState.fUsedPoolVertexBytes = |
| 580 | VertexSize(restoredState.fVertexLayout) * |
| 581 | restoredState.fVertexCount; |
| 582 | } |
| 583 | if (kReserved_GeometrySrcType == restoredState.fIndexSrc || |
| 584 | kArray_GeometrySrcType == restoredState.fIndexSrc) { |
| 585 | poolState.fUsedPoolVertexBytes = sizeof(uint16_t) * |
| 586 | restoredState.fIndexCount; |
| 587 | } |
| 588 | } |
| 589 | |
bsalomon@google.com | 86afc2a | 2011-02-16 16:12:19 +0000 | [diff] [blame] | 590 | bool GrInOrderDrawBuffer::needsNewState() const { |
| 591 | if (fStates.empty()) { |
| 592 | return true; |
| 593 | } else { |
| 594 | const DrState& old = this->accessSavedDrawState(fStates.back()); |
| 595 | return old != fCurrDrawState; |
| 596 | } |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 597 | } |
| 598 | |
bsalomon@google.com | 86afc2a | 2011-02-16 16:12:19 +0000 | [diff] [blame] | 599 | void GrInOrderDrawBuffer::pushState() { |
| 600 | for (int s = 0; s < kNumStages; ++s) { |
| 601 | GrSafeRef(fCurrDrawState.fTextures[s]); |
| 602 | } |
bsalomon@google.com | 1da0746 | 2011-03-10 14:51:57 +0000 | [diff] [blame] | 603 | GrSafeRef(fCurrDrawState.fRenderTarget); |
bsalomon@google.com | 86afc2a | 2011-02-16 16:12:19 +0000 | [diff] [blame] | 604 | this->saveCurrentDrawState(&fStates.push_back()); |
| 605 | } |
bsalomon@google.com | d302f14 | 2011-03-03 13:54:13 +0000 | [diff] [blame] | 606 | |
bsalomon@google.com | 86afc2a | 2011-02-16 16:12:19 +0000 | [diff] [blame] | 607 | bool GrInOrderDrawBuffer::needsNewClip() const { |
| 608 | if (fCurrDrawState.fFlagBits & kClip_StateBit) { |
| 609 | if (fClips.empty() || (fClipSet && fClips.back() != fClip)) { |
| 610 | return true; |
| 611 | } |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 612 | } |
| 613 | return false; |
| 614 | } |
bsalomon@google.com | d302f14 | 2011-03-03 13:54:13 +0000 | [diff] [blame] | 615 | |
bsalomon@google.com | 86afc2a | 2011-02-16 16:12:19 +0000 | [diff] [blame] | 616 | void GrInOrderDrawBuffer::pushClip() { |
| 617 | fClips.push_back() = fClip; |
| 618 | fClipSet = false; |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 619 | } |
bsalomon@google.com | d302f14 | 2011-03-03 13:54:13 +0000 | [diff] [blame] | 620 | |
bsalomon@google.com | dea2f8d | 2011-08-01 15:51:05 +0000 | [diff] [blame] | 621 | void GrInOrderDrawBuffer::clipWillBeSet(const GrClip& newClip) { |
| 622 | INHERITED::clipWillBeSet(newClip); |
bsalomon@google.com | 86afc2a | 2011-02-16 16:12:19 +0000 | [diff] [blame] | 623 | fClipSet = true; |
| 624 | } |
bsalomon@google.com | 471d471 | 2011-08-23 15:45:25 +0000 | [diff] [blame] | 625 | |
| 626 | bool GrInOrderDrawBuffer::willUseHWAALines() const { |
bsalomon@google.com | 18c9c19 | 2011-09-22 21:01:31 +0000 | [diff] [blame] | 627 | return this->getCaps().fHWAALineSupport && |
bsalomon@google.com | 471d471 | 2011-08-23 15:45:25 +0000 | [diff] [blame] | 628 | CanUseHWAALines(this->getGeomSrc().fVertexLayout, fCurrDrawState); |
| 629 | } |
| 630 | |