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 | |
| 10 | #include "GrInOrderDrawBuffer.h" |
bsalomon@google.com | ded4f4b | 2012-06-28 18:48:06 +0000 | [diff] [blame] | 11 | #include "GrBufferAllocPool.h" |
| 12 | #include "GrGpu.h" |
| 13 | #include "GrIndexBuffer.h" |
| 14 | #include "GrPath.h" |
bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 15 | #include "GrRenderTarget.h" |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 16 | #include "GrTexture.h" |
bsalomon@google.com | 86afc2a | 2011-02-16 16:12:19 +0000 | [diff] [blame] | 17 | #include "GrVertexBuffer.h" |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 18 | |
bsalomon@google.com | 471d471 | 2011-08-23 15:45:25 +0000 | [diff] [blame] | 19 | GrInOrderDrawBuffer::GrInOrderDrawBuffer(const GrGpu* gpu, |
| 20 | GrVertexBufferAllocPool* vertexPool, |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 21 | GrIndexBufferAllocPool* indexPool) |
bsalomon@google.com | 9780538 | 2012-03-13 14:32:07 +0000 | [diff] [blame] | 22 | : fAutoFlushTarget(NULL) |
| 23 | , fClipSet(true) |
robertphillips@google.com | 6970557 | 2012-03-21 19:46:50 +0000 | [diff] [blame] | 24 | , fVertexPool(*vertexPool) |
| 25 | , fIndexPool(*indexPool) |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 26 | , fLastRectVertexLayout(0) |
| 27 | , fQuadIndexBuffer(NULL) |
| 28 | , fMaxQuads(0) |
robertphillips@google.com | c82a8b7 | 2012-06-21 20:15:48 +0000 | [diff] [blame] | 29 | , fFlushing(false) { |
bsalomon@google.com | 18c9c19 | 2011-09-22 21:01:31 +0000 | [diff] [blame] | 30 | |
| 31 | fCaps = gpu->getCaps(); |
| 32 | |
bsalomon@google.com | 1c13c96 | 2011-02-14 16:51:21 +0000 | [diff] [blame] | 33 | GrAssert(NULL != vertexPool); |
| 34 | GrAssert(NULL != indexPool); |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 35 | |
| 36 | GeometryPoolState& poolState = fGeoPoolStateStack.push_back(); |
| 37 | poolState.fUsedPoolVertexBytes = 0; |
| 38 | poolState.fUsedPoolIndexBytes = 0; |
| 39 | #if GR_DEBUG |
| 40 | poolState.fPoolVertexBuffer = (GrVertexBuffer*)~0; |
| 41 | poolState.fPoolStartVertex = ~0; |
| 42 | poolState.fPoolIndexBuffer = (GrIndexBuffer*)~0; |
| 43 | poolState.fPoolStartIndex = ~0; |
| 44 | #endif |
bsalomon@google.com | a4f6b10 | 2012-06-26 21:04:22 +0000 | [diff] [blame] | 45 | this->reset(); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 46 | } |
| 47 | |
| 48 | GrInOrderDrawBuffer::~GrInOrderDrawBuffer() { |
bsalomon@google.com | 86afc2a | 2011-02-16 16:12:19 +0000 | [diff] [blame] | 49 | this->reset(); |
bsalomon@google.com | 4a018bb | 2011-10-28 19:50:21 +0000 | [diff] [blame] | 50 | // This must be called by before the GrDrawTarget destructor |
| 51 | this->releaseGeometry(); |
bsalomon@google.com | 86afc2a | 2011-02-16 16:12:19 +0000 | [diff] [blame] | 52 | GrSafeUnref(fQuadIndexBuffer); |
bsalomon@google.com | 9780538 | 2012-03-13 14:32:07 +0000 | [diff] [blame] | 53 | GrSafeUnref(fAutoFlushTarget); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 54 | } |
| 55 | |
bsalomon@google.com | 86afc2a | 2011-02-16 16:12:19 +0000 | [diff] [blame] | 56 | void GrInOrderDrawBuffer::setQuadIndexBuffer(const GrIndexBuffer* indexBuffer) { |
| 57 | bool newIdxBuffer = fQuadIndexBuffer != indexBuffer; |
| 58 | if (newIdxBuffer) { |
| 59 | GrSafeUnref(fQuadIndexBuffer); |
| 60 | fQuadIndexBuffer = indexBuffer; |
| 61 | GrSafeRef(fQuadIndexBuffer); |
| 62 | fCurrQuad = 0; |
| 63 | fMaxQuads = (NULL == indexBuffer) ? 0 : indexBuffer->maxQuads(); |
| 64 | } else { |
bsalomon@google.com | d302f14 | 2011-03-03 13:54:13 +0000 | [diff] [blame] | 65 | GrAssert((NULL == indexBuffer && 0 == fMaxQuads) || |
bsalomon@google.com | 86afc2a | 2011-02-16 16:12:19 +0000 | [diff] [blame] | 66 | (indexBuffer->maxQuads() == fMaxQuads)); |
| 67 | } |
| 68 | } |
| 69 | |
bsalomon@google.com | 934c570 | 2012-03-20 21:17:58 +0000 | [diff] [blame] | 70 | //////////////////////////////////////////////////////////////////////////////// |
| 71 | |
| 72 | void GrInOrderDrawBuffer::resetDrawTracking() { |
| 73 | fCurrQuad = 0; |
| 74 | fInstancedDrawTracker.reset(); |
| 75 | } |
| 76 | |
bsalomon@google.com | d302f14 | 2011-03-03 13:54:13 +0000 | [diff] [blame] | 77 | void GrInOrderDrawBuffer::drawRect(const GrRect& rect, |
bsalomon@google.com | 86afc2a | 2011-02-16 16:12:19 +0000 | [diff] [blame] | 78 | const GrMatrix* matrix, |
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 | |
bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 86 | GrDrawState* drawState = this->drawState(); |
| 87 | |
bsalomon@google.com | 86afc2a | 2011-02-16 16:12:19 +0000 | [diff] [blame] | 88 | // if we have a quad IB then either append to the previous run of |
| 89 | // rects or start a new run |
| 90 | if (fMaxQuads) { |
bsalomon@google.com | d302f14 | 2011-03-03 13:54:13 +0000 | [diff] [blame] | 91 | |
bsalomon@google.com | 86afc2a | 2011-02-16 16:12:19 +0000 | [diff] [blame] | 92 | bool appendToPreviousDraw = false; |
bsalomon@google.com | e3d3216 | 2012-07-20 13:37:06 +0000 | [diff] [blame] | 93 | GrVertexLayout layout = GetRectVertexLayout(srcRects); |
bsalomon@google.com | 86afc2a | 2011-02-16 16:12:19 +0000 | [diff] [blame] | 94 | AutoReleaseGeometry geo(this, layout, 4, 0); |
bsalomon@google.com | 6513cd0 | 2011-08-05 20:12:30 +0000 | [diff] [blame] | 95 | if (!geo.succeeded()) { |
| 96 | GrPrintf("Failed to get space for vertices!\n"); |
| 97 | return; |
| 98 | } |
bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 99 | GrMatrix combinedMatrix = drawState->getViewMatrix(); |
bsalomon@google.com | 3f5a95e | 2012-03-08 16:41:42 +0000 | [diff] [blame] | 100 | // We go to device space so that matrix changes allow us to concat |
| 101 | // rect draws. When the caller has provided explicit source rects |
| 102 | // then we don't want to modify the sampler matrices. Otherwise we do |
| 103 | // we have to account for the view matrix change in the sampler |
| 104 | // matrices. |
bsalomon@google.com | e3d3216 | 2012-07-20 13:37:06 +0000 | [diff] [blame] | 105 | uint32_t explicitCoordMask = 0; |
| 106 | if (srcRects) { |
| 107 | for (int s = 0; s < GrDrawState::kNumStages; ++s) { |
| 108 | if (srcRects[s]) { |
| 109 | explicitCoordMask |= (1 << s); |
| 110 | } |
| 111 | } |
| 112 | } |
| 113 | GrDrawTarget::AutoDeviceCoordDraw adcd(this, explicitCoordMask); |
| 114 | if (!adcd.succeeded()) { |
| 115 | return; |
| 116 | } |
bsalomon@google.com | 86afc2a | 2011-02-16 16:12:19 +0000 | [diff] [blame] | 117 | if (NULL != matrix) { |
| 118 | combinedMatrix.preConcat(*matrix); |
| 119 | } |
| 120 | |
| 121 | SetRectVertices(rect, &combinedMatrix, srcRects, srcMatrices, layout, geo.vertices()); |
| 122 | |
| 123 | // we don't want to miss an opportunity to batch rects together |
| 124 | // simply because the clip has changed if the clip doesn't affect |
| 125 | // the rect. |
| 126 | bool disabledClip = false; |
bsalomon@google.com | d302f14 | 2011-03-03 13:54:13 +0000 | [diff] [blame] | 127 | |
robertphillips@google.com | 641f8b1 | 2012-07-31 19:15:58 +0000 | [diff] [blame] | 128 | if (drawState->isClipState()) { |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame^] | 129 | |
robertphillips@google.com | 641f8b1 | 2012-07-31 19:15:58 +0000 | [diff] [blame] | 130 | GrRect devClipRect; |
| 131 | bool isIntersectionOfRects = false; |
robertphillips@google.com | beb1af7 | 2012-07-26 18:52:16 +0000 | [diff] [blame] | 132 | |
robertphillips@google.com | 641f8b1 | 2012-07-31 19:15:58 +0000 | [diff] [blame] | 133 | fClip->fClipStack->getConservativeBounds(-fClip->fOrigin.fX, |
| 134 | -fClip->fOrigin.fY, |
| 135 | drawState->getRenderTarget()->width(), |
| 136 | drawState->getRenderTarget()->height(), |
| 137 | &devClipRect, |
| 138 | &isIntersectionOfRects); |
robertphillips@google.com | a6f11c4 | 2012-07-23 17:39:44 +0000 | [diff] [blame] | 139 | |
robertphillips@google.com | 641f8b1 | 2012-07-31 19:15:58 +0000 | [diff] [blame] | 140 | if (isIntersectionOfRects) { |
| 141 | // If the clip rect touches the edge of the viewport, extended it |
| 142 | // out (close) to infinity to avoid bogus intersections. |
| 143 | // We might consider a more exact clip to viewport if this |
| 144 | // conservative test fails. |
| 145 | const GrRenderTarget* target = drawState->getRenderTarget(); |
| 146 | if (0 >= devClipRect.fLeft) { |
| 147 | devClipRect.fLeft = GR_ScalarMin; |
| 148 | } |
| 149 | if (target->width() <= devClipRect.fRight) { |
| 150 | devClipRect.fRight = GR_ScalarMax; |
| 151 | } |
| 152 | if (0 >= devClipRect.top()) { |
| 153 | devClipRect.fTop = GR_ScalarMin; |
| 154 | } |
| 155 | if (target->height() <= devClipRect.fBottom) { |
| 156 | devClipRect.fBottom = GR_ScalarMax; |
| 157 | } |
| 158 | int stride = VertexSize(layout); |
| 159 | bool insideClip = true; |
| 160 | for (int v = 0; v < 4; ++v) { |
| 161 | const GrPoint& p = *GetVertexPoint(geo.vertices(), v, stride); |
| 162 | if (!devClipRect.contains(p)) { |
| 163 | insideClip = false; |
| 164 | break; |
| 165 | } |
| 166 | } |
| 167 | if (insideClip) { |
| 168 | drawState->disableState(GrDrawState::kClip_StateBit); |
| 169 | disabledClip = true; |
bsalomon@google.com | 86afc2a | 2011-02-16 16:12:19 +0000 | [diff] [blame] | 170 | } |
| 171 | } |
bsalomon@google.com | 86afc2a | 2011-02-16 16:12:19 +0000 | [diff] [blame] | 172 | } |
robertphillips@google.com | 641f8b1 | 2012-07-31 19:15:58 +0000 | [diff] [blame] | 173 | |
bsalomon@google.com | a4f6b10 | 2012-06-26 21:04:22 +0000 | [diff] [blame] | 174 | if (!this->needsNewClip() && |
| 175 | !this->needsNewState() && |
| 176 | fCurrQuad > 0 && |
| 177 | fCurrQuad < fMaxQuads && |
| 178 | layout == fLastRectVertexLayout) { |
bsalomon@google.com | 86afc2a | 2011-02-16 16:12:19 +0000 | [diff] [blame] | 179 | |
| 180 | int vsize = VertexSize(layout); |
bsalomon@google.com | d302f14 | 2011-03-03 13:54:13 +0000 | [diff] [blame] | 181 | |
bsalomon@google.com | 86afc2a | 2011-02-16 16:12:19 +0000 | [diff] [blame] | 182 | Draw& lastDraw = fDraws.back(); |
| 183 | |
| 184 | GrAssert(lastDraw.fIndexBuffer == fQuadIndexBuffer); |
bsalomon@google.com | 4705954 | 2012-06-06 20:51:20 +0000 | [diff] [blame] | 185 | GrAssert(kTriangles_GrPrimitiveType == lastDraw.fPrimitiveType); |
bsalomon@google.com | 86afc2a | 2011-02-16 16:12:19 +0000 | [diff] [blame] | 186 | GrAssert(0 == lastDraw.fVertexCount % 4); |
| 187 | GrAssert(0 == lastDraw.fIndexCount % 6); |
| 188 | GrAssert(0 == lastDraw.fStartIndex); |
| 189 | |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 190 | GeometryPoolState& poolState = fGeoPoolStateStack.back(); |
bsalomon@google.com | 6aa25c3 | 2011-04-27 19:55:29 +0000 | [diff] [blame] | 191 | |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame^] | 192 | appendToPreviousDraw = |
bsalomon@google.com | a4f6b10 | 2012-06-26 21:04:22 +0000 | [diff] [blame] | 193 | kDraw_Cmd != fCmds.back() && |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 194 | lastDraw.fVertexBuffer == poolState.fPoolVertexBuffer && |
| 195 | (fCurrQuad * 4 + lastDraw.fStartVertex) == poolState.fPoolStartVertex; |
| 196 | |
bsalomon@google.com | 86afc2a | 2011-02-16 16:12:19 +0000 | [diff] [blame] | 197 | if (appendToPreviousDraw) { |
| 198 | lastDraw.fVertexCount += 4; |
| 199 | lastDraw.fIndexCount += 6; |
| 200 | fCurrQuad += 1; |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 201 | // we reserved above, so we should be the first |
bsalomon@google.com | a4f6b10 | 2012-06-26 21:04:22 +0000 | [diff] [blame] | 202 | // use of this vertex reservation. |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 203 | GrAssert(0 == poolState.fUsedPoolVertexBytes); |
| 204 | poolState.fUsedPoolVertexBytes = 4 * vsize; |
bsalomon@google.com | 86afc2a | 2011-02-16 16:12:19 +0000 | [diff] [blame] | 205 | } |
| 206 | } |
| 207 | if (!appendToPreviousDraw) { |
| 208 | this->setIndexSourceToBuffer(fQuadIndexBuffer); |
bsalomon@google.com | 4705954 | 2012-06-06 20:51:20 +0000 | [diff] [blame] | 209 | this->drawIndexed(kTriangles_GrPrimitiveType, 0, 0, 4, 6); |
bsalomon@google.com | 86afc2a | 2011-02-16 16:12:19 +0000 | [diff] [blame] | 210 | fCurrQuad = 1; |
| 211 | fLastRectVertexLayout = layout; |
| 212 | } |
| 213 | if (disabledClip) { |
bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 214 | drawState->enableState(GrDrawState::kClip_StateBit); |
bsalomon@google.com | 86afc2a | 2011-02-16 16:12:19 +0000 | [diff] [blame] | 215 | } |
bsalomon@google.com | 934c570 | 2012-03-20 21:17:58 +0000 | [diff] [blame] | 216 | fInstancedDrawTracker.reset(); |
bsalomon@google.com | 86afc2a | 2011-02-16 16:12:19 +0000 | [diff] [blame] | 217 | } else { |
bsalomon@google.com | e3d3216 | 2012-07-20 13:37:06 +0000 | [diff] [blame] | 218 | INHERITED::drawRect(rect, matrix, srcRects, srcMatrices); |
bsalomon@google.com | 86afc2a | 2011-02-16 16:12:19 +0000 | [diff] [blame] | 219 | } |
| 220 | } |
| 221 | |
bsalomon@google.com | 934c570 | 2012-03-20 21:17:58 +0000 | [diff] [blame] | 222 | void GrInOrderDrawBuffer::drawIndexedInstances(GrPrimitiveType type, |
| 223 | int instanceCount, |
| 224 | int verticesPerInstance, |
| 225 | int indicesPerInstance) { |
| 226 | if (!verticesPerInstance || !indicesPerInstance) { |
| 227 | return; |
| 228 | } |
| 229 | |
| 230 | const GeometrySrcState& geomSrc = this->getGeomSrc(); |
| 231 | |
| 232 | // we only attempt to concat the case when reserved verts are used with |
| 233 | // an index buffer. |
| 234 | if (kReserved_GeometrySrcType == geomSrc.fVertexSrc && |
| 235 | kBuffer_GeometrySrcType == geomSrc.fIndexSrc) { |
| 236 | |
bsalomon@google.com | a4f6b10 | 2012-06-26 21:04:22 +0000 | [diff] [blame] | 237 | if (this->needsNewClip()) { |
| 238 | this->recordClip(); |
| 239 | } |
| 240 | if (this->needsNewState()) { |
| 241 | this->recordState(); |
| 242 | } |
| 243 | |
bsalomon@google.com | 934c570 | 2012-03-20 21:17:58 +0000 | [diff] [blame] | 244 | Draw* draw = NULL; |
| 245 | // if the last draw used the same indices/vertices per shape then we |
| 246 | // may be able to append to it. |
bsalomon@google.com | a4f6b10 | 2012-06-26 21:04:22 +0000 | [diff] [blame] | 247 | if (kDraw_Cmd == fCmds.back() && |
| 248 | verticesPerInstance == fInstancedDrawTracker.fVerticesPerInstance && |
bsalomon@google.com | 934c570 | 2012-03-20 21:17:58 +0000 | [diff] [blame] | 249 | indicesPerInstance == fInstancedDrawTracker.fIndicesPerInstance) { |
| 250 | GrAssert(fDraws.count()); |
| 251 | draw = &fDraws.back(); |
| 252 | } |
| 253 | |
bsalomon@google.com | 934c570 | 2012-03-20 21:17:58 +0000 | [diff] [blame] | 254 | GeometryPoolState& poolState = fGeoPoolStateStack.back(); |
| 255 | const GrVertexBuffer* vertexBuffer = poolState.fPoolVertexBuffer; |
| 256 | |
| 257 | // Check whether the draw is compatible with this draw in order to |
| 258 | // append |
| 259 | if (NULL == draw || |
bsalomon@google.com | 934c570 | 2012-03-20 21:17:58 +0000 | [diff] [blame] | 260 | draw->fIndexBuffer != geomSrc.fIndexBuffer || |
| 261 | draw->fPrimitiveType != type || |
| 262 | draw->fVertexBuffer != vertexBuffer) { |
| 263 | |
bsalomon@google.com | a4f6b10 | 2012-06-26 21:04:22 +0000 | [diff] [blame] | 264 | draw = this->recordDraw(); |
bsalomon@google.com | 934c570 | 2012-03-20 21:17:58 +0000 | [diff] [blame] | 265 | draw->fIndexBuffer = geomSrc.fIndexBuffer; |
| 266 | geomSrc.fIndexBuffer->ref(); |
| 267 | draw->fVertexBuffer = vertexBuffer; |
| 268 | vertexBuffer->ref(); |
| 269 | draw->fPrimitiveType = type; |
| 270 | draw->fStartIndex = 0; |
| 271 | draw->fIndexCount = 0; |
| 272 | draw->fStartVertex = poolState.fPoolStartVertex; |
| 273 | draw->fVertexCount = 0; |
| 274 | draw->fVertexLayout = geomSrc.fVertexLayout; |
| 275 | } else { |
| 276 | GrAssert(!(draw->fIndexCount % indicesPerInstance)); |
| 277 | GrAssert(!(draw->fVertexCount % verticesPerInstance)); |
| 278 | GrAssert(poolState.fPoolStartVertex == draw->fStartVertex + |
| 279 | draw->fVertexCount); |
| 280 | } |
| 281 | |
| 282 | // how many instances can be in a single draw |
| 283 | int maxInstancesPerDraw = this->indexCountInCurrentSource() / |
| 284 | indicesPerInstance; |
| 285 | if (!maxInstancesPerDraw) { |
| 286 | return; |
| 287 | } |
| 288 | // how many instances should be concat'ed onto draw |
| 289 | int instancesToConcat = maxInstancesPerDraw - draw->fVertexCount / |
| 290 | verticesPerInstance; |
| 291 | if (maxInstancesPerDraw > instanceCount) { |
| 292 | maxInstancesPerDraw = instanceCount; |
| 293 | if (instancesToConcat > instanceCount) { |
| 294 | instancesToConcat = instanceCount; |
| 295 | } |
| 296 | } |
| 297 | |
| 298 | // update the amount of reserved data actually referenced in draws |
| 299 | size_t vertexBytes = instanceCount * verticesPerInstance * |
| 300 | VertexSize(draw->fVertexLayout); |
| 301 | poolState.fUsedPoolVertexBytes = |
| 302 | GrMax(poolState.fUsedPoolVertexBytes, vertexBytes); |
| 303 | |
| 304 | while (instanceCount) { |
| 305 | if (!instancesToConcat) { |
| 306 | int startVertex = draw->fStartVertex + draw->fVertexCount; |
bsalomon@google.com | a4f6b10 | 2012-06-26 21:04:22 +0000 | [diff] [blame] | 307 | draw = this->recordDraw(); |
bsalomon@google.com | 934c570 | 2012-03-20 21:17:58 +0000 | [diff] [blame] | 308 | draw->fIndexBuffer = geomSrc.fIndexBuffer; |
| 309 | geomSrc.fIndexBuffer->ref(); |
| 310 | draw->fVertexBuffer = vertexBuffer; |
| 311 | vertexBuffer->ref(); |
| 312 | draw->fPrimitiveType = type; |
| 313 | draw->fStartIndex = 0; |
| 314 | draw->fStartVertex = startVertex; |
| 315 | draw->fVertexCount = 0; |
| 316 | draw->fVertexLayout = geomSrc.fVertexLayout; |
| 317 | instancesToConcat = maxInstancesPerDraw; |
| 318 | } |
| 319 | draw->fVertexCount += instancesToConcat * verticesPerInstance; |
| 320 | draw->fIndexCount += instancesToConcat * indicesPerInstance; |
| 321 | instanceCount -= instancesToConcat; |
| 322 | instancesToConcat = 0; |
| 323 | } |
| 324 | |
| 325 | // update draw tracking for next draw |
| 326 | fCurrQuad = 0; |
| 327 | fInstancedDrawTracker.fVerticesPerInstance = verticesPerInstance; |
| 328 | fInstancedDrawTracker.fIndicesPerInstance = indicesPerInstance; |
| 329 | } else { |
| 330 | this->INHERITED::drawIndexedInstances(type, |
| 331 | instanceCount, |
| 332 | verticesPerInstance, |
| 333 | indicesPerInstance); |
| 334 | } |
| 335 | |
| 336 | } |
| 337 | |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 338 | void GrInOrderDrawBuffer::onDrawIndexed(GrPrimitiveType primitiveType, |
| 339 | int startVertex, |
| 340 | int startIndex, |
| 341 | int vertexCount, |
| 342 | int indexCount) { |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 343 | |
| 344 | if (!vertexCount || !indexCount) { |
| 345 | return; |
| 346 | } |
| 347 | |
bsalomon@google.com | 934c570 | 2012-03-20 21:17:58 +0000 | [diff] [blame] | 348 | this->resetDrawTracking(); |
bsalomon@google.com | 86afc2a | 2011-02-16 16:12:19 +0000 | [diff] [blame] | 349 | |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 350 | GeometryPoolState& poolState = fGeoPoolStateStack.back(); |
| 351 | |
bsalomon@google.com | a4f6b10 | 2012-06-26 21:04:22 +0000 | [diff] [blame] | 352 | if (this->needsNewClip()) { |
| 353 | this->recordClip(); |
| 354 | } |
| 355 | if (this->needsNewState()) { |
| 356 | this->recordState(); |
bsalomon@google.com | 86afc2a | 2011-02-16 16:12:19 +0000 | [diff] [blame] | 357 | } |
| 358 | |
bsalomon@google.com | a4f6b10 | 2012-06-26 21:04:22 +0000 | [diff] [blame] | 359 | Draw* draw = this->recordDraw(); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 360 | |
bsalomon@google.com | a4f6b10 | 2012-06-26 21:04:22 +0000 | [diff] [blame] | 361 | draw->fPrimitiveType = primitiveType; |
| 362 | draw->fStartVertex = startVertex; |
| 363 | draw->fStartIndex = startIndex; |
| 364 | draw->fVertexCount = vertexCount; |
| 365 | draw->fIndexCount = indexCount; |
| 366 | |
| 367 | draw->fVertexLayout = this->getVertexLayout(); |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 368 | switch (this->getGeomSrc().fVertexSrc) { |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 369 | case kBuffer_GeometrySrcType: |
bsalomon@google.com | a4f6b10 | 2012-06-26 21:04:22 +0000 | [diff] [blame] | 370 | draw->fVertexBuffer = this->getGeomSrc().fVertexBuffer; |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 371 | break; |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 372 | case kReserved_GeometrySrcType: // fallthrough |
| 373 | case kArray_GeometrySrcType: { |
bsalomon@google.com | 1c13c96 | 2011-02-14 16:51:21 +0000 | [diff] [blame] | 374 | size_t vertexBytes = (vertexCount + startVertex) * |
bsalomon@google.com | a4f6b10 | 2012-06-26 21:04:22 +0000 | [diff] [blame] | 375 | VertexSize(draw->fVertexLayout); |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame^] | 376 | poolState.fUsedPoolVertexBytes = |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 377 | GrMax(poolState.fUsedPoolVertexBytes, vertexBytes); |
bsalomon@google.com | a4f6b10 | 2012-06-26 21:04:22 +0000 | [diff] [blame] | 378 | draw->fVertexBuffer = poolState.fPoolVertexBuffer; |
| 379 | draw->fStartVertex += poolState.fPoolStartVertex; |
bsalomon@google.com | 1c13c96 | 2011-02-14 16:51:21 +0000 | [diff] [blame] | 380 | break; |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 381 | } |
bsalomon@google.com | 1c13c96 | 2011-02-14 16:51:21 +0000 | [diff] [blame] | 382 | default: |
| 383 | GrCrash("unknown geom src type"); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 384 | } |
bsalomon@google.com | a4f6b10 | 2012-06-26 21:04:22 +0000 | [diff] [blame] | 385 | draw->fVertexBuffer->ref(); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 386 | |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 387 | switch (this->getGeomSrc().fIndexSrc) { |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 388 | case kBuffer_GeometrySrcType: |
bsalomon@google.com | a4f6b10 | 2012-06-26 21:04:22 +0000 | [diff] [blame] | 389 | draw->fIndexBuffer = this->getGeomSrc().fIndexBuffer; |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 390 | break; |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame^] | 391 | case kReserved_GeometrySrcType: // fallthrough |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 392 | case kArray_GeometrySrcType: { |
bsalomon@google.com | 1c13c96 | 2011-02-14 16:51:21 +0000 | [diff] [blame] | 393 | size_t indexBytes = (indexCount + startIndex) * sizeof(uint16_t); |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame^] | 394 | poolState.fUsedPoolIndexBytes = |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 395 | GrMax(poolState.fUsedPoolIndexBytes, indexBytes); |
bsalomon@google.com | a4f6b10 | 2012-06-26 21:04:22 +0000 | [diff] [blame] | 396 | draw->fIndexBuffer = poolState.fPoolIndexBuffer; |
| 397 | draw->fStartIndex += poolState.fPoolStartIndex; |
bsalomon@google.com | 1c13c96 | 2011-02-14 16:51:21 +0000 | [diff] [blame] | 398 | break; |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 399 | } |
bsalomon@google.com | 1c13c96 | 2011-02-14 16:51:21 +0000 | [diff] [blame] | 400 | default: |
| 401 | GrCrash("unknown geom src type"); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 402 | } |
bsalomon@google.com | a4f6b10 | 2012-06-26 21:04:22 +0000 | [diff] [blame] | 403 | draw->fIndexBuffer->ref(); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 404 | } |
| 405 | |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 406 | void GrInOrderDrawBuffer::onDrawNonIndexed(GrPrimitiveType primitiveType, |
| 407 | int startVertex, |
| 408 | int vertexCount) { |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 409 | if (!vertexCount) { |
| 410 | return; |
| 411 | } |
| 412 | |
bsalomon@google.com | 934c570 | 2012-03-20 21:17:58 +0000 | [diff] [blame] | 413 | this->resetDrawTracking(); |
bsalomon@google.com | 86afc2a | 2011-02-16 16:12:19 +0000 | [diff] [blame] | 414 | |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 415 | GeometryPoolState& poolState = fGeoPoolStateStack.back(); |
bsalomon@google.com | a4f6b10 | 2012-06-26 21:04:22 +0000 | [diff] [blame] | 416 | if (this->needsNewClip()) { |
| 417 | this->recordClip(); |
| 418 | } |
| 419 | if (this->needsNewState()) { |
| 420 | this->recordState(); |
bsalomon@google.com | 86afc2a | 2011-02-16 16:12:19 +0000 | [diff] [blame] | 421 | } |
| 422 | |
bsalomon@google.com | a4f6b10 | 2012-06-26 21:04:22 +0000 | [diff] [blame] | 423 | Draw* draw = this->recordDraw(); |
| 424 | draw->fPrimitiveType = primitiveType; |
| 425 | draw->fStartVertex = startVertex; |
| 426 | draw->fStartIndex = 0; |
| 427 | draw->fVertexCount = vertexCount; |
| 428 | draw->fIndexCount = 0; |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 429 | |
bsalomon@google.com | a4f6b10 | 2012-06-26 21:04:22 +0000 | [diff] [blame] | 430 | draw->fVertexLayout = this->getVertexLayout(); |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 431 | switch (this->getGeomSrc().fVertexSrc) { |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 432 | case kBuffer_GeometrySrcType: |
bsalomon@google.com | a4f6b10 | 2012-06-26 21:04:22 +0000 | [diff] [blame] | 433 | draw->fVertexBuffer = this->getGeomSrc().fVertexBuffer; |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 434 | break; |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 435 | case kReserved_GeometrySrcType: // fallthrough |
| 436 | case kArray_GeometrySrcType: { |
bsalomon@google.com | 1c13c96 | 2011-02-14 16:51:21 +0000 | [diff] [blame] | 437 | size_t vertexBytes = (vertexCount + startVertex) * |
bsalomon@google.com | a4f6b10 | 2012-06-26 21:04:22 +0000 | [diff] [blame] | 438 | VertexSize(draw->fVertexLayout); |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame^] | 439 | poolState.fUsedPoolVertexBytes = |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 440 | GrMax(poolState.fUsedPoolVertexBytes, vertexBytes); |
bsalomon@google.com | a4f6b10 | 2012-06-26 21:04:22 +0000 | [diff] [blame] | 441 | draw->fVertexBuffer = poolState.fPoolVertexBuffer; |
| 442 | draw->fStartVertex += poolState.fPoolStartVertex; |
bsalomon@google.com | 1c13c96 | 2011-02-14 16:51:21 +0000 | [diff] [blame] | 443 | break; |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 444 | } |
bsalomon@google.com | 1c13c96 | 2011-02-14 16:51:21 +0000 | [diff] [blame] | 445 | default: |
| 446 | GrCrash("unknown geom src type"); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 447 | } |
bsalomon@google.com | a4f6b10 | 2012-06-26 21:04:22 +0000 | [diff] [blame] | 448 | draw->fVertexBuffer->ref(); |
| 449 | draw->fIndexBuffer = NULL; |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 450 | } |
| 451 | |
bsalomon@google.com | ded4f4b | 2012-06-28 18:48:06 +0000 | [diff] [blame] | 452 | void GrInOrderDrawBuffer::onStencilPath(const GrPath* path, GrPathFill fill) { |
| 453 | if (this->needsNewClip()) { |
| 454 | this->recordClip(); |
| 455 | } |
| 456 | // Only compare the subset of GrDrawState relevant to path stenciling? |
| 457 | if (this->needsNewState()) { |
| 458 | this->recordState(); |
| 459 | } |
| 460 | StencilPath* sp = this->recordStencilPath(); |
| 461 | sp->fPath.reset(path); |
| 462 | path->ref(); |
| 463 | sp->fFill = fill; |
bsalomon@google.com | 64aef2b | 2012-06-11 15:36:13 +0000 | [diff] [blame] | 464 | } |
| 465 | |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame^] | 466 | void GrInOrderDrawBuffer::clear(const GrIRect* rect, |
robertphillips@google.com | c82a8b7 | 2012-06-21 20:15:48 +0000 | [diff] [blame] | 467 | GrColor color, |
| 468 | GrRenderTarget* renderTarget) { |
bsalomon@google.com | 6aa25c3 | 2011-04-27 19:55:29 +0000 | [diff] [blame] | 469 | GrIRect r; |
bsalomon@google.com | 1b3ce47 | 2012-08-17 13:43:08 +0000 | [diff] [blame] | 470 | if (NULL == renderTarget) { |
| 471 | renderTarget = this->drawState()->getRenderTarget(); |
| 472 | GrAssert(NULL != renderTarget); |
| 473 | } |
bsalomon@google.com | 6aa25c3 | 2011-04-27 19:55:29 +0000 | [diff] [blame] | 474 | if (NULL == rect) { |
| 475 | // We could do something smart and remove previous draws and clears to |
| 476 | // the current render target. If we get that smart we have to make sure |
| 477 | // those draws aren't read before this clear (render-to-texture). |
bsalomon@google.com | 1b3ce47 | 2012-08-17 13:43:08 +0000 | [diff] [blame] | 478 | r.setLTRB(0, 0, renderTarget->width(), renderTarget->height()); |
bsalomon@google.com | 6aa25c3 | 2011-04-27 19:55:29 +0000 | [diff] [blame] | 479 | rect = &r; |
| 480 | } |
bsalomon@google.com | a4f6b10 | 2012-06-26 21:04:22 +0000 | [diff] [blame] | 481 | Clear* clr = this->recordClear(); |
| 482 | clr->fColor = color; |
| 483 | clr->fRect = *rect; |
| 484 | clr->fRenderTarget = renderTarget; |
bsalomon@google.com | 1b3ce47 | 2012-08-17 13:43:08 +0000 | [diff] [blame] | 485 | renderTarget->ref(); |
bsalomon@google.com | 0b335c1 | 2011-04-25 19:17:44 +0000 | [diff] [blame] | 486 | } |
| 487 | |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 488 | void GrInOrderDrawBuffer::reset() { |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 489 | GrAssert(1 == fGeoPoolStateStack.count()); |
| 490 | this->resetVertexSource(); |
| 491 | this->resetIndexSource(); |
bsalomon@google.com | 86afc2a | 2011-02-16 16:12:19 +0000 | [diff] [blame] | 492 | int numDraws = fDraws.count(); |
| 493 | for (int d = 0; d < numDraws; ++d) { |
| 494 | // we always have a VB, but not always an IB |
| 495 | GrAssert(NULL != fDraws[d].fVertexBuffer); |
| 496 | fDraws[d].fVertexBuffer->unref(); |
| 497 | GrSafeUnref(fDraws[d].fIndexBuffer); |
| 498 | } |
bsalomon@google.com | a4f6b10 | 2012-06-26 21:04:22 +0000 | [diff] [blame] | 499 | fCmds.reset(); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 500 | fDraws.reset(); |
bsalomon@google.com | ded4f4b | 2012-06-28 18:48:06 +0000 | [diff] [blame] | 501 | fStencilPaths.reset(); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 502 | fStates.reset(); |
bsalomon@google.com | 0b335c1 | 2011-04-25 19:17:44 +0000 | [diff] [blame] | 503 | fClears.reset(); |
bsalomon@google.com | 1c13c96 | 2011-02-14 16:51:21 +0000 | [diff] [blame] | 504 | fVertexPool.reset(); |
| 505 | fIndexPool.reset(); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 506 | fClips.reset(); |
robertphillips@google.com | beb1af7 | 2012-07-26 18:52:16 +0000 | [diff] [blame] | 507 | fClipOrigins.reset(); |
bsalomon@google.com | a4f6b10 | 2012-06-26 21:04:22 +0000 | [diff] [blame] | 508 | fClipSet = true; |
bsalomon@google.com | 86afc2a | 2011-02-16 16:12:19 +0000 | [diff] [blame] | 509 | |
bsalomon@google.com | 934c570 | 2012-03-20 21:17:58 +0000 | [diff] [blame] | 510 | this->resetDrawTracking(); |
bsalomon@google.com | a4f6b10 | 2012-06-26 21:04:22 +0000 | [diff] [blame] | 511 | |
| 512 | // we start off with a default clip and state so that we don't have |
| 513 | // to do count checks on fClips, fStates, or fCmds before checking their |
| 514 | // last entry. |
| 515 | this->recordDefaultState(); |
| 516 | this->recordDefaultClip(); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 517 | } |
| 518 | |
bsalomon@google.com | a4f6b10 | 2012-06-26 21:04:22 +0000 | [diff] [blame] | 519 | bool GrInOrderDrawBuffer::playback(GrDrawTarget* target) { |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 520 | GrAssert(kReserved_GeometrySrcType != this->getGeomSrc().fVertexSrc); |
| 521 | GrAssert(kReserved_GeometrySrcType != this->getGeomSrc().fIndexSrc); |
bsalomon@google.com | 3f5a95e | 2012-03-08 16:41:42 +0000 | [diff] [blame] | 522 | |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 523 | GrAssert(NULL != target); |
| 524 | GrAssert(target != this); // not considered and why? |
| 525 | |
bsalomon@google.com | a4f6b10 | 2012-06-26 21:04:22 +0000 | [diff] [blame] | 526 | int numCmds = fCmds.count(); |
| 527 | GrAssert(numCmds >= 2); |
| 528 | if (2 == numCmds) { |
| 529 | GrAssert(kSetState_Cmd == fCmds[0]); |
| 530 | GrAssert(kSetClip_Cmd == fCmds[1]); |
| 531 | return false; |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 532 | } |
| 533 | |
bsalomon@google.com | 1c13c96 | 2011-02-14 16:51:21 +0000 | [diff] [blame] | 534 | fVertexPool.unlock(); |
| 535 | fIndexPool.unlock(); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 536 | |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 537 | GrDrawTarget::AutoClipRestore acr(target); |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 538 | AutoGeometryPush agp(target); |
bsalomon@google.com | a5d056a | 2012-03-27 15:59:58 +0000 | [diff] [blame] | 539 | GrDrawState* prevDrawState = target->drawState(); |
| 540 | prevDrawState->ref(); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 541 | |
robertphillips@google.com | beb1af7 | 2012-07-26 18:52:16 +0000 | [diff] [blame] | 542 | GrClipData clipData; |
| 543 | |
bsalomon@google.com | ded4f4b | 2012-06-28 18:48:06 +0000 | [diff] [blame] | 544 | int currState = 0; |
| 545 | int currClip = 0; |
| 546 | int currClear = 0; |
| 547 | int currDraw = 0; |
| 548 | int currStencilPath = 0; |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 549 | |
bsalomon@google.com | a4f6b10 | 2012-06-26 21:04:22 +0000 | [diff] [blame] | 550 | for (int c = 0; c < numCmds; ++c) { |
| 551 | switch (fCmds[c]) { |
| 552 | case kDraw_Cmd: { |
| 553 | const Draw& draw = fDraws[currDraw]; |
| 554 | target->setVertexSourceToBuffer(draw.fVertexLayout, draw.fVertexBuffer); |
| 555 | if (draw.fIndexCount) { |
| 556 | target->setIndexSourceToBuffer(draw.fIndexBuffer); |
| 557 | } |
bsalomon@google.com | 0b335c1 | 2011-04-25 19:17:44 +0000 | [diff] [blame] | 558 | |
bsalomon@google.com | a4f6b10 | 2012-06-26 21:04:22 +0000 | [diff] [blame] | 559 | if (draw.fIndexCount) { |
| 560 | target->drawIndexed(draw.fPrimitiveType, |
| 561 | draw.fStartVertex, |
| 562 | draw.fStartIndex, |
| 563 | draw.fVertexCount, |
| 564 | draw.fIndexCount); |
| 565 | } else { |
| 566 | target->drawNonIndexed(draw.fPrimitiveType, |
| 567 | draw.fStartVertex, |
| 568 | draw.fVertexCount); |
| 569 | } |
| 570 | ++currDraw; |
| 571 | break; |
| 572 | } |
bsalomon@google.com | ded4f4b | 2012-06-28 18:48:06 +0000 | [diff] [blame] | 573 | case kStencilPath_Cmd: { |
| 574 | const StencilPath& sp = fStencilPaths[currStencilPath]; |
| 575 | target->stencilPath(sp.fPath.get(), sp.fFill); |
| 576 | ++currStencilPath; |
| 577 | break; |
| 578 | } |
bsalomon@google.com | a4f6b10 | 2012-06-26 21:04:22 +0000 | [diff] [blame] | 579 | case kSetState_Cmd: |
| 580 | target->setDrawState(&fStates[currState]); |
| 581 | ++currState; |
| 582 | break; |
| 583 | case kSetClip_Cmd: |
robertphillips@google.com | beb1af7 | 2012-07-26 18:52:16 +0000 | [diff] [blame] | 584 | clipData.fClipStack = &fClips[currClip]; |
| 585 | clipData.fOrigin = fClipOrigins[currClip]; |
| 586 | target->setClip(&clipData); |
bsalomon@google.com | a4f6b10 | 2012-06-26 21:04:22 +0000 | [diff] [blame] | 587 | ++currClip; |
| 588 | break; |
| 589 | case kClear_Cmd: |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame^] | 590 | target->clear(&fClears[currClear].fRect, |
bsalomon@google.com | a4f6b10 | 2012-06-26 21:04:22 +0000 | [diff] [blame] | 591 | fClears[currClear].fColor, |
| 592 | fClears[currClear].fRenderTarget); |
| 593 | ++currClear; |
| 594 | break; |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 595 | } |
| 596 | } |
bsalomon@google.com | a4f6b10 | 2012-06-26 21:04:22 +0000 | [diff] [blame] | 597 | // we should have consumed all the states, clips, etc. |
| 598 | GrAssert(fStates.count() == currState); |
| 599 | GrAssert(fClips.count() == currClip); |
robertphillips@google.com | beb1af7 | 2012-07-26 18:52:16 +0000 | [diff] [blame] | 600 | GrAssert(fClipOrigins.count() == currClip); |
bsalomon@google.com | a4f6b10 | 2012-06-26 21:04:22 +0000 | [diff] [blame] | 601 | GrAssert(fClears.count() == currClear); |
| 602 | GrAssert(fDraws.count() == currDraw); |
| 603 | |
bsalomon@google.com | a5d056a | 2012-03-27 15:59:58 +0000 | [diff] [blame] | 604 | target->setDrawState(prevDrawState); |
| 605 | prevDrawState->unref(); |
bsalomon@google.com | a4f6b10 | 2012-06-26 21:04:22 +0000 | [diff] [blame] | 606 | return true; |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 607 | } |
| 608 | |
bsalomon@google.com | 9780538 | 2012-03-13 14:32:07 +0000 | [diff] [blame] | 609 | void GrInOrderDrawBuffer::setAutoFlushTarget(GrDrawTarget* target) { |
| 610 | GrSafeAssign(fAutoFlushTarget, target); |
| 611 | } |
| 612 | |
| 613 | void GrInOrderDrawBuffer::willReserveVertexAndIndexSpace( |
| 614 | GrVertexLayout vertexLayout, |
| 615 | int vertexCount, |
| 616 | int indexCount) { |
| 617 | if (NULL != fAutoFlushTarget) { |
| 618 | // We use geometryHints() to know whether to flush the draw buffer. We |
| 619 | // can't flush if we are inside an unbalanced pushGeometrySource. |
| 620 | // Moreover, flushing blows away vertex and index data that was |
| 621 | // previously reserved. So if the vertex or index data is pulled from |
| 622 | // reserved space and won't be released by this request then we can't |
| 623 | // flush. |
| 624 | bool insideGeoPush = fGeoPoolStateStack.count() > 1; |
| 625 | |
| 626 | bool unreleasedVertexSpace = |
| 627 | !vertexCount && |
| 628 | kReserved_GeometrySrcType == this->getGeomSrc().fVertexSrc; |
| 629 | |
| 630 | bool unreleasedIndexSpace = |
| 631 | !indexCount && |
| 632 | kReserved_GeometrySrcType == this->getGeomSrc().fIndexSrc; |
| 633 | |
| 634 | // we don't want to finalize any reserved geom on the target since |
| 635 | // we don't know that the client has finished writing to it. |
| 636 | bool targetHasReservedGeom = |
| 637 | fAutoFlushTarget->hasReservedVerticesOrIndices(); |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame^] | 638 | |
bsalomon@google.com | 9780538 | 2012-03-13 14:32:07 +0000 | [diff] [blame] | 639 | int vcount = vertexCount; |
| 640 | int icount = indexCount; |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame^] | 641 | |
bsalomon@google.com | 9780538 | 2012-03-13 14:32:07 +0000 | [diff] [blame] | 642 | if (!insideGeoPush && |
| 643 | !unreleasedVertexSpace && |
| 644 | !unreleasedIndexSpace && |
| 645 | !targetHasReservedGeom && |
| 646 | this->geometryHints(vertexLayout, &vcount, &icount)) { |
| 647 | |
| 648 | this->flushTo(fAutoFlushTarget); |
| 649 | } |
| 650 | } |
| 651 | } |
| 652 | |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 653 | bool GrInOrderDrawBuffer::geometryHints(GrVertexLayout vertexLayout, |
bsalomon@google.com | 1c13c96 | 2011-02-14 16:51:21 +0000 | [diff] [blame] | 654 | int* vertexCount, |
| 655 | int* indexCount) const { |
| 656 | // we will recommend a flush if the data could fit in a single |
| 657 | // preallocated buffer but none are left and it can't fit |
| 658 | // in the current buffer (which may not be prealloced). |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 659 | bool flush = false; |
| 660 | if (NULL != indexCount) { |
bsalomon@google.com | 1c13c96 | 2011-02-14 16:51:21 +0000 | [diff] [blame] | 661 | int32_t currIndices = fIndexPool.currentBufferIndices(); |
| 662 | if (*indexCount > currIndices && |
| 663 | (!fIndexPool.preallocatedBuffersRemaining() && |
| 664 | *indexCount <= fIndexPool.preallocatedBufferIndices())) { |
| 665 | |
| 666 | flush = true; |
| 667 | } |
| 668 | *indexCount = currIndices; |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 669 | } |
| 670 | if (NULL != vertexCount) { |
bsalomon@google.com | 1c13c96 | 2011-02-14 16:51:21 +0000 | [diff] [blame] | 671 | int32_t currVertices = fVertexPool.currentBufferVertices(vertexLayout); |
| 672 | if (*vertexCount > currVertices && |
| 673 | (!fVertexPool.preallocatedBuffersRemaining() && |
| 674 | *vertexCount <= fVertexPool.preallocatedBufferVertices(vertexLayout))) { |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 675 | |
bsalomon@google.com | 1c13c96 | 2011-02-14 16:51:21 +0000 | [diff] [blame] | 676 | flush = true; |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 677 | } |
bsalomon@google.com | 1c13c96 | 2011-02-14 16:51:21 +0000 | [diff] [blame] | 678 | *vertexCount = currVertices; |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 679 | } |
| 680 | return flush; |
| 681 | } |
| 682 | |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 683 | bool GrInOrderDrawBuffer::onReserveVertexSpace(GrVertexLayout vertexLayout, |
| 684 | int vertexCount, |
| 685 | void** vertices) { |
| 686 | GeometryPoolState& poolState = fGeoPoolStateStack.back(); |
| 687 | GrAssert(vertexCount > 0); |
| 688 | GrAssert(NULL != vertices); |
| 689 | GrAssert(0 == poolState.fUsedPoolVertexBytes); |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame^] | 690 | |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 691 | *vertices = fVertexPool.makeSpace(vertexLayout, |
| 692 | vertexCount, |
| 693 | &poolState.fPoolVertexBuffer, |
| 694 | &poolState.fPoolStartVertex); |
| 695 | return NULL != *vertices; |
| 696 | } |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame^] | 697 | |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 698 | bool GrInOrderDrawBuffer::onReserveIndexSpace(int indexCount, void** indices) { |
| 699 | GeometryPoolState& poolState = fGeoPoolStateStack.back(); |
| 700 | GrAssert(indexCount > 0); |
| 701 | GrAssert(NULL != indices); |
| 702 | GrAssert(0 == poolState.fUsedPoolIndexBytes); |
bsalomon@google.com | 1c13c96 | 2011-02-14 16:51:21 +0000 | [diff] [blame] | 703 | |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 704 | *indices = fIndexPool.makeSpace(indexCount, |
| 705 | &poolState.fPoolIndexBuffer, |
| 706 | &poolState.fPoolStartIndex); |
| 707 | return NULL != *indices; |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 708 | } |
| 709 | |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 710 | void GrInOrderDrawBuffer::releaseReservedVertexSpace() { |
| 711 | GeometryPoolState& poolState = fGeoPoolStateStack.back(); |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame^] | 712 | const GeometrySrcState& geoSrc = this->getGeomSrc(); |
bsalomon@google.com | d57d71a | 2012-08-16 16:26:33 +0000 | [diff] [blame] | 713 | |
| 714 | // If we get a release vertex space call then our current source should either be reserved |
| 715 | // or array (which we copied into reserved space). |
| 716 | GrAssert(kReserved_GeometrySrcType == geoSrc.fVertexSrc || |
| 717 | kArray_GeometrySrcType == geoSrc.fVertexSrc); |
bsalomon@google.com | 3f5a95e | 2012-03-08 16:41:42 +0000 | [diff] [blame] | 718 | |
| 719 | // When the caller reserved vertex buffer space we gave it back a pointer |
| 720 | // provided by the vertex buffer pool. At each draw we tracked the largest |
| 721 | // offset into the pool's pointer that was referenced. Now we return to the |
| 722 | // pool any portion at the tail of the allocation that no draw referenced. |
| 723 | size_t reservedVertexBytes = VertexSize(geoSrc.fVertexLayout) * |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 724 | geoSrc.fVertexCount; |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame^] | 725 | fVertexPool.putBack(reservedVertexBytes - |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 726 | poolState.fUsedPoolVertexBytes); |
| 727 | poolState.fUsedPoolVertexBytes = 0; |
bsalomon@google.com | 3f5a95e | 2012-03-08 16:41:42 +0000 | [diff] [blame] | 728 | poolState.fPoolVertexBuffer = NULL; |
| 729 | poolState.fPoolStartVertex = 0; |
bsalomon@google.com | 1c13c96 | 2011-02-14 16:51:21 +0000 | [diff] [blame] | 730 | } |
| 731 | |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 732 | void GrInOrderDrawBuffer::releaseReservedIndexSpace() { |
| 733 | GeometryPoolState& poolState = fGeoPoolStateStack.back(); |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame^] | 734 | const GeometrySrcState& geoSrc = this->getGeomSrc(); |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 735 | |
bsalomon@google.com | d57d71a | 2012-08-16 16:26:33 +0000 | [diff] [blame] | 736 | // If we get a release index space call then our current source should either be reserved |
| 737 | // or array (which we copied into reserved space). |
| 738 | GrAssert(kReserved_GeometrySrcType == geoSrc.fIndexSrc || |
| 739 | kArray_GeometrySrcType == geoSrc.fIndexSrc); |
bsalomon@google.com | 3f5a95e | 2012-03-08 16:41:42 +0000 | [diff] [blame] | 740 | |
| 741 | // Similar to releaseReservedVertexSpace we return any unused portion at |
| 742 | // the tail |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 743 | size_t reservedIndexBytes = sizeof(uint16_t) * geoSrc.fIndexCount; |
| 744 | fIndexPool.putBack(reservedIndexBytes - poolState.fUsedPoolIndexBytes); |
| 745 | poolState.fUsedPoolIndexBytes = 0; |
bsalomon@google.com | 3f5a95e | 2012-03-08 16:41:42 +0000 | [diff] [blame] | 746 | poolState.fPoolIndexBuffer = NULL; |
| 747 | poolState.fPoolStartIndex = 0; |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 748 | } |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame^] | 749 | |
bsalomon@google.com | bcdbbe6 | 2011-04-12 15:40:00 +0000 | [diff] [blame] | 750 | void GrInOrderDrawBuffer::onSetVertexSourceToArray(const void* vertexArray, |
| 751 | int vertexCount) { |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 752 | |
| 753 | GeometryPoolState& poolState = fGeoPoolStateStack.back(); |
| 754 | GrAssert(0 == poolState.fUsedPoolVertexBytes); |
bsalomon@google.com | 1c13c96 | 2011-02-14 16:51:21 +0000 | [diff] [blame] | 755 | #if GR_DEBUG |
| 756 | bool success = |
| 757 | #endif |
bsalomon@google.com | e79c815 | 2012-03-29 19:07:12 +0000 | [diff] [blame] | 758 | fVertexPool.appendVertices(this->getVertexLayout(), |
bsalomon@google.com | 1c13c96 | 2011-02-14 16:51:21 +0000 | [diff] [blame] | 759 | vertexCount, |
| 760 | vertexArray, |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 761 | &poolState.fPoolVertexBuffer, |
| 762 | &poolState.fPoolStartVertex); |
bsalomon@google.com | 1c13c96 | 2011-02-14 16:51:21 +0000 | [diff] [blame] | 763 | GR_DEBUGASSERT(success); |
| 764 | } |
| 765 | |
bsalomon@google.com | bcdbbe6 | 2011-04-12 15:40:00 +0000 | [diff] [blame] | 766 | void GrInOrderDrawBuffer::onSetIndexSourceToArray(const void* indexArray, |
| 767 | int indexCount) { |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 768 | GeometryPoolState& poolState = fGeoPoolStateStack.back(); |
| 769 | GrAssert(0 == poolState.fUsedPoolIndexBytes); |
bsalomon@google.com | 1c13c96 | 2011-02-14 16:51:21 +0000 | [diff] [blame] | 770 | #if GR_DEBUG |
| 771 | bool success = |
| 772 | #endif |
| 773 | fIndexPool.appendIndices(indexCount, |
| 774 | indexArray, |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 775 | &poolState.fPoolIndexBuffer, |
| 776 | &poolState.fPoolStartIndex); |
bsalomon@google.com | 1c13c96 | 2011-02-14 16:51:21 +0000 | [diff] [blame] | 777 | GR_DEBUGASSERT(success); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 778 | } |
| 779 | |
bsalomon@google.com | 3f5a95e | 2012-03-08 16:41:42 +0000 | [diff] [blame] | 780 | void GrInOrderDrawBuffer::releaseVertexArray() { |
| 781 | // When the client provides an array as the vertex source we handled it |
| 782 | // by copying their array into reserved space. |
| 783 | this->GrInOrderDrawBuffer::releaseReservedVertexSpace(); |
| 784 | } |
| 785 | |
| 786 | void GrInOrderDrawBuffer::releaseIndexArray() { |
| 787 | // When the client provides an array as the index source we handled it |
| 788 | // by copying their array into reserved space. |
| 789 | this->GrInOrderDrawBuffer::releaseReservedIndexSpace(); |
| 790 | } |
| 791 | |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 792 | void GrInOrderDrawBuffer::geometrySourceWillPush() { |
| 793 | GeometryPoolState& poolState = fGeoPoolStateStack.push_back(); |
| 794 | poolState.fUsedPoolVertexBytes = 0; |
| 795 | poolState.fUsedPoolIndexBytes = 0; |
bsalomon@google.com | 934c570 | 2012-03-20 21:17:58 +0000 | [diff] [blame] | 796 | this->resetDrawTracking(); |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 797 | #if GR_DEBUG |
| 798 | poolState.fPoolVertexBuffer = (GrVertexBuffer*)~0; |
| 799 | poolState.fPoolStartVertex = ~0; |
| 800 | poolState.fPoolIndexBuffer = (GrIndexBuffer*)~0; |
| 801 | poolState.fPoolStartIndex = ~0; |
| 802 | #endif |
| 803 | } |
| 804 | |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 805 | void GrInOrderDrawBuffer::geometrySourceWillPop( |
| 806 | const GeometrySrcState& restoredState) { |
| 807 | GrAssert(fGeoPoolStateStack.count() > 1); |
| 808 | fGeoPoolStateStack.pop_back(); |
| 809 | GeometryPoolState& poolState = fGeoPoolStateStack.back(); |
| 810 | // we have to assume that any slack we had in our vertex/index data |
| 811 | // is now unreleasable because data may have been appended later in the |
| 812 | // pool. |
| 813 | if (kReserved_GeometrySrcType == restoredState.fVertexSrc || |
| 814 | kArray_GeometrySrcType == restoredState.fVertexSrc) { |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame^] | 815 | poolState.fUsedPoolVertexBytes = |
| 816 | VertexSize(restoredState.fVertexLayout) * |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 817 | restoredState.fVertexCount; |
| 818 | } |
| 819 | if (kReserved_GeometrySrcType == restoredState.fIndexSrc || |
| 820 | kArray_GeometrySrcType == restoredState.fIndexSrc) { |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame^] | 821 | poolState.fUsedPoolIndexBytes = sizeof(uint16_t) * |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 822 | restoredState.fIndexCount; |
| 823 | } |
bsalomon@google.com | 934c570 | 2012-03-20 21:17:58 +0000 | [diff] [blame] | 824 | this->resetDrawTracking(); |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 825 | } |
| 826 | |
bsalomon@google.com | 86afc2a | 2011-02-16 16:12:19 +0000 | [diff] [blame] | 827 | bool GrInOrderDrawBuffer::needsNewState() const { |
bsalomon@google.com | a4f6b10 | 2012-06-26 21:04:22 +0000 | [diff] [blame] | 828 | // we should have recorded a default state in reset() |
| 829 | GrAssert(!fStates.empty()); |
| 830 | return fStates.back() != this->getDrawState(); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 831 | } |
| 832 | |
bsalomon@google.com | 86afc2a | 2011-02-16 16:12:19 +0000 | [diff] [blame] | 833 | bool GrInOrderDrawBuffer::needsNewClip() const { |
bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 834 | if (this->getDrawState().isClipState()) { |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame^] | 835 | if (fClipSet && |
robertphillips@google.com | beb1af7 | 2012-07-26 18:52:16 +0000 | [diff] [blame] | 836 | (fClips.back() != *fClip->fClipStack || |
| 837 | fClipOrigins.back() != fClip->fOrigin)) { |
bsalomon@google.com | 86afc2a | 2011-02-16 16:12:19 +0000 | [diff] [blame] | 838 | return true; |
| 839 | } |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 840 | } |
| 841 | return false; |
| 842 | } |
bsalomon@google.com | d302f14 | 2011-03-03 13:54:13 +0000 | [diff] [blame] | 843 | |
bsalomon@google.com | a4f6b10 | 2012-06-26 21:04:22 +0000 | [diff] [blame] | 844 | void GrInOrderDrawBuffer::recordClip() { |
robertphillips@google.com | beb1af7 | 2012-07-26 18:52:16 +0000 | [diff] [blame] | 845 | fClips.push_back() = *fClip->fClipStack; |
| 846 | fClipOrigins.push_back() = fClip->fOrigin; |
bsalomon@google.com | 86afc2a | 2011-02-16 16:12:19 +0000 | [diff] [blame] | 847 | fClipSet = false; |
bsalomon@google.com | a4f6b10 | 2012-06-26 21:04:22 +0000 | [diff] [blame] | 848 | fCmds.push_back(kSetClip_Cmd); |
| 849 | } |
| 850 | |
| 851 | void GrInOrderDrawBuffer::recordDefaultClip() { |
robertphillips@google.com | 641f8b1 | 2012-07-31 19:15:58 +0000 | [diff] [blame] | 852 | fClips.push_back() = SkClipStack(); |
robertphillips@google.com | beb1af7 | 2012-07-26 18:52:16 +0000 | [diff] [blame] | 853 | fClipOrigins.push_back() = SkIPoint::Make(0, 0); |
bsalomon@google.com | a4f6b10 | 2012-06-26 21:04:22 +0000 | [diff] [blame] | 854 | fCmds.push_back(kSetClip_Cmd); |
| 855 | } |
| 856 | |
| 857 | void GrInOrderDrawBuffer::recordState() { |
| 858 | fStates.push_back(this->getDrawState()); |
| 859 | fCmds.push_back(kSetState_Cmd); |
| 860 | } |
| 861 | |
| 862 | void GrInOrderDrawBuffer::recordDefaultState() { |
| 863 | fStates.push_back(GrDrawState()); |
| 864 | fCmds.push_back(kSetState_Cmd); |
| 865 | } |
| 866 | |
| 867 | GrInOrderDrawBuffer::Draw* GrInOrderDrawBuffer::recordDraw() { |
| 868 | fCmds.push_back(kDraw_Cmd); |
| 869 | return &fDraws.push_back(); |
| 870 | } |
| 871 | |
bsalomon@google.com | ded4f4b | 2012-06-28 18:48:06 +0000 | [diff] [blame] | 872 | GrInOrderDrawBuffer::StencilPath* GrInOrderDrawBuffer::recordStencilPath() { |
| 873 | fCmds.push_back(kStencilPath_Cmd); |
| 874 | return &fStencilPaths.push_back(); |
| 875 | } |
| 876 | |
bsalomon@google.com | a4f6b10 | 2012-06-26 21:04:22 +0000 | [diff] [blame] | 877 | GrInOrderDrawBuffer::Clear* GrInOrderDrawBuffer::recordClear() { |
| 878 | fCmds.push_back(kClear_Cmd); |
| 879 | return &fClears.push_back(); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 880 | } |
bsalomon@google.com | d302f14 | 2011-03-03 13:54:13 +0000 | [diff] [blame] | 881 | |
robertphillips@google.com | beb1af7 | 2012-07-26 18:52:16 +0000 | [diff] [blame] | 882 | void GrInOrderDrawBuffer::clipWillBeSet(const GrClipData* newClipData) { |
| 883 | INHERITED::clipWillBeSet(newClipData); |
bsalomon@google.com | 86afc2a | 2011-02-16 16:12:19 +0000 | [diff] [blame] | 884 | fClipSet = true; |
| 885 | } |