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