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