blob: 00aaadbe98be290b3b235a69784769b584347c09 [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"
12#include "GrGpu.h"
13#include "GrIndexBuffer.h"
14#include "GrPath.h"
bsalomon@google.com8f9cbd62011-12-09 15:55:34 +000015#include "GrRenderTarget.h"
bsalomon@google.com6e4e6502013-02-25 20:12:45 +000016#include "GrTemplates.h"
reed@google.comac10a2d2010-12-22 21:39:39 +000017#include "GrTexture.h"
bsalomon@google.com86afc2a2011-02-16 16:12:19 +000018#include "GrVertexBuffer.h"
reed@google.comac10a2d2010-12-22 21:39:39 +000019
bsalomon@google.com6e4e6502013-02-25 20:12:45 +000020GrInOrderDrawBuffer::GrInOrderDrawBuffer(GrGpu* gpu,
bsalomon@google.com471d4712011-08-23 15:45:25 +000021 GrVertexBufferAllocPool* vertexPool,
bsalomon@google.com25fb21f2011-06-21 18:17:25 +000022 GrIndexBufferAllocPool* indexPool)
bsalomon@google.com6e4e6502013-02-25 20:12:45 +000023 : GrDrawTarget(gpu->getContext())
24 , fDstGpu(gpu)
bsalomon@google.com97805382012-03-13 14:32:07 +000025 , fClipSet(true)
bsalomon@google.comd62e88e2013-02-01 14:19:27 +000026 , fClipProxyState(kUnknown_ClipProxyState)
robertphillips@google.com69705572012-03-21 19:46:50 +000027 , fVertexPool(*vertexPool)
28 , fIndexPool(*indexPool)
robertphillips@google.comc82a8b72012-06-21 20:15:48 +000029 , fFlushing(false) {
bsalomon@google.com18c9c192011-09-22 21:01:31 +000030
bsalomon@google.com6e4e6502013-02-25 20:12:45 +000031 fDstGpu->ref();
32 fCaps = fDstGpu->getCaps();
bsalomon@google.com18c9c192011-09-22 21:01:31 +000033
bsalomon@google.com1c13c962011-02-14 16:51:21 +000034 GrAssert(NULL != vertexPool);
35 GrAssert(NULL != indexPool);
bsalomon@google.com25fb21f2011-06-21 18:17:25 +000036
37 GeometryPoolState& poolState = fGeoPoolStateStack.push_back();
38 poolState.fUsedPoolVertexBytes = 0;
39 poolState.fUsedPoolIndexBytes = 0;
40#if GR_DEBUG
41 poolState.fPoolVertexBuffer = (GrVertexBuffer*)~0;
42 poolState.fPoolStartVertex = ~0;
43 poolState.fPoolIndexBuffer = (GrIndexBuffer*)~0;
44 poolState.fPoolStartIndex = ~0;
45#endif
bsalomon@google.coma4f6b102012-06-26 21:04:22 +000046 this->reset();
reed@google.comac10a2d2010-12-22 21:39:39 +000047}
48
49GrInOrderDrawBuffer::~GrInOrderDrawBuffer() {
bsalomon@google.com86afc2a2011-02-16 16:12:19 +000050 this->reset();
bsalomon@google.com4a018bb2011-10-28 19:50:21 +000051 // This must be called by before the GrDrawTarget destructor
52 this->releaseGeometry();
bsalomon@google.com6e4e6502013-02-25 20:12:45 +000053 fDstGpu->unref();
reed@google.comac10a2d2010-12-22 21:39:39 +000054}
55
bsalomon@google.com934c5702012-03-20 21:17:58 +000056////////////////////////////////////////////////////////////////////////////////
57
bsalomon@google.comd62e88e2013-02-01 14:19:27 +000058namespace {
59void get_vertex_bounds(const void* vertices,
60 size_t vertexSize,
61 int vertexCount,
62 SkRect* bounds) {
63 GrAssert(vertexSize >= sizeof(GrPoint));
64 GrAssert(vertexCount > 0);
65 const GrPoint* point = static_cast<const GrPoint*>(vertices);
66 bounds->fLeft = bounds->fRight = point->fX;
67 bounds->fTop = bounds->fBottom = point->fY;
68 for (int i = 1; i < vertexCount; ++i) {
69 point = reinterpret_cast<GrPoint*>(reinterpret_cast<intptr_t>(point) + vertexSize);
70 bounds->growToInclude(point->fX, point->fY);
71 }
72}
bsalomon@google.com934c5702012-03-20 21:17:58 +000073}
74
bsalomon@google.comd302f142011-03-03 13:54:13 +000075void GrInOrderDrawBuffer::drawRect(const GrRect& rect,
bsalomon@google.comb9086a02012-11-01 18:02:54 +000076 const SkMatrix* matrix,
jvanverth@google.com39768252013-02-14 15:25:44 +000077 const GrRect* srcRect,
78 const SkMatrix* srcMatrix,
79 int stage) {
bsalomon@google.comd302f142011-03-03 13:54:13 +000080
bsalomon@google.comd62e88e2013-02-01 14:19:27 +000081 GrVertexLayout layout = 0;
82 GrDrawState::AutoColorRestore acr;
83 GrColor color = this->drawState()->getColor();
bsalomon@google.com86afc2a2011-02-16 16:12:19 +000084
bsalomon@google.comd62e88e2013-02-01 14:19:27 +000085 // Using per-vertex colors allows batching across colors. (A lot of rects in a row differing
86 // only in color is a common occurrence in tables). However, having per-vertex colors disables
87 // blending optimizations because we don't know if the color will be solid or not. These
88 // optimizations help determine whether coverage and color can be blended correctly when
89 // dual-source blending isn't available. This comes into play when there is coverage. If colors
90 // were a stage it could take a hint that every vertex's color will be opaque.
91 if (this->getCaps().dualSourceBlendingSupport() ||
jvanverth@google.comb75b0a02013-02-05 20:33:30 +000092 this->getDrawState().hasSolidCoverage(this->getDrawState().getVertexLayout())) {
bsalomon@google.comd62e88e2013-02-01 14:19:27 +000093 layout |= GrDrawState::kColor_VertexLayoutBit;;
94 // We set the draw state's color to white here. This is done so that any batching performed
95 // in our subclass's onDraw() won't get a false from GrDrawState::op== due to a color
96 // mismatch. TODO: Once vertex layout is owned by GrDrawState it should skip comparing the
97 // constant color in its op== when the kColor layout bit is set and then we can remove this.
98 acr.set(this->drawState(), 0xFFFFFFFF);
bsalomon@google.com86afc2a2011-02-16 16:12:19 +000099 }
bsalomon@google.com86afc2a2011-02-16 16:12:19 +0000100
bsalomon@google.comd62e88e2013-02-01 14:19:27 +0000101 uint32_t explicitCoordMask = 0;
jvanverth@google.com39768252013-02-14 15:25:44 +0000102 if (NULL != srcRect) {
103 layout |= GrDrawState::StageTexCoordVertexLayoutBit(stage);
104 explicitCoordMask = (1 << stage);
bsalomon@google.comd62e88e2013-02-01 14:19:27 +0000105 }
106
jvanverth@google.comb75b0a02013-02-05 20:33:30 +0000107 this->drawState()->setVertexLayout(layout);
108 AutoReleaseGeometry geo(this, 4, 0);
bsalomon@google.comd62e88e2013-02-01 14:19:27 +0000109 if (!geo.succeeded()) {
110 GrPrintf("Failed to get space for vertices!\n");
bsalomon@google.com934c5702012-03-20 21:17:58 +0000111 return;
112 }
113
bsalomon@google.comd62e88e2013-02-01 14:19:27 +0000114 // Go to device coords to allow batching across matrix changes
115 SkMatrix combinedMatrix;
116 if (NULL != matrix) {
117 combinedMatrix = *matrix;
118 } else {
119 combinedMatrix.reset();
120 }
121 combinedMatrix.postConcat(this->drawState()->getViewMatrix());
jvanverth@google.com39768252013-02-14 15:25:44 +0000122 // 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 +0000123 // modify that stage's matrix. Otherwise if the effect is generating its source rect from
124 // the vertex positions then we have to account for the view matrix change.
125 GrDrawState::AutoDeviceCoordDraw adcd(this->drawState(), explicitCoordMask);
126 if (!adcd.succeeded()) {
127 return;
128 }
129
130 int stageOffsets[GrDrawState::kNumStages], colorOffset;
131 int vsize = GrDrawState::VertexSizeAndOffsetsByStage(layout, stageOffsets,
132 &colorOffset, NULL, NULL);
133
134 geo.positions()->setRectFan(rect.fLeft, rect.fTop, rect.fRight, rect.fBottom, vsize);
135 combinedMatrix.mapPointsWithStride(geo.positions(), vsize, 4);
136
137 SkRect devBounds;
138 // since we already computed the dev verts, set the bounds hint. This will help us avoid
139 // unnecessary clipping in our onDraw().
140 get_vertex_bounds(geo.vertices(), vsize, 4, &devBounds);
141
142 for (int i = 0; i < GrDrawState::kNumStages; ++i) {
143 if (explicitCoordMask & (1 << i)) {
reed@google.com009dfe22013-02-01 15:05:18 +0000144 GrAssert(0 != stageOffsets[i]);
bsalomon@google.comd62e88e2013-02-01 14:19:27 +0000145 GrPoint* coords = GrTCast<GrPoint*>(GrTCast<intptr_t>(geo.vertices()) +
146 stageOffsets[i]);
jvanverth@google.com39768252013-02-14 15:25:44 +0000147 coords->setRectFan(srcRect->fLeft, srcRect->fTop,
148 srcRect->fRight, srcRect->fBottom,
bsalomon@google.comd62e88e2013-02-01 14:19:27 +0000149 vsize);
jvanverth@google.com39768252013-02-14 15:25:44 +0000150 if (NULL != srcMatrix) {
151 srcMatrix->mapPointsWithStride(coords, vsize, 4);
bsalomon@google.comd62e88e2013-02-01 14:19:27 +0000152 }
153 } else {
reed@google.com009dfe22013-02-01 15:05:18 +0000154 GrAssert(0 == stageOffsets[i]);
bsalomon@google.comd62e88e2013-02-01 14:19:27 +0000155 }
156 }
157
158 if (colorOffset >= 0) {
159 GrColor* vertColor = GrTCast<GrColor*>(GrTCast<intptr_t>(geo.vertices()) + colorOffset);
160 for (int i = 0; i < 4; ++i) {
161 *vertColor = color;
162 vertColor = (GrColor*) ((intptr_t) vertColor + vsize);
163 }
164 }
165
bsalomon@google.com6e4e6502013-02-25 20:12:45 +0000166 this->setIndexSourceToBuffer(this->getContext()->getQuadIndexBuffer());
bsalomon@google.comd62e88e2013-02-01 14:19:27 +0000167 this->drawIndexedInstances(kTriangles_GrPrimitiveType, 1, 4, 6, &devBounds);
168}
169
170bool GrInOrderDrawBuffer::quickInsideClip(const SkRect& devBounds) {
171 if (!this->getDrawState().isClipState()) {
172 return true;
173 }
174 if (kUnknown_ClipProxyState == fClipProxyState) {
175 SkIRect rect;
176 bool iior;
177 this->getClip()->getConservativeBounds(this->getDrawState().getRenderTarget(), &rect, &iior);
178 if (iior) {
179 // The clip is a rect. We will remember that in fProxyClip. It is common for an edge (or
180 // all edges) of the clip to be at the edge of the RT. However, we get that clipping for
181 // free via the viewport. We don't want to think that clipping must be enabled in this
182 // case. So we extend the clip outward from the edge to avoid these false negatives.
183 fClipProxyState = kValid_ClipProxyState;
184 fClipProxy = SkRect::MakeFromIRect(rect);
185
186 if (fClipProxy.fLeft <= 0) {
187 fClipProxy.fLeft = SK_ScalarMin;
188 }
189 if (fClipProxy.fTop <= 0) {
190 fClipProxy.fTop = SK_ScalarMin;
191 }
192 if (fClipProxy.fRight >= this->getDrawState().getRenderTarget()->width()) {
193 fClipProxy.fRight = SK_ScalarMax;
194 }
195 if (fClipProxy.fBottom >= this->getDrawState().getRenderTarget()->height()) {
196 fClipProxy.fBottom = SK_ScalarMax;
197 }
198 } else {
199 fClipProxyState = kInvalid_ClipProxyState;
200 }
201 }
202 if (kValid_ClipProxyState == fClipProxyState) {
203 return fClipProxy.contains(devBounds);
204 }
205 SkPoint originOffset = {SkIntToScalar(this->getClip()->fOrigin.fX),
206 SkIntToScalar(this->getClip()->fOrigin.fY)};
207 SkRect clipSpaceBounds = devBounds;
208 clipSpaceBounds.offset(originOffset);
209 return this->getClip()->fClipStack->quickContains(clipSpaceBounds);
210}
211
212int GrInOrderDrawBuffer::concatInstancedDraw(const DrawInfo& info) {
213 GrAssert(info.isInstanced());
214
bsalomon@google.com934c5702012-03-20 21:17:58 +0000215 const GeometrySrcState& geomSrc = this->getGeomSrc();
jvanverth@google.comb75b0a02013-02-05 20:33:30 +0000216 const GrDrawState& drawState = this->getDrawState();
bsalomon@google.com934c5702012-03-20 21:17:58 +0000217
bsalomon@google.comd62e88e2013-02-01 14:19:27 +0000218 // we only attempt to concat the case when reserved verts are used with a client-specified index
219 // buffer. To make this work with client-specified VBs we'd need to know if the VB was updated
220 // between draws.
221 if (kReserved_GeometrySrcType != geomSrc.fVertexSrc ||
222 kBuffer_GeometrySrcType != geomSrc.fIndexSrc) {
223 return 0;
bsalomon@google.com934c5702012-03-20 21:17:58 +0000224 }
bsalomon@google.comd62e88e2013-02-01 14:19:27 +0000225 // Check if there is a draw info that is compatible that uses the same VB from the pool and
226 // the same IB
227 if (kDraw_Cmd != fCmds.back()) {
228 return 0;
229 }
230
231 DrawRecord* draw = &fDraws.back();
232 GeometryPoolState& poolState = fGeoPoolStateStack.back();
233 const GrVertexBuffer* vertexBuffer = poolState.fPoolVertexBuffer;
234
235 if (!draw->isInstanced() ||
236 draw->verticesPerInstance() != info.verticesPerInstance() ||
237 draw->indicesPerInstance() != info.indicesPerInstance() ||
238 draw->fVertexBuffer != vertexBuffer ||
jvanverth@google.comb75b0a02013-02-05 20:33:30 +0000239 draw->fIndexBuffer != geomSrc.fIndexBuffer) {
bsalomon@google.comd62e88e2013-02-01 14:19:27 +0000240 return 0;
241 }
242 // info does not yet account for the offset from the start of the pool's VB while the previous
243 // draw record does.
244 int adjustedStartVertex = poolState.fPoolStartVertex + info.startVertex();
245 if (draw->startVertex() + draw->vertexCount() != adjustedStartVertex) {
246 return 0;
247 }
248
249 GrAssert(poolState.fPoolStartVertex == draw->startVertex() + draw->vertexCount());
250
251 // how many instances can be concat'ed onto draw given the size of the index buffer
252 int instancesToConcat = this->indexCountInCurrentSource() / info.indicesPerInstance();
253 instancesToConcat -= draw->instanceCount();
254 instancesToConcat = GrMin(instancesToConcat, info.instanceCount());
255
256 // update the amount of reserved vertex data actually referenced in draws
skia.committer@gmail.comae683922013-02-06 07:01:54 +0000257 size_t vertexBytes = instancesToConcat * info.verticesPerInstance() *
jvanverth@google.comb75b0a02013-02-05 20:33:30 +0000258 drawState.getVertexSize();
bsalomon@google.comd62e88e2013-02-01 14:19:27 +0000259 poolState.fUsedPoolVertexBytes = GrMax(poolState.fUsedPoolVertexBytes, vertexBytes);
260
261 draw->adjustInstanceCount(instancesToConcat);
262 return instancesToConcat;
bsalomon@google.com934c5702012-03-20 21:17:58 +0000263}
264
bsalomon@google.comd62e88e2013-02-01 14:19:27 +0000265class AutoClipReenable {
266public:
267 AutoClipReenable() : fDrawState(NULL) {}
268 ~AutoClipReenable() {
269 if (NULL != fDrawState) {
270 fDrawState->enableState(GrDrawState::kClip_StateBit);
271 }
272 }
273 void set(GrDrawState* drawState) {
274 if (drawState->isClipState()) {
275 fDrawState = drawState;
276 drawState->disableState(GrDrawState::kClip_StateBit);
277 }
278 }
279private:
280 GrDrawState* fDrawState;
281};
282
bsalomon@google.com74749cd2013-01-30 16:12:41 +0000283void GrInOrderDrawBuffer::onDraw(const DrawInfo& info) {
reed@google.comac10a2d2010-12-22 21:39:39 +0000284
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000285 GeometryPoolState& poolState = fGeoPoolStateStack.back();
jvanverth@google.comb75b0a02013-02-05 20:33:30 +0000286 const GrDrawState& drawState = this->getDrawState();
bsalomon@google.comd62e88e2013-02-01 14:19:27 +0000287 AutoClipReenable acr;
288
jvanverth@google.comb75b0a02013-02-05 20:33:30 +0000289 if (drawState.isClipState() &&
bsalomon@google.comd62e88e2013-02-01 14:19:27 +0000290 NULL != info.getDevBounds() &&
291 this->quickInsideClip(*info.getDevBounds())) {
292 acr.set(this->drawState());
293 }
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000294
bsalomon@google.coma4f6b102012-06-26 21:04:22 +0000295 if (this->needsNewClip()) {
296 this->recordClip();
297 }
298 if (this->needsNewState()) {
299 this->recordState();
bsalomon@google.com86afc2a2011-02-16 16:12:19 +0000300 }
301
bsalomon@google.comd62e88e2013-02-01 14:19:27 +0000302 DrawRecord* draw;
303 if (info.isInstanced()) {
304 int instancesConcated = this->concatInstancedDraw(info);
305 if (info.instanceCount() > instancesConcated) {
306 draw = this->recordDraw(info);
307 draw->adjustInstanceCount(-instancesConcated);
308 } else {
309 return;
310 }
311 } else {
312 draw = this->recordDraw(info);
313 }
bsalomon@google.com74749cd2013-01-30 16:12:41 +0000314
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000315 switch (this->getGeomSrc().fVertexSrc) {
bsalomon@google.com74749cd2013-01-30 16:12:41 +0000316 case kBuffer_GeometrySrcType:
317 draw->fVertexBuffer = this->getGeomSrc().fVertexBuffer;
318 break;
319 case kReserved_GeometrySrcType: // fallthrough
320 case kArray_GeometrySrcType: {
skia.committer@gmail.comae683922013-02-06 07:01:54 +0000321 size_t vertexBytes = (info.vertexCount() + info.startVertex()) *
jvanverth@google.comb75b0a02013-02-05 20:33:30 +0000322 drawState.getVertexSize();
bsalomon@google.com74749cd2013-01-30 16:12:41 +0000323 poolState.fUsedPoolVertexBytes = GrMax(poolState.fUsedPoolVertexBytes, vertexBytes);
324 draw->fVertexBuffer = poolState.fPoolVertexBuffer;
bsalomon@google.comd62e88e2013-02-01 14:19:27 +0000325 draw->adjustStartVertex(poolState.fPoolStartVertex);
bsalomon@google.com74749cd2013-01-30 16:12:41 +0000326 break;
327 }
328 default:
329 GrCrash("unknown geom src type");
reed@google.comac10a2d2010-12-22 21:39:39 +0000330 }
bsalomon@google.coma4f6b102012-06-26 21:04:22 +0000331 draw->fVertexBuffer->ref();
reed@google.comac10a2d2010-12-22 21:39:39 +0000332
bsalomon@google.com74749cd2013-01-30 16:12:41 +0000333 if (info.isIndexed()) {
334 switch (this->getGeomSrc().fIndexSrc) {
335 case kBuffer_GeometrySrcType:
336 draw->fIndexBuffer = this->getGeomSrc().fIndexBuffer;
337 break;
338 case kReserved_GeometrySrcType: // fallthrough
339 case kArray_GeometrySrcType: {
340 size_t indexBytes = (info.indexCount() + info.startIndex()) * sizeof(uint16_t);
341 poolState.fUsedPoolIndexBytes = GrMax(poolState.fUsedPoolIndexBytes, indexBytes);
342 draw->fIndexBuffer = poolState.fPoolIndexBuffer;
bsalomon@google.comd62e88e2013-02-01 14:19:27 +0000343 draw->adjustStartIndex(poolState.fPoolStartIndex);
bsalomon@google.com74749cd2013-01-30 16:12:41 +0000344 break;
345 }
346 default:
347 GrCrash("unknown geom src type");
348 }
349 draw->fIndexBuffer->ref();
350 } else {
351 draw->fIndexBuffer = NULL;
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000352 }
reed@google.comac10a2d2010-12-22 21:39:39 +0000353}
354
sugoi@google.com5f74cf82012-12-17 21:16:45 +0000355GrInOrderDrawBuffer::StencilPath::StencilPath() : fStroke(SkStrokeRec::kFill_InitStyle) {}
356
357void GrInOrderDrawBuffer::onStencilPath(const GrPath* path, const SkStrokeRec& stroke,
sugoi@google.com12b4e272012-12-06 20:13:11 +0000358 SkPath::FillType fill) {
bsalomon@google.comded4f4b2012-06-28 18:48:06 +0000359 if (this->needsNewClip()) {
360 this->recordClip();
361 }
362 // Only compare the subset of GrDrawState relevant to path stenciling?
363 if (this->needsNewState()) {
364 this->recordState();
365 }
366 StencilPath* sp = this->recordStencilPath();
367 sp->fPath.reset(path);
368 path->ref();
369 sp->fFill = fill;
sugoi@google.com12b4e272012-12-06 20:13:11 +0000370 sp->fStroke = stroke;
bsalomon@google.com64aef2b2012-06-11 15:36:13 +0000371}
372
bsalomon@google.comd62e88e2013-02-01 14:19:27 +0000373void GrInOrderDrawBuffer::clear(const GrIRect* rect, GrColor color, GrRenderTarget* renderTarget) {
bsalomon@google.com6aa25c32011-04-27 19:55:29 +0000374 GrIRect r;
bsalomon@google.com1b3ce472012-08-17 13:43:08 +0000375 if (NULL == renderTarget) {
376 renderTarget = this->drawState()->getRenderTarget();
377 GrAssert(NULL != renderTarget);
378 }
bsalomon@google.com6aa25c32011-04-27 19:55:29 +0000379 if (NULL == rect) {
380 // We could do something smart and remove previous draws and clears to
381 // the current render target. If we get that smart we have to make sure
382 // those draws aren't read before this clear (render-to-texture).
bsalomon@google.com1b3ce472012-08-17 13:43:08 +0000383 r.setLTRB(0, 0, renderTarget->width(), renderTarget->height());
bsalomon@google.com6aa25c32011-04-27 19:55:29 +0000384 rect = &r;
385 }
bsalomon@google.coma4f6b102012-06-26 21:04:22 +0000386 Clear* clr = this->recordClear();
387 clr->fColor = color;
388 clr->fRect = *rect;
389 clr->fRenderTarget = renderTarget;
bsalomon@google.com1b3ce472012-08-17 13:43:08 +0000390 renderTarget->ref();
bsalomon@google.com0b335c12011-04-25 19:17:44 +0000391}
392
reed@google.comac10a2d2010-12-22 21:39:39 +0000393void GrInOrderDrawBuffer::reset() {
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000394 GrAssert(1 == fGeoPoolStateStack.count());
395 this->resetVertexSource();
396 this->resetIndexSource();
bsalomon@google.com86afc2a2011-02-16 16:12:19 +0000397 int numDraws = fDraws.count();
398 for (int d = 0; d < numDraws; ++d) {
399 // we always have a VB, but not always an IB
400 GrAssert(NULL != fDraws[d].fVertexBuffer);
401 fDraws[d].fVertexBuffer->unref();
402 GrSafeUnref(fDraws[d].fIndexBuffer);
403 }
bsalomon@google.coma4f6b102012-06-26 21:04:22 +0000404 fCmds.reset();
reed@google.comac10a2d2010-12-22 21:39:39 +0000405 fDraws.reset();
bsalomon@google.comded4f4b2012-06-28 18:48:06 +0000406 fStencilPaths.reset();
reed@google.comac10a2d2010-12-22 21:39:39 +0000407 fStates.reset();
bsalomon@google.com0b335c12011-04-25 19:17:44 +0000408 fClears.reset();
bsalomon@google.com1c13c962011-02-14 16:51:21 +0000409 fVertexPool.reset();
410 fIndexPool.reset();
reed@google.comac10a2d2010-12-22 21:39:39 +0000411 fClips.reset();
robertphillips@google.combeb1af72012-07-26 18:52:16 +0000412 fClipOrigins.reset();
bsalomon@google.coma4f6b102012-06-26 21:04:22 +0000413 fClipSet = true;
reed@google.comac10a2d2010-12-22 21:39:39 +0000414}
415
bsalomon@google.com6e4e6502013-02-25 20:12:45 +0000416bool GrInOrderDrawBuffer::flush() {
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000417 GrAssert(kReserved_GeometrySrcType != this->getGeomSrc().fVertexSrc);
418 GrAssert(kReserved_GeometrySrcType != this->getGeomSrc().fIndexSrc);
bsalomon@google.com3f5a95e2012-03-08 16:41:42 +0000419
bsalomon@google.coma4f6b102012-06-26 21:04:22 +0000420 int numCmds = fCmds.count();
bsalomon@google.com358e4272013-01-10 14:40:28 +0000421 if (0 == numCmds) {
bsalomon@google.coma4f6b102012-06-26 21:04:22 +0000422 return false;
reed@google.comac10a2d2010-12-22 21:39:39 +0000423 }
bsalomon@google.com6e4e6502013-02-25 20:12:45 +0000424 GrAssert(!fFlushing);
425
426 GrAutoTRestore<bool> flushRestore(&fFlushing);
427 fFlushing = true;
reed@google.comac10a2d2010-12-22 21:39:39 +0000428
bsalomon@google.com1c13c962011-02-14 16:51:21 +0000429 fVertexPool.unlock();
430 fIndexPool.unlock();
reed@google.comac10a2d2010-12-22 21:39:39 +0000431
bsalomon@google.com6e4e6502013-02-25 20:12:45 +0000432 GrDrawTarget::AutoClipRestore acr(fDstGpu);
433 AutoGeometryAndStatePush agasp(fDstGpu, kPreserve_ASRInit);
bsalomon@google.comca432082013-01-23 19:53:46 +0000434
435 GrDrawState playbackState;
bsalomon@google.com6e4e6502013-02-25 20:12:45 +0000436 GrDrawState* prevDrawState = fDstGpu->drawState();
bsalomon@google.coma5d056a2012-03-27 15:59:58 +0000437 prevDrawState->ref();
bsalomon@google.com6e4e6502013-02-25 20:12:45 +0000438 fDstGpu->setDrawState(&playbackState);
reed@google.comac10a2d2010-12-22 21:39:39 +0000439
robertphillips@google.combeb1af72012-07-26 18:52:16 +0000440 GrClipData clipData;
441
bsalomon@google.comded4f4b2012-06-28 18:48:06 +0000442 int currState = 0;
443 int currClip = 0;
444 int currClear = 0;
445 int currDraw = 0;
446 int currStencilPath = 0;
reed@google.comac10a2d2010-12-22 21:39:39 +0000447
bsalomon@google.coma4f6b102012-06-26 21:04:22 +0000448 for (int c = 0; c < numCmds; ++c) {
449 switch (fCmds[c]) {
450 case kDraw_Cmd: {
bsalomon@google.com74749cd2013-01-30 16:12:41 +0000451 const DrawRecord& draw = fDraws[currDraw];
bsalomon@google.com6e4e6502013-02-25 20:12:45 +0000452 fDstGpu->setVertexSourceToBuffer(draw.fVertexBuffer);
bsalomon@google.comd62e88e2013-02-01 14:19:27 +0000453 if (draw.isIndexed()) {
bsalomon@google.com6e4e6502013-02-25 20:12:45 +0000454 fDstGpu->setIndexSourceToBuffer(draw.fIndexBuffer);
bsalomon@google.coma4f6b102012-06-26 21:04:22 +0000455 }
bsalomon@google.com6e4e6502013-02-25 20:12:45 +0000456 fDstGpu->executeDraw(draw);
bsalomon@google.com0b335c12011-04-25 19:17:44 +0000457
bsalomon@google.coma4f6b102012-06-26 21:04:22 +0000458 ++currDraw;
459 break;
460 }
bsalomon@google.comded4f4b2012-06-28 18:48:06 +0000461 case kStencilPath_Cmd: {
462 const StencilPath& sp = fStencilPaths[currStencilPath];
bsalomon@google.com6e4e6502013-02-25 20:12:45 +0000463 fDstGpu->stencilPath(sp.fPath.get(), sp.fStroke, sp.fFill);
bsalomon@google.comded4f4b2012-06-28 18:48:06 +0000464 ++currStencilPath;
465 break;
466 }
bsalomon@google.coma4f6b102012-06-26 21:04:22 +0000467 case kSetState_Cmd:
bsalomon@google.comca432082013-01-23 19:53:46 +0000468 fStates[currState].restoreTo(&playbackState);
bsalomon@google.coma4f6b102012-06-26 21:04:22 +0000469 ++currState;
470 break;
471 case kSetClip_Cmd:
robertphillips@google.combeb1af72012-07-26 18:52:16 +0000472 clipData.fClipStack = &fClips[currClip];
473 clipData.fOrigin = fClipOrigins[currClip];
bsalomon@google.com6e4e6502013-02-25 20:12:45 +0000474 fDstGpu->setClip(&clipData);
bsalomon@google.coma4f6b102012-06-26 21:04:22 +0000475 ++currClip;
476 break;
477 case kClear_Cmd:
bsalomon@google.com6e4e6502013-02-25 20:12:45 +0000478 fDstGpu->clear(&fClears[currClear].fRect,
479 fClears[currClear].fColor,
480 fClears[currClear].fRenderTarget);
bsalomon@google.coma4f6b102012-06-26 21:04:22 +0000481 ++currClear;
482 break;
reed@google.comac10a2d2010-12-22 21:39:39 +0000483 }
484 }
bsalomon@google.coma4f6b102012-06-26 21:04:22 +0000485 // we should have consumed all the states, clips, etc.
486 GrAssert(fStates.count() == currState);
487 GrAssert(fClips.count() == currClip);
robertphillips@google.combeb1af72012-07-26 18:52:16 +0000488 GrAssert(fClipOrigins.count() == currClip);
bsalomon@google.coma4f6b102012-06-26 21:04:22 +0000489 GrAssert(fClears.count() == currClear);
490 GrAssert(fDraws.count() == currDraw);
491
bsalomon@google.com6e4e6502013-02-25 20:12:45 +0000492 fDstGpu->setDrawState(prevDrawState);
bsalomon@google.coma5d056a2012-03-27 15:59:58 +0000493 prevDrawState->unref();
bsalomon@google.com55e4a202013-01-11 13:54:21 +0000494 this->reset();
bsalomon@google.coma4f6b102012-06-26 21:04:22 +0000495 return true;
reed@google.comac10a2d2010-12-22 21:39:39 +0000496}
497
bsalomon@google.com97805382012-03-13 14:32:07 +0000498void GrInOrderDrawBuffer::willReserveVertexAndIndexSpace(
bsalomon@google.com97805382012-03-13 14:32:07 +0000499 int vertexCount,
500 int indexCount) {
bsalomon@google.com6e4e6502013-02-25 20:12:45 +0000501 // We use geometryHints() to know whether to flush the draw buffer. We
502 // can't flush if we are inside an unbalanced pushGeometrySource.
503 // Moreover, flushing blows away vertex and index data that was
504 // previously reserved. So if the vertex or index data is pulled from
505 // reserved space and won't be released by this request then we can't
506 // flush.
507 bool insideGeoPush = fGeoPoolStateStack.count() > 1;
bsalomon@google.com97805382012-03-13 14:32:07 +0000508
bsalomon@google.com6e4e6502013-02-25 20:12:45 +0000509 bool unreleasedVertexSpace =
510 !vertexCount &&
511 kReserved_GeometrySrcType == this->getGeomSrc().fVertexSrc;
bsalomon@google.com97805382012-03-13 14:32:07 +0000512
bsalomon@google.com6e4e6502013-02-25 20:12:45 +0000513 bool unreleasedIndexSpace =
514 !indexCount &&
515 kReserved_GeometrySrcType == this->getGeomSrc().fIndexSrc;
bsalomon@google.com97805382012-03-13 14:32:07 +0000516
bsalomon@google.com6e4e6502013-02-25 20:12:45 +0000517 // we don't want to finalize any reserved geom on the target since
518 // we don't know that the client has finished writing to it.
519 bool targetHasReservedGeom = fDstGpu->hasReservedVerticesOrIndices();
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000520
bsalomon@google.com6e4e6502013-02-25 20:12:45 +0000521 int vcount = vertexCount;
522 int icount = indexCount;
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000523
bsalomon@google.com6e4e6502013-02-25 20:12:45 +0000524 if (!insideGeoPush &&
525 !unreleasedVertexSpace &&
526 !unreleasedIndexSpace &&
527 !targetHasReservedGeom &&
528 this->geometryHints(&vcount, &icount)) {
bsalomon@google.com97805382012-03-13 14:32:07 +0000529
bsalomon@google.com6e4e6502013-02-25 20:12:45 +0000530 this->flush();
bsalomon@google.com97805382012-03-13 14:32:07 +0000531 }
532}
533
jvanverth@google.comb75b0a02013-02-05 20:33:30 +0000534bool GrInOrderDrawBuffer::geometryHints(int* vertexCount,
bsalomon@google.com1c13c962011-02-14 16:51:21 +0000535 int* indexCount) const {
536 // we will recommend a flush if the data could fit in a single
537 // preallocated buffer but none are left and it can't fit
538 // in the current buffer (which may not be prealloced).
reed@google.comac10a2d2010-12-22 21:39:39 +0000539 bool flush = false;
540 if (NULL != indexCount) {
bsalomon@google.com1c13c962011-02-14 16:51:21 +0000541 int32_t currIndices = fIndexPool.currentBufferIndices();
542 if (*indexCount > currIndices &&
543 (!fIndexPool.preallocatedBuffersRemaining() &&
544 *indexCount <= fIndexPool.preallocatedBufferIndices())) {
545
546 flush = true;
547 }
548 *indexCount = currIndices;
reed@google.comac10a2d2010-12-22 21:39:39 +0000549 }
550 if (NULL != vertexCount) {
jvanverth@google.comb75b0a02013-02-05 20:33:30 +0000551 size_t vertexSize = this->getDrawState().getVertexSize();
jvanverth@google.coma6338982013-01-31 21:34:25 +0000552 int32_t currVertices = fVertexPool.currentBufferVertices(vertexSize);
bsalomon@google.com1c13c962011-02-14 16:51:21 +0000553 if (*vertexCount > currVertices &&
554 (!fVertexPool.preallocatedBuffersRemaining() &&
jvanverth@google.coma6338982013-01-31 21:34:25 +0000555 *vertexCount <= fVertexPool.preallocatedBufferVertices(vertexSize))) {
reed@google.comac10a2d2010-12-22 21:39:39 +0000556
bsalomon@google.com1c13c962011-02-14 16:51:21 +0000557 flush = true;
reed@google.comac10a2d2010-12-22 21:39:39 +0000558 }
bsalomon@google.com1c13c962011-02-14 16:51:21 +0000559 *vertexCount = currVertices;
reed@google.comac10a2d2010-12-22 21:39:39 +0000560 }
561 return flush;
562}
563
jvanverth@google.coma6338982013-01-31 21:34:25 +0000564bool GrInOrderDrawBuffer::onReserveVertexSpace(size_t vertexSize,
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000565 int vertexCount,
566 void** vertices) {
567 GeometryPoolState& poolState = fGeoPoolStateStack.back();
568 GrAssert(vertexCount > 0);
569 GrAssert(NULL != vertices);
570 GrAssert(0 == poolState.fUsedPoolVertexBytes);
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000571
jvanverth@google.coma6338982013-01-31 21:34:25 +0000572 *vertices = fVertexPool.makeSpace(vertexSize,
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000573 vertexCount,
574 &poolState.fPoolVertexBuffer,
575 &poolState.fPoolStartVertex);
576 return NULL != *vertices;
577}
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000578
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000579bool GrInOrderDrawBuffer::onReserveIndexSpace(int indexCount, void** indices) {
580 GeometryPoolState& poolState = fGeoPoolStateStack.back();
581 GrAssert(indexCount > 0);
582 GrAssert(NULL != indices);
583 GrAssert(0 == poolState.fUsedPoolIndexBytes);
bsalomon@google.com1c13c962011-02-14 16:51:21 +0000584
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000585 *indices = fIndexPool.makeSpace(indexCount,
586 &poolState.fPoolIndexBuffer,
587 &poolState.fPoolStartIndex);
588 return NULL != *indices;
reed@google.comac10a2d2010-12-22 21:39:39 +0000589}
590
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000591void GrInOrderDrawBuffer::releaseReservedVertexSpace() {
592 GeometryPoolState& poolState = fGeoPoolStateStack.back();
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000593 const GeometrySrcState& geoSrc = this->getGeomSrc();
bsalomon@google.comd57d71a2012-08-16 16:26:33 +0000594
595 // If we get a release vertex space call then our current source should either be reserved
596 // or array (which we copied into reserved space).
597 GrAssert(kReserved_GeometrySrcType == geoSrc.fVertexSrc ||
598 kArray_GeometrySrcType == geoSrc.fVertexSrc);
bsalomon@google.com3f5a95e2012-03-08 16:41:42 +0000599
600 // When the caller reserved vertex buffer space we gave it back a pointer
601 // provided by the vertex buffer pool. At each draw we tracked the largest
602 // offset into the pool's pointer that was referenced. Now we return to the
603 // pool any portion at the tail of the allocation that no draw referenced.
jvanverth@google.comb75b0a02013-02-05 20:33:30 +0000604 size_t reservedVertexBytes = geoSrc.fVertexSize * geoSrc.fVertexCount;
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000605 fVertexPool.putBack(reservedVertexBytes -
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000606 poolState.fUsedPoolVertexBytes);
607 poolState.fUsedPoolVertexBytes = 0;
bsalomon@google.com3f5a95e2012-03-08 16:41:42 +0000608 poolState.fPoolVertexBuffer = NULL;
609 poolState.fPoolStartVertex = 0;
bsalomon@google.com1c13c962011-02-14 16:51:21 +0000610}
611
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000612void GrInOrderDrawBuffer::releaseReservedIndexSpace() {
613 GeometryPoolState& poolState = fGeoPoolStateStack.back();
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000614 const GeometrySrcState& geoSrc = this->getGeomSrc();
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000615
bsalomon@google.comd57d71a2012-08-16 16:26:33 +0000616 // If we get a release index space call then our current source should either be reserved
617 // or array (which we copied into reserved space).
618 GrAssert(kReserved_GeometrySrcType == geoSrc.fIndexSrc ||
619 kArray_GeometrySrcType == geoSrc.fIndexSrc);
bsalomon@google.com3f5a95e2012-03-08 16:41:42 +0000620
621 // Similar to releaseReservedVertexSpace we return any unused portion at
622 // the tail
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000623 size_t reservedIndexBytes = sizeof(uint16_t) * geoSrc.fIndexCount;
624 fIndexPool.putBack(reservedIndexBytes - poolState.fUsedPoolIndexBytes);
625 poolState.fUsedPoolIndexBytes = 0;
bsalomon@google.com3f5a95e2012-03-08 16:41:42 +0000626 poolState.fPoolIndexBuffer = NULL;
627 poolState.fPoolStartIndex = 0;
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000628}
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000629
bsalomon@google.combcdbbe62011-04-12 15:40:00 +0000630void GrInOrderDrawBuffer::onSetVertexSourceToArray(const void* vertexArray,
631 int vertexCount) {
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000632
633 GeometryPoolState& poolState = fGeoPoolStateStack.back();
634 GrAssert(0 == poolState.fUsedPoolVertexBytes);
bsalomon@google.com1c13c962011-02-14 16:51:21 +0000635#if GR_DEBUG
636 bool success =
637#endif
jvanverth@google.comb75b0a02013-02-05 20:33:30 +0000638 fVertexPool.appendVertices(this->getVertexSize(),
bsalomon@google.com1c13c962011-02-14 16:51:21 +0000639 vertexCount,
640 vertexArray,
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000641 &poolState.fPoolVertexBuffer,
642 &poolState.fPoolStartVertex);
bsalomon@google.com1c13c962011-02-14 16:51:21 +0000643 GR_DEBUGASSERT(success);
644}
645
bsalomon@google.combcdbbe62011-04-12 15:40:00 +0000646void GrInOrderDrawBuffer::onSetIndexSourceToArray(const void* indexArray,
647 int indexCount) {
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000648 GeometryPoolState& poolState = fGeoPoolStateStack.back();
649 GrAssert(0 == poolState.fUsedPoolIndexBytes);
bsalomon@google.com1c13c962011-02-14 16:51:21 +0000650#if GR_DEBUG
651 bool success =
652#endif
653 fIndexPool.appendIndices(indexCount,
654 indexArray,
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000655 &poolState.fPoolIndexBuffer,
656 &poolState.fPoolStartIndex);
bsalomon@google.com1c13c962011-02-14 16:51:21 +0000657 GR_DEBUGASSERT(success);
reed@google.comac10a2d2010-12-22 21:39:39 +0000658}
659
bsalomon@google.com3f5a95e2012-03-08 16:41:42 +0000660void GrInOrderDrawBuffer::releaseVertexArray() {
661 // When the client provides an array as the vertex source we handled it
662 // by copying their array into reserved space.
663 this->GrInOrderDrawBuffer::releaseReservedVertexSpace();
664}
665
666void GrInOrderDrawBuffer::releaseIndexArray() {
667 // When the client provides an array as the index source we handled it
668 // by copying their array into reserved space.
669 this->GrInOrderDrawBuffer::releaseReservedIndexSpace();
670}
671
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000672void GrInOrderDrawBuffer::geometrySourceWillPush() {
673 GeometryPoolState& poolState = fGeoPoolStateStack.push_back();
674 poolState.fUsedPoolVertexBytes = 0;
675 poolState.fUsedPoolIndexBytes = 0;
676#if GR_DEBUG
677 poolState.fPoolVertexBuffer = (GrVertexBuffer*)~0;
678 poolState.fPoolStartVertex = ~0;
679 poolState.fPoolIndexBuffer = (GrIndexBuffer*)~0;
680 poolState.fPoolStartIndex = ~0;
681#endif
682}
683
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000684void GrInOrderDrawBuffer::geometrySourceWillPop(
685 const GeometrySrcState& restoredState) {
686 GrAssert(fGeoPoolStateStack.count() > 1);
687 fGeoPoolStateStack.pop_back();
688 GeometryPoolState& poolState = fGeoPoolStateStack.back();
689 // we have to assume that any slack we had in our vertex/index data
690 // is now unreleasable because data may have been appended later in the
691 // pool.
692 if (kReserved_GeometrySrcType == restoredState.fVertexSrc ||
693 kArray_GeometrySrcType == restoredState.fVertexSrc) {
jvanverth@google.comb75b0a02013-02-05 20:33:30 +0000694 poolState.fUsedPoolVertexBytes = restoredState.fVertexSize * restoredState.fVertexCount;
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000695 }
696 if (kReserved_GeometrySrcType == restoredState.fIndexSrc ||
697 kArray_GeometrySrcType == restoredState.fIndexSrc) {
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000698 poolState.fUsedPoolIndexBytes = sizeof(uint16_t) *
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000699 restoredState.fIndexCount;
700 }
701}
702
bsalomon@google.com86afc2a2011-02-16 16:12:19 +0000703bool GrInOrderDrawBuffer::needsNewState() const {
bsalomon@google.comca432082013-01-23 19:53:46 +0000704 return fStates.empty() || !fStates.back().isEqual(this->getDrawState());
reed@google.comac10a2d2010-12-22 21:39:39 +0000705}
706
bsalomon@google.com86afc2a2011-02-16 16:12:19 +0000707bool GrInOrderDrawBuffer::needsNewClip() const {
bsalomon@google.com358e4272013-01-10 14:40:28 +0000708 GrAssert(fClips.count() == fClipOrigins.count());
709 if (this->getDrawState().isClipState()) {
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000710 if (fClipSet &&
bsalomon@google.com358e4272013-01-10 14:40:28 +0000711 (fClips.empty() ||
bsalomon@google.com02ddc8b2013-01-28 15:35:28 +0000712 fClips.back() != *this->getClip()->fClipStack ||
713 fClipOrigins.back() != this->getClip()->fOrigin)) {
bsalomon@google.com86afc2a2011-02-16 16:12:19 +0000714 return true;
715 }
reed@google.comac10a2d2010-12-22 21:39:39 +0000716 }
717 return false;
718}
bsalomon@google.comd302f142011-03-03 13:54:13 +0000719
bsalomon@google.coma4f6b102012-06-26 21:04:22 +0000720void GrInOrderDrawBuffer::recordClip() {
bsalomon@google.com02ddc8b2013-01-28 15:35:28 +0000721 fClips.push_back() = *this->getClip()->fClipStack;
722 fClipOrigins.push_back() = this->getClip()->fOrigin;
bsalomon@google.com86afc2a2011-02-16 16:12:19 +0000723 fClipSet = false;
bsalomon@google.coma4f6b102012-06-26 21:04:22 +0000724 fCmds.push_back(kSetClip_Cmd);
725}
726
bsalomon@google.coma4f6b102012-06-26 21:04:22 +0000727void GrInOrderDrawBuffer::recordState() {
bsalomon@google.comca432082013-01-23 19:53:46 +0000728 fStates.push_back().saveFrom(this->getDrawState());
bsalomon@google.coma4f6b102012-06-26 21:04:22 +0000729 fCmds.push_back(kSetState_Cmd);
730}
731
bsalomon@google.com74749cd2013-01-30 16:12:41 +0000732GrInOrderDrawBuffer::DrawRecord* GrInOrderDrawBuffer::recordDraw(const DrawInfo& info) {
bsalomon@google.comd62e88e2013-02-01 14:19:27 +0000733 fCmds.push_back(kDraw_Cmd);
734 return &fDraws.push_back(info);
bsalomon@google.com74749cd2013-01-30 16:12:41 +0000735}
736
bsalomon@google.comded4f4b2012-06-28 18:48:06 +0000737GrInOrderDrawBuffer::StencilPath* GrInOrderDrawBuffer::recordStencilPath() {
738 fCmds.push_back(kStencilPath_Cmd);
739 return &fStencilPaths.push_back();
740}
741
bsalomon@google.coma4f6b102012-06-26 21:04:22 +0000742GrInOrderDrawBuffer::Clear* GrInOrderDrawBuffer::recordClear() {
743 fCmds.push_back(kClear_Cmd);
744 return &fClears.push_back();
reed@google.comac10a2d2010-12-22 21:39:39 +0000745}
bsalomon@google.comd302f142011-03-03 13:54:13 +0000746
robertphillips@google.combeb1af72012-07-26 18:52:16 +0000747void GrInOrderDrawBuffer::clipWillBeSet(const GrClipData* newClipData) {
748 INHERITED::clipWillBeSet(newClipData);
bsalomon@google.com86afc2a2011-02-16 16:12:19 +0000749 fClipSet = true;
bsalomon@google.comd62e88e2013-02-01 14:19:27 +0000750 fClipProxyState = kUnknown_ClipProxyState;
bsalomon@google.com86afc2a2011-02-16 16:12:19 +0000751}