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