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