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