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) { |
jvanverth@google.com | cc78238 | 2013-01-28 20:39:48 +0000 | [diff] [blame] | 121 | layout |= GrDrawState::kColor_VertexLayoutBit; |
robertphillips@google.com | f04c40e | 2012-10-09 17:40:32 +0000 | [diff] [blame] | 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; |
bsalomon@google.com | 02ddc8b | 2013-01-28 15:35:28 +0000 | [diff] [blame] | 170 | const GrClipData* clip = this->getClip(); |
| 171 | clip->fClipStack->getConservativeBounds(-clip->fOrigin.fX, |
| 172 | -clip->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 | } |
jvanverth@google.com | cc78238 | 2013-01-28 20:39:48 +0000 | [diff] [blame] | 196 | int stride = GrDrawState::VertexSize(layout); |
robertphillips@google.com | 641f8b1 | 2012-07-31 19:15:58 +0000 | [diff] [blame] | 197 | bool insideClip = true; |
| 198 | for (int v = 0; v < 4; ++v) { |
jvanverth@google.com | cc78238 | 2013-01-28 20:39:48 +0000 | [diff] [blame] | 199 | const GrPoint& p = *GrDrawState::GetVertexPoint(geo.vertices(), v, stride); |
robertphillips@google.com | 641f8b1 | 2012-07-31 19:15:58 +0000 | [diff] [blame] | 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 | |
jvanverth@google.com | cc78238 | 2013-01-28 20:39:48 +0000 | [diff] [blame] | 218 | int vsize = GrDrawState::VertexSize(layout); |
bsalomon@google.com | d302f14 | 2011-03-03 13:54:13 +0000 | [diff] [blame] | 219 | |
bsalomon@google.com | 74749cd | 2013-01-30 16:12:41 +0000 | [diff] [blame^] | 220 | DrawRecord& lastDraw = fDraws.back(); |
bsalomon@google.com | 86afc2a | 2011-02-16 16:12:19 +0000 | [diff] [blame] | 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 | |
bsalomon@google.com | 74749cd | 2013-01-30 16:12:41 +0000 | [diff] [blame^] | 230 | appendToPreviousDraw = kDraw_Cmd == fCmds.back() && |
| 231 | lastDraw.fVertexBuffer == poolState.fPoolVertexBuffer && |
| 232 | (fCurrQuad * 4 + lastDraw.fStartVertex) == |
| 233 | poolState.fPoolStartVertex; |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 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 | 74749cd | 2013-01-30 16:12:41 +0000 | [diff] [blame^] | 282 | DrawRecord* draw = NULL; |
bsalomon@google.com | 934c570 | 2012-03-20 21:17:58 +0000 | [diff] [blame] | 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 * |
jvanverth@google.com | cc78238 | 2013-01-28 20:39:48 +0000 | [diff] [blame] | 338 | GrDrawState::VertexSize(draw->fVertexLayout); |
bsalomon@google.com | 934c570 | 2012-03-20 21:17:58 +0000 | [diff] [blame] | 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 | } |
bsalomon@google.com | 934c570 | 2012-03-20 21:17:58 +0000 | [diff] [blame] | 374 | } |
| 375 | |
bsalomon@google.com | 74749cd | 2013-01-30 16:12:41 +0000 | [diff] [blame^] | 376 | void GrInOrderDrawBuffer::onDraw(const DrawInfo& info) { |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 377 | |
bsalomon@google.com | 934c570 | 2012-03-20 21:17:58 +0000 | [diff] [blame] | 378 | this->resetDrawTracking(); |
bsalomon@google.com | 86afc2a | 2011-02-16 16:12:19 +0000 | [diff] [blame] | 379 | |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 380 | GeometryPoolState& poolState = fGeoPoolStateStack.back(); |
| 381 | |
bsalomon@google.com | a4f6b10 | 2012-06-26 21:04:22 +0000 | [diff] [blame] | 382 | if (this->needsNewClip()) { |
| 383 | this->recordClip(); |
| 384 | } |
| 385 | if (this->needsNewState()) { |
| 386 | this->recordState(); |
bsalomon@google.com | 86afc2a | 2011-02-16 16:12:19 +0000 | [diff] [blame] | 387 | } |
| 388 | |
bsalomon@google.com | 74749cd | 2013-01-30 16:12:41 +0000 | [diff] [blame^] | 389 | DrawRecord* draw = this->recordDraw(info); |
bsalomon@google.com | a4f6b10 | 2012-06-26 21:04:22 +0000 | [diff] [blame] | 390 | draw->fVertexLayout = this->getVertexLayout(); |
bsalomon@google.com | 74749cd | 2013-01-30 16:12:41 +0000 | [diff] [blame^] | 391 | |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 392 | switch (this->getGeomSrc().fVertexSrc) { |
bsalomon@google.com | 74749cd | 2013-01-30 16:12:41 +0000 | [diff] [blame^] | 393 | case kBuffer_GeometrySrcType: |
| 394 | draw->fVertexBuffer = this->getGeomSrc().fVertexBuffer; |
| 395 | break; |
| 396 | case kReserved_GeometrySrcType: // fallthrough |
| 397 | case kArray_GeometrySrcType: { |
| 398 | size_t vertexBytes = (info.vertexCount() + info.startVertex()) * |
| 399 | GrDrawState::VertexSize(draw->fVertexLayout); |
| 400 | poolState.fUsedPoolVertexBytes = GrMax(poolState.fUsedPoolVertexBytes, vertexBytes); |
| 401 | draw->fVertexBuffer = poolState.fPoolVertexBuffer; |
| 402 | draw->fStartVertex += poolState.fPoolStartVertex; |
| 403 | break; |
| 404 | } |
| 405 | default: |
| 406 | GrCrash("unknown geom src type"); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 407 | } |
bsalomon@google.com | a4f6b10 | 2012-06-26 21:04:22 +0000 | [diff] [blame] | 408 | draw->fVertexBuffer->ref(); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 409 | |
bsalomon@google.com | 74749cd | 2013-01-30 16:12:41 +0000 | [diff] [blame^] | 410 | if (info.isIndexed()) { |
| 411 | switch (this->getGeomSrc().fIndexSrc) { |
| 412 | case kBuffer_GeometrySrcType: |
| 413 | draw->fIndexBuffer = this->getGeomSrc().fIndexBuffer; |
| 414 | break; |
| 415 | case kReserved_GeometrySrcType: // fallthrough |
| 416 | case kArray_GeometrySrcType: { |
| 417 | size_t indexBytes = (info.indexCount() + info.startIndex()) * sizeof(uint16_t); |
| 418 | poolState.fUsedPoolIndexBytes = GrMax(poolState.fUsedPoolIndexBytes, indexBytes); |
| 419 | draw->fIndexBuffer = poolState.fPoolIndexBuffer; |
| 420 | draw->fStartIndex += poolState.fPoolStartIndex; |
| 421 | break; |
| 422 | } |
| 423 | default: |
| 424 | GrCrash("unknown geom src type"); |
| 425 | } |
| 426 | draw->fIndexBuffer->ref(); |
| 427 | } else { |
| 428 | draw->fIndexBuffer = NULL; |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 429 | } |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 430 | } |
| 431 | |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 432 | |
sugoi@google.com | 5f74cf8 | 2012-12-17 21:16:45 +0000 | [diff] [blame] | 433 | GrInOrderDrawBuffer::StencilPath::StencilPath() : fStroke(SkStrokeRec::kFill_InitStyle) {} |
| 434 | |
| 435 | void GrInOrderDrawBuffer::onStencilPath(const GrPath* path, const SkStrokeRec& stroke, |
sugoi@google.com | 12b4e27 | 2012-12-06 20:13:11 +0000 | [diff] [blame] | 436 | SkPath::FillType fill) { |
bsalomon@google.com | ded4f4b | 2012-06-28 18:48:06 +0000 | [diff] [blame] | 437 | if (this->needsNewClip()) { |
| 438 | this->recordClip(); |
| 439 | } |
| 440 | // Only compare the subset of GrDrawState relevant to path stenciling? |
| 441 | if (this->needsNewState()) { |
| 442 | this->recordState(); |
| 443 | } |
| 444 | StencilPath* sp = this->recordStencilPath(); |
| 445 | sp->fPath.reset(path); |
| 446 | path->ref(); |
| 447 | sp->fFill = fill; |
sugoi@google.com | 12b4e27 | 2012-12-06 20:13:11 +0000 | [diff] [blame] | 448 | sp->fStroke = stroke; |
bsalomon@google.com | 64aef2b | 2012-06-11 15:36:13 +0000 | [diff] [blame] | 449 | } |
| 450 | |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 451 | void GrInOrderDrawBuffer::clear(const GrIRect* rect, |
robertphillips@google.com | c82a8b7 | 2012-06-21 20:15:48 +0000 | [diff] [blame] | 452 | GrColor color, |
| 453 | GrRenderTarget* renderTarget) { |
bsalomon@google.com | 6aa25c3 | 2011-04-27 19:55:29 +0000 | [diff] [blame] | 454 | GrIRect r; |
bsalomon@google.com | 1b3ce47 | 2012-08-17 13:43:08 +0000 | [diff] [blame] | 455 | if (NULL == renderTarget) { |
| 456 | renderTarget = this->drawState()->getRenderTarget(); |
| 457 | GrAssert(NULL != renderTarget); |
| 458 | } |
bsalomon@google.com | 6aa25c3 | 2011-04-27 19:55:29 +0000 | [diff] [blame] | 459 | if (NULL == rect) { |
| 460 | // We could do something smart and remove previous draws and clears to |
| 461 | // the current render target. If we get that smart we have to make sure |
| 462 | // those draws aren't read before this clear (render-to-texture). |
bsalomon@google.com | 1b3ce47 | 2012-08-17 13:43:08 +0000 | [diff] [blame] | 463 | r.setLTRB(0, 0, renderTarget->width(), renderTarget->height()); |
bsalomon@google.com | 6aa25c3 | 2011-04-27 19:55:29 +0000 | [diff] [blame] | 464 | rect = &r; |
| 465 | } |
bsalomon@google.com | a4f6b10 | 2012-06-26 21:04:22 +0000 | [diff] [blame] | 466 | Clear* clr = this->recordClear(); |
| 467 | clr->fColor = color; |
| 468 | clr->fRect = *rect; |
| 469 | clr->fRenderTarget = renderTarget; |
bsalomon@google.com | 1b3ce47 | 2012-08-17 13:43:08 +0000 | [diff] [blame] | 470 | renderTarget->ref(); |
bsalomon@google.com | 0b335c1 | 2011-04-25 19:17:44 +0000 | [diff] [blame] | 471 | } |
| 472 | |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 473 | void GrInOrderDrawBuffer::reset() { |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 474 | GrAssert(1 == fGeoPoolStateStack.count()); |
| 475 | this->resetVertexSource(); |
| 476 | this->resetIndexSource(); |
bsalomon@google.com | 86afc2a | 2011-02-16 16:12:19 +0000 | [diff] [blame] | 477 | int numDraws = fDraws.count(); |
| 478 | for (int d = 0; d < numDraws; ++d) { |
| 479 | // we always have a VB, but not always an IB |
| 480 | GrAssert(NULL != fDraws[d].fVertexBuffer); |
| 481 | fDraws[d].fVertexBuffer->unref(); |
| 482 | GrSafeUnref(fDraws[d].fIndexBuffer); |
| 483 | } |
bsalomon@google.com | a4f6b10 | 2012-06-26 21:04:22 +0000 | [diff] [blame] | 484 | fCmds.reset(); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 485 | fDraws.reset(); |
bsalomon@google.com | ded4f4b | 2012-06-28 18:48:06 +0000 | [diff] [blame] | 486 | fStencilPaths.reset(); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 487 | fStates.reset(); |
bsalomon@google.com | 0b335c1 | 2011-04-25 19:17:44 +0000 | [diff] [blame] | 488 | fClears.reset(); |
bsalomon@google.com | 1c13c96 | 2011-02-14 16:51:21 +0000 | [diff] [blame] | 489 | fVertexPool.reset(); |
| 490 | fIndexPool.reset(); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 491 | fClips.reset(); |
robertphillips@google.com | beb1af7 | 2012-07-26 18:52:16 +0000 | [diff] [blame] | 492 | fClipOrigins.reset(); |
bsalomon@google.com | a4f6b10 | 2012-06-26 21:04:22 +0000 | [diff] [blame] | 493 | fClipSet = true; |
bsalomon@google.com | 86afc2a | 2011-02-16 16:12:19 +0000 | [diff] [blame] | 494 | |
bsalomon@google.com | 934c570 | 2012-03-20 21:17:58 +0000 | [diff] [blame] | 495 | this->resetDrawTracking(); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 496 | } |
| 497 | |
bsalomon@google.com | 55e4a20 | 2013-01-11 13:54:21 +0000 | [diff] [blame] | 498 | bool GrInOrderDrawBuffer::flushTo(GrDrawTarget* target) { |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 499 | GrAssert(kReserved_GeometrySrcType != this->getGeomSrc().fVertexSrc); |
| 500 | GrAssert(kReserved_GeometrySrcType != this->getGeomSrc().fIndexSrc); |
bsalomon@google.com | 3f5a95e | 2012-03-08 16:41:42 +0000 | [diff] [blame] | 501 | |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 502 | GrAssert(NULL != target); |
| 503 | GrAssert(target != this); // not considered and why? |
| 504 | |
bsalomon@google.com | a4f6b10 | 2012-06-26 21:04:22 +0000 | [diff] [blame] | 505 | int numCmds = fCmds.count(); |
bsalomon@google.com | 358e427 | 2013-01-10 14:40:28 +0000 | [diff] [blame] | 506 | if (0 == numCmds) { |
bsalomon@google.com | a4f6b10 | 2012-06-26 21:04:22 +0000 | [diff] [blame] | 507 | return false; |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 508 | } |
| 509 | |
bsalomon@google.com | 1c13c96 | 2011-02-14 16:51:21 +0000 | [diff] [blame] | 510 | fVertexPool.unlock(); |
| 511 | fIndexPool.unlock(); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 512 | |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 513 | GrDrawTarget::AutoClipRestore acr(target); |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 514 | AutoGeometryPush agp(target); |
bsalomon@google.com | ca43208 | 2013-01-23 19:53:46 +0000 | [diff] [blame] | 515 | |
| 516 | GrDrawState playbackState; |
bsalomon@google.com | a5d056a | 2012-03-27 15:59:58 +0000 | [diff] [blame] | 517 | GrDrawState* prevDrawState = target->drawState(); |
| 518 | prevDrawState->ref(); |
bsalomon@google.com | ca43208 | 2013-01-23 19:53:46 +0000 | [diff] [blame] | 519 | target->setDrawState(&playbackState); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 520 | |
robertphillips@google.com | beb1af7 | 2012-07-26 18:52:16 +0000 | [diff] [blame] | 521 | GrClipData clipData; |
| 522 | |
bsalomon@google.com | ded4f4b | 2012-06-28 18:48:06 +0000 | [diff] [blame] | 523 | int currState = 0; |
| 524 | int currClip = 0; |
| 525 | int currClear = 0; |
| 526 | int currDraw = 0; |
| 527 | int currStencilPath = 0; |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 528 | |
bsalomon@google.com | ca43208 | 2013-01-23 19:53:46 +0000 | [diff] [blame] | 529 | |
bsalomon@google.com | a4f6b10 | 2012-06-26 21:04:22 +0000 | [diff] [blame] | 530 | for (int c = 0; c < numCmds; ++c) { |
| 531 | switch (fCmds[c]) { |
| 532 | case kDraw_Cmd: { |
bsalomon@google.com | 74749cd | 2013-01-30 16:12:41 +0000 | [diff] [blame^] | 533 | const DrawRecord& draw = fDraws[currDraw]; |
bsalomon@google.com | a4f6b10 | 2012-06-26 21:04:22 +0000 | [diff] [blame] | 534 | target->setVertexSourceToBuffer(draw.fVertexLayout, draw.fVertexBuffer); |
| 535 | if (draw.fIndexCount) { |
| 536 | target->setIndexSourceToBuffer(draw.fIndexBuffer); |
| 537 | } |
bsalomon@google.com | 0b335c1 | 2011-04-25 19:17:44 +0000 | [diff] [blame] | 538 | |
bsalomon@google.com | a4f6b10 | 2012-06-26 21:04:22 +0000 | [diff] [blame] | 539 | if (draw.fIndexCount) { |
| 540 | target->drawIndexed(draw.fPrimitiveType, |
| 541 | draw.fStartVertex, |
| 542 | draw.fStartIndex, |
| 543 | draw.fVertexCount, |
| 544 | draw.fIndexCount); |
| 545 | } else { |
| 546 | target->drawNonIndexed(draw.fPrimitiveType, |
| 547 | draw.fStartVertex, |
| 548 | draw.fVertexCount); |
| 549 | } |
| 550 | ++currDraw; |
| 551 | break; |
| 552 | } |
bsalomon@google.com | ded4f4b | 2012-06-28 18:48:06 +0000 | [diff] [blame] | 553 | case kStencilPath_Cmd: { |
| 554 | const StencilPath& sp = fStencilPaths[currStencilPath]; |
sugoi@google.com | 12b4e27 | 2012-12-06 20:13:11 +0000 | [diff] [blame] | 555 | target->stencilPath(sp.fPath.get(), sp.fStroke, sp.fFill); |
bsalomon@google.com | ded4f4b | 2012-06-28 18:48:06 +0000 | [diff] [blame] | 556 | ++currStencilPath; |
| 557 | break; |
| 558 | } |
bsalomon@google.com | a4f6b10 | 2012-06-26 21:04:22 +0000 | [diff] [blame] | 559 | case kSetState_Cmd: |
bsalomon@google.com | ca43208 | 2013-01-23 19:53:46 +0000 | [diff] [blame] | 560 | fStates[currState].restoreTo(&playbackState); |
bsalomon@google.com | a4f6b10 | 2012-06-26 21:04:22 +0000 | [diff] [blame] | 561 | ++currState; |
| 562 | break; |
| 563 | case kSetClip_Cmd: |
robertphillips@google.com | beb1af7 | 2012-07-26 18:52:16 +0000 | [diff] [blame] | 564 | clipData.fClipStack = &fClips[currClip]; |
| 565 | clipData.fOrigin = fClipOrigins[currClip]; |
| 566 | target->setClip(&clipData); |
bsalomon@google.com | a4f6b10 | 2012-06-26 21:04:22 +0000 | [diff] [blame] | 567 | ++currClip; |
| 568 | break; |
| 569 | case kClear_Cmd: |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 570 | target->clear(&fClears[currClear].fRect, |
bsalomon@google.com | a4f6b10 | 2012-06-26 21:04:22 +0000 | [diff] [blame] | 571 | fClears[currClear].fColor, |
| 572 | fClears[currClear].fRenderTarget); |
| 573 | ++currClear; |
| 574 | break; |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 575 | } |
| 576 | } |
bsalomon@google.com | a4f6b10 | 2012-06-26 21:04:22 +0000 | [diff] [blame] | 577 | // we should have consumed all the states, clips, etc. |
| 578 | GrAssert(fStates.count() == currState); |
| 579 | GrAssert(fClips.count() == currClip); |
robertphillips@google.com | beb1af7 | 2012-07-26 18:52:16 +0000 | [diff] [blame] | 580 | GrAssert(fClipOrigins.count() == currClip); |
bsalomon@google.com | a4f6b10 | 2012-06-26 21:04:22 +0000 | [diff] [blame] | 581 | GrAssert(fClears.count() == currClear); |
| 582 | GrAssert(fDraws.count() == currDraw); |
| 583 | |
bsalomon@google.com | a5d056a | 2012-03-27 15:59:58 +0000 | [diff] [blame] | 584 | target->setDrawState(prevDrawState); |
| 585 | prevDrawState->unref(); |
bsalomon@google.com | 55e4a20 | 2013-01-11 13:54:21 +0000 | [diff] [blame] | 586 | this->reset(); |
bsalomon@google.com | a4f6b10 | 2012-06-26 21:04:22 +0000 | [diff] [blame] | 587 | return true; |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 588 | } |
| 589 | |
bsalomon@google.com | 9780538 | 2012-03-13 14:32:07 +0000 | [diff] [blame] | 590 | void GrInOrderDrawBuffer::setAutoFlushTarget(GrDrawTarget* target) { |
| 591 | GrSafeAssign(fAutoFlushTarget, target); |
| 592 | } |
| 593 | |
| 594 | void GrInOrderDrawBuffer::willReserveVertexAndIndexSpace( |
| 595 | GrVertexLayout vertexLayout, |
| 596 | int vertexCount, |
| 597 | int indexCount) { |
| 598 | if (NULL != fAutoFlushTarget) { |
| 599 | // We use geometryHints() to know whether to flush the draw buffer. We |
| 600 | // can't flush if we are inside an unbalanced pushGeometrySource. |
| 601 | // Moreover, flushing blows away vertex and index data that was |
| 602 | // previously reserved. So if the vertex or index data is pulled from |
| 603 | // reserved space and won't be released by this request then we can't |
| 604 | // flush. |
| 605 | bool insideGeoPush = fGeoPoolStateStack.count() > 1; |
| 606 | |
| 607 | bool unreleasedVertexSpace = |
| 608 | !vertexCount && |
| 609 | kReserved_GeometrySrcType == this->getGeomSrc().fVertexSrc; |
| 610 | |
| 611 | bool unreleasedIndexSpace = |
| 612 | !indexCount && |
| 613 | kReserved_GeometrySrcType == this->getGeomSrc().fIndexSrc; |
| 614 | |
| 615 | // we don't want to finalize any reserved geom on the target since |
| 616 | // we don't know that the client has finished writing to it. |
| 617 | bool targetHasReservedGeom = |
| 618 | fAutoFlushTarget->hasReservedVerticesOrIndices(); |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 619 | |
bsalomon@google.com | 9780538 | 2012-03-13 14:32:07 +0000 | [diff] [blame] | 620 | int vcount = vertexCount; |
| 621 | int icount = indexCount; |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 622 | |
bsalomon@google.com | 9780538 | 2012-03-13 14:32:07 +0000 | [diff] [blame] | 623 | if (!insideGeoPush && |
| 624 | !unreleasedVertexSpace && |
| 625 | !unreleasedIndexSpace && |
| 626 | !targetHasReservedGeom && |
| 627 | this->geometryHints(vertexLayout, &vcount, &icount)) { |
| 628 | |
| 629 | this->flushTo(fAutoFlushTarget); |
| 630 | } |
| 631 | } |
| 632 | } |
| 633 | |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 634 | bool GrInOrderDrawBuffer::geometryHints(GrVertexLayout vertexLayout, |
bsalomon@google.com | 1c13c96 | 2011-02-14 16:51:21 +0000 | [diff] [blame] | 635 | int* vertexCount, |
| 636 | int* indexCount) const { |
| 637 | // we will recommend a flush if the data could fit in a single |
| 638 | // preallocated buffer but none are left and it can't fit |
| 639 | // in the current buffer (which may not be prealloced). |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 640 | bool flush = false; |
| 641 | if (NULL != indexCount) { |
bsalomon@google.com | 1c13c96 | 2011-02-14 16:51:21 +0000 | [diff] [blame] | 642 | int32_t currIndices = fIndexPool.currentBufferIndices(); |
| 643 | if (*indexCount > currIndices && |
| 644 | (!fIndexPool.preallocatedBuffersRemaining() && |
| 645 | *indexCount <= fIndexPool.preallocatedBufferIndices())) { |
| 646 | |
| 647 | flush = true; |
| 648 | } |
| 649 | *indexCount = currIndices; |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 650 | } |
| 651 | if (NULL != vertexCount) { |
bsalomon@google.com | 1c13c96 | 2011-02-14 16:51:21 +0000 | [diff] [blame] | 652 | int32_t currVertices = fVertexPool.currentBufferVertices(vertexLayout); |
| 653 | if (*vertexCount > currVertices && |
| 654 | (!fVertexPool.preallocatedBuffersRemaining() && |
| 655 | *vertexCount <= fVertexPool.preallocatedBufferVertices(vertexLayout))) { |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 656 | |
bsalomon@google.com | 1c13c96 | 2011-02-14 16:51:21 +0000 | [diff] [blame] | 657 | flush = true; |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 658 | } |
bsalomon@google.com | 1c13c96 | 2011-02-14 16:51:21 +0000 | [diff] [blame] | 659 | *vertexCount = currVertices; |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 660 | } |
| 661 | return flush; |
| 662 | } |
| 663 | |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 664 | bool GrInOrderDrawBuffer::onReserveVertexSpace(GrVertexLayout vertexLayout, |
| 665 | int vertexCount, |
| 666 | void** vertices) { |
| 667 | GeometryPoolState& poolState = fGeoPoolStateStack.back(); |
| 668 | GrAssert(vertexCount > 0); |
| 669 | GrAssert(NULL != vertices); |
| 670 | GrAssert(0 == poolState.fUsedPoolVertexBytes); |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 671 | |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 672 | *vertices = fVertexPool.makeSpace(vertexLayout, |
| 673 | vertexCount, |
| 674 | &poolState.fPoolVertexBuffer, |
| 675 | &poolState.fPoolStartVertex); |
| 676 | return NULL != *vertices; |
| 677 | } |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 678 | |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 679 | bool GrInOrderDrawBuffer::onReserveIndexSpace(int indexCount, void** indices) { |
| 680 | GeometryPoolState& poolState = fGeoPoolStateStack.back(); |
| 681 | GrAssert(indexCount > 0); |
| 682 | GrAssert(NULL != indices); |
| 683 | GrAssert(0 == poolState.fUsedPoolIndexBytes); |
bsalomon@google.com | 1c13c96 | 2011-02-14 16:51:21 +0000 | [diff] [blame] | 684 | |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 685 | *indices = fIndexPool.makeSpace(indexCount, |
| 686 | &poolState.fPoolIndexBuffer, |
| 687 | &poolState.fPoolStartIndex); |
| 688 | return NULL != *indices; |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 689 | } |
| 690 | |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 691 | void GrInOrderDrawBuffer::releaseReservedVertexSpace() { |
| 692 | GeometryPoolState& poolState = fGeoPoolStateStack.back(); |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 693 | const GeometrySrcState& geoSrc = this->getGeomSrc(); |
bsalomon@google.com | d57d71a | 2012-08-16 16:26:33 +0000 | [diff] [blame] | 694 | |
| 695 | // If we get a release vertex space call then our current source should either be reserved |
| 696 | // or array (which we copied into reserved space). |
| 697 | GrAssert(kReserved_GeometrySrcType == geoSrc.fVertexSrc || |
| 698 | kArray_GeometrySrcType == geoSrc.fVertexSrc); |
bsalomon@google.com | 3f5a95e | 2012-03-08 16:41:42 +0000 | [diff] [blame] | 699 | |
| 700 | // When the caller reserved vertex buffer space we gave it back a pointer |
| 701 | // provided by the vertex buffer pool. At each draw we tracked the largest |
| 702 | // offset into the pool's pointer that was referenced. Now we return to the |
| 703 | // pool any portion at the tail of the allocation that no draw referenced. |
jvanverth@google.com | cc78238 | 2013-01-28 20:39:48 +0000 | [diff] [blame] | 704 | size_t reservedVertexBytes = GrDrawState::VertexSize(geoSrc.fVertexLayout) * |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 705 | geoSrc.fVertexCount; |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 706 | fVertexPool.putBack(reservedVertexBytes - |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 707 | poolState.fUsedPoolVertexBytes); |
| 708 | poolState.fUsedPoolVertexBytes = 0; |
bsalomon@google.com | 3f5a95e | 2012-03-08 16:41:42 +0000 | [diff] [blame] | 709 | poolState.fPoolVertexBuffer = NULL; |
| 710 | poolState.fPoolStartVertex = 0; |
bsalomon@google.com | 1c13c96 | 2011-02-14 16:51:21 +0000 | [diff] [blame] | 711 | } |
| 712 | |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 713 | void GrInOrderDrawBuffer::releaseReservedIndexSpace() { |
| 714 | GeometryPoolState& poolState = fGeoPoolStateStack.back(); |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 715 | const GeometrySrcState& geoSrc = this->getGeomSrc(); |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 716 | |
bsalomon@google.com | d57d71a | 2012-08-16 16:26:33 +0000 | [diff] [blame] | 717 | // If we get a release index space call then our current source should either be reserved |
| 718 | // or array (which we copied into reserved space). |
| 719 | GrAssert(kReserved_GeometrySrcType == geoSrc.fIndexSrc || |
| 720 | kArray_GeometrySrcType == geoSrc.fIndexSrc); |
bsalomon@google.com | 3f5a95e | 2012-03-08 16:41:42 +0000 | [diff] [blame] | 721 | |
| 722 | // Similar to releaseReservedVertexSpace we return any unused portion at |
| 723 | // the tail |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 724 | size_t reservedIndexBytes = sizeof(uint16_t) * geoSrc.fIndexCount; |
| 725 | fIndexPool.putBack(reservedIndexBytes - poolState.fUsedPoolIndexBytes); |
| 726 | poolState.fUsedPoolIndexBytes = 0; |
bsalomon@google.com | 3f5a95e | 2012-03-08 16:41:42 +0000 | [diff] [blame] | 727 | poolState.fPoolIndexBuffer = NULL; |
| 728 | poolState.fPoolStartIndex = 0; |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 729 | } |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 730 | |
bsalomon@google.com | bcdbbe6 | 2011-04-12 15:40:00 +0000 | [diff] [blame] | 731 | void GrInOrderDrawBuffer::onSetVertexSourceToArray(const void* vertexArray, |
| 732 | int vertexCount) { |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 733 | |
| 734 | GeometryPoolState& poolState = fGeoPoolStateStack.back(); |
| 735 | GrAssert(0 == poolState.fUsedPoolVertexBytes); |
bsalomon@google.com | 1c13c96 | 2011-02-14 16:51:21 +0000 | [diff] [blame] | 736 | #if GR_DEBUG |
| 737 | bool success = |
| 738 | #endif |
bsalomon@google.com | e79c815 | 2012-03-29 19:07:12 +0000 | [diff] [blame] | 739 | fVertexPool.appendVertices(this->getVertexLayout(), |
bsalomon@google.com | 1c13c96 | 2011-02-14 16:51:21 +0000 | [diff] [blame] | 740 | vertexCount, |
| 741 | vertexArray, |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 742 | &poolState.fPoolVertexBuffer, |
| 743 | &poolState.fPoolStartVertex); |
bsalomon@google.com | 1c13c96 | 2011-02-14 16:51:21 +0000 | [diff] [blame] | 744 | GR_DEBUGASSERT(success); |
| 745 | } |
| 746 | |
bsalomon@google.com | bcdbbe6 | 2011-04-12 15:40:00 +0000 | [diff] [blame] | 747 | void GrInOrderDrawBuffer::onSetIndexSourceToArray(const void* indexArray, |
| 748 | int indexCount) { |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 749 | GeometryPoolState& poolState = fGeoPoolStateStack.back(); |
| 750 | GrAssert(0 == poolState.fUsedPoolIndexBytes); |
bsalomon@google.com | 1c13c96 | 2011-02-14 16:51:21 +0000 | [diff] [blame] | 751 | #if GR_DEBUG |
| 752 | bool success = |
| 753 | #endif |
| 754 | fIndexPool.appendIndices(indexCount, |
| 755 | indexArray, |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 756 | &poolState.fPoolIndexBuffer, |
| 757 | &poolState.fPoolStartIndex); |
bsalomon@google.com | 1c13c96 | 2011-02-14 16:51:21 +0000 | [diff] [blame] | 758 | GR_DEBUGASSERT(success); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 759 | } |
| 760 | |
bsalomon@google.com | 3f5a95e | 2012-03-08 16:41:42 +0000 | [diff] [blame] | 761 | void GrInOrderDrawBuffer::releaseVertexArray() { |
| 762 | // When the client provides an array as the vertex source we handled it |
| 763 | // by copying their array into reserved space. |
| 764 | this->GrInOrderDrawBuffer::releaseReservedVertexSpace(); |
| 765 | } |
| 766 | |
| 767 | void GrInOrderDrawBuffer::releaseIndexArray() { |
| 768 | // When the client provides an array as the index source we handled it |
| 769 | // by copying their array into reserved space. |
| 770 | this->GrInOrderDrawBuffer::releaseReservedIndexSpace(); |
| 771 | } |
| 772 | |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 773 | void GrInOrderDrawBuffer::geometrySourceWillPush() { |
| 774 | GeometryPoolState& poolState = fGeoPoolStateStack.push_back(); |
| 775 | poolState.fUsedPoolVertexBytes = 0; |
| 776 | poolState.fUsedPoolIndexBytes = 0; |
bsalomon@google.com | 934c570 | 2012-03-20 21:17:58 +0000 | [diff] [blame] | 777 | this->resetDrawTracking(); |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 778 | #if GR_DEBUG |
| 779 | poolState.fPoolVertexBuffer = (GrVertexBuffer*)~0; |
| 780 | poolState.fPoolStartVertex = ~0; |
| 781 | poolState.fPoolIndexBuffer = (GrIndexBuffer*)~0; |
| 782 | poolState.fPoolStartIndex = ~0; |
| 783 | #endif |
| 784 | } |
| 785 | |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 786 | void GrInOrderDrawBuffer::geometrySourceWillPop( |
| 787 | const GeometrySrcState& restoredState) { |
| 788 | GrAssert(fGeoPoolStateStack.count() > 1); |
| 789 | fGeoPoolStateStack.pop_back(); |
| 790 | GeometryPoolState& poolState = fGeoPoolStateStack.back(); |
| 791 | // we have to assume that any slack we had in our vertex/index data |
| 792 | // is now unreleasable because data may have been appended later in the |
| 793 | // pool. |
| 794 | if (kReserved_GeometrySrcType == restoredState.fVertexSrc || |
| 795 | kArray_GeometrySrcType == restoredState.fVertexSrc) { |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 796 | poolState.fUsedPoolVertexBytes = |
jvanverth@google.com | cc78238 | 2013-01-28 20:39:48 +0000 | [diff] [blame] | 797 | GrDrawState::VertexSize(restoredState.fVertexLayout) * |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 798 | restoredState.fVertexCount; |
| 799 | } |
| 800 | if (kReserved_GeometrySrcType == restoredState.fIndexSrc || |
| 801 | kArray_GeometrySrcType == restoredState.fIndexSrc) { |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 802 | poolState.fUsedPoolIndexBytes = sizeof(uint16_t) * |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 803 | restoredState.fIndexCount; |
| 804 | } |
bsalomon@google.com | 934c570 | 2012-03-20 21:17:58 +0000 | [diff] [blame] | 805 | this->resetDrawTracking(); |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 806 | } |
| 807 | |
bsalomon@google.com | 86afc2a | 2011-02-16 16:12:19 +0000 | [diff] [blame] | 808 | bool GrInOrderDrawBuffer::needsNewState() const { |
bsalomon@google.com | ca43208 | 2013-01-23 19:53:46 +0000 | [diff] [blame] | 809 | return fStates.empty() || !fStates.back().isEqual(this->getDrawState()); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 810 | } |
| 811 | |
bsalomon@google.com | 86afc2a | 2011-02-16 16:12:19 +0000 | [diff] [blame] | 812 | bool GrInOrderDrawBuffer::needsNewClip() const { |
bsalomon@google.com | 358e427 | 2013-01-10 14:40:28 +0000 | [diff] [blame] | 813 | GrAssert(fClips.count() == fClipOrigins.count()); |
| 814 | if (this->getDrawState().isClipState()) { |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 815 | if (fClipSet && |
bsalomon@google.com | 358e427 | 2013-01-10 14:40:28 +0000 | [diff] [blame] | 816 | (fClips.empty() || |
bsalomon@google.com | 02ddc8b | 2013-01-28 15:35:28 +0000 | [diff] [blame] | 817 | fClips.back() != *this->getClip()->fClipStack || |
| 818 | fClipOrigins.back() != this->getClip()->fOrigin)) { |
bsalomon@google.com | 86afc2a | 2011-02-16 16:12:19 +0000 | [diff] [blame] | 819 | return true; |
| 820 | } |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 821 | } |
| 822 | return false; |
| 823 | } |
bsalomon@google.com | d302f14 | 2011-03-03 13:54:13 +0000 | [diff] [blame] | 824 | |
bsalomon@google.com | a4f6b10 | 2012-06-26 21:04:22 +0000 | [diff] [blame] | 825 | void GrInOrderDrawBuffer::recordClip() { |
bsalomon@google.com | 02ddc8b | 2013-01-28 15:35:28 +0000 | [diff] [blame] | 826 | fClips.push_back() = *this->getClip()->fClipStack; |
| 827 | fClipOrigins.push_back() = this->getClip()->fOrigin; |
bsalomon@google.com | 86afc2a | 2011-02-16 16:12:19 +0000 | [diff] [blame] | 828 | fClipSet = false; |
bsalomon@google.com | a4f6b10 | 2012-06-26 21:04:22 +0000 | [diff] [blame] | 829 | fCmds.push_back(kSetClip_Cmd); |
| 830 | } |
| 831 | |
bsalomon@google.com | a4f6b10 | 2012-06-26 21:04:22 +0000 | [diff] [blame] | 832 | void GrInOrderDrawBuffer::recordState() { |
bsalomon@google.com | ca43208 | 2013-01-23 19:53:46 +0000 | [diff] [blame] | 833 | fStates.push_back().saveFrom(this->getDrawState()); |
bsalomon@google.com | a4f6b10 | 2012-06-26 21:04:22 +0000 | [diff] [blame] | 834 | fCmds.push_back(kSetState_Cmd); |
| 835 | } |
| 836 | |
bsalomon@google.com | 74749cd | 2013-01-30 16:12:41 +0000 | [diff] [blame^] | 837 | GrInOrderDrawBuffer::DrawRecord* GrInOrderDrawBuffer::recordDraw() { |
bsalomon@google.com | a4f6b10 | 2012-06-26 21:04:22 +0000 | [diff] [blame] | 838 | fCmds.push_back(kDraw_Cmd); |
| 839 | return &fDraws.push_back(); |
| 840 | } |
| 841 | |
bsalomon@google.com | 74749cd | 2013-01-30 16:12:41 +0000 | [diff] [blame^] | 842 | GrInOrderDrawBuffer::DrawRecord* GrInOrderDrawBuffer::recordDraw(const DrawInfo& info) { |
| 843 | DrawRecord* record = this->recordDraw(); |
| 844 | record->fPrimitiveType = info.primitiveType(); |
| 845 | record->fStartVertex = info.startVertex(); |
| 846 | record->fVertexCount = info.vertexCount(); |
| 847 | record->fStartIndex = info.startIndex(); |
| 848 | record->fIndexCount = info.indexCount(); |
| 849 | return record; |
| 850 | } |
| 851 | |
bsalomon@google.com | ded4f4b | 2012-06-28 18:48:06 +0000 | [diff] [blame] | 852 | GrInOrderDrawBuffer::StencilPath* GrInOrderDrawBuffer::recordStencilPath() { |
| 853 | fCmds.push_back(kStencilPath_Cmd); |
| 854 | return &fStencilPaths.push_back(); |
| 855 | } |
| 856 | |
bsalomon@google.com | a4f6b10 | 2012-06-26 21:04:22 +0000 | [diff] [blame] | 857 | GrInOrderDrawBuffer::Clear* GrInOrderDrawBuffer::recordClear() { |
| 858 | fCmds.push_back(kClear_Cmd); |
| 859 | return &fClears.push_back(); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 860 | } |
bsalomon@google.com | d302f14 | 2011-03-03 13:54:13 +0000 | [diff] [blame] | 861 | |
robertphillips@google.com | beb1af7 | 2012-07-26 18:52:16 +0000 | [diff] [blame] | 862 | void GrInOrderDrawBuffer::clipWillBeSet(const GrClipData* newClipData) { |
| 863 | INHERITED::clipWillBeSet(newClipData); |
bsalomon@google.com | 86afc2a | 2011-02-16 16:12:19 +0000 | [diff] [blame] | 864 | fClipSet = true; |
| 865 | } |