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