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