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