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