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 | 5478d42 | 2014-11-14 16:00:38 -0800 | [diff] [blame] | 10 | #include "GrDefaultGeoProcFactory.h" |
bsalomon@google.com | 6e4e650 | 2013-02-25 20:12:45 +0000 | [diff] [blame] | 11 | #include "GrTemplates.h" |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 12 | |
bsalomon@google.com | 6e4e650 | 2013-02-25 20:12:45 +0000 | [diff] [blame] | 13 | GrInOrderDrawBuffer::GrInOrderDrawBuffer(GrGpu* gpu, |
bsalomon@google.com | 471d471 | 2011-08-23 15:45:25 +0000 | [diff] [blame] | 14 | GrVertexBufferAllocPool* vertexPool, |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 15 | GrIndexBufferAllocPool* indexPool) |
bsalomon | 371bcbc | 2014-12-01 08:19:34 -0800 | [diff] [blame] | 16 | : INHERITED(gpu, vertexPool, indexPool) |
robertphillips | dad7794 | 2015-03-03 09:28:16 -0800 | [diff] [blame] | 17 | , fCommands(gpu, vertexPool, indexPool) |
robertphillips | 9888b22 | 2015-02-27 08:50:34 -0800 | [diff] [blame] | 18 | , fPathIndexBuffer(kPathIdxBufferMinReserve * sizeof(char)/4) |
| 19 | , fPathTransformBuffer(kPathXformBufferMinReserve * sizeof(float)/4) |
robertphillips | dad7794 | 2015-03-03 09:28:16 -0800 | [diff] [blame] | 20 | , fDrawID(0) { |
bsalomon@google.com | 18c9c19 | 2011-09-22 21:01:31 +0000 | [diff] [blame] | 21 | |
bsalomon | 49f085d | 2014-09-05 13:34:00 -0700 | [diff] [blame] | 22 | SkASSERT(vertexPool); |
| 23 | SkASSERT(indexPool); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 24 | } |
| 25 | |
| 26 | GrInOrderDrawBuffer::~GrInOrderDrawBuffer() { |
bsalomon@google.com | 86afc2a | 2011-02-16 16:12:19 +0000 | [diff] [blame] | 27 | this->reset(); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 28 | } |
| 29 | |
bsalomon@google.com | 934c570 | 2012-03-20 21:17:58 +0000 | [diff] [blame] | 30 | //////////////////////////////////////////////////////////////////////////////// |
| 31 | |
bsalomon | 62c447d | 2014-08-08 08:08:50 -0700 | [diff] [blame] | 32 | /** We always use per-vertex colors so that rects can be batched across color changes. Sometimes we |
| 33 | have explicit local coords and sometimes not. We *could* always provide explicit local coords |
| 34 | and just duplicate the positions when the caller hasn't provided a local coord rect, but we |
| 35 | haven't seen a use case which frequently switches between local rect and no local rect draws. |
| 36 | |
| 37 | The color param is used to determine whether the opaque hint can be set on the draw state. |
| 38 | The caller must populate the vertex colors itself. |
| 39 | |
| 40 | The vertex attrib order is always pos, color, [local coords]. |
| 41 | */ |
joshualitt | 8fc6c2d | 2014-12-22 15:27:05 -0800 | [diff] [blame] | 42 | static const GrGeometryProcessor* create_rect_gp(bool hasExplicitLocalCoords, |
| 43 | GrColor color, |
| 44 | const SkMatrix* localMatrix) { |
joshualitt | 5478d42 | 2014-11-14 16:00:38 -0800 | [diff] [blame] | 45 | uint32_t flags = GrDefaultGeoProcFactory::kPosition_GPType | |
| 46 | GrDefaultGeoProcFactory::kColor_GPType; |
joshualitt | 8fc6c2d | 2014-12-22 15:27:05 -0800 | [diff] [blame] | 47 | flags |= hasExplicitLocalCoords ? GrDefaultGeoProcFactory::kLocalCoord_GPType : 0; |
| 48 | if (localMatrix) { |
joshualitt | 8059eb9 | 2014-12-29 15:10:07 -0800 | [diff] [blame] | 49 | return GrDefaultGeoProcFactory::Create(flags, color, SkMatrix::I(), *localMatrix, |
| 50 | GrColorIsOpaque(color)); |
joshualitt | 8fc6c2d | 2014-12-22 15:27:05 -0800 | [diff] [blame] | 51 | } else { |
joshualitt | 8059eb9 | 2014-12-29 15:10:07 -0800 | [diff] [blame] | 52 | return GrDefaultGeoProcFactory::Create(flags, color, SkMatrix::I(), SkMatrix::I(), |
| 53 | GrColorIsOpaque(color)); |
joshualitt | 8fc6c2d | 2014-12-22 15:27:05 -0800 | [diff] [blame] | 54 | } |
bsalomon | 62c447d | 2014-08-08 08:08:50 -0700 | [diff] [blame] | 55 | } |
robertphillips@google.com | 4290330 | 2013-04-20 12:26:07 +0000 | [diff] [blame] | 56 | |
joshualitt | 5877333 | 2015-02-23 16:41:42 -0800 | [diff] [blame] | 57 | class RectBatch : public GrBatch { |
| 58 | public: |
| 59 | struct Geometry { |
| 60 | GrColor fColor; |
| 61 | SkMatrix fViewMatrix; |
| 62 | SkRect fRect; |
| 63 | bool fHasLocalRect; |
| 64 | bool fHasLocalMatrix; |
| 65 | SkRect fLocalRect; |
| 66 | SkMatrix fLocalMatrix; |
| 67 | }; |
| 68 | |
| 69 | static GrBatch* Create(const Geometry& geometry) { |
| 70 | return SkNEW_ARGS(RectBatch, (geometry)); |
| 71 | } |
| 72 | |
| 73 | const char* name() const SK_OVERRIDE { return "RectBatch"; } |
| 74 | |
| 75 | void getInvariantOutputColor(GrInitInvariantOutput* out) const SK_OVERRIDE { |
| 76 | // When this is called on a batch, there is only one geometry bundle |
| 77 | out->setKnownFourComponents(fGeoData[0].fColor); |
| 78 | } |
| 79 | |
| 80 | void getInvariantOutputCoverage(GrInitInvariantOutput* out) const SK_OVERRIDE { |
| 81 | out->setKnownSingleComponent(0xff); |
| 82 | } |
| 83 | |
| 84 | void initBatchTracker(const GrPipelineInfo& init) SK_OVERRIDE { |
| 85 | // Handle any color overrides |
| 86 | if (init.fColorIgnored) { |
| 87 | fGeoData[0].fColor = GrColor_ILLEGAL; |
| 88 | } else if (GrColor_ILLEGAL != init.fOverrideColor) { |
| 89 | fGeoData[0].fColor = init.fOverrideColor; |
| 90 | } |
| 91 | |
| 92 | // setup batch properties |
| 93 | fBatch.fColorIgnored = init.fColorIgnored; |
| 94 | fBatch.fColor = fGeoData[0].fColor; |
| 95 | fBatch.fUsesLocalCoords = init.fUsesLocalCoords; |
| 96 | fBatch.fCoverageIgnored = init.fCoverageIgnored; |
| 97 | } |
| 98 | |
| 99 | void generateGeometry(GrBatchTarget* batchTarget, const GrPipeline* pipeline) SK_OVERRIDE { |
| 100 | // Go to device coords to allow batching across matrix changes |
| 101 | SkMatrix invert = SkMatrix::I(); |
| 102 | |
| 103 | // if we have a local rect, then we apply the localMatrix directly to the localRect to |
| 104 | // generate vertex local coords |
| 105 | bool hasExplicitLocalCoords = this->hasLocalRect(); |
| 106 | if (!hasExplicitLocalCoords) { |
| 107 | if (!this->viewMatrix().isIdentity() && !this->viewMatrix().invert(&invert)) { |
| 108 | SkDebugf("Could not invert\n"); |
| 109 | return; |
| 110 | } |
| 111 | |
| 112 | if (this->hasLocalMatrix()) { |
| 113 | invert.preConcat(this->localMatrix()); |
| 114 | } |
| 115 | } |
| 116 | |
| 117 | SkAutoTUnref<const GrGeometryProcessor> gp(create_rect_gp(hasExplicitLocalCoords, |
| 118 | this->color(), |
| 119 | &invert)); |
| 120 | |
| 121 | batchTarget->initDraw(gp, pipeline); |
| 122 | |
| 123 | // TODO this is hacky, but the only way we have to initialize the GP is to use the |
| 124 | // GrPipelineInfo struct so we can generate the correct shader. Once we have GrBatch |
| 125 | // everywhere we can remove this nastiness |
| 126 | GrPipelineInfo init; |
| 127 | init.fColorIgnored = fBatch.fColorIgnored; |
| 128 | init.fOverrideColor = GrColor_ILLEGAL; |
| 129 | init.fCoverageIgnored = fBatch.fCoverageIgnored; |
| 130 | init.fUsesLocalCoords = this->usesLocalCoords(); |
| 131 | gp->initBatchTracker(batchTarget->currentBatchTracker(), init); |
| 132 | |
| 133 | size_t vertexStride = gp->getVertexStride(); |
| 134 | |
| 135 | SkASSERT(hasExplicitLocalCoords ? |
| 136 | vertexStride == sizeof(GrDefaultGeoProcFactory::PositionColorLocalCoordAttr) : |
| 137 | vertexStride == sizeof(GrDefaultGeoProcFactory::PositionColorAttr)); |
| 138 | |
| 139 | int instanceCount = fGeoData.count(); |
| 140 | int vertexCount = kVertsPerRect * instanceCount; |
| 141 | |
| 142 | const GrVertexBuffer* vertexBuffer; |
| 143 | int firstVertex; |
| 144 | |
| 145 | void* vertices = batchTarget->vertexPool()->makeSpace(vertexStride, |
| 146 | vertexCount, |
| 147 | &vertexBuffer, |
| 148 | &firstVertex); |
| 149 | |
| 150 | for (int i = 0; i < instanceCount; i++) { |
| 151 | const Geometry& args = fGeoData[i]; |
| 152 | |
| 153 | intptr_t offset = GrTCast<intptr_t>(vertices) + kVertsPerRect * i * vertexStride; |
| 154 | SkPoint* positions = GrTCast<SkPoint*>(offset); |
| 155 | |
| 156 | positions->setRectFan(args.fRect.fLeft, args.fRect.fTop, |
| 157 | args.fRect.fRight, args.fRect.fBottom, vertexStride); |
| 158 | args.fViewMatrix.mapPointsWithStride(positions, vertexStride, kVertsPerRect); |
| 159 | |
| 160 | if (args.fHasLocalRect) { |
| 161 | static const int kLocalOffset = sizeof(SkPoint) + sizeof(GrColor); |
| 162 | SkPoint* coords = GrTCast<SkPoint*>(offset + kLocalOffset); |
| 163 | coords->setRectFan(args.fLocalRect.fLeft, args.fLocalRect.fTop, |
| 164 | args.fLocalRect.fRight, args.fLocalRect.fBottom, |
| 165 | vertexStride); |
| 166 | if (args.fHasLocalMatrix) { |
| 167 | args.fLocalMatrix.mapPointsWithStride(coords, vertexStride, kVertsPerRect); |
| 168 | } |
| 169 | } |
| 170 | |
| 171 | static const int kColorOffset = sizeof(SkPoint); |
| 172 | GrColor* vertColor = GrTCast<GrColor*>(offset + kColorOffset); |
| 173 | for (int j = 0; j < 4; ++j) { |
| 174 | *vertColor = args.fColor; |
| 175 | vertColor = (GrColor*) ((intptr_t) vertColor + vertexStride); |
| 176 | } |
| 177 | } |
| 178 | |
| 179 | const GrIndexBuffer* quadIndexBuffer = batchTarget->quadIndexBuffer(); |
| 180 | |
| 181 | GrDrawTarget::DrawInfo drawInfo; |
| 182 | drawInfo.setPrimitiveType(kTriangles_GrPrimitiveType); |
| 183 | drawInfo.setStartVertex(0); |
| 184 | drawInfo.setStartIndex(0); |
| 185 | drawInfo.setVerticesPerInstance(kVertsPerRect); |
| 186 | drawInfo.setIndicesPerInstance(kIndicesPerRect); |
| 187 | drawInfo.adjustStartVertex(firstVertex); |
| 188 | drawInfo.setVertexBuffer(vertexBuffer); |
| 189 | drawInfo.setIndexBuffer(quadIndexBuffer); |
| 190 | |
| 191 | int maxInstancesPerDraw = quadIndexBuffer->maxQuads(); |
| 192 | while (instanceCount) { |
| 193 | drawInfo.setInstanceCount(SkTMin(instanceCount, maxInstancesPerDraw)); |
| 194 | drawInfo.setVertexCount(drawInfo.instanceCount() * drawInfo.verticesPerInstance()); |
| 195 | drawInfo.setIndexCount(drawInfo.instanceCount() * drawInfo.indicesPerInstance()); |
| 196 | |
| 197 | batchTarget->draw(drawInfo); |
| 198 | |
| 199 | drawInfo.setStartVertex(drawInfo.startVertex() + drawInfo.vertexCount()); |
| 200 | instanceCount -= drawInfo.instanceCount(); |
| 201 | } |
| 202 | } |
| 203 | |
| 204 | SkSTArray<1, Geometry, true>* geoData() { return &fGeoData; } |
| 205 | |
| 206 | private: |
| 207 | RectBatch(const Geometry& geometry) { |
| 208 | this->initClassID<RectBatch>(); |
| 209 | fGeoData.push_back(geometry); |
| 210 | } |
| 211 | |
| 212 | GrColor color() const { return fBatch.fColor; } |
| 213 | bool usesLocalCoords() const { return fBatch.fUsesLocalCoords; } |
| 214 | bool colorIgnored() const { return fBatch.fColorIgnored; } |
| 215 | const SkMatrix& viewMatrix() const { return fGeoData[0].fViewMatrix; } |
| 216 | const SkMatrix& localMatrix() const { return fGeoData[0].fLocalMatrix; } |
| 217 | bool hasLocalRect() const { return fGeoData[0].fHasLocalRect; } |
| 218 | bool hasLocalMatrix() const { return fGeoData[0].fHasLocalMatrix; } |
| 219 | |
| 220 | bool onCombineIfPossible(GrBatch* t) SK_OVERRIDE { |
| 221 | RectBatch* that = t->cast<RectBatch>(); |
| 222 | |
| 223 | if (this->hasLocalRect() != that->hasLocalRect()) { |
| 224 | return false; |
| 225 | } |
| 226 | |
| 227 | SkASSERT(this->usesLocalCoords() == that->usesLocalCoords()); |
| 228 | if (!this->hasLocalRect() && this->usesLocalCoords()) { |
| 229 | if (!this->viewMatrix().cheapEqualTo(that->viewMatrix())) { |
| 230 | return false; |
| 231 | } |
| 232 | |
| 233 | if (this->hasLocalMatrix() != that->hasLocalMatrix()) { |
| 234 | return false; |
| 235 | } |
| 236 | |
| 237 | if (this->hasLocalMatrix() && !this->localMatrix().cheapEqualTo(that->localMatrix())) { |
| 238 | return false; |
| 239 | } |
| 240 | } |
| 241 | |
| 242 | if (this->color() != that->color()) { |
| 243 | fBatch.fColor = GrColor_ILLEGAL; |
| 244 | } |
| 245 | fGeoData.push_back_n(that->geoData()->count(), that->geoData()->begin()); |
| 246 | return true; |
| 247 | } |
| 248 | |
| 249 | struct BatchTracker { |
| 250 | GrColor fColor; |
| 251 | bool fUsesLocalCoords; |
| 252 | bool fColorIgnored; |
| 253 | bool fCoverageIgnored; |
| 254 | }; |
| 255 | |
| 256 | const static int kVertsPerRect = 4; |
| 257 | const static int kIndicesPerRect = 6; |
| 258 | |
| 259 | BatchTracker fBatch; |
| 260 | SkSTArray<1, Geometry, true> fGeoData; |
| 261 | }; |
| 262 | |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 263 | void GrInOrderDrawBuffer::onDrawRect(GrPipelineBuilder* pipelineBuilder, |
joshualitt | 2e3b3e3 | 2014-12-09 13:31:14 -0800 | [diff] [blame] | 264 | GrColor color, |
joshualitt | 8059eb9 | 2014-12-29 15:10:07 -0800 | [diff] [blame] | 265 | const SkMatrix& viewMatrix, |
joshualitt | 9853cce | 2014-11-17 14:22:48 -0800 | [diff] [blame] | 266 | const SkRect& rect, |
commit-bot@chromium.org | fd03d4a | 2013-07-17 21:39:42 +0000 | [diff] [blame] | 267 | const SkRect* localRect, |
bsalomon@google.com | 0406b9e | 2013-04-02 21:00:15 +0000 | [diff] [blame] | 268 | const SkMatrix* localMatrix) { |
joshualitt | 5877333 | 2015-02-23 16:41:42 -0800 | [diff] [blame] | 269 | RectBatch::Geometry geometry; |
| 270 | geometry.fColor = color; |
| 271 | geometry.fViewMatrix = viewMatrix; |
| 272 | geometry.fRect = rect; |
bsalomon@google.com | d62e88e | 2013-02-01 14:19:27 +0000 | [diff] [blame] | 273 | |
bsalomon | 49f085d | 2014-09-05 13:34:00 -0700 | [diff] [blame] | 274 | if (localRect) { |
joshualitt | 5877333 | 2015-02-23 16:41:42 -0800 | [diff] [blame] | 275 | geometry.fHasLocalRect = true; |
| 276 | geometry.fLocalRect = *localRect; |
| 277 | } else { |
| 278 | geometry.fHasLocalRect = false; |
bsalomon@google.com | d62e88e | 2013-02-01 14:19:27 +0000 | [diff] [blame] | 279 | } |
| 280 | |
joshualitt | 5877333 | 2015-02-23 16:41:42 -0800 | [diff] [blame] | 281 | if (localMatrix) { |
| 282 | geometry.fHasLocalMatrix = true; |
| 283 | geometry.fLocalMatrix = *localMatrix; |
| 284 | } else { |
| 285 | geometry.fHasLocalMatrix = false; |
bsalomon@google.com | d62e88e | 2013-02-01 14:19:27 +0000 | [diff] [blame] | 286 | } |
| 287 | |
joshualitt | 5877333 | 2015-02-23 16:41:42 -0800 | [diff] [blame] | 288 | SkAutoTUnref<GrBatch> batch(RectBatch::Create(geometry)); |
| 289 | |
| 290 | SkRect bounds = rect; |
| 291 | viewMatrix.mapRect(&bounds); |
| 292 | this->drawBatch(pipelineBuilder, batch, &bounds); |
bsalomon@google.com | d62e88e | 2013-02-01 14:19:27 +0000 | [diff] [blame] | 293 | } |
| 294 | |
egdaniel | e36914c | 2015-02-13 09:00:33 -0800 | [diff] [blame] | 295 | void GrInOrderDrawBuffer::onDraw(const GrGeometryProcessor* gp, |
joshualitt | 9853cce | 2014-11-17 14:22:48 -0800 | [diff] [blame] | 296 | const DrawInfo& info, |
egdaniel | e36914c | 2015-02-13 09:00:33 -0800 | [diff] [blame] | 297 | const PipelineInfo& pipelineInfo) { |
robertphillips | dad7794 | 2015-03-03 09:28:16 -0800 | [diff] [blame] | 298 | GrTargetCommands::Cmd* cmd = fCommands.recordDraw(this, gp, info, pipelineInfo); |
| 299 | this->recordTraceMarkersIfNecessary(cmd); |
| 300 | } |
| 301 | |
joshualitt | 4d8da81 | 2015-01-28 12:53:54 -0800 | [diff] [blame] | 302 | void GrInOrderDrawBuffer::onDrawBatch(GrBatch* batch, |
egdaniel | e36914c | 2015-02-13 09:00:33 -0800 | [diff] [blame] | 303 | const PipelineInfo& pipelineInfo) { |
robertphillips | dad7794 | 2015-03-03 09:28:16 -0800 | [diff] [blame] | 304 | GrTargetCommands::Cmd* cmd = fCommands.recordDrawBatch(this, batch, pipelineInfo); |
| 305 | this->recordTraceMarkersIfNecessary(cmd); |
| 306 | } |
| 307 | |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 308 | void GrInOrderDrawBuffer::onStencilPath(const GrPipelineBuilder& pipelineBuilder, |
joshualitt | 56995b5 | 2014-12-11 15:44:02 -0800 | [diff] [blame] | 309 | const GrPathProcessor* pathProc, |
joshualitt | 9853cce | 2014-11-17 14:22:48 -0800 | [diff] [blame] | 310 | const GrPath* path, |
bsalomon | 3e79124 | 2014-12-17 13:43:13 -0800 | [diff] [blame] | 311 | const GrScissorState& scissorState, |
joshualitt | 2c93efe | 2014-11-06 12:57:13 -0800 | [diff] [blame] | 312 | const GrStencilSettings& stencilSettings) { |
robertphillips | dad7794 | 2015-03-03 09:28:16 -0800 | [diff] [blame] | 313 | GrTargetCommands::Cmd* cmd = fCommands.recordStencilPath(this, pipelineBuilder, |
| 314 | pathProc, path, scissorState, |
| 315 | stencilSettings); |
| 316 | this->recordTraceMarkersIfNecessary(cmd); |
| 317 | } |
| 318 | |
egdaniel | e36914c | 2015-02-13 09:00:33 -0800 | [diff] [blame] | 319 | void GrInOrderDrawBuffer::onDrawPath(const GrPathProcessor* pathProc, |
joshualitt | 9853cce | 2014-11-17 14:22:48 -0800 | [diff] [blame] | 320 | const GrPath* path, |
joshualitt | 2c93efe | 2014-11-06 12:57:13 -0800 | [diff] [blame] | 321 | const GrStencilSettings& stencilSettings, |
egdaniel | e36914c | 2015-02-13 09:00:33 -0800 | [diff] [blame] | 322 | const PipelineInfo& pipelineInfo) { |
robertphillips | dad7794 | 2015-03-03 09:28:16 -0800 | [diff] [blame] | 323 | GrTargetCommands::Cmd* cmd = fCommands.recordDrawPath(this, pathProc, |
| 324 | path, stencilSettings, |
| 325 | pipelineInfo); |
| 326 | this->recordTraceMarkersIfNecessary(cmd); |
| 327 | } |
| 328 | |
egdaniel | e36914c | 2015-02-13 09:00:33 -0800 | [diff] [blame] | 329 | void GrInOrderDrawBuffer::onDrawPaths(const GrPathProcessor* pathProc, |
joshualitt | 9853cce | 2014-11-17 14:22:48 -0800 | [diff] [blame] | 330 | const GrPathRange* pathRange, |
cdalton | 55b24af | 2014-11-25 11:00:56 -0800 | [diff] [blame] | 331 | const void* indices, |
| 332 | PathIndexType indexType, |
| 333 | const float transformValues[], |
| 334 | PathTransformType transformType, |
joshualitt | 2c93efe | 2014-11-06 12:57:13 -0800 | [diff] [blame] | 335 | int count, |
joshualitt | 2c93efe | 2014-11-06 12:57:13 -0800 | [diff] [blame] | 336 | const GrStencilSettings& stencilSettings, |
egdaniel | e36914c | 2015-02-13 09:00:33 -0800 | [diff] [blame] | 337 | const PipelineInfo& pipelineInfo) { |
robertphillips | dad7794 | 2015-03-03 09:28:16 -0800 | [diff] [blame] | 338 | GrTargetCommands::Cmd* cmd = fCommands.recordDrawPaths(this, pathProc, pathRange, |
| 339 | indices, indexType, transformValues, |
| 340 | transformType, count, |
| 341 | stencilSettings, pipelineInfo); |
| 342 | this->recordTraceMarkersIfNecessary(cmd); |
| 343 | } |
| 344 | |
bsalomon | 63b2196 | 2014-11-05 07:05:34 -0800 | [diff] [blame] | 345 | void GrInOrderDrawBuffer::onClear(const SkIRect* rect, GrColor color, |
| 346 | bool canIgnoreRect, GrRenderTarget* renderTarget) { |
robertphillips | dad7794 | 2015-03-03 09:28:16 -0800 | [diff] [blame] | 347 | GrTargetCommands::Cmd* cmd = fCommands.recordClear(this, rect, color, |
| 348 | canIgnoreRect, renderTarget); |
| 349 | this->recordTraceMarkersIfNecessary(cmd); |
| 350 | } |
| 351 | |
joshualitt | 6db519c | 2014-10-29 08:48:18 -0700 | [diff] [blame] | 352 | void GrInOrderDrawBuffer::clearStencilClip(const SkIRect& rect, |
| 353 | bool insideClip, |
| 354 | GrRenderTarget* renderTarget) { |
robertphillips | dad7794 | 2015-03-03 09:28:16 -0800 | [diff] [blame] | 355 | GrTargetCommands::Cmd* cmd = fCommands.recordClearStencilClip(this, rect, |
| 356 | insideClip, renderTarget); |
| 357 | this->recordTraceMarkersIfNecessary(cmd); |
| 358 | } |
| 359 | |
commit-bot@chromium.org | 28361fa | 2014-03-28 16:08:05 +0000 | [diff] [blame] | 360 | void GrInOrderDrawBuffer::discard(GrRenderTarget* renderTarget) { |
| 361 | if (!this->caps()->discardRenderTargetSupport()) { |
| 362 | return; |
| 363 | } |
robertphillips | dad7794 | 2015-03-03 09:28:16 -0800 | [diff] [blame] | 364 | |
| 365 | GrTargetCommands::Cmd* cmd = fCommands.recordDiscard(this, renderTarget); |
| 366 | this->recordTraceMarkersIfNecessary(cmd); |
| 367 | } |
| 368 | |
bsalomon | 371bcbc | 2014-12-01 08:19:34 -0800 | [diff] [blame] | 369 | void GrInOrderDrawBuffer::onReset() { |
robertphillips | dad7794 | 2015-03-03 09:28:16 -0800 | [diff] [blame] | 370 | fCommands.reset(); |
robertphillips | 9888b22 | 2015-02-27 08:50:34 -0800 | [diff] [blame] | 371 | fPathIndexBuffer.rewind(); |
| 372 | fPathTransformBuffer.rewind(); |
commit-bot@chromium.org | 2a05de0 | 2014-03-25 15:17:32 +0000 | [diff] [blame] | 373 | fGpuCmdMarkers.reset(); |
robertphillips | dad7794 | 2015-03-03 09:28:16 -0800 | [diff] [blame] | 374 | } |
| 375 | |
bsalomon | 371bcbc | 2014-12-01 08:19:34 -0800 | [diff] [blame] | 376 | void GrInOrderDrawBuffer::onFlush() { |
robertphillips | dad7794 | 2015-03-03 09:28:16 -0800 | [diff] [blame] | 377 | fCommands.flush(this); |
| 378 | ++fDrawID; |
| 379 | } |
| 380 | |
bsalomon | f90a02b | 2014-11-26 12:28:00 -0800 | [diff] [blame] | 381 | bool GrInOrderDrawBuffer::onCopySurface(GrSurface* dst, |
| 382 | GrSurface* src, |
| 383 | const SkIRect& srcRect, |
| 384 | const SkIPoint& dstPoint) { |
robertphillips | dad7794 | 2015-03-03 09:28:16 -0800 | [diff] [blame] | 385 | GrTargetCommands::Cmd* cmd = fCommands.recordCopySurface(this, dst, src, |
| 386 | srcRect, dstPoint); |
| 387 | this->recordTraceMarkersIfNecessary(cmd); |
| 388 | return SkToBool(cmd); |
| 389 | } |
| 390 | |
robertphillips | dad7794 | 2015-03-03 09:28:16 -0800 | [diff] [blame] | 391 | void GrInOrderDrawBuffer::recordTraceMarkersIfNecessary(GrTargetCommands::Cmd* cmd) { |
robertphillips | 7f966f4 | 2015-03-02 06:40:12 -0800 | [diff] [blame] | 392 | if (!cmd) { |
| 393 | return; |
| 394 | } |
mtklein | f439c77 | 2014-10-14 14:29:30 -0700 | [diff] [blame] | 395 | const GrTraceMarkerSet& activeTraceMarkers = this->getActiveTraceMarkers(); |
| 396 | if (activeTraceMarkers.count() > 0) { |
robertphillips | 7f966f4 | 2015-03-02 06:40:12 -0800 | [diff] [blame] | 397 | if (cmd->isTraced()) { |
| 398 | fGpuCmdMarkers.back().addSet(activeTraceMarkers); |
| 399 | } else { |
| 400 | cmd->makeTraced(); |
| 401 | fGpuCmdMarkers.push_back(activeTraceMarkers); |
| 402 | } |
mtklein | 07894c4 | 2014-10-13 14:00:42 -0700 | [diff] [blame] | 403 | } |
mtklein | 07894c4 | 2014-10-13 14:00:42 -0700 | [diff] [blame] | 404 | } |
joshualitt | 4d8da81 | 2015-01-28 12:53:54 -0800 | [diff] [blame] | 405 | |
joshualitt | 4d8da81 | 2015-01-28 12:53:54 -0800 | [diff] [blame] | 406 | void GrInOrderDrawBuffer::willReserveVertexAndIndexSpace(int vertexCount, |
| 407 | size_t vertexStride, |
| 408 | int indexCount) { |
robertphillips | dad7794 | 2015-03-03 09:28:16 -0800 | [diff] [blame] | 409 | fCommands.closeBatch(); |
joshualitt | 4d8da81 | 2015-01-28 12:53:54 -0800 | [diff] [blame] | 410 | |
robertphillips | 54fac8b | 2015-02-16 09:35:50 -0800 | [diff] [blame] | 411 | this->INHERITED::willReserveVertexAndIndexSpace(vertexCount, vertexStride, indexCount); |
joshualitt | 4d8da81 | 2015-01-28 12:53:54 -0800 | [diff] [blame] | 412 | } |