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