blob: 31b1a57c1f503fc193ee65fd380b6885a7543984 [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
jvanverth@google.com9b855c72013-03-01 18:21:22 +000081 GrAttribBindings bindings = GrDrawState::kDefault_AttribBindings;
bsalomon@google.comd62e88e2013-02-01 14:19:27 +000082 GrDrawState::AutoColorRestore acr;
jvanverth@google.com9b855c72013-03-01 18:21:22 +000083
84 GrDrawState* drawState = this->drawState();
85
86 GrColor color = drawState->getColor();
87 GrVertexAttribArray<3> attribs;
88 size_t currentOffset = 0;
89 int colorOffset = -1, texOffset = -1;
90
91 // set position attrib
92 drawState->setAttribIndex(GrDrawState::kPosition_AttribIndex, attribs.count());
jvanverth@google.com3b0d6312013-03-01 20:30:01 +000093 GrVertexAttrib currAttrib = {kVec2f_GrVertexAttribType, currentOffset};
94 attribs.push_back(currAttrib);
jvanverth@google.com9b855c72013-03-01 18:21:22 +000095 currentOffset += sizeof(GrPoint);
bsalomon@google.com86afc2a2011-02-16 16:12:19 +000096
bsalomon@google.comd62e88e2013-02-01 14:19:27 +000097 // Using per-vertex colors allows batching across colors. (A lot of rects in a row differing
98 // only in color is a common occurrence in tables). However, having per-vertex colors disables
99 // blending optimizations because we don't know if the color will be solid or not. These
100 // optimizations help determine whether coverage and color can be blended correctly when
101 // dual-source blending isn't available. This comes into play when there is coverage. If colors
102 // were a stage it could take a hint that every vertex's color will be opaque.
103 if (this->getCaps().dualSourceBlendingSupport() ||
jvanverth@google.com9b855c72013-03-01 18:21:22 +0000104 drawState->hasSolidCoverage(drawState->getAttribBindings())) {
105 bindings |= GrDrawState::kColor_AttribBindingsBit;
106 drawState->setAttribIndex(GrDrawState::kColor_AttribIndex, attribs.count());
jvanverth@google.com3b0d6312013-03-01 20:30:01 +0000107 currAttrib.set(kVec4ub_GrVertexAttribType, currentOffset);
108 attribs.push_back(currAttrib);
jvanverth@google.com9b855c72013-03-01 18:21:22 +0000109 colorOffset = currentOffset;
110 currentOffset += sizeof(GrColor);
bsalomon@google.comd62e88e2013-02-01 14:19:27 +0000111 // We set the draw state's color to white here. This is done so that any batching performed
112 // in our subclass's onDraw() won't get a false from GrDrawState::op== due to a color
113 // mismatch. TODO: Once vertex layout is owned by GrDrawState it should skip comparing the
114 // 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 +0000115 acr.set(drawState, 0xFFFFFFFF);
bsalomon@google.com86afc2a2011-02-16 16:12:19 +0000116 }
bsalomon@google.com86afc2a2011-02-16 16:12:19 +0000117
bsalomon@google.comd62e88e2013-02-01 14:19:27 +0000118 uint32_t explicitCoordMask = 0;
jvanverth@google.com39768252013-02-14 15:25:44 +0000119 if (NULL != srcRect) {
jvanverth@google.com9b855c72013-03-01 18:21:22 +0000120 bindings |= GrDrawState::ExplicitTexCoordAttribBindingsBit(stage);
121 drawState->setAttribIndex(GrDrawState::kTexCoord_AttribIndex, attribs.count());
jvanverth@google.com3b0d6312013-03-01 20:30:01 +0000122 currAttrib.set(kVec2f_GrVertexAttribType, currentOffset);
123 attribs.push_back(currAttrib);
jvanverth@google.com9b855c72013-03-01 18:21:22 +0000124 texOffset = currentOffset;
125 currentOffset += sizeof(GrPoint);
jvanverth@google.com39768252013-02-14 15:25:44 +0000126 explicitCoordMask = (1 << stage);
bsalomon@google.comd62e88e2013-02-01 14:19:27 +0000127 }
128
jvanverth@google.com9b855c72013-03-01 18:21:22 +0000129 drawState->setVertexAttribs(attribs.begin(), attribs.count());
130 drawState->setAttribBindings(bindings);
jvanverth@google.comb75b0a02013-02-05 20:33:30 +0000131 AutoReleaseGeometry geo(this, 4, 0);
bsalomon@google.comd62e88e2013-02-01 14:19:27 +0000132 if (!geo.succeeded()) {
133 GrPrintf("Failed to get space for vertices!\n");
bsalomon@google.com934c5702012-03-20 21:17:58 +0000134 return;
135 }
136
bsalomon@google.comd62e88e2013-02-01 14:19:27 +0000137 // Go to device coords to allow batching across matrix changes
138 SkMatrix combinedMatrix;
139 if (NULL != matrix) {
140 combinedMatrix = *matrix;
141 } else {
142 combinedMatrix.reset();
143 }
jvanverth@google.com9b855c72013-03-01 18:21:22 +0000144 combinedMatrix.postConcat(drawState->getViewMatrix());
jvanverth@google.com39768252013-02-14 15:25:44 +0000145 // 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 +0000146 // modify that stage's matrix. Otherwise if the effect is generating its source rect from
147 // the vertex positions then we have to account for the view matrix change.
jvanverth@google.com9b855c72013-03-01 18:21:22 +0000148 GrDrawState::AutoDeviceCoordDraw adcd(drawState, explicitCoordMask);
bsalomon@google.comd62e88e2013-02-01 14:19:27 +0000149 if (!adcd.succeeded()) {
150 return;
151 }
152
jvanverth@google.com9b855c72013-03-01 18:21:22 +0000153 size_t vsize = drawState->getVertexSize();
154 GrAssert(vsize == currentOffset);
bsalomon@google.comd62e88e2013-02-01 14:19:27 +0000155
156 geo.positions()->setRectFan(rect.fLeft, rect.fTop, rect.fRight, rect.fBottom, vsize);
157 combinedMatrix.mapPointsWithStride(geo.positions(), vsize, 4);
158
159 SkRect devBounds;
160 // since we already computed the dev verts, set the bounds hint. This will help us avoid
161 // unnecessary clipping in our onDraw().
162 get_vertex_bounds(geo.vertices(), vsize, 4, &devBounds);
163
jvanverth@google.com9b855c72013-03-01 18:21:22 +0000164 if (texOffset >= 0) {
165 GrAssert(explicitCoordMask != 0);
166 GrPoint* coords = GrTCast<GrPoint*>(GrTCast<intptr_t>(geo.vertices()) +
167 texOffset);
168 coords->setRectFan(srcRect->fLeft, srcRect->fTop,
169 srcRect->fRight, srcRect->fBottom,
170 vsize);
171 if (NULL != srcMatrix) {
172 srcMatrix->mapPointsWithStride(coords, vsize, 4);
bsalomon@google.comd62e88e2013-02-01 14:19:27 +0000173 }
174 }
175
176 if (colorOffset >= 0) {
177 GrColor* vertColor = GrTCast<GrColor*>(GrTCast<intptr_t>(geo.vertices()) + colorOffset);
178 for (int i = 0; i < 4; ++i) {
179 *vertColor = color;
180 vertColor = (GrColor*) ((intptr_t) vertColor + vsize);
181 }
182 }
183
bsalomon@google.com6e4e6502013-02-25 20:12:45 +0000184 this->setIndexSourceToBuffer(this->getContext()->getQuadIndexBuffer());
bsalomon@google.comd62e88e2013-02-01 14:19:27 +0000185 this->drawIndexedInstances(kTriangles_GrPrimitiveType, 1, 4, 6, &devBounds);
jvanverth@google.com9b855c72013-03-01 18:21:22 +0000186
187 // to ensure that stashing the drawState ptr is valid
188 GrAssert(this->drawState() == drawState);
bsalomon@google.comd62e88e2013-02-01 14:19:27 +0000189}
190
191bool GrInOrderDrawBuffer::quickInsideClip(const SkRect& devBounds) {
192 if (!this->getDrawState().isClipState()) {
193 return true;
194 }
195 if (kUnknown_ClipProxyState == fClipProxyState) {
196 SkIRect rect;
197 bool iior;
198 this->getClip()->getConservativeBounds(this->getDrawState().getRenderTarget(), &rect, &iior);
199 if (iior) {
200 // The clip is a rect. We will remember that in fProxyClip. It is common for an edge (or
201 // all edges) of the clip to be at the edge of the RT. However, we get that clipping for
202 // free via the viewport. We don't want to think that clipping must be enabled in this
203 // case. So we extend the clip outward from the edge to avoid these false negatives.
204 fClipProxyState = kValid_ClipProxyState;
205 fClipProxy = SkRect::MakeFromIRect(rect);
206
207 if (fClipProxy.fLeft <= 0) {
208 fClipProxy.fLeft = SK_ScalarMin;
209 }
210 if (fClipProxy.fTop <= 0) {
211 fClipProxy.fTop = SK_ScalarMin;
212 }
213 if (fClipProxy.fRight >= this->getDrawState().getRenderTarget()->width()) {
214 fClipProxy.fRight = SK_ScalarMax;
215 }
216 if (fClipProxy.fBottom >= this->getDrawState().getRenderTarget()->height()) {
217 fClipProxy.fBottom = SK_ScalarMax;
218 }
219 } else {
220 fClipProxyState = kInvalid_ClipProxyState;
221 }
222 }
223 if (kValid_ClipProxyState == fClipProxyState) {
224 return fClipProxy.contains(devBounds);
225 }
226 SkPoint originOffset = {SkIntToScalar(this->getClip()->fOrigin.fX),
227 SkIntToScalar(this->getClip()->fOrigin.fY)};
228 SkRect clipSpaceBounds = devBounds;
229 clipSpaceBounds.offset(originOffset);
230 return this->getClip()->fClipStack->quickContains(clipSpaceBounds);
231}
232
233int GrInOrderDrawBuffer::concatInstancedDraw(const DrawInfo& info) {
234 GrAssert(info.isInstanced());
235
bsalomon@google.com934c5702012-03-20 21:17:58 +0000236 const GeometrySrcState& geomSrc = this->getGeomSrc();
jvanverth@google.comb75b0a02013-02-05 20:33:30 +0000237 const GrDrawState& drawState = this->getDrawState();
bsalomon@google.com934c5702012-03-20 21:17:58 +0000238
bsalomon@google.comd62e88e2013-02-01 14:19:27 +0000239 // we only attempt to concat the case when reserved verts are used with a client-specified index
240 // buffer. To make this work with client-specified VBs we'd need to know if the VB was updated
241 // between draws.
242 if (kReserved_GeometrySrcType != geomSrc.fVertexSrc ||
243 kBuffer_GeometrySrcType != geomSrc.fIndexSrc) {
244 return 0;
bsalomon@google.com934c5702012-03-20 21:17:58 +0000245 }
bsalomon@google.comd62e88e2013-02-01 14:19:27 +0000246 // Check if there is a draw info that is compatible that uses the same VB from the pool and
247 // the same IB
248 if (kDraw_Cmd != fCmds.back()) {
249 return 0;
250 }
251
252 DrawRecord* draw = &fDraws.back();
253 GeometryPoolState& poolState = fGeoPoolStateStack.back();
254 const GrVertexBuffer* vertexBuffer = poolState.fPoolVertexBuffer;
255
256 if (!draw->isInstanced() ||
257 draw->verticesPerInstance() != info.verticesPerInstance() ||
258 draw->indicesPerInstance() != info.indicesPerInstance() ||
259 draw->fVertexBuffer != vertexBuffer ||
jvanverth@google.comb75b0a02013-02-05 20:33:30 +0000260 draw->fIndexBuffer != geomSrc.fIndexBuffer) {
bsalomon@google.comd62e88e2013-02-01 14:19:27 +0000261 return 0;
262 }
263 // info does not yet account for the offset from the start of the pool's VB while the previous
264 // draw record does.
265 int adjustedStartVertex = poolState.fPoolStartVertex + info.startVertex();
266 if (draw->startVertex() + draw->vertexCount() != adjustedStartVertex) {
267 return 0;
268 }
269
270 GrAssert(poolState.fPoolStartVertex == draw->startVertex() + draw->vertexCount());
271
272 // how many instances can be concat'ed onto draw given the size of the index buffer
273 int instancesToConcat = this->indexCountInCurrentSource() / info.indicesPerInstance();
274 instancesToConcat -= draw->instanceCount();
275 instancesToConcat = GrMin(instancesToConcat, info.instanceCount());
276
277 // update the amount of reserved vertex data actually referenced in draws
skia.committer@gmail.comae683922013-02-06 07:01:54 +0000278 size_t vertexBytes = instancesToConcat * info.verticesPerInstance() *
jvanverth@google.comb75b0a02013-02-05 20:33:30 +0000279 drawState.getVertexSize();
bsalomon@google.comd62e88e2013-02-01 14:19:27 +0000280 poolState.fUsedPoolVertexBytes = GrMax(poolState.fUsedPoolVertexBytes, vertexBytes);
281
282 draw->adjustInstanceCount(instancesToConcat);
283 return instancesToConcat;
bsalomon@google.com934c5702012-03-20 21:17:58 +0000284}
285
bsalomon@google.comd62e88e2013-02-01 14:19:27 +0000286class AutoClipReenable {
287public:
288 AutoClipReenable() : fDrawState(NULL) {}
289 ~AutoClipReenable() {
290 if (NULL != fDrawState) {
291 fDrawState->enableState(GrDrawState::kClip_StateBit);
292 }
293 }
294 void set(GrDrawState* drawState) {
295 if (drawState->isClipState()) {
296 fDrawState = drawState;
297 drawState->disableState(GrDrawState::kClip_StateBit);
298 }
299 }
300private:
301 GrDrawState* fDrawState;
302};
303
bsalomon@google.com74749cd2013-01-30 16:12:41 +0000304void GrInOrderDrawBuffer::onDraw(const DrawInfo& info) {
reed@google.comac10a2d2010-12-22 21:39:39 +0000305
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000306 GeometryPoolState& poolState = fGeoPoolStateStack.back();
jvanverth@google.comb75b0a02013-02-05 20:33:30 +0000307 const GrDrawState& drawState = this->getDrawState();
bsalomon@google.comd62e88e2013-02-01 14:19:27 +0000308 AutoClipReenable acr;
309
jvanverth@google.comb75b0a02013-02-05 20:33:30 +0000310 if (drawState.isClipState() &&
bsalomon@google.comd62e88e2013-02-01 14:19:27 +0000311 NULL != info.getDevBounds() &&
312 this->quickInsideClip(*info.getDevBounds())) {
313 acr.set(this->drawState());
314 }
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000315
bsalomon@google.coma4f6b102012-06-26 21:04:22 +0000316 if (this->needsNewClip()) {
317 this->recordClip();
318 }
319 if (this->needsNewState()) {
320 this->recordState();
bsalomon@google.com86afc2a2011-02-16 16:12:19 +0000321 }
322
bsalomon@google.comd62e88e2013-02-01 14:19:27 +0000323 DrawRecord* draw;
324 if (info.isInstanced()) {
325 int instancesConcated = this->concatInstancedDraw(info);
326 if (info.instanceCount() > instancesConcated) {
327 draw = this->recordDraw(info);
328 draw->adjustInstanceCount(-instancesConcated);
329 } else {
330 return;
331 }
332 } else {
333 draw = this->recordDraw(info);
334 }
bsalomon@google.com74749cd2013-01-30 16:12:41 +0000335
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000336 switch (this->getGeomSrc().fVertexSrc) {
bsalomon@google.com74749cd2013-01-30 16:12:41 +0000337 case kBuffer_GeometrySrcType:
338 draw->fVertexBuffer = this->getGeomSrc().fVertexBuffer;
339 break;
340 case kReserved_GeometrySrcType: // fallthrough
341 case kArray_GeometrySrcType: {
skia.committer@gmail.comae683922013-02-06 07:01:54 +0000342 size_t vertexBytes = (info.vertexCount() + info.startVertex()) *
jvanverth@google.comb75b0a02013-02-05 20:33:30 +0000343 drawState.getVertexSize();
bsalomon@google.com74749cd2013-01-30 16:12:41 +0000344 poolState.fUsedPoolVertexBytes = GrMax(poolState.fUsedPoolVertexBytes, vertexBytes);
345 draw->fVertexBuffer = poolState.fPoolVertexBuffer;
bsalomon@google.comd62e88e2013-02-01 14:19:27 +0000346 draw->adjustStartVertex(poolState.fPoolStartVertex);
bsalomon@google.com74749cd2013-01-30 16:12:41 +0000347 break;
348 }
349 default:
350 GrCrash("unknown geom src type");
reed@google.comac10a2d2010-12-22 21:39:39 +0000351 }
bsalomon@google.coma4f6b102012-06-26 21:04:22 +0000352 draw->fVertexBuffer->ref();
reed@google.comac10a2d2010-12-22 21:39:39 +0000353
bsalomon@google.com74749cd2013-01-30 16:12:41 +0000354 if (info.isIndexed()) {
355 switch (this->getGeomSrc().fIndexSrc) {
356 case kBuffer_GeometrySrcType:
357 draw->fIndexBuffer = this->getGeomSrc().fIndexBuffer;
358 break;
359 case kReserved_GeometrySrcType: // fallthrough
360 case kArray_GeometrySrcType: {
361 size_t indexBytes = (info.indexCount() + info.startIndex()) * sizeof(uint16_t);
362 poolState.fUsedPoolIndexBytes = GrMax(poolState.fUsedPoolIndexBytes, indexBytes);
363 draw->fIndexBuffer = poolState.fPoolIndexBuffer;
bsalomon@google.comd62e88e2013-02-01 14:19:27 +0000364 draw->adjustStartIndex(poolState.fPoolStartIndex);
bsalomon@google.com74749cd2013-01-30 16:12:41 +0000365 break;
366 }
367 default:
368 GrCrash("unknown geom src type");
369 }
370 draw->fIndexBuffer->ref();
371 } else {
372 draw->fIndexBuffer = NULL;
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000373 }
reed@google.comac10a2d2010-12-22 21:39:39 +0000374}
375
sugoi@google.com5f74cf82012-12-17 21:16:45 +0000376GrInOrderDrawBuffer::StencilPath::StencilPath() : fStroke(SkStrokeRec::kFill_InitStyle) {}
377
378void GrInOrderDrawBuffer::onStencilPath(const GrPath* path, const SkStrokeRec& stroke,
sugoi@google.com12b4e272012-12-06 20:13:11 +0000379 SkPath::FillType fill) {
bsalomon@google.comded4f4b2012-06-28 18:48:06 +0000380 if (this->needsNewClip()) {
381 this->recordClip();
382 }
383 // Only compare the subset of GrDrawState relevant to path stenciling?
384 if (this->needsNewState()) {
385 this->recordState();
386 }
387 StencilPath* sp = this->recordStencilPath();
388 sp->fPath.reset(path);
389 path->ref();
390 sp->fFill = fill;
sugoi@google.com12b4e272012-12-06 20:13:11 +0000391 sp->fStroke = stroke;
bsalomon@google.com64aef2b2012-06-11 15:36:13 +0000392}
393
bsalomon@google.comd62e88e2013-02-01 14:19:27 +0000394void GrInOrderDrawBuffer::clear(const GrIRect* rect, GrColor color, GrRenderTarget* renderTarget) {
bsalomon@google.com6aa25c32011-04-27 19:55:29 +0000395 GrIRect r;
bsalomon@google.com1b3ce472012-08-17 13:43:08 +0000396 if (NULL == renderTarget) {
397 renderTarget = this->drawState()->getRenderTarget();
398 GrAssert(NULL != renderTarget);
399 }
bsalomon@google.com6aa25c32011-04-27 19:55:29 +0000400 if (NULL == rect) {
401 // We could do something smart and remove previous draws and clears to
402 // the current render target. If we get that smart we have to make sure
403 // those draws aren't read before this clear (render-to-texture).
bsalomon@google.com1b3ce472012-08-17 13:43:08 +0000404 r.setLTRB(0, 0, renderTarget->width(), renderTarget->height());
bsalomon@google.com6aa25c32011-04-27 19:55:29 +0000405 rect = &r;
406 }
bsalomon@google.coma4f6b102012-06-26 21:04:22 +0000407 Clear* clr = this->recordClear();
408 clr->fColor = color;
409 clr->fRect = *rect;
410 clr->fRenderTarget = renderTarget;
bsalomon@google.com1b3ce472012-08-17 13:43:08 +0000411 renderTarget->ref();
bsalomon@google.com0b335c12011-04-25 19:17:44 +0000412}
413
reed@google.comac10a2d2010-12-22 21:39:39 +0000414void GrInOrderDrawBuffer::reset() {
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000415 GrAssert(1 == fGeoPoolStateStack.count());
416 this->resetVertexSource();
417 this->resetIndexSource();
bsalomon@google.com86afc2a2011-02-16 16:12:19 +0000418 int numDraws = fDraws.count();
419 for (int d = 0; d < numDraws; ++d) {
420 // we always have a VB, but not always an IB
421 GrAssert(NULL != fDraws[d].fVertexBuffer);
422 fDraws[d].fVertexBuffer->unref();
423 GrSafeUnref(fDraws[d].fIndexBuffer);
424 }
bsalomon@google.coma4f6b102012-06-26 21:04:22 +0000425 fCmds.reset();
reed@google.comac10a2d2010-12-22 21:39:39 +0000426 fDraws.reset();
bsalomon@google.comded4f4b2012-06-28 18:48:06 +0000427 fStencilPaths.reset();
reed@google.comac10a2d2010-12-22 21:39:39 +0000428 fStates.reset();
bsalomon@google.com0b335c12011-04-25 19:17:44 +0000429 fClears.reset();
bsalomon@google.com1c13c962011-02-14 16:51:21 +0000430 fVertexPool.reset();
431 fIndexPool.reset();
reed@google.comac10a2d2010-12-22 21:39:39 +0000432 fClips.reset();
robertphillips@google.combeb1af72012-07-26 18:52:16 +0000433 fClipOrigins.reset();
bsalomon@google.coma4f6b102012-06-26 21:04:22 +0000434 fClipSet = true;
reed@google.comac10a2d2010-12-22 21:39:39 +0000435}
436
bsalomon@google.com6e4e6502013-02-25 20:12:45 +0000437bool GrInOrderDrawBuffer::flush() {
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000438 GrAssert(kReserved_GeometrySrcType != this->getGeomSrc().fVertexSrc);
439 GrAssert(kReserved_GeometrySrcType != this->getGeomSrc().fIndexSrc);
bsalomon@google.com3f5a95e2012-03-08 16:41:42 +0000440
bsalomon@google.coma4f6b102012-06-26 21:04:22 +0000441 int numCmds = fCmds.count();
bsalomon@google.com358e4272013-01-10 14:40:28 +0000442 if (0 == numCmds) {
bsalomon@google.coma4f6b102012-06-26 21:04:22 +0000443 return false;
reed@google.comac10a2d2010-12-22 21:39:39 +0000444 }
bsalomon@google.com6e4e6502013-02-25 20:12:45 +0000445 GrAssert(!fFlushing);
446
447 GrAutoTRestore<bool> flushRestore(&fFlushing);
448 fFlushing = true;
reed@google.comac10a2d2010-12-22 21:39:39 +0000449
bsalomon@google.com1c13c962011-02-14 16:51:21 +0000450 fVertexPool.unlock();
451 fIndexPool.unlock();
reed@google.comac10a2d2010-12-22 21:39:39 +0000452
bsalomon@google.com6e4e6502013-02-25 20:12:45 +0000453 GrDrawTarget::AutoClipRestore acr(fDstGpu);
454 AutoGeometryAndStatePush agasp(fDstGpu, kPreserve_ASRInit);
bsalomon@google.comca432082013-01-23 19:53:46 +0000455
456 GrDrawState playbackState;
bsalomon@google.com6e4e6502013-02-25 20:12:45 +0000457 GrDrawState* prevDrawState = fDstGpu->drawState();
bsalomon@google.coma5d056a2012-03-27 15:59:58 +0000458 prevDrawState->ref();
bsalomon@google.com6e4e6502013-02-25 20:12:45 +0000459 fDstGpu->setDrawState(&playbackState);
reed@google.comac10a2d2010-12-22 21:39:39 +0000460
robertphillips@google.combeb1af72012-07-26 18:52:16 +0000461 GrClipData clipData;
462
bsalomon@google.comded4f4b2012-06-28 18:48:06 +0000463 int currState = 0;
464 int currClip = 0;
465 int currClear = 0;
466 int currDraw = 0;
467 int currStencilPath = 0;
reed@google.comac10a2d2010-12-22 21:39:39 +0000468
bsalomon@google.coma4f6b102012-06-26 21:04:22 +0000469 for (int c = 0; c < numCmds; ++c) {
470 switch (fCmds[c]) {
471 case kDraw_Cmd: {
bsalomon@google.com74749cd2013-01-30 16:12:41 +0000472 const DrawRecord& draw = fDraws[currDraw];
bsalomon@google.com6e4e6502013-02-25 20:12:45 +0000473 fDstGpu->setVertexSourceToBuffer(draw.fVertexBuffer);
bsalomon@google.comd62e88e2013-02-01 14:19:27 +0000474 if (draw.isIndexed()) {
bsalomon@google.com6e4e6502013-02-25 20:12:45 +0000475 fDstGpu->setIndexSourceToBuffer(draw.fIndexBuffer);
bsalomon@google.coma4f6b102012-06-26 21:04:22 +0000476 }
bsalomon@google.com6e4e6502013-02-25 20:12:45 +0000477 fDstGpu->executeDraw(draw);
bsalomon@google.com0b335c12011-04-25 19:17:44 +0000478
bsalomon@google.coma4f6b102012-06-26 21:04:22 +0000479 ++currDraw;
480 break;
481 }
bsalomon@google.comded4f4b2012-06-28 18:48:06 +0000482 case kStencilPath_Cmd: {
483 const StencilPath& sp = fStencilPaths[currStencilPath];
bsalomon@google.com6e4e6502013-02-25 20:12:45 +0000484 fDstGpu->stencilPath(sp.fPath.get(), sp.fStroke, sp.fFill);
bsalomon@google.comded4f4b2012-06-28 18:48:06 +0000485 ++currStencilPath;
486 break;
487 }
bsalomon@google.coma4f6b102012-06-26 21:04:22 +0000488 case kSetState_Cmd:
bsalomon@google.comca432082013-01-23 19:53:46 +0000489 fStates[currState].restoreTo(&playbackState);
bsalomon@google.coma4f6b102012-06-26 21:04:22 +0000490 ++currState;
491 break;
492 case kSetClip_Cmd:
robertphillips@google.combeb1af72012-07-26 18:52:16 +0000493 clipData.fClipStack = &fClips[currClip];
494 clipData.fOrigin = fClipOrigins[currClip];
bsalomon@google.com6e4e6502013-02-25 20:12:45 +0000495 fDstGpu->setClip(&clipData);
bsalomon@google.coma4f6b102012-06-26 21:04:22 +0000496 ++currClip;
497 break;
498 case kClear_Cmd:
bsalomon@google.com6e4e6502013-02-25 20:12:45 +0000499 fDstGpu->clear(&fClears[currClear].fRect,
500 fClears[currClear].fColor,
501 fClears[currClear].fRenderTarget);
bsalomon@google.coma4f6b102012-06-26 21:04:22 +0000502 ++currClear;
503 break;
reed@google.comac10a2d2010-12-22 21:39:39 +0000504 }
505 }
bsalomon@google.coma4f6b102012-06-26 21:04:22 +0000506 // we should have consumed all the states, clips, etc.
507 GrAssert(fStates.count() == currState);
508 GrAssert(fClips.count() == currClip);
robertphillips@google.combeb1af72012-07-26 18:52:16 +0000509 GrAssert(fClipOrigins.count() == currClip);
bsalomon@google.coma4f6b102012-06-26 21:04:22 +0000510 GrAssert(fClears.count() == currClear);
511 GrAssert(fDraws.count() == currDraw);
512
bsalomon@google.com6e4e6502013-02-25 20:12:45 +0000513 fDstGpu->setDrawState(prevDrawState);
bsalomon@google.coma5d056a2012-03-27 15:59:58 +0000514 prevDrawState->unref();
bsalomon@google.com55e4a202013-01-11 13:54:21 +0000515 this->reset();
bsalomon@google.coma4f6b102012-06-26 21:04:22 +0000516 return true;
reed@google.comac10a2d2010-12-22 21:39:39 +0000517}
518
bsalomon@google.com97805382012-03-13 14:32:07 +0000519void GrInOrderDrawBuffer::willReserveVertexAndIndexSpace(
bsalomon@google.com97805382012-03-13 14:32:07 +0000520 int vertexCount,
521 int indexCount) {
bsalomon@google.com6e4e6502013-02-25 20:12:45 +0000522 // We use geometryHints() to know whether to flush the draw buffer. We
523 // can't flush if we are inside an unbalanced pushGeometrySource.
524 // Moreover, flushing blows away vertex and index data that was
525 // previously reserved. So if the vertex or index data is pulled from
526 // reserved space and won't be released by this request then we can't
527 // flush.
528 bool insideGeoPush = fGeoPoolStateStack.count() > 1;
bsalomon@google.com97805382012-03-13 14:32:07 +0000529
bsalomon@google.com6e4e6502013-02-25 20:12:45 +0000530 bool unreleasedVertexSpace =
531 !vertexCount &&
532 kReserved_GeometrySrcType == this->getGeomSrc().fVertexSrc;
bsalomon@google.com97805382012-03-13 14:32:07 +0000533
bsalomon@google.com6e4e6502013-02-25 20:12:45 +0000534 bool unreleasedIndexSpace =
535 !indexCount &&
536 kReserved_GeometrySrcType == this->getGeomSrc().fIndexSrc;
bsalomon@google.com97805382012-03-13 14:32:07 +0000537
bsalomon@google.com6e4e6502013-02-25 20:12:45 +0000538 // we don't want to finalize any reserved geom on the target since
539 // we don't know that the client has finished writing to it.
540 bool targetHasReservedGeom = fDstGpu->hasReservedVerticesOrIndices();
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000541
bsalomon@google.com6e4e6502013-02-25 20:12:45 +0000542 int vcount = vertexCount;
543 int icount = indexCount;
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000544
bsalomon@google.com6e4e6502013-02-25 20:12:45 +0000545 if (!insideGeoPush &&
546 !unreleasedVertexSpace &&
547 !unreleasedIndexSpace &&
548 !targetHasReservedGeom &&
549 this->geometryHints(&vcount, &icount)) {
bsalomon@google.com97805382012-03-13 14:32:07 +0000550
bsalomon@google.com6e4e6502013-02-25 20:12:45 +0000551 this->flush();
bsalomon@google.com97805382012-03-13 14:32:07 +0000552 }
553}
554
jvanverth@google.comb75b0a02013-02-05 20:33:30 +0000555bool GrInOrderDrawBuffer::geometryHints(int* vertexCount,
bsalomon@google.com1c13c962011-02-14 16:51:21 +0000556 int* indexCount) const {
557 // we will recommend a flush if the data could fit in a single
558 // preallocated buffer but none are left and it can't fit
559 // in the current buffer (which may not be prealloced).
reed@google.comac10a2d2010-12-22 21:39:39 +0000560 bool flush = false;
561 if (NULL != indexCount) {
bsalomon@google.com1c13c962011-02-14 16:51:21 +0000562 int32_t currIndices = fIndexPool.currentBufferIndices();
563 if (*indexCount > currIndices &&
564 (!fIndexPool.preallocatedBuffersRemaining() &&
565 *indexCount <= fIndexPool.preallocatedBufferIndices())) {
566
567 flush = true;
568 }
569 *indexCount = currIndices;
reed@google.comac10a2d2010-12-22 21:39:39 +0000570 }
571 if (NULL != vertexCount) {
jvanverth@google.comb75b0a02013-02-05 20:33:30 +0000572 size_t vertexSize = this->getDrawState().getVertexSize();
jvanverth@google.coma6338982013-01-31 21:34:25 +0000573 int32_t currVertices = fVertexPool.currentBufferVertices(vertexSize);
bsalomon@google.com1c13c962011-02-14 16:51:21 +0000574 if (*vertexCount > currVertices &&
575 (!fVertexPool.preallocatedBuffersRemaining() &&
jvanverth@google.coma6338982013-01-31 21:34:25 +0000576 *vertexCount <= fVertexPool.preallocatedBufferVertices(vertexSize))) {
reed@google.comac10a2d2010-12-22 21:39:39 +0000577
bsalomon@google.com1c13c962011-02-14 16:51:21 +0000578 flush = true;
reed@google.comac10a2d2010-12-22 21:39:39 +0000579 }
bsalomon@google.com1c13c962011-02-14 16:51:21 +0000580 *vertexCount = currVertices;
reed@google.comac10a2d2010-12-22 21:39:39 +0000581 }
582 return flush;
583}
584
jvanverth@google.coma6338982013-01-31 21:34:25 +0000585bool GrInOrderDrawBuffer::onReserveVertexSpace(size_t vertexSize,
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000586 int vertexCount,
587 void** vertices) {
588 GeometryPoolState& poolState = fGeoPoolStateStack.back();
589 GrAssert(vertexCount > 0);
590 GrAssert(NULL != vertices);
591 GrAssert(0 == poolState.fUsedPoolVertexBytes);
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000592
jvanverth@google.coma6338982013-01-31 21:34:25 +0000593 *vertices = fVertexPool.makeSpace(vertexSize,
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000594 vertexCount,
595 &poolState.fPoolVertexBuffer,
596 &poolState.fPoolStartVertex);
597 return NULL != *vertices;
598}
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000599
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000600bool GrInOrderDrawBuffer::onReserveIndexSpace(int indexCount, void** indices) {
601 GeometryPoolState& poolState = fGeoPoolStateStack.back();
602 GrAssert(indexCount > 0);
603 GrAssert(NULL != indices);
604 GrAssert(0 == poolState.fUsedPoolIndexBytes);
bsalomon@google.com1c13c962011-02-14 16:51:21 +0000605
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000606 *indices = fIndexPool.makeSpace(indexCount,
607 &poolState.fPoolIndexBuffer,
608 &poolState.fPoolStartIndex);
609 return NULL != *indices;
reed@google.comac10a2d2010-12-22 21:39:39 +0000610}
611
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000612void GrInOrderDrawBuffer::releaseReservedVertexSpace() {
613 GeometryPoolState& poolState = fGeoPoolStateStack.back();
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000614 const GeometrySrcState& geoSrc = this->getGeomSrc();
bsalomon@google.comd57d71a2012-08-16 16:26:33 +0000615
616 // If we get a release vertex space call then our current source should either be reserved
617 // or array (which we copied into reserved space).
618 GrAssert(kReserved_GeometrySrcType == geoSrc.fVertexSrc ||
619 kArray_GeometrySrcType == geoSrc.fVertexSrc);
bsalomon@google.com3f5a95e2012-03-08 16:41:42 +0000620
621 // When the caller reserved vertex buffer space we gave it back a pointer
622 // provided by the vertex buffer pool. At each draw we tracked the largest
623 // offset into the pool's pointer that was referenced. Now we return to the
624 // pool any portion at the tail of the allocation that no draw referenced.
jvanverth@google.comb75b0a02013-02-05 20:33:30 +0000625 size_t reservedVertexBytes = geoSrc.fVertexSize * geoSrc.fVertexCount;
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000626 fVertexPool.putBack(reservedVertexBytes -
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000627 poolState.fUsedPoolVertexBytes);
628 poolState.fUsedPoolVertexBytes = 0;
bsalomon@google.com3f5a95e2012-03-08 16:41:42 +0000629 poolState.fPoolVertexBuffer = NULL;
630 poolState.fPoolStartVertex = 0;
bsalomon@google.com1c13c962011-02-14 16:51:21 +0000631}
632
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000633void GrInOrderDrawBuffer::releaseReservedIndexSpace() {
634 GeometryPoolState& poolState = fGeoPoolStateStack.back();
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000635 const GeometrySrcState& geoSrc = this->getGeomSrc();
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000636
bsalomon@google.comd57d71a2012-08-16 16:26:33 +0000637 // If we get a release index space call then our current source should either be reserved
638 // or array (which we copied into reserved space).
639 GrAssert(kReserved_GeometrySrcType == geoSrc.fIndexSrc ||
640 kArray_GeometrySrcType == geoSrc.fIndexSrc);
bsalomon@google.com3f5a95e2012-03-08 16:41:42 +0000641
642 // Similar to releaseReservedVertexSpace we return any unused portion at
643 // the tail
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000644 size_t reservedIndexBytes = sizeof(uint16_t) * geoSrc.fIndexCount;
645 fIndexPool.putBack(reservedIndexBytes - poolState.fUsedPoolIndexBytes);
646 poolState.fUsedPoolIndexBytes = 0;
bsalomon@google.com3f5a95e2012-03-08 16:41:42 +0000647 poolState.fPoolIndexBuffer = NULL;
648 poolState.fPoolStartIndex = 0;
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000649}
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000650
bsalomon@google.combcdbbe62011-04-12 15:40:00 +0000651void GrInOrderDrawBuffer::onSetVertexSourceToArray(const void* vertexArray,
652 int vertexCount) {
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000653
654 GeometryPoolState& poolState = fGeoPoolStateStack.back();
655 GrAssert(0 == poolState.fUsedPoolVertexBytes);
bsalomon@google.com1c13c962011-02-14 16:51:21 +0000656#if GR_DEBUG
657 bool success =
658#endif
jvanverth@google.comb75b0a02013-02-05 20:33:30 +0000659 fVertexPool.appendVertices(this->getVertexSize(),
bsalomon@google.com1c13c962011-02-14 16:51:21 +0000660 vertexCount,
661 vertexArray,
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000662 &poolState.fPoolVertexBuffer,
663 &poolState.fPoolStartVertex);
bsalomon@google.com1c13c962011-02-14 16:51:21 +0000664 GR_DEBUGASSERT(success);
665}
666
bsalomon@google.combcdbbe62011-04-12 15:40:00 +0000667void GrInOrderDrawBuffer::onSetIndexSourceToArray(const void* indexArray,
668 int indexCount) {
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000669 GeometryPoolState& poolState = fGeoPoolStateStack.back();
670 GrAssert(0 == poolState.fUsedPoolIndexBytes);
bsalomon@google.com1c13c962011-02-14 16:51:21 +0000671#if GR_DEBUG
672 bool success =
673#endif
674 fIndexPool.appendIndices(indexCount,
675 indexArray,
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000676 &poolState.fPoolIndexBuffer,
677 &poolState.fPoolStartIndex);
bsalomon@google.com1c13c962011-02-14 16:51:21 +0000678 GR_DEBUGASSERT(success);
reed@google.comac10a2d2010-12-22 21:39:39 +0000679}
680
bsalomon@google.com3f5a95e2012-03-08 16:41:42 +0000681void GrInOrderDrawBuffer::releaseVertexArray() {
682 // When the client provides an array as the vertex source we handled it
683 // by copying their array into reserved space.
684 this->GrInOrderDrawBuffer::releaseReservedVertexSpace();
685}
686
687void GrInOrderDrawBuffer::releaseIndexArray() {
688 // When the client provides an array as the index source we handled it
689 // by copying their array into reserved space.
690 this->GrInOrderDrawBuffer::releaseReservedIndexSpace();
691}
692
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000693void GrInOrderDrawBuffer::geometrySourceWillPush() {
694 GeometryPoolState& poolState = fGeoPoolStateStack.push_back();
695 poolState.fUsedPoolVertexBytes = 0;
696 poolState.fUsedPoolIndexBytes = 0;
697#if GR_DEBUG
698 poolState.fPoolVertexBuffer = (GrVertexBuffer*)~0;
699 poolState.fPoolStartVertex = ~0;
700 poolState.fPoolIndexBuffer = (GrIndexBuffer*)~0;
701 poolState.fPoolStartIndex = ~0;
702#endif
703}
704
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000705void GrInOrderDrawBuffer::geometrySourceWillPop(
706 const GeometrySrcState& restoredState) {
707 GrAssert(fGeoPoolStateStack.count() > 1);
708 fGeoPoolStateStack.pop_back();
709 GeometryPoolState& poolState = fGeoPoolStateStack.back();
710 // we have to assume that any slack we had in our vertex/index data
711 // is now unreleasable because data may have been appended later in the
712 // pool.
713 if (kReserved_GeometrySrcType == restoredState.fVertexSrc ||
714 kArray_GeometrySrcType == restoredState.fVertexSrc) {
jvanverth@google.comb75b0a02013-02-05 20:33:30 +0000715 poolState.fUsedPoolVertexBytes = restoredState.fVertexSize * restoredState.fVertexCount;
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000716 }
717 if (kReserved_GeometrySrcType == restoredState.fIndexSrc ||
718 kArray_GeometrySrcType == restoredState.fIndexSrc) {
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000719 poolState.fUsedPoolIndexBytes = sizeof(uint16_t) *
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000720 restoredState.fIndexCount;
721 }
722}
723
bsalomon@google.com86afc2a2011-02-16 16:12:19 +0000724bool GrInOrderDrawBuffer::needsNewState() const {
bsalomon@google.comca432082013-01-23 19:53:46 +0000725 return fStates.empty() || !fStates.back().isEqual(this->getDrawState());
reed@google.comac10a2d2010-12-22 21:39:39 +0000726}
727
bsalomon@google.com86afc2a2011-02-16 16:12:19 +0000728bool GrInOrderDrawBuffer::needsNewClip() const {
bsalomon@google.com358e4272013-01-10 14:40:28 +0000729 GrAssert(fClips.count() == fClipOrigins.count());
730 if (this->getDrawState().isClipState()) {
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000731 if (fClipSet &&
bsalomon@google.com358e4272013-01-10 14:40:28 +0000732 (fClips.empty() ||
bsalomon@google.com02ddc8b2013-01-28 15:35:28 +0000733 fClips.back() != *this->getClip()->fClipStack ||
734 fClipOrigins.back() != this->getClip()->fOrigin)) {
bsalomon@google.com86afc2a2011-02-16 16:12:19 +0000735 return true;
736 }
reed@google.comac10a2d2010-12-22 21:39:39 +0000737 }
738 return false;
739}
bsalomon@google.comd302f142011-03-03 13:54:13 +0000740
bsalomon@google.coma4f6b102012-06-26 21:04:22 +0000741void GrInOrderDrawBuffer::recordClip() {
bsalomon@google.com02ddc8b2013-01-28 15:35:28 +0000742 fClips.push_back() = *this->getClip()->fClipStack;
743 fClipOrigins.push_back() = this->getClip()->fOrigin;
bsalomon@google.com86afc2a2011-02-16 16:12:19 +0000744 fClipSet = false;
bsalomon@google.coma4f6b102012-06-26 21:04:22 +0000745 fCmds.push_back(kSetClip_Cmd);
746}
747
bsalomon@google.coma4f6b102012-06-26 21:04:22 +0000748void GrInOrderDrawBuffer::recordState() {
bsalomon@google.comca432082013-01-23 19:53:46 +0000749 fStates.push_back().saveFrom(this->getDrawState());
bsalomon@google.coma4f6b102012-06-26 21:04:22 +0000750 fCmds.push_back(kSetState_Cmd);
751}
752
bsalomon@google.com74749cd2013-01-30 16:12:41 +0000753GrInOrderDrawBuffer::DrawRecord* GrInOrderDrawBuffer::recordDraw(const DrawInfo& info) {
bsalomon@google.comd62e88e2013-02-01 14:19:27 +0000754 fCmds.push_back(kDraw_Cmd);
755 return &fDraws.push_back(info);
bsalomon@google.com74749cd2013-01-30 16:12:41 +0000756}
757
bsalomon@google.comded4f4b2012-06-28 18:48:06 +0000758GrInOrderDrawBuffer::StencilPath* GrInOrderDrawBuffer::recordStencilPath() {
759 fCmds.push_back(kStencilPath_Cmd);
760 return &fStencilPaths.push_back();
761}
762
bsalomon@google.coma4f6b102012-06-26 21:04:22 +0000763GrInOrderDrawBuffer::Clear* GrInOrderDrawBuffer::recordClear() {
764 fCmds.push_back(kClear_Cmd);
765 return &fClears.push_back();
reed@google.comac10a2d2010-12-22 21:39:39 +0000766}
bsalomon@google.comd302f142011-03-03 13:54:13 +0000767
robertphillips@google.combeb1af72012-07-26 18:52:16 +0000768void GrInOrderDrawBuffer::clipWillBeSet(const GrClipData* newClipData) {
769 INHERITED::clipWillBeSet(newClipData);
bsalomon@google.com86afc2a2011-02-16 16:12:19 +0000770 fClipSet = true;
bsalomon@google.comd62e88e2013-02-01 14:19:27 +0000771 fClipProxyState = kUnknown_ClipProxyState;
bsalomon@google.com86afc2a2011-02-16 16:12:19 +0000772}