blob: 43779675bd0f99ad89f56ce9f988caf8332611b1 [file] [log] [blame]
epoger@google.comec3ed6a2011-07-28 14:26:00 +00001
reed@google.comac10a2d2010-12-22 21:39:39 +00002/*
epoger@google.comec3ed6a2011-07-28 14:26:00 +00003 * Copyright 2011 Google Inc.
4 *
5 * Use of this source code is governed by a BSD-style license that can be
6 * found in the LICENSE file.
reed@google.comac10a2d2010-12-22 21:39:39 +00007 */
8
9
10#include "GrInOrderDrawBuffer.h"
bsalomon@google.comded4f4b2012-06-28 18:48:06 +000011#include "GrBufferAllocPool.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"
14#include "GrIndexBuffer.h"
15#include "GrPath.h"
bsalomon@google.com8f9cbd62011-12-09 15:55:34 +000016#include "GrRenderTarget.h"
bsalomon@google.com6e4e6502013-02-25 20:12:45 +000017#include "GrTemplates.h"
reed@google.comac10a2d2010-12-22 21:39:39 +000018#include "GrTexture.h"
bsalomon@google.com86afc2a2011-02-16 16:12:19 +000019#include "GrVertexBuffer.h"
reed@google.comac10a2d2010-12-22 21:39:39 +000020
bsalomon@google.com6e4e6502013-02-25 20:12:45 +000021GrInOrderDrawBuffer::GrInOrderDrawBuffer(GrGpu* gpu,
bsalomon@google.com471d4712011-08-23 15:45:25 +000022 GrVertexBufferAllocPool* vertexPool,
bsalomon@google.com25fb21f2011-06-21 18:17:25 +000023 GrIndexBufferAllocPool* indexPool)
bsalomon@google.com6e4e6502013-02-25 20:12:45 +000024 : GrDrawTarget(gpu->getContext())
25 , fDstGpu(gpu)
bsalomon@google.com97805382012-03-13 14:32:07 +000026 , fClipSet(true)
bsalomon@google.comd62e88e2013-02-01 14:19:27 +000027 , fClipProxyState(kUnknown_ClipProxyState)
robertphillips@google.com69705572012-03-21 19:46:50 +000028 , fVertexPool(*vertexPool)
29 , fIndexPool(*indexPool)
robertphillips@google.comc82a8b72012-06-21 20:15:48 +000030 , fFlushing(false) {
bsalomon@google.com18c9c192011-09-22 21:01:31 +000031
bsalomon@google.com6e4e6502013-02-25 20:12:45 +000032 fDstGpu->ref();
bsalomon@google.combcce8922013-03-25 15:38:39 +000033 fCaps.reset(SkRef(fDstGpu->caps()));
bsalomon@google.com18c9c192011-09-22 21:01:31 +000034
bsalomon@google.com1c13c962011-02-14 16:51:21 +000035 GrAssert(NULL != vertexPool);
36 GrAssert(NULL != indexPool);
bsalomon@google.com25fb21f2011-06-21 18:17:25 +000037
38 GeometryPoolState& poolState = fGeoPoolStateStack.push_back();
39 poolState.fUsedPoolVertexBytes = 0;
40 poolState.fUsedPoolIndexBytes = 0;
41#if GR_DEBUG
42 poolState.fPoolVertexBuffer = (GrVertexBuffer*)~0;
43 poolState.fPoolStartVertex = ~0;
44 poolState.fPoolIndexBuffer = (GrIndexBuffer*)~0;
45 poolState.fPoolStartIndex = ~0;
46#endif
bsalomon@google.coma4f6b102012-06-26 21:04:22 +000047 this->reset();
reed@google.comac10a2d2010-12-22 21:39:39 +000048}
49
50GrInOrderDrawBuffer::~GrInOrderDrawBuffer() {
bsalomon@google.com86afc2a2011-02-16 16:12:19 +000051 this->reset();
bsalomon@google.com4a018bb2011-10-28 19:50:21 +000052 // This must be called by before the GrDrawTarget destructor
53 this->releaseGeometry();
bsalomon@google.com6e4e6502013-02-25 20:12:45 +000054 fDstGpu->unref();
reed@google.comac10a2d2010-12-22 21:39:39 +000055}
56
bsalomon@google.com934c5702012-03-20 21:17:58 +000057////////////////////////////////////////////////////////////////////////////////
58
bsalomon@google.comd62e88e2013-02-01 14:19:27 +000059namespace {
60void get_vertex_bounds(const void* vertices,
61 size_t vertexSize,
62 int vertexCount,
63 SkRect* bounds) {
64 GrAssert(vertexSize >= sizeof(GrPoint));
65 GrAssert(vertexCount > 0);
66 const GrPoint* point = static_cast<const GrPoint*>(vertices);
67 bounds->fLeft = bounds->fRight = point->fX;
68 bounds->fTop = bounds->fBottom = point->fY;
69 for (int i = 1; i < vertexCount; ++i) {
70 point = reinterpret_cast<GrPoint*>(reinterpret_cast<intptr_t>(point) + vertexSize);
71 bounds->growToInclude(point->fX, point->fY);
72 }
73}
bsalomon@google.com934c5702012-03-20 21:17:58 +000074}
75
bsalomon@google.com0406b9e2013-04-02 21:00:15 +000076void GrInOrderDrawBuffer::onDrawRect(const GrRect& rect,
77 const SkMatrix* matrix,
78 const GrRect* localRect,
79 const SkMatrix* localMatrix) {
bsalomon@google.comd62e88e2013-02-01 14:19:27 +000080 GrDrawState::AutoColorRestore acr;
jvanverth@google.com9b855c72013-03-01 18:21:22 +000081
82 GrDrawState* drawState = this->drawState();
83
84 GrColor color = drawState->getColor();
85 GrVertexAttribArray<3> attribs;
jvanverth@google.com9b855c72013-03-01 18:21:22 +000086
87 // set position attrib
jvanverth@google.com054ae992013-04-01 20:06:51 +000088 static const GrVertexAttrib kPosAttrib =
89 {kVec2f_GrVertexAttribType, 0, kPosition_GrVertexAttribBinding};
90 attribs.push_back(kPosAttrib);
91
92 size_t currentOffset = sizeof(GrPoint);
93 int colorOffset = -1;
94 int localOffset = -1;
bsalomon@google.com86afc2a2011-02-16 16:12:19 +000095
bsalomon@google.comd62e88e2013-02-01 14:19:27 +000096 // Using per-vertex colors allows batching across colors. (A lot of rects in a row differing
97 // only in color is a common occurrence in tables). However, having per-vertex colors disables
98 // blending optimizations because we don't know if the color will be solid or not. These
99 // optimizations help determine whether coverage and color can be blended correctly when
100 // dual-source blending isn't available. This comes into play when there is coverage. If colors
101 // were a stage it could take a hint that every vertex's color will be opaque.
jvanverth@google.com054ae992013-04-01 20:06:51 +0000102 if (this->caps()->dualSourceBlendingSupport() || drawState->hasSolidCoverage()) {
jvanverth@google.com9b855c72013-03-01 18:21:22 +0000103 colorOffset = currentOffset;
jvanverth@google.com054ae992013-04-01 20:06:51 +0000104 GrVertexAttrib colorAttrib =
jvanverth@google.comb084c772013-04-01 20:28:08 +0000105 {kVec4ub_GrVertexAttribType, currentOffset, kColor_GrVertexAttribBinding};
jvanverth@google.com054ae992013-04-01 20:06:51 +0000106 attribs.push_back(colorAttrib);
jvanverth@google.com9b855c72013-03-01 18:21:22 +0000107 currentOffset += sizeof(GrColor);
bsalomon@google.comd62e88e2013-02-01 14:19:27 +0000108 // We set the draw state's color to white here. This is done so that any batching performed
109 // in our subclass's onDraw() won't get a false from GrDrawState::op== due to a color
110 // mismatch. TODO: Once vertex layout is owned by GrDrawState it should skip comparing the
111 // constant color in its op== when the kColor layout bit is set and then we can remove this.
jvanverth@google.com9b855c72013-03-01 18:21:22 +0000112 acr.set(drawState, 0xFFFFFFFF);
bsalomon@google.com86afc2a2011-02-16 16:12:19 +0000113 }
bsalomon@google.com86afc2a2011-02-16 16:12:19 +0000114
bsalomon@google.comc7818882013-03-20 19:19:53 +0000115 if (NULL != localRect) {
bsalomon@google.comc7818882013-03-20 19:19:53 +0000116 localOffset = currentOffset;
jvanverth@google.com054ae992013-04-01 20:06:51 +0000117 GrVertexAttrib localCoordAttrib =
jvanverth@google.comb084c772013-04-01 20:28:08 +0000118 {kVec2f_GrVertexAttribType, currentOffset, kLocalCoord_GrVertexAttribBinding};
jvanverth@google.com054ae992013-04-01 20:06:51 +0000119 attribs.push_back(localCoordAttrib);
jvanverth@google.com9b855c72013-03-01 18:21:22 +0000120 currentOffset += sizeof(GrPoint);
bsalomon@google.comd62e88e2013-02-01 14:19:27 +0000121 }
122
jvanverth@google.com9b855c72013-03-01 18:21:22 +0000123 drawState->setVertexAttribs(attribs.begin(), attribs.count());
jvanverth@google.comb75b0a02013-02-05 20:33:30 +0000124 AutoReleaseGeometry geo(this, 4, 0);
bsalomon@google.comd62e88e2013-02-01 14:19:27 +0000125 if (!geo.succeeded()) {
126 GrPrintf("Failed to get space for vertices!\n");
bsalomon@google.com934c5702012-03-20 21:17:58 +0000127 return;
128 }
129
bsalomon@google.comd62e88e2013-02-01 14:19:27 +0000130 // Go to device coords to allow batching across matrix changes
131 SkMatrix combinedMatrix;
132 if (NULL != matrix) {
133 combinedMatrix = *matrix;
134 } else {
135 combinedMatrix.reset();
136 }
jvanverth@google.com9b855c72013-03-01 18:21:22 +0000137 combinedMatrix.postConcat(drawState->getViewMatrix());
jvanverth@google.com39768252013-02-14 15:25:44 +0000138 // 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 +0000139 // modify that stage's matrix. Otherwise if the effect is generating its source rect from
140 // the vertex positions then we have to account for the view matrix change.
bsalomon@google.comc7818882013-03-20 19:19:53 +0000141 GrDrawState::AutoDeviceCoordDraw adcd(drawState);
bsalomon@google.comd62e88e2013-02-01 14:19:27 +0000142 if (!adcd.succeeded()) {
143 return;
144 }
145
jvanverth@google.com9b855c72013-03-01 18:21:22 +0000146 size_t vsize = drawState->getVertexSize();
147 GrAssert(vsize == currentOffset);
bsalomon@google.comd62e88e2013-02-01 14:19:27 +0000148
149 geo.positions()->setRectFan(rect.fLeft, rect.fTop, rect.fRight, rect.fBottom, vsize);
150 combinedMatrix.mapPointsWithStride(geo.positions(), vsize, 4);
151
152 SkRect devBounds;
153 // since we already computed the dev verts, set the bounds hint. This will help us avoid
154 // unnecessary clipping in our onDraw().
155 get_vertex_bounds(geo.vertices(), vsize, 4, &devBounds);
156
bsalomon@google.comc7818882013-03-20 19:19:53 +0000157 if (localOffset >= 0) {
158 GrPoint* coords = GrTCast<GrPoint*>(GrTCast<intptr_t>(geo.vertices()) + localOffset);
159 coords->setRectFan(localRect->fLeft, localRect->fTop,
160 localRect->fRight, localRect->fBottom,
jvanverth@google.com9b855c72013-03-01 18:21:22 +0000161 vsize);
bsalomon@google.comc7818882013-03-20 19:19:53 +0000162 if (NULL != localMatrix) {
163 localMatrix->mapPointsWithStride(coords, vsize, 4);
bsalomon@google.comd62e88e2013-02-01 14:19:27 +0000164 }
165 }
166
167 if (colorOffset >= 0) {
168 GrColor* vertColor = GrTCast<GrColor*>(GrTCast<intptr_t>(geo.vertices()) + colorOffset);
169 for (int i = 0; i < 4; ++i) {
170 *vertColor = color;
171 vertColor = (GrColor*) ((intptr_t) vertColor + vsize);
172 }
173 }
174
bsalomon@google.com6e4e6502013-02-25 20:12:45 +0000175 this->setIndexSourceToBuffer(this->getContext()->getQuadIndexBuffer());
bsalomon@google.comd62e88e2013-02-01 14:19:27 +0000176 this->drawIndexedInstances(kTriangles_GrPrimitiveType, 1, 4, 6, &devBounds);
jvanverth@google.com9b855c72013-03-01 18:21:22 +0000177
178 // to ensure that stashing the drawState ptr is valid
179 GrAssert(this->drawState() == drawState);
bsalomon@google.comd62e88e2013-02-01 14:19:27 +0000180}
181
182bool GrInOrderDrawBuffer::quickInsideClip(const SkRect& devBounds) {
183 if (!this->getDrawState().isClipState()) {
184 return true;
185 }
186 if (kUnknown_ClipProxyState == fClipProxyState) {
187 SkIRect rect;
188 bool iior;
189 this->getClip()->getConservativeBounds(this->getDrawState().getRenderTarget(), &rect, &iior);
190 if (iior) {
191 // The clip is a rect. We will remember that in fProxyClip. It is common for an edge (or
192 // all edges) of the clip to be at the edge of the RT. However, we get that clipping for
193 // free via the viewport. We don't want to think that clipping must be enabled in this
194 // case. So we extend the clip outward from the edge to avoid these false negatives.
195 fClipProxyState = kValid_ClipProxyState;
196 fClipProxy = SkRect::MakeFromIRect(rect);
197
198 if (fClipProxy.fLeft <= 0) {
199 fClipProxy.fLeft = SK_ScalarMin;
200 }
201 if (fClipProxy.fTop <= 0) {
202 fClipProxy.fTop = SK_ScalarMin;
203 }
204 if (fClipProxy.fRight >= this->getDrawState().getRenderTarget()->width()) {
205 fClipProxy.fRight = SK_ScalarMax;
206 }
207 if (fClipProxy.fBottom >= this->getDrawState().getRenderTarget()->height()) {
208 fClipProxy.fBottom = SK_ScalarMax;
209 }
210 } else {
211 fClipProxyState = kInvalid_ClipProxyState;
212 }
213 }
214 if (kValid_ClipProxyState == fClipProxyState) {
215 return fClipProxy.contains(devBounds);
216 }
217 SkPoint originOffset = {SkIntToScalar(this->getClip()->fOrigin.fX),
218 SkIntToScalar(this->getClip()->fOrigin.fY)};
219 SkRect clipSpaceBounds = devBounds;
220 clipSpaceBounds.offset(originOffset);
221 return this->getClip()->fClipStack->quickContains(clipSpaceBounds);
222}
223
224int GrInOrderDrawBuffer::concatInstancedDraw(const DrawInfo& info) {
225 GrAssert(info.isInstanced());
226
bsalomon@google.com934c5702012-03-20 21:17:58 +0000227 const GeometrySrcState& geomSrc = this->getGeomSrc();
jvanverth@google.comb75b0a02013-02-05 20:33:30 +0000228 const GrDrawState& drawState = this->getDrawState();
bsalomon@google.com934c5702012-03-20 21:17:58 +0000229
bsalomon@google.comd62e88e2013-02-01 14:19:27 +0000230 // we only attempt to concat the case when reserved verts are used with a client-specified index
231 // buffer. To make this work with client-specified VBs we'd need to know if the VB was updated
232 // between draws.
233 if (kReserved_GeometrySrcType != geomSrc.fVertexSrc ||
234 kBuffer_GeometrySrcType != geomSrc.fIndexSrc) {
235 return 0;
bsalomon@google.com934c5702012-03-20 21:17:58 +0000236 }
bsalomon@google.comd62e88e2013-02-01 14:19:27 +0000237 // Check if there is a draw info that is compatible that uses the same VB from the pool and
238 // the same IB
239 if (kDraw_Cmd != fCmds.back()) {
240 return 0;
241 }
242
243 DrawRecord* draw = &fDraws.back();
244 GeometryPoolState& poolState = fGeoPoolStateStack.back();
245 const GrVertexBuffer* vertexBuffer = poolState.fPoolVertexBuffer;
246
247 if (!draw->isInstanced() ||
248 draw->verticesPerInstance() != info.verticesPerInstance() ||
249 draw->indicesPerInstance() != info.indicesPerInstance() ||
250 draw->fVertexBuffer != vertexBuffer ||
jvanverth@google.comb75b0a02013-02-05 20:33:30 +0000251 draw->fIndexBuffer != geomSrc.fIndexBuffer) {
bsalomon@google.comd62e88e2013-02-01 14:19:27 +0000252 return 0;
253 }
254 // info does not yet account for the offset from the start of the pool's VB while the previous
255 // draw record does.
256 int adjustedStartVertex = poolState.fPoolStartVertex + info.startVertex();
257 if (draw->startVertex() + draw->vertexCount() != adjustedStartVertex) {
258 return 0;
259 }
260
261 GrAssert(poolState.fPoolStartVertex == draw->startVertex() + draw->vertexCount());
262
263 // how many instances can be concat'ed onto draw given the size of the index buffer
264 int instancesToConcat = this->indexCountInCurrentSource() / info.indicesPerInstance();
265 instancesToConcat -= draw->instanceCount();
266 instancesToConcat = GrMin(instancesToConcat, info.instanceCount());
267
268 // update the amount of reserved vertex data actually referenced in draws
skia.committer@gmail.comae683922013-02-06 07:01:54 +0000269 size_t vertexBytes = instancesToConcat * info.verticesPerInstance() *
jvanverth@google.comb75b0a02013-02-05 20:33:30 +0000270 drawState.getVertexSize();
bsalomon@google.comd62e88e2013-02-01 14:19:27 +0000271 poolState.fUsedPoolVertexBytes = GrMax(poolState.fUsedPoolVertexBytes, vertexBytes);
272
273 draw->adjustInstanceCount(instancesToConcat);
274 return instancesToConcat;
bsalomon@google.com934c5702012-03-20 21:17:58 +0000275}
276
bsalomon@google.comd62e88e2013-02-01 14:19:27 +0000277class AutoClipReenable {
278public:
279 AutoClipReenable() : fDrawState(NULL) {}
280 ~AutoClipReenable() {
281 if (NULL != fDrawState) {
282 fDrawState->enableState(GrDrawState::kClip_StateBit);
283 }
284 }
285 void set(GrDrawState* drawState) {
286 if (drawState->isClipState()) {
287 fDrawState = drawState;
288 drawState->disableState(GrDrawState::kClip_StateBit);
289 }
290 }
291private:
292 GrDrawState* fDrawState;
293};
294
bsalomon@google.com74749cd2013-01-30 16:12:41 +0000295void GrInOrderDrawBuffer::onDraw(const DrawInfo& info) {
reed@google.comac10a2d2010-12-22 21:39:39 +0000296
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000297 GeometryPoolState& poolState = fGeoPoolStateStack.back();
jvanverth@google.comb75b0a02013-02-05 20:33:30 +0000298 const GrDrawState& drawState = this->getDrawState();
bsalomon@google.comd62e88e2013-02-01 14:19:27 +0000299 AutoClipReenable acr;
300
jvanverth@google.comb75b0a02013-02-05 20:33:30 +0000301 if (drawState.isClipState() &&
bsalomon@google.comd62e88e2013-02-01 14:19:27 +0000302 NULL != info.getDevBounds() &&
303 this->quickInsideClip(*info.getDevBounds())) {
304 acr.set(this->drawState());
305 }
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000306
bsalomon@google.coma4f6b102012-06-26 21:04:22 +0000307 if (this->needsNewClip()) {
308 this->recordClip();
309 }
310 if (this->needsNewState()) {
311 this->recordState();
bsalomon@google.com86afc2a2011-02-16 16:12:19 +0000312 }
313
bsalomon@google.comd62e88e2013-02-01 14:19:27 +0000314 DrawRecord* draw;
315 if (info.isInstanced()) {
316 int instancesConcated = this->concatInstancedDraw(info);
317 if (info.instanceCount() > instancesConcated) {
318 draw = this->recordDraw(info);
319 draw->adjustInstanceCount(-instancesConcated);
320 } else {
321 return;
322 }
323 } else {
324 draw = this->recordDraw(info);
325 }
bsalomon@google.com74749cd2013-01-30 16:12:41 +0000326
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000327 switch (this->getGeomSrc().fVertexSrc) {
bsalomon@google.com74749cd2013-01-30 16:12:41 +0000328 case kBuffer_GeometrySrcType:
329 draw->fVertexBuffer = this->getGeomSrc().fVertexBuffer;
330 break;
331 case kReserved_GeometrySrcType: // fallthrough
332 case kArray_GeometrySrcType: {
skia.committer@gmail.comae683922013-02-06 07:01:54 +0000333 size_t vertexBytes = (info.vertexCount() + info.startVertex()) *
jvanverth@google.comb75b0a02013-02-05 20:33:30 +0000334 drawState.getVertexSize();
bsalomon@google.com74749cd2013-01-30 16:12:41 +0000335 poolState.fUsedPoolVertexBytes = GrMax(poolState.fUsedPoolVertexBytes, vertexBytes);
336 draw->fVertexBuffer = poolState.fPoolVertexBuffer;
bsalomon@google.comd62e88e2013-02-01 14:19:27 +0000337 draw->adjustStartVertex(poolState.fPoolStartVertex);
bsalomon@google.com74749cd2013-01-30 16:12:41 +0000338 break;
339 }
340 default:
341 GrCrash("unknown geom src type");
reed@google.comac10a2d2010-12-22 21:39:39 +0000342 }
bsalomon@google.coma4f6b102012-06-26 21:04:22 +0000343 draw->fVertexBuffer->ref();
reed@google.comac10a2d2010-12-22 21:39:39 +0000344
bsalomon@google.com74749cd2013-01-30 16:12:41 +0000345 if (info.isIndexed()) {
346 switch (this->getGeomSrc().fIndexSrc) {
347 case kBuffer_GeometrySrcType:
348 draw->fIndexBuffer = this->getGeomSrc().fIndexBuffer;
349 break;
350 case kReserved_GeometrySrcType: // fallthrough
351 case kArray_GeometrySrcType: {
352 size_t indexBytes = (info.indexCount() + info.startIndex()) * sizeof(uint16_t);
353 poolState.fUsedPoolIndexBytes = GrMax(poolState.fUsedPoolIndexBytes, indexBytes);
354 draw->fIndexBuffer = poolState.fPoolIndexBuffer;
bsalomon@google.comd62e88e2013-02-01 14:19:27 +0000355 draw->adjustStartIndex(poolState.fPoolStartIndex);
bsalomon@google.com74749cd2013-01-30 16:12:41 +0000356 break;
357 }
358 default:
359 GrCrash("unknown geom src type");
360 }
361 draw->fIndexBuffer->ref();
362 } else {
363 draw->fIndexBuffer = NULL;
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000364 }
reed@google.comac10a2d2010-12-22 21:39:39 +0000365}
366
sugoi@google.com5f74cf82012-12-17 21:16:45 +0000367GrInOrderDrawBuffer::StencilPath::StencilPath() : fStroke(SkStrokeRec::kFill_InitStyle) {}
368
369void GrInOrderDrawBuffer::onStencilPath(const GrPath* path, const SkStrokeRec& stroke,
sugoi@google.com12b4e272012-12-06 20:13:11 +0000370 SkPath::FillType fill) {
bsalomon@google.comded4f4b2012-06-28 18:48:06 +0000371 if (this->needsNewClip()) {
372 this->recordClip();
373 }
374 // Only compare the subset of GrDrawState relevant to path stenciling?
375 if (this->needsNewState()) {
376 this->recordState();
377 }
378 StencilPath* sp = this->recordStencilPath();
379 sp->fPath.reset(path);
380 path->ref();
381 sp->fFill = fill;
sugoi@google.com12b4e272012-12-06 20:13:11 +0000382 sp->fStroke = stroke;
bsalomon@google.com64aef2b2012-06-11 15:36:13 +0000383}
384
bsalomon@google.comd62e88e2013-02-01 14:19:27 +0000385void GrInOrderDrawBuffer::clear(const GrIRect* rect, GrColor color, GrRenderTarget* renderTarget) {
bsalomon@google.com6aa25c32011-04-27 19:55:29 +0000386 GrIRect r;
bsalomon@google.com1b3ce472012-08-17 13:43:08 +0000387 if (NULL == renderTarget) {
388 renderTarget = this->drawState()->getRenderTarget();
389 GrAssert(NULL != renderTarget);
390 }
bsalomon@google.com6aa25c32011-04-27 19:55:29 +0000391 if (NULL == rect) {
392 // We could do something smart and remove previous draws and clears to
393 // the current render target. If we get that smart we have to make sure
394 // those draws aren't read before this clear (render-to-texture).
bsalomon@google.com1b3ce472012-08-17 13:43:08 +0000395 r.setLTRB(0, 0, renderTarget->width(), renderTarget->height());
bsalomon@google.com6aa25c32011-04-27 19:55:29 +0000396 rect = &r;
397 }
bsalomon@google.coma4f6b102012-06-26 21:04:22 +0000398 Clear* clr = this->recordClear();
399 clr->fColor = color;
400 clr->fRect = *rect;
401 clr->fRenderTarget = renderTarget;
bsalomon@google.com1b3ce472012-08-17 13:43:08 +0000402 renderTarget->ref();
bsalomon@google.com0b335c12011-04-25 19:17:44 +0000403}
404
reed@google.comac10a2d2010-12-22 21:39:39 +0000405void GrInOrderDrawBuffer::reset() {
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000406 GrAssert(1 == fGeoPoolStateStack.count());
407 this->resetVertexSource();
408 this->resetIndexSource();
bsalomon@google.com86afc2a2011-02-16 16:12:19 +0000409 int numDraws = fDraws.count();
410 for (int d = 0; d < numDraws; ++d) {
411 // we always have a VB, but not always an IB
412 GrAssert(NULL != fDraws[d].fVertexBuffer);
413 fDraws[d].fVertexBuffer->unref();
414 GrSafeUnref(fDraws[d].fIndexBuffer);
415 }
bsalomon@google.coma4f6b102012-06-26 21:04:22 +0000416 fCmds.reset();
reed@google.comac10a2d2010-12-22 21:39:39 +0000417 fDraws.reset();
bsalomon@google.comded4f4b2012-06-28 18:48:06 +0000418 fStencilPaths.reset();
reed@google.comac10a2d2010-12-22 21:39:39 +0000419 fStates.reset();
bsalomon@google.com0b335c12011-04-25 19:17:44 +0000420 fClears.reset();
bsalomon@google.com1c13c962011-02-14 16:51:21 +0000421 fVertexPool.reset();
422 fIndexPool.reset();
reed@google.comac10a2d2010-12-22 21:39:39 +0000423 fClips.reset();
robertphillips@google.combeb1af72012-07-26 18:52:16 +0000424 fClipOrigins.reset();
bsalomon@google.coma4f6b102012-06-26 21:04:22 +0000425 fClipSet = true;
reed@google.comac10a2d2010-12-22 21:39:39 +0000426}
427
bsalomon@google.com6e4e6502013-02-25 20:12:45 +0000428bool GrInOrderDrawBuffer::flush() {
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000429 GrAssert(kReserved_GeometrySrcType != this->getGeomSrc().fVertexSrc);
430 GrAssert(kReserved_GeometrySrcType != this->getGeomSrc().fIndexSrc);
bsalomon@google.com3f5a95e2012-03-08 16:41:42 +0000431
bsalomon@google.coma4f6b102012-06-26 21:04:22 +0000432 int numCmds = fCmds.count();
bsalomon@google.com358e4272013-01-10 14:40:28 +0000433 if (0 == numCmds) {
bsalomon@google.coma4f6b102012-06-26 21:04:22 +0000434 return false;
reed@google.comac10a2d2010-12-22 21:39:39 +0000435 }
bsalomon@google.com6e4e6502013-02-25 20:12:45 +0000436 GrAssert(!fFlushing);
437
438 GrAutoTRestore<bool> flushRestore(&fFlushing);
439 fFlushing = true;
reed@google.comac10a2d2010-12-22 21:39:39 +0000440
bsalomon@google.com1c13c962011-02-14 16:51:21 +0000441 fVertexPool.unlock();
442 fIndexPool.unlock();
reed@google.comac10a2d2010-12-22 21:39:39 +0000443
bsalomon@google.com6e4e6502013-02-25 20:12:45 +0000444 GrDrawTarget::AutoClipRestore acr(fDstGpu);
445 AutoGeometryAndStatePush agasp(fDstGpu, kPreserve_ASRInit);
bsalomon@google.comca432082013-01-23 19:53:46 +0000446
447 GrDrawState playbackState;
bsalomon@google.com6e4e6502013-02-25 20:12:45 +0000448 GrDrawState* prevDrawState = fDstGpu->drawState();
bsalomon@google.coma5d056a2012-03-27 15:59:58 +0000449 prevDrawState->ref();
bsalomon@google.com6e4e6502013-02-25 20:12:45 +0000450 fDstGpu->setDrawState(&playbackState);
reed@google.comac10a2d2010-12-22 21:39:39 +0000451
robertphillips@google.combeb1af72012-07-26 18:52:16 +0000452 GrClipData clipData;
453
bsalomon@google.comded4f4b2012-06-28 18:48:06 +0000454 int currState = 0;
455 int currClip = 0;
456 int currClear = 0;
457 int currDraw = 0;
458 int currStencilPath = 0;
reed@google.comac10a2d2010-12-22 21:39:39 +0000459
bsalomon@google.coma4f6b102012-06-26 21:04:22 +0000460 for (int c = 0; c < numCmds; ++c) {
461 switch (fCmds[c]) {
462 case kDraw_Cmd: {
bsalomon@google.com74749cd2013-01-30 16:12:41 +0000463 const DrawRecord& draw = fDraws[currDraw];
bsalomon@google.com6e4e6502013-02-25 20:12:45 +0000464 fDstGpu->setVertexSourceToBuffer(draw.fVertexBuffer);
bsalomon@google.comd62e88e2013-02-01 14:19:27 +0000465 if (draw.isIndexed()) {
bsalomon@google.com6e4e6502013-02-25 20:12:45 +0000466 fDstGpu->setIndexSourceToBuffer(draw.fIndexBuffer);
bsalomon@google.coma4f6b102012-06-26 21:04:22 +0000467 }
bsalomon@google.com6e4e6502013-02-25 20:12:45 +0000468 fDstGpu->executeDraw(draw);
bsalomon@google.com0b335c12011-04-25 19:17:44 +0000469
bsalomon@google.coma4f6b102012-06-26 21:04:22 +0000470 ++currDraw;
471 break;
472 }
bsalomon@google.comded4f4b2012-06-28 18:48:06 +0000473 case kStencilPath_Cmd: {
474 const StencilPath& sp = fStencilPaths[currStencilPath];
bsalomon@google.com6e4e6502013-02-25 20:12:45 +0000475 fDstGpu->stencilPath(sp.fPath.get(), sp.fStroke, sp.fFill);
bsalomon@google.comded4f4b2012-06-28 18:48:06 +0000476 ++currStencilPath;
477 break;
478 }
bsalomon@google.coma4f6b102012-06-26 21:04:22 +0000479 case kSetState_Cmd:
bsalomon@google.comca432082013-01-23 19:53:46 +0000480 fStates[currState].restoreTo(&playbackState);
bsalomon@google.coma4f6b102012-06-26 21:04:22 +0000481 ++currState;
482 break;
483 case kSetClip_Cmd:
robertphillips@google.combeb1af72012-07-26 18:52:16 +0000484 clipData.fClipStack = &fClips[currClip];
485 clipData.fOrigin = fClipOrigins[currClip];
bsalomon@google.com6e4e6502013-02-25 20:12:45 +0000486 fDstGpu->setClip(&clipData);
bsalomon@google.coma4f6b102012-06-26 21:04:22 +0000487 ++currClip;
488 break;
489 case kClear_Cmd:
bsalomon@google.com6e4e6502013-02-25 20:12:45 +0000490 fDstGpu->clear(&fClears[currClear].fRect,
491 fClears[currClear].fColor,
492 fClears[currClear].fRenderTarget);
bsalomon@google.coma4f6b102012-06-26 21:04:22 +0000493 ++currClear;
494 break;
reed@google.comac10a2d2010-12-22 21:39:39 +0000495 }
496 }
bsalomon@google.coma4f6b102012-06-26 21:04:22 +0000497 // we should have consumed all the states, clips, etc.
498 GrAssert(fStates.count() == currState);
499 GrAssert(fClips.count() == currClip);
robertphillips@google.combeb1af72012-07-26 18:52:16 +0000500 GrAssert(fClipOrigins.count() == currClip);
bsalomon@google.coma4f6b102012-06-26 21:04:22 +0000501 GrAssert(fClears.count() == currClear);
502 GrAssert(fDraws.count() == currDraw);
503
bsalomon@google.com6e4e6502013-02-25 20:12:45 +0000504 fDstGpu->setDrawState(prevDrawState);
bsalomon@google.coma5d056a2012-03-27 15:59:58 +0000505 prevDrawState->unref();
bsalomon@google.com55e4a202013-01-11 13:54:21 +0000506 this->reset();
bsalomon@google.coma4f6b102012-06-26 21:04:22 +0000507 return true;
reed@google.comac10a2d2010-12-22 21:39:39 +0000508}
509
bsalomon@google.com97805382012-03-13 14:32:07 +0000510void GrInOrderDrawBuffer::willReserveVertexAndIndexSpace(
bsalomon@google.com97805382012-03-13 14:32:07 +0000511 int vertexCount,
512 int indexCount) {
bsalomon@google.com6e4e6502013-02-25 20:12:45 +0000513 // We use geometryHints() to know whether to flush the draw buffer. We
514 // can't flush if we are inside an unbalanced pushGeometrySource.
515 // Moreover, flushing blows away vertex and index data that was
516 // previously reserved. So if the vertex or index data is pulled from
517 // reserved space and won't be released by this request then we can't
518 // flush.
519 bool insideGeoPush = fGeoPoolStateStack.count() > 1;
bsalomon@google.com97805382012-03-13 14:32:07 +0000520
bsalomon@google.com6e4e6502013-02-25 20:12:45 +0000521 bool unreleasedVertexSpace =
522 !vertexCount &&
523 kReserved_GeometrySrcType == this->getGeomSrc().fVertexSrc;
bsalomon@google.com97805382012-03-13 14:32:07 +0000524
bsalomon@google.com6e4e6502013-02-25 20:12:45 +0000525 bool unreleasedIndexSpace =
526 !indexCount &&
527 kReserved_GeometrySrcType == this->getGeomSrc().fIndexSrc;
bsalomon@google.com97805382012-03-13 14:32:07 +0000528
bsalomon@google.com6e4e6502013-02-25 20:12:45 +0000529 // we don't want to finalize any reserved geom on the target since
530 // we don't know that the client has finished writing to it.
531 bool targetHasReservedGeom = fDstGpu->hasReservedVerticesOrIndices();
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000532
bsalomon@google.com6e4e6502013-02-25 20:12:45 +0000533 int vcount = vertexCount;
534 int icount = indexCount;
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000535
bsalomon@google.com6e4e6502013-02-25 20:12:45 +0000536 if (!insideGeoPush &&
537 !unreleasedVertexSpace &&
538 !unreleasedIndexSpace &&
539 !targetHasReservedGeom &&
540 this->geometryHints(&vcount, &icount)) {
bsalomon@google.com97805382012-03-13 14:32:07 +0000541
bsalomon@google.com6e4e6502013-02-25 20:12:45 +0000542 this->flush();
bsalomon@google.com97805382012-03-13 14:32:07 +0000543 }
544}
545
jvanverth@google.comb75b0a02013-02-05 20:33:30 +0000546bool GrInOrderDrawBuffer::geometryHints(int* vertexCount,
bsalomon@google.com1c13c962011-02-14 16:51:21 +0000547 int* indexCount) const {
548 // we will recommend a flush if the data could fit in a single
549 // preallocated buffer but none are left and it can't fit
550 // in the current buffer (which may not be prealloced).
reed@google.comac10a2d2010-12-22 21:39:39 +0000551 bool flush = false;
552 if (NULL != indexCount) {
bsalomon@google.com1c13c962011-02-14 16:51:21 +0000553 int32_t currIndices = fIndexPool.currentBufferIndices();
554 if (*indexCount > currIndices &&
555 (!fIndexPool.preallocatedBuffersRemaining() &&
556 *indexCount <= fIndexPool.preallocatedBufferIndices())) {
557
558 flush = true;
559 }
560 *indexCount = currIndices;
reed@google.comac10a2d2010-12-22 21:39:39 +0000561 }
562 if (NULL != vertexCount) {
jvanverth@google.comb75b0a02013-02-05 20:33:30 +0000563 size_t vertexSize = this->getDrawState().getVertexSize();
jvanverth@google.coma6338982013-01-31 21:34:25 +0000564 int32_t currVertices = fVertexPool.currentBufferVertices(vertexSize);
bsalomon@google.com1c13c962011-02-14 16:51:21 +0000565 if (*vertexCount > currVertices &&
566 (!fVertexPool.preallocatedBuffersRemaining() &&
jvanverth@google.coma6338982013-01-31 21:34:25 +0000567 *vertexCount <= fVertexPool.preallocatedBufferVertices(vertexSize))) {
reed@google.comac10a2d2010-12-22 21:39:39 +0000568
bsalomon@google.com1c13c962011-02-14 16:51:21 +0000569 flush = true;
reed@google.comac10a2d2010-12-22 21:39:39 +0000570 }
bsalomon@google.com1c13c962011-02-14 16:51:21 +0000571 *vertexCount = currVertices;
reed@google.comac10a2d2010-12-22 21:39:39 +0000572 }
573 return flush;
574}
575
jvanverth@google.coma6338982013-01-31 21:34:25 +0000576bool GrInOrderDrawBuffer::onReserveVertexSpace(size_t vertexSize,
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000577 int vertexCount,
578 void** vertices) {
579 GeometryPoolState& poolState = fGeoPoolStateStack.back();
580 GrAssert(vertexCount > 0);
581 GrAssert(NULL != vertices);
582 GrAssert(0 == poolState.fUsedPoolVertexBytes);
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000583
jvanverth@google.coma6338982013-01-31 21:34:25 +0000584 *vertices = fVertexPool.makeSpace(vertexSize,
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000585 vertexCount,
586 &poolState.fPoolVertexBuffer,
587 &poolState.fPoolStartVertex);
588 return NULL != *vertices;
589}
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000590
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000591bool GrInOrderDrawBuffer::onReserveIndexSpace(int indexCount, void** indices) {
592 GeometryPoolState& poolState = fGeoPoolStateStack.back();
593 GrAssert(indexCount > 0);
594 GrAssert(NULL != indices);
595 GrAssert(0 == poolState.fUsedPoolIndexBytes);
bsalomon@google.com1c13c962011-02-14 16:51:21 +0000596
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000597 *indices = fIndexPool.makeSpace(indexCount,
598 &poolState.fPoolIndexBuffer,
599 &poolState.fPoolStartIndex);
600 return NULL != *indices;
reed@google.comac10a2d2010-12-22 21:39:39 +0000601}
602
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000603void GrInOrderDrawBuffer::releaseReservedVertexSpace() {
604 GeometryPoolState& poolState = fGeoPoolStateStack.back();
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000605 const GeometrySrcState& geoSrc = this->getGeomSrc();
bsalomon@google.comd57d71a2012-08-16 16:26:33 +0000606
607 // If we get a release vertex space call then our current source should either be reserved
608 // or array (which we copied into reserved space).
609 GrAssert(kReserved_GeometrySrcType == geoSrc.fVertexSrc ||
610 kArray_GeometrySrcType == geoSrc.fVertexSrc);
bsalomon@google.com3f5a95e2012-03-08 16:41:42 +0000611
612 // When the caller reserved vertex buffer space we gave it back a pointer
613 // provided by the vertex buffer pool. At each draw we tracked the largest
614 // offset into the pool's pointer that was referenced. Now we return to the
615 // pool any portion at the tail of the allocation that no draw referenced.
jvanverth@google.comb75b0a02013-02-05 20:33:30 +0000616 size_t reservedVertexBytes = geoSrc.fVertexSize * geoSrc.fVertexCount;
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000617 fVertexPool.putBack(reservedVertexBytes -
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000618 poolState.fUsedPoolVertexBytes);
619 poolState.fUsedPoolVertexBytes = 0;
bsalomon@google.com3f5a95e2012-03-08 16:41:42 +0000620 poolState.fPoolVertexBuffer = NULL;
621 poolState.fPoolStartVertex = 0;
bsalomon@google.com1c13c962011-02-14 16:51:21 +0000622}
623
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000624void GrInOrderDrawBuffer::releaseReservedIndexSpace() {
625 GeometryPoolState& poolState = fGeoPoolStateStack.back();
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000626 const GeometrySrcState& geoSrc = this->getGeomSrc();
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000627
bsalomon@google.comd57d71a2012-08-16 16:26:33 +0000628 // If we get a release index space call then our current source should either be reserved
629 // or array (which we copied into reserved space).
630 GrAssert(kReserved_GeometrySrcType == geoSrc.fIndexSrc ||
631 kArray_GeometrySrcType == geoSrc.fIndexSrc);
bsalomon@google.com3f5a95e2012-03-08 16:41:42 +0000632
633 // Similar to releaseReservedVertexSpace we return any unused portion at
634 // the tail
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000635 size_t reservedIndexBytes = sizeof(uint16_t) * geoSrc.fIndexCount;
636 fIndexPool.putBack(reservedIndexBytes - poolState.fUsedPoolIndexBytes);
637 poolState.fUsedPoolIndexBytes = 0;
bsalomon@google.com3f5a95e2012-03-08 16:41:42 +0000638 poolState.fPoolIndexBuffer = NULL;
639 poolState.fPoolStartIndex = 0;
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000640}
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000641
bsalomon@google.combcdbbe62011-04-12 15:40:00 +0000642void GrInOrderDrawBuffer::onSetVertexSourceToArray(const void* vertexArray,
643 int vertexCount) {
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000644
645 GeometryPoolState& poolState = fGeoPoolStateStack.back();
646 GrAssert(0 == poolState.fUsedPoolVertexBytes);
bsalomon@google.com1c13c962011-02-14 16:51:21 +0000647#if GR_DEBUG
648 bool success =
649#endif
jvanverth@google.comb75b0a02013-02-05 20:33:30 +0000650 fVertexPool.appendVertices(this->getVertexSize(),
bsalomon@google.com1c13c962011-02-14 16:51:21 +0000651 vertexCount,
652 vertexArray,
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000653 &poolState.fPoolVertexBuffer,
654 &poolState.fPoolStartVertex);
bsalomon@google.com1c13c962011-02-14 16:51:21 +0000655 GR_DEBUGASSERT(success);
656}
657
bsalomon@google.combcdbbe62011-04-12 15:40:00 +0000658void GrInOrderDrawBuffer::onSetIndexSourceToArray(const void* indexArray,
659 int indexCount) {
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000660 GeometryPoolState& poolState = fGeoPoolStateStack.back();
661 GrAssert(0 == poolState.fUsedPoolIndexBytes);
bsalomon@google.com1c13c962011-02-14 16:51:21 +0000662#if GR_DEBUG
663 bool success =
664#endif
665 fIndexPool.appendIndices(indexCount,
666 indexArray,
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000667 &poolState.fPoolIndexBuffer,
668 &poolState.fPoolStartIndex);
bsalomon@google.com1c13c962011-02-14 16:51:21 +0000669 GR_DEBUGASSERT(success);
reed@google.comac10a2d2010-12-22 21:39:39 +0000670}
671
bsalomon@google.com3f5a95e2012-03-08 16:41:42 +0000672void GrInOrderDrawBuffer::releaseVertexArray() {
673 // When the client provides an array as the vertex source we handled it
674 // by copying their array into reserved space.
675 this->GrInOrderDrawBuffer::releaseReservedVertexSpace();
676}
677
678void GrInOrderDrawBuffer::releaseIndexArray() {
679 // When the client provides an array as the index source we handled it
680 // by copying their array into reserved space.
681 this->GrInOrderDrawBuffer::releaseReservedIndexSpace();
682}
683
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000684void GrInOrderDrawBuffer::geometrySourceWillPush() {
685 GeometryPoolState& poolState = fGeoPoolStateStack.push_back();
686 poolState.fUsedPoolVertexBytes = 0;
687 poolState.fUsedPoolIndexBytes = 0;
688#if GR_DEBUG
689 poolState.fPoolVertexBuffer = (GrVertexBuffer*)~0;
690 poolState.fPoolStartVertex = ~0;
691 poolState.fPoolIndexBuffer = (GrIndexBuffer*)~0;
692 poolState.fPoolStartIndex = ~0;
693#endif
694}
695
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000696void GrInOrderDrawBuffer::geometrySourceWillPop(
697 const GeometrySrcState& restoredState) {
698 GrAssert(fGeoPoolStateStack.count() > 1);
699 fGeoPoolStateStack.pop_back();
700 GeometryPoolState& poolState = fGeoPoolStateStack.back();
701 // we have to assume that any slack we had in our vertex/index data
702 // is now unreleasable because data may have been appended later in the
703 // pool.
704 if (kReserved_GeometrySrcType == restoredState.fVertexSrc ||
705 kArray_GeometrySrcType == restoredState.fVertexSrc) {
jvanverth@google.comb75b0a02013-02-05 20:33:30 +0000706 poolState.fUsedPoolVertexBytes = restoredState.fVertexSize * restoredState.fVertexCount;
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000707 }
708 if (kReserved_GeometrySrcType == restoredState.fIndexSrc ||
709 kArray_GeometrySrcType == restoredState.fIndexSrc) {
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000710 poolState.fUsedPoolIndexBytes = sizeof(uint16_t) *
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000711 restoredState.fIndexCount;
712 }
713}
714
bsalomon@google.com86afc2a2011-02-16 16:12:19 +0000715bool GrInOrderDrawBuffer::needsNewState() const {
bsalomon@google.comca432082013-01-23 19:53:46 +0000716 return fStates.empty() || !fStates.back().isEqual(this->getDrawState());
reed@google.comac10a2d2010-12-22 21:39:39 +0000717}
718
bsalomon@google.com86afc2a2011-02-16 16:12:19 +0000719bool GrInOrderDrawBuffer::needsNewClip() const {
bsalomon@google.com358e4272013-01-10 14:40:28 +0000720 GrAssert(fClips.count() == fClipOrigins.count());
721 if (this->getDrawState().isClipState()) {
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000722 if (fClipSet &&
bsalomon@google.com358e4272013-01-10 14:40:28 +0000723 (fClips.empty() ||
bsalomon@google.com02ddc8b2013-01-28 15:35:28 +0000724 fClips.back() != *this->getClip()->fClipStack ||
725 fClipOrigins.back() != this->getClip()->fOrigin)) {
bsalomon@google.com86afc2a2011-02-16 16:12:19 +0000726 return true;
727 }
reed@google.comac10a2d2010-12-22 21:39:39 +0000728 }
729 return false;
730}
bsalomon@google.comd302f142011-03-03 13:54:13 +0000731
bsalomon@google.coma4f6b102012-06-26 21:04:22 +0000732void GrInOrderDrawBuffer::recordClip() {
bsalomon@google.com02ddc8b2013-01-28 15:35:28 +0000733 fClips.push_back() = *this->getClip()->fClipStack;
734 fClipOrigins.push_back() = this->getClip()->fOrigin;
bsalomon@google.com86afc2a2011-02-16 16:12:19 +0000735 fClipSet = false;
bsalomon@google.coma4f6b102012-06-26 21:04:22 +0000736 fCmds.push_back(kSetClip_Cmd);
737}
738
bsalomon@google.coma4f6b102012-06-26 21:04:22 +0000739void GrInOrderDrawBuffer::recordState() {
bsalomon@google.comca432082013-01-23 19:53:46 +0000740 fStates.push_back().saveFrom(this->getDrawState());
bsalomon@google.coma4f6b102012-06-26 21:04:22 +0000741 fCmds.push_back(kSetState_Cmd);
742}
743
bsalomon@google.com74749cd2013-01-30 16:12:41 +0000744GrInOrderDrawBuffer::DrawRecord* GrInOrderDrawBuffer::recordDraw(const DrawInfo& info) {
bsalomon@google.comd62e88e2013-02-01 14:19:27 +0000745 fCmds.push_back(kDraw_Cmd);
746 return &fDraws.push_back(info);
bsalomon@google.com74749cd2013-01-30 16:12:41 +0000747}
748
bsalomon@google.comded4f4b2012-06-28 18:48:06 +0000749GrInOrderDrawBuffer::StencilPath* GrInOrderDrawBuffer::recordStencilPath() {
750 fCmds.push_back(kStencilPath_Cmd);
751 return &fStencilPaths.push_back();
752}
753
bsalomon@google.coma4f6b102012-06-26 21:04:22 +0000754GrInOrderDrawBuffer::Clear* GrInOrderDrawBuffer::recordClear() {
755 fCmds.push_back(kClear_Cmd);
756 return &fClears.push_back();
reed@google.comac10a2d2010-12-22 21:39:39 +0000757}
bsalomon@google.comd302f142011-03-03 13:54:13 +0000758
robertphillips@google.combeb1af72012-07-26 18:52:16 +0000759void GrInOrderDrawBuffer::clipWillBeSet(const GrClipData* newClipData) {
760 INHERITED::clipWillBeSet(newClipData);
bsalomon@google.com86afc2a2011-02-16 16:12:19 +0000761 fClipSet = true;
bsalomon@google.comd62e88e2013-02-01 14:19:27 +0000762 fClipProxyState = kUnknown_ClipProxyState;
bsalomon@google.com86afc2a2011-02-16 16:12:19 +0000763}