blob: 2e86147d6e154054c8aaf4d9c1f68da9202dcda4 [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();
bsalomon@google.combcce8922013-03-25 15:38:39 +000032 fCaps.reset(SkRef(fDstGpu->caps()));
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,
bsalomon@google.comc7818882013-03-20 19:19:53 +000077 const GrRect* localRect,
78 const SkMatrix* localMatrix) {
bsalomon@google.comd302f142011-03-03 13:54:13 +000079
jvanverth@google.com9b855c72013-03-01 18:21:22 +000080 GrAttribBindings bindings = GrDrawState::kDefault_AttribBindings;
bsalomon@google.comd62e88e2013-02-01 14:19:27 +000081 GrDrawState::AutoColorRestore acr;
jvanverth@google.com9b855c72013-03-01 18:21:22 +000082
83 GrDrawState* drawState = this->drawState();
84
85 GrColor color = drawState->getColor();
86 GrVertexAttribArray<3> attribs;
87 size_t currentOffset = 0;
bsalomon@google.comc7818882013-03-20 19:19:53 +000088 int colorOffset = -1, localOffset = -1;
jvanverth@google.com9b855c72013-03-01 18:21:22 +000089
90 // set position attrib
91 drawState->setAttribIndex(GrDrawState::kPosition_AttribIndex, attribs.count());
jvanverth@google.com3b0d6312013-03-01 20:30:01 +000092 GrVertexAttrib currAttrib = {kVec2f_GrVertexAttribType, currentOffset};
93 attribs.push_back(currAttrib);
jvanverth@google.com9b855c72013-03-01 18:21:22 +000094 currentOffset += sizeof(GrPoint);
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.
bsalomon@google.combcce8922013-03-25 15:38:39 +0000102 if (this->caps()->dualSourceBlendingSupport() ||
jvanverth@google.com9b855c72013-03-01 18:21:22 +0000103 drawState->hasSolidCoverage(drawState->getAttribBindings())) {
104 bindings |= GrDrawState::kColor_AttribBindingsBit;
105 drawState->setAttribIndex(GrDrawState::kColor_AttribIndex, attribs.count());
jvanverth@google.com3b0d6312013-03-01 20:30:01 +0000106 currAttrib.set(kVec4ub_GrVertexAttribType, currentOffset);
107 attribs.push_back(currAttrib);
jvanverth@google.com9b855c72013-03-01 18:21:22 +0000108 colorOffset = currentOffset;
109 currentOffset += sizeof(GrColor);
bsalomon@google.comd62e88e2013-02-01 14:19:27 +0000110 // We set the draw state's color to white here. This is done so that any batching performed
111 // in our subclass's onDraw() won't get a false from GrDrawState::op== due to a color
112 // mismatch. TODO: Once vertex layout is owned by GrDrawState it should skip comparing the
113 // 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 +0000114 acr.set(drawState, 0xFFFFFFFF);
bsalomon@google.com86afc2a2011-02-16 16:12:19 +0000115 }
bsalomon@google.com86afc2a2011-02-16 16:12:19 +0000116
bsalomon@google.comc7818882013-03-20 19:19:53 +0000117 if (NULL != localRect) {
118 bindings |= GrDrawState::kLocalCoords_AttribBindingsBit;
119 drawState->setAttribIndex(GrDrawState::kLocalCoords_AttribIndex, attribs.count());
jvanverth@google.com3b0d6312013-03-01 20:30:01 +0000120 currAttrib.set(kVec2f_GrVertexAttribType, currentOffset);
121 attribs.push_back(currAttrib);
bsalomon@google.comc7818882013-03-20 19:19:53 +0000122 localOffset = currentOffset;
jvanverth@google.com9b855c72013-03-01 18:21:22 +0000123 currentOffset += sizeof(GrPoint);
bsalomon@google.comd62e88e2013-02-01 14:19:27 +0000124 }
125
jvanverth@google.com9b855c72013-03-01 18:21:22 +0000126 drawState->setVertexAttribs(attribs.begin(), attribs.count());
127 drawState->setAttribBindings(bindings);
jvanverth@google.comb75b0a02013-02-05 20:33:30 +0000128 AutoReleaseGeometry geo(this, 4, 0);
bsalomon@google.comd62e88e2013-02-01 14:19:27 +0000129 if (!geo.succeeded()) {
130 GrPrintf("Failed to get space for vertices!\n");
bsalomon@google.com934c5702012-03-20 21:17:58 +0000131 return;
132 }
133
bsalomon@google.comd62e88e2013-02-01 14:19:27 +0000134 // Go to device coords to allow batching across matrix changes
135 SkMatrix combinedMatrix;
136 if (NULL != matrix) {
137 combinedMatrix = *matrix;
138 } else {
139 combinedMatrix.reset();
140 }
jvanverth@google.com9b855c72013-03-01 18:21:22 +0000141 combinedMatrix.postConcat(drawState->getViewMatrix());
jvanverth@google.com39768252013-02-14 15:25:44 +0000142 // 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 +0000143 // modify that stage's matrix. Otherwise if the effect is generating its source rect from
144 // the vertex positions then we have to account for the view matrix change.
bsalomon@google.comc7818882013-03-20 19:19:53 +0000145 GrDrawState::AutoDeviceCoordDraw adcd(drawState);
bsalomon@google.comd62e88e2013-02-01 14:19:27 +0000146 if (!adcd.succeeded()) {
147 return;
148 }
149
jvanverth@google.com9b855c72013-03-01 18:21:22 +0000150 size_t vsize = drawState->getVertexSize();
151 GrAssert(vsize == currentOffset);
bsalomon@google.comd62e88e2013-02-01 14:19:27 +0000152
153 geo.positions()->setRectFan(rect.fLeft, rect.fTop, rect.fRight, rect.fBottom, vsize);
154 combinedMatrix.mapPointsWithStride(geo.positions(), vsize, 4);
155
156 SkRect devBounds;
157 // since we already computed the dev verts, set the bounds hint. This will help us avoid
158 // unnecessary clipping in our onDraw().
159 get_vertex_bounds(geo.vertices(), vsize, 4, &devBounds);
160
bsalomon@google.comc7818882013-03-20 19:19:53 +0000161 if (localOffset >= 0) {
162 GrPoint* coords = GrTCast<GrPoint*>(GrTCast<intptr_t>(geo.vertices()) + localOffset);
163 coords->setRectFan(localRect->fLeft, localRect->fTop,
164 localRect->fRight, localRect->fBottom,
jvanverth@google.com9b855c72013-03-01 18:21:22 +0000165 vsize);
bsalomon@google.comc7818882013-03-20 19:19:53 +0000166 if (NULL != localMatrix) {
167 localMatrix->mapPointsWithStride(coords, vsize, 4);
bsalomon@google.comd62e88e2013-02-01 14:19:27 +0000168 }
169 }
170
171 if (colorOffset >= 0) {
172 GrColor* vertColor = GrTCast<GrColor*>(GrTCast<intptr_t>(geo.vertices()) + colorOffset);
173 for (int i = 0; i < 4; ++i) {
174 *vertColor = color;
175 vertColor = (GrColor*) ((intptr_t) vertColor + vsize);
176 }
177 }
178
bsalomon@google.com6e4e6502013-02-25 20:12:45 +0000179 this->setIndexSourceToBuffer(this->getContext()->getQuadIndexBuffer());
bsalomon@google.comd62e88e2013-02-01 14:19:27 +0000180 this->drawIndexedInstances(kTriangles_GrPrimitiveType, 1, 4, 6, &devBounds);
jvanverth@google.com9b855c72013-03-01 18:21:22 +0000181
182 // to ensure that stashing the drawState ptr is valid
183 GrAssert(this->drawState() == drawState);
bsalomon@google.comd62e88e2013-02-01 14:19:27 +0000184}
185
186bool GrInOrderDrawBuffer::quickInsideClip(const SkRect& devBounds) {
187 if (!this->getDrawState().isClipState()) {
188 return true;
189 }
190 if (kUnknown_ClipProxyState == fClipProxyState) {
191 SkIRect rect;
192 bool iior;
193 this->getClip()->getConservativeBounds(this->getDrawState().getRenderTarget(), &rect, &iior);
194 if (iior) {
195 // The clip is a rect. We will remember that in fProxyClip. It is common for an edge (or
196 // all edges) of the clip to be at the edge of the RT. However, we get that clipping for
197 // free via the viewport. We don't want to think that clipping must be enabled in this
198 // case. So we extend the clip outward from the edge to avoid these false negatives.
199 fClipProxyState = kValid_ClipProxyState;
200 fClipProxy = SkRect::MakeFromIRect(rect);
201
202 if (fClipProxy.fLeft <= 0) {
203 fClipProxy.fLeft = SK_ScalarMin;
204 }
205 if (fClipProxy.fTop <= 0) {
206 fClipProxy.fTop = SK_ScalarMin;
207 }
208 if (fClipProxy.fRight >= this->getDrawState().getRenderTarget()->width()) {
209 fClipProxy.fRight = SK_ScalarMax;
210 }
211 if (fClipProxy.fBottom >= this->getDrawState().getRenderTarget()->height()) {
212 fClipProxy.fBottom = SK_ScalarMax;
213 }
214 } else {
215 fClipProxyState = kInvalid_ClipProxyState;
216 }
217 }
218 if (kValid_ClipProxyState == fClipProxyState) {
219 return fClipProxy.contains(devBounds);
220 }
221 SkPoint originOffset = {SkIntToScalar(this->getClip()->fOrigin.fX),
222 SkIntToScalar(this->getClip()->fOrigin.fY)};
223 SkRect clipSpaceBounds = devBounds;
224 clipSpaceBounds.offset(originOffset);
225 return this->getClip()->fClipStack->quickContains(clipSpaceBounds);
226}
227
228int GrInOrderDrawBuffer::concatInstancedDraw(const DrawInfo& info) {
229 GrAssert(info.isInstanced());
230
bsalomon@google.com934c5702012-03-20 21:17:58 +0000231 const GeometrySrcState& geomSrc = this->getGeomSrc();
jvanverth@google.comb75b0a02013-02-05 20:33:30 +0000232 const GrDrawState& drawState = this->getDrawState();
bsalomon@google.com934c5702012-03-20 21:17:58 +0000233
bsalomon@google.comd62e88e2013-02-01 14:19:27 +0000234 // we only attempt to concat the case when reserved verts are used with a client-specified index
235 // buffer. To make this work with client-specified VBs we'd need to know if the VB was updated
236 // between draws.
237 if (kReserved_GeometrySrcType != geomSrc.fVertexSrc ||
238 kBuffer_GeometrySrcType != geomSrc.fIndexSrc) {
239 return 0;
bsalomon@google.com934c5702012-03-20 21:17:58 +0000240 }
bsalomon@google.comd62e88e2013-02-01 14:19:27 +0000241 // Check if there is a draw info that is compatible that uses the same VB from the pool and
242 // the same IB
243 if (kDraw_Cmd != fCmds.back()) {
244 return 0;
245 }
246
247 DrawRecord* draw = &fDraws.back();
248 GeometryPoolState& poolState = fGeoPoolStateStack.back();
249 const GrVertexBuffer* vertexBuffer = poolState.fPoolVertexBuffer;
250
251 if (!draw->isInstanced() ||
252 draw->verticesPerInstance() != info.verticesPerInstance() ||
253 draw->indicesPerInstance() != info.indicesPerInstance() ||
254 draw->fVertexBuffer != vertexBuffer ||
jvanverth@google.comb75b0a02013-02-05 20:33:30 +0000255 draw->fIndexBuffer != geomSrc.fIndexBuffer) {
bsalomon@google.comd62e88e2013-02-01 14:19:27 +0000256 return 0;
257 }
258 // info does not yet account for the offset from the start of the pool's VB while the previous
259 // draw record does.
260 int adjustedStartVertex = poolState.fPoolStartVertex + info.startVertex();
261 if (draw->startVertex() + draw->vertexCount() != adjustedStartVertex) {
262 return 0;
263 }
264
265 GrAssert(poolState.fPoolStartVertex == draw->startVertex() + draw->vertexCount());
266
267 // how many instances can be concat'ed onto draw given the size of the index buffer
268 int instancesToConcat = this->indexCountInCurrentSource() / info.indicesPerInstance();
269 instancesToConcat -= draw->instanceCount();
270 instancesToConcat = GrMin(instancesToConcat, info.instanceCount());
271
272 // update the amount of reserved vertex data actually referenced in draws
skia.committer@gmail.comae683922013-02-06 07:01:54 +0000273 size_t vertexBytes = instancesToConcat * info.verticesPerInstance() *
jvanverth@google.comb75b0a02013-02-05 20:33:30 +0000274 drawState.getVertexSize();
bsalomon@google.comd62e88e2013-02-01 14:19:27 +0000275 poolState.fUsedPoolVertexBytes = GrMax(poolState.fUsedPoolVertexBytes, vertexBytes);
276
277 draw->adjustInstanceCount(instancesToConcat);
278 return instancesToConcat;
bsalomon@google.com934c5702012-03-20 21:17:58 +0000279}
280
bsalomon@google.comd62e88e2013-02-01 14:19:27 +0000281class AutoClipReenable {
282public:
283 AutoClipReenable() : fDrawState(NULL) {}
284 ~AutoClipReenable() {
285 if (NULL != fDrawState) {
286 fDrawState->enableState(GrDrawState::kClip_StateBit);
287 }
288 }
289 void set(GrDrawState* drawState) {
290 if (drawState->isClipState()) {
291 fDrawState = drawState;
292 drawState->disableState(GrDrawState::kClip_StateBit);
293 }
294 }
295private:
296 GrDrawState* fDrawState;
297};
298
bsalomon@google.com74749cd2013-01-30 16:12:41 +0000299void GrInOrderDrawBuffer::onDraw(const DrawInfo& info) {
reed@google.comac10a2d2010-12-22 21:39:39 +0000300
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000301 GeometryPoolState& poolState = fGeoPoolStateStack.back();
jvanverth@google.comb75b0a02013-02-05 20:33:30 +0000302 const GrDrawState& drawState = this->getDrawState();
bsalomon@google.comd62e88e2013-02-01 14:19:27 +0000303 AutoClipReenable acr;
304
jvanverth@google.comb75b0a02013-02-05 20:33:30 +0000305 if (drawState.isClipState() &&
bsalomon@google.comd62e88e2013-02-01 14:19:27 +0000306 NULL != info.getDevBounds() &&
307 this->quickInsideClip(*info.getDevBounds())) {
308 acr.set(this->drawState());
309 }
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000310
bsalomon@google.coma4f6b102012-06-26 21:04:22 +0000311 if (this->needsNewClip()) {
312 this->recordClip();
313 }
314 if (this->needsNewState()) {
315 this->recordState();
bsalomon@google.com86afc2a2011-02-16 16:12:19 +0000316 }
317
bsalomon@google.comd62e88e2013-02-01 14:19:27 +0000318 DrawRecord* draw;
319 if (info.isInstanced()) {
320 int instancesConcated = this->concatInstancedDraw(info);
321 if (info.instanceCount() > instancesConcated) {
322 draw = this->recordDraw(info);
323 draw->adjustInstanceCount(-instancesConcated);
324 } else {
325 return;
326 }
327 } else {
328 draw = this->recordDraw(info);
329 }
bsalomon@google.com74749cd2013-01-30 16:12:41 +0000330
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000331 switch (this->getGeomSrc().fVertexSrc) {
bsalomon@google.com74749cd2013-01-30 16:12:41 +0000332 case kBuffer_GeometrySrcType:
333 draw->fVertexBuffer = this->getGeomSrc().fVertexBuffer;
334 break;
335 case kReserved_GeometrySrcType: // fallthrough
336 case kArray_GeometrySrcType: {
skia.committer@gmail.comae683922013-02-06 07:01:54 +0000337 size_t vertexBytes = (info.vertexCount() + info.startVertex()) *
jvanverth@google.comb75b0a02013-02-05 20:33:30 +0000338 drawState.getVertexSize();
bsalomon@google.com74749cd2013-01-30 16:12:41 +0000339 poolState.fUsedPoolVertexBytes = GrMax(poolState.fUsedPoolVertexBytes, vertexBytes);
340 draw->fVertexBuffer = poolState.fPoolVertexBuffer;
bsalomon@google.comd62e88e2013-02-01 14:19:27 +0000341 draw->adjustStartVertex(poolState.fPoolStartVertex);
bsalomon@google.com74749cd2013-01-30 16:12:41 +0000342 break;
343 }
344 default:
345 GrCrash("unknown geom src type");
reed@google.comac10a2d2010-12-22 21:39:39 +0000346 }
bsalomon@google.coma4f6b102012-06-26 21:04:22 +0000347 draw->fVertexBuffer->ref();
reed@google.comac10a2d2010-12-22 21:39:39 +0000348
bsalomon@google.com74749cd2013-01-30 16:12:41 +0000349 if (info.isIndexed()) {
350 switch (this->getGeomSrc().fIndexSrc) {
351 case kBuffer_GeometrySrcType:
352 draw->fIndexBuffer = this->getGeomSrc().fIndexBuffer;
353 break;
354 case kReserved_GeometrySrcType: // fallthrough
355 case kArray_GeometrySrcType: {
356 size_t indexBytes = (info.indexCount() + info.startIndex()) * sizeof(uint16_t);
357 poolState.fUsedPoolIndexBytes = GrMax(poolState.fUsedPoolIndexBytes, indexBytes);
358 draw->fIndexBuffer = poolState.fPoolIndexBuffer;
bsalomon@google.comd62e88e2013-02-01 14:19:27 +0000359 draw->adjustStartIndex(poolState.fPoolStartIndex);
bsalomon@google.com74749cd2013-01-30 16:12:41 +0000360 break;
361 }
362 default:
363 GrCrash("unknown geom src type");
364 }
365 draw->fIndexBuffer->ref();
366 } else {
367 draw->fIndexBuffer = NULL;
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000368 }
reed@google.comac10a2d2010-12-22 21:39:39 +0000369}
370
sugoi@google.com5f74cf82012-12-17 21:16:45 +0000371GrInOrderDrawBuffer::StencilPath::StencilPath() : fStroke(SkStrokeRec::kFill_InitStyle) {}
372
373void GrInOrderDrawBuffer::onStencilPath(const GrPath* path, const SkStrokeRec& stroke,
sugoi@google.com12b4e272012-12-06 20:13:11 +0000374 SkPath::FillType fill) {
bsalomon@google.comded4f4b2012-06-28 18:48:06 +0000375 if (this->needsNewClip()) {
376 this->recordClip();
377 }
378 // Only compare the subset of GrDrawState relevant to path stenciling?
379 if (this->needsNewState()) {
380 this->recordState();
381 }
382 StencilPath* sp = this->recordStencilPath();
383 sp->fPath.reset(path);
384 path->ref();
385 sp->fFill = fill;
sugoi@google.com12b4e272012-12-06 20:13:11 +0000386 sp->fStroke = stroke;
bsalomon@google.com64aef2b2012-06-11 15:36:13 +0000387}
388
bsalomon@google.comd62e88e2013-02-01 14:19:27 +0000389void GrInOrderDrawBuffer::clear(const GrIRect* rect, GrColor color, GrRenderTarget* renderTarget) {
bsalomon@google.com6aa25c32011-04-27 19:55:29 +0000390 GrIRect r;
bsalomon@google.com1b3ce472012-08-17 13:43:08 +0000391 if (NULL == renderTarget) {
392 renderTarget = this->drawState()->getRenderTarget();
393 GrAssert(NULL != renderTarget);
394 }
bsalomon@google.com6aa25c32011-04-27 19:55:29 +0000395 if (NULL == rect) {
396 // We could do something smart and remove previous draws and clears to
397 // the current render target. If we get that smart we have to make sure
398 // those draws aren't read before this clear (render-to-texture).
bsalomon@google.com1b3ce472012-08-17 13:43:08 +0000399 r.setLTRB(0, 0, renderTarget->width(), renderTarget->height());
bsalomon@google.com6aa25c32011-04-27 19:55:29 +0000400 rect = &r;
401 }
bsalomon@google.coma4f6b102012-06-26 21:04:22 +0000402 Clear* clr = this->recordClear();
403 clr->fColor = color;
404 clr->fRect = *rect;
405 clr->fRenderTarget = renderTarget;
bsalomon@google.com1b3ce472012-08-17 13:43:08 +0000406 renderTarget->ref();
bsalomon@google.com0b335c12011-04-25 19:17:44 +0000407}
408
reed@google.comac10a2d2010-12-22 21:39:39 +0000409void GrInOrderDrawBuffer::reset() {
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000410 GrAssert(1 == fGeoPoolStateStack.count());
411 this->resetVertexSource();
412 this->resetIndexSource();
bsalomon@google.com86afc2a2011-02-16 16:12:19 +0000413 int numDraws = fDraws.count();
414 for (int d = 0; d < numDraws; ++d) {
415 // we always have a VB, but not always an IB
416 GrAssert(NULL != fDraws[d].fVertexBuffer);
417 fDraws[d].fVertexBuffer->unref();
418 GrSafeUnref(fDraws[d].fIndexBuffer);
419 }
bsalomon@google.coma4f6b102012-06-26 21:04:22 +0000420 fCmds.reset();
reed@google.comac10a2d2010-12-22 21:39:39 +0000421 fDraws.reset();
bsalomon@google.comded4f4b2012-06-28 18:48:06 +0000422 fStencilPaths.reset();
reed@google.comac10a2d2010-12-22 21:39:39 +0000423 fStates.reset();
bsalomon@google.com0b335c12011-04-25 19:17:44 +0000424 fClears.reset();
bsalomon@google.com1c13c962011-02-14 16:51:21 +0000425 fVertexPool.reset();
426 fIndexPool.reset();
reed@google.comac10a2d2010-12-22 21:39:39 +0000427 fClips.reset();
robertphillips@google.combeb1af72012-07-26 18:52:16 +0000428 fClipOrigins.reset();
bsalomon@google.coma4f6b102012-06-26 21:04:22 +0000429 fClipSet = true;
reed@google.comac10a2d2010-12-22 21:39:39 +0000430}
431
bsalomon@google.com6e4e6502013-02-25 20:12:45 +0000432bool GrInOrderDrawBuffer::flush() {
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000433 GrAssert(kReserved_GeometrySrcType != this->getGeomSrc().fVertexSrc);
434 GrAssert(kReserved_GeometrySrcType != this->getGeomSrc().fIndexSrc);
bsalomon@google.com3f5a95e2012-03-08 16:41:42 +0000435
bsalomon@google.coma4f6b102012-06-26 21:04:22 +0000436 int numCmds = fCmds.count();
bsalomon@google.com358e4272013-01-10 14:40:28 +0000437 if (0 == numCmds) {
bsalomon@google.coma4f6b102012-06-26 21:04:22 +0000438 return false;
reed@google.comac10a2d2010-12-22 21:39:39 +0000439 }
bsalomon@google.com6e4e6502013-02-25 20:12:45 +0000440 GrAssert(!fFlushing);
441
442 GrAutoTRestore<bool> flushRestore(&fFlushing);
443 fFlushing = true;
reed@google.comac10a2d2010-12-22 21:39:39 +0000444
bsalomon@google.com1c13c962011-02-14 16:51:21 +0000445 fVertexPool.unlock();
446 fIndexPool.unlock();
reed@google.comac10a2d2010-12-22 21:39:39 +0000447
bsalomon@google.com6e4e6502013-02-25 20:12:45 +0000448 GrDrawTarget::AutoClipRestore acr(fDstGpu);
449 AutoGeometryAndStatePush agasp(fDstGpu, kPreserve_ASRInit);
bsalomon@google.comca432082013-01-23 19:53:46 +0000450
451 GrDrawState playbackState;
bsalomon@google.com6e4e6502013-02-25 20:12:45 +0000452 GrDrawState* prevDrawState = fDstGpu->drawState();
bsalomon@google.coma5d056a2012-03-27 15:59:58 +0000453 prevDrawState->ref();
bsalomon@google.com6e4e6502013-02-25 20:12:45 +0000454 fDstGpu->setDrawState(&playbackState);
reed@google.comac10a2d2010-12-22 21:39:39 +0000455
robertphillips@google.combeb1af72012-07-26 18:52:16 +0000456 GrClipData clipData;
457
bsalomon@google.comded4f4b2012-06-28 18:48:06 +0000458 int currState = 0;
459 int currClip = 0;
460 int currClear = 0;
461 int currDraw = 0;
462 int currStencilPath = 0;
reed@google.comac10a2d2010-12-22 21:39:39 +0000463
bsalomon@google.coma4f6b102012-06-26 21:04:22 +0000464 for (int c = 0; c < numCmds; ++c) {
465 switch (fCmds[c]) {
466 case kDraw_Cmd: {
bsalomon@google.com74749cd2013-01-30 16:12:41 +0000467 const DrawRecord& draw = fDraws[currDraw];
bsalomon@google.com6e4e6502013-02-25 20:12:45 +0000468 fDstGpu->setVertexSourceToBuffer(draw.fVertexBuffer);
bsalomon@google.comd62e88e2013-02-01 14:19:27 +0000469 if (draw.isIndexed()) {
bsalomon@google.com6e4e6502013-02-25 20:12:45 +0000470 fDstGpu->setIndexSourceToBuffer(draw.fIndexBuffer);
bsalomon@google.coma4f6b102012-06-26 21:04:22 +0000471 }
bsalomon@google.com6e4e6502013-02-25 20:12:45 +0000472 fDstGpu->executeDraw(draw);
bsalomon@google.com0b335c12011-04-25 19:17:44 +0000473
bsalomon@google.coma4f6b102012-06-26 21:04:22 +0000474 ++currDraw;
475 break;
476 }
bsalomon@google.comded4f4b2012-06-28 18:48:06 +0000477 case kStencilPath_Cmd: {
478 const StencilPath& sp = fStencilPaths[currStencilPath];
bsalomon@google.com6e4e6502013-02-25 20:12:45 +0000479 fDstGpu->stencilPath(sp.fPath.get(), sp.fStroke, sp.fFill);
bsalomon@google.comded4f4b2012-06-28 18:48:06 +0000480 ++currStencilPath;
481 break;
482 }
bsalomon@google.coma4f6b102012-06-26 21:04:22 +0000483 case kSetState_Cmd:
bsalomon@google.comca432082013-01-23 19:53:46 +0000484 fStates[currState].restoreTo(&playbackState);
bsalomon@google.coma4f6b102012-06-26 21:04:22 +0000485 ++currState;
486 break;
487 case kSetClip_Cmd:
robertphillips@google.combeb1af72012-07-26 18:52:16 +0000488 clipData.fClipStack = &fClips[currClip];
489 clipData.fOrigin = fClipOrigins[currClip];
bsalomon@google.com6e4e6502013-02-25 20:12:45 +0000490 fDstGpu->setClip(&clipData);
bsalomon@google.coma4f6b102012-06-26 21:04:22 +0000491 ++currClip;
492 break;
493 case kClear_Cmd:
bsalomon@google.com6e4e6502013-02-25 20:12:45 +0000494 fDstGpu->clear(&fClears[currClear].fRect,
495 fClears[currClear].fColor,
496 fClears[currClear].fRenderTarget);
bsalomon@google.coma4f6b102012-06-26 21:04:22 +0000497 ++currClear;
498 break;
reed@google.comac10a2d2010-12-22 21:39:39 +0000499 }
500 }
bsalomon@google.coma4f6b102012-06-26 21:04:22 +0000501 // we should have consumed all the states, clips, etc.
502 GrAssert(fStates.count() == currState);
503 GrAssert(fClips.count() == currClip);
robertphillips@google.combeb1af72012-07-26 18:52:16 +0000504 GrAssert(fClipOrigins.count() == currClip);
bsalomon@google.coma4f6b102012-06-26 21:04:22 +0000505 GrAssert(fClears.count() == currClear);
506 GrAssert(fDraws.count() == currDraw);
507
bsalomon@google.com6e4e6502013-02-25 20:12:45 +0000508 fDstGpu->setDrawState(prevDrawState);
bsalomon@google.coma5d056a2012-03-27 15:59:58 +0000509 prevDrawState->unref();
bsalomon@google.com55e4a202013-01-11 13:54:21 +0000510 this->reset();
bsalomon@google.coma4f6b102012-06-26 21:04:22 +0000511 return true;
reed@google.comac10a2d2010-12-22 21:39:39 +0000512}
513
bsalomon@google.com97805382012-03-13 14:32:07 +0000514void GrInOrderDrawBuffer::willReserveVertexAndIndexSpace(
bsalomon@google.com97805382012-03-13 14:32:07 +0000515 int vertexCount,
516 int indexCount) {
bsalomon@google.com6e4e6502013-02-25 20:12:45 +0000517 // We use geometryHints() to know whether to flush the draw buffer. We
518 // can't flush if we are inside an unbalanced pushGeometrySource.
519 // Moreover, flushing blows away vertex and index data that was
520 // previously reserved. So if the vertex or index data is pulled from
521 // reserved space and won't be released by this request then we can't
522 // flush.
523 bool insideGeoPush = fGeoPoolStateStack.count() > 1;
bsalomon@google.com97805382012-03-13 14:32:07 +0000524
bsalomon@google.com6e4e6502013-02-25 20:12:45 +0000525 bool unreleasedVertexSpace =
526 !vertexCount &&
527 kReserved_GeometrySrcType == this->getGeomSrc().fVertexSrc;
bsalomon@google.com97805382012-03-13 14:32:07 +0000528
bsalomon@google.com6e4e6502013-02-25 20:12:45 +0000529 bool unreleasedIndexSpace =
530 !indexCount &&
531 kReserved_GeometrySrcType == this->getGeomSrc().fIndexSrc;
bsalomon@google.com97805382012-03-13 14:32:07 +0000532
bsalomon@google.com6e4e6502013-02-25 20:12:45 +0000533 // we don't want to finalize any reserved geom on the target since
534 // we don't know that the client has finished writing to it.
535 bool targetHasReservedGeom = fDstGpu->hasReservedVerticesOrIndices();
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000536
bsalomon@google.com6e4e6502013-02-25 20:12:45 +0000537 int vcount = vertexCount;
538 int icount = indexCount;
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000539
bsalomon@google.com6e4e6502013-02-25 20:12:45 +0000540 if (!insideGeoPush &&
541 !unreleasedVertexSpace &&
542 !unreleasedIndexSpace &&
543 !targetHasReservedGeom &&
544 this->geometryHints(&vcount, &icount)) {
bsalomon@google.com97805382012-03-13 14:32:07 +0000545
bsalomon@google.com6e4e6502013-02-25 20:12:45 +0000546 this->flush();
bsalomon@google.com97805382012-03-13 14:32:07 +0000547 }
548}
549
jvanverth@google.comb75b0a02013-02-05 20:33:30 +0000550bool GrInOrderDrawBuffer::geometryHints(int* vertexCount,
bsalomon@google.com1c13c962011-02-14 16:51:21 +0000551 int* indexCount) const {
552 // we will recommend a flush if the data could fit in a single
553 // preallocated buffer but none are left and it can't fit
554 // in the current buffer (which may not be prealloced).
reed@google.comac10a2d2010-12-22 21:39:39 +0000555 bool flush = false;
556 if (NULL != indexCount) {
bsalomon@google.com1c13c962011-02-14 16:51:21 +0000557 int32_t currIndices = fIndexPool.currentBufferIndices();
558 if (*indexCount > currIndices &&
559 (!fIndexPool.preallocatedBuffersRemaining() &&
560 *indexCount <= fIndexPool.preallocatedBufferIndices())) {
561
562 flush = true;
563 }
564 *indexCount = currIndices;
reed@google.comac10a2d2010-12-22 21:39:39 +0000565 }
566 if (NULL != vertexCount) {
jvanverth@google.comb75b0a02013-02-05 20:33:30 +0000567 size_t vertexSize = this->getDrawState().getVertexSize();
jvanverth@google.coma6338982013-01-31 21:34:25 +0000568 int32_t currVertices = fVertexPool.currentBufferVertices(vertexSize);
bsalomon@google.com1c13c962011-02-14 16:51:21 +0000569 if (*vertexCount > currVertices &&
570 (!fVertexPool.preallocatedBuffersRemaining() &&
jvanverth@google.coma6338982013-01-31 21:34:25 +0000571 *vertexCount <= fVertexPool.preallocatedBufferVertices(vertexSize))) {
reed@google.comac10a2d2010-12-22 21:39:39 +0000572
bsalomon@google.com1c13c962011-02-14 16:51:21 +0000573 flush = true;
reed@google.comac10a2d2010-12-22 21:39:39 +0000574 }
bsalomon@google.com1c13c962011-02-14 16:51:21 +0000575 *vertexCount = currVertices;
reed@google.comac10a2d2010-12-22 21:39:39 +0000576 }
577 return flush;
578}
579
jvanverth@google.coma6338982013-01-31 21:34:25 +0000580bool GrInOrderDrawBuffer::onReserveVertexSpace(size_t vertexSize,
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000581 int vertexCount,
582 void** vertices) {
583 GeometryPoolState& poolState = fGeoPoolStateStack.back();
584 GrAssert(vertexCount > 0);
585 GrAssert(NULL != vertices);
586 GrAssert(0 == poolState.fUsedPoolVertexBytes);
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000587
jvanverth@google.coma6338982013-01-31 21:34:25 +0000588 *vertices = fVertexPool.makeSpace(vertexSize,
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000589 vertexCount,
590 &poolState.fPoolVertexBuffer,
591 &poolState.fPoolStartVertex);
592 return NULL != *vertices;
593}
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000594
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000595bool GrInOrderDrawBuffer::onReserveIndexSpace(int indexCount, void** indices) {
596 GeometryPoolState& poolState = fGeoPoolStateStack.back();
597 GrAssert(indexCount > 0);
598 GrAssert(NULL != indices);
599 GrAssert(0 == poolState.fUsedPoolIndexBytes);
bsalomon@google.com1c13c962011-02-14 16:51:21 +0000600
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000601 *indices = fIndexPool.makeSpace(indexCount,
602 &poolState.fPoolIndexBuffer,
603 &poolState.fPoolStartIndex);
604 return NULL != *indices;
reed@google.comac10a2d2010-12-22 21:39:39 +0000605}
606
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000607void GrInOrderDrawBuffer::releaseReservedVertexSpace() {
608 GeometryPoolState& poolState = fGeoPoolStateStack.back();
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000609 const GeometrySrcState& geoSrc = this->getGeomSrc();
bsalomon@google.comd57d71a2012-08-16 16:26:33 +0000610
611 // If we get a release vertex space call then our current source should either be reserved
612 // or array (which we copied into reserved space).
613 GrAssert(kReserved_GeometrySrcType == geoSrc.fVertexSrc ||
614 kArray_GeometrySrcType == geoSrc.fVertexSrc);
bsalomon@google.com3f5a95e2012-03-08 16:41:42 +0000615
616 // When the caller reserved vertex buffer space we gave it back a pointer
617 // provided by the vertex buffer pool. At each draw we tracked the largest
618 // offset into the pool's pointer that was referenced. Now we return to the
619 // pool any portion at the tail of the allocation that no draw referenced.
jvanverth@google.comb75b0a02013-02-05 20:33:30 +0000620 size_t reservedVertexBytes = geoSrc.fVertexSize * geoSrc.fVertexCount;
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000621 fVertexPool.putBack(reservedVertexBytes -
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000622 poolState.fUsedPoolVertexBytes);
623 poolState.fUsedPoolVertexBytes = 0;
bsalomon@google.com3f5a95e2012-03-08 16:41:42 +0000624 poolState.fPoolVertexBuffer = NULL;
625 poolState.fPoolStartVertex = 0;
bsalomon@google.com1c13c962011-02-14 16:51:21 +0000626}
627
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000628void GrInOrderDrawBuffer::releaseReservedIndexSpace() {
629 GeometryPoolState& poolState = fGeoPoolStateStack.back();
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000630 const GeometrySrcState& geoSrc = this->getGeomSrc();
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000631
bsalomon@google.comd57d71a2012-08-16 16:26:33 +0000632 // If we get a release index space call then our current source should either be reserved
633 // or array (which we copied into reserved space).
634 GrAssert(kReserved_GeometrySrcType == geoSrc.fIndexSrc ||
635 kArray_GeometrySrcType == geoSrc.fIndexSrc);
bsalomon@google.com3f5a95e2012-03-08 16:41:42 +0000636
637 // Similar to releaseReservedVertexSpace we return any unused portion at
638 // the tail
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000639 size_t reservedIndexBytes = sizeof(uint16_t) * geoSrc.fIndexCount;
640 fIndexPool.putBack(reservedIndexBytes - poolState.fUsedPoolIndexBytes);
641 poolState.fUsedPoolIndexBytes = 0;
bsalomon@google.com3f5a95e2012-03-08 16:41:42 +0000642 poolState.fPoolIndexBuffer = NULL;
643 poolState.fPoolStartIndex = 0;
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000644}
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000645
bsalomon@google.combcdbbe62011-04-12 15:40:00 +0000646void GrInOrderDrawBuffer::onSetVertexSourceToArray(const void* vertexArray,
647 int vertexCount) {
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000648
649 GeometryPoolState& poolState = fGeoPoolStateStack.back();
650 GrAssert(0 == poolState.fUsedPoolVertexBytes);
bsalomon@google.com1c13c962011-02-14 16:51:21 +0000651#if GR_DEBUG
652 bool success =
653#endif
jvanverth@google.comb75b0a02013-02-05 20:33:30 +0000654 fVertexPool.appendVertices(this->getVertexSize(),
bsalomon@google.com1c13c962011-02-14 16:51:21 +0000655 vertexCount,
656 vertexArray,
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000657 &poolState.fPoolVertexBuffer,
658 &poolState.fPoolStartVertex);
bsalomon@google.com1c13c962011-02-14 16:51:21 +0000659 GR_DEBUGASSERT(success);
660}
661
bsalomon@google.combcdbbe62011-04-12 15:40:00 +0000662void GrInOrderDrawBuffer::onSetIndexSourceToArray(const void* indexArray,
663 int indexCount) {
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000664 GeometryPoolState& poolState = fGeoPoolStateStack.back();
665 GrAssert(0 == poolState.fUsedPoolIndexBytes);
bsalomon@google.com1c13c962011-02-14 16:51:21 +0000666#if GR_DEBUG
667 bool success =
668#endif
669 fIndexPool.appendIndices(indexCount,
670 indexArray,
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000671 &poolState.fPoolIndexBuffer,
672 &poolState.fPoolStartIndex);
bsalomon@google.com1c13c962011-02-14 16:51:21 +0000673 GR_DEBUGASSERT(success);
reed@google.comac10a2d2010-12-22 21:39:39 +0000674}
675
bsalomon@google.com3f5a95e2012-03-08 16:41:42 +0000676void GrInOrderDrawBuffer::releaseVertexArray() {
677 // When the client provides an array as the vertex source we handled it
678 // by copying their array into reserved space.
679 this->GrInOrderDrawBuffer::releaseReservedVertexSpace();
680}
681
682void GrInOrderDrawBuffer::releaseIndexArray() {
683 // When the client provides an array as the index source we handled it
684 // by copying their array into reserved space.
685 this->GrInOrderDrawBuffer::releaseReservedIndexSpace();
686}
687
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000688void GrInOrderDrawBuffer::geometrySourceWillPush() {
689 GeometryPoolState& poolState = fGeoPoolStateStack.push_back();
690 poolState.fUsedPoolVertexBytes = 0;
691 poolState.fUsedPoolIndexBytes = 0;
692#if GR_DEBUG
693 poolState.fPoolVertexBuffer = (GrVertexBuffer*)~0;
694 poolState.fPoolStartVertex = ~0;
695 poolState.fPoolIndexBuffer = (GrIndexBuffer*)~0;
696 poolState.fPoolStartIndex = ~0;
697#endif
698}
699
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000700void GrInOrderDrawBuffer::geometrySourceWillPop(
701 const GeometrySrcState& restoredState) {
702 GrAssert(fGeoPoolStateStack.count() > 1);
703 fGeoPoolStateStack.pop_back();
704 GeometryPoolState& poolState = fGeoPoolStateStack.back();
705 // we have to assume that any slack we had in our vertex/index data
706 // is now unreleasable because data may have been appended later in the
707 // pool.
708 if (kReserved_GeometrySrcType == restoredState.fVertexSrc ||
709 kArray_GeometrySrcType == restoredState.fVertexSrc) {
jvanverth@google.comb75b0a02013-02-05 20:33:30 +0000710 poolState.fUsedPoolVertexBytes = restoredState.fVertexSize * restoredState.fVertexCount;
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000711 }
712 if (kReserved_GeometrySrcType == restoredState.fIndexSrc ||
713 kArray_GeometrySrcType == restoredState.fIndexSrc) {
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000714 poolState.fUsedPoolIndexBytes = sizeof(uint16_t) *
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000715 restoredState.fIndexCount;
716 }
717}
718
bsalomon@google.com86afc2a2011-02-16 16:12:19 +0000719bool GrInOrderDrawBuffer::needsNewState() const {
bsalomon@google.comca432082013-01-23 19:53:46 +0000720 return fStates.empty() || !fStates.back().isEqual(this->getDrawState());
reed@google.comac10a2d2010-12-22 21:39:39 +0000721}
722
bsalomon@google.com86afc2a2011-02-16 16:12:19 +0000723bool GrInOrderDrawBuffer::needsNewClip() const {
bsalomon@google.com358e4272013-01-10 14:40:28 +0000724 GrAssert(fClips.count() == fClipOrigins.count());
725 if (this->getDrawState().isClipState()) {
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000726 if (fClipSet &&
bsalomon@google.com358e4272013-01-10 14:40:28 +0000727 (fClips.empty() ||
bsalomon@google.com02ddc8b2013-01-28 15:35:28 +0000728 fClips.back() != *this->getClip()->fClipStack ||
729 fClipOrigins.back() != this->getClip()->fOrigin)) {
bsalomon@google.com86afc2a2011-02-16 16:12:19 +0000730 return true;
731 }
reed@google.comac10a2d2010-12-22 21:39:39 +0000732 }
733 return false;
734}
bsalomon@google.comd302f142011-03-03 13:54:13 +0000735
bsalomon@google.coma4f6b102012-06-26 21:04:22 +0000736void GrInOrderDrawBuffer::recordClip() {
bsalomon@google.com02ddc8b2013-01-28 15:35:28 +0000737 fClips.push_back() = *this->getClip()->fClipStack;
738 fClipOrigins.push_back() = this->getClip()->fOrigin;
bsalomon@google.com86afc2a2011-02-16 16:12:19 +0000739 fClipSet = false;
bsalomon@google.coma4f6b102012-06-26 21:04:22 +0000740 fCmds.push_back(kSetClip_Cmd);
741}
742
bsalomon@google.coma4f6b102012-06-26 21:04:22 +0000743void GrInOrderDrawBuffer::recordState() {
bsalomon@google.comca432082013-01-23 19:53:46 +0000744 fStates.push_back().saveFrom(this->getDrawState());
bsalomon@google.coma4f6b102012-06-26 21:04:22 +0000745 fCmds.push_back(kSetState_Cmd);
746}
747
bsalomon@google.com74749cd2013-01-30 16:12:41 +0000748GrInOrderDrawBuffer::DrawRecord* GrInOrderDrawBuffer::recordDraw(const DrawInfo& info) {
bsalomon@google.comd62e88e2013-02-01 14:19:27 +0000749 fCmds.push_back(kDraw_Cmd);
750 return &fDraws.push_back(info);
bsalomon@google.com74749cd2013-01-30 16:12:41 +0000751}
752
bsalomon@google.comded4f4b2012-06-28 18:48:06 +0000753GrInOrderDrawBuffer::StencilPath* GrInOrderDrawBuffer::recordStencilPath() {
754 fCmds.push_back(kStencilPath_Cmd);
755 return &fStencilPaths.push_back();
756}
757
bsalomon@google.coma4f6b102012-06-26 21:04:22 +0000758GrInOrderDrawBuffer::Clear* GrInOrderDrawBuffer::recordClear() {
759 fCmds.push_back(kClear_Cmd);
760 return &fClears.push_back();
reed@google.comac10a2d2010-12-22 21:39:39 +0000761}
bsalomon@google.comd302f142011-03-03 13:54:13 +0000762
robertphillips@google.combeb1af72012-07-26 18:52:16 +0000763void GrInOrderDrawBuffer::clipWillBeSet(const GrClipData* newClipData) {
764 INHERITED::clipWillBeSet(newClipData);
bsalomon@google.com86afc2a2011-02-16 16:12:19 +0000765 fClipSet = true;
bsalomon@google.comd62e88e2013-02-01 14:19:27 +0000766 fClipProxyState = kUnknown_ClipProxyState;
bsalomon@google.com86afc2a2011-02-16 16:12:19 +0000767}