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