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) |
bsalomon@google.com | 6e4e650 | 2013-02-25 20:12:45 +0000 | [diff] [blame] | 23 | , fDstGpu(gpu) |
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()) { |
tfarina | 38406c8 | 2014-10-31 07:11:12 -0700 | [diff] [blame] | 126 | SkDebugf("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 | |
joshualitt | 2c93efe | 2014-11-06 12:57:13 -0800 | [diff] [blame^] | 176 | int GrInOrderDrawBuffer::concatInstancedDraw(const DrawInfo& info, |
| 177 | const GrClipMaskManager::ScissorState& scissorState) { |
cdalton | 6819df3 | 2014-10-15 13:43:48 -0700 | [diff] [blame] | 178 | SkASSERT(!fCmdBuffer.empty()); |
tfarina@chromium.org | f6de475 | 2013-08-17 00:02:59 +0000 | [diff] [blame] | 179 | SkASSERT(info.isInstanced()); |
bsalomon@google.com | d62e88e | 2013-02-01 14:19:27 +0000 | [diff] [blame] | 180 | |
bsalomon@google.com | 934c570 | 2012-03-20 21:17:58 +0000 | [diff] [blame] | 181 | const GeometrySrcState& geomSrc = this->getGeomSrc(); |
jvanverth@google.com | b75b0a0 | 2013-02-05 20:33:30 +0000 | [diff] [blame] | 182 | const GrDrawState& drawState = this->getDrawState(); |
bsalomon@google.com | 934c570 | 2012-03-20 21:17:58 +0000 | [diff] [blame] | 183 | |
bsalomon@google.com | d62e88e | 2013-02-01 14:19:27 +0000 | [diff] [blame] | 184 | // we only attempt to concat the case when reserved verts are used with a client-specified index |
| 185 | // buffer. To make this work with client-specified VBs we'd need to know if the VB was updated |
| 186 | // between draws. |
| 187 | if (kReserved_GeometrySrcType != geomSrc.fVertexSrc || |
| 188 | kBuffer_GeometrySrcType != geomSrc.fIndexSrc) { |
| 189 | return 0; |
bsalomon@google.com | 934c570 | 2012-03-20 21:17:58 +0000 | [diff] [blame] | 190 | } |
bsalomon@google.com | d62e88e | 2013-02-01 14:19:27 +0000 | [diff] [blame] | 191 | // Check if there is a draw info that is compatible that uses the same VB from the pool and |
| 192 | // the same IB |
cdalton | 6819df3 | 2014-10-15 13:43:48 -0700 | [diff] [blame] | 193 | if (kDraw_Cmd != strip_trace_bit(fCmdBuffer.back().fType)) { |
bsalomon@google.com | d62e88e | 2013-02-01 14:19:27 +0000 | [diff] [blame] | 194 | return 0; |
| 195 | } |
| 196 | |
cdalton | 6819df3 | 2014-10-15 13:43:48 -0700 | [diff] [blame] | 197 | Draw* draw = static_cast<Draw*>(&fCmdBuffer.back()); |
bsalomon@google.com | d62e88e | 2013-02-01 14:19:27 +0000 | [diff] [blame] | 198 | GeometryPoolState& poolState = fGeoPoolStateStack.back(); |
| 199 | const GrVertexBuffer* vertexBuffer = poolState.fPoolVertexBuffer; |
| 200 | |
cdalton | 6819df3 | 2014-10-15 13:43:48 -0700 | [diff] [blame] | 201 | if (!draw->fInfo.isInstanced() || |
| 202 | draw->fInfo.verticesPerInstance() != info.verticesPerInstance() || |
| 203 | draw->fInfo.indicesPerInstance() != info.indicesPerInstance() || |
bsalomon | b3e3a95 | 2014-09-19 11:10:40 -0700 | [diff] [blame] | 204 | draw->vertexBuffer() != vertexBuffer || |
joshualitt | 2c93efe | 2014-11-06 12:57:13 -0800 | [diff] [blame^] | 205 | draw->indexBuffer() != geomSrc.fIndexBuffer || |
| 206 | draw->fScissorState != scissorState) { |
bsalomon@google.com | d62e88e | 2013-02-01 14:19:27 +0000 | [diff] [blame] | 207 | return 0; |
| 208 | } |
| 209 | // info does not yet account for the offset from the start of the pool's VB while the previous |
| 210 | // draw record does. |
| 211 | int adjustedStartVertex = poolState.fPoolStartVertex + info.startVertex(); |
cdalton | 6819df3 | 2014-10-15 13:43:48 -0700 | [diff] [blame] | 212 | if (draw->fInfo.startVertex() + draw->fInfo.vertexCount() != adjustedStartVertex) { |
bsalomon@google.com | d62e88e | 2013-02-01 14:19:27 +0000 | [diff] [blame] | 213 | return 0; |
| 214 | } |
| 215 | |
cdalton | 6819df3 | 2014-10-15 13:43:48 -0700 | [diff] [blame] | 216 | SkASSERT(poolState.fPoolStartVertex == draw->fInfo.startVertex() + draw->fInfo.vertexCount()); |
bsalomon@google.com | d62e88e | 2013-02-01 14:19:27 +0000 | [diff] [blame] | 217 | |
| 218 | // how many instances can be concat'ed onto draw given the size of the index buffer |
| 219 | int instancesToConcat = this->indexCountInCurrentSource() / info.indicesPerInstance(); |
cdalton | 6819df3 | 2014-10-15 13:43:48 -0700 | [diff] [blame] | 220 | instancesToConcat -= draw->fInfo.instanceCount(); |
commit-bot@chromium.org | 972f9cd | 2014-03-28 17:58:28 +0000 | [diff] [blame] | 221 | instancesToConcat = SkTMin(instancesToConcat, info.instanceCount()); |
bsalomon@google.com | d62e88e | 2013-02-01 14:19:27 +0000 | [diff] [blame] | 222 | |
| 223 | // 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] | 224 | size_t vertexBytes = instancesToConcat * info.verticesPerInstance() * |
egdaniel | 7b3d5ee | 2014-08-28 05:41:14 -0700 | [diff] [blame] | 225 | drawState.getVertexStride(); |
commit-bot@chromium.org | 972f9cd | 2014-03-28 17:58:28 +0000 | [diff] [blame] | 226 | poolState.fUsedPoolVertexBytes = SkTMax(poolState.fUsedPoolVertexBytes, vertexBytes); |
bsalomon@google.com | d62e88e | 2013-02-01 14:19:27 +0000 | [diff] [blame] | 227 | |
cdalton | 6819df3 | 2014-10-15 13:43:48 -0700 | [diff] [blame] | 228 | draw->fInfo.adjustInstanceCount(instancesToConcat); |
commit-bot@chromium.org | 2a05de0 | 2014-03-25 15:17:32 +0000 | [diff] [blame] | 229 | |
| 230 | // update last fGpuCmdMarkers to include any additional trace markers that have been added |
| 231 | if (this->getActiveTraceMarkers().count() > 0) { |
cdalton | 6819df3 | 2014-10-15 13:43:48 -0700 | [diff] [blame] | 232 | if (cmd_has_trace_marker(draw->fType)) { |
commit-bot@chromium.org | 2a05de0 | 2014-03-25 15:17:32 +0000 | [diff] [blame] | 233 | fGpuCmdMarkers.back().addSet(this->getActiveTraceMarkers()); |
| 234 | } else { |
| 235 | fGpuCmdMarkers.push_back(this->getActiveTraceMarkers()); |
cdalton | 6819df3 | 2014-10-15 13:43:48 -0700 | [diff] [blame] | 236 | draw->fType = add_trace_bit(draw->fType); |
commit-bot@chromium.org | 2a05de0 | 2014-03-25 15:17:32 +0000 | [diff] [blame] | 237 | } |
| 238 | } |
| 239 | |
bsalomon@google.com | d62e88e | 2013-02-01 14:19:27 +0000 | [diff] [blame] | 240 | return instancesToConcat; |
bsalomon@google.com | 934c570 | 2012-03-20 21:17:58 +0000 | [diff] [blame] | 241 | } |
| 242 | |
joshualitt | 2c93efe | 2014-11-06 12:57:13 -0800 | [diff] [blame^] | 243 | void GrInOrderDrawBuffer::onDraw(const DrawInfo& info, |
| 244 | const GrClipMaskManager::ScissorState& scissorState) { |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 245 | |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 246 | GeometryPoolState& poolState = fGeoPoolStateStack.back(); |
jvanverth@google.com | b75b0a0 | 2013-02-05 20:33:30 +0000 | [diff] [blame] | 247 | const GrDrawState& drawState = this->getDrawState(); |
bsalomon@google.com | d62e88e | 2013-02-01 14:19:27 +0000 | [diff] [blame] | 248 | |
bsalomon | 838f62d | 2014-08-05 07:15:57 -0700 | [diff] [blame] | 249 | this->recordStateIfNecessary(); |
bsalomon@google.com | 86afc2a | 2011-02-16 16:12:19 +0000 | [diff] [blame] | 250 | |
bsalomon | b3e3a95 | 2014-09-19 11:10:40 -0700 | [diff] [blame] | 251 | const GrVertexBuffer* vb; |
| 252 | if (kBuffer_GeometrySrcType == this->getGeomSrc().fVertexSrc) { |
| 253 | vb = this->getGeomSrc().fVertexBuffer; |
| 254 | } else { |
| 255 | vb = poolState.fPoolVertexBuffer; |
| 256 | } |
| 257 | |
| 258 | const GrIndexBuffer* ib = NULL; |
| 259 | if (info.isIndexed()) { |
| 260 | if (kBuffer_GeometrySrcType == this->getGeomSrc().fIndexSrc) { |
| 261 | ib = this->getGeomSrc().fIndexBuffer; |
| 262 | } else { |
| 263 | ib = poolState.fPoolIndexBuffer; |
| 264 | } |
| 265 | } |
| 266 | |
| 267 | Draw* draw; |
bsalomon@google.com | d62e88e | 2013-02-01 14:19:27 +0000 | [diff] [blame] | 268 | if (info.isInstanced()) { |
joshualitt | 2c93efe | 2014-11-06 12:57:13 -0800 | [diff] [blame^] | 269 | int instancesConcated = this->concatInstancedDraw(info, scissorState); |
bsalomon@google.com | d62e88e | 2013-02-01 14:19:27 +0000 | [diff] [blame] | 270 | if (info.instanceCount() > instancesConcated) { |
joshualitt | 2c93efe | 2014-11-06 12:57:13 -0800 | [diff] [blame^] | 271 | draw = GrNEW_APPEND_TO_RECORDER(fCmdBuffer, Draw, (info, scissorState, vb, ib)); |
cdalton | 6819df3 | 2014-10-15 13:43:48 -0700 | [diff] [blame] | 272 | draw->fInfo.adjustInstanceCount(-instancesConcated); |
bsalomon@google.com | d62e88e | 2013-02-01 14:19:27 +0000 | [diff] [blame] | 273 | } else { |
| 274 | return; |
| 275 | } |
| 276 | } else { |
joshualitt | 2c93efe | 2014-11-06 12:57:13 -0800 | [diff] [blame^] | 277 | draw = GrNEW_APPEND_TO_RECORDER(fCmdBuffer, Draw, (info, scissorState, vb, ib)); |
bsalomon@google.com | d62e88e | 2013-02-01 14:19:27 +0000 | [diff] [blame] | 278 | } |
cdalton | 6819df3 | 2014-10-15 13:43:48 -0700 | [diff] [blame] | 279 | this->recordTraceMarkersIfNecessary(); |
bsalomon@google.com | 74749cd | 2013-01-30 16:12:41 +0000 | [diff] [blame] | 280 | |
bsalomon | b3e3a95 | 2014-09-19 11:10:40 -0700 | [diff] [blame] | 281 | // Adjust the starting vertex and index when we are using reserved or array sources to |
| 282 | // compensate for the fact that the data was inserted into a larger vb/ib owned by the pool. |
| 283 | if (kBuffer_GeometrySrcType != this->getGeomSrc().fVertexSrc) { |
| 284 | size_t bytes = (info.vertexCount() + info.startVertex()) * drawState.getVertexStride(); |
| 285 | poolState.fUsedPoolVertexBytes = SkTMax(poolState.fUsedPoolVertexBytes, bytes); |
cdalton | 6819df3 | 2014-10-15 13:43:48 -0700 | [diff] [blame] | 286 | draw->fInfo.adjustStartVertex(poolState.fPoolStartVertex); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 287 | } |
bsalomon | b3e3a95 | 2014-09-19 11:10:40 -0700 | [diff] [blame] | 288 | |
| 289 | if (info.isIndexed() && kBuffer_GeometrySrcType != this->getGeomSrc().fIndexSrc) { |
| 290 | size_t bytes = (info.indexCount() + info.startIndex()) * sizeof(uint16_t); |
| 291 | poolState.fUsedPoolIndexBytes = SkTMax(poolState.fUsedPoolIndexBytes, bytes); |
cdalton | 6819df3 | 2014-10-15 13:43:48 -0700 | [diff] [blame] | 292 | draw->fInfo.adjustStartIndex(poolState.fPoolStartIndex); |
commit-bot@chromium.org | 9b62aa1 | 2014-03-25 11:59:40 +0000 | [diff] [blame] | 293 | } |
commit-bot@chromium.org | 9b62aa1 | 2014-03-25 11:59:40 +0000 | [diff] [blame] | 294 | } |
sugoi@google.com | 5f74cf8 | 2012-12-17 21:16:45 +0000 | [diff] [blame] | 295 | |
joshualitt | 2c93efe | 2014-11-06 12:57:13 -0800 | [diff] [blame^] | 296 | void GrInOrderDrawBuffer::onStencilPath(const GrPath* path, |
| 297 | const GrClipMaskManager::ScissorState& scissorState, |
| 298 | const GrStencilSettings& stencilSettings) { |
bsalomon@google.com | ded4f4b | 2012-06-28 18:48:06 +0000 | [diff] [blame] | 299 | // Only compare the subset of GrDrawState relevant to path stenciling? |
bsalomon | 838f62d | 2014-08-05 07:15:57 -0700 | [diff] [blame] | 300 | this->recordStateIfNecessary(); |
cdalton | 6819df3 | 2014-10-15 13:43:48 -0700 | [diff] [blame] | 301 | StencilPath* sp = GrNEW_APPEND_TO_RECORDER(fCmdBuffer, StencilPath, (path)); |
joshualitt | 2c93efe | 2014-11-06 12:57:13 -0800 | [diff] [blame^] | 302 | sp->fScissorState = scissorState; |
| 303 | sp->fStencilSettings = stencilSettings; |
cdalton | 6819df3 | 2014-10-15 13:43:48 -0700 | [diff] [blame] | 304 | this->recordTraceMarkersIfNecessary(); |
bsalomon@google.com | 64aef2b | 2012-06-11 15:36:13 +0000 | [diff] [blame] | 305 | } |
| 306 | |
commit-bot@chromium.org | 32184d8 | 2013-10-09 15:14:18 +0000 | [diff] [blame] | 307 | void GrInOrderDrawBuffer::onDrawPath(const GrPath* path, |
joshualitt | 2c93efe | 2014-11-06 12:57:13 -0800 | [diff] [blame^] | 308 | const GrClipMaskManager::ScissorState& scissorState, |
| 309 | const GrStencilSettings& stencilSettings, |
joshualitt | 92e496f | 2014-10-31 13:56:50 -0700 | [diff] [blame] | 310 | const GrDeviceCoordTexture* dstCopy) { |
commit-bot@chromium.org | c4dc0ad | 2013-10-09 14:11:33 +0000 | [diff] [blame] | 311 | // TODO: Only compare the subset of GrDrawState relevant to path covering? |
bsalomon | 838f62d | 2014-08-05 07:15:57 -0700 | [diff] [blame] | 312 | this->recordStateIfNecessary(); |
cdalton | 6819df3 | 2014-10-15 13:43:48 -0700 | [diff] [blame] | 313 | DrawPath* dp = GrNEW_APPEND_TO_RECORDER(fCmdBuffer, DrawPath, (path)); |
bsalomon | 49f085d | 2014-09-05 13:34:00 -0700 | [diff] [blame] | 314 | if (dstCopy) { |
cdalton | 6819df3 | 2014-10-15 13:43:48 -0700 | [diff] [blame] | 315 | dp->fDstCopy = *dstCopy; |
commit-bot@chromium.org | c4dc0ad | 2013-10-09 14:11:33 +0000 | [diff] [blame] | 316 | } |
joshualitt | 2c93efe | 2014-11-06 12:57:13 -0800 | [diff] [blame^] | 317 | dp->fScissorState = scissorState; |
| 318 | dp->fStencilSettings = stencilSettings; |
cdalton | 6819df3 | 2014-10-15 13:43:48 -0700 | [diff] [blame] | 319 | this->recordTraceMarkersIfNecessary(); |
commit-bot@chromium.org | c4dc0ad | 2013-10-09 14:11:33 +0000 | [diff] [blame] | 320 | } |
| 321 | |
cdalton | b85a0aa | 2014-07-21 15:32:44 -0700 | [diff] [blame] | 322 | void GrInOrderDrawBuffer::onDrawPaths(const GrPathRange* pathRange, |
joshualitt | 2c93efe | 2014-11-06 12:57:13 -0800 | [diff] [blame^] | 323 | const uint32_t indices[], |
| 324 | int count, |
| 325 | const float transforms[], |
| 326 | PathTransformType transformsType, |
| 327 | const GrClipMaskManager::ScissorState& scissorState, |
| 328 | const GrStencilSettings& stencilSettings, |
joshualitt | 92e496f | 2014-10-31 13:56:50 -0700 | [diff] [blame] | 329 | const GrDeviceCoordTexture* dstCopy) { |
bsalomon | 49f085d | 2014-09-05 13:34:00 -0700 | [diff] [blame] | 330 | SkASSERT(pathRange); |
| 331 | SkASSERT(indices); |
| 332 | SkASSERT(transforms); |
commit-bot@chromium.org | 9b62aa1 | 2014-03-25 11:59:40 +0000 | [diff] [blame] | 333 | |
bsalomon | 838f62d | 2014-08-05 07:15:57 -0700 | [diff] [blame] | 334 | this->recordStateIfNecessary(); |
cdalton | 6819df3 | 2014-10-15 13:43:48 -0700 | [diff] [blame] | 335 | |
| 336 | int sizeOfIndices = sizeof(uint32_t) * count; |
| 337 | int sizeOfTransforms = sizeof(float) * count * |
| 338 | GrPathRendering::PathTransformSize(transformsType); |
| 339 | |
| 340 | DrawPaths* dp = GrNEW_APPEND_WITH_DATA_TO_RECORDER(fCmdBuffer, DrawPaths, (pathRange), |
| 341 | sizeOfIndices + sizeOfTransforms); |
| 342 | memcpy(dp->indices(), indices, sizeOfIndices); |
cdalton | b85a0aa | 2014-07-21 15:32:44 -0700 | [diff] [blame] | 343 | dp->fCount = count; |
cdalton | 6819df3 | 2014-10-15 13:43:48 -0700 | [diff] [blame] | 344 | memcpy(dp->transforms(), transforms, sizeOfTransforms); |
cdalton | b85a0aa | 2014-07-21 15:32:44 -0700 | [diff] [blame] | 345 | dp->fTransformsType = transformsType; |
joshualitt | 2c93efe | 2014-11-06 12:57:13 -0800 | [diff] [blame^] | 346 | dp->fScissorState = scissorState; |
| 347 | dp->fStencilSettings = stencilSettings; |
bsalomon | 49f085d | 2014-09-05 13:34:00 -0700 | [diff] [blame] | 348 | if (dstCopy) { |
commit-bot@chromium.org | 9b62aa1 | 2014-03-25 11:59:40 +0000 | [diff] [blame] | 349 | dp->fDstCopy = *dstCopy; |
| 350 | } |
cdalton | 6819df3 | 2014-10-15 13:43:48 -0700 | [diff] [blame] | 351 | |
| 352 | this->recordTraceMarkersIfNecessary(); |
commit-bot@chromium.org | 9b62aa1 | 2014-03-25 11:59:40 +0000 | [diff] [blame] | 353 | } |
| 354 | |
bsalomon | 63b2196 | 2014-11-05 07:05:34 -0800 | [diff] [blame] | 355 | void GrInOrderDrawBuffer::onClear(const SkIRect* rect, GrColor color, |
| 356 | bool canIgnoreRect, GrRenderTarget* renderTarget) { |
commit-bot@chromium.org | fd03d4a | 2013-07-17 21:39:42 +0000 | [diff] [blame] | 357 | SkIRect r; |
bsalomon@google.com | 1b3ce47 | 2012-08-17 13:43:08 +0000 | [diff] [blame] | 358 | if (NULL == renderTarget) { |
| 359 | renderTarget = this->drawState()->getRenderTarget(); |
bsalomon | 49f085d | 2014-09-05 13:34:00 -0700 | [diff] [blame] | 360 | SkASSERT(renderTarget); |
bsalomon@google.com | 1b3ce47 | 2012-08-17 13:43:08 +0000 | [diff] [blame] | 361 | } |
bsalomon@google.com | 6aa25c3 | 2011-04-27 19:55:29 +0000 | [diff] [blame] | 362 | if (NULL == rect) { |
| 363 | // We could do something smart and remove previous draws and clears to |
| 364 | // the current render target. If we get that smart we have to make sure |
| 365 | // those draws aren't read before this clear (render-to-texture). |
bsalomon@google.com | 1b3ce47 | 2012-08-17 13:43:08 +0000 | [diff] [blame] | 366 | r.setLTRB(0, 0, renderTarget->width(), renderTarget->height()); |
bsalomon@google.com | 6aa25c3 | 2011-04-27 19:55:29 +0000 | [diff] [blame] | 367 | rect = &r; |
| 368 | } |
cdalton | 6819df3 | 2014-10-15 13:43:48 -0700 | [diff] [blame] | 369 | Clear* clr = GrNEW_APPEND_TO_RECORDER(fCmdBuffer, Clear, (renderTarget)); |
commit-bot@chromium.org | 28361fa | 2014-03-28 16:08:05 +0000 | [diff] [blame] | 370 | GrColorIsPMAssert(color); |
bsalomon@google.com | a4f6b10 | 2012-06-26 21:04:22 +0000 | [diff] [blame] | 371 | clr->fColor = color; |
| 372 | clr->fRect = *rect; |
robertphillips@google.com | 56ce48a | 2013-10-31 21:44:25 +0000 | [diff] [blame] | 373 | clr->fCanIgnoreRect = canIgnoreRect; |
cdalton | 6819df3 | 2014-10-15 13:43:48 -0700 | [diff] [blame] | 374 | this->recordTraceMarkersIfNecessary(); |
bsalomon@google.com | 0b335c1 | 2011-04-25 19:17:44 +0000 | [diff] [blame] | 375 | } |
| 376 | |
joshualitt | 6db519c | 2014-10-29 08:48:18 -0700 | [diff] [blame] | 377 | void GrInOrderDrawBuffer::clearStencilClip(const SkIRect& rect, |
| 378 | bool insideClip, |
| 379 | GrRenderTarget* renderTarget) { |
| 380 | if (NULL == renderTarget) { |
| 381 | renderTarget = this->drawState()->getRenderTarget(); |
| 382 | SkASSERT(renderTarget); |
| 383 | } |
| 384 | ClearStencilClip* clr = GrNEW_APPEND_TO_RECORDER(fCmdBuffer, ClearStencilClip, (renderTarget)); |
| 385 | clr->fRect = rect; |
| 386 | clr->fInsideClip = insideClip; |
| 387 | this->recordTraceMarkersIfNecessary(); |
| 388 | } |
| 389 | |
commit-bot@chromium.org | 28361fa | 2014-03-28 16:08:05 +0000 | [diff] [blame] | 390 | void GrInOrderDrawBuffer::discard(GrRenderTarget* renderTarget) { |
bsalomon | 89c6298 | 2014-11-03 12:08:42 -0800 | [diff] [blame] | 391 | SkASSERT(renderTarget); |
commit-bot@chromium.org | 28361fa | 2014-03-28 16:08:05 +0000 | [diff] [blame] | 392 | if (!this->caps()->discardRenderTargetSupport()) { |
| 393 | return; |
| 394 | } |
cdalton | 6819df3 | 2014-10-15 13:43:48 -0700 | [diff] [blame] | 395 | Clear* clr = GrNEW_APPEND_TO_RECORDER(fCmdBuffer, Clear, (renderTarget)); |
commit-bot@chromium.org | 28361fa | 2014-03-28 16:08:05 +0000 | [diff] [blame] | 396 | clr->fColor = GrColor_ILLEGAL; |
cdalton | 6819df3 | 2014-10-15 13:43:48 -0700 | [diff] [blame] | 397 | this->recordTraceMarkersIfNecessary(); |
commit-bot@chromium.org | 28361fa | 2014-03-28 16:08:05 +0000 | [diff] [blame] | 398 | } |
| 399 | |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 400 | void GrInOrderDrawBuffer::reset() { |
tfarina@chromium.org | f6de475 | 2013-08-17 00:02:59 +0000 | [diff] [blame] | 401 | SkASSERT(1 == fGeoPoolStateStack.count()); |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 402 | this->resetVertexSource(); |
| 403 | this->resetIndexSource(); |
cdalton | 6819df3 | 2014-10-15 13:43:48 -0700 | [diff] [blame] | 404 | |
| 405 | fCmdBuffer.reset(); |
| 406 | fLastState = NULL; |
bsalomon@google.com | 1c13c96 | 2011-02-14 16:51:21 +0000 | [diff] [blame] | 407 | fVertexPool.reset(); |
| 408 | fIndexPool.reset(); |
commit-bot@chromium.org | 2a05de0 | 2014-03-25 15:17:32 +0000 | [diff] [blame] | 409 | fGpuCmdMarkers.reset(); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 410 | } |
| 411 | |
robertphillips@google.com | 1267fbd | 2013-07-03 18:37:27 +0000 | [diff] [blame] | 412 | void GrInOrderDrawBuffer::flush() { |
| 413 | if (fFlushing) { |
| 414 | return; |
| 415 | } |
| 416 | |
jvanverth | 8e80d17 | 2014-06-19 12:01:10 -0700 | [diff] [blame] | 417 | this->getContext()->getFontCache()->updateTextures(); |
| 418 | |
tfarina@chromium.org | f6de475 | 2013-08-17 00:02:59 +0000 | [diff] [blame] | 419 | SkASSERT(kReserved_GeometrySrcType != this->getGeomSrc().fVertexSrc); |
| 420 | SkASSERT(kReserved_GeometrySrcType != this->getGeomSrc().fIndexSrc); |
bsalomon@google.com | 3f5a95e | 2012-03-08 16:41:42 +0000 | [diff] [blame] | 421 | |
cdalton | 6819df3 | 2014-10-15 13:43:48 -0700 | [diff] [blame] | 422 | if (fCmdBuffer.empty()) { |
robertphillips@google.com | 1267fbd | 2013-07-03 18:37:27 +0000 | [diff] [blame] | 423 | return; |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 424 | } |
bsalomon@google.com | 6e4e650 | 2013-02-25 20:12:45 +0000 | [diff] [blame] | 425 | |
| 426 | GrAutoTRestore<bool> flushRestore(&fFlushing); |
| 427 | fFlushing = true; |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 428 | |
commit-bot@chromium.org | 8341eb7 | 2014-05-07 20:51:05 +0000 | [diff] [blame] | 429 | fVertexPool.unmap(); |
| 430 | fIndexPool.unmap(); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 431 | |
bsalomon | a70353e | 2014-07-07 08:15:07 -0700 | [diff] [blame] | 432 | GrDrawState* prevDrawState = SkRef(fDstGpu->drawState()); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 433 | |
cdalton | 6819df3 | 2014-10-15 13:43:48 -0700 | [diff] [blame] | 434 | CmdBuffer::Iter iter(fCmdBuffer); |
robertphillips@google.com | beb1af7 | 2012-07-26 18:52:16 +0000 | [diff] [blame] | 435 | |
cdalton | 6819df3 | 2014-10-15 13:43:48 -0700 | [diff] [blame] | 436 | int currCmdMarker = 0; |
egdaniel | 3eee383 | 2014-06-18 13:09:11 -0700 | [diff] [blame] | 437 | fDstGpu->saveActiveTraceMarkers(); |
cdalton | 6819df3 | 2014-10-15 13:43:48 -0700 | [diff] [blame] | 438 | |
| 439 | while (iter.next()) { |
commit-bot@chromium.org | 2a05de0 | 2014-03-25 15:17:32 +0000 | [diff] [blame] | 440 | GrGpuTraceMarker newMarker("", -1); |
egdaniel | d78a168 | 2014-07-09 10:41:26 -0700 | [diff] [blame] | 441 | SkString traceString; |
cdalton | 6819df3 | 2014-10-15 13:43:48 -0700 | [diff] [blame] | 442 | if (cmd_has_trace_marker(iter->fType)) { |
egdaniel | d78a168 | 2014-07-09 10:41:26 -0700 | [diff] [blame] | 443 | traceString = fGpuCmdMarkers[currCmdMarker].toString(); |
commit-bot@chromium.org | 2a05de0 | 2014-03-25 15:17:32 +0000 | [diff] [blame] | 444 | newMarker.fMarker = traceString.c_str(); |
| 445 | fDstGpu->addGpuTraceMarker(&newMarker); |
| 446 | ++currCmdMarker; |
| 447 | } |
cdalton | 6819df3 | 2014-10-15 13:43:48 -0700 | [diff] [blame] | 448 | |
| 449 | SkDEBUGCODE(bool isDraw = kDraw_Cmd == strip_trace_bit(iter->fType) || |
| 450 | kStencilPath_Cmd == strip_trace_bit(iter->fType) || |
| 451 | kDrawPath_Cmd == strip_trace_bit(iter->fType) || |
| 452 | kDrawPaths_Cmd == strip_trace_bit(iter->fType)); |
| 453 | SkASSERT(!isDraw || fDstGpu->drawState() != prevDrawState); |
| 454 | |
| 455 | iter->execute(fDstGpu); |
| 456 | |
| 457 | if (cmd_has_trace_marker(iter->fType)) { |
commit-bot@chromium.org | 2a05de0 | 2014-03-25 15:17:32 +0000 | [diff] [blame] | 458 | fDstGpu->removeGpuTraceMarker(&newMarker); |
| 459 | } |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 460 | } |
mtklein | f439c77 | 2014-10-14 14:29:30 -0700 | [diff] [blame] | 461 | |
cdalton | 6819df3 | 2014-10-15 13:43:48 -0700 | [diff] [blame] | 462 | fDstGpu->restoreActiveTraceMarkers(); |
commit-bot@chromium.org | 2a05de0 | 2014-03-25 15:17:32 +0000 | [diff] [blame] | 463 | SkASSERT(fGpuCmdMarkers.count() == currCmdMarker); |
bsalomon@google.com | a4f6b10 | 2012-06-26 21:04:22 +0000 | [diff] [blame] | 464 | |
bsalomon@google.com | 6e4e650 | 2013-02-25 20:12:45 +0000 | [diff] [blame] | 465 | fDstGpu->setDrawState(prevDrawState); |
bsalomon@google.com | a5d056a | 2012-03-27 15:59:58 +0000 | [diff] [blame] | 466 | prevDrawState->unref(); |
bsalomon@google.com | 55e4a20 | 2013-01-11 13:54:21 +0000 | [diff] [blame] | 467 | this->reset(); |
commit-bot@chromium.org | a8916ff | 2013-08-16 15:53:46 +0000 | [diff] [blame] | 468 | ++fDrawID; |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 469 | } |
| 470 | |
joshualitt | 6db519c | 2014-10-29 08:48:18 -0700 | [diff] [blame] | 471 | void GrInOrderDrawBuffer::Draw::execute(GrClipTarget* gpu) { |
cdalton | 6819df3 | 2014-10-15 13:43:48 -0700 | [diff] [blame] | 472 | gpu->setVertexSourceToBuffer(this->vertexBuffer()); |
| 473 | if (fInfo.isIndexed()) { |
| 474 | gpu->setIndexSourceToBuffer(this->indexBuffer()); |
| 475 | } |
joshualitt | 2c93efe | 2014-11-06 12:57:13 -0800 | [diff] [blame^] | 476 | gpu->executeDraw(fInfo, fScissorState); |
cdalton | 6819df3 | 2014-10-15 13:43:48 -0700 | [diff] [blame] | 477 | } |
| 478 | |
joshualitt | 6db519c | 2014-10-29 08:48:18 -0700 | [diff] [blame] | 479 | void GrInOrderDrawBuffer::StencilPath::execute(GrClipTarget* gpu) { |
joshualitt | 2c93efe | 2014-11-06 12:57:13 -0800 | [diff] [blame^] | 480 | gpu->executeStencilPath(this->path(), fScissorState, fStencilSettings); |
cdalton | 6819df3 | 2014-10-15 13:43:48 -0700 | [diff] [blame] | 481 | } |
| 482 | |
joshualitt | 6db519c | 2014-10-29 08:48:18 -0700 | [diff] [blame] | 483 | void GrInOrderDrawBuffer::DrawPath::execute(GrClipTarget* gpu) { |
joshualitt | 2c93efe | 2014-11-06 12:57:13 -0800 | [diff] [blame^] | 484 | gpu->executeDrawPath(this->path(), fScissorState, fStencilSettings, |
| 485 | fDstCopy.texture() ? &fDstCopy : NULL); |
cdalton | 6819df3 | 2014-10-15 13:43:48 -0700 | [diff] [blame] | 486 | } |
| 487 | |
joshualitt | 6db519c | 2014-10-29 08:48:18 -0700 | [diff] [blame] | 488 | void GrInOrderDrawBuffer::DrawPaths::execute(GrClipTarget* gpu) { |
cdalton | 6819df3 | 2014-10-15 13:43:48 -0700 | [diff] [blame] | 489 | gpu->executeDrawPaths(this->pathRange(), this->indices(), fCount, this->transforms(), |
joshualitt | 2c93efe | 2014-11-06 12:57:13 -0800 | [diff] [blame^] | 490 | fTransformsType, fScissorState, fStencilSettings, |
| 491 | fDstCopy.texture() ? &fDstCopy : NULL); |
cdalton | 6819df3 | 2014-10-15 13:43:48 -0700 | [diff] [blame] | 492 | } |
| 493 | |
joshualitt | 6db519c | 2014-10-29 08:48:18 -0700 | [diff] [blame] | 494 | void GrInOrderDrawBuffer::SetState::execute(GrClipTarget* gpu) { |
cdalton | 6819df3 | 2014-10-15 13:43:48 -0700 | [diff] [blame] | 495 | gpu->setDrawState(&fState); |
| 496 | } |
| 497 | |
joshualitt | 6db519c | 2014-10-29 08:48:18 -0700 | [diff] [blame] | 498 | void GrInOrderDrawBuffer::Clear::execute(GrClipTarget* gpu) { |
cdalton | 6819df3 | 2014-10-15 13:43:48 -0700 | [diff] [blame] | 499 | if (GrColor_ILLEGAL == fColor) { |
| 500 | gpu->discard(this->renderTarget()); |
| 501 | } else { |
| 502 | gpu->clear(&fRect, fColor, fCanIgnoreRect, this->renderTarget()); |
| 503 | } |
| 504 | } |
| 505 | |
joshualitt | 6db519c | 2014-10-29 08:48:18 -0700 | [diff] [blame] | 506 | void GrInOrderDrawBuffer::ClearStencilClip::execute(GrClipTarget* gpu) { |
| 507 | gpu->clearStencilClip(fRect, fInsideClip, this->renderTarget()); |
| 508 | } |
| 509 | |
| 510 | void GrInOrderDrawBuffer::CopySurface::execute(GrClipTarget* gpu) { |
cdalton | 6819df3 | 2014-10-15 13:43:48 -0700 | [diff] [blame] | 511 | gpu->copySurface(this->dst(), this->src(), fSrcRect, fDstPoint); |
| 512 | } |
| 513 | |
joshualitt | a702415 | 2014-11-03 14:16:35 -0800 | [diff] [blame] | 514 | bool GrInOrderDrawBuffer::copySurface(GrSurface* dst, |
| 515 | GrSurface* src, |
| 516 | const SkIRect& srcRect, |
| 517 | const SkIPoint& dstPoint) { |
bsalomon@google.com | 116ad84 | 2013-04-09 15:38:19 +0000 | [diff] [blame] | 518 | if (fDstGpu->canCopySurface(dst, src, srcRect, dstPoint)) { |
cdalton | 6819df3 | 2014-10-15 13:43:48 -0700 | [diff] [blame] | 519 | CopySurface* cs = GrNEW_APPEND_TO_RECORDER(fCmdBuffer, CopySurface, (dst, src)); |
bsalomon@google.com | 116ad84 | 2013-04-09 15:38:19 +0000 | [diff] [blame] | 520 | cs->fSrcRect = srcRect; |
| 521 | cs->fDstPoint = dstPoint; |
cdalton | 6819df3 | 2014-10-15 13:43:48 -0700 | [diff] [blame] | 522 | this->recordTraceMarkersIfNecessary(); |
bsalomon@google.com | 116ad84 | 2013-04-09 15:38:19 +0000 | [diff] [blame] | 523 | return true; |
joshualitt | a702415 | 2014-11-03 14:16:35 -0800 | [diff] [blame] | 524 | } else if (GrDrawTarget::canCopySurface(dst, src, srcRect, dstPoint)) { |
| 525 | GrDrawTarget::copySurface(dst, src, srcRect, dstPoint); |
| 526 | return true; |
bsalomon@google.com | 116ad84 | 2013-04-09 15:38:19 +0000 | [diff] [blame] | 527 | } else { |
| 528 | return false; |
| 529 | } |
| 530 | } |
| 531 | |
joshualitt | a702415 | 2014-11-03 14:16:35 -0800 | [diff] [blame] | 532 | bool GrInOrderDrawBuffer::canCopySurface(GrSurface* dst, |
| 533 | GrSurface* src, |
| 534 | const SkIRect& srcRect, |
| 535 | const SkIPoint& dstPoint) { |
| 536 | return fDstGpu->canCopySurface(dst, src, srcRect, dstPoint) || |
| 537 | GrDrawTarget::canCopySurface(dst, src, srcRect, dstPoint); |
bsalomon@google.com | 116ad84 | 2013-04-09 15:38:19 +0000 | [diff] [blame] | 538 | } |
| 539 | |
bsalomon | f2703d8 | 2014-10-28 14:33:06 -0700 | [diff] [blame] | 540 | void GrInOrderDrawBuffer::initCopySurfaceDstDesc(const GrSurface* src, GrSurfaceDesc* desc) { |
bsalomon@google.com | eb85117 | 2013-04-15 13:51:00 +0000 | [diff] [blame] | 541 | fDstGpu->initCopySurfaceDstDesc(src, desc); |
| 542 | } |
| 543 | |
robertphillips@google.com | 9528bdb | 2013-09-18 22:33:57 +0000 | [diff] [blame] | 544 | void GrInOrderDrawBuffer::willReserveVertexAndIndexSpace(int vertexCount, |
| 545 | int indexCount) { |
bsalomon@google.com | 6e4e650 | 2013-02-25 20:12:45 +0000 | [diff] [blame] | 546 | // We use geometryHints() to know whether to flush the draw buffer. We |
| 547 | // can't flush if we are inside an unbalanced pushGeometrySource. |
| 548 | // Moreover, flushing blows away vertex and index data that was |
| 549 | // previously reserved. So if the vertex or index data is pulled from |
| 550 | // reserved space and won't be released by this request then we can't |
| 551 | // flush. |
| 552 | bool insideGeoPush = fGeoPoolStateStack.count() > 1; |
bsalomon@google.com | 9780538 | 2012-03-13 14:32:07 +0000 | [diff] [blame] | 553 | |
bsalomon@google.com | 6e4e650 | 2013-02-25 20:12:45 +0000 | [diff] [blame] | 554 | bool unreleasedVertexSpace = |
| 555 | !vertexCount && |
| 556 | kReserved_GeometrySrcType == this->getGeomSrc().fVertexSrc; |
bsalomon@google.com | 9780538 | 2012-03-13 14:32:07 +0000 | [diff] [blame] | 557 | |
bsalomon@google.com | 6e4e650 | 2013-02-25 20:12:45 +0000 | [diff] [blame] | 558 | bool unreleasedIndexSpace = |
| 559 | !indexCount && |
| 560 | kReserved_GeometrySrcType == this->getGeomSrc().fIndexSrc; |
bsalomon@google.com | 9780538 | 2012-03-13 14:32:07 +0000 | [diff] [blame] | 561 | |
bsalomon@google.com | 6e4e650 | 2013-02-25 20:12:45 +0000 | [diff] [blame] | 562 | // we don't want to finalize any reserved geom on the target since |
| 563 | // we don't know that the client has finished writing to it. |
| 564 | bool targetHasReservedGeom = fDstGpu->hasReservedVerticesOrIndices(); |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 565 | |
bsalomon@google.com | 6e4e650 | 2013-02-25 20:12:45 +0000 | [diff] [blame] | 566 | int vcount = vertexCount; |
| 567 | int icount = indexCount; |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 568 | |
bsalomon@google.com | 6e4e650 | 2013-02-25 20:12:45 +0000 | [diff] [blame] | 569 | if (!insideGeoPush && |
| 570 | !unreleasedVertexSpace && |
| 571 | !unreleasedIndexSpace && |
| 572 | !targetHasReservedGeom && |
| 573 | this->geometryHints(&vcount, &icount)) { |
bsalomon@google.com | 6e4e650 | 2013-02-25 20:12:45 +0000 | [diff] [blame] | 574 | this->flush(); |
bsalomon@google.com | 9780538 | 2012-03-13 14:32:07 +0000 | [diff] [blame] | 575 | } |
| 576 | } |
| 577 | |
jvanverth@google.com | b75b0a0 | 2013-02-05 20:33:30 +0000 | [diff] [blame] | 578 | bool GrInOrderDrawBuffer::geometryHints(int* vertexCount, |
bsalomon@google.com | 1c13c96 | 2011-02-14 16:51:21 +0000 | [diff] [blame] | 579 | int* indexCount) const { |
| 580 | // we will recommend a flush if the data could fit in a single |
| 581 | // preallocated buffer but none are left and it can't fit |
| 582 | // in the current buffer (which may not be prealloced). |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 583 | bool flush = false; |
bsalomon | 49f085d | 2014-09-05 13:34:00 -0700 | [diff] [blame] | 584 | if (indexCount) { |
bsalomon@google.com | 1c13c96 | 2011-02-14 16:51:21 +0000 | [diff] [blame] | 585 | int32_t currIndices = fIndexPool.currentBufferIndices(); |
| 586 | if (*indexCount > currIndices && |
| 587 | (!fIndexPool.preallocatedBuffersRemaining() && |
| 588 | *indexCount <= fIndexPool.preallocatedBufferIndices())) { |
| 589 | |
| 590 | flush = true; |
| 591 | } |
| 592 | *indexCount = currIndices; |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 593 | } |
bsalomon | 49f085d | 2014-09-05 13:34:00 -0700 | [diff] [blame] | 594 | if (vertexCount) { |
egdaniel | 7b3d5ee | 2014-08-28 05:41:14 -0700 | [diff] [blame] | 595 | size_t vertexStride = this->getDrawState().getVertexStride(); |
| 596 | int32_t currVertices = fVertexPool.currentBufferVertices(vertexStride); |
bsalomon@google.com | 1c13c96 | 2011-02-14 16:51:21 +0000 | [diff] [blame] | 597 | if (*vertexCount > currVertices && |
| 598 | (!fVertexPool.preallocatedBuffersRemaining() && |
egdaniel | 7b3d5ee | 2014-08-28 05:41:14 -0700 | [diff] [blame] | 599 | *vertexCount <= fVertexPool.preallocatedBufferVertices(vertexStride))) { |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 600 | |
bsalomon@google.com | 1c13c96 | 2011-02-14 16:51:21 +0000 | [diff] [blame] | 601 | flush = true; |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 602 | } |
bsalomon@google.com | 1c13c96 | 2011-02-14 16:51:21 +0000 | [diff] [blame] | 603 | *vertexCount = currVertices; |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 604 | } |
| 605 | return flush; |
| 606 | } |
| 607 | |
jvanverth@google.com | a633898 | 2013-01-31 21:34:25 +0000 | [diff] [blame] | 608 | bool GrInOrderDrawBuffer::onReserveVertexSpace(size_t vertexSize, |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 609 | int vertexCount, |
| 610 | void** vertices) { |
| 611 | GeometryPoolState& poolState = fGeoPoolStateStack.back(); |
tfarina@chromium.org | f6de475 | 2013-08-17 00:02:59 +0000 | [diff] [blame] | 612 | SkASSERT(vertexCount > 0); |
bsalomon | 49f085d | 2014-09-05 13:34:00 -0700 | [diff] [blame] | 613 | SkASSERT(vertices); |
tfarina@chromium.org | f6de475 | 2013-08-17 00:02:59 +0000 | [diff] [blame] | 614 | SkASSERT(0 == poolState.fUsedPoolVertexBytes); |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 615 | |
jvanverth@google.com | a633898 | 2013-01-31 21:34:25 +0000 | [diff] [blame] | 616 | *vertices = fVertexPool.makeSpace(vertexSize, |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 617 | vertexCount, |
| 618 | &poolState.fPoolVertexBuffer, |
| 619 | &poolState.fPoolStartVertex); |
bsalomon | 49f085d | 2014-09-05 13:34:00 -0700 | [diff] [blame] | 620 | return SkToBool(*vertices); |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 621 | } |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 622 | |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 623 | bool GrInOrderDrawBuffer::onReserveIndexSpace(int indexCount, void** indices) { |
| 624 | GeometryPoolState& poolState = fGeoPoolStateStack.back(); |
tfarina@chromium.org | f6de475 | 2013-08-17 00:02:59 +0000 | [diff] [blame] | 625 | SkASSERT(indexCount > 0); |
bsalomon | 49f085d | 2014-09-05 13:34:00 -0700 | [diff] [blame] | 626 | SkASSERT(indices); |
tfarina@chromium.org | f6de475 | 2013-08-17 00:02:59 +0000 | [diff] [blame] | 627 | SkASSERT(0 == poolState.fUsedPoolIndexBytes); |
bsalomon@google.com | 1c13c96 | 2011-02-14 16:51:21 +0000 | [diff] [blame] | 628 | |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 629 | *indices = fIndexPool.makeSpace(indexCount, |
| 630 | &poolState.fPoolIndexBuffer, |
| 631 | &poolState.fPoolStartIndex); |
bsalomon | 49f085d | 2014-09-05 13:34:00 -0700 | [diff] [blame] | 632 | return SkToBool(*indices); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 633 | } |
| 634 | |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 635 | void GrInOrderDrawBuffer::releaseReservedVertexSpace() { |
| 636 | GeometryPoolState& poolState = fGeoPoolStateStack.back(); |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 637 | const GeometrySrcState& geoSrc = this->getGeomSrc(); |
bsalomon@google.com | d57d71a | 2012-08-16 16:26:33 +0000 | [diff] [blame] | 638 | |
| 639 | // If we get a release vertex space call then our current source should either be reserved |
| 640 | // or array (which we copied into reserved space). |
joshualitt | d1aa8ff | 2014-11-04 07:47:55 -0800 | [diff] [blame] | 641 | SkASSERT(kReserved_GeometrySrcType == geoSrc.fVertexSrc); |
bsalomon@google.com | 3f5a95e | 2012-03-08 16:41:42 +0000 | [diff] [blame] | 642 | |
| 643 | // When the caller reserved vertex buffer space we gave it back a pointer |
| 644 | // provided by the vertex buffer pool. At each draw we tracked the largest |
| 645 | // offset into the pool's pointer that was referenced. Now we return to the |
| 646 | // 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] | 647 | size_t reservedVertexBytes = geoSrc.fVertexSize * geoSrc.fVertexCount; |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 648 | fVertexPool.putBack(reservedVertexBytes - |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 649 | poolState.fUsedPoolVertexBytes); |
| 650 | poolState.fUsedPoolVertexBytes = 0; |
bsalomon@google.com | 3f5a95e | 2012-03-08 16:41:42 +0000 | [diff] [blame] | 651 | poolState.fPoolVertexBuffer = NULL; |
| 652 | poolState.fPoolStartVertex = 0; |
bsalomon@google.com | 1c13c96 | 2011-02-14 16:51:21 +0000 | [diff] [blame] | 653 | } |
| 654 | |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 655 | void GrInOrderDrawBuffer::releaseReservedIndexSpace() { |
| 656 | GeometryPoolState& poolState = fGeoPoolStateStack.back(); |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 657 | const GeometrySrcState& geoSrc = this->getGeomSrc(); |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 658 | |
bsalomon@google.com | d57d71a | 2012-08-16 16:26:33 +0000 | [diff] [blame] | 659 | // If we get a release index space call then our current source should either be reserved |
| 660 | // or array (which we copied into reserved space). |
joshualitt | d1aa8ff | 2014-11-04 07:47:55 -0800 | [diff] [blame] | 661 | SkASSERT(kReserved_GeometrySrcType == geoSrc.fIndexSrc); |
bsalomon@google.com | 3f5a95e | 2012-03-08 16:41:42 +0000 | [diff] [blame] | 662 | |
| 663 | // Similar to releaseReservedVertexSpace we return any unused portion at |
| 664 | // the tail |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 665 | size_t reservedIndexBytes = sizeof(uint16_t) * geoSrc.fIndexCount; |
| 666 | fIndexPool.putBack(reservedIndexBytes - poolState.fUsedPoolIndexBytes); |
| 667 | poolState.fUsedPoolIndexBytes = 0; |
bsalomon@google.com | 3f5a95e | 2012-03-08 16:41:42 +0000 | [diff] [blame] | 668 | poolState.fPoolIndexBuffer = NULL; |
| 669 | poolState.fPoolStartIndex = 0; |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 670 | } |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 671 | |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 672 | void GrInOrderDrawBuffer::geometrySourceWillPush() { |
| 673 | GeometryPoolState& poolState = fGeoPoolStateStack.push_back(); |
| 674 | poolState.fUsedPoolVertexBytes = 0; |
| 675 | poolState.fUsedPoolIndexBytes = 0; |
commit-bot@chromium.org | 515dcd3 | 2013-08-28 14:17:03 +0000 | [diff] [blame] | 676 | #ifdef SK_DEBUG |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 677 | poolState.fPoolVertexBuffer = (GrVertexBuffer*)~0; |
| 678 | poolState.fPoolStartVertex = ~0; |
| 679 | poolState.fPoolIndexBuffer = (GrIndexBuffer*)~0; |
| 680 | poolState.fPoolStartIndex = ~0; |
| 681 | #endif |
| 682 | } |
| 683 | |
bsalomon | b3e3a95 | 2014-09-19 11:10:40 -0700 | [diff] [blame] | 684 | void GrInOrderDrawBuffer::geometrySourceWillPop(const GeometrySrcState& restoredState) { |
tfarina@chromium.org | f6de475 | 2013-08-17 00:02:59 +0000 | [diff] [blame] | 685 | SkASSERT(fGeoPoolStateStack.count() > 1); |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 686 | fGeoPoolStateStack.pop_back(); |
| 687 | GeometryPoolState& poolState = fGeoPoolStateStack.back(); |
| 688 | // we have to assume that any slack we had in our vertex/index data |
| 689 | // is now unreleasable because data may have been appended later in the |
| 690 | // pool. |
joshualitt | d1aa8ff | 2014-11-04 07:47:55 -0800 | [diff] [blame] | 691 | if (kReserved_GeometrySrcType == restoredState.fVertexSrc) { |
jvanverth@google.com | b75b0a0 | 2013-02-05 20:33:30 +0000 | [diff] [blame] | 692 | poolState.fUsedPoolVertexBytes = restoredState.fVertexSize * restoredState.fVertexCount; |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 693 | } |
joshualitt | d1aa8ff | 2014-11-04 07:47:55 -0800 | [diff] [blame] | 694 | if (kReserved_GeometrySrcType == restoredState.fIndexSrc) { |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 695 | poolState.fUsedPoolIndexBytes = sizeof(uint16_t) * |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 696 | restoredState.fIndexCount; |
| 697 | } |
| 698 | } |
| 699 | |
bsalomon | 838f62d | 2014-08-05 07:15:57 -0700 | [diff] [blame] | 700 | void GrInOrderDrawBuffer::recordStateIfNecessary() { |
cdalton | 6819df3 | 2014-10-15 13:43:48 -0700 | [diff] [blame] | 701 | if (!fLastState) { |
| 702 | SetState* ss = GrNEW_APPEND_TO_RECORDER(fCmdBuffer, SetState, (this->getDrawState())); |
| 703 | fLastState = &ss->fState; |
| 704 | this->convertDrawStateToPendingExec(fLastState); |
| 705 | this->recordTraceMarkersIfNecessary(); |
bsalomon | 838f62d | 2014-08-05 07:15:57 -0700 | [diff] [blame] | 706 | return; |
| 707 | } |
| 708 | const GrDrawState& curr = this->getDrawState(); |
cdalton | 6819df3 | 2014-10-15 13:43:48 -0700 | [diff] [blame] | 709 | switch (GrDrawState::CombineIfPossible(*fLastState, curr, *this->caps())) { |
bsalomon | 838f62d | 2014-08-05 07:15:57 -0700 | [diff] [blame] | 710 | case GrDrawState::kIncompatible_CombinedState: |
cdalton | 6819df3 | 2014-10-15 13:43:48 -0700 | [diff] [blame] | 711 | fLastState = &GrNEW_APPEND_TO_RECORDER(fCmdBuffer, SetState, (curr))->fState; |
| 712 | this->convertDrawStateToPendingExec(fLastState); |
| 713 | this->recordTraceMarkersIfNecessary(); |
bsalomon | 838f62d | 2014-08-05 07:15:57 -0700 | [diff] [blame] | 714 | break; |
| 715 | case GrDrawState::kA_CombinedState: |
| 716 | case GrDrawState::kAOrB_CombinedState: // Treat the same as kA. |
| 717 | break; |
| 718 | case GrDrawState::kB_CombinedState: |
bsalomon | 2a9ca78 | 2014-09-05 14:27:43 -0700 | [diff] [blame] | 719 | // 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] | 720 | // So here we just destruct the previous state and reinit with a new copy of curr. |
| 721 | // Note that this goes away when we move GrIODB over to taking optimized snapshots |
| 722 | // of draw states. |
| 723 | fLastState->~GrDrawState(); |
| 724 | SkNEW_PLACEMENT_ARGS(fLastState, GrDrawState, (curr)); |
| 725 | this->convertDrawStateToPendingExec(fLastState); |
bsalomon | 838f62d | 2014-08-05 07:15:57 -0700 | [diff] [blame] | 726 | break; |
| 727 | } |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 728 | } |
| 729 | |
cdalton | 6819df3 | 2014-10-15 13:43:48 -0700 | [diff] [blame] | 730 | void GrInOrderDrawBuffer::recordTraceMarkersIfNecessary() { |
| 731 | SkASSERT(!fCmdBuffer.empty()); |
| 732 | SkASSERT(!cmd_has_trace_marker(fCmdBuffer.back().fType)); |
mtklein | f439c77 | 2014-10-14 14:29:30 -0700 | [diff] [blame] | 733 | const GrTraceMarkerSet& activeTraceMarkers = this->getActiveTraceMarkers(); |
| 734 | if (activeTraceMarkers.count() > 0) { |
cdalton | 6819df3 | 2014-10-15 13:43:48 -0700 | [diff] [blame] | 735 | fCmdBuffer.back().fType = add_trace_bit(fCmdBuffer.back().fType); |
mtklein | f439c77 | 2014-10-14 14:29:30 -0700 | [diff] [blame] | 736 | fGpuCmdMarkers.push_back(activeTraceMarkers); |
mtklein | 07894c4 | 2014-10-13 14:00:42 -0700 | [diff] [blame] | 737 | } |
mtklein | 07894c4 | 2014-10-13 14:00:42 -0700 | [diff] [blame] | 738 | } |