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