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