blob: 4629d4f7f03cd967da26f5b1c0f5522d8be2f85f [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
joshualitt4d8da812015-01-28 12:53:54 -080010#include "GrBufferAllocPool.h"
joshualitt5478d422014-11-14 16:00:38 -080011#include "GrDefaultGeoProcFactory.h"
bsalomon@google.comc26d94f2013-03-25 18:19:00 +000012#include "GrDrawTargetCaps.h"
bsalomon@google.comded4f4b2012-06-28 18:48:06 +000013#include "GrGpu.h"
bsalomon@google.com6e4e6502013-02-25 20:12:45 +000014#include "GrTemplates.h"
jvanverth787cdf92014-12-04 10:46:50 -080015#include "GrFontCache.h"
reed@google.comac10a2d2010-12-22 21:39:39 +000016#include "GrTexture.h"
reed@google.comac10a2d2010-12-22 21:39:39 +000017
bsalomon@google.com6e4e6502013-02-25 20:12:45 +000018GrInOrderDrawBuffer::GrInOrderDrawBuffer(GrGpu* gpu,
bsalomon@google.com471d4712011-08-23 15:45:25 +000019 GrVertexBufferAllocPool* vertexPool,
bsalomon@google.com25fb21f2011-06-21 18:17:25 +000020 GrIndexBufferAllocPool* indexPool)
bsalomon371bcbc2014-12-01 08:19:34 -080021 : INHERITED(gpu, vertexPool, indexPool)
cdalton6819df32014-10-15 13:43:48 -070022 , fCmdBuffer(kCmdBufferInitialSizeInBytes)
bsalomon932f8662014-11-24 06:47:48 -080023 , fPrevState(NULL)
joshualitt4d8da812015-01-28 12:53:54 -080024 , fDrawID(0)
25 , fBatchTarget(gpu, vertexPool, indexPool)
26 , fDrawBatch(NULL) {
bsalomon@google.com18c9c192011-09-22 21:01:31 +000027
bsalomon49f085d2014-09-05 13:34:00 -070028 SkASSERT(vertexPool);
29 SkASSERT(indexPool);
bsalomon@google.com25fb21f2011-06-21 18:17:25 +000030
cdalton3fc6a2f2014-11-13 11:54:20 -080031 fPathIndexBuffer.setReserve(kPathIdxBufferMinReserve);
32 fPathTransformBuffer.setReserve(kPathXformBufferMinReserve);
reed@google.comac10a2d2010-12-22 21:39:39 +000033}
34
35GrInOrderDrawBuffer::~GrInOrderDrawBuffer() {
bsalomon@google.com86afc2a2011-02-16 16:12:19 +000036 this->reset();
reed@google.comac10a2d2010-12-22 21:39:39 +000037}
38
bsalomon@google.com934c5702012-03-20 21:17:58 +000039////////////////////////////////////////////////////////////////////////////////
40
bsalomon@google.comd62e88e2013-02-01 14:19:27 +000041namespace {
42void get_vertex_bounds(const void* vertices,
43 size_t vertexSize,
44 int vertexCount,
45 SkRect* bounds) {
commit-bot@chromium.org972f9cd2014-03-28 17:58:28 +000046 SkASSERT(vertexSize >= sizeof(SkPoint));
tfarina@chromium.orgf6de4752013-08-17 00:02:59 +000047 SkASSERT(vertexCount > 0);
commit-bot@chromium.org972f9cd2014-03-28 17:58:28 +000048 const SkPoint* point = static_cast<const SkPoint*>(vertices);
bsalomon@google.comd62e88e2013-02-01 14:19:27 +000049 bounds->fLeft = bounds->fRight = point->fX;
50 bounds->fTop = bounds->fBottom = point->fY;
51 for (int i = 1; i < vertexCount; ++i) {
commit-bot@chromium.org972f9cd2014-03-28 17:58:28 +000052 point = reinterpret_cast<SkPoint*>(reinterpret_cast<intptr_t>(point) + vertexSize);
bsalomon@google.comd62e88e2013-02-01 14:19:27 +000053 bounds->growToInclude(point->fX, point->fY);
54 }
55}
bsalomon@google.com934c5702012-03-20 21:17:58 +000056}
57
bsalomon62c447d2014-08-08 08:08:50 -070058/** We always use per-vertex colors so that rects can be batched across color changes. Sometimes we
59 have explicit local coords and sometimes not. We *could* always provide explicit local coords
60 and just duplicate the positions when the caller hasn't provided a local coord rect, but we
61 haven't seen a use case which frequently switches between local rect and no local rect draws.
62
63 The color param is used to determine whether the opaque hint can be set on the draw state.
64 The caller must populate the vertex colors itself.
65
66 The vertex attrib order is always pos, color, [local coords].
67 */
joshualitt8fc6c2d2014-12-22 15:27:05 -080068static const GrGeometryProcessor* create_rect_gp(bool hasExplicitLocalCoords,
69 GrColor color,
70 const SkMatrix* localMatrix) {
joshualitt5478d422014-11-14 16:00:38 -080071 uint32_t flags = GrDefaultGeoProcFactory::kPosition_GPType |
72 GrDefaultGeoProcFactory::kColor_GPType;
joshualitt8fc6c2d2014-12-22 15:27:05 -080073 flags |= hasExplicitLocalCoords ? GrDefaultGeoProcFactory::kLocalCoord_GPType : 0;
74 if (localMatrix) {
joshualitt8059eb92014-12-29 15:10:07 -080075 return GrDefaultGeoProcFactory::Create(flags, color, SkMatrix::I(), *localMatrix,
76 GrColorIsOpaque(color));
joshualitt8fc6c2d2014-12-22 15:27:05 -080077 } else {
joshualitt8059eb92014-12-29 15:10:07 -080078 return GrDefaultGeoProcFactory::Create(flags, color, SkMatrix::I(), SkMatrix::I(),
79 GrColorIsOpaque(color));
joshualitt8fc6c2d2014-12-22 15:27:05 -080080 }
bsalomon62c447d2014-08-08 08:08:50 -070081}
robertphillips@google.com42903302013-04-20 12:26:07 +000082
cdalton3fc6a2f2014-11-13 11:54:20 -080083static bool path_fill_type_is_winding(const GrStencilSettings& pathStencilSettings) {
84 static const GrStencilSettings::Face pathFace = GrStencilSettings::kFront_Face;
85 bool isWinding = kInvert_StencilOp != pathStencilSettings.passOp(pathFace);
86 if (isWinding) {
87 // Double check that it is in fact winding.
88 SkASSERT(kIncClamp_StencilOp == pathStencilSettings.passOp(pathFace));
89 SkASSERT(kIncClamp_StencilOp == pathStencilSettings.failOp(pathFace));
90 SkASSERT(0x1 != pathStencilSettings.writeMask(pathFace));
91 SkASSERT(!pathStencilSettings.isTwoSided());
92 }
93 return isWinding;
94}
95
96template<typename T> static void reset_data_buffer(SkTDArray<T>* buffer, int minReserve) {
97 // Assume the next time this buffer fills up it will use approximately the same amount
98 // of space as last time. Only resize if we're using less than a third of the
99 // allocated space, and leave enough for 50% growth over last time.
100 if (3 * buffer->count() < buffer->reserved() && buffer->reserved() > minReserve) {
101 int reserve = SkTMax(minReserve, buffer->count() * 3 / 2);
102 buffer->reset();
103 buffer->setReserve(reserve);
104 } else {
105 buffer->rewind();
106 }
107}
108
commit-bot@chromium.org2a05de02014-03-25 15:17:32 +0000109enum {
110 kTraceCmdBit = 0x80,
111 kCmdMask = 0x7f,
112};
113
bsalomon62c447d2014-08-08 08:08:50 -0700114static inline uint8_t add_trace_bit(uint8_t cmd) { return cmd | kTraceCmdBit; }
commit-bot@chromium.org2a05de02014-03-25 15:17:32 +0000115
bsalomon62c447d2014-08-08 08:08:50 -0700116static inline uint8_t strip_trace_bit(uint8_t cmd) { return cmd & kCmdMask; }
commit-bot@chromium.org2a05de02014-03-25 15:17:32 +0000117
bsalomon62c447d2014-08-08 08:08:50 -0700118static inline bool cmd_has_trace_marker(uint8_t cmd) { return SkToBool(cmd & kTraceCmdBit); }
commit-bot@chromium.org2a05de02014-03-25 15:17:32 +0000119
egdaniel8dd688b2015-01-22 10:16:09 -0800120void GrInOrderDrawBuffer::onDrawRect(GrPipelineBuilder* pipelineBuilder,
joshualitt2e3b3e32014-12-09 13:31:14 -0800121 GrColor color,
joshualitt8059eb92014-12-29 15:10:07 -0800122 const SkMatrix& viewMatrix,
joshualitt9853cce2014-11-17 14:22:48 -0800123 const SkRect& rect,
commit-bot@chromium.orgfd03d4a2013-07-17 21:39:42 +0000124 const SkRect* localRect,
bsalomon@google.com0406b9e2013-04-02 21:00:15 +0000125 const SkMatrix* localMatrix) {
egdaniel8dd688b2015-01-22 10:16:09 -0800126 GrPipelineBuilder::AutoRestoreEffects are(pipelineBuilder);
jvanverth@google.com9b855c72013-03-01 18:21:22 +0000127
joshualittd27f73e2014-12-29 07:43:36 -0800128 // Go to device coords to allow batching across matrix changes
joshualittd27f73e2014-12-29 07:43:36 -0800129 SkMatrix invert = SkMatrix::I();
130
131 // if we have a local rect, then we apply the localMatrix directly to the localRect to generate
132 // vertex local coords
joshualitt8fc6c2d2014-12-22 15:27:05 -0800133 bool hasExplicitLocalCoords = SkToBool(localRect);
joshualittd27f73e2014-12-29 07:43:36 -0800134 if (!hasExplicitLocalCoords) {
joshualitt8059eb92014-12-29 15:10:07 -0800135 if (!viewMatrix.isIdentity() && !viewMatrix.invert(&invert)) {
joshualittd27f73e2014-12-29 07:43:36 -0800136 SkDebugf("Could not invert\n");
137 return;
138 }
139
140 if (localMatrix) {
141 invert.preConcat(*localMatrix);
142 }
143 }
144
145 SkAutoTUnref<const GrGeometryProcessor> gp(create_rect_gp(hasExplicitLocalCoords,
146 color,
147 &invert));
jvanverth@google.com9b855c72013-03-01 18:21:22 +0000148
joshualitt56995b52014-12-11 15:44:02 -0800149 size_t vstride = gp->getVertexStride();
joshualitt2dd1ae02014-12-03 06:24:10 -0800150 SkASSERT(vstride == sizeof(SkPoint) + sizeof(GrColor) + (SkToBool(localRect) ? sizeof(SkPoint) :
151 0));
152 AutoReleaseGeometry geo(this, 4, vstride, 0);
bsalomon@google.comd62e88e2013-02-01 14:19:27 +0000153 if (!geo.succeeded()) {
tfarina38406c82014-10-31 07:11:12 -0700154 SkDebugf("Failed to get space for vertices!\n");
bsalomon@google.com934c5702012-03-20 21:17:58 +0000155 return;
156 }
157
joshualitt8059eb92014-12-29 15:10:07 -0800158 geo.positions()->setRectFan(rect.fLeft, rect.fTop, rect.fRight, rect.fBottom, vstride);
159 viewMatrix.mapPointsWithStride(geo.positions(), vstride, 4);
160
jvanverth@google.com39768252013-02-14 15:25:44 +0000161 // When the caller has provided an explicit source rect for a stage then we don't want to
bsalomon@google.comd62e88e2013-02-01 14:19:27 +0000162 // modify that stage's matrix. Otherwise if the effect is generating its source rect from
joshualitt8059eb92014-12-29 15:10:07 -0800163 // the vertex positions then we have to account for the view matrix
bsalomon@google.comd62e88e2013-02-01 14:19:27 +0000164 SkRect devBounds;
joshualitt8059eb92014-12-29 15:10:07 -0800165
bsalomon@google.comd62e88e2013-02-01 14:19:27 +0000166 // since we already computed the dev verts, set the bounds hint. This will help us avoid
167 // unnecessary clipping in our onDraw().
egdaniel7b3d5ee2014-08-28 05:41:14 -0700168 get_vertex_bounds(geo.vertices(), vstride, 4, &devBounds);
bsalomon@google.comd62e88e2013-02-01 14:19:27 +0000169
bsalomon49f085d2014-09-05 13:34:00 -0700170 if (localRect) {
bsalomon62c447d2014-08-08 08:08:50 -0700171 static const int kLocalOffset = sizeof(SkPoint) + sizeof(GrColor);
172 SkPoint* coords = GrTCast<SkPoint*>(GrTCast<intptr_t>(geo.vertices()) + kLocalOffset);
bsalomon@google.comc7818882013-03-20 19:19:53 +0000173 coords->setRectFan(localRect->fLeft, localRect->fTop,
174 localRect->fRight, localRect->fBottom,
egdaniel7b3d5ee2014-08-28 05:41:14 -0700175 vstride);
bsalomon49f085d2014-09-05 13:34:00 -0700176 if (localMatrix) {
egdaniel7b3d5ee2014-08-28 05:41:14 -0700177 localMatrix->mapPointsWithStride(coords, vstride, 4);
bsalomon@google.comd62e88e2013-02-01 14:19:27 +0000178 }
179 }
180
bsalomon62c447d2014-08-08 08:08:50 -0700181 static const int kColorOffset = sizeof(SkPoint);
182 GrColor* vertColor = GrTCast<GrColor*>(GrTCast<intptr_t>(geo.vertices()) + kColorOffset);
183 for (int i = 0; i < 4; ++i) {
184 *vertColor = color;
egdaniel7b3d5ee2014-08-28 05:41:14 -0700185 vertColor = (GrColor*) ((intptr_t) vertColor + vstride);
bsalomon@google.comd62e88e2013-02-01 14:19:27 +0000186 }
187
bsalomon@google.com6e4e6502013-02-25 20:12:45 +0000188 this->setIndexSourceToBuffer(this->getContext()->getQuadIndexBuffer());
egdaniel8dd688b2015-01-22 10:16:09 -0800189 this->drawIndexedInstances(pipelineBuilder, gp, kTriangles_GrPrimitiveType, 1, 4, 6,
190 &devBounds);
bsalomon@google.comd62e88e2013-02-01 14:19:27 +0000191}
192
egdaniel8dd688b2015-01-22 10:16:09 -0800193int GrInOrderDrawBuffer::concatInstancedDraw(const GrPipelineBuilder& pipelineBuilder,
194 const DrawInfo& info) {
cdalton6819df32014-10-15 13:43:48 -0700195 SkASSERT(!fCmdBuffer.empty());
tfarina@chromium.orgf6de4752013-08-17 00:02:59 +0000196 SkASSERT(info.isInstanced());
bsalomon@google.comd62e88e2013-02-01 14:19:27 +0000197
bsalomon@google.com934c5702012-03-20 21:17:58 +0000198 const GeometrySrcState& geomSrc = this->getGeomSrc();
199
bsalomon@google.comd62e88e2013-02-01 14:19:27 +0000200 // we only attempt to concat the case when reserved verts are used with a client-specified index
201 // buffer. To make this work with client-specified VBs we'd need to know if the VB was updated
202 // between draws.
203 if (kReserved_GeometrySrcType != geomSrc.fVertexSrc ||
204 kBuffer_GeometrySrcType != geomSrc.fIndexSrc) {
205 return 0;
bsalomon@google.com934c5702012-03-20 21:17:58 +0000206 }
bsalomon@google.comd62e88e2013-02-01 14:19:27 +0000207 // Check if there is a draw info that is compatible that uses the same VB from the pool and
208 // the same IB
cdalton6819df32014-10-15 13:43:48 -0700209 if (kDraw_Cmd != strip_trace_bit(fCmdBuffer.back().fType)) {
bsalomon@google.comd62e88e2013-02-01 14:19:27 +0000210 return 0;
211 }
212
cdalton6819df32014-10-15 13:43:48 -0700213 Draw* draw = static_cast<Draw*>(&fCmdBuffer.back());
bsalomon@google.comd62e88e2013-02-01 14:19:27 +0000214
cdalton6819df32014-10-15 13:43:48 -0700215 if (!draw->fInfo.isInstanced() ||
joshualitt4d8da812015-01-28 12:53:54 -0800216 draw->fInfo.primitiveType() != info.primitiveType() ||
cdalton6819df32014-10-15 13:43:48 -0700217 draw->fInfo.verticesPerInstance() != info.verticesPerInstance() ||
218 draw->fInfo.indicesPerInstance() != info.indicesPerInstance() ||
bsalomon371bcbc2014-12-01 08:19:34 -0800219 draw->fInfo.vertexBuffer() != info.vertexBuffer() ||
joshualitt54e0c122014-11-19 09:38:51 -0800220 draw->fInfo.indexBuffer() != geomSrc.fIndexBuffer) {
bsalomon@google.comd62e88e2013-02-01 14:19:27 +0000221 return 0;
222 }
bsalomon371bcbc2014-12-01 08:19:34 -0800223 if (draw->fInfo.startVertex() + draw->fInfo.vertexCount() != info.startVertex()) {
bsalomon@google.comd62e88e2013-02-01 14:19:27 +0000224 return 0;
225 }
226
bsalomon@google.comd62e88e2013-02-01 14:19:27 +0000227 // how many instances can be concat'ed onto draw given the size of the index buffer
228 int instancesToConcat = this->indexCountInCurrentSource() / info.indicesPerInstance();
cdalton6819df32014-10-15 13:43:48 -0700229 instancesToConcat -= draw->fInfo.instanceCount();
commit-bot@chromium.org972f9cd2014-03-28 17:58:28 +0000230 instancesToConcat = SkTMin(instancesToConcat, info.instanceCount());
bsalomon@google.comd62e88e2013-02-01 14:19:27 +0000231
cdalton6819df32014-10-15 13:43:48 -0700232 draw->fInfo.adjustInstanceCount(instancesToConcat);
commit-bot@chromium.org2a05de02014-03-25 15:17:32 +0000233
234 // update last fGpuCmdMarkers to include any additional trace markers that have been added
235 if (this->getActiveTraceMarkers().count() > 0) {
cdalton6819df32014-10-15 13:43:48 -0700236 if (cmd_has_trace_marker(draw->fType)) {
commit-bot@chromium.org2a05de02014-03-25 15:17:32 +0000237 fGpuCmdMarkers.back().addSet(this->getActiveTraceMarkers());
238 } else {
239 fGpuCmdMarkers.push_back(this->getActiveTraceMarkers());
cdalton6819df32014-10-15 13:43:48 -0700240 draw->fType = add_trace_bit(draw->fType);
commit-bot@chromium.org2a05de02014-03-25 15:17:32 +0000241 }
242 }
243
bsalomon@google.comd62e88e2013-02-01 14:19:27 +0000244 return instancesToConcat;
bsalomon@google.com934c5702012-03-20 21:17:58 +0000245}
246
egdaniel8dd688b2015-01-22 10:16:09 -0800247void GrInOrderDrawBuffer::onDraw(const GrPipelineBuilder& pipelineBuilder,
joshualitt56995b52014-12-11 15:44:02 -0800248 const GrGeometryProcessor* gp,
joshualitt9853cce2014-11-17 14:22:48 -0800249 const DrawInfo& info,
egdaniel74a11752015-02-03 15:02:43 -0800250 const GrScissorState& scissorState) {
joshualitt7eb8c7b2014-11-18 14:24:27 -0800251 SkASSERT(info.vertexBuffer() && (!info.isIndexed() || info.indexBuffer()));
252
joshualitt4d8da812015-01-28 12:53:54 -0800253 // This closeBatch call is required because we may introduce new draws when we setup clip
254 this->closeBatch();
255
egdaniel74a11752015-02-03 15:02:43 -0800256 if (!this->recordStateAndShouldDraw(pipelineBuilder, gp, scissorState, info.getDevBounds())) {
bsalomonae59b772014-11-19 08:23:49 -0800257 return;
258 }
bsalomon@google.com86afc2a2011-02-16 16:12:19 +0000259
bsalomonb3e3a952014-09-19 11:10:40 -0700260 Draw* draw;
bsalomon@google.comd62e88e2013-02-01 14:19:27 +0000261 if (info.isInstanced()) {
egdaniel8dd688b2015-01-22 10:16:09 -0800262 int instancesConcated = this->concatInstancedDraw(pipelineBuilder, info);
bsalomon@google.comd62e88e2013-02-01 14:19:27 +0000263 if (info.instanceCount() > instancesConcated) {
joshualitt54e0c122014-11-19 09:38:51 -0800264 draw = GrNEW_APPEND_TO_RECORDER(fCmdBuffer, Draw, (info));
cdalton6819df32014-10-15 13:43:48 -0700265 draw->fInfo.adjustInstanceCount(-instancesConcated);
bsalomon@google.comd62e88e2013-02-01 14:19:27 +0000266 } else {
267 return;
268 }
269 } else {
joshualitt54e0c122014-11-19 09:38:51 -0800270 draw = GrNEW_APPEND_TO_RECORDER(fCmdBuffer, Draw, (info));
bsalomon@google.comd62e88e2013-02-01 14:19:27 +0000271 }
cdalton6819df32014-10-15 13:43:48 -0700272 this->recordTraceMarkersIfNecessary();
commit-bot@chromium.org9b62aa12014-03-25 11:59:40 +0000273}
sugoi@google.com5f74cf82012-12-17 21:16:45 +0000274
joshualitt4d8da812015-01-28 12:53:54 -0800275void GrInOrderDrawBuffer::onDrawBatch(GrBatch* batch,
276 const GrPipelineBuilder& pipelineBuilder,
277 const GrScissorState& scissorState,
egdaniel74a11752015-02-03 15:02:43 -0800278 const SkRect* devBounds) {
279 if (!this->recordStateAndShouldDraw(batch, pipelineBuilder, scissorState, devBounds)) {
joshualitt4d8da812015-01-28 12:53:54 -0800280 return;
281 }
282
283 // Check if there is a Batch Draw we can batch with
284 if (kDrawBatch_Cmd != strip_trace_bit(fCmdBuffer.back().fType)) {
285 fDrawBatch = GrNEW_APPEND_TO_RECORDER(fCmdBuffer, DrawBatch, (batch));
286 return;
287 }
288
289 DrawBatch* draw = static_cast<DrawBatch*>(&fCmdBuffer.back());
290 if (draw->fBatch->combineIfPossible(batch)) {
291 return;
292 } else {
293 this->closeBatch();
294 fDrawBatch = GrNEW_APPEND_TO_RECORDER(fCmdBuffer, DrawBatch, (batch));
295 }
296 this->recordTraceMarkersIfNecessary();
297}
298
egdaniel8dd688b2015-01-22 10:16:09 -0800299void GrInOrderDrawBuffer::onStencilPath(const GrPipelineBuilder& pipelineBuilder,
joshualitt56995b52014-12-11 15:44:02 -0800300 const GrPathProcessor* pathProc,
joshualitt9853cce2014-11-17 14:22:48 -0800301 const GrPath* path,
bsalomon3e791242014-12-17 13:43:13 -0800302 const GrScissorState& scissorState,
joshualitt2c93efe2014-11-06 12:57:13 -0800303 const GrStencilSettings& stencilSettings) {
bsalomon3e791242014-12-17 13:43:13 -0800304 StencilPath* sp = GrNEW_APPEND_TO_RECORDER(fCmdBuffer, StencilPath,
egdaniel8dd688b2015-01-22 10:16:09 -0800305 (path, pipelineBuilder.getRenderTarget()));
bsalomon3e791242014-12-17 13:43:13 -0800306 sp->fScissor = scissorState;
egdaniel8dd688b2015-01-22 10:16:09 -0800307 sp->fUseHWAA = pipelineBuilder.isHWAntialias();
joshualitt8059eb92014-12-29 15:10:07 -0800308 sp->fViewMatrix = pathProc->viewMatrix();
bsalomon3e791242014-12-17 13:43:13 -0800309 sp->fStencil = stencilSettings;
cdalton6819df32014-10-15 13:43:48 -0700310 this->recordTraceMarkersIfNecessary();
bsalomon@google.com64aef2b2012-06-11 15:36:13 +0000311}
312
egdaniel8dd688b2015-01-22 10:16:09 -0800313void GrInOrderDrawBuffer::onDrawPath(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,
egdaniel74a11752015-02-03 15:02:43 -0800318 const SkRect* devBounds) {
joshualitt4d8da812015-01-28 12:53:54 -0800319 this->closeBatch();
320
egdaniel8dd688b2015-01-22 10:16:09 -0800321 // TODO: Only compare the subset of GrPipelineBuilder relevant to path covering?
egdaniel74a11752015-02-03 15:02:43 -0800322 if (!this->recordStateAndShouldDraw(pipelineBuilder, pathProc, scissorState, devBounds)) {
bsalomonae59b772014-11-19 08:23:49 -0800323 return;
324 }
cdalton6819df32014-10-15 13:43:48 -0700325 DrawPath* dp = GrNEW_APPEND_TO_RECORDER(fCmdBuffer, DrawPath, (path));
joshualitt2c93efe2014-11-06 12:57:13 -0800326 dp->fStencilSettings = stencilSettings;
cdalton6819df32014-10-15 13:43:48 -0700327 this->recordTraceMarkersIfNecessary();
commit-bot@chromium.orgc4dc0ad2013-10-09 14:11:33 +0000328}
329
egdaniel8dd688b2015-01-22 10:16:09 -0800330void GrInOrderDrawBuffer::onDrawPaths(const GrPipelineBuilder& pipelineBuilder,
joshualitt56995b52014-12-11 15:44:02 -0800331 const GrPathProcessor* pathProc,
joshualitt9853cce2014-11-17 14:22:48 -0800332 const GrPathRange* pathRange,
cdalton55b24af2014-11-25 11:00:56 -0800333 const void* indices,
334 PathIndexType indexType,
335 const float transformValues[],
336 PathTransformType transformType,
joshualitt2c93efe2014-11-06 12:57:13 -0800337 int count,
bsalomon3e791242014-12-17 13:43:13 -0800338 const GrScissorState& scissorState,
joshualitt2c93efe2014-11-06 12:57:13 -0800339 const GrStencilSettings& stencilSettings,
egdaniel74a11752015-02-03 15:02:43 -0800340 const SkRect* devBounds) {
bsalomon49f085d2014-09-05 13:34:00 -0700341 SkASSERT(pathRange);
342 SkASSERT(indices);
cdalton55b24af2014-11-25 11:00:56 -0800343 SkASSERT(transformValues);
commit-bot@chromium.org9b62aa12014-03-25 11:59:40 +0000344
joshualitt4d8da812015-01-28 12:53:54 -0800345 this->closeBatch();
346
egdaniel74a11752015-02-03 15:02:43 -0800347 if (!this->recordStateAndShouldDraw(pipelineBuilder, pathProc, scissorState, devBounds)) {
bsalomonae59b772014-11-19 08:23:49 -0800348 return;
349 }
cdalton6819df32014-10-15 13:43:48 -0700350
cdalton55b24af2014-11-25 11:00:56 -0800351 int indexBytes = GrPathRange::PathIndexSizeInBytes(indexType);
352 if (int misalign = fPathIndexBuffer.count() % indexBytes) {
353 // Add padding to the index buffer so the indices are aligned properly.
354 fPathIndexBuffer.append(indexBytes - misalign);
355 }
356
357 char* savedIndices = fPathIndexBuffer.append(count * indexBytes,
358 reinterpret_cast<const char*>(indices));
359 float* savedTransforms = fPathTransformBuffer.append(
360 count * GrPathRendering::PathTransformSize(transformType),
361 transformValues);
cdalton6819df32014-10-15 13:43:48 -0700362
cdalton3fc6a2f2014-11-13 11:54:20 -0800363 if (kDrawPaths_Cmd == strip_trace_bit(fCmdBuffer.back().fType)) {
364 // The previous command was also DrawPaths. Try to collapse this call into the one
bsalomon371bcbc2014-12-01 08:19:34 -0800365 // before. Note that stenciling all the paths at once, then covering, may not be
cdalton3fc6a2f2014-11-13 11:54:20 -0800366 // equivalent to two separate draw calls if there is overlap. Blending won't work,
367 // and the combined calls may also cancel each other's winding numbers in some
368 // places. For now the winding numbers are only an issue if the fill is even/odd,
369 // because DrawPaths is currently only used for glyphs, and glyphs in the same
370 // font tend to all wind in the same direction.
371 DrawPaths* previous = static_cast<DrawPaths*>(&fCmdBuffer.back());
372 if (pathRange == previous->pathRange() &&
cdalton55b24af2014-11-25 11:00:56 -0800373 indexType == previous->fIndexType &&
374 transformType == previous->fTransformType &&
cdalton3fc6a2f2014-11-13 11:54:20 -0800375 stencilSettings == previous->fStencilSettings &&
376 path_fill_type_is_winding(stencilSettings) &&
egdaniel8dd688b2015-01-22 10:16:09 -0800377 !pipelineBuilder.willBlendWithDst(pathProc)) {
cdalton3fc6a2f2014-11-13 11:54:20 -0800378 // Fold this DrawPaths call into the one previous.
379 previous->fCount += count;
380 return;
381 }
382 }
383
384 DrawPaths* dp = GrNEW_APPEND_TO_RECORDER(fCmdBuffer, DrawPaths, (pathRange));
bsalomonef3fcd82014-12-12 08:51:38 -0800385 dp->fIndicesLocation = SkToU32(savedIndices - fPathIndexBuffer.begin());
cdalton55b24af2014-11-25 11:00:56 -0800386 dp->fIndexType = indexType;
bsalomonef3fcd82014-12-12 08:51:38 -0800387 dp->fTransformsLocation = SkToU32(savedTransforms - fPathTransformBuffer.begin());
cdalton55b24af2014-11-25 11:00:56 -0800388 dp->fTransformType = transformType;
389 dp->fCount = count;
joshualitt2c93efe2014-11-06 12:57:13 -0800390 dp->fStencilSettings = stencilSettings;
cdalton6819df32014-10-15 13:43:48 -0700391
392 this->recordTraceMarkersIfNecessary();
commit-bot@chromium.org9b62aa12014-03-25 11:59:40 +0000393}
394
bsalomon63b21962014-11-05 07:05:34 -0800395void GrInOrderDrawBuffer::onClear(const SkIRect* rect, GrColor color,
396 bool canIgnoreRect, GrRenderTarget* renderTarget) {
joshualitt9853cce2014-11-17 14:22:48 -0800397 SkASSERT(renderTarget);
commit-bot@chromium.orgfd03d4a2013-07-17 21:39:42 +0000398 SkIRect r;
bsalomon@google.com6aa25c32011-04-27 19:55:29 +0000399 if (NULL == rect) {
400 // We could do something smart and remove previous draws and clears to
401 // the current render target. If we get that smart we have to make sure
402 // those draws aren't read before this clear (render-to-texture).
bsalomon@google.com1b3ce472012-08-17 13:43:08 +0000403 r.setLTRB(0, 0, renderTarget->width(), renderTarget->height());
bsalomon@google.com6aa25c32011-04-27 19:55:29 +0000404 rect = &r;
405 }
cdalton6819df32014-10-15 13:43:48 -0700406 Clear* clr = GrNEW_APPEND_TO_RECORDER(fCmdBuffer, Clear, (renderTarget));
commit-bot@chromium.org28361fa2014-03-28 16:08:05 +0000407 GrColorIsPMAssert(color);
bsalomon@google.coma4f6b102012-06-26 21:04:22 +0000408 clr->fColor = color;
409 clr->fRect = *rect;
robertphillips@google.com56ce48a2013-10-31 21:44:25 +0000410 clr->fCanIgnoreRect = canIgnoreRect;
cdalton6819df32014-10-15 13:43:48 -0700411 this->recordTraceMarkersIfNecessary();
bsalomon@google.com0b335c12011-04-25 19:17:44 +0000412}
413
joshualitt6db519c2014-10-29 08:48:18 -0700414void GrInOrderDrawBuffer::clearStencilClip(const SkIRect& rect,
415 bool insideClip,
416 GrRenderTarget* renderTarget) {
joshualitt9853cce2014-11-17 14:22:48 -0800417 SkASSERT(renderTarget);
joshualitt6db519c2014-10-29 08:48:18 -0700418 ClearStencilClip* clr = GrNEW_APPEND_TO_RECORDER(fCmdBuffer, ClearStencilClip, (renderTarget));
419 clr->fRect = rect;
420 clr->fInsideClip = insideClip;
421 this->recordTraceMarkersIfNecessary();
422}
423
commit-bot@chromium.org28361fa2014-03-28 16:08:05 +0000424void GrInOrderDrawBuffer::discard(GrRenderTarget* renderTarget) {
bsalomon89c62982014-11-03 12:08:42 -0800425 SkASSERT(renderTarget);
commit-bot@chromium.org28361fa2014-03-28 16:08:05 +0000426 if (!this->caps()->discardRenderTargetSupport()) {
427 return;
428 }
cdalton6819df32014-10-15 13:43:48 -0700429 Clear* clr = GrNEW_APPEND_TO_RECORDER(fCmdBuffer, Clear, (renderTarget));
commit-bot@chromium.org28361fa2014-03-28 16:08:05 +0000430 clr->fColor = GrColor_ILLEGAL;
cdalton6819df32014-10-15 13:43:48 -0700431 this->recordTraceMarkersIfNecessary();
commit-bot@chromium.org28361fa2014-03-28 16:08:05 +0000432}
433
bsalomon371bcbc2014-12-01 08:19:34 -0800434void GrInOrderDrawBuffer::onReset() {
cdalton6819df32014-10-15 13:43:48 -0700435 fCmdBuffer.reset();
bsalomon932f8662014-11-24 06:47:48 -0800436 fPrevState = NULL;
cdalton3fc6a2f2014-11-13 11:54:20 -0800437 reset_data_buffer(&fPathIndexBuffer, kPathIdxBufferMinReserve);
438 reset_data_buffer(&fPathTransformBuffer, kPathXformBufferMinReserve);
commit-bot@chromium.org2a05de02014-03-25 15:17:32 +0000439 fGpuCmdMarkers.reset();
joshualitt4d8da812015-01-28 12:53:54 -0800440 fDrawBatch = NULL;
reed@google.comac10a2d2010-12-22 21:39:39 +0000441}
442
bsalomon371bcbc2014-12-01 08:19:34 -0800443void GrInOrderDrawBuffer::onFlush() {
cdalton6819df32014-10-15 13:43:48 -0700444 if (fCmdBuffer.empty()) {
robertphillips@google.com1267fbd2013-07-03 18:37:27 +0000445 return;
reed@google.comac10a2d2010-12-22 21:39:39 +0000446 }
bsalomon@google.com6e4e6502013-02-25 20:12:45 +0000447
joshualittc2893c52015-01-28 06:54:30 -0800448 // Updated every time we find a set state cmd to reflect the current state in the playback
449 // stream.
450 SetState* currentState = NULL;
451
joshualitt4d8da812015-01-28 12:53:54 -0800452 // TODO this is temporary while batch is being rolled out
453 this->closeBatch();
454 this->getVertexAllocPool()->unmap();
455 this->getIndexAllocPool()->unmap();
456 fBatchTarget.preFlush();
457
458 currentState = NULL;
459 CmdBuffer::Iter iter(fCmdBuffer);
460
461 int currCmdMarker = 0;
462
cdalton6819df32014-10-15 13:43:48 -0700463 while (iter.next()) {
commit-bot@chromium.org2a05de02014-03-25 15:17:32 +0000464 GrGpuTraceMarker newMarker("", -1);
egdanield78a1682014-07-09 10:41:26 -0700465 SkString traceString;
cdalton6819df32014-10-15 13:43:48 -0700466 if (cmd_has_trace_marker(iter->fType)) {
egdanield78a1682014-07-09 10:41:26 -0700467 traceString = fGpuCmdMarkers[currCmdMarker].toString();
commit-bot@chromium.org2a05de02014-03-25 15:17:32 +0000468 newMarker.fMarker = traceString.c_str();
bsalomon371bcbc2014-12-01 08:19:34 -0800469 this->getGpu()->addGpuTraceMarker(&newMarker);
commit-bot@chromium.org2a05de02014-03-25 15:17:32 +0000470 ++currCmdMarker;
471 }
cdalton6819df32014-10-15 13:43:48 -0700472
joshualitt4d8da812015-01-28 12:53:54 -0800473 // TODO temporary hack
474 if (kDrawBatch_Cmd == strip_trace_bit(iter->fType)) {
joshualitt46c77f72015-02-03 08:40:22 -0800475 fBatchTarget.flushNext();
joshualitt4d8da812015-01-28 12:53:54 -0800476 continue;
477 }
478
479 bool isSetState = kSetState_Cmd == strip_trace_bit(iter->fType);
480 if (isSetState) {
joshualitt9853cce2014-11-17 14:22:48 -0800481 SetState* ss = reinterpret_cast<SetState*>(iter.get());
joshualitt873ad0e2015-01-20 09:08:51 -0800482
joshualitt4d8da812015-01-28 12:53:54 -0800483 // TODO sometimes we have a prim proc, othertimes we have a GrBatch. Eventually we will
484 // only have GrBatch and we can delete this
485 if (ss->fPrimitiveProcessor) {
486 this->getGpu()->buildProgramDesc(&ss->fDesc, *ss->fPrimitiveProcessor,
487 ss->fPipeline,
joshualitt4d8da812015-01-28 12:53:54 -0800488 ss->fBatchTracker);
489 }
joshualitt873ad0e2015-01-20 09:08:51 -0800490 currentState = ss;
joshualittd53a8272014-11-10 16:03:14 -0800491 } else {
joshualitt873ad0e2015-01-20 09:08:51 -0800492 iter->execute(this, currentState);
joshualittd53a8272014-11-10 16:03:14 -0800493 }
cdalton6819df32014-10-15 13:43:48 -0700494
495 if (cmd_has_trace_marker(iter->fType)) {
bsalomon371bcbc2014-12-01 08:19:34 -0800496 this->getGpu()->removeGpuTraceMarker(&newMarker);
commit-bot@chromium.org2a05de02014-03-25 15:17:32 +0000497 }
reed@google.comac10a2d2010-12-22 21:39:39 +0000498 }
mtkleinf439c772014-10-14 14:29:30 -0700499
joshualitt4d8da812015-01-28 12:53:54 -0800500 // TODO see copious notes about hack
501 fBatchTarget.postFlush();
502
commit-bot@chromium.org2a05de02014-03-25 15:17:32 +0000503 SkASSERT(fGpuCmdMarkers.count() == currCmdMarker);
commit-bot@chromium.orga8916ff2013-08-16 15:53:46 +0000504 ++fDrawID;
reed@google.comac10a2d2010-12-22 21:39:39 +0000505}
506
joshualitt873ad0e2015-01-20 09:08:51 -0800507void GrInOrderDrawBuffer::Draw::execute(GrInOrderDrawBuffer* buf, const SetState* state) {
508 SkASSERT(state);
egdaniel8dd688b2015-01-22 10:16:09 -0800509 DrawArgs args(state->fPrimitiveProcessor.get(), &state->fPipeline, &state->fDesc,
joshualitt17e73142015-01-21 11:52:36 -0800510 &state->fBatchTracker);
joshualitt873ad0e2015-01-20 09:08:51 -0800511 buf->getGpu()->draw(args, fInfo);
cdalton6819df32014-10-15 13:43:48 -0700512}
513
joshualitt873ad0e2015-01-20 09:08:51 -0800514void GrInOrderDrawBuffer::StencilPath::execute(GrInOrderDrawBuffer* buf, const SetState*) {
bsalomon3e791242014-12-17 13:43:13 -0800515 GrGpu::StencilPathState state;
516 state.fRenderTarget = fRenderTarget.get();
517 state.fScissor = &fScissor;
518 state.fStencil = &fStencil;
519 state.fUseHWAA = fUseHWAA;
520 state.fViewMatrix = &fViewMatrix;
521
522 buf->getGpu()->stencilPath(this->path(), state);
cdalton6819df32014-10-15 13:43:48 -0700523}
524
joshualitt873ad0e2015-01-20 09:08:51 -0800525void GrInOrderDrawBuffer::DrawPath::execute(GrInOrderDrawBuffer* buf, const SetState* state) {
526 SkASSERT(state);
egdaniel8dd688b2015-01-22 10:16:09 -0800527 DrawArgs args(state->fPrimitiveProcessor.get(), &state->fPipeline, &state->fDesc,
joshualitt17e73142015-01-21 11:52:36 -0800528 &state->fBatchTracker);
joshualitt873ad0e2015-01-20 09:08:51 -0800529 buf->getGpu()->drawPath(args, this->path(), fStencilSettings);
cdalton6819df32014-10-15 13:43:48 -0700530}
531
joshualitt873ad0e2015-01-20 09:08:51 -0800532void GrInOrderDrawBuffer::DrawPaths::execute(GrInOrderDrawBuffer* buf, const SetState* state) {
533 SkASSERT(state);
egdaniel8dd688b2015-01-22 10:16:09 -0800534 DrawArgs args(state->fPrimitiveProcessor.get(), &state->fPipeline, &state->fDesc,
joshualitt17e73142015-01-21 11:52:36 -0800535 &state->fBatchTracker);
joshualitt873ad0e2015-01-20 09:08:51 -0800536 buf->getGpu()->drawPaths(args, this->pathRange(),
cdalton55b24af2014-11-25 11:00:56 -0800537 &buf->fPathIndexBuffer[fIndicesLocation], fIndexType,
538 &buf->fPathTransformBuffer[fTransformsLocation], fTransformType,
539 fCount, fStencilSettings);
cdalton6819df32014-10-15 13:43:48 -0700540}
541
joshualitt4d8da812015-01-28 12:53:54 -0800542void GrInOrderDrawBuffer::DrawBatch::execute(GrInOrderDrawBuffer* buf, const SetState* state) {
543 SkASSERT(state);
544 fBatch->generateGeometry(buf->getBatchTarget(), &state->fPipeline);
545}
546
joshualitt873ad0e2015-01-20 09:08:51 -0800547void GrInOrderDrawBuffer::SetState::execute(GrInOrderDrawBuffer*, const SetState*) {}
cdalton6819df32014-10-15 13:43:48 -0700548
joshualitt873ad0e2015-01-20 09:08:51 -0800549void GrInOrderDrawBuffer::Clear::execute(GrInOrderDrawBuffer* buf, const SetState*) {
cdalton6819df32014-10-15 13:43:48 -0700550 if (GrColor_ILLEGAL == fColor) {
bsalomon371bcbc2014-12-01 08:19:34 -0800551 buf->getGpu()->discard(this->renderTarget());
cdalton6819df32014-10-15 13:43:48 -0700552 } else {
bsalomon371bcbc2014-12-01 08:19:34 -0800553 buf->getGpu()->clear(&fRect, fColor, fCanIgnoreRect, this->renderTarget());
cdalton6819df32014-10-15 13:43:48 -0700554 }
555}
556
joshualitt873ad0e2015-01-20 09:08:51 -0800557void GrInOrderDrawBuffer::ClearStencilClip::execute(GrInOrderDrawBuffer* buf, const SetState*) {
bsalomon371bcbc2014-12-01 08:19:34 -0800558 buf->getGpu()->clearStencilClip(fRect, fInsideClip, this->renderTarget());
joshualitt6db519c2014-10-29 08:48:18 -0700559}
560
joshualitt873ad0e2015-01-20 09:08:51 -0800561void GrInOrderDrawBuffer::CopySurface::execute(GrInOrderDrawBuffer* buf, const SetState*) {
bsalomon371bcbc2014-12-01 08:19:34 -0800562 buf->getGpu()->copySurface(this->dst(), this->src(), fSrcRect, fDstPoint);
cdalton6819df32014-10-15 13:43:48 -0700563}
564
bsalomonf90a02b2014-11-26 12:28:00 -0800565bool GrInOrderDrawBuffer::onCopySurface(GrSurface* dst,
566 GrSurface* src,
567 const SkIRect& srcRect,
568 const SkIPoint& dstPoint) {
bsalomon371bcbc2014-12-01 08:19:34 -0800569 if (getGpu()->canCopySurface(dst, src, srcRect, dstPoint)) {
cdalton6819df32014-10-15 13:43:48 -0700570 CopySurface* cs = GrNEW_APPEND_TO_RECORDER(fCmdBuffer, CopySurface, (dst, src));
bsalomon@google.com116ad842013-04-09 15:38:19 +0000571 cs->fSrcRect = srcRect;
572 cs->fDstPoint = dstPoint;
cdalton6819df32014-10-15 13:43:48 -0700573 this->recordTraceMarkersIfNecessary();
bsalomon@google.com116ad842013-04-09 15:38:19 +0000574 return true;
bsalomon@google.com116ad842013-04-09 15:38:19 +0000575 }
bsalomonf90a02b2014-11-26 12:28:00 -0800576 return false;
bsalomon@google.com116ad842013-04-09 15:38:19 +0000577}
578
egdaniel8dd688b2015-01-22 10:16:09 -0800579bool GrInOrderDrawBuffer::recordStateAndShouldDraw(const GrPipelineBuilder& pipelineBuilder,
joshualitt71c92602015-01-14 08:12:47 -0800580 const GrPrimitiveProcessor* primProc,
bsalomon3e791242014-12-17 13:43:13 -0800581 const GrScissorState& scissor,
egdaniel74a11752015-02-03 15:02:43 -0800582 const SkRect* devBounds) {
583 GrDeviceCoordTexture dstCopy;
584 if (!this->setupDstReadIfNecessary(pipelineBuilder, &dstCopy, devBounds)) {
585 return false;
586 }
bsalomon932f8662014-11-24 06:47:48 -0800587 SetState* ss = GrNEW_APPEND_TO_RECORDER(fCmdBuffer, SetState,
egdaniel8dd688b2015-01-22 10:16:09 -0800588 (pipelineBuilder, primProc, *this->getGpu()->caps(),
egdaniel74a11752015-02-03 15:02:43 -0800589 scissor, &dstCopy));
egdaniel8dd688b2015-01-22 10:16:09 -0800590 if (ss->fPipeline.mustSkip()) {
bsalomon932f8662014-11-24 06:47:48 -0800591 fCmdBuffer.pop_back();
bsalomonae59b772014-11-19 08:23:49 -0800592 return false;
593 }
joshualitt873ad0e2015-01-20 09:08:51 -0800594
595 ss->fPrimitiveProcessor->initBatchTracker(&ss->fBatchTracker,
egdaniel8dd688b2015-01-22 10:16:09 -0800596 ss->fPipeline.getInitBatchTracker());
joshualitt873ad0e2015-01-20 09:08:51 -0800597
joshualitt4d8da812015-01-28 12:53:54 -0800598 if (fPrevState && fPrevState->fPrimitiveProcessor.get() &&
joshualitt873ad0e2015-01-20 09:08:51 -0800599 fPrevState->fPrimitiveProcessor->canMakeEqual(fPrevState->fBatchTracker,
600 *ss->fPrimitiveProcessor,
601 ss->fBatchTracker) &&
egdaniel8dd688b2015-01-22 10:16:09 -0800602 fPrevState->fPipeline.isEqual(ss->fPipeline)) {
bsalomon932f8662014-11-24 06:47:48 -0800603 fCmdBuffer.pop_back();
604 } else {
joshualitt873ad0e2015-01-20 09:08:51 -0800605 fPrevState = ss;
cdalton6819df32014-10-15 13:43:48 -0700606 this->recordTraceMarkersIfNecessary();
bsalomon838f62d2014-08-05 07:15:57 -0700607 }
bsalomonae59b772014-11-19 08:23:49 -0800608 return true;
reed@google.comac10a2d2010-12-22 21:39:39 +0000609}
610
joshualitt4d8da812015-01-28 12:53:54 -0800611bool GrInOrderDrawBuffer::recordStateAndShouldDraw(GrBatch* batch,
612 const GrPipelineBuilder& pipelineBuilder,
613 const GrScissorState& scissor,
egdaniel74a11752015-02-03 15:02:43 -0800614 const SkRect* devBounds) {
615 GrDeviceCoordTexture dstCopy;
616 if (!this->setupDstReadIfNecessary(pipelineBuilder, &dstCopy, devBounds)) {
617 return false;
618 }
joshualitt4d8da812015-01-28 12:53:54 -0800619 // TODO this gets much simpler when we have batches everywhere.
620 // If the previous command is also a set state, then we check to see if it has a Batch. If so,
621 // and we can make the two batches equal, and we can combine the states, then we make them equal
622 SetState* ss = GrNEW_APPEND_TO_RECORDER(fCmdBuffer, SetState,
623 (batch, pipelineBuilder, *this->getGpu()->caps(), scissor,
egdaniel74a11752015-02-03 15:02:43 -0800624 &dstCopy));
joshualitt4d8da812015-01-28 12:53:54 -0800625 if (ss->fPipeline.mustSkip()) {
626 fCmdBuffer.pop_back();
627 return false;
628 }
629
630 batch->initBatchTracker(ss->fPipeline.getInitBatchTracker());
631
632 if (fPrevState && !fPrevState->fPrimitiveProcessor.get() &&
633 fPrevState->fPipeline.isEqual(ss->fPipeline)) {
634 fCmdBuffer.pop_back();
635 } else {
636 this->closeBatch();
637 fPrevState = ss;
638 this->recordTraceMarkersIfNecessary();
639 }
640 return true;
641}
642
cdalton6819df32014-10-15 13:43:48 -0700643void GrInOrderDrawBuffer::recordTraceMarkersIfNecessary() {
644 SkASSERT(!fCmdBuffer.empty());
645 SkASSERT(!cmd_has_trace_marker(fCmdBuffer.back().fType));
mtkleinf439c772014-10-14 14:29:30 -0700646 const GrTraceMarkerSet& activeTraceMarkers = this->getActiveTraceMarkers();
647 if (activeTraceMarkers.count() > 0) {
cdalton6819df32014-10-15 13:43:48 -0700648 fCmdBuffer.back().fType = add_trace_bit(fCmdBuffer.back().fType);
mtkleinf439c772014-10-14 14:29:30 -0700649 fGpuCmdMarkers.push_back(activeTraceMarkers);
mtklein07894c42014-10-13 14:00:42 -0700650 }
mtklein07894c42014-10-13 14:00:42 -0700651}
joshualitt4d8da812015-01-28 12:53:54 -0800652
653void GrInOrderDrawBuffer::closeBatch() {
654 if (fDrawBatch) {
655 fDrawBatch->execute(this, fPrevState);
656 fDrawBatch = NULL;
657 }
658}
659
660void GrInOrderDrawBuffer::willReserveVertexAndIndexSpace(int vertexCount,
661 size_t vertexStride,
662 int indexCount) {
663 this->closeBatch();
664
665 // We use geometryHints() to know whether to flush the draw buffer. We
666 // can't flush if we are inside an unbalanced pushGeometrySource.
667 // Moreover, flushing blows away vertex and index data that was
668 // previously reserved. So if the vertex or index data is pulled from
669 // reserved space and won't be released by this request then we can't
670 // flush.
671 bool insideGeoPush = this->getGeoPoolStateStack().count() > 1;
672
673 bool unreleasedVertexSpace =
674 !vertexCount &&
675 kReserved_GeometrySrcType == this->getGeomSrc().fVertexSrc;
676
677 bool unreleasedIndexSpace =
678 !indexCount &&
679 kReserved_GeometrySrcType == this->getGeomSrc().fIndexSrc;
680
681 int vcount = vertexCount;
682 int icount = indexCount;
683
684 if (!insideGeoPush &&
685 !unreleasedVertexSpace &&
686 !unreleasedIndexSpace &&
687 this->geometryHints(vertexStride, &vcount, &icount)) {
688 this->flush();
689 }
690}