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