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