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 | |
joshualitt | 4d8da81 | 2015-01-28 12:53:54 -0800 | [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" |
jvanverth | 787cdf9 | 2014-12-04 10:46:50 -0800 | [diff] [blame] | 15 | #include "GrFontCache.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) |
bsalomon | 371bcbc | 2014-12-01 08:19:34 -0800 | [diff] [blame] | 21 | : INHERITED(gpu, vertexPool, indexPool) |
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) |
joshualitt | 4d8da81 | 2015-01-28 12:53:54 -0800 | [diff] [blame] | 24 | , fDrawID(0) |
| 25 | , fBatchTarget(gpu, vertexPool, indexPool) |
| 26 | , fDrawBatch(NULL) { |
bsalomon@google.com | 18c9c19 | 2011-09-22 21:01:31 +0000 | [diff] [blame] | 27 | |
bsalomon | 49f085d | 2014-09-05 13:34:00 -0700 | [diff] [blame] | 28 | SkASSERT(vertexPool); |
| 29 | SkASSERT(indexPool); |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 30 | |
cdalton | 3fc6a2f | 2014-11-13 11:54:20 -0800 | [diff] [blame] | 31 | fPathIndexBuffer.setReserve(kPathIdxBufferMinReserve); |
| 32 | fPathTransformBuffer.setReserve(kPathXformBufferMinReserve); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 33 | } |
| 34 | |
| 35 | GrInOrderDrawBuffer::~GrInOrderDrawBuffer() { |
bsalomon@google.com | 86afc2a | 2011-02-16 16:12:19 +0000 | [diff] [blame] | 36 | this->reset(); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 37 | } |
| 38 | |
bsalomon@google.com | 934c570 | 2012-03-20 21:17:58 +0000 | [diff] [blame] | 39 | //////////////////////////////////////////////////////////////////////////////// |
| 40 | |
bsalomon@google.com | d62e88e | 2013-02-01 14:19:27 +0000 | [diff] [blame] | 41 | namespace { |
| 42 | void get_vertex_bounds(const void* vertices, |
| 43 | size_t vertexSize, |
| 44 | int vertexCount, |
| 45 | SkRect* bounds) { |
commit-bot@chromium.org | 972f9cd | 2014-03-28 17:58:28 +0000 | [diff] [blame] | 46 | SkASSERT(vertexSize >= sizeof(SkPoint)); |
tfarina@chromium.org | f6de475 | 2013-08-17 00:02:59 +0000 | [diff] [blame] | 47 | SkASSERT(vertexCount > 0); |
commit-bot@chromium.org | 972f9cd | 2014-03-28 17:58:28 +0000 | [diff] [blame] | 48 | const SkPoint* point = static_cast<const SkPoint*>(vertices); |
bsalomon@google.com | d62e88e | 2013-02-01 14:19:27 +0000 | [diff] [blame] | 49 | bounds->fLeft = bounds->fRight = point->fX; |
| 50 | bounds->fTop = bounds->fBottom = point->fY; |
| 51 | for (int i = 1; i < vertexCount; ++i) { |
commit-bot@chromium.org | 972f9cd | 2014-03-28 17:58:28 +0000 | [diff] [blame] | 52 | point = reinterpret_cast<SkPoint*>(reinterpret_cast<intptr_t>(point) + vertexSize); |
bsalomon@google.com | d62e88e | 2013-02-01 14:19:27 +0000 | [diff] [blame] | 53 | bounds->growToInclude(point->fX, point->fY); |
| 54 | } |
| 55 | } |
bsalomon@google.com | 934c570 | 2012-03-20 21:17:58 +0000 | [diff] [blame] | 56 | } |
| 57 | |
bsalomon | 62c447d | 2014-08-08 08:08:50 -0700 | [diff] [blame] | 58 | /** We always use per-vertex colors so that rects can be batched across color changes. Sometimes we |
| 59 | have explicit local coords and sometimes not. We *could* always provide explicit local coords |
| 60 | and just duplicate the positions when the caller hasn't provided a local coord rect, but we |
| 61 | haven't seen a use case which frequently switches between local rect and no local rect draws. |
| 62 | |
| 63 | The color param is used to determine whether the opaque hint can be set on the draw state. |
| 64 | The caller must populate the vertex colors itself. |
| 65 | |
| 66 | The vertex attrib order is always pos, color, [local coords]. |
| 67 | */ |
joshualitt | 8fc6c2d | 2014-12-22 15:27:05 -0800 | [diff] [blame] | 68 | static const GrGeometryProcessor* create_rect_gp(bool hasExplicitLocalCoords, |
| 69 | GrColor color, |
| 70 | const SkMatrix* localMatrix) { |
joshualitt | 5478d42 | 2014-11-14 16:00:38 -0800 | [diff] [blame] | 71 | uint32_t flags = GrDefaultGeoProcFactory::kPosition_GPType | |
| 72 | GrDefaultGeoProcFactory::kColor_GPType; |
joshualitt | 8fc6c2d | 2014-12-22 15:27:05 -0800 | [diff] [blame] | 73 | flags |= hasExplicitLocalCoords ? GrDefaultGeoProcFactory::kLocalCoord_GPType : 0; |
| 74 | if (localMatrix) { |
joshualitt | 8059eb9 | 2014-12-29 15:10:07 -0800 | [diff] [blame] | 75 | return GrDefaultGeoProcFactory::Create(flags, color, SkMatrix::I(), *localMatrix, |
| 76 | GrColorIsOpaque(color)); |
joshualitt | 8fc6c2d | 2014-12-22 15:27:05 -0800 | [diff] [blame] | 77 | } else { |
joshualitt | 8059eb9 | 2014-12-29 15:10:07 -0800 | [diff] [blame] | 78 | return GrDefaultGeoProcFactory::Create(flags, color, SkMatrix::I(), SkMatrix::I(), |
| 79 | GrColorIsOpaque(color)); |
joshualitt | 8fc6c2d | 2014-12-22 15:27:05 -0800 | [diff] [blame] | 80 | } |
bsalomon | 62c447d | 2014-08-08 08:08:50 -0700 | [diff] [blame] | 81 | } |
robertphillips@google.com | 4290330 | 2013-04-20 12:26:07 +0000 | [diff] [blame] | 82 | |
cdalton | 3fc6a2f | 2014-11-13 11:54:20 -0800 | [diff] [blame] | 83 | static bool path_fill_type_is_winding(const GrStencilSettings& pathStencilSettings) { |
| 84 | static const GrStencilSettings::Face pathFace = GrStencilSettings::kFront_Face; |
| 85 | bool isWinding = kInvert_StencilOp != pathStencilSettings.passOp(pathFace); |
| 86 | if (isWinding) { |
| 87 | // Double check that it is in fact winding. |
| 88 | SkASSERT(kIncClamp_StencilOp == pathStencilSettings.passOp(pathFace)); |
| 89 | SkASSERT(kIncClamp_StencilOp == pathStencilSettings.failOp(pathFace)); |
| 90 | SkASSERT(0x1 != pathStencilSettings.writeMask(pathFace)); |
| 91 | SkASSERT(!pathStencilSettings.isTwoSided()); |
| 92 | } |
| 93 | return isWinding; |
| 94 | } |
| 95 | |
| 96 | template<typename T> static void reset_data_buffer(SkTDArray<T>* buffer, int minReserve) { |
| 97 | // Assume the next time this buffer fills up it will use approximately the same amount |
| 98 | // of space as last time. Only resize if we're using less than a third of the |
| 99 | // allocated space, and leave enough for 50% growth over last time. |
| 100 | if (3 * buffer->count() < buffer->reserved() && buffer->reserved() > minReserve) { |
| 101 | int reserve = SkTMax(minReserve, buffer->count() * 3 / 2); |
| 102 | buffer->reset(); |
| 103 | buffer->setReserve(reserve); |
| 104 | } else { |
| 105 | buffer->rewind(); |
| 106 | } |
| 107 | } |
| 108 | |
commit-bot@chromium.org | 2a05de0 | 2014-03-25 15:17:32 +0000 | [diff] [blame] | 109 | enum { |
| 110 | kTraceCmdBit = 0x80, |
| 111 | kCmdMask = 0x7f, |
| 112 | }; |
| 113 | |
bsalomon | 62c447d | 2014-08-08 08:08:50 -0700 | [diff] [blame] | 114 | 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] | 115 | |
bsalomon | 62c447d | 2014-08-08 08:08:50 -0700 | [diff] [blame] | 116 | 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] | 117 | |
bsalomon | 62c447d | 2014-08-08 08:08:50 -0700 | [diff] [blame] | 118 | 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] | 119 | |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 120 | void GrInOrderDrawBuffer::onDrawRect(GrPipelineBuilder* pipelineBuilder, |
joshualitt | 2e3b3e3 | 2014-12-09 13:31:14 -0800 | [diff] [blame] | 121 | GrColor color, |
joshualitt | 8059eb9 | 2014-12-29 15:10:07 -0800 | [diff] [blame] | 122 | const SkMatrix& viewMatrix, |
joshualitt | 9853cce | 2014-11-17 14:22:48 -0800 | [diff] [blame] | 123 | const SkRect& rect, |
commit-bot@chromium.org | fd03d4a | 2013-07-17 21:39:42 +0000 | [diff] [blame] | 124 | const SkRect* localRect, |
bsalomon@google.com | 0406b9e | 2013-04-02 21:00:15 +0000 | [diff] [blame] | 125 | const SkMatrix* localMatrix) { |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 126 | GrPipelineBuilder::AutoRestoreEffects are(pipelineBuilder); |
jvanverth@google.com | 9b855c7 | 2013-03-01 18:21:22 +0000 | [diff] [blame] | 127 | |
joshualitt | d27f73e | 2014-12-29 07:43:36 -0800 | [diff] [blame] | 128 | // Go to device coords to allow batching across matrix changes |
joshualitt | d27f73e | 2014-12-29 07:43:36 -0800 | [diff] [blame] | 129 | SkMatrix invert = SkMatrix::I(); |
| 130 | |
| 131 | // if we have a local rect, then we apply the localMatrix directly to the localRect to generate |
| 132 | // vertex local coords |
joshualitt | 8fc6c2d | 2014-12-22 15:27:05 -0800 | [diff] [blame] | 133 | bool hasExplicitLocalCoords = SkToBool(localRect); |
joshualitt | d27f73e | 2014-12-29 07:43:36 -0800 | [diff] [blame] | 134 | if (!hasExplicitLocalCoords) { |
joshualitt | 8059eb9 | 2014-12-29 15:10:07 -0800 | [diff] [blame] | 135 | if (!viewMatrix.isIdentity() && !viewMatrix.invert(&invert)) { |
joshualitt | d27f73e | 2014-12-29 07:43:36 -0800 | [diff] [blame] | 136 | SkDebugf("Could not invert\n"); |
| 137 | return; |
| 138 | } |
| 139 | |
| 140 | if (localMatrix) { |
| 141 | invert.preConcat(*localMatrix); |
| 142 | } |
| 143 | } |
| 144 | |
| 145 | SkAutoTUnref<const GrGeometryProcessor> gp(create_rect_gp(hasExplicitLocalCoords, |
| 146 | color, |
| 147 | &invert)); |
jvanverth@google.com | 9b855c7 | 2013-03-01 18:21:22 +0000 | [diff] [blame] | 148 | |
joshualitt | 56995b5 | 2014-12-11 15:44:02 -0800 | [diff] [blame] | 149 | size_t vstride = gp->getVertexStride(); |
joshualitt | 2dd1ae0 | 2014-12-03 06:24:10 -0800 | [diff] [blame] | 150 | SkASSERT(vstride == sizeof(SkPoint) + sizeof(GrColor) + (SkToBool(localRect) ? sizeof(SkPoint) : |
| 151 | 0)); |
| 152 | AutoReleaseGeometry geo(this, 4, vstride, 0); |
bsalomon@google.com | d62e88e | 2013-02-01 14:19:27 +0000 | [diff] [blame] | 153 | if (!geo.succeeded()) { |
tfarina | 38406c8 | 2014-10-31 07:11:12 -0700 | [diff] [blame] | 154 | SkDebugf("Failed to get space for vertices!\n"); |
bsalomon@google.com | 934c570 | 2012-03-20 21:17:58 +0000 | [diff] [blame] | 155 | return; |
| 156 | } |
| 157 | |
joshualitt | 8059eb9 | 2014-12-29 15:10:07 -0800 | [diff] [blame] | 158 | geo.positions()->setRectFan(rect.fLeft, rect.fTop, rect.fRight, rect.fBottom, vstride); |
| 159 | viewMatrix.mapPointsWithStride(geo.positions(), vstride, 4); |
| 160 | |
jvanverth@google.com | 3976825 | 2013-02-14 15:25:44 +0000 | [diff] [blame] | 161 | // 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] | 162 | // modify that stage's matrix. Otherwise if the effect is generating its source rect from |
joshualitt | 8059eb9 | 2014-12-29 15:10:07 -0800 | [diff] [blame] | 163 | // the vertex positions then we have to account for the view matrix |
bsalomon@google.com | d62e88e | 2013-02-01 14:19:27 +0000 | [diff] [blame] | 164 | SkRect devBounds; |
joshualitt | 8059eb9 | 2014-12-29 15:10:07 -0800 | [diff] [blame] | 165 | |
bsalomon@google.com | d62e88e | 2013-02-01 14:19:27 +0000 | [diff] [blame] | 166 | // since we already computed the dev verts, set the bounds hint. This will help us avoid |
| 167 | // unnecessary clipping in our onDraw(). |
egdaniel | 7b3d5ee | 2014-08-28 05:41:14 -0700 | [diff] [blame] | 168 | get_vertex_bounds(geo.vertices(), vstride, 4, &devBounds); |
bsalomon@google.com | d62e88e | 2013-02-01 14:19:27 +0000 | [diff] [blame] | 169 | |
bsalomon | 49f085d | 2014-09-05 13:34:00 -0700 | [diff] [blame] | 170 | if (localRect) { |
bsalomon | 62c447d | 2014-08-08 08:08:50 -0700 | [diff] [blame] | 171 | static const int kLocalOffset = sizeof(SkPoint) + sizeof(GrColor); |
| 172 | SkPoint* coords = GrTCast<SkPoint*>(GrTCast<intptr_t>(geo.vertices()) + kLocalOffset); |
bsalomon@google.com | c781888 | 2013-03-20 19:19:53 +0000 | [diff] [blame] | 173 | coords->setRectFan(localRect->fLeft, localRect->fTop, |
| 174 | localRect->fRight, localRect->fBottom, |
egdaniel | 7b3d5ee | 2014-08-28 05:41:14 -0700 | [diff] [blame] | 175 | vstride); |
bsalomon | 49f085d | 2014-09-05 13:34:00 -0700 | [diff] [blame] | 176 | if (localMatrix) { |
egdaniel | 7b3d5ee | 2014-08-28 05:41:14 -0700 | [diff] [blame] | 177 | localMatrix->mapPointsWithStride(coords, vstride, 4); |
bsalomon@google.com | d62e88e | 2013-02-01 14:19:27 +0000 | [diff] [blame] | 178 | } |
| 179 | } |
| 180 | |
bsalomon | 62c447d | 2014-08-08 08:08:50 -0700 | [diff] [blame] | 181 | static const int kColorOffset = sizeof(SkPoint); |
| 182 | GrColor* vertColor = GrTCast<GrColor*>(GrTCast<intptr_t>(geo.vertices()) + kColorOffset); |
| 183 | for (int i = 0; i < 4; ++i) { |
| 184 | *vertColor = color; |
egdaniel | 7b3d5ee | 2014-08-28 05:41:14 -0700 | [diff] [blame] | 185 | vertColor = (GrColor*) ((intptr_t) vertColor + vstride); |
bsalomon@google.com | d62e88e | 2013-02-01 14:19:27 +0000 | [diff] [blame] | 186 | } |
| 187 | |
bsalomon@google.com | 6e4e650 | 2013-02-25 20:12:45 +0000 | [diff] [blame] | 188 | this->setIndexSourceToBuffer(this->getContext()->getQuadIndexBuffer()); |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 189 | this->drawIndexedInstances(pipelineBuilder, gp, kTriangles_GrPrimitiveType, 1, 4, 6, |
| 190 | &devBounds); |
bsalomon@google.com | d62e88e | 2013-02-01 14:19:27 +0000 | [diff] [blame] | 191 | } |
| 192 | |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 193 | int GrInOrderDrawBuffer::concatInstancedDraw(const GrPipelineBuilder& pipelineBuilder, |
| 194 | const DrawInfo& info) { |
cdalton | 6819df3 | 2014-10-15 13:43:48 -0700 | [diff] [blame] | 195 | SkASSERT(!fCmdBuffer.empty()); |
tfarina@chromium.org | f6de475 | 2013-08-17 00:02:59 +0000 | [diff] [blame] | 196 | SkASSERT(info.isInstanced()); |
bsalomon@google.com | d62e88e | 2013-02-01 14:19:27 +0000 | [diff] [blame] | 197 | |
bsalomon@google.com | 934c570 | 2012-03-20 21:17:58 +0000 | [diff] [blame] | 198 | const GeometrySrcState& geomSrc = this->getGeomSrc(); |
| 199 | |
bsalomon@google.com | d62e88e | 2013-02-01 14:19:27 +0000 | [diff] [blame] | 200 | // we only attempt to concat the case when reserved verts are used with a client-specified index |
| 201 | // buffer. To make this work with client-specified VBs we'd need to know if the VB was updated |
| 202 | // between draws. |
| 203 | if (kReserved_GeometrySrcType != geomSrc.fVertexSrc || |
| 204 | kBuffer_GeometrySrcType != geomSrc.fIndexSrc) { |
| 205 | return 0; |
bsalomon@google.com | 934c570 | 2012-03-20 21:17:58 +0000 | [diff] [blame] | 206 | } |
bsalomon@google.com | d62e88e | 2013-02-01 14:19:27 +0000 | [diff] [blame] | 207 | // Check if there is a draw info that is compatible that uses the same VB from the pool and |
| 208 | // the same IB |
cdalton | 6819df3 | 2014-10-15 13:43:48 -0700 | [diff] [blame] | 209 | if (kDraw_Cmd != strip_trace_bit(fCmdBuffer.back().fType)) { |
bsalomon@google.com | d62e88e | 2013-02-01 14:19:27 +0000 | [diff] [blame] | 210 | return 0; |
| 211 | } |
| 212 | |
cdalton | 6819df3 | 2014-10-15 13:43:48 -0700 | [diff] [blame] | 213 | Draw* draw = static_cast<Draw*>(&fCmdBuffer.back()); |
bsalomon@google.com | d62e88e | 2013-02-01 14:19:27 +0000 | [diff] [blame] | 214 | |
cdalton | 6819df3 | 2014-10-15 13:43:48 -0700 | [diff] [blame] | 215 | if (!draw->fInfo.isInstanced() || |
joshualitt | 4d8da81 | 2015-01-28 12:53:54 -0800 | [diff] [blame] | 216 | draw->fInfo.primitiveType() != info.primitiveType() || |
cdalton | 6819df3 | 2014-10-15 13:43:48 -0700 | [diff] [blame] | 217 | draw->fInfo.verticesPerInstance() != info.verticesPerInstance() || |
| 218 | draw->fInfo.indicesPerInstance() != info.indicesPerInstance() || |
bsalomon | 371bcbc | 2014-12-01 08:19:34 -0800 | [diff] [blame] | 219 | draw->fInfo.vertexBuffer() != info.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 | } |
bsalomon | 371bcbc | 2014-12-01 08:19:34 -0800 | [diff] [blame] | 223 | if (draw->fInfo.startVertex() + draw->fInfo.vertexCount() != info.startVertex()) { |
bsalomon@google.com | d62e88e | 2013-02-01 14:19:27 +0000 | [diff] [blame] | 224 | return 0; |
| 225 | } |
| 226 | |
bsalomon@google.com | d62e88e | 2013-02-01 14:19:27 +0000 | [diff] [blame] | 227 | // how many instances can be concat'ed onto draw given the size of the index buffer |
| 228 | int instancesToConcat = this->indexCountInCurrentSource() / info.indicesPerInstance(); |
cdalton | 6819df3 | 2014-10-15 13:43:48 -0700 | [diff] [blame] | 229 | instancesToConcat -= draw->fInfo.instanceCount(); |
commit-bot@chromium.org | 972f9cd | 2014-03-28 17:58:28 +0000 | [diff] [blame] | 230 | instancesToConcat = SkTMin(instancesToConcat, info.instanceCount()); |
bsalomon@google.com | d62e88e | 2013-02-01 14:19:27 +0000 | [diff] [blame] | 231 | |
cdalton | 6819df3 | 2014-10-15 13:43:48 -0700 | [diff] [blame] | 232 | draw->fInfo.adjustInstanceCount(instancesToConcat); |
commit-bot@chromium.org | 2a05de0 | 2014-03-25 15:17:32 +0000 | [diff] [blame] | 233 | |
| 234 | // update last fGpuCmdMarkers to include any additional trace markers that have been added |
| 235 | if (this->getActiveTraceMarkers().count() > 0) { |
cdalton | 6819df3 | 2014-10-15 13:43:48 -0700 | [diff] [blame] | 236 | if (cmd_has_trace_marker(draw->fType)) { |
commit-bot@chromium.org | 2a05de0 | 2014-03-25 15:17:32 +0000 | [diff] [blame] | 237 | fGpuCmdMarkers.back().addSet(this->getActiveTraceMarkers()); |
| 238 | } else { |
| 239 | fGpuCmdMarkers.push_back(this->getActiveTraceMarkers()); |
cdalton | 6819df3 | 2014-10-15 13:43:48 -0700 | [diff] [blame] | 240 | draw->fType = add_trace_bit(draw->fType); |
commit-bot@chromium.org | 2a05de0 | 2014-03-25 15:17:32 +0000 | [diff] [blame] | 241 | } |
| 242 | } |
| 243 | |
bsalomon@google.com | d62e88e | 2013-02-01 14:19:27 +0000 | [diff] [blame] | 244 | return instancesToConcat; |
bsalomon@google.com | 934c570 | 2012-03-20 21:17:58 +0000 | [diff] [blame] | 245 | } |
| 246 | |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 247 | void GrInOrderDrawBuffer::onDraw(const GrPipelineBuilder& pipelineBuilder, |
joshualitt | 56995b5 | 2014-12-11 15:44:02 -0800 | [diff] [blame] | 248 | const GrGeometryProcessor* gp, |
joshualitt | 9853cce | 2014-11-17 14:22:48 -0800 | [diff] [blame] | 249 | const DrawInfo& info, |
bsalomon | 50785a3 | 2015-02-06 07:02:37 -0800 | [diff] [blame] | 250 | const GrScissorState& scissorState) { |
joshualitt | 7eb8c7b | 2014-11-18 14:24:27 -0800 | [diff] [blame] | 251 | SkASSERT(info.vertexBuffer() && (!info.isIndexed() || info.indexBuffer())); |
joshualitt | 4d8da81 | 2015-01-28 12:53:54 -0800 | [diff] [blame] | 252 | this->closeBatch(); |
| 253 | |
bsalomon | 50785a3 | 2015-02-06 07:02:37 -0800 | [diff] [blame] | 254 | if (!this->recordStateAndShouldDraw(pipelineBuilder, gp, scissorState, info.getDevBounds())) { |
bsalomon | ae59b77 | 2014-11-19 08:23:49 -0800 | [diff] [blame] | 255 | return; |
| 256 | } |
bsalomon@google.com | 86afc2a | 2011-02-16 16:12:19 +0000 | [diff] [blame] | 257 | |
bsalomon | b3e3a95 | 2014-09-19 11:10:40 -0700 | [diff] [blame] | 258 | Draw* draw; |
bsalomon@google.com | d62e88e | 2013-02-01 14:19:27 +0000 | [diff] [blame] | 259 | if (info.isInstanced()) { |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 260 | int instancesConcated = this->concatInstancedDraw(pipelineBuilder, info); |
bsalomon@google.com | d62e88e | 2013-02-01 14:19:27 +0000 | [diff] [blame] | 261 | if (info.instanceCount() > instancesConcated) { |
joshualitt | 54e0c12 | 2014-11-19 09:38:51 -0800 | [diff] [blame] | 262 | draw = GrNEW_APPEND_TO_RECORDER(fCmdBuffer, Draw, (info)); |
cdalton | 6819df3 | 2014-10-15 13:43:48 -0700 | [diff] [blame] | 263 | draw->fInfo.adjustInstanceCount(-instancesConcated); |
bsalomon@google.com | d62e88e | 2013-02-01 14:19:27 +0000 | [diff] [blame] | 264 | } else { |
| 265 | return; |
| 266 | } |
| 267 | } else { |
joshualitt | 54e0c12 | 2014-11-19 09:38:51 -0800 | [diff] [blame] | 268 | draw = GrNEW_APPEND_TO_RECORDER(fCmdBuffer, Draw, (info)); |
bsalomon@google.com | d62e88e | 2013-02-01 14:19:27 +0000 | [diff] [blame] | 269 | } |
cdalton | 6819df3 | 2014-10-15 13:43:48 -0700 | [diff] [blame] | 270 | this->recordTraceMarkersIfNecessary(); |
commit-bot@chromium.org | 9b62aa1 | 2014-03-25 11:59:40 +0000 | [diff] [blame] | 271 | } |
sugoi@google.com | 5f74cf8 | 2012-12-17 21:16:45 +0000 | [diff] [blame] | 272 | |
joshualitt | 4d8da81 | 2015-01-28 12:53:54 -0800 | [diff] [blame] | 273 | void GrInOrderDrawBuffer::onDrawBatch(GrBatch* batch, |
| 274 | const GrPipelineBuilder& pipelineBuilder, |
| 275 | const GrScissorState& scissorState, |
bsalomon | 50785a3 | 2015-02-06 07:02:37 -0800 | [diff] [blame] | 276 | const SkRect* devBounds) { |
| 277 | if (!this->recordStateAndShouldDraw(batch, pipelineBuilder, scissorState, devBounds)) { |
joshualitt | 4d8da81 | 2015-01-28 12:53:54 -0800 | [diff] [blame] | 278 | return; |
| 279 | } |
| 280 | |
| 281 | // Check if there is a Batch Draw we can batch with |
| 282 | if (kDrawBatch_Cmd != strip_trace_bit(fCmdBuffer.back().fType)) { |
| 283 | fDrawBatch = GrNEW_APPEND_TO_RECORDER(fCmdBuffer, DrawBatch, (batch)); |
| 284 | return; |
| 285 | } |
| 286 | |
| 287 | DrawBatch* draw = static_cast<DrawBatch*>(&fCmdBuffer.back()); |
| 288 | if (draw->fBatch->combineIfPossible(batch)) { |
| 289 | return; |
| 290 | } else { |
| 291 | this->closeBatch(); |
| 292 | fDrawBatch = GrNEW_APPEND_TO_RECORDER(fCmdBuffer, DrawBatch, (batch)); |
| 293 | } |
| 294 | this->recordTraceMarkersIfNecessary(); |
| 295 | } |
| 296 | |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 297 | void GrInOrderDrawBuffer::onStencilPath(const GrPipelineBuilder& pipelineBuilder, |
joshualitt | 56995b5 | 2014-12-11 15:44:02 -0800 | [diff] [blame] | 298 | const GrPathProcessor* pathProc, |
joshualitt | 9853cce | 2014-11-17 14:22:48 -0800 | [diff] [blame] | 299 | const GrPath* path, |
bsalomon | 3e79124 | 2014-12-17 13:43:13 -0800 | [diff] [blame] | 300 | const GrScissorState& scissorState, |
joshualitt | 2c93efe | 2014-11-06 12:57:13 -0800 | [diff] [blame] | 301 | const GrStencilSettings& stencilSettings) { |
joshualitt | 70f0004 | 2015-02-06 15:53:59 -0800 | [diff] [blame^] | 302 | this->closeBatch(); |
| 303 | |
bsalomon | 3e79124 | 2014-12-17 13:43:13 -0800 | [diff] [blame] | 304 | StencilPath* sp = GrNEW_APPEND_TO_RECORDER(fCmdBuffer, StencilPath, |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 305 | (path, pipelineBuilder.getRenderTarget())); |
bsalomon | 3e79124 | 2014-12-17 13:43:13 -0800 | [diff] [blame] | 306 | sp->fScissor = scissorState; |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 307 | sp->fUseHWAA = pipelineBuilder.isHWAntialias(); |
joshualitt | 8059eb9 | 2014-12-29 15:10:07 -0800 | [diff] [blame] | 308 | sp->fViewMatrix = pathProc->viewMatrix(); |
bsalomon | 3e79124 | 2014-12-17 13:43:13 -0800 | [diff] [blame] | 309 | sp->fStencil = stencilSettings; |
cdalton | 6819df3 | 2014-10-15 13:43:48 -0700 | [diff] [blame] | 310 | this->recordTraceMarkersIfNecessary(); |
bsalomon@google.com | 64aef2b | 2012-06-11 15:36:13 +0000 | [diff] [blame] | 311 | } |
| 312 | |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 313 | void GrInOrderDrawBuffer::onDrawPath(const GrPipelineBuilder& pipelineBuilder, |
joshualitt | 56995b5 | 2014-12-11 15:44:02 -0800 | [diff] [blame] | 314 | const GrPathProcessor* pathProc, |
joshualitt | 9853cce | 2014-11-17 14:22:48 -0800 | [diff] [blame] | 315 | const GrPath* path, |
bsalomon | 3e79124 | 2014-12-17 13:43:13 -0800 | [diff] [blame] | 316 | const GrScissorState& scissorState, |
joshualitt | 2c93efe | 2014-11-06 12:57:13 -0800 | [diff] [blame] | 317 | const GrStencilSettings& stencilSettings, |
bsalomon | 50785a3 | 2015-02-06 07:02:37 -0800 | [diff] [blame] | 318 | const SkRect* devBounds) { |
joshualitt | 4d8da81 | 2015-01-28 12:53:54 -0800 | [diff] [blame] | 319 | this->closeBatch(); |
| 320 | |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 321 | // TODO: Only compare the subset of GrPipelineBuilder relevant to path covering? |
bsalomon | 50785a3 | 2015-02-06 07:02:37 -0800 | [diff] [blame] | 322 | if (!this->recordStateAndShouldDraw(pipelineBuilder, pathProc, scissorState, devBounds)) { |
bsalomon | ae59b77 | 2014-11-19 08:23:49 -0800 | [diff] [blame] | 323 | return; |
| 324 | } |
cdalton | 6819df3 | 2014-10-15 13:43:48 -0700 | [diff] [blame] | 325 | DrawPath* dp = GrNEW_APPEND_TO_RECORDER(fCmdBuffer, DrawPath, (path)); |
joshualitt | 2c93efe | 2014-11-06 12:57:13 -0800 | [diff] [blame] | 326 | dp->fStencilSettings = stencilSettings; |
cdalton | 6819df3 | 2014-10-15 13:43:48 -0700 | [diff] [blame] | 327 | this->recordTraceMarkersIfNecessary(); |
commit-bot@chromium.org | c4dc0ad | 2013-10-09 14:11:33 +0000 | [diff] [blame] | 328 | } |
| 329 | |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 330 | void GrInOrderDrawBuffer::onDrawPaths(const GrPipelineBuilder& pipelineBuilder, |
joshualitt | 56995b5 | 2014-12-11 15:44:02 -0800 | [diff] [blame] | 331 | const GrPathProcessor* pathProc, |
joshualitt | 9853cce | 2014-11-17 14:22:48 -0800 | [diff] [blame] | 332 | const GrPathRange* pathRange, |
cdalton | 55b24af | 2014-11-25 11:00:56 -0800 | [diff] [blame] | 333 | const void* indices, |
| 334 | PathIndexType indexType, |
| 335 | const float transformValues[], |
| 336 | PathTransformType transformType, |
joshualitt | 2c93efe | 2014-11-06 12:57:13 -0800 | [diff] [blame] | 337 | int count, |
bsalomon | 3e79124 | 2014-12-17 13:43:13 -0800 | [diff] [blame] | 338 | const GrScissorState& scissorState, |
joshualitt | 2c93efe | 2014-11-06 12:57:13 -0800 | [diff] [blame] | 339 | const GrStencilSettings& stencilSettings, |
bsalomon | 50785a3 | 2015-02-06 07:02:37 -0800 | [diff] [blame] | 340 | const SkRect* devBounds) { |
bsalomon | 49f085d | 2014-09-05 13:34:00 -0700 | [diff] [blame] | 341 | SkASSERT(pathRange); |
| 342 | SkASSERT(indices); |
cdalton | 55b24af | 2014-11-25 11:00:56 -0800 | [diff] [blame] | 343 | SkASSERT(transformValues); |
joshualitt | 4d8da81 | 2015-01-28 12:53:54 -0800 | [diff] [blame] | 344 | this->closeBatch(); |
| 345 | |
bsalomon | 50785a3 | 2015-02-06 07:02:37 -0800 | [diff] [blame] | 346 | if (!this->recordStateAndShouldDraw(pipelineBuilder, pathProc, scissorState, devBounds)) { |
bsalomon | ae59b77 | 2014-11-19 08:23:49 -0800 | [diff] [blame] | 347 | return; |
| 348 | } |
cdalton | 6819df3 | 2014-10-15 13:43:48 -0700 | [diff] [blame] | 349 | |
cdalton | 55b24af | 2014-11-25 11:00:56 -0800 | [diff] [blame] | 350 | int indexBytes = GrPathRange::PathIndexSizeInBytes(indexType); |
| 351 | if (int misalign = fPathIndexBuffer.count() % indexBytes) { |
| 352 | // Add padding to the index buffer so the indices are aligned properly. |
| 353 | fPathIndexBuffer.append(indexBytes - misalign); |
| 354 | } |
| 355 | |
| 356 | char* savedIndices = fPathIndexBuffer.append(count * indexBytes, |
| 357 | reinterpret_cast<const char*>(indices)); |
| 358 | float* savedTransforms = fPathTransformBuffer.append( |
| 359 | count * GrPathRendering::PathTransformSize(transformType), |
| 360 | transformValues); |
cdalton | 6819df3 | 2014-10-15 13:43:48 -0700 | [diff] [blame] | 361 | |
cdalton | 3fc6a2f | 2014-11-13 11:54:20 -0800 | [diff] [blame] | 362 | if (kDrawPaths_Cmd == strip_trace_bit(fCmdBuffer.back().fType)) { |
| 363 | // The previous command was also DrawPaths. Try to collapse this call into the one |
bsalomon | 371bcbc | 2014-12-01 08:19:34 -0800 | [diff] [blame] | 364 | // before. Note that stenciling all the paths at once, then covering, may not be |
cdalton | 3fc6a2f | 2014-11-13 11:54:20 -0800 | [diff] [blame] | 365 | // equivalent to two separate draw calls if there is overlap. Blending won't work, |
| 366 | // and the combined calls may also cancel each other's winding numbers in some |
| 367 | // places. For now the winding numbers are only an issue if the fill is even/odd, |
| 368 | // because DrawPaths is currently only used for glyphs, and glyphs in the same |
| 369 | // font tend to all wind in the same direction. |
| 370 | DrawPaths* previous = static_cast<DrawPaths*>(&fCmdBuffer.back()); |
| 371 | if (pathRange == previous->pathRange() && |
cdalton | 55b24af | 2014-11-25 11:00:56 -0800 | [diff] [blame] | 372 | indexType == previous->fIndexType && |
| 373 | transformType == previous->fTransformType && |
cdalton | 3fc6a2f | 2014-11-13 11:54:20 -0800 | [diff] [blame] | 374 | stencilSettings == previous->fStencilSettings && |
| 375 | path_fill_type_is_winding(stencilSettings) && |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 376 | !pipelineBuilder.willBlendWithDst(pathProc)) { |
cdalton | 3fc6a2f | 2014-11-13 11:54:20 -0800 | [diff] [blame] | 377 | // Fold this DrawPaths call into the one previous. |
| 378 | previous->fCount += count; |
| 379 | return; |
| 380 | } |
| 381 | } |
| 382 | |
| 383 | DrawPaths* dp = GrNEW_APPEND_TO_RECORDER(fCmdBuffer, DrawPaths, (pathRange)); |
bsalomon | ef3fcd8 | 2014-12-12 08:51:38 -0800 | [diff] [blame] | 384 | dp->fIndicesLocation = SkToU32(savedIndices - fPathIndexBuffer.begin()); |
cdalton | 55b24af | 2014-11-25 11:00:56 -0800 | [diff] [blame] | 385 | dp->fIndexType = indexType; |
bsalomon | ef3fcd8 | 2014-12-12 08:51:38 -0800 | [diff] [blame] | 386 | dp->fTransformsLocation = SkToU32(savedTransforms - fPathTransformBuffer.begin()); |
cdalton | 55b24af | 2014-11-25 11:00:56 -0800 | [diff] [blame] | 387 | dp->fTransformType = transformType; |
| 388 | dp->fCount = count; |
joshualitt | 2c93efe | 2014-11-06 12:57:13 -0800 | [diff] [blame] | 389 | dp->fStencilSettings = stencilSettings; |
cdalton | 6819df3 | 2014-10-15 13:43:48 -0700 | [diff] [blame] | 390 | |
| 391 | this->recordTraceMarkersIfNecessary(); |
commit-bot@chromium.org | 9b62aa1 | 2014-03-25 11:59:40 +0000 | [diff] [blame] | 392 | } |
| 393 | |
bsalomon | 63b2196 | 2014-11-05 07:05:34 -0800 | [diff] [blame] | 394 | void GrInOrderDrawBuffer::onClear(const SkIRect* rect, GrColor color, |
| 395 | bool canIgnoreRect, GrRenderTarget* renderTarget) { |
joshualitt | 9853cce | 2014-11-17 14:22:48 -0800 | [diff] [blame] | 396 | SkASSERT(renderTarget); |
joshualitt | 70f0004 | 2015-02-06 15:53:59 -0800 | [diff] [blame^] | 397 | this->closeBatch(); |
| 398 | |
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 | 70f0004 | 2015-02-06 15:53:59 -0800 | [diff] [blame^] | 419 | this->closeBatch(); |
| 420 | |
joshualitt | 6db519c | 2014-10-29 08:48:18 -0700 | [diff] [blame] | 421 | ClearStencilClip* clr = GrNEW_APPEND_TO_RECORDER(fCmdBuffer, ClearStencilClip, (renderTarget)); |
| 422 | clr->fRect = rect; |
| 423 | clr->fInsideClip = insideClip; |
| 424 | this->recordTraceMarkersIfNecessary(); |
| 425 | } |
| 426 | |
commit-bot@chromium.org | 28361fa | 2014-03-28 16:08:05 +0000 | [diff] [blame] | 427 | void GrInOrderDrawBuffer::discard(GrRenderTarget* renderTarget) { |
bsalomon | 89c6298 | 2014-11-03 12:08:42 -0800 | [diff] [blame] | 428 | SkASSERT(renderTarget); |
joshualitt | 70f0004 | 2015-02-06 15:53:59 -0800 | [diff] [blame^] | 429 | this->closeBatch(); |
| 430 | |
commit-bot@chromium.org | 28361fa | 2014-03-28 16:08:05 +0000 | [diff] [blame] | 431 | if (!this->caps()->discardRenderTargetSupport()) { |
| 432 | return; |
| 433 | } |
cdalton | 6819df3 | 2014-10-15 13:43:48 -0700 | [diff] [blame] | 434 | Clear* clr = GrNEW_APPEND_TO_RECORDER(fCmdBuffer, Clear, (renderTarget)); |
commit-bot@chromium.org | 28361fa | 2014-03-28 16:08:05 +0000 | [diff] [blame] | 435 | clr->fColor = GrColor_ILLEGAL; |
cdalton | 6819df3 | 2014-10-15 13:43:48 -0700 | [diff] [blame] | 436 | this->recordTraceMarkersIfNecessary(); |
commit-bot@chromium.org | 28361fa | 2014-03-28 16:08:05 +0000 | [diff] [blame] | 437 | } |
| 438 | |
bsalomon | 371bcbc | 2014-12-01 08:19:34 -0800 | [diff] [blame] | 439 | void GrInOrderDrawBuffer::onReset() { |
cdalton | 6819df3 | 2014-10-15 13:43:48 -0700 | [diff] [blame] | 440 | fCmdBuffer.reset(); |
bsalomon | 932f866 | 2014-11-24 06:47:48 -0800 | [diff] [blame] | 441 | fPrevState = NULL; |
cdalton | 3fc6a2f | 2014-11-13 11:54:20 -0800 | [diff] [blame] | 442 | reset_data_buffer(&fPathIndexBuffer, kPathIdxBufferMinReserve); |
| 443 | reset_data_buffer(&fPathTransformBuffer, kPathXformBufferMinReserve); |
commit-bot@chromium.org | 2a05de0 | 2014-03-25 15:17:32 +0000 | [diff] [blame] | 444 | fGpuCmdMarkers.reset(); |
joshualitt | 4d8da81 | 2015-01-28 12:53:54 -0800 | [diff] [blame] | 445 | fDrawBatch = NULL; |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 446 | } |
| 447 | |
bsalomon | 371bcbc | 2014-12-01 08:19:34 -0800 | [diff] [blame] | 448 | void GrInOrderDrawBuffer::onFlush() { |
cdalton | 6819df3 | 2014-10-15 13:43:48 -0700 | [diff] [blame] | 449 | if (fCmdBuffer.empty()) { |
robertphillips@google.com | 1267fbd | 2013-07-03 18:37:27 +0000 | [diff] [blame] | 450 | return; |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 451 | } |
bsalomon@google.com | 6e4e650 | 2013-02-25 20:12:45 +0000 | [diff] [blame] | 452 | |
joshualitt | c2893c5 | 2015-01-28 06:54:30 -0800 | [diff] [blame] | 453 | // Updated every time we find a set state cmd to reflect the current state in the playback |
| 454 | // stream. |
| 455 | SetState* currentState = NULL; |
| 456 | |
joshualitt | 4d8da81 | 2015-01-28 12:53:54 -0800 | [diff] [blame] | 457 | // TODO this is temporary while batch is being rolled out |
| 458 | this->closeBatch(); |
| 459 | this->getVertexAllocPool()->unmap(); |
| 460 | this->getIndexAllocPool()->unmap(); |
| 461 | fBatchTarget.preFlush(); |
| 462 | |
| 463 | currentState = NULL; |
| 464 | CmdBuffer::Iter iter(fCmdBuffer); |
| 465 | |
| 466 | int currCmdMarker = 0; |
| 467 | |
joshualitt | 7bc18b7 | 2015-02-03 16:41:41 -0800 | [diff] [blame] | 468 | int i = 0; |
cdalton | 6819df3 | 2014-10-15 13:43:48 -0700 | [diff] [blame] | 469 | while (iter.next()) { |
joshualitt | 7bc18b7 | 2015-02-03 16:41:41 -0800 | [diff] [blame] | 470 | i++; |
commit-bot@chromium.org | 2a05de0 | 2014-03-25 15:17:32 +0000 | [diff] [blame] | 471 | GrGpuTraceMarker newMarker("", -1); |
egdaniel | d78a168 | 2014-07-09 10:41:26 -0700 | [diff] [blame] | 472 | SkString traceString; |
cdalton | 6819df3 | 2014-10-15 13:43:48 -0700 | [diff] [blame] | 473 | if (cmd_has_trace_marker(iter->fType)) { |
egdaniel | d78a168 | 2014-07-09 10:41:26 -0700 | [diff] [blame] | 474 | traceString = fGpuCmdMarkers[currCmdMarker].toString(); |
commit-bot@chromium.org | 2a05de0 | 2014-03-25 15:17:32 +0000 | [diff] [blame] | 475 | newMarker.fMarker = traceString.c_str(); |
bsalomon | 371bcbc | 2014-12-01 08:19:34 -0800 | [diff] [blame] | 476 | this->getGpu()->addGpuTraceMarker(&newMarker); |
commit-bot@chromium.org | 2a05de0 | 2014-03-25 15:17:32 +0000 | [diff] [blame] | 477 | ++currCmdMarker; |
| 478 | } |
cdalton | 6819df3 | 2014-10-15 13:43:48 -0700 | [diff] [blame] | 479 | |
joshualitt | 4d8da81 | 2015-01-28 12:53:54 -0800 | [diff] [blame] | 480 | // TODO temporary hack |
| 481 | if (kDrawBatch_Cmd == strip_trace_bit(iter->fType)) { |
joshualitt | 7bc18b7 | 2015-02-03 16:41:41 -0800 | [diff] [blame] | 482 | DrawBatch* db = reinterpret_cast<DrawBatch*>(iter.get()); |
| 483 | fBatchTarget.flushNext(db->fBatch->numberOfDraws()); |
joshualitt | 4d8da81 | 2015-01-28 12:53:54 -0800 | [diff] [blame] | 484 | continue; |
| 485 | } |
| 486 | |
| 487 | bool isSetState = kSetState_Cmd == strip_trace_bit(iter->fType); |
| 488 | if (isSetState) { |
joshualitt | 9853cce | 2014-11-17 14:22:48 -0800 | [diff] [blame] | 489 | SetState* ss = reinterpret_cast<SetState*>(iter.get()); |
joshualitt | 873ad0e | 2015-01-20 09:08:51 -0800 | [diff] [blame] | 490 | |
joshualitt | 4d8da81 | 2015-01-28 12:53:54 -0800 | [diff] [blame] | 491 | // TODO sometimes we have a prim proc, othertimes we have a GrBatch. Eventually we will |
| 492 | // only have GrBatch and we can delete this |
| 493 | if (ss->fPrimitiveProcessor) { |
| 494 | this->getGpu()->buildProgramDesc(&ss->fDesc, *ss->fPrimitiveProcessor, |
| 495 | ss->fPipeline, |
joshualitt | 4d8da81 | 2015-01-28 12:53:54 -0800 | [diff] [blame] | 496 | ss->fBatchTracker); |
| 497 | } |
joshualitt | 873ad0e | 2015-01-20 09:08:51 -0800 | [diff] [blame] | 498 | currentState = ss; |
joshualitt | d53a827 | 2014-11-10 16:03:14 -0800 | [diff] [blame] | 499 | } else { |
joshualitt | 873ad0e | 2015-01-20 09:08:51 -0800 | [diff] [blame] | 500 | iter->execute(this, currentState); |
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)) { |
bsalomon | 371bcbc | 2014-12-01 08:19:34 -0800 | [diff] [blame] | 504 | this->getGpu()->removeGpuTraceMarker(&newMarker); |
commit-bot@chromium.org | 2a05de0 | 2014-03-25 15:17:32 +0000 | [diff] [blame] | 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 | |
joshualitt | 4d8da81 | 2015-01-28 12:53:54 -0800 | [diff] [blame] | 508 | // TODO see copious notes about hack |
| 509 | fBatchTarget.postFlush(); |
| 510 | |
commit-bot@chromium.org | 2a05de0 | 2014-03-25 15:17:32 +0000 | [diff] [blame] | 511 | SkASSERT(fGpuCmdMarkers.count() == currCmdMarker); |
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 | |
joshualitt | 873ad0e | 2015-01-20 09:08:51 -0800 | [diff] [blame] | 515 | void GrInOrderDrawBuffer::Draw::execute(GrInOrderDrawBuffer* buf, const SetState* state) { |
| 516 | SkASSERT(state); |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 517 | DrawArgs args(state->fPrimitiveProcessor.get(), &state->fPipeline, &state->fDesc, |
joshualitt | 17e7314 | 2015-01-21 11:52:36 -0800 | [diff] [blame] | 518 | &state->fBatchTracker); |
joshualitt | 873ad0e | 2015-01-20 09:08:51 -0800 | [diff] [blame] | 519 | buf->getGpu()->draw(args, fInfo); |
cdalton | 6819df3 | 2014-10-15 13:43:48 -0700 | [diff] [blame] | 520 | } |
| 521 | |
joshualitt | 873ad0e | 2015-01-20 09:08:51 -0800 | [diff] [blame] | 522 | void GrInOrderDrawBuffer::StencilPath::execute(GrInOrderDrawBuffer* buf, const SetState*) { |
bsalomon | 3e79124 | 2014-12-17 13:43:13 -0800 | [diff] [blame] | 523 | GrGpu::StencilPathState state; |
| 524 | state.fRenderTarget = fRenderTarget.get(); |
| 525 | state.fScissor = &fScissor; |
| 526 | state.fStencil = &fStencil; |
| 527 | state.fUseHWAA = fUseHWAA; |
| 528 | state.fViewMatrix = &fViewMatrix; |
| 529 | |
| 530 | buf->getGpu()->stencilPath(this->path(), state); |
cdalton | 6819df3 | 2014-10-15 13:43:48 -0700 | [diff] [blame] | 531 | } |
| 532 | |
joshualitt | 873ad0e | 2015-01-20 09:08:51 -0800 | [diff] [blame] | 533 | void GrInOrderDrawBuffer::DrawPath::execute(GrInOrderDrawBuffer* buf, const SetState* state) { |
| 534 | SkASSERT(state); |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 535 | DrawArgs args(state->fPrimitiveProcessor.get(), &state->fPipeline, &state->fDesc, |
joshualitt | 17e7314 | 2015-01-21 11:52:36 -0800 | [diff] [blame] | 536 | &state->fBatchTracker); |
joshualitt | 873ad0e | 2015-01-20 09:08:51 -0800 | [diff] [blame] | 537 | buf->getGpu()->drawPath(args, this->path(), fStencilSettings); |
cdalton | 6819df3 | 2014-10-15 13:43:48 -0700 | [diff] [blame] | 538 | } |
| 539 | |
joshualitt | 873ad0e | 2015-01-20 09:08:51 -0800 | [diff] [blame] | 540 | void GrInOrderDrawBuffer::DrawPaths::execute(GrInOrderDrawBuffer* buf, const SetState* state) { |
| 541 | SkASSERT(state); |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 542 | DrawArgs args(state->fPrimitiveProcessor.get(), &state->fPipeline, &state->fDesc, |
joshualitt | 17e7314 | 2015-01-21 11:52:36 -0800 | [diff] [blame] | 543 | &state->fBatchTracker); |
joshualitt | 873ad0e | 2015-01-20 09:08:51 -0800 | [diff] [blame] | 544 | buf->getGpu()->drawPaths(args, this->pathRange(), |
cdalton | 55b24af | 2014-11-25 11:00:56 -0800 | [diff] [blame] | 545 | &buf->fPathIndexBuffer[fIndicesLocation], fIndexType, |
| 546 | &buf->fPathTransformBuffer[fTransformsLocation], fTransformType, |
| 547 | fCount, fStencilSettings); |
cdalton | 6819df3 | 2014-10-15 13:43:48 -0700 | [diff] [blame] | 548 | } |
| 549 | |
joshualitt | 4d8da81 | 2015-01-28 12:53:54 -0800 | [diff] [blame] | 550 | void GrInOrderDrawBuffer::DrawBatch::execute(GrInOrderDrawBuffer* buf, const SetState* state) { |
| 551 | SkASSERT(state); |
| 552 | fBatch->generateGeometry(buf->getBatchTarget(), &state->fPipeline); |
| 553 | } |
| 554 | |
joshualitt | 873ad0e | 2015-01-20 09:08:51 -0800 | [diff] [blame] | 555 | void GrInOrderDrawBuffer::SetState::execute(GrInOrderDrawBuffer*, const SetState*) {} |
cdalton | 6819df3 | 2014-10-15 13:43:48 -0700 | [diff] [blame] | 556 | |
joshualitt | 873ad0e | 2015-01-20 09:08:51 -0800 | [diff] [blame] | 557 | void GrInOrderDrawBuffer::Clear::execute(GrInOrderDrawBuffer* buf, const SetState*) { |
cdalton | 6819df3 | 2014-10-15 13:43:48 -0700 | [diff] [blame] | 558 | if (GrColor_ILLEGAL == fColor) { |
bsalomon | 371bcbc | 2014-12-01 08:19:34 -0800 | [diff] [blame] | 559 | buf->getGpu()->discard(this->renderTarget()); |
cdalton | 6819df3 | 2014-10-15 13:43:48 -0700 | [diff] [blame] | 560 | } else { |
bsalomon | 371bcbc | 2014-12-01 08:19:34 -0800 | [diff] [blame] | 561 | buf->getGpu()->clear(&fRect, fColor, fCanIgnoreRect, this->renderTarget()); |
cdalton | 6819df3 | 2014-10-15 13:43:48 -0700 | [diff] [blame] | 562 | } |
| 563 | } |
| 564 | |
joshualitt | 873ad0e | 2015-01-20 09:08:51 -0800 | [diff] [blame] | 565 | void GrInOrderDrawBuffer::ClearStencilClip::execute(GrInOrderDrawBuffer* buf, const SetState*) { |
bsalomon | 371bcbc | 2014-12-01 08:19:34 -0800 | [diff] [blame] | 566 | buf->getGpu()->clearStencilClip(fRect, fInsideClip, this->renderTarget()); |
joshualitt | 6db519c | 2014-10-29 08:48:18 -0700 | [diff] [blame] | 567 | } |
| 568 | |
joshualitt | 873ad0e | 2015-01-20 09:08:51 -0800 | [diff] [blame] | 569 | void GrInOrderDrawBuffer::CopySurface::execute(GrInOrderDrawBuffer* buf, const SetState*) { |
bsalomon | 371bcbc | 2014-12-01 08:19:34 -0800 | [diff] [blame] | 570 | buf->getGpu()->copySurface(this->dst(), this->src(), fSrcRect, fDstPoint); |
cdalton | 6819df3 | 2014-10-15 13:43:48 -0700 | [diff] [blame] | 571 | } |
| 572 | |
bsalomon | f90a02b | 2014-11-26 12:28:00 -0800 | [diff] [blame] | 573 | bool GrInOrderDrawBuffer::onCopySurface(GrSurface* dst, |
| 574 | GrSurface* src, |
| 575 | const SkIRect& srcRect, |
| 576 | const SkIPoint& dstPoint) { |
bsalomon | 371bcbc | 2014-12-01 08:19:34 -0800 | [diff] [blame] | 577 | if (getGpu()->canCopySurface(dst, src, srcRect, dstPoint)) { |
cdalton | 6819df3 | 2014-10-15 13:43:48 -0700 | [diff] [blame] | 578 | CopySurface* cs = GrNEW_APPEND_TO_RECORDER(fCmdBuffer, CopySurface, (dst, src)); |
bsalomon@google.com | 116ad84 | 2013-04-09 15:38:19 +0000 | [diff] [blame] | 579 | cs->fSrcRect = srcRect; |
| 580 | cs->fDstPoint = dstPoint; |
cdalton | 6819df3 | 2014-10-15 13:43:48 -0700 | [diff] [blame] | 581 | this->recordTraceMarkersIfNecessary(); |
bsalomon@google.com | 116ad84 | 2013-04-09 15:38:19 +0000 | [diff] [blame] | 582 | return true; |
bsalomon@google.com | 116ad84 | 2013-04-09 15:38:19 +0000 | [diff] [blame] | 583 | } |
bsalomon | f90a02b | 2014-11-26 12:28:00 -0800 | [diff] [blame] | 584 | return false; |
bsalomon@google.com | 116ad84 | 2013-04-09 15:38:19 +0000 | [diff] [blame] | 585 | } |
| 586 | |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 587 | bool GrInOrderDrawBuffer::recordStateAndShouldDraw(const GrPipelineBuilder& pipelineBuilder, |
joshualitt | 71c9260 | 2015-01-14 08:12:47 -0800 | [diff] [blame] | 588 | const GrPrimitiveProcessor* primProc, |
bsalomon | 3e79124 | 2014-12-17 13:43:13 -0800 | [diff] [blame] | 589 | const GrScissorState& scissor, |
bsalomon | 50785a3 | 2015-02-06 07:02:37 -0800 | [diff] [blame] | 590 | const SkRect* devBounds) { |
| 591 | GrDeviceCoordTexture dstCopy; |
| 592 | if (!this->setupDstReadIfNecessary(pipelineBuilder, &dstCopy, devBounds)) { |
| 593 | return false; |
| 594 | } |
bsalomon | 932f866 | 2014-11-24 06:47:48 -0800 | [diff] [blame] | 595 | SetState* ss = GrNEW_APPEND_TO_RECORDER(fCmdBuffer, SetState, |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 596 | (pipelineBuilder, primProc, *this->getGpu()->caps(), |
bsalomon | 50785a3 | 2015-02-06 07:02:37 -0800 | [diff] [blame] | 597 | scissor, &dstCopy)); |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 598 | if (ss->fPipeline.mustSkip()) { |
bsalomon | 932f866 | 2014-11-24 06:47:48 -0800 | [diff] [blame] | 599 | fCmdBuffer.pop_back(); |
bsalomon | ae59b77 | 2014-11-19 08:23:49 -0800 | [diff] [blame] | 600 | return false; |
| 601 | } |
joshualitt | 873ad0e | 2015-01-20 09:08:51 -0800 | [diff] [blame] | 602 | |
| 603 | ss->fPrimitiveProcessor->initBatchTracker(&ss->fBatchTracker, |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 604 | ss->fPipeline.getInitBatchTracker()); |
joshualitt | 873ad0e | 2015-01-20 09:08:51 -0800 | [diff] [blame] | 605 | |
joshualitt | 4d8da81 | 2015-01-28 12:53:54 -0800 | [diff] [blame] | 606 | if (fPrevState && fPrevState->fPrimitiveProcessor.get() && |
joshualitt | 873ad0e | 2015-01-20 09:08:51 -0800 | [diff] [blame] | 607 | fPrevState->fPrimitiveProcessor->canMakeEqual(fPrevState->fBatchTracker, |
| 608 | *ss->fPrimitiveProcessor, |
| 609 | ss->fBatchTracker) && |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 610 | fPrevState->fPipeline.isEqual(ss->fPipeline)) { |
bsalomon | 932f866 | 2014-11-24 06:47:48 -0800 | [diff] [blame] | 611 | fCmdBuffer.pop_back(); |
| 612 | } else { |
joshualitt | 873ad0e | 2015-01-20 09:08:51 -0800 | [diff] [blame] | 613 | fPrevState = ss; |
cdalton | 6819df3 | 2014-10-15 13:43:48 -0700 | [diff] [blame] | 614 | this->recordTraceMarkersIfNecessary(); |
bsalomon | 838f62d | 2014-08-05 07:15:57 -0700 | [diff] [blame] | 615 | } |
bsalomon | ae59b77 | 2014-11-19 08:23:49 -0800 | [diff] [blame] | 616 | return true; |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 617 | } |
| 618 | |
joshualitt | 4d8da81 | 2015-01-28 12:53:54 -0800 | [diff] [blame] | 619 | bool GrInOrderDrawBuffer::recordStateAndShouldDraw(GrBatch* batch, |
| 620 | const GrPipelineBuilder& pipelineBuilder, |
| 621 | const GrScissorState& scissor, |
bsalomon | 50785a3 | 2015-02-06 07:02:37 -0800 | [diff] [blame] | 622 | const SkRect* devBounds) { |
| 623 | GrDeviceCoordTexture dstCopy; |
| 624 | if (!this->setupDstReadIfNecessary(pipelineBuilder, &dstCopy, devBounds)) { |
| 625 | return false; |
| 626 | } |
joshualitt | 4d8da81 | 2015-01-28 12:53:54 -0800 | [diff] [blame] | 627 | // TODO this gets much simpler when we have batches everywhere. |
| 628 | // If the previous command is also a set state, then we check to see if it has a Batch. If so, |
| 629 | // and we can make the two batches equal, and we can combine the states, then we make them equal |
| 630 | SetState* ss = GrNEW_APPEND_TO_RECORDER(fCmdBuffer, SetState, |
| 631 | (batch, pipelineBuilder, *this->getGpu()->caps(), scissor, |
bsalomon | 50785a3 | 2015-02-06 07:02:37 -0800 | [diff] [blame] | 632 | &dstCopy)); |
joshualitt | 4d8da81 | 2015-01-28 12:53:54 -0800 | [diff] [blame] | 633 | if (ss->fPipeline.mustSkip()) { |
| 634 | fCmdBuffer.pop_back(); |
| 635 | return false; |
| 636 | } |
| 637 | |
| 638 | batch->initBatchTracker(ss->fPipeline.getInitBatchTracker()); |
| 639 | |
| 640 | if (fPrevState && !fPrevState->fPrimitiveProcessor.get() && |
| 641 | fPrevState->fPipeline.isEqual(ss->fPipeline)) { |
| 642 | fCmdBuffer.pop_back(); |
| 643 | } else { |
| 644 | this->closeBatch(); |
| 645 | fPrevState = ss; |
| 646 | this->recordTraceMarkersIfNecessary(); |
| 647 | } |
| 648 | return true; |
| 649 | } |
| 650 | |
cdalton | 6819df3 | 2014-10-15 13:43:48 -0700 | [diff] [blame] | 651 | void GrInOrderDrawBuffer::recordTraceMarkersIfNecessary() { |
| 652 | SkASSERT(!fCmdBuffer.empty()); |
| 653 | SkASSERT(!cmd_has_trace_marker(fCmdBuffer.back().fType)); |
mtklein | f439c77 | 2014-10-14 14:29:30 -0700 | [diff] [blame] | 654 | const GrTraceMarkerSet& activeTraceMarkers = this->getActiveTraceMarkers(); |
| 655 | if (activeTraceMarkers.count() > 0) { |
cdalton | 6819df3 | 2014-10-15 13:43:48 -0700 | [diff] [blame] | 656 | fCmdBuffer.back().fType = add_trace_bit(fCmdBuffer.back().fType); |
mtklein | f439c77 | 2014-10-14 14:29:30 -0700 | [diff] [blame] | 657 | fGpuCmdMarkers.push_back(activeTraceMarkers); |
mtklein | 07894c4 | 2014-10-13 14:00:42 -0700 | [diff] [blame] | 658 | } |
mtklein | 07894c4 | 2014-10-13 14:00:42 -0700 | [diff] [blame] | 659 | } |
joshualitt | 4d8da81 | 2015-01-28 12:53:54 -0800 | [diff] [blame] | 660 | |
joshualitt | 4d8da81 | 2015-01-28 12:53:54 -0800 | [diff] [blame] | 661 | void GrInOrderDrawBuffer::willReserveVertexAndIndexSpace(int vertexCount, |
| 662 | size_t vertexStride, |
| 663 | int indexCount) { |
| 664 | this->closeBatch(); |
| 665 | |
| 666 | // We use geometryHints() to know whether to flush the draw buffer. We |
| 667 | // can't flush if we are inside an unbalanced pushGeometrySource. |
| 668 | // Moreover, flushing blows away vertex and index data that was |
| 669 | // previously reserved. So if the vertex or index data is pulled from |
| 670 | // reserved space and won't be released by this request then we can't |
| 671 | // flush. |
| 672 | bool insideGeoPush = this->getGeoPoolStateStack().count() > 1; |
| 673 | |
| 674 | bool unreleasedVertexSpace = |
| 675 | !vertexCount && |
| 676 | kReserved_GeometrySrcType == this->getGeomSrc().fVertexSrc; |
| 677 | |
| 678 | bool unreleasedIndexSpace = |
| 679 | !indexCount && |
| 680 | kReserved_GeometrySrcType == this->getGeomSrc().fIndexSrc; |
| 681 | |
| 682 | int vcount = vertexCount; |
| 683 | int icount = indexCount; |
| 684 | |
| 685 | if (!insideGeoPush && |
| 686 | !unreleasedVertexSpace && |
| 687 | !unreleasedIndexSpace && |
| 688 | this->geometryHints(vertexStride, &vcount, &icount)) { |
| 689 | this->flush(); |
| 690 | } |
| 691 | } |