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) |
bsalomon | 932f866 | 2014-11-24 06:47:48 -0800 | [diff] [blame] | 23 | , fPrevState(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 | 54e0c12 | 2014-11-19 09:38:51 -0800 | [diff] [blame] | 193 | int GrInOrderDrawBuffer::concatInstancedDraw(const GrDrawState& ds, const DrawInfo& info) { |
cdalton | 6819df3 | 2014-10-15 13:43:48 -0700 | [diff] [blame] | 194 | SkASSERT(!fCmdBuffer.empty()); |
tfarina@chromium.org | f6de475 | 2013-08-17 00:02:59 +0000 | [diff] [blame] | 195 | SkASSERT(info.isInstanced()); |
bsalomon@google.com | d62e88e | 2013-02-01 14:19:27 +0000 | [diff] [blame] | 196 | |
bsalomon@google.com | 934c570 | 2012-03-20 21:17:58 +0000 | [diff] [blame] | 197 | const GeometrySrcState& geomSrc = this->getGeomSrc(); |
| 198 | |
bsalomon@google.com | d62e88e | 2013-02-01 14:19:27 +0000 | [diff] [blame] | 199 | // we only attempt to concat the case when reserved verts are used with a client-specified index |
| 200 | // buffer. To make this work with client-specified VBs we'd need to know if the VB was updated |
| 201 | // between draws. |
| 202 | if (kReserved_GeometrySrcType != geomSrc.fVertexSrc || |
| 203 | kBuffer_GeometrySrcType != geomSrc.fIndexSrc) { |
| 204 | return 0; |
bsalomon@google.com | 934c570 | 2012-03-20 21:17:58 +0000 | [diff] [blame] | 205 | } |
bsalomon@google.com | d62e88e | 2013-02-01 14:19:27 +0000 | [diff] [blame] | 206 | // Check if there is a draw info that is compatible that uses the same VB from the pool and |
| 207 | // the same IB |
cdalton | 6819df3 | 2014-10-15 13:43:48 -0700 | [diff] [blame] | 208 | if (kDraw_Cmd != strip_trace_bit(fCmdBuffer.back().fType)) { |
bsalomon@google.com | d62e88e | 2013-02-01 14:19:27 +0000 | [diff] [blame] | 209 | return 0; |
| 210 | } |
| 211 | |
cdalton | 6819df3 | 2014-10-15 13:43:48 -0700 | [diff] [blame] | 212 | Draw* draw = static_cast<Draw*>(&fCmdBuffer.back()); |
bsalomon@google.com | d62e88e | 2013-02-01 14:19:27 +0000 | [diff] [blame] | 213 | GeometryPoolState& poolState = fGeoPoolStateStack.back(); |
| 214 | const GrVertexBuffer* vertexBuffer = poolState.fPoolVertexBuffer; |
| 215 | |
cdalton | 6819df3 | 2014-10-15 13:43:48 -0700 | [diff] [blame] | 216 | if (!draw->fInfo.isInstanced() || |
| 217 | draw->fInfo.verticesPerInstance() != info.verticesPerInstance() || |
| 218 | draw->fInfo.indicesPerInstance() != info.indicesPerInstance() || |
joshualitt | 7eb8c7b | 2014-11-18 14:24:27 -0800 | [diff] [blame] | 219 | draw->fInfo.vertexBuffer() != vertexBuffer || |
joshualitt | 54e0c12 | 2014-11-19 09:38:51 -0800 | [diff] [blame] | 220 | draw->fInfo.indexBuffer() != geomSrc.fIndexBuffer) { |
bsalomon@google.com | d62e88e | 2013-02-01 14:19:27 +0000 | [diff] [blame] | 221 | return 0; |
| 222 | } |
| 223 | // info does not yet account for the offset from the start of the pool's VB while the previous |
| 224 | // draw record does. |
| 225 | int adjustedStartVertex = poolState.fPoolStartVertex + info.startVertex(); |
cdalton | 6819df3 | 2014-10-15 13:43:48 -0700 | [diff] [blame] | 226 | if (draw->fInfo.startVertex() + draw->fInfo.vertexCount() != adjustedStartVertex) { |
bsalomon@google.com | d62e88e | 2013-02-01 14:19:27 +0000 | [diff] [blame] | 227 | return 0; |
| 228 | } |
| 229 | |
cdalton | 6819df3 | 2014-10-15 13:43:48 -0700 | [diff] [blame] | 230 | SkASSERT(poolState.fPoolStartVertex == draw->fInfo.startVertex() + draw->fInfo.vertexCount()); |
bsalomon@google.com | d62e88e | 2013-02-01 14:19:27 +0000 | [diff] [blame] | 231 | |
| 232 | // how many instances can be concat'ed onto draw given the size of the index buffer |
| 233 | int instancesToConcat = this->indexCountInCurrentSource() / info.indicesPerInstance(); |
cdalton | 6819df3 | 2014-10-15 13:43:48 -0700 | [diff] [blame] | 234 | instancesToConcat -= draw->fInfo.instanceCount(); |
commit-bot@chromium.org | 972f9cd | 2014-03-28 17:58:28 +0000 | [diff] [blame] | 235 | instancesToConcat = SkTMin(instancesToConcat, info.instanceCount()); |
bsalomon@google.com | d62e88e | 2013-02-01 14:19:27 +0000 | [diff] [blame] | 236 | |
| 237 | // update the amount of reserved vertex data actually referenced in draws |
joshualitt | 9853cce | 2014-11-17 14:22:48 -0800 | [diff] [blame] | 238 | size_t vertexBytes = instancesToConcat * info.verticesPerInstance() * ds.getVertexStride(); |
commit-bot@chromium.org | 972f9cd | 2014-03-28 17:58:28 +0000 | [diff] [blame] | 239 | poolState.fUsedPoolVertexBytes = SkTMax(poolState.fUsedPoolVertexBytes, vertexBytes); |
bsalomon@google.com | d62e88e | 2013-02-01 14:19:27 +0000 | [diff] [blame] | 240 | |
cdalton | 6819df3 | 2014-10-15 13:43:48 -0700 | [diff] [blame] | 241 | draw->fInfo.adjustInstanceCount(instancesToConcat); |
commit-bot@chromium.org | 2a05de0 | 2014-03-25 15:17:32 +0000 | [diff] [blame] | 242 | |
| 243 | // update last fGpuCmdMarkers to include any additional trace markers that have been added |
| 244 | if (this->getActiveTraceMarkers().count() > 0) { |
cdalton | 6819df3 | 2014-10-15 13:43:48 -0700 | [diff] [blame] | 245 | if (cmd_has_trace_marker(draw->fType)) { |
commit-bot@chromium.org | 2a05de0 | 2014-03-25 15:17:32 +0000 | [diff] [blame] | 246 | fGpuCmdMarkers.back().addSet(this->getActiveTraceMarkers()); |
| 247 | } else { |
| 248 | fGpuCmdMarkers.push_back(this->getActiveTraceMarkers()); |
cdalton | 6819df3 | 2014-10-15 13:43:48 -0700 | [diff] [blame] | 249 | draw->fType = add_trace_bit(draw->fType); |
commit-bot@chromium.org | 2a05de0 | 2014-03-25 15:17:32 +0000 | [diff] [blame] | 250 | } |
| 251 | } |
| 252 | |
bsalomon@google.com | d62e88e | 2013-02-01 14:19:27 +0000 | [diff] [blame] | 253 | return instancesToConcat; |
bsalomon@google.com | 934c570 | 2012-03-20 21:17:58 +0000 | [diff] [blame] | 254 | } |
| 255 | |
joshualitt | 9853cce | 2014-11-17 14:22:48 -0800 | [diff] [blame] | 256 | void GrInOrderDrawBuffer::onDraw(const GrDrawState& ds, |
| 257 | const DrawInfo& info, |
joshualitt | 9176e2c | 2014-11-20 07:28:52 -0800 | [diff] [blame] | 258 | const ScissorState& scissorState, |
| 259 | const GrDeviceCoordTexture* dstCopy) { |
joshualitt | 7eb8c7b | 2014-11-18 14:24:27 -0800 | [diff] [blame] | 260 | SkASSERT(info.vertexBuffer() && (!info.isIndexed() || info.indexBuffer())); |
| 261 | |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 262 | GeometryPoolState& poolState = fGeoPoolStateStack.back(); |
bsalomon@google.com | d62e88e | 2013-02-01 14:19:27 +0000 | [diff] [blame] | 263 | |
bsalomon | ae59b77 | 2014-11-19 08:23:49 -0800 | [diff] [blame] | 264 | if (!this->recordStateAndShouldDraw(ds, GrGpu::PrimTypeToDrawType(info.primitiveType()), |
joshualitt | 9176e2c | 2014-11-20 07:28:52 -0800 | [diff] [blame] | 265 | scissorState, dstCopy)) { |
bsalomon | ae59b77 | 2014-11-19 08:23:49 -0800 | [diff] [blame] | 266 | return; |
| 267 | } |
bsalomon@google.com | 86afc2a | 2011-02-16 16:12:19 +0000 | [diff] [blame] | 268 | |
bsalomon | b3e3a95 | 2014-09-19 11:10:40 -0700 | [diff] [blame] | 269 | Draw* draw; |
bsalomon@google.com | d62e88e | 2013-02-01 14:19:27 +0000 | [diff] [blame] | 270 | if (info.isInstanced()) { |
joshualitt | 54e0c12 | 2014-11-19 09:38:51 -0800 | [diff] [blame] | 271 | int instancesConcated = this->concatInstancedDraw(ds, info); |
bsalomon@google.com | d62e88e | 2013-02-01 14:19:27 +0000 | [diff] [blame] | 272 | if (info.instanceCount() > instancesConcated) { |
joshualitt | 54e0c12 | 2014-11-19 09:38:51 -0800 | [diff] [blame] | 273 | draw = GrNEW_APPEND_TO_RECORDER(fCmdBuffer, Draw, (info)); |
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 | 54e0c12 | 2014-11-19 09:38:51 -0800 | [diff] [blame] | 279 | draw = GrNEW_APPEND_TO_RECORDER(fCmdBuffer, Draw, (info)); |
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) { |
joshualitt | 9853cce | 2014-11-17 14:22:48 -0800 | [diff] [blame] | 286 | size_t bytes = (info.vertexCount() + info.startVertex()) * ds.getVertexStride(); |
bsalomon | b3e3a95 | 2014-09-19 11:10:40 -0700 | [diff] [blame] | 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 | 9853cce | 2014-11-17 14:22:48 -0800 | [diff] [blame] | 298 | void GrInOrderDrawBuffer::onStencilPath(const GrDrawState& ds, |
| 299 | const GrPath* path, |
joshualitt | 2c93efe | 2014-11-06 12:57:13 -0800 | [diff] [blame] | 300 | const GrClipMaskManager::ScissorState& scissorState, |
| 301 | const GrStencilSettings& stencilSettings) { |
bsalomon@google.com | ded4f4b | 2012-06-28 18:48:06 +0000 | [diff] [blame] | 302 | // Only compare the subset of GrDrawState relevant to path stenciling? |
joshualitt | 54e0c12 | 2014-11-19 09:38:51 -0800 | [diff] [blame] | 303 | if (!this->recordStateAndShouldDraw(ds, GrGpu::kStencilPath_DrawType, scissorState, NULL)) { |
bsalomon | ae59b77 | 2014-11-19 08:23:49 -0800 | [diff] [blame] | 304 | return; |
| 305 | } |
cdalton | 6819df3 | 2014-10-15 13:43:48 -0700 | [diff] [blame] | 306 | StencilPath* sp = GrNEW_APPEND_TO_RECORDER(fCmdBuffer, StencilPath, (path)); |
joshualitt | 2c93efe | 2014-11-06 12:57:13 -0800 | [diff] [blame] | 307 | sp->fStencilSettings = stencilSettings; |
cdalton | 6819df3 | 2014-10-15 13:43:48 -0700 | [diff] [blame] | 308 | this->recordTraceMarkersIfNecessary(); |
bsalomon@google.com | 64aef2b | 2012-06-11 15:36:13 +0000 | [diff] [blame] | 309 | } |
| 310 | |
joshualitt | 9853cce | 2014-11-17 14:22:48 -0800 | [diff] [blame] | 311 | void GrInOrderDrawBuffer::onDrawPath(const GrDrawState& ds, |
| 312 | const GrPath* path, |
joshualitt | 2c93efe | 2014-11-06 12:57:13 -0800 | [diff] [blame] | 313 | const GrClipMaskManager::ScissorState& scissorState, |
| 314 | const GrStencilSettings& stencilSettings, |
joshualitt | 92e496f | 2014-10-31 13:56:50 -0700 | [diff] [blame] | 315 | const GrDeviceCoordTexture* dstCopy) { |
commit-bot@chromium.org | c4dc0ad | 2013-10-09 14:11:33 +0000 | [diff] [blame] | 316 | // TODO: Only compare the subset of GrDrawState relevant to path covering? |
joshualitt | 54e0c12 | 2014-11-19 09:38:51 -0800 | [diff] [blame] | 317 | if (!this->recordStateAndShouldDraw(ds, GrGpu::kDrawPath_DrawType, scissorState, dstCopy)) { |
bsalomon | ae59b77 | 2014-11-19 08:23:49 -0800 | [diff] [blame] | 318 | return; |
| 319 | } |
cdalton | 6819df3 | 2014-10-15 13:43:48 -0700 | [diff] [blame] | 320 | DrawPath* dp = GrNEW_APPEND_TO_RECORDER(fCmdBuffer, DrawPath, (path)); |
joshualitt | 2c93efe | 2014-11-06 12:57:13 -0800 | [diff] [blame] | 321 | dp->fStencilSettings = stencilSettings; |
cdalton | 6819df3 | 2014-10-15 13:43:48 -0700 | [diff] [blame] | 322 | this->recordTraceMarkersIfNecessary(); |
commit-bot@chromium.org | c4dc0ad | 2013-10-09 14:11:33 +0000 | [diff] [blame] | 323 | } |
| 324 | |
joshualitt | 9853cce | 2014-11-17 14:22:48 -0800 | [diff] [blame] | 325 | void GrInOrderDrawBuffer::onDrawPaths(const GrDrawState& ds, |
| 326 | const GrPathRange* pathRange, |
cdalton | 55b24af | 2014-11-25 11:00:56 -0800 | [diff] [blame] | 327 | const void* indices, |
| 328 | PathIndexType indexType, |
| 329 | const float transformValues[], |
| 330 | PathTransformType transformType, |
joshualitt | 2c93efe | 2014-11-06 12:57:13 -0800 | [diff] [blame] | 331 | int count, |
joshualitt | 2c93efe | 2014-11-06 12:57:13 -0800 | [diff] [blame] | 332 | const GrClipMaskManager::ScissorState& scissorState, |
| 333 | const GrStencilSettings& stencilSettings, |
joshualitt | 92e496f | 2014-10-31 13:56:50 -0700 | [diff] [blame] | 334 | const GrDeviceCoordTexture* dstCopy) { |
bsalomon | 49f085d | 2014-09-05 13:34:00 -0700 | [diff] [blame] | 335 | SkASSERT(pathRange); |
| 336 | SkASSERT(indices); |
cdalton | 55b24af | 2014-11-25 11:00:56 -0800 | [diff] [blame] | 337 | SkASSERT(transformValues); |
commit-bot@chromium.org | 9b62aa1 | 2014-03-25 11:59:40 +0000 | [diff] [blame] | 338 | |
joshualitt | 54e0c12 | 2014-11-19 09:38:51 -0800 | [diff] [blame] | 339 | if (!this->recordStateAndShouldDraw(ds, GrGpu::kDrawPath_DrawType, scissorState, dstCopy)) { |
bsalomon | ae59b77 | 2014-11-19 08:23:49 -0800 | [diff] [blame] | 340 | return; |
| 341 | } |
cdalton | 6819df3 | 2014-10-15 13:43:48 -0700 | [diff] [blame] | 342 | |
cdalton | 55b24af | 2014-11-25 11:00:56 -0800 | [diff] [blame] | 343 | int indexBytes = GrPathRange::PathIndexSizeInBytes(indexType); |
| 344 | if (int misalign = fPathIndexBuffer.count() % indexBytes) { |
| 345 | // Add padding to the index buffer so the indices are aligned properly. |
| 346 | fPathIndexBuffer.append(indexBytes - misalign); |
| 347 | } |
| 348 | |
| 349 | char* savedIndices = fPathIndexBuffer.append(count * indexBytes, |
| 350 | reinterpret_cast<const char*>(indices)); |
| 351 | float* savedTransforms = fPathTransformBuffer.append( |
| 352 | count * GrPathRendering::PathTransformSize(transformType), |
| 353 | transformValues); |
cdalton | 6819df3 | 2014-10-15 13:43:48 -0700 | [diff] [blame] | 354 | |
cdalton | 3fc6a2f | 2014-11-13 11:54:20 -0800 | [diff] [blame] | 355 | if (kDrawPaths_Cmd == strip_trace_bit(fCmdBuffer.back().fType)) { |
| 356 | // The previous command was also DrawPaths. Try to collapse this call into the one |
| 357 | // before. Note that stencilling all the paths at once, then covering, may not be |
| 358 | // equivalent to two separate draw calls if there is overlap. Blending won't work, |
| 359 | // and the combined calls may also cancel each other's winding numbers in some |
| 360 | // places. For now the winding numbers are only an issue if the fill is even/odd, |
| 361 | // because DrawPaths is currently only used for glyphs, and glyphs in the same |
| 362 | // font tend to all wind in the same direction. |
| 363 | DrawPaths* previous = static_cast<DrawPaths*>(&fCmdBuffer.back()); |
| 364 | if (pathRange == previous->pathRange() && |
cdalton | 55b24af | 2014-11-25 11:00:56 -0800 | [diff] [blame] | 365 | indexType == previous->fIndexType && |
| 366 | transformType == previous->fTransformType && |
cdalton | 3fc6a2f | 2014-11-13 11:54:20 -0800 | [diff] [blame] | 367 | stencilSettings == previous->fStencilSettings && |
| 368 | path_fill_type_is_winding(stencilSettings) && |
joshualitt | 9853cce | 2014-11-17 14:22:48 -0800 | [diff] [blame] | 369 | !ds.willBlendWithDst()) { |
cdalton | 3fc6a2f | 2014-11-13 11:54:20 -0800 | [diff] [blame] | 370 | // Fold this DrawPaths call into the one previous. |
| 371 | previous->fCount += count; |
| 372 | return; |
| 373 | } |
| 374 | } |
| 375 | |
| 376 | DrawPaths* dp = GrNEW_APPEND_TO_RECORDER(fCmdBuffer, DrawPaths, (pathRange)); |
| 377 | dp->fIndicesLocation = savedIndices - fPathIndexBuffer.begin(); |
cdalton | 55b24af | 2014-11-25 11:00:56 -0800 | [diff] [blame] | 378 | dp->fIndexType = indexType; |
cdalton | 3fc6a2f | 2014-11-13 11:54:20 -0800 | [diff] [blame] | 379 | dp->fTransformsLocation = savedTransforms - fPathTransformBuffer.begin(); |
cdalton | 55b24af | 2014-11-25 11:00:56 -0800 | [diff] [blame] | 380 | dp->fTransformType = transformType; |
| 381 | dp->fCount = count; |
joshualitt | 2c93efe | 2014-11-06 12:57:13 -0800 | [diff] [blame] | 382 | dp->fStencilSettings = stencilSettings; |
cdalton | 6819df3 | 2014-10-15 13:43:48 -0700 | [diff] [blame] | 383 | |
| 384 | this->recordTraceMarkersIfNecessary(); |
commit-bot@chromium.org | 9b62aa1 | 2014-03-25 11:59:40 +0000 | [diff] [blame] | 385 | } |
| 386 | |
bsalomon | 63b2196 | 2014-11-05 07:05:34 -0800 | [diff] [blame] | 387 | void GrInOrderDrawBuffer::onClear(const SkIRect* rect, GrColor color, |
| 388 | bool canIgnoreRect, GrRenderTarget* renderTarget) { |
joshualitt | 9853cce | 2014-11-17 14:22:48 -0800 | [diff] [blame] | 389 | SkASSERT(renderTarget); |
commit-bot@chromium.org | fd03d4a | 2013-07-17 21:39:42 +0000 | [diff] [blame] | 390 | SkIRect r; |
bsalomon@google.com | 6aa25c3 | 2011-04-27 19:55:29 +0000 | [diff] [blame] | 391 | if (NULL == rect) { |
| 392 | // We could do something smart and remove previous draws and clears to |
| 393 | // the current render target. If we get that smart we have to make sure |
| 394 | // those draws aren't read before this clear (render-to-texture). |
bsalomon@google.com | 1b3ce47 | 2012-08-17 13:43:08 +0000 | [diff] [blame] | 395 | r.setLTRB(0, 0, renderTarget->width(), renderTarget->height()); |
bsalomon@google.com | 6aa25c3 | 2011-04-27 19:55:29 +0000 | [diff] [blame] | 396 | rect = &r; |
| 397 | } |
cdalton | 6819df3 | 2014-10-15 13:43:48 -0700 | [diff] [blame] | 398 | Clear* clr = GrNEW_APPEND_TO_RECORDER(fCmdBuffer, Clear, (renderTarget)); |
commit-bot@chromium.org | 28361fa | 2014-03-28 16:08:05 +0000 | [diff] [blame] | 399 | GrColorIsPMAssert(color); |
bsalomon@google.com | a4f6b10 | 2012-06-26 21:04:22 +0000 | [diff] [blame] | 400 | clr->fColor = color; |
| 401 | clr->fRect = *rect; |
robertphillips@google.com | 56ce48a | 2013-10-31 21:44:25 +0000 | [diff] [blame] | 402 | clr->fCanIgnoreRect = canIgnoreRect; |
cdalton | 6819df3 | 2014-10-15 13:43:48 -0700 | [diff] [blame] | 403 | this->recordTraceMarkersIfNecessary(); |
bsalomon@google.com | 0b335c1 | 2011-04-25 19:17:44 +0000 | [diff] [blame] | 404 | } |
| 405 | |
joshualitt | 6db519c | 2014-10-29 08:48:18 -0700 | [diff] [blame] | 406 | void GrInOrderDrawBuffer::clearStencilClip(const SkIRect& rect, |
| 407 | bool insideClip, |
| 408 | GrRenderTarget* renderTarget) { |
joshualitt | 9853cce | 2014-11-17 14:22:48 -0800 | [diff] [blame] | 409 | SkASSERT(renderTarget); |
joshualitt | 6db519c | 2014-10-29 08:48:18 -0700 | [diff] [blame] | 410 | ClearStencilClip* clr = GrNEW_APPEND_TO_RECORDER(fCmdBuffer, ClearStencilClip, (renderTarget)); |
| 411 | clr->fRect = rect; |
| 412 | clr->fInsideClip = insideClip; |
| 413 | this->recordTraceMarkersIfNecessary(); |
| 414 | } |
| 415 | |
commit-bot@chromium.org | 28361fa | 2014-03-28 16:08:05 +0000 | [diff] [blame] | 416 | void GrInOrderDrawBuffer::discard(GrRenderTarget* renderTarget) { |
bsalomon | 89c6298 | 2014-11-03 12:08:42 -0800 | [diff] [blame] | 417 | SkASSERT(renderTarget); |
commit-bot@chromium.org | 28361fa | 2014-03-28 16:08:05 +0000 | [diff] [blame] | 418 | if (!this->caps()->discardRenderTargetSupport()) { |
| 419 | return; |
| 420 | } |
cdalton | 6819df3 | 2014-10-15 13:43:48 -0700 | [diff] [blame] | 421 | Clear* clr = GrNEW_APPEND_TO_RECORDER(fCmdBuffer, Clear, (renderTarget)); |
commit-bot@chromium.org | 28361fa | 2014-03-28 16:08:05 +0000 | [diff] [blame] | 422 | clr->fColor = GrColor_ILLEGAL; |
cdalton | 6819df3 | 2014-10-15 13:43:48 -0700 | [diff] [blame] | 423 | this->recordTraceMarkersIfNecessary(); |
commit-bot@chromium.org | 28361fa | 2014-03-28 16:08:05 +0000 | [diff] [blame] | 424 | } |
| 425 | |
joshualitt | 7eb8c7b | 2014-11-18 14:24:27 -0800 | [diff] [blame] | 426 | void GrInOrderDrawBuffer::setDrawBuffers(DrawInfo* info) { |
| 427 | GeometryPoolState& poolState = fGeoPoolStateStack.back(); |
| 428 | if (kBuffer_GeometrySrcType == this->getGeomSrc().fVertexSrc) { |
| 429 | info->setVertexBuffer(this->getGeomSrc().fVertexBuffer); |
| 430 | } else { |
| 431 | info->setVertexBuffer(poolState.fPoolVertexBuffer); |
| 432 | } |
| 433 | |
| 434 | if (info->isIndexed()) { |
| 435 | if (kBuffer_GeometrySrcType == this->getGeomSrc().fIndexSrc) { |
| 436 | info->setIndexBuffer(this->getGeomSrc().fIndexBuffer); |
| 437 | } else { |
| 438 | info->setIndexBuffer(poolState.fPoolIndexBuffer); |
| 439 | } |
| 440 | } |
| 441 | } |
| 442 | |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 443 | void GrInOrderDrawBuffer::reset() { |
tfarina@chromium.org | f6de475 | 2013-08-17 00:02:59 +0000 | [diff] [blame] | 444 | SkASSERT(1 == fGeoPoolStateStack.count()); |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 445 | this->resetVertexSource(); |
| 446 | this->resetIndexSource(); |
cdalton | 6819df3 | 2014-10-15 13:43:48 -0700 | [diff] [blame] | 447 | |
| 448 | fCmdBuffer.reset(); |
bsalomon | 932f866 | 2014-11-24 06:47:48 -0800 | [diff] [blame] | 449 | fPrevState = NULL; |
bsalomon@google.com | 1c13c96 | 2011-02-14 16:51:21 +0000 | [diff] [blame] | 450 | fVertexPool.reset(); |
| 451 | fIndexPool.reset(); |
cdalton | 3fc6a2f | 2014-11-13 11:54:20 -0800 | [diff] [blame] | 452 | reset_data_buffer(&fPathIndexBuffer, kPathIdxBufferMinReserve); |
| 453 | reset_data_buffer(&fPathTransformBuffer, kPathXformBufferMinReserve); |
commit-bot@chromium.org | 2a05de0 | 2014-03-25 15:17:32 +0000 | [diff] [blame] | 454 | fGpuCmdMarkers.reset(); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 455 | } |
| 456 | |
robertphillips@google.com | 1267fbd | 2013-07-03 18:37:27 +0000 | [diff] [blame] | 457 | void GrInOrderDrawBuffer::flush() { |
| 458 | if (fFlushing) { |
| 459 | return; |
| 460 | } |
| 461 | |
jvanverth | 8e80d17 | 2014-06-19 12:01:10 -0700 | [diff] [blame] | 462 | this->getContext()->getFontCache()->updateTextures(); |
| 463 | |
tfarina@chromium.org | f6de475 | 2013-08-17 00:02:59 +0000 | [diff] [blame] | 464 | SkASSERT(kReserved_GeometrySrcType != this->getGeomSrc().fVertexSrc); |
| 465 | SkASSERT(kReserved_GeometrySrcType != this->getGeomSrc().fIndexSrc); |
bsalomon@google.com | 3f5a95e | 2012-03-08 16:41:42 +0000 | [diff] [blame] | 466 | |
cdalton | 6819df3 | 2014-10-15 13:43:48 -0700 | [diff] [blame] | 467 | if (fCmdBuffer.empty()) { |
robertphillips@google.com | 1267fbd | 2013-07-03 18:37:27 +0000 | [diff] [blame] | 468 | return; |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 469 | } |
bsalomon@google.com | 6e4e650 | 2013-02-25 20:12:45 +0000 | [diff] [blame] | 470 | |
| 471 | GrAutoTRestore<bool> flushRestore(&fFlushing); |
| 472 | fFlushing = true; |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 473 | |
commit-bot@chromium.org | 8341eb7 | 2014-05-07 20:51:05 +0000 | [diff] [blame] | 474 | fVertexPool.unmap(); |
| 475 | fIndexPool.unmap(); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 476 | |
cdalton | 6819df3 | 2014-10-15 13:43:48 -0700 | [diff] [blame] | 477 | CmdBuffer::Iter iter(fCmdBuffer); |
robertphillips@google.com | beb1af7 | 2012-07-26 18:52:16 +0000 | [diff] [blame] | 478 | |
cdalton | 6819df3 | 2014-10-15 13:43:48 -0700 | [diff] [blame] | 479 | int currCmdMarker = 0; |
egdaniel | 3eee383 | 2014-06-18 13:09:11 -0700 | [diff] [blame] | 480 | fDstGpu->saveActiveTraceMarkers(); |
cdalton | 6819df3 | 2014-10-15 13:43:48 -0700 | [diff] [blame] | 481 | |
bsalomon | ae59b77 | 2014-11-19 08:23:49 -0800 | [diff] [blame] | 482 | // Updated every time we find a set state cmd to reflect the current state in the playback |
| 483 | // stream. |
bsalomon | 932f866 | 2014-11-24 06:47:48 -0800 | [diff] [blame] | 484 | const GrOptDrawState* currentOptState = NULL; |
joshualitt | d53a827 | 2014-11-10 16:03:14 -0800 | [diff] [blame] | 485 | |
cdalton | 6819df3 | 2014-10-15 13:43:48 -0700 | [diff] [blame] | 486 | while (iter.next()) { |
commit-bot@chromium.org | 2a05de0 | 2014-03-25 15:17:32 +0000 | [diff] [blame] | 487 | GrGpuTraceMarker newMarker("", -1); |
egdaniel | d78a168 | 2014-07-09 10:41:26 -0700 | [diff] [blame] | 488 | SkString traceString; |
cdalton | 6819df3 | 2014-10-15 13:43:48 -0700 | [diff] [blame] | 489 | if (cmd_has_trace_marker(iter->fType)) { |
egdaniel | d78a168 | 2014-07-09 10:41:26 -0700 | [diff] [blame] | 490 | traceString = fGpuCmdMarkers[currCmdMarker].toString(); |
commit-bot@chromium.org | 2a05de0 | 2014-03-25 15:17:32 +0000 | [diff] [blame] | 491 | newMarker.fMarker = traceString.c_str(); |
| 492 | fDstGpu->addGpuTraceMarker(&newMarker); |
| 493 | ++currCmdMarker; |
| 494 | } |
cdalton | 6819df3 | 2014-10-15 13:43:48 -0700 | [diff] [blame] | 495 | |
joshualitt | d53a827 | 2014-11-10 16:03:14 -0800 | [diff] [blame] | 496 | if (kSetState_Cmd == strip_trace_bit(iter->fType)) { |
joshualitt | 9853cce | 2014-11-17 14:22:48 -0800 | [diff] [blame] | 497 | SetState* ss = reinterpret_cast<SetState*>(iter.get()); |
bsalomon | 932f866 | 2014-11-24 06:47:48 -0800 | [diff] [blame] | 498 | currentOptState = &ss->fState; |
joshualitt | d53a827 | 2014-11-10 16:03:14 -0800 | [diff] [blame] | 499 | } else { |
bsalomon | 932f866 | 2014-11-24 06:47:48 -0800 | [diff] [blame] | 500 | iter->execute(this, currentOptState); |
joshualitt | d53a827 | 2014-11-10 16:03:14 -0800 | [diff] [blame] | 501 | } |
cdalton | 6819df3 | 2014-10-15 13:43:48 -0700 | [diff] [blame] | 502 | |
| 503 | if (cmd_has_trace_marker(iter->fType)) { |
commit-bot@chromium.org | 2a05de0 | 2014-03-25 15:17:32 +0000 | [diff] [blame] | 504 | fDstGpu->removeGpuTraceMarker(&newMarker); |
| 505 | } |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 506 | } |
mtklein | f439c77 | 2014-10-14 14:29:30 -0700 | [diff] [blame] | 507 | |
cdalton | 6819df3 | 2014-10-15 13:43:48 -0700 | [diff] [blame] | 508 | fDstGpu->restoreActiveTraceMarkers(); |
commit-bot@chromium.org | 2a05de0 | 2014-03-25 15:17:32 +0000 | [diff] [blame] | 509 | SkASSERT(fGpuCmdMarkers.count() == currCmdMarker); |
bsalomon@google.com | a4f6b10 | 2012-06-26 21:04:22 +0000 | [diff] [blame] | 510 | |
bsalomon@google.com | 55e4a20 | 2013-01-11 13:54:21 +0000 | [diff] [blame] | 511 | this->reset(); |
commit-bot@chromium.org | a8916ff | 2013-08-16 15:53:46 +0000 | [diff] [blame] | 512 | ++fDrawID; |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 513 | } |
| 514 | |
cdalton | 3fc6a2f | 2014-11-13 11:54:20 -0800 | [diff] [blame] | 515 | void GrInOrderDrawBuffer::Draw::execute(GrInOrderDrawBuffer* buf, const GrOptDrawState* optState) { |
bsalomon | 932f866 | 2014-11-24 06:47:48 -0800 | [diff] [blame] | 516 | SkASSERT(optState); |
joshualitt | 54e0c12 | 2014-11-19 09:38:51 -0800 | [diff] [blame] | 517 | buf->fDstGpu->draw(*optState, fInfo); |
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) { |
bsalomon | 932f866 | 2014-11-24 06:47:48 -0800 | [diff] [blame] | 522 | SkASSERT(optState); |
joshualitt | 54e0c12 | 2014-11-19 09:38:51 -0800 | [diff] [blame] | 523 | buf->fDstGpu->stencilPath(*optState, this->path(), fStencilSettings); |
cdalton | 6819df3 | 2014-10-15 13:43:48 -0700 | [diff] [blame] | 524 | } |
| 525 | |
cdalton | 3fc6a2f | 2014-11-13 11:54:20 -0800 | [diff] [blame] | 526 | void GrInOrderDrawBuffer::DrawPath::execute(GrInOrderDrawBuffer* buf, |
| 527 | const GrOptDrawState* optState) { |
bsalomon | 932f866 | 2014-11-24 06:47:48 -0800 | [diff] [blame] | 528 | SkASSERT(optState); |
joshualitt | 9176e2c | 2014-11-20 07:28:52 -0800 | [diff] [blame] | 529 | buf->fDstGpu->drawPath(*optState, this->path(), fStencilSettings); |
cdalton | 6819df3 | 2014-10-15 13:43:48 -0700 | [diff] [blame] | 530 | } |
| 531 | |
cdalton | 3fc6a2f | 2014-11-13 11:54:20 -0800 | [diff] [blame] | 532 | void GrInOrderDrawBuffer::DrawPaths::execute(GrInOrderDrawBuffer* buf, |
| 533 | const GrOptDrawState* optState) { |
bsalomon | 932f866 | 2014-11-24 06:47:48 -0800 | [diff] [blame] | 534 | SkASSERT(optState); |
cdalton | 3fc6a2f | 2014-11-13 11:54:20 -0800 | [diff] [blame] | 535 | buf->fDstGpu->drawPaths(*optState, this->pathRange(), |
cdalton | 55b24af | 2014-11-25 11:00:56 -0800 | [diff] [blame] | 536 | &buf->fPathIndexBuffer[fIndicesLocation], fIndexType, |
| 537 | &buf->fPathTransformBuffer[fTransformsLocation], fTransformType, |
| 538 | fCount, fStencilSettings); |
cdalton | 6819df3 | 2014-10-15 13:43:48 -0700 | [diff] [blame] | 539 | } |
| 540 | |
bsalomon | 932f866 | 2014-11-24 06:47:48 -0800 | [diff] [blame] | 541 | void GrInOrderDrawBuffer::SetState::execute(GrInOrderDrawBuffer*, const GrOptDrawState*) {} |
cdalton | 6819df3 | 2014-10-15 13:43:48 -0700 | [diff] [blame] | 542 | |
cdalton | 3fc6a2f | 2014-11-13 11:54:20 -0800 | [diff] [blame] | 543 | void GrInOrderDrawBuffer::Clear::execute(GrInOrderDrawBuffer* buf, const GrOptDrawState*) { |
cdalton | 6819df3 | 2014-10-15 13:43:48 -0700 | [diff] [blame] | 544 | if (GrColor_ILLEGAL == fColor) { |
cdalton | 3fc6a2f | 2014-11-13 11:54:20 -0800 | [diff] [blame] | 545 | buf->fDstGpu->discard(this->renderTarget()); |
cdalton | 6819df3 | 2014-10-15 13:43:48 -0700 | [diff] [blame] | 546 | } else { |
cdalton | 3fc6a2f | 2014-11-13 11:54:20 -0800 | [diff] [blame] | 547 | buf->fDstGpu->clear(&fRect, fColor, fCanIgnoreRect, this->renderTarget()); |
cdalton | 6819df3 | 2014-10-15 13:43:48 -0700 | [diff] [blame] | 548 | } |
| 549 | } |
| 550 | |
cdalton | 3fc6a2f | 2014-11-13 11:54:20 -0800 | [diff] [blame] | 551 | void GrInOrderDrawBuffer::ClearStencilClip::execute(GrInOrderDrawBuffer* buf, |
| 552 | const GrOptDrawState*) { |
| 553 | buf->fDstGpu->clearStencilClip(fRect, fInsideClip, this->renderTarget()); |
joshualitt | 6db519c | 2014-10-29 08:48:18 -0700 | [diff] [blame] | 554 | } |
| 555 | |
cdalton | 3fc6a2f | 2014-11-13 11:54:20 -0800 | [diff] [blame] | 556 | void GrInOrderDrawBuffer::CopySurface::execute(GrInOrderDrawBuffer* buf, const GrOptDrawState*) { |
| 557 | buf->fDstGpu->copySurface(this->dst(), this->src(), fSrcRect, fDstPoint); |
cdalton | 6819df3 | 2014-10-15 13:43:48 -0700 | [diff] [blame] | 558 | } |
| 559 | |
bsalomon | f90a02b | 2014-11-26 12:28:00 -0800 | [diff] [blame] | 560 | bool GrInOrderDrawBuffer::onCopySurface(GrSurface* dst, |
| 561 | GrSurface* src, |
| 562 | const SkIRect& srcRect, |
| 563 | const SkIPoint& dstPoint) { |
bsalomon@google.com | 116ad84 | 2013-04-09 15:38:19 +0000 | [diff] [blame] | 564 | if (fDstGpu->canCopySurface(dst, src, srcRect, dstPoint)) { |
cdalton | 6819df3 | 2014-10-15 13:43:48 -0700 | [diff] [blame] | 565 | CopySurface* cs = GrNEW_APPEND_TO_RECORDER(fCmdBuffer, CopySurface, (dst, src)); |
bsalomon@google.com | 116ad84 | 2013-04-09 15:38:19 +0000 | [diff] [blame] | 566 | cs->fSrcRect = srcRect; |
| 567 | cs->fDstPoint = dstPoint; |
cdalton | 6819df3 | 2014-10-15 13:43:48 -0700 | [diff] [blame] | 568 | this->recordTraceMarkersIfNecessary(); |
bsalomon@google.com | 116ad84 | 2013-04-09 15:38:19 +0000 | [diff] [blame] | 569 | return true; |
bsalomon@google.com | 116ad84 | 2013-04-09 15:38:19 +0000 | [diff] [blame] | 570 | } |
bsalomon | f90a02b | 2014-11-26 12:28:00 -0800 | [diff] [blame] | 571 | return false; |
bsalomon@google.com | 116ad84 | 2013-04-09 15:38:19 +0000 | [diff] [blame] | 572 | } |
| 573 | |
bsalomon | f90a02b | 2014-11-26 12:28:00 -0800 | [diff] [blame] | 574 | bool GrInOrderDrawBuffer::onCanCopySurface(const GrSurface* dst, |
joshualitt | 9853cce | 2014-11-17 14:22:48 -0800 | [diff] [blame] | 575 | const GrSurface* src, |
joshualitt | a702415 | 2014-11-03 14:16:35 -0800 | [diff] [blame] | 576 | const SkIRect& srcRect, |
| 577 | const SkIPoint& dstPoint) { |
bsalomon | f90a02b | 2014-11-26 12:28:00 -0800 | [diff] [blame] | 578 | return fDstGpu->canCopySurface(dst, src, srcRect, dstPoint); |
bsalomon@google.com | 116ad84 | 2013-04-09 15:38:19 +0000 | [diff] [blame] | 579 | } |
| 580 | |
bsalomon | f90a02b | 2014-11-26 12:28:00 -0800 | [diff] [blame] | 581 | bool GrInOrderDrawBuffer::onInitCopySurfaceDstDesc(const GrSurface* src, GrSurfaceDesc* desc) { |
| 582 | return fDstGpu->initCopySurfaceDstDesc(src, desc); |
bsalomon@google.com | eb85117 | 2013-04-15 13:51:00 +0000 | [diff] [blame] | 583 | } |
| 584 | |
robertphillips@google.com | 9528bdb | 2013-09-18 22:33:57 +0000 | [diff] [blame] | 585 | void GrInOrderDrawBuffer::willReserveVertexAndIndexSpace(int vertexCount, |
joshualitt | 9853cce | 2014-11-17 14:22:48 -0800 | [diff] [blame] | 586 | size_t vertexStride, |
robertphillips@google.com | 9528bdb | 2013-09-18 22:33:57 +0000 | [diff] [blame] | 587 | int indexCount) { |
bsalomon@google.com | 6e4e650 | 2013-02-25 20:12:45 +0000 | [diff] [blame] | 588 | // We use geometryHints() to know whether to flush the draw buffer. We |
| 589 | // can't flush if we are inside an unbalanced pushGeometrySource. |
| 590 | // Moreover, flushing blows away vertex and index data that was |
| 591 | // previously reserved. So if the vertex or index data is pulled from |
| 592 | // reserved space and won't be released by this request then we can't |
| 593 | // flush. |
| 594 | bool insideGeoPush = fGeoPoolStateStack.count() > 1; |
bsalomon@google.com | 9780538 | 2012-03-13 14:32:07 +0000 | [diff] [blame] | 595 | |
bsalomon@google.com | 6e4e650 | 2013-02-25 20:12:45 +0000 | [diff] [blame] | 596 | bool unreleasedVertexSpace = |
| 597 | !vertexCount && |
| 598 | kReserved_GeometrySrcType == this->getGeomSrc().fVertexSrc; |
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 unreleasedIndexSpace = |
| 601 | !indexCount && |
| 602 | kReserved_GeometrySrcType == this->getGeomSrc().fIndexSrc; |
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 | int vcount = vertexCount; |
| 605 | int icount = indexCount; |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 606 | |
bsalomon@google.com | 6e4e650 | 2013-02-25 20:12:45 +0000 | [diff] [blame] | 607 | if (!insideGeoPush && |
| 608 | !unreleasedVertexSpace && |
| 609 | !unreleasedIndexSpace && |
joshualitt | 9853cce | 2014-11-17 14:22:48 -0800 | [diff] [blame] | 610 | this->geometryHints(vertexStride, &vcount, &icount)) { |
bsalomon@google.com | 6e4e650 | 2013-02-25 20:12:45 +0000 | [diff] [blame] | 611 | this->flush(); |
bsalomon@google.com | 9780538 | 2012-03-13 14:32:07 +0000 | [diff] [blame] | 612 | } |
| 613 | } |
| 614 | |
joshualitt | 9853cce | 2014-11-17 14:22:48 -0800 | [diff] [blame] | 615 | bool GrInOrderDrawBuffer::geometryHints(size_t vertexStride, |
| 616 | int* vertexCount, |
bsalomon@google.com | 1c13c96 | 2011-02-14 16:51:21 +0000 | [diff] [blame] | 617 | int* indexCount) const { |
| 618 | // we will recommend a flush if the data could fit in a single |
| 619 | // preallocated buffer but none are left and it can't fit |
| 620 | // in the current buffer (which may not be prealloced). |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 621 | bool flush = false; |
bsalomon | 49f085d | 2014-09-05 13:34:00 -0700 | [diff] [blame] | 622 | if (indexCount) { |
bsalomon@google.com | 1c13c96 | 2011-02-14 16:51:21 +0000 | [diff] [blame] | 623 | int32_t currIndices = fIndexPool.currentBufferIndices(); |
| 624 | if (*indexCount > currIndices && |
| 625 | (!fIndexPool.preallocatedBuffersRemaining() && |
| 626 | *indexCount <= fIndexPool.preallocatedBufferIndices())) { |
| 627 | |
| 628 | flush = true; |
| 629 | } |
| 630 | *indexCount = currIndices; |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 631 | } |
bsalomon | 49f085d | 2014-09-05 13:34:00 -0700 | [diff] [blame] | 632 | if (vertexCount) { |
egdaniel | 7b3d5ee | 2014-08-28 05:41:14 -0700 | [diff] [blame] | 633 | int32_t currVertices = fVertexPool.currentBufferVertices(vertexStride); |
bsalomon@google.com | 1c13c96 | 2011-02-14 16:51:21 +0000 | [diff] [blame] | 634 | if (*vertexCount > currVertices && |
| 635 | (!fVertexPool.preallocatedBuffersRemaining() && |
egdaniel | 7b3d5ee | 2014-08-28 05:41:14 -0700 | [diff] [blame] | 636 | *vertexCount <= fVertexPool.preallocatedBufferVertices(vertexStride))) { |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 637 | |
bsalomon@google.com | 1c13c96 | 2011-02-14 16:51:21 +0000 | [diff] [blame] | 638 | flush = true; |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 639 | } |
bsalomon@google.com | 1c13c96 | 2011-02-14 16:51:21 +0000 | [diff] [blame] | 640 | *vertexCount = currVertices; |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 641 | } |
| 642 | return flush; |
| 643 | } |
| 644 | |
jvanverth@google.com | a633898 | 2013-01-31 21:34:25 +0000 | [diff] [blame] | 645 | bool GrInOrderDrawBuffer::onReserveVertexSpace(size_t vertexSize, |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 646 | int vertexCount, |
| 647 | void** vertices) { |
| 648 | GeometryPoolState& poolState = fGeoPoolStateStack.back(); |
tfarina@chromium.org | f6de475 | 2013-08-17 00:02:59 +0000 | [diff] [blame] | 649 | SkASSERT(vertexCount > 0); |
bsalomon | 49f085d | 2014-09-05 13:34:00 -0700 | [diff] [blame] | 650 | SkASSERT(vertices); |
tfarina@chromium.org | f6de475 | 2013-08-17 00:02:59 +0000 | [diff] [blame] | 651 | SkASSERT(0 == poolState.fUsedPoolVertexBytes); |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 652 | |
jvanverth@google.com | a633898 | 2013-01-31 21:34:25 +0000 | [diff] [blame] | 653 | *vertices = fVertexPool.makeSpace(vertexSize, |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 654 | vertexCount, |
| 655 | &poolState.fPoolVertexBuffer, |
| 656 | &poolState.fPoolStartVertex); |
bsalomon | 49f085d | 2014-09-05 13:34:00 -0700 | [diff] [blame] | 657 | return SkToBool(*vertices); |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 658 | } |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 659 | |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 660 | bool GrInOrderDrawBuffer::onReserveIndexSpace(int indexCount, void** indices) { |
| 661 | GeometryPoolState& poolState = fGeoPoolStateStack.back(); |
tfarina@chromium.org | f6de475 | 2013-08-17 00:02:59 +0000 | [diff] [blame] | 662 | SkASSERT(indexCount > 0); |
bsalomon | 49f085d | 2014-09-05 13:34:00 -0700 | [diff] [blame] | 663 | SkASSERT(indices); |
tfarina@chromium.org | f6de475 | 2013-08-17 00:02:59 +0000 | [diff] [blame] | 664 | SkASSERT(0 == poolState.fUsedPoolIndexBytes); |
bsalomon@google.com | 1c13c96 | 2011-02-14 16:51:21 +0000 | [diff] [blame] | 665 | |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 666 | *indices = fIndexPool.makeSpace(indexCount, |
| 667 | &poolState.fPoolIndexBuffer, |
| 668 | &poolState.fPoolStartIndex); |
bsalomon | 49f085d | 2014-09-05 13:34:00 -0700 | [diff] [blame] | 669 | return SkToBool(*indices); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 670 | } |
| 671 | |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 672 | void GrInOrderDrawBuffer::releaseReservedVertexSpace() { |
| 673 | GeometryPoolState& poolState = fGeoPoolStateStack.back(); |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 674 | const GeometrySrcState& geoSrc = this->getGeomSrc(); |
bsalomon@google.com | d57d71a | 2012-08-16 16:26:33 +0000 | [diff] [blame] | 675 | |
| 676 | // If we get a release vertex space call then our current source should either be reserved |
| 677 | // or array (which we copied into reserved space). |
joshualitt | d1aa8ff | 2014-11-04 07:47:55 -0800 | [diff] [blame] | 678 | SkASSERT(kReserved_GeometrySrcType == geoSrc.fVertexSrc); |
bsalomon@google.com | 3f5a95e | 2012-03-08 16:41:42 +0000 | [diff] [blame] | 679 | |
| 680 | // When the caller reserved vertex buffer space we gave it back a pointer |
| 681 | // provided by the vertex buffer pool. At each draw we tracked the largest |
| 682 | // offset into the pool's pointer that was referenced. Now we return to the |
| 683 | // 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] | 684 | size_t reservedVertexBytes = geoSrc.fVertexSize * geoSrc.fVertexCount; |
joshualitt | d53a827 | 2014-11-10 16:03:14 -0800 | [diff] [blame] | 685 | fVertexPool.putBack(reservedVertexBytes - poolState.fUsedPoolVertexBytes); |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 686 | poolState.fUsedPoolVertexBytes = 0; |
bsalomon@google.com | 3f5a95e | 2012-03-08 16:41:42 +0000 | [diff] [blame] | 687 | poolState.fPoolVertexBuffer = NULL; |
| 688 | poolState.fPoolStartVertex = 0; |
bsalomon@google.com | 1c13c96 | 2011-02-14 16:51:21 +0000 | [diff] [blame] | 689 | } |
| 690 | |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 691 | void GrInOrderDrawBuffer::releaseReservedIndexSpace() { |
| 692 | GeometryPoolState& poolState = fGeoPoolStateStack.back(); |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 693 | const GeometrySrcState& geoSrc = this->getGeomSrc(); |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 694 | |
bsalomon@google.com | d57d71a | 2012-08-16 16:26:33 +0000 | [diff] [blame] | 695 | // If we get a release index space call then our current source should either be reserved |
| 696 | // or array (which we copied into reserved space). |
joshualitt | d1aa8ff | 2014-11-04 07:47:55 -0800 | [diff] [blame] | 697 | SkASSERT(kReserved_GeometrySrcType == geoSrc.fIndexSrc); |
bsalomon@google.com | 3f5a95e | 2012-03-08 16:41:42 +0000 | [diff] [blame] | 698 | |
| 699 | // Similar to releaseReservedVertexSpace we return any unused portion at |
| 700 | // the tail |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 701 | size_t reservedIndexBytes = sizeof(uint16_t) * geoSrc.fIndexCount; |
| 702 | fIndexPool.putBack(reservedIndexBytes - poolState.fUsedPoolIndexBytes); |
| 703 | poolState.fUsedPoolIndexBytes = 0; |
bsalomon@google.com | 3f5a95e | 2012-03-08 16:41:42 +0000 | [diff] [blame] | 704 | poolState.fPoolIndexBuffer = NULL; |
| 705 | poolState.fPoolStartIndex = 0; |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 706 | } |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 707 | |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 708 | void GrInOrderDrawBuffer::geometrySourceWillPush() { |
| 709 | GeometryPoolState& poolState = fGeoPoolStateStack.push_back(); |
| 710 | poolState.fUsedPoolVertexBytes = 0; |
| 711 | poolState.fUsedPoolIndexBytes = 0; |
commit-bot@chromium.org | 515dcd3 | 2013-08-28 14:17:03 +0000 | [diff] [blame] | 712 | #ifdef SK_DEBUG |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 713 | poolState.fPoolVertexBuffer = (GrVertexBuffer*)~0; |
| 714 | poolState.fPoolStartVertex = ~0; |
| 715 | poolState.fPoolIndexBuffer = (GrIndexBuffer*)~0; |
| 716 | poolState.fPoolStartIndex = ~0; |
| 717 | #endif |
| 718 | } |
| 719 | |
bsalomon | b3e3a95 | 2014-09-19 11:10:40 -0700 | [diff] [blame] | 720 | void GrInOrderDrawBuffer::geometrySourceWillPop(const GeometrySrcState& restoredState) { |
tfarina@chromium.org | f6de475 | 2013-08-17 00:02:59 +0000 | [diff] [blame] | 721 | SkASSERT(fGeoPoolStateStack.count() > 1); |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 722 | fGeoPoolStateStack.pop_back(); |
| 723 | GeometryPoolState& poolState = fGeoPoolStateStack.back(); |
| 724 | // we have to assume that any slack we had in our vertex/index data |
| 725 | // is now unreleasable because data may have been appended later in the |
| 726 | // pool. |
joshualitt | d1aa8ff | 2014-11-04 07:47:55 -0800 | [diff] [blame] | 727 | if (kReserved_GeometrySrcType == restoredState.fVertexSrc) { |
jvanverth@google.com | b75b0a0 | 2013-02-05 20:33:30 +0000 | [diff] [blame] | 728 | poolState.fUsedPoolVertexBytes = restoredState.fVertexSize * restoredState.fVertexCount; |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 729 | } |
joshualitt | d1aa8ff | 2014-11-04 07:47:55 -0800 | [diff] [blame] | 730 | if (kReserved_GeometrySrcType == restoredState.fIndexSrc) { |
joshualitt | d53a827 | 2014-11-10 16:03:14 -0800 | [diff] [blame] | 731 | poolState.fUsedPoolIndexBytes = sizeof(uint16_t) * restoredState.fIndexCount; |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 732 | } |
| 733 | } |
| 734 | |
bsalomon | ae59b77 | 2014-11-19 08:23:49 -0800 | [diff] [blame] | 735 | bool GrInOrderDrawBuffer::recordStateAndShouldDraw(const GrDrawState& ds, |
| 736 | GrGpu::DrawType drawType, |
joshualitt | 54e0c12 | 2014-11-19 09:38:51 -0800 | [diff] [blame] | 737 | const GrClipMaskManager::ScissorState& scissor, |
bsalomon | ae59b77 | 2014-11-19 08:23:49 -0800 | [diff] [blame] | 738 | const GrDeviceCoordTexture* dstCopy) { |
bsalomon | 932f866 | 2014-11-24 06:47:48 -0800 | [diff] [blame] | 739 | SetState* ss = GrNEW_APPEND_TO_RECORDER(fCmdBuffer, SetState, |
| 740 | (ds, fDstGpu, scissor, dstCopy, drawType)); |
| 741 | if (ss->fState.mustSkip()) { |
| 742 | fCmdBuffer.pop_back(); |
bsalomon | ae59b77 | 2014-11-19 08:23:49 -0800 | [diff] [blame] | 743 | return false; |
| 744 | } |
bsalomon | 932f866 | 2014-11-24 06:47:48 -0800 | [diff] [blame] | 745 | if (fPrevState && *fPrevState == ss->fState) { |
| 746 | fCmdBuffer.pop_back(); |
| 747 | } else { |
| 748 | fPrevState = &ss->fState; |
cdalton | 6819df3 | 2014-10-15 13:43:48 -0700 | [diff] [blame] | 749 | this->recordTraceMarkersIfNecessary(); |
bsalomon | 838f62d | 2014-08-05 07:15:57 -0700 | [diff] [blame] | 750 | } |
bsalomon | ae59b77 | 2014-11-19 08:23:49 -0800 | [diff] [blame] | 751 | return true; |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 752 | } |
| 753 | |
cdalton | 6819df3 | 2014-10-15 13:43:48 -0700 | [diff] [blame] | 754 | void GrInOrderDrawBuffer::recordTraceMarkersIfNecessary() { |
| 755 | SkASSERT(!fCmdBuffer.empty()); |
| 756 | SkASSERT(!cmd_has_trace_marker(fCmdBuffer.back().fType)); |
mtklein | f439c77 | 2014-10-14 14:29:30 -0700 | [diff] [blame] | 757 | const GrTraceMarkerSet& activeTraceMarkers = this->getActiveTraceMarkers(); |
| 758 | if (activeTraceMarkers.count() > 0) { |
cdalton | 6819df3 | 2014-10-15 13:43:48 -0700 | [diff] [blame] | 759 | fCmdBuffer.back().fType = add_trace_bit(fCmdBuffer.back().fType); |
mtklein | f439c77 | 2014-10-14 14:29:30 -0700 | [diff] [blame] | 760 | fGpuCmdMarkers.push_back(activeTraceMarkers); |
mtklein | 07894c4 | 2014-10-13 14:00:42 -0700 | [diff] [blame] | 761 | } |
mtklein | 07894c4 | 2014-10-13 14:00:42 -0700 | [diff] [blame] | 762 | } |