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 | 62c447d | 2014-08-08 08:08:50 -0700 | [diff] [blame] | 41 | /** We always use per-vertex colors so that rects can be batched across color changes. Sometimes we |
| 42 | have explicit local coords and sometimes not. We *could* always provide explicit local coords |
| 43 | and just duplicate the positions when the caller hasn't provided a local coord rect, but we |
| 44 | haven't seen a use case which frequently switches between local rect and no local rect draws. |
| 45 | |
| 46 | The color param is used to determine whether the opaque hint can be set on the draw state. |
| 47 | The caller must populate the vertex colors itself. |
| 48 | |
| 49 | The vertex attrib order is always pos, color, [local coords]. |
| 50 | */ |
joshualitt | 8fc6c2d | 2014-12-22 15:27:05 -0800 | [diff] [blame] | 51 | static const GrGeometryProcessor* create_rect_gp(bool hasExplicitLocalCoords, |
| 52 | GrColor color, |
| 53 | const SkMatrix* localMatrix) { |
joshualitt | 5478d42 | 2014-11-14 16:00:38 -0800 | [diff] [blame] | 54 | uint32_t flags = GrDefaultGeoProcFactory::kPosition_GPType | |
| 55 | GrDefaultGeoProcFactory::kColor_GPType; |
joshualitt | 8fc6c2d | 2014-12-22 15:27:05 -0800 | [diff] [blame] | 56 | flags |= hasExplicitLocalCoords ? GrDefaultGeoProcFactory::kLocalCoord_GPType : 0; |
| 57 | if (localMatrix) { |
joshualitt | 8059eb9 | 2014-12-29 15:10:07 -0800 | [diff] [blame] | 58 | return GrDefaultGeoProcFactory::Create(flags, color, SkMatrix::I(), *localMatrix, |
| 59 | GrColorIsOpaque(color)); |
joshualitt | 8fc6c2d | 2014-12-22 15:27:05 -0800 | [diff] [blame] | 60 | } else { |
joshualitt | 8059eb9 | 2014-12-29 15:10:07 -0800 | [diff] [blame] | 61 | return GrDefaultGeoProcFactory::Create(flags, color, SkMatrix::I(), SkMatrix::I(), |
| 62 | GrColorIsOpaque(color)); |
joshualitt | 8fc6c2d | 2014-12-22 15:27:05 -0800 | [diff] [blame] | 63 | } |
bsalomon | 62c447d | 2014-08-08 08:08:50 -0700 | [diff] [blame] | 64 | } |
robertphillips@google.com | 4290330 | 2013-04-20 12:26:07 +0000 | [diff] [blame] | 65 | |
cdalton | 3fc6a2f | 2014-11-13 11:54:20 -0800 | [diff] [blame] | 66 | static bool path_fill_type_is_winding(const GrStencilSettings& pathStencilSettings) { |
| 67 | static const GrStencilSettings::Face pathFace = GrStencilSettings::kFront_Face; |
| 68 | bool isWinding = kInvert_StencilOp != pathStencilSettings.passOp(pathFace); |
| 69 | if (isWinding) { |
| 70 | // Double check that it is in fact winding. |
| 71 | SkASSERT(kIncClamp_StencilOp == pathStencilSettings.passOp(pathFace)); |
| 72 | SkASSERT(kIncClamp_StencilOp == pathStencilSettings.failOp(pathFace)); |
| 73 | SkASSERT(0x1 != pathStencilSettings.writeMask(pathFace)); |
| 74 | SkASSERT(!pathStencilSettings.isTwoSided()); |
| 75 | } |
| 76 | return isWinding; |
| 77 | } |
| 78 | |
| 79 | template<typename T> static void reset_data_buffer(SkTDArray<T>* buffer, int minReserve) { |
| 80 | // Assume the next time this buffer fills up it will use approximately the same amount |
| 81 | // of space as last time. Only resize if we're using less than a third of the |
| 82 | // allocated space, and leave enough for 50% growth over last time. |
| 83 | if (3 * buffer->count() < buffer->reserved() && buffer->reserved() > minReserve) { |
| 84 | int reserve = SkTMax(minReserve, buffer->count() * 3 / 2); |
| 85 | buffer->reset(); |
| 86 | buffer->setReserve(reserve); |
| 87 | } else { |
| 88 | buffer->rewind(); |
| 89 | } |
| 90 | } |
| 91 | |
joshualitt | ee72dde | 2015-02-23 07:16:10 -0800 | [diff] [blame^] | 92 | class RectBatch : public GrBatch { |
| 93 | public: |
| 94 | struct Geometry { |
| 95 | GrColor fColor; |
| 96 | SkMatrix fViewMatrix; |
| 97 | SkRect fRect; |
| 98 | bool fHasLocalRect; |
| 99 | bool fHasLocalMatrix; |
| 100 | SkRect fLocalRect; |
| 101 | SkMatrix fLocalMatrix; |
| 102 | }; |
| 103 | |
| 104 | static GrBatch* Create(const Geometry& geometry) { |
| 105 | return SkNEW_ARGS(RectBatch, (geometry)); |
| 106 | } |
| 107 | |
| 108 | const char* name() const SK_OVERRIDE { return "RectBatch"; } |
| 109 | |
| 110 | void getInvariantOutputColor(GrInitInvariantOutput* out) const SK_OVERRIDE { |
| 111 | // When this is called on a batch, there is only one geometry bundle |
| 112 | if (GrColorIsOpaque(fGeoData[0].fColor)) { |
| 113 | out->setUnknownOpaqueFourComponents(); |
| 114 | } else { |
| 115 | out->setUnknownFourComponents(); |
| 116 | } |
| 117 | } |
| 118 | |
| 119 | void getInvariantOutputCoverage(GrInitInvariantOutput* out) const SK_OVERRIDE { |
| 120 | out->setUnknownSingleComponent(); |
| 121 | } |
| 122 | |
| 123 | void initBatchTracker(const GrPipelineInfo& init) SK_OVERRIDE { |
| 124 | // Handle any color overrides |
| 125 | if (init.fColorIgnored) { |
| 126 | fGeoData[0].fColor = GrColor_ILLEGAL; |
| 127 | } else if (GrColor_ILLEGAL != init.fOverrideColor) { |
| 128 | fGeoData[0].fColor = init.fOverrideColor; |
| 129 | } |
| 130 | |
| 131 | // setup batch properties |
| 132 | fBatch.fColorIgnored = init.fColorIgnored; |
| 133 | fBatch.fColor = fGeoData[0].fColor; |
| 134 | fBatch.fUsesLocalCoords = init.fUsesLocalCoords; |
| 135 | fBatch.fCoverageIgnored = init.fCoverageIgnored; |
| 136 | } |
| 137 | |
| 138 | void generateGeometry(GrBatchTarget* batchTarget, const GrPipeline* pipeline) SK_OVERRIDE { |
| 139 | // Go to device coords to allow batching across matrix changes |
| 140 | SkMatrix invert = SkMatrix::I(); |
| 141 | |
| 142 | // if we have a local rect, then we apply the localMatrix directly to the localRect to |
| 143 | // generate vertex local coords |
| 144 | bool hasExplicitLocalCoords = this->hasLocalRect(); |
| 145 | if (!hasExplicitLocalCoords) { |
| 146 | if (!this->viewMatrix().isIdentity() && !this->viewMatrix().invert(&invert)) { |
| 147 | SkDebugf("Could not invert\n"); |
| 148 | return; |
| 149 | } |
| 150 | |
| 151 | if (this->hasLocalMatrix()) { |
| 152 | invert.preConcat(this->localMatrix()); |
| 153 | } |
| 154 | } |
| 155 | |
| 156 | SkAutoTUnref<const GrGeometryProcessor> gp(create_rect_gp(hasExplicitLocalCoords, |
| 157 | this->color(), |
| 158 | &invert)); |
| 159 | |
| 160 | batchTarget->initDraw(gp, pipeline); |
| 161 | |
| 162 | // TODO this is hacky, but the only way we have to initialize the GP is to use the |
| 163 | // GrPipelineInfo struct so we can generate the correct shader. Once we have GrBatch |
| 164 | // everywhere we can remove this nastiness |
| 165 | GrPipelineInfo init; |
| 166 | init.fColorIgnored = fBatch.fColorIgnored; |
| 167 | init.fOverrideColor = GrColor_ILLEGAL; |
| 168 | init.fCoverageIgnored = fBatch.fCoverageIgnored; |
| 169 | init.fUsesLocalCoords = this->usesLocalCoords(); |
| 170 | gp->initBatchTracker(batchTarget->currentBatchTracker(), init); |
| 171 | |
| 172 | size_t vertexStride = gp->getVertexStride(); |
| 173 | |
| 174 | SkASSERT(hasExplicitLocalCoords ? |
| 175 | vertexStride == sizeof(GrDefaultGeoProcFactory::PositionColorLocalCoordAttr) : |
| 176 | vertexStride == sizeof(GrDefaultGeoProcFactory::PositionColorAttr)); |
| 177 | |
| 178 | int instanceCount = fGeoData.count(); |
| 179 | int vertexCount = kVertsPerRect * instanceCount; |
| 180 | |
| 181 | const GrVertexBuffer* vertexBuffer; |
| 182 | int firstVertex; |
| 183 | |
| 184 | void* vertices = batchTarget->vertexPool()->makeSpace(vertexStride, |
| 185 | vertexCount, |
| 186 | &vertexBuffer, |
| 187 | &firstVertex); |
| 188 | |
| 189 | for (int i = 0; i < instanceCount; i++) { |
| 190 | const Geometry& args = fGeoData[i]; |
| 191 | |
| 192 | intptr_t offset = GrTCast<intptr_t>(vertices) + kVertsPerRect * i * vertexStride; |
| 193 | SkPoint* positions = GrTCast<SkPoint*>(offset); |
| 194 | |
| 195 | positions->setRectFan(args.fRect.fLeft, args.fRect.fTop, |
| 196 | args.fRect.fRight, args.fRect.fBottom, vertexStride); |
| 197 | args.fViewMatrix.mapPointsWithStride(positions, vertexStride, kVertsPerRect); |
| 198 | |
| 199 | if (args.fHasLocalRect) { |
| 200 | static const int kLocalOffset = sizeof(SkPoint) + sizeof(GrColor); |
| 201 | SkPoint* coords = GrTCast<SkPoint*>(offset + kLocalOffset); |
| 202 | coords->setRectFan(args.fLocalRect.fLeft, args.fLocalRect.fTop, |
| 203 | args.fLocalRect.fRight, args.fLocalRect.fBottom, |
| 204 | vertexStride); |
| 205 | if (args.fHasLocalMatrix) { |
| 206 | args.fLocalMatrix.mapPointsWithStride(coords, vertexStride, kVertsPerRect); |
| 207 | } |
| 208 | } |
| 209 | |
| 210 | static const int kColorOffset = sizeof(SkPoint); |
| 211 | GrColor* vertColor = GrTCast<GrColor*>(offset + kColorOffset); |
| 212 | for (int j = 0; j < 4; ++j) { |
| 213 | *vertColor = args.fColor; |
| 214 | vertColor = (GrColor*) ((intptr_t) vertColor + vertexStride); |
| 215 | } |
| 216 | } |
| 217 | |
| 218 | const GrIndexBuffer* quadIndexBuffer = batchTarget->quadIndexBuffer(); |
| 219 | |
| 220 | GrDrawTarget::DrawInfo drawInfo; |
| 221 | drawInfo.setPrimitiveType(kTriangles_GrPrimitiveType); |
| 222 | drawInfo.setStartVertex(0); |
| 223 | drawInfo.setStartIndex(0); |
| 224 | drawInfo.setVerticesPerInstance(kVertsPerRect); |
| 225 | drawInfo.setIndicesPerInstance(kIndicesPerRect); |
| 226 | drawInfo.adjustStartVertex(firstVertex); |
| 227 | drawInfo.setVertexBuffer(vertexBuffer); |
| 228 | drawInfo.setIndexBuffer(quadIndexBuffer); |
| 229 | |
| 230 | int maxInstancesPerDraw = quadIndexBuffer->maxQuads(); |
| 231 | while (instanceCount) { |
| 232 | drawInfo.setInstanceCount(SkTMin(instanceCount, maxInstancesPerDraw)); |
| 233 | drawInfo.setVertexCount(drawInfo.instanceCount() * drawInfo.verticesPerInstance()); |
| 234 | drawInfo.setIndexCount(drawInfo.instanceCount() * drawInfo.indicesPerInstance()); |
| 235 | |
| 236 | batchTarget->draw(drawInfo); |
| 237 | |
| 238 | drawInfo.setStartVertex(drawInfo.startVertex() + drawInfo.vertexCount()); |
| 239 | instanceCount -= drawInfo.instanceCount(); |
| 240 | } |
| 241 | } |
| 242 | |
| 243 | SkSTArray<1, Geometry, true>* geoData() { return &fGeoData; } |
| 244 | |
| 245 | private: |
| 246 | RectBatch(const Geometry& geometry) { |
| 247 | this->initClassID<RectBatch>(); |
| 248 | fGeoData.push_back(geometry); |
| 249 | } |
| 250 | |
| 251 | GrColor color() const { return fBatch.fColor; } |
| 252 | bool usesLocalCoords() const { return fBatch.fUsesLocalCoords; } |
| 253 | bool colorIgnored() const { return fBatch.fColorIgnored; } |
| 254 | const SkMatrix& viewMatrix() const { return fGeoData[0].fViewMatrix; } |
| 255 | const SkMatrix& localMatrix() const { return fGeoData[0].fLocalMatrix; } |
| 256 | bool hasLocalRect() const { return fGeoData[0].fHasLocalRect; } |
| 257 | bool hasLocalMatrix() const { return fGeoData[0].fHasLocalMatrix; } |
| 258 | |
| 259 | bool onCombineIfPossible(GrBatch* t) SK_OVERRIDE { |
| 260 | RectBatch* that = t->cast<RectBatch>(); |
| 261 | |
| 262 | if (this->hasLocalRect() != that->hasLocalRect()) { |
| 263 | return false; |
| 264 | } |
| 265 | |
| 266 | SkASSERT(this->usesLocalCoords() == that->usesLocalCoords()); |
| 267 | if (!this->hasLocalRect() && this->usesLocalCoords()) { |
| 268 | if (!this->viewMatrix().cheapEqualTo(that->viewMatrix())) { |
| 269 | return false; |
| 270 | } |
| 271 | |
| 272 | if (this->hasLocalMatrix() != that->hasLocalMatrix()) { |
| 273 | return false; |
| 274 | } |
| 275 | |
| 276 | if (this->hasLocalMatrix() && !this->localMatrix().cheapEqualTo(that->localMatrix())) { |
| 277 | return false; |
| 278 | } |
| 279 | } |
| 280 | |
| 281 | if (this->color() != that->color()) { |
| 282 | fBatch.fColor = GrColor_ILLEGAL; |
| 283 | } |
| 284 | fGeoData.push_back_n(that->geoData()->count(), that->geoData()->begin()); |
| 285 | return true; |
| 286 | } |
| 287 | |
| 288 | struct BatchTracker { |
| 289 | GrColor fColor; |
| 290 | bool fUsesLocalCoords; |
| 291 | bool fColorIgnored; |
| 292 | bool fCoverageIgnored; |
| 293 | }; |
| 294 | |
| 295 | const static int kVertsPerRect = 4; |
| 296 | const static int kIndicesPerRect = 6; |
| 297 | |
| 298 | BatchTracker fBatch; |
| 299 | SkSTArray<1, Geometry, true> fGeoData; |
| 300 | }; |
| 301 | |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 302 | void GrInOrderDrawBuffer::onDrawRect(GrPipelineBuilder* pipelineBuilder, |
joshualitt | 2e3b3e3 | 2014-12-09 13:31:14 -0800 | [diff] [blame] | 303 | GrColor color, |
joshualitt | 8059eb9 | 2014-12-29 15:10:07 -0800 | [diff] [blame] | 304 | const SkMatrix& viewMatrix, |
joshualitt | 9853cce | 2014-11-17 14:22:48 -0800 | [diff] [blame] | 305 | const SkRect& rect, |
commit-bot@chromium.org | fd03d4a | 2013-07-17 21:39:42 +0000 | [diff] [blame] | 306 | const SkRect* localRect, |
bsalomon@google.com | 0406b9e | 2013-04-02 21:00:15 +0000 | [diff] [blame] | 307 | const SkMatrix* localMatrix) { |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 308 | GrPipelineBuilder::AutoRestoreEffects are(pipelineBuilder); |
joshualitt | ee72dde | 2015-02-23 07:16:10 -0800 | [diff] [blame^] | 309 | RectBatch::Geometry geometry; |
| 310 | geometry.fColor = color; |
| 311 | geometry.fViewMatrix = viewMatrix; |
| 312 | geometry.fRect = rect; |
bsalomon@google.com | d62e88e | 2013-02-01 14:19:27 +0000 | [diff] [blame] | 313 | |
bsalomon | 49f085d | 2014-09-05 13:34:00 -0700 | [diff] [blame] | 314 | if (localRect) { |
joshualitt | ee72dde | 2015-02-23 07:16:10 -0800 | [diff] [blame^] | 315 | geometry.fHasLocalRect = true; |
| 316 | geometry.fLocalRect = *localRect; |
| 317 | } else { |
| 318 | geometry.fHasLocalRect = false; |
bsalomon@google.com | d62e88e | 2013-02-01 14:19:27 +0000 | [diff] [blame] | 319 | } |
| 320 | |
joshualitt | ee72dde | 2015-02-23 07:16:10 -0800 | [diff] [blame^] | 321 | if (localMatrix) { |
| 322 | geometry.fHasLocalMatrix = true; |
| 323 | geometry.fLocalMatrix = *localMatrix; |
| 324 | } else { |
| 325 | geometry.fHasLocalMatrix = false; |
bsalomon@google.com | d62e88e | 2013-02-01 14:19:27 +0000 | [diff] [blame] | 326 | } |
| 327 | |
joshualitt | ee72dde | 2015-02-23 07:16:10 -0800 | [diff] [blame^] | 328 | SkAutoTUnref<GrBatch> batch(RectBatch::Create(geometry)); |
| 329 | |
| 330 | SkRect bounds = rect; |
| 331 | viewMatrix.mapRect(&bounds); |
| 332 | this->drawBatch(pipelineBuilder, batch, &bounds); |
bsalomon@google.com | d62e88e | 2013-02-01 14:19:27 +0000 | [diff] [blame] | 333 | } |
| 334 | |
egdaniel | e36914c | 2015-02-13 09:00:33 -0800 | [diff] [blame] | 335 | int GrInOrderDrawBuffer::concatInstancedDraw(const DrawInfo& info) { |
cdalton | 6819df3 | 2014-10-15 13:43:48 -0700 | [diff] [blame] | 336 | SkASSERT(!fCmdBuffer.empty()); |
tfarina@chromium.org | f6de475 | 2013-08-17 00:02:59 +0000 | [diff] [blame] | 337 | SkASSERT(info.isInstanced()); |
bsalomon@google.com | d62e88e | 2013-02-01 14:19:27 +0000 | [diff] [blame] | 338 | |
bsalomon@google.com | 934c570 | 2012-03-20 21:17:58 +0000 | [diff] [blame] | 339 | const GeometrySrcState& geomSrc = this->getGeomSrc(); |
| 340 | |
bsalomon@google.com | d62e88e | 2013-02-01 14:19:27 +0000 | [diff] [blame] | 341 | // we only attempt to concat the case when reserved verts are used with a client-specified index |
| 342 | // buffer. To make this work with client-specified VBs we'd need to know if the VB was updated |
| 343 | // between draws. |
| 344 | if (kReserved_GeometrySrcType != geomSrc.fVertexSrc || |
| 345 | kBuffer_GeometrySrcType != geomSrc.fIndexSrc) { |
| 346 | return 0; |
bsalomon@google.com | 934c570 | 2012-03-20 21:17:58 +0000 | [diff] [blame] | 347 | } |
bsalomon@google.com | d62e88e | 2013-02-01 14:19:27 +0000 | [diff] [blame] | 348 | // Check if there is a draw info that is compatible that uses the same VB from the pool and |
| 349 | // the same IB |
robertphillips | e5e72f1 | 2015-02-17 09:14:33 -0800 | [diff] [blame] | 350 | if (Cmd::kDraw_Cmd != fCmdBuffer.back().type()) { |
bsalomon@google.com | d62e88e | 2013-02-01 14:19:27 +0000 | [diff] [blame] | 351 | return 0; |
| 352 | } |
| 353 | |
cdalton | 6819df3 | 2014-10-15 13:43:48 -0700 | [diff] [blame] | 354 | Draw* draw = static_cast<Draw*>(&fCmdBuffer.back()); |
bsalomon@google.com | d62e88e | 2013-02-01 14:19:27 +0000 | [diff] [blame] | 355 | |
cdalton | 6819df3 | 2014-10-15 13:43:48 -0700 | [diff] [blame] | 356 | if (!draw->fInfo.isInstanced() || |
joshualitt | 4d8da81 | 2015-01-28 12:53:54 -0800 | [diff] [blame] | 357 | draw->fInfo.primitiveType() != info.primitiveType() || |
cdalton | 6819df3 | 2014-10-15 13:43:48 -0700 | [diff] [blame] | 358 | draw->fInfo.verticesPerInstance() != info.verticesPerInstance() || |
| 359 | draw->fInfo.indicesPerInstance() != info.indicesPerInstance() || |
bsalomon | 371bcbc | 2014-12-01 08:19:34 -0800 | [diff] [blame] | 360 | draw->fInfo.vertexBuffer() != info.vertexBuffer() || |
joshualitt | 54e0c12 | 2014-11-19 09:38:51 -0800 | [diff] [blame] | 361 | draw->fInfo.indexBuffer() != geomSrc.fIndexBuffer) { |
bsalomon@google.com | d62e88e | 2013-02-01 14:19:27 +0000 | [diff] [blame] | 362 | return 0; |
| 363 | } |
bsalomon | 371bcbc | 2014-12-01 08:19:34 -0800 | [diff] [blame] | 364 | if (draw->fInfo.startVertex() + draw->fInfo.vertexCount() != info.startVertex()) { |
bsalomon@google.com | d62e88e | 2013-02-01 14:19:27 +0000 | [diff] [blame] | 365 | return 0; |
| 366 | } |
| 367 | |
bsalomon@google.com | d62e88e | 2013-02-01 14:19:27 +0000 | [diff] [blame] | 368 | // how many instances can be concat'ed onto draw given the size of the index buffer |
| 369 | int instancesToConcat = this->indexCountInCurrentSource() / info.indicesPerInstance(); |
cdalton | 6819df3 | 2014-10-15 13:43:48 -0700 | [diff] [blame] | 370 | instancesToConcat -= draw->fInfo.instanceCount(); |
commit-bot@chromium.org | 972f9cd | 2014-03-28 17:58:28 +0000 | [diff] [blame] | 371 | instancesToConcat = SkTMin(instancesToConcat, info.instanceCount()); |
bsalomon@google.com | d62e88e | 2013-02-01 14:19:27 +0000 | [diff] [blame] | 372 | |
cdalton | 6819df3 | 2014-10-15 13:43:48 -0700 | [diff] [blame] | 373 | draw->fInfo.adjustInstanceCount(instancesToConcat); |
commit-bot@chromium.org | 2a05de0 | 2014-03-25 15:17:32 +0000 | [diff] [blame] | 374 | |
| 375 | // update last fGpuCmdMarkers to include any additional trace markers that have been added |
| 376 | if (this->getActiveTraceMarkers().count() > 0) { |
robertphillips | e5e72f1 | 2015-02-17 09:14:33 -0800 | [diff] [blame] | 377 | if (draw->isTraced()) { |
commit-bot@chromium.org | 2a05de0 | 2014-03-25 15:17:32 +0000 | [diff] [blame] | 378 | fGpuCmdMarkers.back().addSet(this->getActiveTraceMarkers()); |
| 379 | } else { |
| 380 | fGpuCmdMarkers.push_back(this->getActiveTraceMarkers()); |
robertphillips | e5e72f1 | 2015-02-17 09:14:33 -0800 | [diff] [blame] | 381 | draw->makeTraced(); |
commit-bot@chromium.org | 2a05de0 | 2014-03-25 15:17:32 +0000 | [diff] [blame] | 382 | } |
| 383 | } |
| 384 | |
bsalomon@google.com | d62e88e | 2013-02-01 14:19:27 +0000 | [diff] [blame] | 385 | return instancesToConcat; |
bsalomon@google.com | 934c570 | 2012-03-20 21:17:58 +0000 | [diff] [blame] | 386 | } |
| 387 | |
egdaniel | e36914c | 2015-02-13 09:00:33 -0800 | [diff] [blame] | 388 | void GrInOrderDrawBuffer::onDraw(const GrGeometryProcessor* gp, |
joshualitt | 9853cce | 2014-11-17 14:22:48 -0800 | [diff] [blame] | 389 | const DrawInfo& info, |
egdaniel | e36914c | 2015-02-13 09:00:33 -0800 | [diff] [blame] | 390 | const PipelineInfo& pipelineInfo) { |
joshualitt | 7eb8c7b | 2014-11-18 14:24:27 -0800 | [diff] [blame] | 391 | SkASSERT(info.vertexBuffer() && (!info.isIndexed() || info.indexBuffer())); |
joshualitt | 4d8da81 | 2015-01-28 12:53:54 -0800 | [diff] [blame] | 392 | this->closeBatch(); |
| 393 | |
egdaniel | e36914c | 2015-02-13 09:00:33 -0800 | [diff] [blame] | 394 | if (!this->setupPipelineAndShouldDraw(gp, pipelineInfo)) { |
bsalomon | ae59b77 | 2014-11-19 08:23:49 -0800 | [diff] [blame] | 395 | return; |
| 396 | } |
bsalomon@google.com | 86afc2a | 2011-02-16 16:12:19 +0000 | [diff] [blame] | 397 | |
bsalomon | b3e3a95 | 2014-09-19 11:10:40 -0700 | [diff] [blame] | 398 | Draw* draw; |
bsalomon@google.com | d62e88e | 2013-02-01 14:19:27 +0000 | [diff] [blame] | 399 | if (info.isInstanced()) { |
egdaniel | e36914c | 2015-02-13 09:00:33 -0800 | [diff] [blame] | 400 | int instancesConcated = this->concatInstancedDraw(info); |
bsalomon@google.com | d62e88e | 2013-02-01 14:19:27 +0000 | [diff] [blame] | 401 | if (info.instanceCount() > instancesConcated) { |
joshualitt | 54e0c12 | 2014-11-19 09:38:51 -0800 | [diff] [blame] | 402 | draw = GrNEW_APPEND_TO_RECORDER(fCmdBuffer, Draw, (info)); |
cdalton | 6819df3 | 2014-10-15 13:43:48 -0700 | [diff] [blame] | 403 | draw->fInfo.adjustInstanceCount(-instancesConcated); |
bsalomon@google.com | d62e88e | 2013-02-01 14:19:27 +0000 | [diff] [blame] | 404 | } else { |
| 405 | return; |
| 406 | } |
| 407 | } else { |
joshualitt | 54e0c12 | 2014-11-19 09:38:51 -0800 | [diff] [blame] | 408 | draw = GrNEW_APPEND_TO_RECORDER(fCmdBuffer, Draw, (info)); |
bsalomon@google.com | d62e88e | 2013-02-01 14:19:27 +0000 | [diff] [blame] | 409 | } |
cdalton | 6819df3 | 2014-10-15 13:43:48 -0700 | [diff] [blame] | 410 | this->recordTraceMarkersIfNecessary(); |
commit-bot@chromium.org | 9b62aa1 | 2014-03-25 11:59:40 +0000 | [diff] [blame] | 411 | } |
sugoi@google.com | 5f74cf8 | 2012-12-17 21:16:45 +0000 | [diff] [blame] | 412 | |
joshualitt | 4d8da81 | 2015-01-28 12:53:54 -0800 | [diff] [blame] | 413 | void GrInOrderDrawBuffer::onDrawBatch(GrBatch* batch, |
egdaniel | e36914c | 2015-02-13 09:00:33 -0800 | [diff] [blame] | 414 | const PipelineInfo& pipelineInfo) { |
| 415 | if (!this->setupPipelineAndShouldDraw(batch, pipelineInfo)) { |
joshualitt | 4d8da81 | 2015-01-28 12:53:54 -0800 | [diff] [blame] | 416 | return; |
| 417 | } |
| 418 | |
| 419 | // Check if there is a Batch Draw we can batch with |
robertphillips | e5e72f1 | 2015-02-17 09:14:33 -0800 | [diff] [blame] | 420 | if (Cmd::kDrawBatch_Cmd != fCmdBuffer.back().type()) { |
joshualitt | 4d8da81 | 2015-01-28 12:53:54 -0800 | [diff] [blame] | 421 | fDrawBatch = GrNEW_APPEND_TO_RECORDER(fCmdBuffer, DrawBatch, (batch)); |
| 422 | return; |
| 423 | } |
| 424 | |
| 425 | DrawBatch* draw = static_cast<DrawBatch*>(&fCmdBuffer.back()); |
| 426 | if (draw->fBatch->combineIfPossible(batch)) { |
| 427 | return; |
| 428 | } else { |
| 429 | this->closeBatch(); |
| 430 | fDrawBatch = GrNEW_APPEND_TO_RECORDER(fCmdBuffer, DrawBatch, (batch)); |
| 431 | } |
| 432 | this->recordTraceMarkersIfNecessary(); |
| 433 | } |
| 434 | |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 435 | void GrInOrderDrawBuffer::onStencilPath(const GrPipelineBuilder& pipelineBuilder, |
joshualitt | 56995b5 | 2014-12-11 15:44:02 -0800 | [diff] [blame] | 436 | const GrPathProcessor* pathProc, |
joshualitt | 9853cce | 2014-11-17 14:22:48 -0800 | [diff] [blame] | 437 | const GrPath* path, |
bsalomon | 3e79124 | 2014-12-17 13:43:13 -0800 | [diff] [blame] | 438 | const GrScissorState& scissorState, |
joshualitt | 2c93efe | 2014-11-06 12:57:13 -0800 | [diff] [blame] | 439 | const GrStencilSettings& stencilSettings) { |
joshualitt | 70f0004 | 2015-02-06 15:53:59 -0800 | [diff] [blame] | 440 | this->closeBatch(); |
| 441 | |
bsalomon | 3e79124 | 2014-12-17 13:43:13 -0800 | [diff] [blame] | 442 | StencilPath* sp = GrNEW_APPEND_TO_RECORDER(fCmdBuffer, StencilPath, |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 443 | (path, pipelineBuilder.getRenderTarget())); |
joshualitt | ee72dde | 2015-02-23 07:16:10 -0800 | [diff] [blame^] | 444 | |
bsalomon | 3e79124 | 2014-12-17 13:43:13 -0800 | [diff] [blame] | 445 | sp->fScissor = scissorState; |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 446 | sp->fUseHWAA = pipelineBuilder.isHWAntialias(); |
joshualitt | 8059eb9 | 2014-12-29 15:10:07 -0800 | [diff] [blame] | 447 | sp->fViewMatrix = pathProc->viewMatrix(); |
bsalomon | 3e79124 | 2014-12-17 13:43:13 -0800 | [diff] [blame] | 448 | sp->fStencil = stencilSettings; |
cdalton | 6819df3 | 2014-10-15 13:43:48 -0700 | [diff] [blame] | 449 | this->recordTraceMarkersIfNecessary(); |
bsalomon@google.com | 64aef2b | 2012-06-11 15:36:13 +0000 | [diff] [blame] | 450 | } |
| 451 | |
egdaniel | e36914c | 2015-02-13 09:00:33 -0800 | [diff] [blame] | 452 | void GrInOrderDrawBuffer::onDrawPath(const GrPathProcessor* pathProc, |
joshualitt | 9853cce | 2014-11-17 14:22:48 -0800 | [diff] [blame] | 453 | const GrPath* path, |
joshualitt | 2c93efe | 2014-11-06 12:57:13 -0800 | [diff] [blame] | 454 | const GrStencilSettings& stencilSettings, |
egdaniel | e36914c | 2015-02-13 09:00:33 -0800 | [diff] [blame] | 455 | const PipelineInfo& pipelineInfo) { |
joshualitt | 4d8da81 | 2015-01-28 12:53:54 -0800 | [diff] [blame] | 456 | this->closeBatch(); |
| 457 | |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 458 | // TODO: Only compare the subset of GrPipelineBuilder relevant to path covering? |
egdaniel | e36914c | 2015-02-13 09:00:33 -0800 | [diff] [blame] | 459 | if (!this->setupPipelineAndShouldDraw(pathProc, pipelineInfo)) { |
bsalomon | ae59b77 | 2014-11-19 08:23:49 -0800 | [diff] [blame] | 460 | return; |
| 461 | } |
cdalton | 6819df3 | 2014-10-15 13:43:48 -0700 | [diff] [blame] | 462 | DrawPath* dp = GrNEW_APPEND_TO_RECORDER(fCmdBuffer, DrawPath, (path)); |
joshualitt | 2c93efe | 2014-11-06 12:57:13 -0800 | [diff] [blame] | 463 | dp->fStencilSettings = stencilSettings; |
cdalton | 6819df3 | 2014-10-15 13:43:48 -0700 | [diff] [blame] | 464 | this->recordTraceMarkersIfNecessary(); |
commit-bot@chromium.org | c4dc0ad | 2013-10-09 14:11:33 +0000 | [diff] [blame] | 465 | } |
| 466 | |
egdaniel | e36914c | 2015-02-13 09:00:33 -0800 | [diff] [blame] | 467 | void GrInOrderDrawBuffer::onDrawPaths(const GrPathProcessor* pathProc, |
joshualitt | 9853cce | 2014-11-17 14:22:48 -0800 | [diff] [blame] | 468 | const GrPathRange* pathRange, |
cdalton | 55b24af | 2014-11-25 11:00:56 -0800 | [diff] [blame] | 469 | const void* indices, |
| 470 | PathIndexType indexType, |
| 471 | const float transformValues[], |
| 472 | PathTransformType transformType, |
joshualitt | 2c93efe | 2014-11-06 12:57:13 -0800 | [diff] [blame] | 473 | int count, |
joshualitt | 2c93efe | 2014-11-06 12:57:13 -0800 | [diff] [blame] | 474 | const GrStencilSettings& stencilSettings, |
egdaniel | e36914c | 2015-02-13 09:00:33 -0800 | [diff] [blame] | 475 | const PipelineInfo& pipelineInfo) { |
bsalomon | 49f085d | 2014-09-05 13:34:00 -0700 | [diff] [blame] | 476 | SkASSERT(pathRange); |
| 477 | SkASSERT(indices); |
cdalton | 55b24af | 2014-11-25 11:00:56 -0800 | [diff] [blame] | 478 | SkASSERT(transformValues); |
joshualitt | 4d8da81 | 2015-01-28 12:53:54 -0800 | [diff] [blame] | 479 | this->closeBatch(); |
| 480 | |
egdaniel | e36914c | 2015-02-13 09:00:33 -0800 | [diff] [blame] | 481 | if (!this->setupPipelineAndShouldDraw(pathProc, pipelineInfo)) { |
bsalomon | ae59b77 | 2014-11-19 08:23:49 -0800 | [diff] [blame] | 482 | return; |
| 483 | } |
cdalton | 6819df3 | 2014-10-15 13:43:48 -0700 | [diff] [blame] | 484 | |
cdalton | 55b24af | 2014-11-25 11:00:56 -0800 | [diff] [blame] | 485 | int indexBytes = GrPathRange::PathIndexSizeInBytes(indexType); |
| 486 | if (int misalign = fPathIndexBuffer.count() % indexBytes) { |
| 487 | // Add padding to the index buffer so the indices are aligned properly. |
| 488 | fPathIndexBuffer.append(indexBytes - misalign); |
| 489 | } |
| 490 | |
| 491 | char* savedIndices = fPathIndexBuffer.append(count * indexBytes, |
| 492 | reinterpret_cast<const char*>(indices)); |
| 493 | float* savedTransforms = fPathTransformBuffer.append( |
| 494 | count * GrPathRendering::PathTransformSize(transformType), |
| 495 | transformValues); |
cdalton | 6819df3 | 2014-10-15 13:43:48 -0700 | [diff] [blame] | 496 | |
robertphillips | e5e72f1 | 2015-02-17 09:14:33 -0800 | [diff] [blame] | 497 | if (Cmd::kDrawPaths_Cmd == fCmdBuffer.back().type()) { |
cdalton | 3fc6a2f | 2014-11-13 11:54:20 -0800 | [diff] [blame] | 498 | // 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] | 499 | // 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] | 500 | // equivalent to two separate draw calls if there is overlap. Blending won't work, |
| 501 | // and the combined calls may also cancel each other's winding numbers in some |
| 502 | // places. For now the winding numbers are only an issue if the fill is even/odd, |
| 503 | // because DrawPaths is currently only used for glyphs, and glyphs in the same |
| 504 | // font tend to all wind in the same direction. |
| 505 | DrawPaths* previous = static_cast<DrawPaths*>(&fCmdBuffer.back()); |
| 506 | if (pathRange == previous->pathRange() && |
cdalton | 55b24af | 2014-11-25 11:00:56 -0800 | [diff] [blame] | 507 | indexType == previous->fIndexType && |
| 508 | transformType == previous->fTransformType && |
cdalton | 3fc6a2f | 2014-11-13 11:54:20 -0800 | [diff] [blame] | 509 | stencilSettings == previous->fStencilSettings && |
| 510 | path_fill_type_is_winding(stencilSettings) && |
egdaniel | e36914c | 2015-02-13 09:00:33 -0800 | [diff] [blame] | 511 | !pipelineInfo.willBlendWithDst(pathProc)) { |
cdalton | 3fc6a2f | 2014-11-13 11:54:20 -0800 | [diff] [blame] | 512 | // Fold this DrawPaths call into the one previous. |
| 513 | previous->fCount += count; |
| 514 | return; |
| 515 | } |
| 516 | } |
| 517 | |
| 518 | DrawPaths* dp = GrNEW_APPEND_TO_RECORDER(fCmdBuffer, DrawPaths, (pathRange)); |
bsalomon | ef3fcd8 | 2014-12-12 08:51:38 -0800 | [diff] [blame] | 519 | dp->fIndicesLocation = SkToU32(savedIndices - fPathIndexBuffer.begin()); |
cdalton | 55b24af | 2014-11-25 11:00:56 -0800 | [diff] [blame] | 520 | dp->fIndexType = indexType; |
bsalomon | ef3fcd8 | 2014-12-12 08:51:38 -0800 | [diff] [blame] | 521 | dp->fTransformsLocation = SkToU32(savedTransforms - fPathTransformBuffer.begin()); |
cdalton | 55b24af | 2014-11-25 11:00:56 -0800 | [diff] [blame] | 522 | dp->fTransformType = transformType; |
| 523 | dp->fCount = count; |
joshualitt | 2c93efe | 2014-11-06 12:57:13 -0800 | [diff] [blame] | 524 | dp->fStencilSettings = stencilSettings; |
cdalton | 6819df3 | 2014-10-15 13:43:48 -0700 | [diff] [blame] | 525 | |
| 526 | this->recordTraceMarkersIfNecessary(); |
commit-bot@chromium.org | 9b62aa1 | 2014-03-25 11:59:40 +0000 | [diff] [blame] | 527 | } |
| 528 | |
bsalomon | 63b2196 | 2014-11-05 07:05:34 -0800 | [diff] [blame] | 529 | void GrInOrderDrawBuffer::onClear(const SkIRect* rect, GrColor color, |
| 530 | bool canIgnoreRect, GrRenderTarget* renderTarget) { |
joshualitt | 9853cce | 2014-11-17 14:22:48 -0800 | [diff] [blame] | 531 | SkASSERT(renderTarget); |
joshualitt | 70f0004 | 2015-02-06 15:53:59 -0800 | [diff] [blame] | 532 | this->closeBatch(); |
| 533 | |
commit-bot@chromium.org | fd03d4a | 2013-07-17 21:39:42 +0000 | [diff] [blame] | 534 | SkIRect r; |
bsalomon@google.com | 6aa25c3 | 2011-04-27 19:55:29 +0000 | [diff] [blame] | 535 | if (NULL == rect) { |
| 536 | // We could do something smart and remove previous draws and clears to |
| 537 | // the current render target. If we get that smart we have to make sure |
| 538 | // those draws aren't read before this clear (render-to-texture). |
bsalomon@google.com | 1b3ce47 | 2012-08-17 13:43:08 +0000 | [diff] [blame] | 539 | r.setLTRB(0, 0, renderTarget->width(), renderTarget->height()); |
bsalomon@google.com | 6aa25c3 | 2011-04-27 19:55:29 +0000 | [diff] [blame] | 540 | rect = &r; |
| 541 | } |
cdalton | 6819df3 | 2014-10-15 13:43:48 -0700 | [diff] [blame] | 542 | Clear* clr = GrNEW_APPEND_TO_RECORDER(fCmdBuffer, Clear, (renderTarget)); |
commit-bot@chromium.org | 28361fa | 2014-03-28 16:08:05 +0000 | [diff] [blame] | 543 | GrColorIsPMAssert(color); |
bsalomon@google.com | a4f6b10 | 2012-06-26 21:04:22 +0000 | [diff] [blame] | 544 | clr->fColor = color; |
| 545 | clr->fRect = *rect; |
robertphillips@google.com | 56ce48a | 2013-10-31 21:44:25 +0000 | [diff] [blame] | 546 | clr->fCanIgnoreRect = canIgnoreRect; |
cdalton | 6819df3 | 2014-10-15 13:43:48 -0700 | [diff] [blame] | 547 | this->recordTraceMarkersIfNecessary(); |
bsalomon@google.com | 0b335c1 | 2011-04-25 19:17:44 +0000 | [diff] [blame] | 548 | } |
| 549 | |
joshualitt | 6db519c | 2014-10-29 08:48:18 -0700 | [diff] [blame] | 550 | void GrInOrderDrawBuffer::clearStencilClip(const SkIRect& rect, |
| 551 | bool insideClip, |
| 552 | GrRenderTarget* renderTarget) { |
joshualitt | 9853cce | 2014-11-17 14:22:48 -0800 | [diff] [blame] | 553 | SkASSERT(renderTarget); |
joshualitt | 70f0004 | 2015-02-06 15:53:59 -0800 | [diff] [blame] | 554 | this->closeBatch(); |
| 555 | |
joshualitt | 6db519c | 2014-10-29 08:48:18 -0700 | [diff] [blame] | 556 | ClearStencilClip* clr = GrNEW_APPEND_TO_RECORDER(fCmdBuffer, ClearStencilClip, (renderTarget)); |
| 557 | clr->fRect = rect; |
| 558 | clr->fInsideClip = insideClip; |
| 559 | this->recordTraceMarkersIfNecessary(); |
| 560 | } |
| 561 | |
commit-bot@chromium.org | 28361fa | 2014-03-28 16:08:05 +0000 | [diff] [blame] | 562 | void GrInOrderDrawBuffer::discard(GrRenderTarget* renderTarget) { |
bsalomon | 89c6298 | 2014-11-03 12:08:42 -0800 | [diff] [blame] | 563 | SkASSERT(renderTarget); |
joshualitt | 70f0004 | 2015-02-06 15:53:59 -0800 | [diff] [blame] | 564 | this->closeBatch(); |
| 565 | |
commit-bot@chromium.org | 28361fa | 2014-03-28 16:08:05 +0000 | [diff] [blame] | 566 | if (!this->caps()->discardRenderTargetSupport()) { |
| 567 | return; |
| 568 | } |
cdalton | 6819df3 | 2014-10-15 13:43:48 -0700 | [diff] [blame] | 569 | Clear* clr = GrNEW_APPEND_TO_RECORDER(fCmdBuffer, Clear, (renderTarget)); |
commit-bot@chromium.org | 28361fa | 2014-03-28 16:08:05 +0000 | [diff] [blame] | 570 | clr->fColor = GrColor_ILLEGAL; |
cdalton | 6819df3 | 2014-10-15 13:43:48 -0700 | [diff] [blame] | 571 | this->recordTraceMarkersIfNecessary(); |
commit-bot@chromium.org | 28361fa | 2014-03-28 16:08:05 +0000 | [diff] [blame] | 572 | } |
| 573 | |
bsalomon | 371bcbc | 2014-12-01 08:19:34 -0800 | [diff] [blame] | 574 | void GrInOrderDrawBuffer::onReset() { |
cdalton | 6819df3 | 2014-10-15 13:43:48 -0700 | [diff] [blame] | 575 | fCmdBuffer.reset(); |
bsalomon | 932f866 | 2014-11-24 06:47:48 -0800 | [diff] [blame] | 576 | fPrevState = NULL; |
cdalton | 3fc6a2f | 2014-11-13 11:54:20 -0800 | [diff] [blame] | 577 | reset_data_buffer(&fPathIndexBuffer, kPathIdxBufferMinReserve); |
| 578 | reset_data_buffer(&fPathTransformBuffer, kPathXformBufferMinReserve); |
commit-bot@chromium.org | 2a05de0 | 2014-03-25 15:17:32 +0000 | [diff] [blame] | 579 | fGpuCmdMarkers.reset(); |
joshualitt | 4d8da81 | 2015-01-28 12:53:54 -0800 | [diff] [blame] | 580 | fDrawBatch = NULL; |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 581 | } |
| 582 | |
bsalomon | 371bcbc | 2014-12-01 08:19:34 -0800 | [diff] [blame] | 583 | void GrInOrderDrawBuffer::onFlush() { |
cdalton | 6819df3 | 2014-10-15 13:43:48 -0700 | [diff] [blame] | 584 | if (fCmdBuffer.empty()) { |
robertphillips@google.com | 1267fbd | 2013-07-03 18:37:27 +0000 | [diff] [blame] | 585 | return; |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 586 | } |
bsalomon@google.com | 6e4e650 | 2013-02-25 20:12:45 +0000 | [diff] [blame] | 587 | |
joshualitt | c2893c5 | 2015-01-28 06:54:30 -0800 | [diff] [blame] | 588 | // Updated every time we find a set state cmd to reflect the current state in the playback |
| 589 | // stream. |
| 590 | SetState* currentState = NULL; |
| 591 | |
joshualitt | 4d8da81 | 2015-01-28 12:53:54 -0800 | [diff] [blame] | 592 | // TODO this is temporary while batch is being rolled out |
| 593 | this->closeBatch(); |
| 594 | this->getVertexAllocPool()->unmap(); |
| 595 | this->getIndexAllocPool()->unmap(); |
| 596 | fBatchTarget.preFlush(); |
| 597 | |
| 598 | currentState = NULL; |
| 599 | CmdBuffer::Iter iter(fCmdBuffer); |
| 600 | |
| 601 | int currCmdMarker = 0; |
| 602 | |
joshualitt | 7bc18b7 | 2015-02-03 16:41:41 -0800 | [diff] [blame] | 603 | int i = 0; |
cdalton | 6819df3 | 2014-10-15 13:43:48 -0700 | [diff] [blame] | 604 | while (iter.next()) { |
joshualitt | 7bc18b7 | 2015-02-03 16:41:41 -0800 | [diff] [blame] | 605 | i++; |
commit-bot@chromium.org | 2a05de0 | 2014-03-25 15:17:32 +0000 | [diff] [blame] | 606 | GrGpuTraceMarker newMarker("", -1); |
egdaniel | d78a168 | 2014-07-09 10:41:26 -0700 | [diff] [blame] | 607 | SkString traceString; |
robertphillips | e5e72f1 | 2015-02-17 09:14:33 -0800 | [diff] [blame] | 608 | if (iter->isTraced()) { |
egdaniel | d78a168 | 2014-07-09 10:41:26 -0700 | [diff] [blame] | 609 | traceString = fGpuCmdMarkers[currCmdMarker].toString(); |
commit-bot@chromium.org | 2a05de0 | 2014-03-25 15:17:32 +0000 | [diff] [blame] | 610 | newMarker.fMarker = traceString.c_str(); |
bsalomon | 371bcbc | 2014-12-01 08:19:34 -0800 | [diff] [blame] | 611 | this->getGpu()->addGpuTraceMarker(&newMarker); |
commit-bot@chromium.org | 2a05de0 | 2014-03-25 15:17:32 +0000 | [diff] [blame] | 612 | ++currCmdMarker; |
| 613 | } |
cdalton | 6819df3 | 2014-10-15 13:43:48 -0700 | [diff] [blame] | 614 | |
joshualitt | 4d8da81 | 2015-01-28 12:53:54 -0800 | [diff] [blame] | 615 | // TODO temporary hack |
robertphillips | e5e72f1 | 2015-02-17 09:14:33 -0800 | [diff] [blame] | 616 | if (Cmd::kDrawBatch_Cmd == iter->type()) { |
joshualitt | 7bc18b7 | 2015-02-03 16:41:41 -0800 | [diff] [blame] | 617 | DrawBatch* db = reinterpret_cast<DrawBatch*>(iter.get()); |
| 618 | fBatchTarget.flushNext(db->fBatch->numberOfDraws()); |
joshualitt | 4d8da81 | 2015-01-28 12:53:54 -0800 | [diff] [blame] | 619 | continue; |
| 620 | } |
| 621 | |
robertphillips | e5e72f1 | 2015-02-17 09:14:33 -0800 | [diff] [blame] | 622 | if (Cmd::kSetState_Cmd == iter->type()) { |
joshualitt | 9853cce | 2014-11-17 14:22:48 -0800 | [diff] [blame] | 623 | SetState* ss = reinterpret_cast<SetState*>(iter.get()); |
joshualitt | 873ad0e | 2015-01-20 09:08:51 -0800 | [diff] [blame] | 624 | |
joshualitt | 4d8da81 | 2015-01-28 12:53:54 -0800 | [diff] [blame] | 625 | // TODO sometimes we have a prim proc, othertimes we have a GrBatch. Eventually we will |
| 626 | // only have GrBatch and we can delete this |
| 627 | if (ss->fPrimitiveProcessor) { |
| 628 | this->getGpu()->buildProgramDesc(&ss->fDesc, *ss->fPrimitiveProcessor, |
egdaniel | e36914c | 2015-02-13 09:00:33 -0800 | [diff] [blame] | 629 | *ss->getPipeline(), |
joshualitt | 4d8da81 | 2015-01-28 12:53:54 -0800 | [diff] [blame] | 630 | ss->fBatchTracker); |
| 631 | } |
joshualitt | 873ad0e | 2015-01-20 09:08:51 -0800 | [diff] [blame] | 632 | currentState = ss; |
joshualitt | d53a827 | 2014-11-10 16:03:14 -0800 | [diff] [blame] | 633 | } else { |
joshualitt | 873ad0e | 2015-01-20 09:08:51 -0800 | [diff] [blame] | 634 | iter->execute(this, currentState); |
joshualitt | d53a827 | 2014-11-10 16:03:14 -0800 | [diff] [blame] | 635 | } |
cdalton | 6819df3 | 2014-10-15 13:43:48 -0700 | [diff] [blame] | 636 | |
robertphillips | e5e72f1 | 2015-02-17 09:14:33 -0800 | [diff] [blame] | 637 | if (iter->isTraced()) { |
bsalomon | 371bcbc | 2014-12-01 08:19:34 -0800 | [diff] [blame] | 638 | this->getGpu()->removeGpuTraceMarker(&newMarker); |
commit-bot@chromium.org | 2a05de0 | 2014-03-25 15:17:32 +0000 | [diff] [blame] | 639 | } |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 640 | } |
mtklein | f439c77 | 2014-10-14 14:29:30 -0700 | [diff] [blame] | 641 | |
joshualitt | 4d8da81 | 2015-01-28 12:53:54 -0800 | [diff] [blame] | 642 | // TODO see copious notes about hack |
| 643 | fBatchTarget.postFlush(); |
| 644 | |
commit-bot@chromium.org | 2a05de0 | 2014-03-25 15:17:32 +0000 | [diff] [blame] | 645 | SkASSERT(fGpuCmdMarkers.count() == currCmdMarker); |
commit-bot@chromium.org | a8916ff | 2013-08-16 15:53:46 +0000 | [diff] [blame] | 646 | ++fDrawID; |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 647 | } |
| 648 | |
joshualitt | 873ad0e | 2015-01-20 09:08:51 -0800 | [diff] [blame] | 649 | void GrInOrderDrawBuffer::Draw::execute(GrInOrderDrawBuffer* buf, const SetState* state) { |
| 650 | SkASSERT(state); |
egdaniel | e36914c | 2015-02-13 09:00:33 -0800 | [diff] [blame] | 651 | DrawArgs args(state->fPrimitiveProcessor.get(), state->getPipeline(), &state->fDesc, |
joshualitt | 17e7314 | 2015-01-21 11:52:36 -0800 | [diff] [blame] | 652 | &state->fBatchTracker); |
joshualitt | 873ad0e | 2015-01-20 09:08:51 -0800 | [diff] [blame] | 653 | buf->getGpu()->draw(args, fInfo); |
cdalton | 6819df3 | 2014-10-15 13:43:48 -0700 | [diff] [blame] | 654 | } |
| 655 | |
joshualitt | 873ad0e | 2015-01-20 09:08:51 -0800 | [diff] [blame] | 656 | void GrInOrderDrawBuffer::StencilPath::execute(GrInOrderDrawBuffer* buf, const SetState*) { |
bsalomon | 3e79124 | 2014-12-17 13:43:13 -0800 | [diff] [blame] | 657 | GrGpu::StencilPathState state; |
| 658 | state.fRenderTarget = fRenderTarget.get(); |
| 659 | state.fScissor = &fScissor; |
| 660 | state.fStencil = &fStencil; |
| 661 | state.fUseHWAA = fUseHWAA; |
| 662 | state.fViewMatrix = &fViewMatrix; |
| 663 | |
| 664 | buf->getGpu()->stencilPath(this->path(), state); |
cdalton | 6819df3 | 2014-10-15 13:43:48 -0700 | [diff] [blame] | 665 | } |
| 666 | |
joshualitt | 873ad0e | 2015-01-20 09:08:51 -0800 | [diff] [blame] | 667 | void GrInOrderDrawBuffer::DrawPath::execute(GrInOrderDrawBuffer* buf, const SetState* state) { |
| 668 | SkASSERT(state); |
egdaniel | e36914c | 2015-02-13 09:00:33 -0800 | [diff] [blame] | 669 | DrawArgs args(state->fPrimitiveProcessor.get(), state->getPipeline(), &state->fDesc, |
joshualitt | 17e7314 | 2015-01-21 11:52:36 -0800 | [diff] [blame] | 670 | &state->fBatchTracker); |
joshualitt | 873ad0e | 2015-01-20 09:08:51 -0800 | [diff] [blame] | 671 | buf->getGpu()->drawPath(args, this->path(), fStencilSettings); |
cdalton | 6819df3 | 2014-10-15 13:43:48 -0700 | [diff] [blame] | 672 | } |
| 673 | |
joshualitt | 873ad0e | 2015-01-20 09:08:51 -0800 | [diff] [blame] | 674 | void GrInOrderDrawBuffer::DrawPaths::execute(GrInOrderDrawBuffer* buf, const SetState* state) { |
| 675 | SkASSERT(state); |
egdaniel | e36914c | 2015-02-13 09:00:33 -0800 | [diff] [blame] | 676 | DrawArgs args(state->fPrimitiveProcessor.get(), state->getPipeline(), &state->fDesc, |
joshualitt | 17e7314 | 2015-01-21 11:52:36 -0800 | [diff] [blame] | 677 | &state->fBatchTracker); |
joshualitt | 873ad0e | 2015-01-20 09:08:51 -0800 | [diff] [blame] | 678 | buf->getGpu()->drawPaths(args, this->pathRange(), |
cdalton | 55b24af | 2014-11-25 11:00:56 -0800 | [diff] [blame] | 679 | &buf->fPathIndexBuffer[fIndicesLocation], fIndexType, |
| 680 | &buf->fPathTransformBuffer[fTransformsLocation], fTransformType, |
| 681 | fCount, fStencilSettings); |
cdalton | 6819df3 | 2014-10-15 13:43:48 -0700 | [diff] [blame] | 682 | } |
| 683 | |
joshualitt | 4d8da81 | 2015-01-28 12:53:54 -0800 | [diff] [blame] | 684 | void GrInOrderDrawBuffer::DrawBatch::execute(GrInOrderDrawBuffer* buf, const SetState* state) { |
| 685 | SkASSERT(state); |
egdaniel | e36914c | 2015-02-13 09:00:33 -0800 | [diff] [blame] | 686 | fBatch->generateGeometry(buf->getBatchTarget(), state->getPipeline()); |
joshualitt | 4d8da81 | 2015-01-28 12:53:54 -0800 | [diff] [blame] | 687 | } |
| 688 | |
joshualitt | 873ad0e | 2015-01-20 09:08:51 -0800 | [diff] [blame] | 689 | void GrInOrderDrawBuffer::SetState::execute(GrInOrderDrawBuffer*, const SetState*) {} |
cdalton | 6819df3 | 2014-10-15 13:43:48 -0700 | [diff] [blame] | 690 | |
joshualitt | 873ad0e | 2015-01-20 09:08:51 -0800 | [diff] [blame] | 691 | void GrInOrderDrawBuffer::Clear::execute(GrInOrderDrawBuffer* buf, const SetState*) { |
cdalton | 6819df3 | 2014-10-15 13:43:48 -0700 | [diff] [blame] | 692 | if (GrColor_ILLEGAL == fColor) { |
bsalomon | 371bcbc | 2014-12-01 08:19:34 -0800 | [diff] [blame] | 693 | buf->getGpu()->discard(this->renderTarget()); |
cdalton | 6819df3 | 2014-10-15 13:43:48 -0700 | [diff] [blame] | 694 | } else { |
bsalomon | 371bcbc | 2014-12-01 08:19:34 -0800 | [diff] [blame] | 695 | buf->getGpu()->clear(&fRect, fColor, fCanIgnoreRect, this->renderTarget()); |
cdalton | 6819df3 | 2014-10-15 13:43:48 -0700 | [diff] [blame] | 696 | } |
| 697 | } |
| 698 | |
joshualitt | 873ad0e | 2015-01-20 09:08:51 -0800 | [diff] [blame] | 699 | void GrInOrderDrawBuffer::ClearStencilClip::execute(GrInOrderDrawBuffer* buf, const SetState*) { |
bsalomon | 371bcbc | 2014-12-01 08:19:34 -0800 | [diff] [blame] | 700 | buf->getGpu()->clearStencilClip(fRect, fInsideClip, this->renderTarget()); |
joshualitt | 6db519c | 2014-10-29 08:48:18 -0700 | [diff] [blame] | 701 | } |
| 702 | |
joshualitt | 873ad0e | 2015-01-20 09:08:51 -0800 | [diff] [blame] | 703 | void GrInOrderDrawBuffer::CopySurface::execute(GrInOrderDrawBuffer* buf, const SetState*) { |
bsalomon | 371bcbc | 2014-12-01 08:19:34 -0800 | [diff] [blame] | 704 | buf->getGpu()->copySurface(this->dst(), this->src(), fSrcRect, fDstPoint); |
cdalton | 6819df3 | 2014-10-15 13:43:48 -0700 | [diff] [blame] | 705 | } |
| 706 | |
bsalomon | f90a02b | 2014-11-26 12:28:00 -0800 | [diff] [blame] | 707 | bool GrInOrderDrawBuffer::onCopySurface(GrSurface* dst, |
| 708 | GrSurface* src, |
| 709 | const SkIRect& srcRect, |
| 710 | const SkIPoint& dstPoint) { |
bsalomon | 371bcbc | 2014-12-01 08:19:34 -0800 | [diff] [blame] | 711 | if (getGpu()->canCopySurface(dst, src, srcRect, dstPoint)) { |
joshualitt | 95964c6 | 2015-02-11 13:45:50 -0800 | [diff] [blame] | 712 | this->closeBatch(); |
cdalton | 6819df3 | 2014-10-15 13:43:48 -0700 | [diff] [blame] | 713 | CopySurface* cs = GrNEW_APPEND_TO_RECORDER(fCmdBuffer, CopySurface, (dst, src)); |
bsalomon@google.com | 116ad84 | 2013-04-09 15:38:19 +0000 | [diff] [blame] | 714 | cs->fSrcRect = srcRect; |
| 715 | cs->fDstPoint = dstPoint; |
cdalton | 6819df3 | 2014-10-15 13:43:48 -0700 | [diff] [blame] | 716 | this->recordTraceMarkersIfNecessary(); |
bsalomon@google.com | 116ad84 | 2013-04-09 15:38:19 +0000 | [diff] [blame] | 717 | return true; |
bsalomon@google.com | 116ad84 | 2013-04-09 15:38:19 +0000 | [diff] [blame] | 718 | } |
bsalomon | f90a02b | 2014-11-26 12:28:00 -0800 | [diff] [blame] | 719 | return false; |
bsalomon@google.com | 116ad84 | 2013-04-09 15:38:19 +0000 | [diff] [blame] | 720 | } |
| 721 | |
egdaniel | e36914c | 2015-02-13 09:00:33 -0800 | [diff] [blame] | 722 | bool GrInOrderDrawBuffer::setupPipelineAndShouldDraw(const GrPrimitiveProcessor* primProc, |
| 723 | const PipelineInfo& pipelineInfo) { |
| 724 | SetState* ss = GrNEW_APPEND_TO_RECORDER(fCmdBuffer, SetState, (primProc)); |
| 725 | this->setupPipeline(pipelineInfo, ss->pipelineLocation()); |
| 726 | |
| 727 | if (ss->getPipeline()->mustSkip()) { |
bsalomon | 932f866 | 2014-11-24 06:47:48 -0800 | [diff] [blame] | 728 | fCmdBuffer.pop_back(); |
bsalomon | ae59b77 | 2014-11-19 08:23:49 -0800 | [diff] [blame] | 729 | return false; |
| 730 | } |
joshualitt | 873ad0e | 2015-01-20 09:08:51 -0800 | [diff] [blame] | 731 | |
| 732 | ss->fPrimitiveProcessor->initBatchTracker(&ss->fBatchTracker, |
egdaniel | e36914c | 2015-02-13 09:00:33 -0800 | [diff] [blame] | 733 | ss->getPipeline()->getInitBatchTracker()); |
joshualitt | 873ad0e | 2015-01-20 09:08:51 -0800 | [diff] [blame] | 734 | |
joshualitt | 4d8da81 | 2015-01-28 12:53:54 -0800 | [diff] [blame] | 735 | if (fPrevState && fPrevState->fPrimitiveProcessor.get() && |
joshualitt | 873ad0e | 2015-01-20 09:08:51 -0800 | [diff] [blame] | 736 | fPrevState->fPrimitiveProcessor->canMakeEqual(fPrevState->fBatchTracker, |
| 737 | *ss->fPrimitiveProcessor, |
| 738 | ss->fBatchTracker) && |
egdaniel | e36914c | 2015-02-13 09:00:33 -0800 | [diff] [blame] | 739 | fPrevState->getPipeline()->isEqual(*ss->getPipeline())) { |
bsalomon | 932f866 | 2014-11-24 06:47:48 -0800 | [diff] [blame] | 740 | fCmdBuffer.pop_back(); |
| 741 | } else { |
joshualitt | 873ad0e | 2015-01-20 09:08:51 -0800 | [diff] [blame] | 742 | fPrevState = ss; |
cdalton | 6819df3 | 2014-10-15 13:43:48 -0700 | [diff] [blame] | 743 | this->recordTraceMarkersIfNecessary(); |
bsalomon | 838f62d | 2014-08-05 07:15:57 -0700 | [diff] [blame] | 744 | } |
bsalomon | ae59b77 | 2014-11-19 08:23:49 -0800 | [diff] [blame] | 745 | return true; |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 746 | } |
| 747 | |
egdaniel | e36914c | 2015-02-13 09:00:33 -0800 | [diff] [blame] | 748 | bool GrInOrderDrawBuffer::setupPipelineAndShouldDraw(GrBatch* batch, |
| 749 | const PipelineInfo& pipelineInfo) { |
| 750 | SetState* ss = GrNEW_APPEND_TO_RECORDER(fCmdBuffer, SetState, ()); |
| 751 | this->setupPipeline(pipelineInfo, ss->pipelineLocation()); |
| 752 | |
| 753 | if (ss->getPipeline()->mustSkip()) { |
joshualitt | 4d8da81 | 2015-01-28 12:53:54 -0800 | [diff] [blame] | 754 | fCmdBuffer.pop_back(); |
| 755 | return false; |
| 756 | } |
| 757 | |
egdaniel | e36914c | 2015-02-13 09:00:33 -0800 | [diff] [blame] | 758 | batch->initBatchTracker(ss->getPipeline()->getInitBatchTracker()); |
joshualitt | 4d8da81 | 2015-01-28 12:53:54 -0800 | [diff] [blame] | 759 | |
| 760 | if (fPrevState && !fPrevState->fPrimitiveProcessor.get() && |
egdaniel | e36914c | 2015-02-13 09:00:33 -0800 | [diff] [blame] | 761 | fPrevState->getPipeline()->isEqual(*ss->getPipeline())) { |
joshualitt | 4d8da81 | 2015-01-28 12:53:54 -0800 | [diff] [blame] | 762 | fCmdBuffer.pop_back(); |
| 763 | } else { |
| 764 | this->closeBatch(); |
| 765 | fPrevState = ss; |
| 766 | this->recordTraceMarkersIfNecessary(); |
| 767 | } |
| 768 | return true; |
| 769 | } |
| 770 | |
cdalton | 6819df3 | 2014-10-15 13:43:48 -0700 | [diff] [blame] | 771 | void GrInOrderDrawBuffer::recordTraceMarkersIfNecessary() { |
| 772 | SkASSERT(!fCmdBuffer.empty()); |
robertphillips | e5e72f1 | 2015-02-17 09:14:33 -0800 | [diff] [blame] | 773 | SkASSERT(!fCmdBuffer.back().isTraced()); |
mtklein | f439c77 | 2014-10-14 14:29:30 -0700 | [diff] [blame] | 774 | const GrTraceMarkerSet& activeTraceMarkers = this->getActiveTraceMarkers(); |
| 775 | if (activeTraceMarkers.count() > 0) { |
robertphillips | e5e72f1 | 2015-02-17 09:14:33 -0800 | [diff] [blame] | 776 | fCmdBuffer.back().makeTraced(); |
mtklein | f439c77 | 2014-10-14 14:29:30 -0700 | [diff] [blame] | 777 | fGpuCmdMarkers.push_back(activeTraceMarkers); |
mtklein | 07894c4 | 2014-10-13 14:00:42 -0700 | [diff] [blame] | 778 | } |
mtklein | 07894c4 | 2014-10-13 14:00:42 -0700 | [diff] [blame] | 779 | } |
joshualitt | 4d8da81 | 2015-01-28 12:53:54 -0800 | [diff] [blame] | 780 | |
joshualitt | 4d8da81 | 2015-01-28 12:53:54 -0800 | [diff] [blame] | 781 | void GrInOrderDrawBuffer::willReserveVertexAndIndexSpace(int vertexCount, |
| 782 | size_t vertexStride, |
| 783 | int indexCount) { |
| 784 | this->closeBatch(); |
| 785 | |
robertphillips | 54fac8b | 2015-02-16 09:35:50 -0800 | [diff] [blame] | 786 | this->INHERITED::willReserveVertexAndIndexSpace(vertexCount, vertexStride, indexCount); |
joshualitt | 4d8da81 | 2015-01-28 12:53:54 -0800 | [diff] [blame] | 787 | } |