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