blob: 76e085dffa2809a6194e150683832565c875a2cc [file] [log] [blame]
reed@google.comac10a2d2010-12-22 21:39:39 +00001/*
epoger@google.comec3ed6a2011-07-28 14:26:00 +00002 * 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.comac10a2d2010-12-22 21:39:39 +00006 */
7
reed@google.comac10a2d2010-12-22 21:39:39 +00008#include "GrInOrderDrawBuffer.h"
commit-bot@chromium.orgfd03d4a2013-07-17 21:39:42 +00009
joshualitt5478d422014-11-14 16:00:38 -080010#include "GrDefaultGeoProcFactory.h"
bsalomon@google.com6e4e6502013-02-25 20:12:45 +000011#include "GrTemplates.h"
reed@google.comac10a2d2010-12-22 21:39:39 +000012
bsalomona73239a2015-04-28 13:35:17 -070013GrInOrderDrawBuffer::GrInOrderDrawBuffer(GrContext* context,
bsalomon@google.com471d4712011-08-23 15:45:25 +000014 GrVertexBufferAllocPool* vertexPool,
bsalomon@google.com25fb21f2011-06-21 18:17:25 +000015 GrIndexBufferAllocPool* indexPool)
bsalomona73239a2015-04-28 13:35:17 -070016 : INHERITED(context, vertexPool, indexPool)
17 , fCommands(context->getGpu(), vertexPool, indexPool)
robertphillips9888b222015-02-27 08:50:34 -080018 , fPathIndexBuffer(kPathIdxBufferMinReserve * sizeof(char)/4)
19 , fPathTransformBuffer(kPathXformBufferMinReserve * sizeof(float)/4)
joshualitt5d6bb6f2015-05-04 07:41:40 -070020 , fPipelineBuffer(kPipelineBufferMinReserve)
robertphillipsdad77942015-03-03 09:28:16 -080021 , fDrawID(0) {
bsalomon@google.com18c9c192011-09-22 21:01:31 +000022
bsalomon49f085d2014-09-05 13:34:00 -070023 SkASSERT(vertexPool);
24 SkASSERT(indexPool);
reed@google.comac10a2d2010-12-22 21:39:39 +000025}
26
27GrInOrderDrawBuffer::~GrInOrderDrawBuffer() {
bsalomon@google.com86afc2a2011-02-16 16:12:19 +000028 this->reset();
reed@google.comac10a2d2010-12-22 21:39:39 +000029}
30
bsalomon@google.com934c5702012-03-20 21:17:58 +000031////////////////////////////////////////////////////////////////////////////////
32
bsalomon62c447d2014-08-08 08:08:50 -070033/** 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 */
joshualitt8fc6c2d2014-12-22 15:27:05 -080043static const GrGeometryProcessor* create_rect_gp(bool hasExplicitLocalCoords,
44 GrColor color,
45 const SkMatrix* localMatrix) {
joshualitt5478d422014-11-14 16:00:38 -080046 uint32_t flags = GrDefaultGeoProcFactory::kPosition_GPType |
47 GrDefaultGeoProcFactory::kColor_GPType;
joshualitt8fc6c2d2014-12-22 15:27:05 -080048 flags |= hasExplicitLocalCoords ? GrDefaultGeoProcFactory::kLocalCoord_GPType : 0;
49 if (localMatrix) {
joshualitt50cb76b2015-04-28 09:17:05 -070050 return GrDefaultGeoProcFactory::Create(flags, color, SkMatrix::I(), *localMatrix,
51 GrColorIsOpaque(color));
joshualitt8fc6c2d2014-12-22 15:27:05 -080052 } else {
joshualitt50cb76b2015-04-28 09:17:05 -070053 return GrDefaultGeoProcFactory::Create(flags, color, SkMatrix::I(), SkMatrix::I(),
54 GrColorIsOpaque(color));
joshualitt8fc6c2d2014-12-22 15:27:05 -080055 }
bsalomon62c447d2014-08-08 08:08:50 -070056}
robertphillips@google.com42903302013-04-20 12:26:07 +000057
joshualitt58773332015-02-23 16:41:42 -080058class RectBatch : public GrBatch {
59public:
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
mtklein36352bf2015-03-25 18:17:31 -070074 const char* name() const override { return "RectBatch"; }
joshualitt58773332015-02-23 16:41:42 -080075
mtklein36352bf2015-03-25 18:17:31 -070076 void getInvariantOutputColor(GrInitInvariantOutput* out) const override {
joshualitt58773332015-02-23 16:41:42 -080077 // When this is called on a batch, there is only one geometry bundle
78 out->setKnownFourComponents(fGeoData[0].fColor);
79 }
80
mtklein36352bf2015-03-25 18:17:31 -070081 void getInvariantOutputCoverage(GrInitInvariantOutput* out) const override {
joshualitt58773332015-02-23 16:41:42 -080082 out->setKnownSingleComponent(0xff);
83 }
84
mtklein36352bf2015-03-25 18:17:31 -070085 void initBatchTracker(const GrPipelineInfo& init) override {
joshualitt58773332015-02-23 16:41:42 -080086 // 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
mtklein36352bf2015-03-25 18:17:31 -0700100 void generateGeometry(GrBatchTarget* batchTarget, const GrPipeline* pipeline) override {
joshualitt58773332015-02-23 16:41:42 -0800101 // 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
joshualitt4b31de82015-03-05 14:33:41 -0800151 if (!vertices || !batchTarget->quadIndexBuffer()) {
152 SkDebugf("Could not allocate buffers\n");
153 return;
154 }
155
joshualitt58773332015-02-23 16:41:42 -0800156 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
212private:
213 RectBatch(const Geometry& geometry) {
214 this->initClassID<RectBatch>();
215 fGeoData.push_back(geometry);
joshualitt99c7c072015-05-01 13:43:30 -0700216
217 fBounds = geometry.fRect;
218 geometry.fViewMatrix.mapRect(&fBounds);
joshualitt58773332015-02-23 16:41:42 -0800219 }
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
mtklein36352bf2015-03-25 18:17:31 -0700229 bool onCombineIfPossible(GrBatch* t) override {
joshualitt58773332015-02-23 16:41:42 -0800230 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());
joshualitt99c7c072015-05-01 13:43:30 -0700255 this->joinBounds(that->bounds());
joshualitt58773332015-02-23 16:41:42 -0800256 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
egdaniel8dd688b2015-01-22 10:16:09 -0800273void GrInOrderDrawBuffer::onDrawRect(GrPipelineBuilder* pipelineBuilder,
joshualitt2e3b3e32014-12-09 13:31:14 -0800274 GrColor color,
joshualitt8059eb92014-12-29 15:10:07 -0800275 const SkMatrix& viewMatrix,
joshualitt9853cce2014-11-17 14:22:48 -0800276 const SkRect& rect,
commit-bot@chromium.orgfd03d4a2013-07-17 21:39:42 +0000277 const SkRect* localRect,
bsalomon@google.com0406b9e2013-04-02 21:00:15 +0000278 const SkMatrix* localMatrix) {
joshualitt58773332015-02-23 16:41:42 -0800279 RectBatch::Geometry geometry;
280 geometry.fColor = color;
281 geometry.fViewMatrix = viewMatrix;
282 geometry.fRect = rect;
bsalomon@google.comd62e88e2013-02-01 14:19:27 +0000283
bsalomon49f085d2014-09-05 13:34:00 -0700284 if (localRect) {
joshualitt58773332015-02-23 16:41:42 -0800285 geometry.fHasLocalRect = true;
286 geometry.fLocalRect = *localRect;
287 } else {
288 geometry.fHasLocalRect = false;
bsalomon@google.comd62e88e2013-02-01 14:19:27 +0000289 }
290
joshualitt58773332015-02-23 16:41:42 -0800291 if (localMatrix) {
292 geometry.fHasLocalMatrix = true;
293 geometry.fLocalMatrix = *localMatrix;
294 } else {
295 geometry.fHasLocalMatrix = false;
bsalomon@google.comd62e88e2013-02-01 14:19:27 +0000296 }
297
joshualitt58773332015-02-23 16:41:42 -0800298 SkAutoTUnref<GrBatch> batch(RectBatch::Create(geometry));
joshualitt99c7c072015-05-01 13:43:30 -0700299 this->drawBatch(pipelineBuilder, batch);
bsalomon@google.comd62e88e2013-02-01 14:19:27 +0000300}
301
joshualitt4d8da812015-01-28 12:53:54 -0800302void GrInOrderDrawBuffer::onDrawBatch(GrBatch* batch,
egdaniele36914c2015-02-13 09:00:33 -0800303 const PipelineInfo& pipelineInfo) {
joshualitt5d6bb6f2015-05-04 07:41:40 -0700304 State* state = this->setupPipelineAndShouldDraw(batch, pipelineInfo);
305 if (!state) {
306 return;
307 }
308
309 GrTargetCommands::Cmd* cmd = fCommands.recordDrawBatch(state, batch);
robertphillipsdad77942015-03-03 09:28:16 -0800310 this->recordTraceMarkersIfNecessary(cmd);
311}
312
egdaniel8dd688b2015-01-22 10:16:09 -0800313void GrInOrderDrawBuffer::onStencilPath(const GrPipelineBuilder& pipelineBuilder,
joshualitt56995b52014-12-11 15:44:02 -0800314 const GrPathProcessor* pathProc,
joshualitt9853cce2014-11-17 14:22:48 -0800315 const GrPath* path,
bsalomon3e791242014-12-17 13:43:13 -0800316 const GrScissorState& scissorState,
joshualitt2c93efe2014-11-06 12:57:13 -0800317 const GrStencilSettings& stencilSettings) {
joshualitt5d6bb6f2015-05-04 07:41:40 -0700318 GrTargetCommands::Cmd* cmd = fCommands.recordStencilPath(pipelineBuilder,
robertphillipsdad77942015-03-03 09:28:16 -0800319 pathProc, path, scissorState,
320 stencilSettings);
321 this->recordTraceMarkersIfNecessary(cmd);
322}
323
egdaniele36914c2015-02-13 09:00:33 -0800324void GrInOrderDrawBuffer::onDrawPath(const GrPathProcessor* pathProc,
joshualitt9853cce2014-11-17 14:22:48 -0800325 const GrPath* path,
joshualitt2c93efe2014-11-06 12:57:13 -0800326 const GrStencilSettings& stencilSettings,
egdaniele36914c2015-02-13 09:00:33 -0800327 const PipelineInfo& pipelineInfo) {
joshualitt5d6bb6f2015-05-04 07:41:40 -0700328 State* state = this->setupPipelineAndShouldDraw(pathProc, pipelineInfo);
329 if (!state) {
330 return;
331 }
332 GrTargetCommands::Cmd* cmd = fCommands.recordDrawPath(state, pathProc, path, stencilSettings);
robertphillipsdad77942015-03-03 09:28:16 -0800333 this->recordTraceMarkersIfNecessary(cmd);
334}
335
egdaniele36914c2015-02-13 09:00:33 -0800336void GrInOrderDrawBuffer::onDrawPaths(const GrPathProcessor* pathProc,
joshualitt9853cce2014-11-17 14:22:48 -0800337 const GrPathRange* pathRange,
cdalton55b24af2014-11-25 11:00:56 -0800338 const void* indices,
339 PathIndexType indexType,
340 const float transformValues[],
341 PathTransformType transformType,
joshualitt2c93efe2014-11-06 12:57:13 -0800342 int count,
joshualitt2c93efe2014-11-06 12:57:13 -0800343 const GrStencilSettings& stencilSettings,
egdaniele36914c2015-02-13 09:00:33 -0800344 const PipelineInfo& pipelineInfo) {
joshualitt5d6bb6f2015-05-04 07:41:40 -0700345 State* state = this->setupPipelineAndShouldDraw(pathProc, pipelineInfo);
346 if (!state) {
347 return;
348 }
349 GrTargetCommands::Cmd* cmd = fCommands.recordDrawPaths(state, this, pathProc, pathRange,
robertphillipsdad77942015-03-03 09:28:16 -0800350 indices, indexType, transformValues,
351 transformType, count,
352 stencilSettings, pipelineInfo);
353 this->recordTraceMarkersIfNecessary(cmd);
354}
355
bsalomon63b21962014-11-05 07:05:34 -0800356void GrInOrderDrawBuffer::onClear(const SkIRect* rect, GrColor color,
357 bool canIgnoreRect, GrRenderTarget* renderTarget) {
joshualitt5d6bb6f2015-05-04 07:41:40 -0700358 GrTargetCommands::Cmd* cmd = fCommands.recordClear(rect, color, canIgnoreRect, renderTarget);
robertphillipsdad77942015-03-03 09:28:16 -0800359 this->recordTraceMarkersIfNecessary(cmd);
360}
361
joshualitt6db519c2014-10-29 08:48:18 -0700362void GrInOrderDrawBuffer::clearStencilClip(const SkIRect& rect,
363 bool insideClip,
364 GrRenderTarget* renderTarget) {
joshualitt5d6bb6f2015-05-04 07:41:40 -0700365 GrTargetCommands::Cmd* cmd = fCommands.recordClearStencilClip(rect, insideClip, renderTarget);
robertphillipsdad77942015-03-03 09:28:16 -0800366 this->recordTraceMarkersIfNecessary(cmd);
367}
368
commit-bot@chromium.org28361fa2014-03-28 16:08:05 +0000369void GrInOrderDrawBuffer::discard(GrRenderTarget* renderTarget) {
370 if (!this->caps()->discardRenderTargetSupport()) {
371 return;
372 }
robertphillipsdad77942015-03-03 09:28:16 -0800373
joshualitt5d6bb6f2015-05-04 07:41:40 -0700374 GrTargetCommands::Cmd* cmd = fCommands.recordDiscard(renderTarget);
robertphillipsdad77942015-03-03 09:28:16 -0800375 this->recordTraceMarkersIfNecessary(cmd);
376}
377
bsalomon371bcbc2014-12-01 08:19:34 -0800378void GrInOrderDrawBuffer::onReset() {
robertphillipsdad77942015-03-03 09:28:16 -0800379 fCommands.reset();
robertphillips9888b222015-02-27 08:50:34 -0800380 fPathIndexBuffer.rewind();
381 fPathTransformBuffer.rewind();
commit-bot@chromium.org2a05de02014-03-25 15:17:32 +0000382 fGpuCmdMarkers.reset();
joshualitt5d6bb6f2015-05-04 07:41:40 -0700383
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 }
robertphillipsdad77942015-03-03 09:28:16 -0800392}
393
bsalomon371bcbc2014-12-01 08:19:34 -0800394void GrInOrderDrawBuffer::onFlush() {
robertphillipsdad77942015-03-03 09:28:16 -0800395 fCommands.flush(this);
396 ++fDrawID;
397}
398
bsalomona73239a2015-04-28 13:35:17 -0700399void GrInOrderDrawBuffer::onCopySurface(GrSurface* dst,
bsalomonf90a02b2014-11-26 12:28:00 -0800400 GrSurface* src,
401 const SkIRect& srcRect,
402 const SkIPoint& dstPoint) {
bsalomona73239a2015-04-28 13:35:17 -0700403 SkASSERT(this->getGpu()->canCopySurface(dst, src, srcRect, dstPoint));
404 GrTargetCommands::Cmd* cmd = fCommands.recordCopySurface(dst, src, srcRect, dstPoint);
robertphillipsdad77942015-03-03 09:28:16 -0800405 this->recordTraceMarkersIfNecessary(cmd);
robertphillipsdad77942015-03-03 09:28:16 -0800406}
407
robertphillipsdad77942015-03-03 09:28:16 -0800408void GrInOrderDrawBuffer::recordTraceMarkersIfNecessary(GrTargetCommands::Cmd* cmd) {
robertphillips7f966f42015-03-02 06:40:12 -0800409 if (!cmd) {
410 return;
411 }
mtkleinf439c772014-10-14 14:29:30 -0700412 const GrTraceMarkerSet& activeTraceMarkers = this->getActiveTraceMarkers();
413 if (activeTraceMarkers.count() > 0) {
robertphillips7f966f42015-03-02 06:40:12 -0800414 if (cmd->isTraced()) {
robertphillipsbca3c9f2015-03-05 09:17:17 -0800415 fGpuCmdMarkers[cmd->markerID()].addSet(activeTraceMarkers);
robertphillips7f966f42015-03-02 06:40:12 -0800416 } else {
robertphillipsbca3c9f2015-03-05 09:17:17 -0800417 cmd->setMarkerID(fGpuCmdMarkers.count());
robertphillips7f966f42015-03-02 06:40:12 -0800418 fGpuCmdMarkers.push_back(activeTraceMarkers);
419 }
mtklein07894c42014-10-13 14:00:42 -0700420 }
mtklein07894c42014-10-13 14:00:42 -0700421}
joshualitt5d6bb6f2015-05-04 07:41:40 -0700422
423GrTargetCommands::State*
424GrInOrderDrawBuffer::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
451GrTargetCommands::State*
452GrInOrderDrawBuffer::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}