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