reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 1 | /* |
epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 2 | * Copyright 2011 Google Inc. |
| 3 | * |
| 4 | * Use of this source code is governed by a BSD-style license that can be |
| 5 | * found in the LICENSE file. |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 6 | */ |
| 7 | |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 8 | #include "GrInOrderDrawBuffer.h" |
commit-bot@chromium.org | fd03d4a | 2013-07-17 21:39:42 +0000 | [diff] [blame] | 9 | |
bsalomon@google.com | ded4f4b | 2012-06-28 18:48:06 +0000 | [diff] [blame] | 10 | #include "GrBufferAllocPool.h" |
bsalomon@google.com | c26d94f | 2013-03-25 18:19:00 +0000 | [diff] [blame] | 11 | #include "GrDrawTargetCaps.h" |
bsalomon@google.com | ded4f4b | 2012-06-28 18:48:06 +0000 | [diff] [blame] | 12 | #include "GrGpu.h" |
| 13 | #include "GrIndexBuffer.h" |
| 14 | #include "GrPath.h" |
commit-bot@chromium.org | fd03d4a | 2013-07-17 21:39:42 +0000 | [diff] [blame] | 15 | #include "GrPoint.h" |
bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 16 | #include "GrRenderTarget.h" |
bsalomon@google.com | 6e4e650 | 2013-02-25 20:12:45 +0000 | [diff] [blame] | 17 | #include "GrTemplates.h" |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 18 | #include "GrTexture.h" |
bsalomon@google.com | 86afc2a | 2011-02-16 16:12:19 +0000 | [diff] [blame] | 19 | #include "GrVertexBuffer.h" |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 20 | |
bsalomon@google.com | 6e4e650 | 2013-02-25 20:12:45 +0000 | [diff] [blame] | 21 | GrInOrderDrawBuffer::GrInOrderDrawBuffer(GrGpu* gpu, |
bsalomon@google.com | 471d471 | 2011-08-23 15:45:25 +0000 | [diff] [blame] | 22 | GrVertexBufferAllocPool* vertexPool, |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 23 | GrIndexBufferAllocPool* indexPool) |
bsalomon@google.com | 6e4e650 | 2013-02-25 20:12:45 +0000 | [diff] [blame] | 24 | : GrDrawTarget(gpu->getContext()) |
| 25 | , fDstGpu(gpu) |
bsalomon@google.com | 9780538 | 2012-03-13 14:32:07 +0000 | [diff] [blame] | 26 | , fClipSet(true) |
bsalomon@google.com | d62e88e | 2013-02-01 14:19:27 +0000 | [diff] [blame] | 27 | , fClipProxyState(kUnknown_ClipProxyState) |
robertphillips@google.com | 6970557 | 2012-03-21 19:46:50 +0000 | [diff] [blame] | 28 | , fVertexPool(*vertexPool) |
| 29 | , fIndexPool(*indexPool) |
commit-bot@chromium.org | a8916ff | 2013-08-16 15:53:46 +0000 | [diff] [blame] | 30 | , fFlushing(false) |
| 31 | , fDrawID(0) { |
bsalomon@google.com | 18c9c19 | 2011-09-22 21:01:31 +0000 | [diff] [blame] | 32 | |
bsalomon@google.com | 6e4e650 | 2013-02-25 20:12:45 +0000 | [diff] [blame] | 33 | fDstGpu->ref(); |
bsalomon@google.com | bcce892 | 2013-03-25 15:38:39 +0000 | [diff] [blame] | 34 | fCaps.reset(SkRef(fDstGpu->caps())); |
bsalomon@google.com | 18c9c19 | 2011-09-22 21:01:31 +0000 | [diff] [blame] | 35 | |
tfarina@chromium.org | f6de475 | 2013-08-17 00:02:59 +0000 | [diff] [blame] | 36 | SkASSERT(NULL != vertexPool); |
| 37 | SkASSERT(NULL != indexPool); |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 38 | |
| 39 | GeometryPoolState& poolState = fGeoPoolStateStack.push_back(); |
| 40 | poolState.fUsedPoolVertexBytes = 0; |
| 41 | poolState.fUsedPoolIndexBytes = 0; |
commit-bot@chromium.org | 515dcd3 | 2013-08-28 14:17:03 +0000 | [diff] [blame] | 42 | #ifdef SK_DEBUG |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 43 | poolState.fPoolVertexBuffer = (GrVertexBuffer*)~0; |
| 44 | poolState.fPoolStartVertex = ~0; |
| 45 | poolState.fPoolIndexBuffer = (GrIndexBuffer*)~0; |
| 46 | poolState.fPoolStartIndex = ~0; |
| 47 | #endif |
bsalomon@google.com | a4f6b10 | 2012-06-26 21:04:22 +0000 | [diff] [blame] | 48 | this->reset(); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 49 | } |
| 50 | |
| 51 | GrInOrderDrawBuffer::~GrInOrderDrawBuffer() { |
bsalomon@google.com | 86afc2a | 2011-02-16 16:12:19 +0000 | [diff] [blame] | 52 | this->reset(); |
bsalomon@google.com | 4a018bb | 2011-10-28 19:50:21 +0000 | [diff] [blame] | 53 | // This must be called by before the GrDrawTarget destructor |
| 54 | this->releaseGeometry(); |
bsalomon@google.com | 6e4e650 | 2013-02-25 20:12:45 +0000 | [diff] [blame] | 55 | fDstGpu->unref(); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 56 | } |
| 57 | |
bsalomon@google.com | 934c570 | 2012-03-20 21:17:58 +0000 | [diff] [blame] | 58 | //////////////////////////////////////////////////////////////////////////////// |
| 59 | |
bsalomon@google.com | d62e88e | 2013-02-01 14:19:27 +0000 | [diff] [blame] | 60 | namespace { |
| 61 | void get_vertex_bounds(const void* vertices, |
| 62 | size_t vertexSize, |
| 63 | int vertexCount, |
| 64 | SkRect* bounds) { |
tfarina@chromium.org | f6de475 | 2013-08-17 00:02:59 +0000 | [diff] [blame] | 65 | SkASSERT(vertexSize >= sizeof(GrPoint)); |
| 66 | SkASSERT(vertexCount > 0); |
bsalomon@google.com | d62e88e | 2013-02-01 14:19:27 +0000 | [diff] [blame] | 67 | const GrPoint* point = static_cast<const GrPoint*>(vertices); |
| 68 | bounds->fLeft = bounds->fRight = point->fX; |
| 69 | bounds->fTop = bounds->fBottom = point->fY; |
| 70 | for (int i = 1; i < vertexCount; ++i) { |
| 71 | point = reinterpret_cast<GrPoint*>(reinterpret_cast<intptr_t>(point) + vertexSize); |
| 72 | bounds->growToInclude(point->fX, point->fY); |
| 73 | } |
| 74 | } |
bsalomon@google.com | 934c570 | 2012-03-20 21:17:58 +0000 | [diff] [blame] | 75 | } |
| 76 | |
robertphillips@google.com | 4290330 | 2013-04-20 12:26:07 +0000 | [diff] [blame] | 77 | |
| 78 | namespace { |
| 79 | |
| 80 | extern const GrVertexAttrib kRectPosColorUVAttribs[] = { |
| 81 | {kVec2f_GrVertexAttribType, 0, kPosition_GrVertexAttribBinding}, |
| 82 | {kVec4ub_GrVertexAttribType, sizeof(GrPoint), kColor_GrVertexAttribBinding}, |
rmistry@google.com | c9f3b38 | 2013-04-22 12:45:30 +0000 | [diff] [blame] | 83 | {kVec2f_GrVertexAttribType, sizeof(GrPoint)+sizeof(GrColor), |
robertphillips@google.com | 4290330 | 2013-04-20 12:26:07 +0000 | [diff] [blame] | 84 | kLocalCoord_GrVertexAttribBinding}, |
| 85 | }; |
| 86 | |
| 87 | extern const GrVertexAttrib kRectPosUVAttribs[] = { |
| 88 | {kVec2f_GrVertexAttribType, 0, kPosition_GrVertexAttribBinding}, |
| 89 | {kVec2f_GrVertexAttribType, sizeof(GrPoint), kLocalCoord_GrVertexAttribBinding}, |
| 90 | }; |
| 91 | |
| 92 | static void set_vertex_attributes(GrDrawState* drawState, |
| 93 | bool hasColor, bool hasUVs, |
| 94 | int* colorOffset, int* localOffset) { |
| 95 | *colorOffset = -1; |
| 96 | *localOffset = -1; |
| 97 | |
| 98 | // Using per-vertex colors allows batching across colors. (A lot of rects in a row differing |
| 99 | // only in color is a common occurrence in tables). However, having per-vertex colors disables |
| 100 | // blending optimizations because we don't know if the color will be solid or not. These |
| 101 | // optimizations help determine whether coverage and color can be blended correctly when |
| 102 | // dual-source blending isn't available. This comes into play when there is coverage. If colors |
| 103 | // were a stage it could take a hint that every vertex's color will be opaque. |
| 104 | if (hasColor && hasUVs) { |
| 105 | *colorOffset = sizeof(GrPoint); |
| 106 | *localOffset = sizeof(GrPoint) + sizeof(GrColor); |
| 107 | drawState->setVertexAttribs<kRectPosColorUVAttribs>(3); |
| 108 | } else if (hasColor) { |
| 109 | *colorOffset = sizeof(GrPoint); |
| 110 | drawState->setVertexAttribs<kRectPosColorUVAttribs>(2); |
| 111 | } else if (hasUVs) { |
| 112 | *localOffset = sizeof(GrPoint); |
| 113 | drawState->setVertexAttribs<kRectPosUVAttribs>(2); |
| 114 | } else { |
| 115 | drawState->setVertexAttribs<kRectPosUVAttribs>(1); |
| 116 | } |
| 117 | } |
| 118 | |
| 119 | }; |
| 120 | |
commit-bot@chromium.org | fd03d4a | 2013-07-17 21:39:42 +0000 | [diff] [blame] | 121 | void GrInOrderDrawBuffer::onDrawRect(const SkRect& rect, |
bsalomon@google.com | 0406b9e | 2013-04-02 21:00:15 +0000 | [diff] [blame] | 122 | const SkMatrix* matrix, |
commit-bot@chromium.org | fd03d4a | 2013-07-17 21:39:42 +0000 | [diff] [blame] | 123 | const SkRect* localRect, |
bsalomon@google.com | 0406b9e | 2013-04-02 21:00:15 +0000 | [diff] [blame] | 124 | const SkMatrix* localMatrix) { |
bsalomon@google.com | d62e88e | 2013-02-01 14:19:27 +0000 | [diff] [blame] | 125 | GrDrawState::AutoColorRestore acr; |
jvanverth@google.com | 9b855c7 | 2013-03-01 18:21:22 +0000 | [diff] [blame] | 126 | |
| 127 | GrDrawState* drawState = this->drawState(); |
| 128 | |
| 129 | GrColor color = drawState->getColor(); |
jvanverth@google.com | 9b855c7 | 2013-03-01 18:21:22 +0000 | [diff] [blame] | 130 | |
robertphillips@google.com | 4290330 | 2013-04-20 12:26:07 +0000 | [diff] [blame] | 131 | int colorOffset, localOffset; |
| 132 | set_vertex_attributes(drawState, |
| 133 | this->caps()->dualSourceBlendingSupport() || drawState->hasSolidCoverage(), |
| 134 | NULL != localRect, |
| 135 | &colorOffset, &localOffset); |
| 136 | if (colorOffset >= 0) { |
bsalomon@google.com | d62e88e | 2013-02-01 14:19:27 +0000 | [diff] [blame] | 137 | // We set the draw state's color to white here. This is done so that any batching performed |
| 138 | // in our subclass's onDraw() won't get a false from GrDrawState::op== due to a color |
| 139 | // mismatch. TODO: Once vertex layout is owned by GrDrawState it should skip comparing the |
rmistry@google.com | c9f3b38 | 2013-04-22 12:45:30 +0000 | [diff] [blame] | 140 | // constant color in its op== when the kColor layout bit is set and then we can remove |
robertphillips@google.com | 4290330 | 2013-04-20 12:26:07 +0000 | [diff] [blame] | 141 | // this. |
jvanverth@google.com | 9b855c7 | 2013-03-01 18:21:22 +0000 | [diff] [blame] | 142 | acr.set(drawState, 0xFFFFFFFF); |
bsalomon@google.com | 86afc2a | 2011-02-16 16:12:19 +0000 | [diff] [blame] | 143 | } |
bsalomon@google.com | 86afc2a | 2011-02-16 16:12:19 +0000 | [diff] [blame] | 144 | |
jvanverth@google.com | b75b0a0 | 2013-02-05 20:33:30 +0000 | [diff] [blame] | 145 | AutoReleaseGeometry geo(this, 4, 0); |
bsalomon@google.com | d62e88e | 2013-02-01 14:19:27 +0000 | [diff] [blame] | 146 | if (!geo.succeeded()) { |
| 147 | GrPrintf("Failed to get space for vertices!\n"); |
bsalomon@google.com | 934c570 | 2012-03-20 21:17:58 +0000 | [diff] [blame] | 148 | return; |
| 149 | } |
| 150 | |
bsalomon@google.com | d62e88e | 2013-02-01 14:19:27 +0000 | [diff] [blame] | 151 | // Go to device coords to allow batching across matrix changes |
| 152 | SkMatrix combinedMatrix; |
| 153 | if (NULL != matrix) { |
| 154 | combinedMatrix = *matrix; |
| 155 | } else { |
| 156 | combinedMatrix.reset(); |
| 157 | } |
jvanverth@google.com | 9b855c7 | 2013-03-01 18:21:22 +0000 | [diff] [blame] | 158 | combinedMatrix.postConcat(drawState->getViewMatrix()); |
jvanverth@google.com | 3976825 | 2013-02-14 15:25:44 +0000 | [diff] [blame] | 159 | // When the caller has provided an explicit source rect for a stage then we don't want to |
bsalomon@google.com | d62e88e | 2013-02-01 14:19:27 +0000 | [diff] [blame] | 160 | // modify that stage's matrix. Otherwise if the effect is generating its source rect from |
| 161 | // the vertex positions then we have to account for the view matrix change. |
bsalomon@google.com | 137f134 | 2013-05-29 21:27:53 +0000 | [diff] [blame] | 162 | GrDrawState::AutoViewMatrixRestore avmr; |
| 163 | if (!avmr.setIdentity(drawState)) { |
bsalomon@google.com | d62e88e | 2013-02-01 14:19:27 +0000 | [diff] [blame] | 164 | return; |
| 165 | } |
| 166 | |
jvanverth@google.com | 9b855c7 | 2013-03-01 18:21:22 +0000 | [diff] [blame] | 167 | size_t vsize = drawState->getVertexSize(); |
bsalomon@google.com | d62e88e | 2013-02-01 14:19:27 +0000 | [diff] [blame] | 168 | |
| 169 | geo.positions()->setRectFan(rect.fLeft, rect.fTop, rect.fRight, rect.fBottom, vsize); |
| 170 | combinedMatrix.mapPointsWithStride(geo.positions(), vsize, 4); |
| 171 | |
| 172 | SkRect devBounds; |
| 173 | // since we already computed the dev verts, set the bounds hint. This will help us avoid |
| 174 | // unnecessary clipping in our onDraw(). |
| 175 | get_vertex_bounds(geo.vertices(), vsize, 4, &devBounds); |
| 176 | |
bsalomon@google.com | c781888 | 2013-03-20 19:19:53 +0000 | [diff] [blame] | 177 | if (localOffset >= 0) { |
| 178 | GrPoint* coords = GrTCast<GrPoint*>(GrTCast<intptr_t>(geo.vertices()) + localOffset); |
| 179 | coords->setRectFan(localRect->fLeft, localRect->fTop, |
| 180 | localRect->fRight, localRect->fBottom, |
jvanverth@google.com | 9b855c7 | 2013-03-01 18:21:22 +0000 | [diff] [blame] | 181 | vsize); |
bsalomon@google.com | c781888 | 2013-03-20 19:19:53 +0000 | [diff] [blame] | 182 | if (NULL != localMatrix) { |
| 183 | localMatrix->mapPointsWithStride(coords, vsize, 4); |
bsalomon@google.com | d62e88e | 2013-02-01 14:19:27 +0000 | [diff] [blame] | 184 | } |
| 185 | } |
| 186 | |
| 187 | if (colorOffset >= 0) { |
| 188 | GrColor* vertColor = GrTCast<GrColor*>(GrTCast<intptr_t>(geo.vertices()) + colorOffset); |
| 189 | for (int i = 0; i < 4; ++i) { |
| 190 | *vertColor = color; |
| 191 | vertColor = (GrColor*) ((intptr_t) vertColor + vsize); |
| 192 | } |
| 193 | } |
| 194 | |
bsalomon@google.com | 6e4e650 | 2013-02-25 20:12:45 +0000 | [diff] [blame] | 195 | this->setIndexSourceToBuffer(this->getContext()->getQuadIndexBuffer()); |
bsalomon@google.com | d62e88e | 2013-02-01 14:19:27 +0000 | [diff] [blame] | 196 | this->drawIndexedInstances(kTriangles_GrPrimitiveType, 1, 4, 6, &devBounds); |
jvanverth@google.com | 9b855c7 | 2013-03-01 18:21:22 +0000 | [diff] [blame] | 197 | |
| 198 | // to ensure that stashing the drawState ptr is valid |
tfarina@chromium.org | f6de475 | 2013-08-17 00:02:59 +0000 | [diff] [blame] | 199 | SkASSERT(this->drawState() == drawState); |
bsalomon@google.com | d62e88e | 2013-02-01 14:19:27 +0000 | [diff] [blame] | 200 | } |
| 201 | |
| 202 | bool GrInOrderDrawBuffer::quickInsideClip(const SkRect& devBounds) { |
| 203 | if (!this->getDrawState().isClipState()) { |
| 204 | return true; |
| 205 | } |
| 206 | if (kUnknown_ClipProxyState == fClipProxyState) { |
| 207 | SkIRect rect; |
| 208 | bool iior; |
| 209 | this->getClip()->getConservativeBounds(this->getDrawState().getRenderTarget(), &rect, &iior); |
| 210 | if (iior) { |
| 211 | // The clip is a rect. We will remember that in fProxyClip. It is common for an edge (or |
| 212 | // all edges) of the clip to be at the edge of the RT. However, we get that clipping for |
| 213 | // free via the viewport. We don't want to think that clipping must be enabled in this |
| 214 | // case. So we extend the clip outward from the edge to avoid these false negatives. |
| 215 | fClipProxyState = kValid_ClipProxyState; |
reed@google.com | 081560e | 2013-10-31 16:24:08 +0000 | [diff] [blame^] | 216 | fClipProxy = SkRect::Make(rect); |
bsalomon@google.com | d62e88e | 2013-02-01 14:19:27 +0000 | [diff] [blame] | 217 | |
| 218 | if (fClipProxy.fLeft <= 0) { |
| 219 | fClipProxy.fLeft = SK_ScalarMin; |
| 220 | } |
| 221 | if (fClipProxy.fTop <= 0) { |
| 222 | fClipProxy.fTop = SK_ScalarMin; |
| 223 | } |
| 224 | if (fClipProxy.fRight >= this->getDrawState().getRenderTarget()->width()) { |
| 225 | fClipProxy.fRight = SK_ScalarMax; |
| 226 | } |
| 227 | if (fClipProxy.fBottom >= this->getDrawState().getRenderTarget()->height()) { |
| 228 | fClipProxy.fBottom = SK_ScalarMax; |
| 229 | } |
| 230 | } else { |
| 231 | fClipProxyState = kInvalid_ClipProxyState; |
| 232 | } |
| 233 | } |
| 234 | if (kValid_ClipProxyState == fClipProxyState) { |
| 235 | return fClipProxy.contains(devBounds); |
| 236 | } |
| 237 | SkPoint originOffset = {SkIntToScalar(this->getClip()->fOrigin.fX), |
| 238 | SkIntToScalar(this->getClip()->fOrigin.fY)}; |
| 239 | SkRect clipSpaceBounds = devBounds; |
| 240 | clipSpaceBounds.offset(originOffset); |
| 241 | return this->getClip()->fClipStack->quickContains(clipSpaceBounds); |
| 242 | } |
| 243 | |
| 244 | int GrInOrderDrawBuffer::concatInstancedDraw(const DrawInfo& info) { |
tfarina@chromium.org | f6de475 | 2013-08-17 00:02:59 +0000 | [diff] [blame] | 245 | SkASSERT(info.isInstanced()); |
bsalomon@google.com | d62e88e | 2013-02-01 14:19:27 +0000 | [diff] [blame] | 246 | |
bsalomon@google.com | 934c570 | 2012-03-20 21:17:58 +0000 | [diff] [blame] | 247 | const GeometrySrcState& geomSrc = this->getGeomSrc(); |
jvanverth@google.com | b75b0a0 | 2013-02-05 20:33:30 +0000 | [diff] [blame] | 248 | const GrDrawState& drawState = this->getDrawState(); |
bsalomon@google.com | 934c570 | 2012-03-20 21:17:58 +0000 | [diff] [blame] | 249 | |
bsalomon@google.com | d62e88e | 2013-02-01 14:19:27 +0000 | [diff] [blame] | 250 | // we only attempt to concat the case when reserved verts are used with a client-specified index |
| 251 | // buffer. To make this work with client-specified VBs we'd need to know if the VB was updated |
| 252 | // between draws. |
| 253 | if (kReserved_GeometrySrcType != geomSrc.fVertexSrc || |
| 254 | kBuffer_GeometrySrcType != geomSrc.fIndexSrc) { |
| 255 | return 0; |
bsalomon@google.com | 934c570 | 2012-03-20 21:17:58 +0000 | [diff] [blame] | 256 | } |
bsalomon@google.com | d62e88e | 2013-02-01 14:19:27 +0000 | [diff] [blame] | 257 | // Check if there is a draw info that is compatible that uses the same VB from the pool and |
| 258 | // the same IB |
| 259 | if (kDraw_Cmd != fCmds.back()) { |
| 260 | return 0; |
| 261 | } |
| 262 | |
| 263 | DrawRecord* draw = &fDraws.back(); |
| 264 | GeometryPoolState& poolState = fGeoPoolStateStack.back(); |
| 265 | const GrVertexBuffer* vertexBuffer = poolState.fPoolVertexBuffer; |
| 266 | |
| 267 | if (!draw->isInstanced() || |
| 268 | draw->verticesPerInstance() != info.verticesPerInstance() || |
| 269 | draw->indicesPerInstance() != info.indicesPerInstance() || |
| 270 | draw->fVertexBuffer != vertexBuffer || |
jvanverth@google.com | b75b0a0 | 2013-02-05 20:33:30 +0000 | [diff] [blame] | 271 | draw->fIndexBuffer != geomSrc.fIndexBuffer) { |
bsalomon@google.com | d62e88e | 2013-02-01 14:19:27 +0000 | [diff] [blame] | 272 | return 0; |
| 273 | } |
| 274 | // info does not yet account for the offset from the start of the pool's VB while the previous |
| 275 | // draw record does. |
| 276 | int adjustedStartVertex = poolState.fPoolStartVertex + info.startVertex(); |
| 277 | if (draw->startVertex() + draw->vertexCount() != adjustedStartVertex) { |
| 278 | return 0; |
| 279 | } |
| 280 | |
tfarina@chromium.org | f6de475 | 2013-08-17 00:02:59 +0000 | [diff] [blame] | 281 | SkASSERT(poolState.fPoolStartVertex == draw->startVertex() + draw->vertexCount()); |
bsalomon@google.com | d62e88e | 2013-02-01 14:19:27 +0000 | [diff] [blame] | 282 | |
| 283 | // how many instances can be concat'ed onto draw given the size of the index buffer |
| 284 | int instancesToConcat = this->indexCountInCurrentSource() / info.indicesPerInstance(); |
| 285 | instancesToConcat -= draw->instanceCount(); |
| 286 | instancesToConcat = GrMin(instancesToConcat, info.instanceCount()); |
| 287 | |
| 288 | // update the amount of reserved vertex data actually referenced in draws |
skia.committer@gmail.com | ae68392 | 2013-02-06 07:01:54 +0000 | [diff] [blame] | 289 | size_t vertexBytes = instancesToConcat * info.verticesPerInstance() * |
jvanverth@google.com | b75b0a0 | 2013-02-05 20:33:30 +0000 | [diff] [blame] | 290 | drawState.getVertexSize(); |
bsalomon@google.com | d62e88e | 2013-02-01 14:19:27 +0000 | [diff] [blame] | 291 | poolState.fUsedPoolVertexBytes = GrMax(poolState.fUsedPoolVertexBytes, vertexBytes); |
| 292 | |
| 293 | draw->adjustInstanceCount(instancesToConcat); |
| 294 | return instancesToConcat; |
bsalomon@google.com | 934c570 | 2012-03-20 21:17:58 +0000 | [diff] [blame] | 295 | } |
| 296 | |
bsalomon@google.com | d62e88e | 2013-02-01 14:19:27 +0000 | [diff] [blame] | 297 | class AutoClipReenable { |
| 298 | public: |
| 299 | AutoClipReenable() : fDrawState(NULL) {} |
| 300 | ~AutoClipReenable() { |
| 301 | if (NULL != fDrawState) { |
| 302 | fDrawState->enableState(GrDrawState::kClip_StateBit); |
| 303 | } |
| 304 | } |
| 305 | void set(GrDrawState* drawState) { |
| 306 | if (drawState->isClipState()) { |
| 307 | fDrawState = drawState; |
| 308 | drawState->disableState(GrDrawState::kClip_StateBit); |
| 309 | } |
| 310 | } |
| 311 | private: |
| 312 | GrDrawState* fDrawState; |
| 313 | }; |
| 314 | |
bsalomon@google.com | 74749cd | 2013-01-30 16:12:41 +0000 | [diff] [blame] | 315 | void GrInOrderDrawBuffer::onDraw(const DrawInfo& info) { |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 316 | |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 317 | GeometryPoolState& poolState = fGeoPoolStateStack.back(); |
jvanverth@google.com | b75b0a0 | 2013-02-05 20:33:30 +0000 | [diff] [blame] | 318 | const GrDrawState& drawState = this->getDrawState(); |
bsalomon@google.com | d62e88e | 2013-02-01 14:19:27 +0000 | [diff] [blame] | 319 | AutoClipReenable acr; |
| 320 | |
jvanverth@google.com | b75b0a0 | 2013-02-05 20:33:30 +0000 | [diff] [blame] | 321 | if (drawState.isClipState() && |
bsalomon@google.com | d62e88e | 2013-02-01 14:19:27 +0000 | [diff] [blame] | 322 | NULL != info.getDevBounds() && |
| 323 | this->quickInsideClip(*info.getDevBounds())) { |
| 324 | acr.set(this->drawState()); |
| 325 | } |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 326 | |
bsalomon@google.com | a4f6b10 | 2012-06-26 21:04:22 +0000 | [diff] [blame] | 327 | if (this->needsNewClip()) { |
| 328 | this->recordClip(); |
| 329 | } |
| 330 | if (this->needsNewState()) { |
| 331 | this->recordState(); |
bsalomon@google.com | 86afc2a | 2011-02-16 16:12:19 +0000 | [diff] [blame] | 332 | } |
| 333 | |
bsalomon@google.com | d62e88e | 2013-02-01 14:19:27 +0000 | [diff] [blame] | 334 | DrawRecord* draw; |
| 335 | if (info.isInstanced()) { |
| 336 | int instancesConcated = this->concatInstancedDraw(info); |
| 337 | if (info.instanceCount() > instancesConcated) { |
| 338 | draw = this->recordDraw(info); |
| 339 | draw->adjustInstanceCount(-instancesConcated); |
| 340 | } else { |
| 341 | return; |
| 342 | } |
| 343 | } else { |
| 344 | draw = this->recordDraw(info); |
| 345 | } |
bsalomon@google.com | 74749cd | 2013-01-30 16:12:41 +0000 | [diff] [blame] | 346 | |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 347 | switch (this->getGeomSrc().fVertexSrc) { |
bsalomon@google.com | 74749cd | 2013-01-30 16:12:41 +0000 | [diff] [blame] | 348 | case kBuffer_GeometrySrcType: |
| 349 | draw->fVertexBuffer = this->getGeomSrc().fVertexBuffer; |
| 350 | break; |
| 351 | case kReserved_GeometrySrcType: // fallthrough |
| 352 | case kArray_GeometrySrcType: { |
skia.committer@gmail.com | ae68392 | 2013-02-06 07:01:54 +0000 | [diff] [blame] | 353 | size_t vertexBytes = (info.vertexCount() + info.startVertex()) * |
jvanverth@google.com | b75b0a0 | 2013-02-05 20:33:30 +0000 | [diff] [blame] | 354 | drawState.getVertexSize(); |
bsalomon@google.com | 74749cd | 2013-01-30 16:12:41 +0000 | [diff] [blame] | 355 | poolState.fUsedPoolVertexBytes = GrMax(poolState.fUsedPoolVertexBytes, vertexBytes); |
| 356 | draw->fVertexBuffer = poolState.fPoolVertexBuffer; |
bsalomon@google.com | d62e88e | 2013-02-01 14:19:27 +0000 | [diff] [blame] | 357 | draw->adjustStartVertex(poolState.fPoolStartVertex); |
bsalomon@google.com | 74749cd | 2013-01-30 16:12:41 +0000 | [diff] [blame] | 358 | break; |
| 359 | } |
| 360 | default: |
| 361 | GrCrash("unknown geom src type"); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 362 | } |
bsalomon@google.com | a4f6b10 | 2012-06-26 21:04:22 +0000 | [diff] [blame] | 363 | draw->fVertexBuffer->ref(); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 364 | |
bsalomon@google.com | 74749cd | 2013-01-30 16:12:41 +0000 | [diff] [blame] | 365 | if (info.isIndexed()) { |
| 366 | switch (this->getGeomSrc().fIndexSrc) { |
| 367 | case kBuffer_GeometrySrcType: |
| 368 | draw->fIndexBuffer = this->getGeomSrc().fIndexBuffer; |
| 369 | break; |
| 370 | case kReserved_GeometrySrcType: // fallthrough |
| 371 | case kArray_GeometrySrcType: { |
| 372 | size_t indexBytes = (info.indexCount() + info.startIndex()) * sizeof(uint16_t); |
| 373 | poolState.fUsedPoolIndexBytes = GrMax(poolState.fUsedPoolIndexBytes, indexBytes); |
| 374 | draw->fIndexBuffer = poolState.fPoolIndexBuffer; |
bsalomon@google.com | d62e88e | 2013-02-01 14:19:27 +0000 | [diff] [blame] | 375 | draw->adjustStartIndex(poolState.fPoolStartIndex); |
bsalomon@google.com | 74749cd | 2013-01-30 16:12:41 +0000 | [diff] [blame] | 376 | break; |
| 377 | } |
| 378 | default: |
| 379 | GrCrash("unknown geom src type"); |
| 380 | } |
| 381 | draw->fIndexBuffer->ref(); |
| 382 | } else { |
| 383 | draw->fIndexBuffer = NULL; |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 384 | } |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 385 | } |
| 386 | |
commit-bot@chromium.org | 32184d8 | 2013-10-09 15:14:18 +0000 | [diff] [blame] | 387 | GrInOrderDrawBuffer::StencilPath::StencilPath() {} |
| 388 | GrInOrderDrawBuffer::DrawPath::DrawPath() {} |
sugoi@google.com | 5f74cf8 | 2012-12-17 21:16:45 +0000 | [diff] [blame] | 389 | |
commit-bot@chromium.org | 32184d8 | 2013-10-09 15:14:18 +0000 | [diff] [blame] | 390 | void GrInOrderDrawBuffer::onStencilPath(const GrPath* path, SkPath::FillType fill) { |
bsalomon@google.com | ded4f4b | 2012-06-28 18:48:06 +0000 | [diff] [blame] | 391 | if (this->needsNewClip()) { |
| 392 | this->recordClip(); |
| 393 | } |
| 394 | // Only compare the subset of GrDrawState relevant to path stenciling? |
| 395 | if (this->needsNewState()) { |
| 396 | this->recordState(); |
| 397 | } |
| 398 | StencilPath* sp = this->recordStencilPath(); |
| 399 | sp->fPath.reset(path); |
| 400 | path->ref(); |
| 401 | sp->fFill = fill; |
bsalomon@google.com | 64aef2b | 2012-06-11 15:36:13 +0000 | [diff] [blame] | 402 | } |
| 403 | |
commit-bot@chromium.org | 32184d8 | 2013-10-09 15:14:18 +0000 | [diff] [blame] | 404 | void GrInOrderDrawBuffer::onDrawPath(const GrPath* path, |
commit-bot@chromium.org | c4dc0ad | 2013-10-09 14:11:33 +0000 | [diff] [blame] | 405 | SkPath::FillType fill, const GrDeviceCoordTexture* dstCopy) { |
| 406 | if (this->needsNewClip()) { |
| 407 | this->recordClip(); |
| 408 | } |
| 409 | // TODO: Only compare the subset of GrDrawState relevant to path covering? |
| 410 | if (this->needsNewState()) { |
| 411 | this->recordState(); |
| 412 | } |
commit-bot@chromium.org | 32184d8 | 2013-10-09 15:14:18 +0000 | [diff] [blame] | 413 | DrawPath* cp = this->recordDrawPath(); |
commit-bot@chromium.org | c4dc0ad | 2013-10-09 14:11:33 +0000 | [diff] [blame] | 414 | cp->fPath.reset(path); |
| 415 | path->ref(); |
| 416 | cp->fFill = fill; |
commit-bot@chromium.org | c4dc0ad | 2013-10-09 14:11:33 +0000 | [diff] [blame] | 417 | if (NULL != dstCopy) { |
| 418 | cp->fDstCopy = *dstCopy; |
| 419 | } |
| 420 | } |
| 421 | |
commit-bot@chromium.org | fd03d4a | 2013-07-17 21:39:42 +0000 | [diff] [blame] | 422 | void GrInOrderDrawBuffer::clear(const SkIRect* rect, GrColor color, GrRenderTarget* renderTarget) { |
| 423 | SkIRect r; |
bsalomon@google.com | 1b3ce47 | 2012-08-17 13:43:08 +0000 | [diff] [blame] | 424 | if (NULL == renderTarget) { |
| 425 | renderTarget = this->drawState()->getRenderTarget(); |
tfarina@chromium.org | f6de475 | 2013-08-17 00:02:59 +0000 | [diff] [blame] | 426 | SkASSERT(NULL != renderTarget); |
bsalomon@google.com | 1b3ce47 | 2012-08-17 13:43:08 +0000 | [diff] [blame] | 427 | } |
bsalomon@google.com | 6aa25c3 | 2011-04-27 19:55:29 +0000 | [diff] [blame] | 428 | if (NULL == rect) { |
| 429 | // We could do something smart and remove previous draws and clears to |
| 430 | // the current render target. If we get that smart we have to make sure |
| 431 | // those draws aren't read before this clear (render-to-texture). |
bsalomon@google.com | 1b3ce47 | 2012-08-17 13:43:08 +0000 | [diff] [blame] | 432 | r.setLTRB(0, 0, renderTarget->width(), renderTarget->height()); |
bsalomon@google.com | 6aa25c3 | 2011-04-27 19:55:29 +0000 | [diff] [blame] | 433 | rect = &r; |
| 434 | } |
bsalomon@google.com | a4f6b10 | 2012-06-26 21:04:22 +0000 | [diff] [blame] | 435 | Clear* clr = this->recordClear(); |
| 436 | clr->fColor = color; |
| 437 | clr->fRect = *rect; |
| 438 | clr->fRenderTarget = renderTarget; |
bsalomon@google.com | 1b3ce47 | 2012-08-17 13:43:08 +0000 | [diff] [blame] | 439 | renderTarget->ref(); |
bsalomon@google.com | 0b335c1 | 2011-04-25 19:17:44 +0000 | [diff] [blame] | 440 | } |
| 441 | |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 442 | void GrInOrderDrawBuffer::reset() { |
tfarina@chromium.org | f6de475 | 2013-08-17 00:02:59 +0000 | [diff] [blame] | 443 | SkASSERT(1 == fGeoPoolStateStack.count()); |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 444 | this->resetVertexSource(); |
| 445 | this->resetIndexSource(); |
bsalomon@google.com | 86afc2a | 2011-02-16 16:12:19 +0000 | [diff] [blame] | 446 | int numDraws = fDraws.count(); |
| 447 | for (int d = 0; d < numDraws; ++d) { |
| 448 | // we always have a VB, but not always an IB |
tfarina@chromium.org | f6de475 | 2013-08-17 00:02:59 +0000 | [diff] [blame] | 449 | SkASSERT(NULL != fDraws[d].fVertexBuffer); |
bsalomon@google.com | 86afc2a | 2011-02-16 16:12:19 +0000 | [diff] [blame] | 450 | fDraws[d].fVertexBuffer->unref(); |
commit-bot@chromium.org | a4de8c2 | 2013-09-09 13:38:37 +0000 | [diff] [blame] | 451 | SkSafeUnref(fDraws[d].fIndexBuffer); |
bsalomon@google.com | 86afc2a | 2011-02-16 16:12:19 +0000 | [diff] [blame] | 452 | } |
bsalomon@google.com | a4f6b10 | 2012-06-26 21:04:22 +0000 | [diff] [blame] | 453 | fCmds.reset(); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 454 | fDraws.reset(); |
bsalomon@google.com | ded4f4b | 2012-06-28 18:48:06 +0000 | [diff] [blame] | 455 | fStencilPaths.reset(); |
commit-bot@chromium.org | 32184d8 | 2013-10-09 15:14:18 +0000 | [diff] [blame] | 456 | fDrawPaths.reset(); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 457 | fStates.reset(); |
bsalomon@google.com | 0b335c1 | 2011-04-25 19:17:44 +0000 | [diff] [blame] | 458 | fClears.reset(); |
bsalomon@google.com | 1c13c96 | 2011-02-14 16:51:21 +0000 | [diff] [blame] | 459 | fVertexPool.reset(); |
| 460 | fIndexPool.reset(); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 461 | fClips.reset(); |
robertphillips@google.com | beb1af7 | 2012-07-26 18:52:16 +0000 | [diff] [blame] | 462 | fClipOrigins.reset(); |
bsalomon@google.com | 116ad84 | 2013-04-09 15:38:19 +0000 | [diff] [blame] | 463 | fCopySurfaces.reset(); |
bsalomon@google.com | a4f6b10 | 2012-06-26 21:04:22 +0000 | [diff] [blame] | 464 | fClipSet = true; |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 465 | } |
| 466 | |
robertphillips@google.com | 1267fbd | 2013-07-03 18:37:27 +0000 | [diff] [blame] | 467 | void GrInOrderDrawBuffer::flush() { |
| 468 | if (fFlushing) { |
| 469 | return; |
| 470 | } |
| 471 | |
tfarina@chromium.org | f6de475 | 2013-08-17 00:02:59 +0000 | [diff] [blame] | 472 | SkASSERT(kReserved_GeometrySrcType != this->getGeomSrc().fVertexSrc); |
| 473 | SkASSERT(kReserved_GeometrySrcType != this->getGeomSrc().fIndexSrc); |
bsalomon@google.com | 3f5a95e | 2012-03-08 16:41:42 +0000 | [diff] [blame] | 474 | |
bsalomon@google.com | a4f6b10 | 2012-06-26 21:04:22 +0000 | [diff] [blame] | 475 | int numCmds = fCmds.count(); |
bsalomon@google.com | 358e427 | 2013-01-10 14:40:28 +0000 | [diff] [blame] | 476 | if (0 == numCmds) { |
robertphillips@google.com | 1267fbd | 2013-07-03 18:37:27 +0000 | [diff] [blame] | 477 | return; |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 478 | } |
bsalomon@google.com | 6e4e650 | 2013-02-25 20:12:45 +0000 | [diff] [blame] | 479 | |
| 480 | GrAutoTRestore<bool> flushRestore(&fFlushing); |
| 481 | fFlushing = true; |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 482 | |
bsalomon@google.com | 1c13c96 | 2011-02-14 16:51:21 +0000 | [diff] [blame] | 483 | fVertexPool.unlock(); |
| 484 | fIndexPool.unlock(); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 485 | |
bsalomon@google.com | 6e4e650 | 2013-02-25 20:12:45 +0000 | [diff] [blame] | 486 | GrDrawTarget::AutoClipRestore acr(fDstGpu); |
| 487 | AutoGeometryAndStatePush agasp(fDstGpu, kPreserve_ASRInit); |
bsalomon@google.com | ca43208 | 2013-01-23 19:53:46 +0000 | [diff] [blame] | 488 | |
| 489 | GrDrawState playbackState; |
bsalomon@google.com | 6e4e650 | 2013-02-25 20:12:45 +0000 | [diff] [blame] | 490 | GrDrawState* prevDrawState = fDstGpu->drawState(); |
bsalomon@google.com | a5d056a | 2012-03-27 15:59:58 +0000 | [diff] [blame] | 491 | prevDrawState->ref(); |
bsalomon@google.com | 6e4e650 | 2013-02-25 20:12:45 +0000 | [diff] [blame] | 492 | fDstGpu->setDrawState(&playbackState); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 493 | |
robertphillips@google.com | beb1af7 | 2012-07-26 18:52:16 +0000 | [diff] [blame] | 494 | GrClipData clipData; |
| 495 | |
bsalomon@google.com | ded4f4b | 2012-06-28 18:48:06 +0000 | [diff] [blame] | 496 | int currState = 0; |
| 497 | int currClip = 0; |
| 498 | int currClear = 0; |
| 499 | int currDraw = 0; |
| 500 | int currStencilPath = 0; |
commit-bot@chromium.org | 32184d8 | 2013-10-09 15:14:18 +0000 | [diff] [blame] | 501 | int currDrawPath = 0; |
bsalomon@google.com | 116ad84 | 2013-04-09 15:38:19 +0000 | [diff] [blame] | 502 | int currCopySurface = 0; |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 503 | |
bsalomon@google.com | a4f6b10 | 2012-06-26 21:04:22 +0000 | [diff] [blame] | 504 | for (int c = 0; c < numCmds; ++c) { |
| 505 | switch (fCmds[c]) { |
| 506 | case kDraw_Cmd: { |
bsalomon@google.com | 74749cd | 2013-01-30 16:12:41 +0000 | [diff] [blame] | 507 | const DrawRecord& draw = fDraws[currDraw]; |
bsalomon@google.com | 6e4e650 | 2013-02-25 20:12:45 +0000 | [diff] [blame] | 508 | fDstGpu->setVertexSourceToBuffer(draw.fVertexBuffer); |
bsalomon@google.com | d62e88e | 2013-02-01 14:19:27 +0000 | [diff] [blame] | 509 | if (draw.isIndexed()) { |
bsalomon@google.com | 6e4e650 | 2013-02-25 20:12:45 +0000 | [diff] [blame] | 510 | fDstGpu->setIndexSourceToBuffer(draw.fIndexBuffer); |
bsalomon@google.com | a4f6b10 | 2012-06-26 21:04:22 +0000 | [diff] [blame] | 511 | } |
bsalomon@google.com | 6e4e650 | 2013-02-25 20:12:45 +0000 | [diff] [blame] | 512 | fDstGpu->executeDraw(draw); |
bsalomon@google.com | 0b335c1 | 2011-04-25 19:17:44 +0000 | [diff] [blame] | 513 | |
bsalomon@google.com | a4f6b10 | 2012-06-26 21:04:22 +0000 | [diff] [blame] | 514 | ++currDraw; |
| 515 | break; |
| 516 | } |
bsalomon@google.com | ded4f4b | 2012-06-28 18:48:06 +0000 | [diff] [blame] | 517 | case kStencilPath_Cmd: { |
| 518 | const StencilPath& sp = fStencilPaths[currStencilPath]; |
commit-bot@chromium.org | 32184d8 | 2013-10-09 15:14:18 +0000 | [diff] [blame] | 519 | fDstGpu->stencilPath(sp.fPath.get(), sp.fFill); |
bsalomon@google.com | ded4f4b | 2012-06-28 18:48:06 +0000 | [diff] [blame] | 520 | ++currStencilPath; |
| 521 | break; |
| 522 | } |
commit-bot@chromium.org | 32184d8 | 2013-10-09 15:14:18 +0000 | [diff] [blame] | 523 | case kDrawPath_Cmd: { |
| 524 | const DrawPath& cp = fDrawPaths[currDrawPath]; |
| 525 | fDstGpu->executeDrawPath(cp.fPath.get(), cp.fFill, |
commit-bot@chromium.org | c4dc0ad | 2013-10-09 14:11:33 +0000 | [diff] [blame] | 526 | NULL != cp.fDstCopy.texture() ? &cp.fDstCopy : NULL); |
commit-bot@chromium.org | 32184d8 | 2013-10-09 15:14:18 +0000 | [diff] [blame] | 527 | ++currDrawPath; |
commit-bot@chromium.org | c4dc0ad | 2013-10-09 14:11:33 +0000 | [diff] [blame] | 528 | break; |
| 529 | } |
bsalomon@google.com | a4f6b10 | 2012-06-26 21:04:22 +0000 | [diff] [blame] | 530 | case kSetState_Cmd: |
bsalomon@google.com | ca43208 | 2013-01-23 19:53:46 +0000 | [diff] [blame] | 531 | fStates[currState].restoreTo(&playbackState); |
bsalomon@google.com | a4f6b10 | 2012-06-26 21:04:22 +0000 | [diff] [blame] | 532 | ++currState; |
| 533 | break; |
| 534 | case kSetClip_Cmd: |
robertphillips@google.com | beb1af7 | 2012-07-26 18:52:16 +0000 | [diff] [blame] | 535 | clipData.fClipStack = &fClips[currClip]; |
| 536 | clipData.fOrigin = fClipOrigins[currClip]; |
bsalomon@google.com | 6e4e650 | 2013-02-25 20:12:45 +0000 | [diff] [blame] | 537 | fDstGpu->setClip(&clipData); |
bsalomon@google.com | a4f6b10 | 2012-06-26 21:04:22 +0000 | [diff] [blame] | 538 | ++currClip; |
| 539 | break; |
| 540 | case kClear_Cmd: |
bsalomon@google.com | 6e4e650 | 2013-02-25 20:12:45 +0000 | [diff] [blame] | 541 | fDstGpu->clear(&fClears[currClear].fRect, |
| 542 | fClears[currClear].fColor, |
| 543 | fClears[currClear].fRenderTarget); |
bsalomon@google.com | a4f6b10 | 2012-06-26 21:04:22 +0000 | [diff] [blame] | 544 | ++currClear; |
| 545 | break; |
bsalomon@google.com | 116ad84 | 2013-04-09 15:38:19 +0000 | [diff] [blame] | 546 | case kCopySurface_Cmd: |
| 547 | fDstGpu->copySurface(fCopySurfaces[currCopySurface].fDst.get(), |
| 548 | fCopySurfaces[currCopySurface].fSrc.get(), |
| 549 | fCopySurfaces[currCopySurface].fSrcRect, |
| 550 | fCopySurfaces[currCopySurface].fDstPoint); |
| 551 | ++currCopySurface; |
| 552 | break; |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 553 | } |
| 554 | } |
bsalomon@google.com | a4f6b10 | 2012-06-26 21:04:22 +0000 | [diff] [blame] | 555 | // we should have consumed all the states, clips, etc. |
tfarina@chromium.org | f6de475 | 2013-08-17 00:02:59 +0000 | [diff] [blame] | 556 | SkASSERT(fStates.count() == currState); |
| 557 | SkASSERT(fClips.count() == currClip); |
| 558 | SkASSERT(fClipOrigins.count() == currClip); |
| 559 | SkASSERT(fClears.count() == currClear); |
| 560 | SkASSERT(fDraws.count() == currDraw); |
| 561 | SkASSERT(fCopySurfaces.count() == currCopySurface); |
bsalomon@google.com | a4f6b10 | 2012-06-26 21:04:22 +0000 | [diff] [blame] | 562 | |
bsalomon@google.com | 6e4e650 | 2013-02-25 20:12:45 +0000 | [diff] [blame] | 563 | fDstGpu->setDrawState(prevDrawState); |
bsalomon@google.com | a5d056a | 2012-03-27 15:59:58 +0000 | [diff] [blame] | 564 | prevDrawState->unref(); |
bsalomon@google.com | 55e4a20 | 2013-01-11 13:54:21 +0000 | [diff] [blame] | 565 | this->reset(); |
commit-bot@chromium.org | a8916ff | 2013-08-16 15:53:46 +0000 | [diff] [blame] | 566 | ++fDrawID; |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 567 | } |
| 568 | |
bsalomon@google.com | 116ad84 | 2013-04-09 15:38:19 +0000 | [diff] [blame] | 569 | bool GrInOrderDrawBuffer::onCopySurface(GrSurface* dst, |
| 570 | GrSurface* src, |
| 571 | const SkIRect& srcRect, |
| 572 | const SkIPoint& dstPoint) { |
| 573 | if (fDstGpu->canCopySurface(dst, src, srcRect, dstPoint)) { |
| 574 | CopySurface* cs = this->recordCopySurface(); |
| 575 | cs->fDst.reset(SkRef(dst)); |
| 576 | cs->fSrc.reset(SkRef(src)); |
| 577 | cs->fSrcRect = srcRect; |
| 578 | cs->fDstPoint = dstPoint; |
| 579 | return true; |
| 580 | } else { |
| 581 | return false; |
| 582 | } |
| 583 | } |
| 584 | |
| 585 | bool GrInOrderDrawBuffer::onCanCopySurface(GrSurface* dst, |
| 586 | GrSurface* src, |
| 587 | const SkIRect& srcRect, |
| 588 | const SkIPoint& dstPoint) { |
| 589 | return fDstGpu->canCopySurface(dst, src, srcRect, dstPoint); |
| 590 | } |
| 591 | |
bsalomon@google.com | eb85117 | 2013-04-15 13:51:00 +0000 | [diff] [blame] | 592 | void GrInOrderDrawBuffer::initCopySurfaceDstDesc(const GrSurface* src, GrTextureDesc* desc) { |
| 593 | fDstGpu->initCopySurfaceDstDesc(src, desc); |
| 594 | } |
| 595 | |
robertphillips@google.com | 9528bdb | 2013-09-18 22:33:57 +0000 | [diff] [blame] | 596 | void GrInOrderDrawBuffer::willReserveVertexAndIndexSpace(int vertexCount, |
| 597 | int indexCount) { |
bsalomon@google.com | 6e4e650 | 2013-02-25 20:12:45 +0000 | [diff] [blame] | 598 | // We use geometryHints() to know whether to flush the draw buffer. We |
| 599 | // can't flush if we are inside an unbalanced pushGeometrySource. |
| 600 | // Moreover, flushing blows away vertex and index data that was |
| 601 | // previously reserved. So if the vertex or index data is pulled from |
| 602 | // reserved space and won't be released by this request then we can't |
| 603 | // flush. |
| 604 | bool insideGeoPush = fGeoPoolStateStack.count() > 1; |
bsalomon@google.com | 9780538 | 2012-03-13 14:32:07 +0000 | [diff] [blame] | 605 | |
bsalomon@google.com | 6e4e650 | 2013-02-25 20:12:45 +0000 | [diff] [blame] | 606 | bool unreleasedVertexSpace = |
| 607 | !vertexCount && |
| 608 | kReserved_GeometrySrcType == this->getGeomSrc().fVertexSrc; |
bsalomon@google.com | 9780538 | 2012-03-13 14:32:07 +0000 | [diff] [blame] | 609 | |
bsalomon@google.com | 6e4e650 | 2013-02-25 20:12:45 +0000 | [diff] [blame] | 610 | bool unreleasedIndexSpace = |
| 611 | !indexCount && |
| 612 | kReserved_GeometrySrcType == this->getGeomSrc().fIndexSrc; |
bsalomon@google.com | 9780538 | 2012-03-13 14:32:07 +0000 | [diff] [blame] | 613 | |
bsalomon@google.com | 6e4e650 | 2013-02-25 20:12:45 +0000 | [diff] [blame] | 614 | // we don't want to finalize any reserved geom on the target since |
| 615 | // we don't know that the client has finished writing to it. |
| 616 | bool targetHasReservedGeom = fDstGpu->hasReservedVerticesOrIndices(); |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 617 | |
bsalomon@google.com | 6e4e650 | 2013-02-25 20:12:45 +0000 | [diff] [blame] | 618 | int vcount = vertexCount; |
| 619 | int icount = indexCount; |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 620 | |
bsalomon@google.com | 6e4e650 | 2013-02-25 20:12:45 +0000 | [diff] [blame] | 621 | if (!insideGeoPush && |
| 622 | !unreleasedVertexSpace && |
| 623 | !unreleasedIndexSpace && |
| 624 | !targetHasReservedGeom && |
| 625 | this->geometryHints(&vcount, &icount)) { |
bsalomon@google.com | 9780538 | 2012-03-13 14:32:07 +0000 | [diff] [blame] | 626 | |
bsalomon@google.com | 6e4e650 | 2013-02-25 20:12:45 +0000 | [diff] [blame] | 627 | this->flush(); |
bsalomon@google.com | 9780538 | 2012-03-13 14:32:07 +0000 | [diff] [blame] | 628 | } |
| 629 | } |
| 630 | |
jvanverth@google.com | b75b0a0 | 2013-02-05 20:33:30 +0000 | [diff] [blame] | 631 | bool GrInOrderDrawBuffer::geometryHints(int* vertexCount, |
bsalomon@google.com | 1c13c96 | 2011-02-14 16:51:21 +0000 | [diff] [blame] | 632 | int* indexCount) const { |
| 633 | // we will recommend a flush if the data could fit in a single |
| 634 | // preallocated buffer but none are left and it can't fit |
| 635 | // in the current buffer (which may not be prealloced). |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 636 | bool flush = false; |
| 637 | if (NULL != indexCount) { |
bsalomon@google.com | 1c13c96 | 2011-02-14 16:51:21 +0000 | [diff] [blame] | 638 | int32_t currIndices = fIndexPool.currentBufferIndices(); |
| 639 | if (*indexCount > currIndices && |
| 640 | (!fIndexPool.preallocatedBuffersRemaining() && |
| 641 | *indexCount <= fIndexPool.preallocatedBufferIndices())) { |
| 642 | |
| 643 | flush = true; |
| 644 | } |
| 645 | *indexCount = currIndices; |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 646 | } |
| 647 | if (NULL != vertexCount) { |
jvanverth@google.com | b75b0a0 | 2013-02-05 20:33:30 +0000 | [diff] [blame] | 648 | size_t vertexSize = this->getDrawState().getVertexSize(); |
jvanverth@google.com | a633898 | 2013-01-31 21:34:25 +0000 | [diff] [blame] | 649 | int32_t currVertices = fVertexPool.currentBufferVertices(vertexSize); |
bsalomon@google.com | 1c13c96 | 2011-02-14 16:51:21 +0000 | [diff] [blame] | 650 | if (*vertexCount > currVertices && |
| 651 | (!fVertexPool.preallocatedBuffersRemaining() && |
jvanverth@google.com | a633898 | 2013-01-31 21:34:25 +0000 | [diff] [blame] | 652 | *vertexCount <= fVertexPool.preallocatedBufferVertices(vertexSize))) { |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 653 | |
bsalomon@google.com | 1c13c96 | 2011-02-14 16:51:21 +0000 | [diff] [blame] | 654 | flush = true; |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 655 | } |
bsalomon@google.com | 1c13c96 | 2011-02-14 16:51:21 +0000 | [diff] [blame] | 656 | *vertexCount = currVertices; |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 657 | } |
| 658 | return flush; |
| 659 | } |
| 660 | |
jvanverth@google.com | a633898 | 2013-01-31 21:34:25 +0000 | [diff] [blame] | 661 | bool GrInOrderDrawBuffer::onReserveVertexSpace(size_t vertexSize, |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 662 | int vertexCount, |
| 663 | void** vertices) { |
| 664 | GeometryPoolState& poolState = fGeoPoolStateStack.back(); |
tfarina@chromium.org | f6de475 | 2013-08-17 00:02:59 +0000 | [diff] [blame] | 665 | SkASSERT(vertexCount > 0); |
| 666 | SkASSERT(NULL != vertices); |
| 667 | SkASSERT(0 == poolState.fUsedPoolVertexBytes); |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 668 | |
jvanverth@google.com | a633898 | 2013-01-31 21:34:25 +0000 | [diff] [blame] | 669 | *vertices = fVertexPool.makeSpace(vertexSize, |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 670 | vertexCount, |
| 671 | &poolState.fPoolVertexBuffer, |
| 672 | &poolState.fPoolStartVertex); |
| 673 | return NULL != *vertices; |
| 674 | } |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 675 | |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 676 | bool GrInOrderDrawBuffer::onReserveIndexSpace(int indexCount, void** indices) { |
| 677 | GeometryPoolState& poolState = fGeoPoolStateStack.back(); |
tfarina@chromium.org | f6de475 | 2013-08-17 00:02:59 +0000 | [diff] [blame] | 678 | SkASSERT(indexCount > 0); |
| 679 | SkASSERT(NULL != indices); |
| 680 | SkASSERT(0 == poolState.fUsedPoolIndexBytes); |
bsalomon@google.com | 1c13c96 | 2011-02-14 16:51:21 +0000 | [diff] [blame] | 681 | |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 682 | *indices = fIndexPool.makeSpace(indexCount, |
| 683 | &poolState.fPoolIndexBuffer, |
| 684 | &poolState.fPoolStartIndex); |
| 685 | return NULL != *indices; |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 686 | } |
| 687 | |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 688 | void GrInOrderDrawBuffer::releaseReservedVertexSpace() { |
| 689 | GeometryPoolState& poolState = fGeoPoolStateStack.back(); |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 690 | const GeometrySrcState& geoSrc = this->getGeomSrc(); |
bsalomon@google.com | d57d71a | 2012-08-16 16:26:33 +0000 | [diff] [blame] | 691 | |
| 692 | // If we get a release vertex space call then our current source should either be reserved |
| 693 | // or array (which we copied into reserved space). |
tfarina@chromium.org | f6de475 | 2013-08-17 00:02:59 +0000 | [diff] [blame] | 694 | SkASSERT(kReserved_GeometrySrcType == geoSrc.fVertexSrc || |
bsalomon@google.com | d57d71a | 2012-08-16 16:26:33 +0000 | [diff] [blame] | 695 | kArray_GeometrySrcType == geoSrc.fVertexSrc); |
bsalomon@google.com | 3f5a95e | 2012-03-08 16:41:42 +0000 | [diff] [blame] | 696 | |
| 697 | // When the caller reserved vertex buffer space we gave it back a pointer |
| 698 | // provided by the vertex buffer pool. At each draw we tracked the largest |
| 699 | // offset into the pool's pointer that was referenced. Now we return to the |
| 700 | // pool any portion at the tail of the allocation that no draw referenced. |
jvanverth@google.com | b75b0a0 | 2013-02-05 20:33:30 +0000 | [diff] [blame] | 701 | size_t reservedVertexBytes = geoSrc.fVertexSize * geoSrc.fVertexCount; |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 702 | fVertexPool.putBack(reservedVertexBytes - |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 703 | poolState.fUsedPoolVertexBytes); |
| 704 | poolState.fUsedPoolVertexBytes = 0; |
bsalomon@google.com | 3f5a95e | 2012-03-08 16:41:42 +0000 | [diff] [blame] | 705 | poolState.fPoolVertexBuffer = NULL; |
| 706 | poolState.fPoolStartVertex = 0; |
bsalomon@google.com | 1c13c96 | 2011-02-14 16:51:21 +0000 | [diff] [blame] | 707 | } |
| 708 | |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 709 | void GrInOrderDrawBuffer::releaseReservedIndexSpace() { |
| 710 | GeometryPoolState& poolState = fGeoPoolStateStack.back(); |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 711 | const GeometrySrcState& geoSrc = this->getGeomSrc(); |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 712 | |
bsalomon@google.com | d57d71a | 2012-08-16 16:26:33 +0000 | [diff] [blame] | 713 | // If we get a release index space call then our current source should either be reserved |
| 714 | // or array (which we copied into reserved space). |
tfarina@chromium.org | f6de475 | 2013-08-17 00:02:59 +0000 | [diff] [blame] | 715 | SkASSERT(kReserved_GeometrySrcType == geoSrc.fIndexSrc || |
bsalomon@google.com | d57d71a | 2012-08-16 16:26:33 +0000 | [diff] [blame] | 716 | kArray_GeometrySrcType == geoSrc.fIndexSrc); |
bsalomon@google.com | 3f5a95e | 2012-03-08 16:41:42 +0000 | [diff] [blame] | 717 | |
| 718 | // Similar to releaseReservedVertexSpace we return any unused portion at |
| 719 | // the tail |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 720 | size_t reservedIndexBytes = sizeof(uint16_t) * geoSrc.fIndexCount; |
| 721 | fIndexPool.putBack(reservedIndexBytes - poolState.fUsedPoolIndexBytes); |
| 722 | poolState.fUsedPoolIndexBytes = 0; |
bsalomon@google.com | 3f5a95e | 2012-03-08 16:41:42 +0000 | [diff] [blame] | 723 | poolState.fPoolIndexBuffer = NULL; |
| 724 | poolState.fPoolStartIndex = 0; |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 725 | } |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 726 | |
bsalomon@google.com | bcdbbe6 | 2011-04-12 15:40:00 +0000 | [diff] [blame] | 727 | void GrInOrderDrawBuffer::onSetVertexSourceToArray(const void* vertexArray, |
| 728 | int vertexCount) { |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 729 | |
| 730 | GeometryPoolState& poolState = fGeoPoolStateStack.back(); |
tfarina@chromium.org | f6de475 | 2013-08-17 00:02:59 +0000 | [diff] [blame] | 731 | SkASSERT(0 == poolState.fUsedPoolVertexBytes); |
commit-bot@chromium.org | 515dcd3 | 2013-08-28 14:17:03 +0000 | [diff] [blame] | 732 | #ifdef SK_DEBUG |
bsalomon@google.com | 1c13c96 | 2011-02-14 16:51:21 +0000 | [diff] [blame] | 733 | bool success = |
| 734 | #endif |
jvanverth@google.com | b75b0a0 | 2013-02-05 20:33:30 +0000 | [diff] [blame] | 735 | fVertexPool.appendVertices(this->getVertexSize(), |
bsalomon@google.com | 1c13c96 | 2011-02-14 16:51:21 +0000 | [diff] [blame] | 736 | vertexCount, |
| 737 | vertexArray, |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 738 | &poolState.fPoolVertexBuffer, |
| 739 | &poolState.fPoolStartVertex); |
bsalomon@google.com | 1c13c96 | 2011-02-14 16:51:21 +0000 | [diff] [blame] | 740 | GR_DEBUGASSERT(success); |
| 741 | } |
| 742 | |
bsalomon@google.com | bcdbbe6 | 2011-04-12 15:40:00 +0000 | [diff] [blame] | 743 | void GrInOrderDrawBuffer::onSetIndexSourceToArray(const void* indexArray, |
| 744 | int indexCount) { |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 745 | GeometryPoolState& poolState = fGeoPoolStateStack.back(); |
tfarina@chromium.org | f6de475 | 2013-08-17 00:02:59 +0000 | [diff] [blame] | 746 | SkASSERT(0 == poolState.fUsedPoolIndexBytes); |
commit-bot@chromium.org | 515dcd3 | 2013-08-28 14:17:03 +0000 | [diff] [blame] | 747 | #ifdef SK_DEBUG |
bsalomon@google.com | 1c13c96 | 2011-02-14 16:51:21 +0000 | [diff] [blame] | 748 | bool success = |
| 749 | #endif |
| 750 | fIndexPool.appendIndices(indexCount, |
| 751 | indexArray, |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 752 | &poolState.fPoolIndexBuffer, |
| 753 | &poolState.fPoolStartIndex); |
bsalomon@google.com | 1c13c96 | 2011-02-14 16:51:21 +0000 | [diff] [blame] | 754 | GR_DEBUGASSERT(success); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 755 | } |
| 756 | |
bsalomon@google.com | 3f5a95e | 2012-03-08 16:41:42 +0000 | [diff] [blame] | 757 | void GrInOrderDrawBuffer::releaseVertexArray() { |
| 758 | // When the client provides an array as the vertex source we handled it |
| 759 | // by copying their array into reserved space. |
| 760 | this->GrInOrderDrawBuffer::releaseReservedVertexSpace(); |
| 761 | } |
| 762 | |
| 763 | void GrInOrderDrawBuffer::releaseIndexArray() { |
| 764 | // When the client provides an array as the index source we handled it |
| 765 | // by copying their array into reserved space. |
| 766 | this->GrInOrderDrawBuffer::releaseReservedIndexSpace(); |
| 767 | } |
| 768 | |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 769 | void GrInOrderDrawBuffer::geometrySourceWillPush() { |
| 770 | GeometryPoolState& poolState = fGeoPoolStateStack.push_back(); |
| 771 | poolState.fUsedPoolVertexBytes = 0; |
| 772 | poolState.fUsedPoolIndexBytes = 0; |
commit-bot@chromium.org | 515dcd3 | 2013-08-28 14:17:03 +0000 | [diff] [blame] | 773 | #ifdef SK_DEBUG |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 774 | poolState.fPoolVertexBuffer = (GrVertexBuffer*)~0; |
| 775 | poolState.fPoolStartVertex = ~0; |
| 776 | poolState.fPoolIndexBuffer = (GrIndexBuffer*)~0; |
| 777 | poolState.fPoolStartIndex = ~0; |
| 778 | #endif |
| 779 | } |
| 780 | |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 781 | void GrInOrderDrawBuffer::geometrySourceWillPop( |
| 782 | const GeometrySrcState& restoredState) { |
tfarina@chromium.org | f6de475 | 2013-08-17 00:02:59 +0000 | [diff] [blame] | 783 | SkASSERT(fGeoPoolStateStack.count() > 1); |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 784 | fGeoPoolStateStack.pop_back(); |
| 785 | GeometryPoolState& poolState = fGeoPoolStateStack.back(); |
| 786 | // we have to assume that any slack we had in our vertex/index data |
| 787 | // is now unreleasable because data may have been appended later in the |
| 788 | // pool. |
| 789 | if (kReserved_GeometrySrcType == restoredState.fVertexSrc || |
| 790 | kArray_GeometrySrcType == restoredState.fVertexSrc) { |
jvanverth@google.com | b75b0a0 | 2013-02-05 20:33:30 +0000 | [diff] [blame] | 791 | poolState.fUsedPoolVertexBytes = restoredState.fVertexSize * restoredState.fVertexCount; |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 792 | } |
| 793 | if (kReserved_GeometrySrcType == restoredState.fIndexSrc || |
| 794 | kArray_GeometrySrcType == restoredState.fIndexSrc) { |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 795 | poolState.fUsedPoolIndexBytes = sizeof(uint16_t) * |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 796 | restoredState.fIndexCount; |
| 797 | } |
| 798 | } |
| 799 | |
bsalomon@google.com | 86afc2a | 2011-02-16 16:12:19 +0000 | [diff] [blame] | 800 | bool GrInOrderDrawBuffer::needsNewState() const { |
bsalomon@google.com | ca43208 | 2013-01-23 19:53:46 +0000 | [diff] [blame] | 801 | return fStates.empty() || !fStates.back().isEqual(this->getDrawState()); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 802 | } |
| 803 | |
bsalomon@google.com | 86afc2a | 2011-02-16 16:12:19 +0000 | [diff] [blame] | 804 | bool GrInOrderDrawBuffer::needsNewClip() const { |
tfarina@chromium.org | f6de475 | 2013-08-17 00:02:59 +0000 | [diff] [blame] | 805 | SkASSERT(fClips.count() == fClipOrigins.count()); |
bsalomon@google.com | 358e427 | 2013-01-10 14:40:28 +0000 | [diff] [blame] | 806 | if (this->getDrawState().isClipState()) { |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 807 | if (fClipSet && |
bsalomon@google.com | 358e427 | 2013-01-10 14:40:28 +0000 | [diff] [blame] | 808 | (fClips.empty() || |
bsalomon@google.com | 02ddc8b | 2013-01-28 15:35:28 +0000 | [diff] [blame] | 809 | fClips.back() != *this->getClip()->fClipStack || |
| 810 | fClipOrigins.back() != this->getClip()->fOrigin)) { |
bsalomon@google.com | 86afc2a | 2011-02-16 16:12:19 +0000 | [diff] [blame] | 811 | return true; |
| 812 | } |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 813 | } |
| 814 | return false; |
| 815 | } |
bsalomon@google.com | d302f14 | 2011-03-03 13:54:13 +0000 | [diff] [blame] | 816 | |
bsalomon@google.com | a4f6b10 | 2012-06-26 21:04:22 +0000 | [diff] [blame] | 817 | void GrInOrderDrawBuffer::recordClip() { |
bsalomon@google.com | 02ddc8b | 2013-01-28 15:35:28 +0000 | [diff] [blame] | 818 | fClips.push_back() = *this->getClip()->fClipStack; |
| 819 | fClipOrigins.push_back() = this->getClip()->fOrigin; |
bsalomon@google.com | 86afc2a | 2011-02-16 16:12:19 +0000 | [diff] [blame] | 820 | fClipSet = false; |
bsalomon@google.com | a4f6b10 | 2012-06-26 21:04:22 +0000 | [diff] [blame] | 821 | fCmds.push_back(kSetClip_Cmd); |
| 822 | } |
| 823 | |
bsalomon@google.com | a4f6b10 | 2012-06-26 21:04:22 +0000 | [diff] [blame] | 824 | void GrInOrderDrawBuffer::recordState() { |
bsalomon@google.com | ca43208 | 2013-01-23 19:53:46 +0000 | [diff] [blame] | 825 | fStates.push_back().saveFrom(this->getDrawState()); |
bsalomon@google.com | a4f6b10 | 2012-06-26 21:04:22 +0000 | [diff] [blame] | 826 | fCmds.push_back(kSetState_Cmd); |
| 827 | } |
| 828 | |
bsalomon@google.com | 74749cd | 2013-01-30 16:12:41 +0000 | [diff] [blame] | 829 | GrInOrderDrawBuffer::DrawRecord* GrInOrderDrawBuffer::recordDraw(const DrawInfo& info) { |
bsalomon@google.com | d62e88e | 2013-02-01 14:19:27 +0000 | [diff] [blame] | 830 | fCmds.push_back(kDraw_Cmd); |
| 831 | return &fDraws.push_back(info); |
bsalomon@google.com | 74749cd | 2013-01-30 16:12:41 +0000 | [diff] [blame] | 832 | } |
| 833 | |
bsalomon@google.com | ded4f4b | 2012-06-28 18:48:06 +0000 | [diff] [blame] | 834 | GrInOrderDrawBuffer::StencilPath* GrInOrderDrawBuffer::recordStencilPath() { |
| 835 | fCmds.push_back(kStencilPath_Cmd); |
| 836 | return &fStencilPaths.push_back(); |
| 837 | } |
| 838 | |
commit-bot@chromium.org | 32184d8 | 2013-10-09 15:14:18 +0000 | [diff] [blame] | 839 | GrInOrderDrawBuffer::DrawPath* GrInOrderDrawBuffer::recordDrawPath() { |
| 840 | fCmds.push_back(kDrawPath_Cmd); |
| 841 | return &fDrawPaths.push_back(); |
commit-bot@chromium.org | c4dc0ad | 2013-10-09 14:11:33 +0000 | [diff] [blame] | 842 | } |
| 843 | |
bsalomon@google.com | a4f6b10 | 2012-06-26 21:04:22 +0000 | [diff] [blame] | 844 | GrInOrderDrawBuffer::Clear* GrInOrderDrawBuffer::recordClear() { |
| 845 | fCmds.push_back(kClear_Cmd); |
| 846 | return &fClears.push_back(); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 847 | } |
bsalomon@google.com | d302f14 | 2011-03-03 13:54:13 +0000 | [diff] [blame] | 848 | |
bsalomon@google.com | 116ad84 | 2013-04-09 15:38:19 +0000 | [diff] [blame] | 849 | GrInOrderDrawBuffer::CopySurface* GrInOrderDrawBuffer::recordCopySurface() { |
| 850 | fCmds.push_back(kCopySurface_Cmd); |
| 851 | return &fCopySurfaces.push_back(); |
| 852 | } |
| 853 | |
| 854 | |
robertphillips@google.com | beb1af7 | 2012-07-26 18:52:16 +0000 | [diff] [blame] | 855 | void GrInOrderDrawBuffer::clipWillBeSet(const GrClipData* newClipData) { |
| 856 | INHERITED::clipWillBeSet(newClipData); |
bsalomon@google.com | 86afc2a | 2011-02-16 16:12:19 +0000 | [diff] [blame] | 857 | fClipSet = true; |
bsalomon@google.com | d62e88e | 2013-02-01 14:19:27 +0000 | [diff] [blame] | 858 | fClipProxyState = kUnknown_ClipProxyState; |
bsalomon@google.com | 86afc2a | 2011-02-16 16:12:19 +0000 | [diff] [blame] | 859 | } |