blob: 25e74e37e478ae53f27e75c221a0879e16444f3b [file] [log] [blame]
reed@google.comac10a2d2010-12-22 21:39:39 +00001/*
2 Copyright 2010 Google Inc.
3
4 Licensed under the Apache License, Version 2.0 (the "License");
5 you may not use this file except in compliance with the License.
6 You may obtain a copy of the License at
7
8 http://www.apache.org/licenses/LICENSE-2.0
9
10 Unless required by applicable law or agreed to in writing, software
11 distributed under the License is distributed on an "AS IS" BASIS,
12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 See the License for the specific language governing permissions and
14 limitations under the License.
15 */
16
17
18#include "GrInOrderDrawBuffer.h"
19#include "GrTexture.h"
bsalomon@google.com1c13c962011-02-14 16:51:21 +000020#include "GrBufferAllocPool.h"
bsalomon@google.com86afc2a2011-02-16 16:12:19 +000021#include "GrIndexBuffer.h"
22#include "GrVertexBuffer.h"
reed@google.comac10a2d2010-12-22 21:39:39 +000023#include "GrGpu.h"
24
bsalomon@google.com1c13c962011-02-14 16:51:21 +000025GrInOrderDrawBuffer::GrInOrderDrawBuffer(GrVertexBufferAllocPool* vertexPool,
26 GrIndexBufferAllocPool* indexPool) :
reed@google.comac10a2d2010-12-22 21:39:39 +000027 fDraws(DRAWS_BLOCK_SIZE, fDrawsStorage),
28 fStates(STATES_BLOCK_SIZE, fStatesStorage),
29 fClips(CLIPS_BLOCK_SIZE, fClipsStorage),
bsalomon@google.com86afc2a2011-02-16 16:12:19 +000030 fClipSet(true),
31
32 fLastRectVertexLayout(0),
33 fQuadIndexBuffer(NULL),
34 fMaxQuads(0),
35 fCurrQuad(0),
36
bsalomon@google.com1c13c962011-02-14 16:51:21 +000037 fVertexPool(*vertexPool),
38 fCurrPoolVertexBuffer(NULL),
39 fCurrPoolStartVertex(0),
40 fIndexPool(*indexPool),
41 fCurrPoolIndexBuffer(NULL),
42 fCurrPoolStartIndex(0),
reed@google.comac10a2d2010-12-22 21:39:39 +000043 fReservedVertexBytes(0),
44 fReservedIndexBytes(0),
45 fUsedReservedVertexBytes(0),
46 fUsedReservedIndexBytes(0) {
bsalomon@google.com1c13c962011-02-14 16:51:21 +000047 GrAssert(NULL != vertexPool);
48 GrAssert(NULL != indexPool);
reed@google.comac10a2d2010-12-22 21:39:39 +000049}
50
51GrInOrderDrawBuffer::~GrInOrderDrawBuffer() {
bsalomon@google.com86afc2a2011-02-16 16:12:19 +000052 this->reset();
53 GrSafeUnref(fQuadIndexBuffer);
reed@google.comac10a2d2010-12-22 21:39:39 +000054}
55
56void GrInOrderDrawBuffer::initializeDrawStateAndClip(const GrDrawTarget& target) {
57 this->copyDrawState(target);
58 this->setClip(target.getClip());
59}
60
bsalomon@google.com86afc2a2011-02-16 16:12:19 +000061void GrInOrderDrawBuffer::setQuadIndexBuffer(const GrIndexBuffer* indexBuffer) {
62 bool newIdxBuffer = fQuadIndexBuffer != indexBuffer;
63 if (newIdxBuffer) {
64 GrSafeUnref(fQuadIndexBuffer);
65 fQuadIndexBuffer = indexBuffer;
66 GrSafeRef(fQuadIndexBuffer);
67 fCurrQuad = 0;
68 fMaxQuads = (NULL == indexBuffer) ? 0 : indexBuffer->maxQuads();
69 } else {
70 GrAssert((NULL == indexBuffer && 0 == fMaxQuads) ||
71 (indexBuffer->maxQuads() == fMaxQuads));
72 }
73}
74
75void GrInOrderDrawBuffer::drawRect(const GrRect& rect,
76 const GrMatrix* matrix,
77 int stageEnableMask,
78 const GrRect* srcRects[],
79 const GrMatrix* srcMatrices[]) {
80
81 GrAssert(!(NULL == fQuadIndexBuffer && fCurrQuad));
82 GrAssert(!(fDraws.empty() && fCurrQuad));
83 GrAssert(!(0 != fMaxQuads && NULL == fQuadIndexBuffer));
84
85 // if we have a quad IB then either append to the previous run of
86 // rects or start a new run
87 if (fMaxQuads) {
88
89 bool appendToPreviousDraw = false;
90 GrVertexLayout layout = GetRectVertexLayout(stageEnableMask, srcRects);
91 AutoReleaseGeometry geo(this, layout, 4, 0);
92 AutoViewMatrixRestore avmr(this);
93 GrMatrix combinedMatrix = this->getViewMatrix();
94 this->setViewMatrix(GrMatrix::I());
95 if (NULL != matrix) {
96 combinedMatrix.preConcat(*matrix);
97 }
98
99 SetRectVertices(rect, &combinedMatrix, srcRects, srcMatrices, layout, geo.vertices());
100
101 // we don't want to miss an opportunity to batch rects together
102 // simply because the clip has changed if the clip doesn't affect
103 // the rect.
104 bool disabledClip = false;
105 if (this->isClipState() && fClip.isRect()) {
106 GrRect clipRect = GrRect(*fClip.getRects());
107 // If the clip rect touches the edge of the viewport, extended it
108 // out (close) to infinity to avoid bogus intersections.
109 // We might consider a more exact clip to viewport if this
110 // conservative test fails.
111 const GrRenderTarget* target = this->getRenderTarget();
112 if (0 >= clipRect.fLeft) {
113 clipRect.fLeft = GR_ScalarMin;
114 }
115 if (target->width() <= clipRect.fRight) {
116 clipRect.fRight = GR_ScalarMax;
117 }
118 if (0 >= clipRect.top()) {
119 clipRect.fTop = GR_ScalarMin;
120 }
121 if (target->height() <= clipRect.fBottom) {
122 clipRect.fBottom = GR_ScalarMax;
123 }
124 int stride = VertexSize(layout);
125 bool insideClip = true;
126 for (int v = 0; v < 4; ++v) {
127 const GrPoint& p = *GetVertexPoint(geo.vertices(), v, stride);
128 if (!clipRect.contains(p)) {
129 insideClip = false;
130 break;
131 }
132 }
133 if (insideClip) {
134 this->disableState(kClip_StateBit);
135 disabledClip = true;
136 }
137 }
138 if (!needsNewClip() && !needsNewState() && fCurrQuad > 0 &&
139 fCurrQuad < fMaxQuads && layout == fLastRectVertexLayout) {
140
141 int vsize = VertexSize(layout);
142
143 Draw& lastDraw = fDraws.back();
144
145 GrAssert(lastDraw.fIndexBuffer == fQuadIndexBuffer);
146 GrAssert(kTriangles_PrimitiveType == lastDraw.fPrimitiveType);
147 GrAssert(0 == lastDraw.fVertexCount % 4);
148 GrAssert(0 == lastDraw.fIndexCount % 6);
149 GrAssert(0 == lastDraw.fStartIndex);
150
151 appendToPreviousDraw = lastDraw.fVertexBuffer == fCurrPoolVertexBuffer &&
152 (fCurrQuad * 4 + lastDraw.fStartVertex) == fCurrPoolStartVertex;
153 if (appendToPreviousDraw) {
154 lastDraw.fVertexCount += 4;
155 lastDraw.fIndexCount += 6;
156 fCurrQuad += 1;
157 GrAssert(0 == fUsedReservedVertexBytes);
158 fUsedReservedVertexBytes = 4 * vsize;
159 }
160 }
161 if (!appendToPreviousDraw) {
162 this->setIndexSourceToBuffer(fQuadIndexBuffer);
163 drawIndexed(kTriangles_PrimitiveType, 0, 0, 4, 6);
164 fCurrQuad = 1;
165 fLastRectVertexLayout = layout;
166 }
167 if (disabledClip) {
168 this->enableState(kClip_StateBit);
169 }
170this->enableState(kClip_StateBit);
171 } else {
172 INHERITED::drawRect(rect, matrix, stageEnableMask, srcRects, srcMatrices);
173 }
174}
175
bsalomon@google.com1c13c962011-02-14 16:51:21 +0000176void GrInOrderDrawBuffer::drawIndexed(PrimitiveType primitiveType,
177 int startVertex,
178 int startIndex,
179 int vertexCount,
180 int indexCount) {
reed@google.comac10a2d2010-12-22 21:39:39 +0000181
182 if (!vertexCount || !indexCount) {
183 return;
184 }
185
bsalomon@google.com86afc2a2011-02-16 16:12:19 +0000186 fCurrQuad = 0;
187
reed@google.comac10a2d2010-12-22 21:39:39 +0000188 Draw& draw = fDraws.push_back();
bsalomon@google.com1c13c962011-02-14 16:51:21 +0000189 draw.fPrimitiveType = primitiveType;
reed@google.comac10a2d2010-12-22 21:39:39 +0000190 draw.fStartVertex = startVertex;
191 draw.fStartIndex = startIndex;
192 draw.fVertexCount = vertexCount;
193 draw.fIndexCount = indexCount;
bsalomon@google.com86afc2a2011-02-16 16:12:19 +0000194
195 draw.fClipChanged = this->needsNewClip();
196 if (draw.fClipChanged) {
197 this->pushClip();
198 }
199
200 draw.fStateChanged = this->needsNewState();
201 if (draw.fStateChanged) {
202 this->pushState();
203 }
reed@google.comac10a2d2010-12-22 21:39:39 +0000204
205 draw.fVertexLayout = fGeometrySrc.fVertexLayout;
206 switch (fGeometrySrc.fVertexSrc) {
reed@google.comac10a2d2010-12-22 21:39:39 +0000207 case kBuffer_GeometrySrcType:
reed@google.comac10a2d2010-12-22 21:39:39 +0000208 draw.fVertexBuffer = fGeometrySrc.fVertexBuffer;
209 break;
bsalomon@google.com1c13c962011-02-14 16:51:21 +0000210 case kReserved_GeometrySrcType: {
211 size_t vertexBytes = (vertexCount + startVertex) *
212 VertexSize(fGeometrySrc.fVertexLayout);
bsalomon@google.com86afc2a2011-02-16 16:12:19 +0000213 fUsedReservedVertexBytes = GrMax(fUsedReservedVertexBytes, vertexBytes);
bsalomon@google.com1c13c962011-02-14 16:51:21 +0000214 } // fallthrough
215 case kArray_GeometrySrcType:
216 draw.fVertexBuffer = fCurrPoolVertexBuffer;
217 draw.fStartVertex += fCurrPoolStartVertex;
218 break;
219 default:
220 GrCrash("unknown geom src type");
reed@google.comac10a2d2010-12-22 21:39:39 +0000221 }
bsalomon@google.com86afc2a2011-02-16 16:12:19 +0000222 draw.fVertexBuffer->ref();
reed@google.comac10a2d2010-12-22 21:39:39 +0000223
224 switch (fGeometrySrc.fIndexSrc) {
reed@google.comac10a2d2010-12-22 21:39:39 +0000225 case kBuffer_GeometrySrcType:
reed@google.comac10a2d2010-12-22 21:39:39 +0000226 draw.fIndexBuffer = fGeometrySrc.fIndexBuffer;
227 break;
bsalomon@google.com1c13c962011-02-14 16:51:21 +0000228 case kReserved_GeometrySrcType: {
229 size_t indexBytes = (indexCount + startIndex) * sizeof(uint16_t);
230 fUsedReservedIndexBytes = GrMax(fUsedReservedIndexBytes, indexBytes);
231 } // fallthrough
232 case kArray_GeometrySrcType:
233 draw.fIndexBuffer = fCurrPoolIndexBuffer;
234 draw.fStartIndex += fCurrPoolStartVertex;
235 break;
236 default:
237 GrCrash("unknown geom src type");
reed@google.comac10a2d2010-12-22 21:39:39 +0000238 }
bsalomon@google.com86afc2a2011-02-16 16:12:19 +0000239 draw.fIndexBuffer->ref();
reed@google.comac10a2d2010-12-22 21:39:39 +0000240}
241
bsalomon@google.com1c13c962011-02-14 16:51:21 +0000242void GrInOrderDrawBuffer::drawNonIndexed(PrimitiveType primitiveType,
243 int startVertex,
244 int vertexCount) {
reed@google.comac10a2d2010-12-22 21:39:39 +0000245 if (!vertexCount) {
246 return;
247 }
248
bsalomon@google.com86afc2a2011-02-16 16:12:19 +0000249 fCurrQuad = 0;
250
reed@google.comac10a2d2010-12-22 21:39:39 +0000251 Draw& draw = fDraws.push_back();
bsalomon@google.com1c13c962011-02-14 16:51:21 +0000252 draw.fPrimitiveType = primitiveType;
reed@google.comac10a2d2010-12-22 21:39:39 +0000253 draw.fStartVertex = startVertex;
254 draw.fStartIndex = 0;
255 draw.fVertexCount = vertexCount;
256 draw.fIndexCount = 0;
257
bsalomon@google.com86afc2a2011-02-16 16:12:19 +0000258 draw.fClipChanged = this->needsNewClip();
259 if (draw.fClipChanged) {
260 this->pushClip();
261 }
262
263 draw.fStateChanged = this->needsNewState();
264 if (draw.fStateChanged) {
265 this->pushState();
266 }
reed@google.comac10a2d2010-12-22 21:39:39 +0000267
268 draw.fVertexLayout = fGeometrySrc.fVertexLayout;
269 switch (fGeometrySrc.fVertexSrc) {
reed@google.comac10a2d2010-12-22 21:39:39 +0000270 case kBuffer_GeometrySrcType:
reed@google.comac10a2d2010-12-22 21:39:39 +0000271 draw.fVertexBuffer = fGeometrySrc.fVertexBuffer;
272 break;
bsalomon@google.com1c13c962011-02-14 16:51:21 +0000273 case kReserved_GeometrySrcType: {
274 size_t vertexBytes = (vertexCount + startVertex) *
275 VertexSize(fGeometrySrc.fVertexLayout);
276 fUsedReservedVertexBytes = GrMax(fUsedReservedVertexBytes,
277 vertexBytes);
278 } // fallthrough
279 case kArray_GeometrySrcType:
280 draw.fVertexBuffer = fCurrPoolVertexBuffer;
281 draw.fStartVertex += fCurrPoolStartVertex;
282 break;
283 default:
284 GrCrash("unknown geom src type");
reed@google.comac10a2d2010-12-22 21:39:39 +0000285 }
bsalomon@google.com86afc2a2011-02-16 16:12:19 +0000286 draw.fVertexBuffer->ref();
287 draw.fIndexBuffer = NULL;
reed@google.comac10a2d2010-12-22 21:39:39 +0000288}
289
290void GrInOrderDrawBuffer::reset() {
291 GrAssert(!fReservedGeometry.fLocked);
292 uint32_t numStates = fStates.count();
293 for (uint32_t i = 0; i < numStates; ++i) {
bsalomon@google.com8531c1c2011-01-13 19:52:45 +0000294 for (int s = 0; s < kNumStages; ++s) {
bsalomon@google.com86afc2a2011-02-16 16:12:19 +0000295 GrTexture* tex = this->accessSavedDrawState(fStates[i]).fTextures[s];
bsalomon@google.com8531c1c2011-01-13 19:52:45 +0000296 if (NULL != tex) {
297 tex->unref();
298 }
reed@google.comac10a2d2010-12-22 21:39:39 +0000299 }
300 }
bsalomon@google.com86afc2a2011-02-16 16:12:19 +0000301 int numDraws = fDraws.count();
302 for (int d = 0; d < numDraws; ++d) {
303 // we always have a VB, but not always an IB
304 GrAssert(NULL != fDraws[d].fVertexBuffer);
305 fDraws[d].fVertexBuffer->unref();
306 GrSafeUnref(fDraws[d].fIndexBuffer);
307 }
reed@google.comac10a2d2010-12-22 21:39:39 +0000308 fDraws.reset();
309 fStates.reset();
bsalomon@google.com1c13c962011-02-14 16:51:21 +0000310
311 fVertexPool.reset();
312 fIndexPool.reset();
313
reed@google.comac10a2d2010-12-22 21:39:39 +0000314 fClips.reset();
bsalomon@google.com86afc2a2011-02-16 16:12:19 +0000315
316 fCurrQuad = 0;
reed@google.comac10a2d2010-12-22 21:39:39 +0000317}
318
319void GrInOrderDrawBuffer::playback(GrDrawTarget* target) {
320 GrAssert(NULL != target);
321 GrAssert(target != this); // not considered and why?
322
323 uint32_t numDraws = fDraws.count();
324 if (!numDraws) {
325 return;
326 }
327
bsalomon@google.com1c13c962011-02-14 16:51:21 +0000328 fVertexPool.unlock();
329 fIndexPool.unlock();
reed@google.comac10a2d2010-12-22 21:39:39 +0000330
331 GrDrawTarget::AutoStateRestore asr(target);
332 GrDrawTarget::AutoClipRestore acr(target);
333 // important to not mess with reserve/lock geometry in the target with this
334 // on the stack.
335 GrDrawTarget::AutoGeometrySrcRestore agsr(target);
336
337 uint32_t currState = ~0;
338 uint32_t currClip = ~0;
339
340 for (uint32_t i = 0; i < numDraws; ++i) {
341 const Draw& draw = fDraws[i];
bsalomon@google.com1c13c962011-02-14 16:51:21 +0000342 if (draw.fStateChanged) {
reed@google.comac10a2d2010-12-22 21:39:39 +0000343 ++currState;
344 target->restoreDrawState(fStates[currState]);
345 }
346 if (draw.fClipChanged) {
347 ++currClip;
348 target->setClip(fClips[currClip]);
349 }
bsalomon@google.com1c13c962011-02-14 16:51:21 +0000350 uint32_t vertexReserveCount = 0;
351 uint32_t indexReserveCount = 0;
352
353 target->setVertexSourceToBuffer(draw.fVertexLayout, draw.fVertexBuffer);
354
reed@google.comac10a2d2010-12-22 21:39:39 +0000355 if (draw.fIndexCount) {
bsalomon@google.com1c13c962011-02-14 16:51:21 +0000356 target->setIndexSourceToBuffer(draw.fIndexBuffer);
357 }
358
359 if (draw.fIndexCount) {
360 target->drawIndexed(draw.fPrimitiveType,
reed@google.comac10a2d2010-12-22 21:39:39 +0000361 draw.fStartVertex,
362 draw.fStartIndex,
363 draw.fVertexCount,
364 draw.fIndexCount);
365 } else {
bsalomon@google.com1c13c962011-02-14 16:51:21 +0000366 target->drawNonIndexed(draw.fPrimitiveType,
reed@google.comac10a2d2010-12-22 21:39:39 +0000367 draw.fStartVertex,
368 draw.fVertexCount);
369 }
bsalomon@google.com1c13c962011-02-14 16:51:21 +0000370 if (vertexReserveCount || indexReserveCount) {
371 target->releaseReservedGeometry();
372 }
reed@google.comac10a2d2010-12-22 21:39:39 +0000373 }
374}
375
376bool GrInOrderDrawBuffer::geometryHints(GrVertexLayout vertexLayout,
bsalomon@google.com1c13c962011-02-14 16:51:21 +0000377 int* vertexCount,
378 int* indexCount) const {
379 // we will recommend a flush if the data could fit in a single
380 // preallocated buffer but none are left and it can't fit
381 // in the current buffer (which may not be prealloced).
reed@google.comac10a2d2010-12-22 21:39:39 +0000382 bool flush = false;
383 if (NULL != indexCount) {
bsalomon@google.com1c13c962011-02-14 16:51:21 +0000384 int32_t currIndices = fIndexPool.currentBufferIndices();
385 if (*indexCount > currIndices &&
386 (!fIndexPool.preallocatedBuffersRemaining() &&
387 *indexCount <= fIndexPool.preallocatedBufferIndices())) {
388
389 flush = true;
390 }
391 *indexCount = currIndices;
reed@google.comac10a2d2010-12-22 21:39:39 +0000392 }
393 if (NULL != vertexCount) {
bsalomon@google.com1c13c962011-02-14 16:51:21 +0000394 int32_t currVertices = fVertexPool.currentBufferVertices(vertexLayout);
395 if (*vertexCount > currVertices &&
396 (!fVertexPool.preallocatedBuffersRemaining() &&
397 *vertexCount <= fVertexPool.preallocatedBufferVertices(vertexLayout))) {
reed@google.comac10a2d2010-12-22 21:39:39 +0000398
bsalomon@google.com1c13c962011-02-14 16:51:21 +0000399 flush = true;
reed@google.comac10a2d2010-12-22 21:39:39 +0000400 }
bsalomon@google.com1c13c962011-02-14 16:51:21 +0000401 *vertexCount = currVertices;
reed@google.comac10a2d2010-12-22 21:39:39 +0000402 }
403 return flush;
404}
405
406bool GrInOrderDrawBuffer::acquireGeometryHelper(GrVertexLayout vertexLayout,
407 void** vertices,
408 void** indices) {
bsalomon@google.com1c13c962011-02-14 16:51:21 +0000409 GrAssert(!fReservedGeometry.fLocked);
reed@google.comac10a2d2010-12-22 21:39:39 +0000410 if (fReservedGeometry.fVertexCount) {
bsalomon@google.com1c13c962011-02-14 16:51:21 +0000411 GrAssert(NULL != vertices);
412 GrAssert(0 == fReservedVertexBytes);
413 GrAssert(0 == fUsedReservedVertexBytes);
414
reed@google.comac10a2d2010-12-22 21:39:39 +0000415 fReservedVertexBytes = VertexSize(vertexLayout) *
416 fReservedGeometry.fVertexCount;
bsalomon@google.com1c13c962011-02-14 16:51:21 +0000417 *vertices = fVertexPool.makeSpace(vertexLayout,
418 fReservedGeometry.fVertexCount,
419 &fCurrPoolVertexBuffer,
420 &fCurrPoolStartVertex);
421 if (NULL == *vertices) {
reed@google.comac10a2d2010-12-22 21:39:39 +0000422 return false;
423 }
424 }
425 if (fReservedGeometry.fIndexCount) {
bsalomon@google.com1c13c962011-02-14 16:51:21 +0000426 GrAssert(NULL != indices);
427 GrAssert(0 == fReservedIndexBytes);
428 GrAssert(0 == fUsedReservedIndexBytes);
429
430 *indices = fIndexPool.makeSpace(fReservedGeometry.fIndexCount,
431 &fCurrPoolIndexBuffer,
432 &fCurrPoolStartIndex);
433 if (NULL == *indices) {
434 fVertexPool.putBack(fReservedVertexBytes);
435 fReservedVertexBytes = 0;
436 fCurrPoolVertexBuffer = NULL;
reed@google.comac10a2d2010-12-22 21:39:39 +0000437 return false;
438 }
439 }
440 return true;
441}
442
443void GrInOrderDrawBuffer::releaseGeometryHelper() {
444 GrAssert(fUsedReservedVertexBytes <= fReservedVertexBytes);
445 GrAssert(fUsedReservedIndexBytes <= fReservedIndexBytes);
446
447 size_t vertexSlack = fReservedVertexBytes - fUsedReservedVertexBytes;
bsalomon@google.com1c13c962011-02-14 16:51:21 +0000448 fVertexPool.putBack(vertexSlack);
reed@google.comac10a2d2010-12-22 21:39:39 +0000449
bsalomon@google.com1c13c962011-02-14 16:51:21 +0000450 size_t indexSlack = fReservedIndexBytes - fUsedReservedIndexBytes;
451 fIndexPool.putBack(indexSlack);
reed@google.comac10a2d2010-12-22 21:39:39 +0000452
reed@google.comac10a2d2010-12-22 21:39:39 +0000453 fReservedVertexBytes = 0;
454 fReservedIndexBytes = 0;
455 fUsedReservedVertexBytes = 0;
456 fUsedReservedIndexBytes = 0;
bsalomon@google.com1c13c962011-02-14 16:51:21 +0000457 fCurrPoolVertexBuffer = 0;
458 fCurrPoolStartVertex = 0;
459
460}
461
462void GrInOrderDrawBuffer::setVertexSourceToArrayHelper(const void* vertexArray,
463 int vertexCount) {
464 GrAssert(!fReservedGeometry.fLocked || !fReservedGeometry.fVertexCount);
465#if GR_DEBUG
466 bool success =
467#endif
468 fVertexPool.appendVertices(fGeometrySrc.fVertexLayout,
469 vertexCount,
470 vertexArray,
471 &fCurrPoolVertexBuffer,
472 &fCurrPoolStartVertex);
473 GR_DEBUGASSERT(success);
474}
475
476void GrInOrderDrawBuffer::setIndexSourceToArrayHelper(const void* indexArray,
477 int indexCount) {
478 GrAssert(!fReservedGeometry.fLocked || !fReservedGeometry.fIndexCount);
479#if GR_DEBUG
480 bool success =
481#endif
482 fIndexPool.appendIndices(indexCount,
483 indexArray,
484 &fCurrPoolIndexBuffer,
485 &fCurrPoolStartIndex);
486 GR_DEBUGASSERT(success);
reed@google.comac10a2d2010-12-22 21:39:39 +0000487}
488
bsalomon@google.com86afc2a2011-02-16 16:12:19 +0000489bool GrInOrderDrawBuffer::needsNewState() const {
490 if (fStates.empty()) {
491 return true;
492 } else {
493 const DrState& old = this->accessSavedDrawState(fStates.back());
494 return old != fCurrDrawState;
495 }
reed@google.comac10a2d2010-12-22 21:39:39 +0000496}
497
bsalomon@google.com86afc2a2011-02-16 16:12:19 +0000498void GrInOrderDrawBuffer::pushState() {
499 for (int s = 0; s < kNumStages; ++s) {
500 GrSafeRef(fCurrDrawState.fTextures[s]);
501 }
502 this->saveCurrentDrawState(&fStates.push_back());
503 }
504
505bool GrInOrderDrawBuffer::needsNewClip() const {
506 if (fCurrDrawState.fFlagBits & kClip_StateBit) {
507 if (fClips.empty() || (fClipSet && fClips.back() != fClip)) {
508 return true;
509 }
reed@google.comac10a2d2010-12-22 21:39:39 +0000510 }
511 return false;
512}
bsalomon@google.com86afc2a2011-02-16 16:12:19 +0000513
514void GrInOrderDrawBuffer::pushClip() {
515 fClips.push_back() = fClip;
516 fClipSet = false;
reed@google.comac10a2d2010-12-22 21:39:39 +0000517}
bsalomon@google.com86afc2a2011-02-16 16:12:19 +0000518
519void GrInOrderDrawBuffer::clipWillBeSet(const GrClip& newClip) {
520 fClipSet = true;
521}