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