blob: 68590fc8abb89344eef0a200f5c1fa83a589001b [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,
bsalomon@google.comffca4002011-02-22 20:34:01 +000077 StageBitfield stageEnableBitfield,
bsalomon@google.com86afc2a2011-02-16 16:12:19 +000078 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;
bsalomon@google.comffca4002011-02-22 20:34:01 +000090 GrVertexLayout layout = GetRectVertexLayout(stageEnableBitfield, srcRects);
bsalomon@google.com86afc2a2011-02-16 16:12:19 +000091 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 }
bsalomon@google.com86afc2a2011-02-16 16:12:19 +0000170 } else {
bsalomon@google.comffca4002011-02-22 20:34:01 +0000171 INHERITED::drawRect(rect, matrix, stageEnableBitfield, srcRects, srcMatrices);
bsalomon@google.com86afc2a2011-02-16 16:12:19 +0000172 }
173}
174
bsalomon@google.comffca4002011-02-22 20:34:01 +0000175void GrInOrderDrawBuffer::drawIndexed(GrPrimitiveType primitiveType,
bsalomon@google.com1c13c962011-02-14 16:51:21 +0000176 int startVertex,
177 int startIndex,
178 int vertexCount,
179 int indexCount) {
reed@google.comac10a2d2010-12-22 21:39:39 +0000180
181 if (!vertexCount || !indexCount) {
182 return;
183 }
184
bsalomon@google.com86afc2a2011-02-16 16:12:19 +0000185 fCurrQuad = 0;
186
reed@google.comac10a2d2010-12-22 21:39:39 +0000187 Draw& draw = fDraws.push_back();
bsalomon@google.com1c13c962011-02-14 16:51:21 +0000188 draw.fPrimitiveType = primitiveType;
reed@google.comac10a2d2010-12-22 21:39:39 +0000189 draw.fStartVertex = startVertex;
190 draw.fStartIndex = startIndex;
191 draw.fVertexCount = vertexCount;
192 draw.fIndexCount = indexCount;
bsalomon@google.com86afc2a2011-02-16 16:12:19 +0000193
194 draw.fClipChanged = this->needsNewClip();
195 if (draw.fClipChanged) {
196 this->pushClip();
197 }
198
199 draw.fStateChanged = this->needsNewState();
200 if (draw.fStateChanged) {
201 this->pushState();
202 }
reed@google.comac10a2d2010-12-22 21:39:39 +0000203
204 draw.fVertexLayout = fGeometrySrc.fVertexLayout;
205 switch (fGeometrySrc.fVertexSrc) {
reed@google.comac10a2d2010-12-22 21:39:39 +0000206 case kBuffer_GeometrySrcType:
reed@google.comac10a2d2010-12-22 21:39:39 +0000207 draw.fVertexBuffer = fGeometrySrc.fVertexBuffer;
208 break;
bsalomon@google.com1c13c962011-02-14 16:51:21 +0000209 case kReserved_GeometrySrcType: {
210 size_t vertexBytes = (vertexCount + startVertex) *
211 VertexSize(fGeometrySrc.fVertexLayout);
bsalomon@google.com86afc2a2011-02-16 16:12:19 +0000212 fUsedReservedVertexBytes = GrMax(fUsedReservedVertexBytes, vertexBytes);
bsalomon@google.com1c13c962011-02-14 16:51:21 +0000213 } // fallthrough
214 case kArray_GeometrySrcType:
215 draw.fVertexBuffer = fCurrPoolVertexBuffer;
216 draw.fStartVertex += fCurrPoolStartVertex;
217 break;
218 default:
219 GrCrash("unknown geom src type");
reed@google.comac10a2d2010-12-22 21:39:39 +0000220 }
bsalomon@google.com86afc2a2011-02-16 16:12:19 +0000221 draw.fVertexBuffer->ref();
reed@google.comac10a2d2010-12-22 21:39:39 +0000222
223 switch (fGeometrySrc.fIndexSrc) {
reed@google.comac10a2d2010-12-22 21:39:39 +0000224 case kBuffer_GeometrySrcType:
reed@google.comac10a2d2010-12-22 21:39:39 +0000225 draw.fIndexBuffer = fGeometrySrc.fIndexBuffer;
226 break;
bsalomon@google.com1c13c962011-02-14 16:51:21 +0000227 case kReserved_GeometrySrcType: {
228 size_t indexBytes = (indexCount + startIndex) * sizeof(uint16_t);
229 fUsedReservedIndexBytes = GrMax(fUsedReservedIndexBytes, indexBytes);
230 } // fallthrough
231 case kArray_GeometrySrcType:
232 draw.fIndexBuffer = fCurrPoolIndexBuffer;
233 draw.fStartIndex += fCurrPoolStartVertex;
234 break;
235 default:
236 GrCrash("unknown geom src type");
reed@google.comac10a2d2010-12-22 21:39:39 +0000237 }
bsalomon@google.com86afc2a2011-02-16 16:12:19 +0000238 draw.fIndexBuffer->ref();
reed@google.comac10a2d2010-12-22 21:39:39 +0000239}
240
bsalomon@google.comffca4002011-02-22 20:34:01 +0000241void GrInOrderDrawBuffer::drawNonIndexed(GrPrimitiveType primitiveType,
bsalomon@google.com1c13c962011-02-14 16:51:21 +0000242 int startVertex,
243 int vertexCount) {
reed@google.comac10a2d2010-12-22 21:39:39 +0000244 if (!vertexCount) {
245 return;
246 }
247
bsalomon@google.com86afc2a2011-02-16 16:12:19 +0000248 fCurrQuad = 0;
249
reed@google.comac10a2d2010-12-22 21:39:39 +0000250 Draw& draw = fDraws.push_back();
bsalomon@google.com1c13c962011-02-14 16:51:21 +0000251 draw.fPrimitiveType = primitiveType;
reed@google.comac10a2d2010-12-22 21:39:39 +0000252 draw.fStartVertex = startVertex;
253 draw.fStartIndex = 0;
254 draw.fVertexCount = vertexCount;
255 draw.fIndexCount = 0;
256
bsalomon@google.com86afc2a2011-02-16 16:12:19 +0000257 draw.fClipChanged = this->needsNewClip();
258 if (draw.fClipChanged) {
259 this->pushClip();
260 }
261
262 draw.fStateChanged = this->needsNewState();
263 if (draw.fStateChanged) {
264 this->pushState();
265 }
reed@google.comac10a2d2010-12-22 21:39:39 +0000266
267 draw.fVertexLayout = fGeometrySrc.fVertexLayout;
268 switch (fGeometrySrc.fVertexSrc) {
reed@google.comac10a2d2010-12-22 21:39:39 +0000269 case kBuffer_GeometrySrcType:
reed@google.comac10a2d2010-12-22 21:39:39 +0000270 draw.fVertexBuffer = fGeometrySrc.fVertexBuffer;
271 break;
bsalomon@google.com1c13c962011-02-14 16:51:21 +0000272 case kReserved_GeometrySrcType: {
273 size_t vertexBytes = (vertexCount + startVertex) *
274 VertexSize(fGeometrySrc.fVertexLayout);
275 fUsedReservedVertexBytes = GrMax(fUsedReservedVertexBytes,
276 vertexBytes);
277 } // fallthrough
278 case kArray_GeometrySrcType:
279 draw.fVertexBuffer = fCurrPoolVertexBuffer;
280 draw.fStartVertex += fCurrPoolStartVertex;
281 break;
282 default:
283 GrCrash("unknown geom src type");
reed@google.comac10a2d2010-12-22 21:39:39 +0000284 }
bsalomon@google.com86afc2a2011-02-16 16:12:19 +0000285 draw.fVertexBuffer->ref();
286 draw.fIndexBuffer = NULL;
reed@google.comac10a2d2010-12-22 21:39:39 +0000287}
288
289void GrInOrderDrawBuffer::reset() {
290 GrAssert(!fReservedGeometry.fLocked);
291 uint32_t numStates = fStates.count();
292 for (uint32_t i = 0; i < numStates; ++i) {
bsalomon@google.com8531c1c2011-01-13 19:52:45 +0000293 for (int s = 0; s < kNumStages; ++s) {
bsalomon@google.com86afc2a2011-02-16 16:12:19 +0000294 GrTexture* tex = this->accessSavedDrawState(fStates[i]).fTextures[s];
bsalomon@google.com8531c1c2011-01-13 19:52:45 +0000295 if (NULL != tex) {
296 tex->unref();
297 }
reed@google.comac10a2d2010-12-22 21:39:39 +0000298 }
299 }
bsalomon@google.com86afc2a2011-02-16 16:12:19 +0000300 int numDraws = fDraws.count();
301 for (int d = 0; d < numDraws; ++d) {
302 // we always have a VB, but not always an IB
303 GrAssert(NULL != fDraws[d].fVertexBuffer);
304 fDraws[d].fVertexBuffer->unref();
305 GrSafeUnref(fDraws[d].fIndexBuffer);
306 }
reed@google.comac10a2d2010-12-22 21:39:39 +0000307 fDraws.reset();
308 fStates.reset();
bsalomon@google.com1c13c962011-02-14 16:51:21 +0000309
310 fVertexPool.reset();
311 fIndexPool.reset();
312
reed@google.comac10a2d2010-12-22 21:39:39 +0000313 fClips.reset();
bsalomon@google.com86afc2a2011-02-16 16:12:19 +0000314
315 fCurrQuad = 0;
reed@google.comac10a2d2010-12-22 21:39:39 +0000316}
317
318void GrInOrderDrawBuffer::playback(GrDrawTarget* target) {
319 GrAssert(NULL != target);
320 GrAssert(target != this); // not considered and why?
321
322 uint32_t numDraws = fDraws.count();
323 if (!numDraws) {
324 return;
325 }
326
bsalomon@google.com1c13c962011-02-14 16:51:21 +0000327 fVertexPool.unlock();
328 fIndexPool.unlock();
reed@google.comac10a2d2010-12-22 21:39:39 +0000329
330 GrDrawTarget::AutoStateRestore asr(target);
331 GrDrawTarget::AutoClipRestore acr(target);
332 // important to not mess with reserve/lock geometry in the target with this
333 // on the stack.
334 GrDrawTarget::AutoGeometrySrcRestore agsr(target);
335
336 uint32_t currState = ~0;
337 uint32_t currClip = ~0;
338
339 for (uint32_t i = 0; i < numDraws; ++i) {
340 const Draw& draw = fDraws[i];
bsalomon@google.com1c13c962011-02-14 16:51:21 +0000341 if (draw.fStateChanged) {
reed@google.comac10a2d2010-12-22 21:39:39 +0000342 ++currState;
343 target->restoreDrawState(fStates[currState]);
344 }
345 if (draw.fClipChanged) {
346 ++currClip;
347 target->setClip(fClips[currClip]);
348 }
bsalomon@google.com1c13c962011-02-14 16:51:21 +0000349 uint32_t vertexReserveCount = 0;
350 uint32_t indexReserveCount = 0;
351
352 target->setVertexSourceToBuffer(draw.fVertexLayout, draw.fVertexBuffer);
353
reed@google.comac10a2d2010-12-22 21:39:39 +0000354 if (draw.fIndexCount) {
bsalomon@google.com1c13c962011-02-14 16:51:21 +0000355 target->setIndexSourceToBuffer(draw.fIndexBuffer);
356 }
357
358 if (draw.fIndexCount) {
359 target->drawIndexed(draw.fPrimitiveType,
reed@google.comac10a2d2010-12-22 21:39:39 +0000360 draw.fStartVertex,
361 draw.fStartIndex,
362 draw.fVertexCount,
363 draw.fIndexCount);
364 } else {
bsalomon@google.com1c13c962011-02-14 16:51:21 +0000365 target->drawNonIndexed(draw.fPrimitiveType,
reed@google.comac10a2d2010-12-22 21:39:39 +0000366 draw.fStartVertex,
367 draw.fVertexCount);
368 }
bsalomon@google.com1c13c962011-02-14 16:51:21 +0000369 if (vertexReserveCount || indexReserveCount) {
370 target->releaseReservedGeometry();
371 }
reed@google.comac10a2d2010-12-22 21:39:39 +0000372 }
373}
374
375bool GrInOrderDrawBuffer::geometryHints(GrVertexLayout vertexLayout,
bsalomon@google.com1c13c962011-02-14 16:51:21 +0000376 int* vertexCount,
377 int* indexCount) const {
378 // we will recommend a flush if the data could fit in a single
379 // preallocated buffer but none are left and it can't fit
380 // in the current buffer (which may not be prealloced).
reed@google.comac10a2d2010-12-22 21:39:39 +0000381 bool flush = false;
382 if (NULL != indexCount) {
bsalomon@google.com1c13c962011-02-14 16:51:21 +0000383 int32_t currIndices = fIndexPool.currentBufferIndices();
384 if (*indexCount > currIndices &&
385 (!fIndexPool.preallocatedBuffersRemaining() &&
386 *indexCount <= fIndexPool.preallocatedBufferIndices())) {
387
388 flush = true;
389 }
390 *indexCount = currIndices;
reed@google.comac10a2d2010-12-22 21:39:39 +0000391 }
392 if (NULL != vertexCount) {
bsalomon@google.com1c13c962011-02-14 16:51:21 +0000393 int32_t currVertices = fVertexPool.currentBufferVertices(vertexLayout);
394 if (*vertexCount > currVertices &&
395 (!fVertexPool.preallocatedBuffersRemaining() &&
396 *vertexCount <= fVertexPool.preallocatedBufferVertices(vertexLayout))) {
reed@google.comac10a2d2010-12-22 21:39:39 +0000397
bsalomon@google.com1c13c962011-02-14 16:51:21 +0000398 flush = true;
reed@google.comac10a2d2010-12-22 21:39:39 +0000399 }
bsalomon@google.com1c13c962011-02-14 16:51:21 +0000400 *vertexCount = currVertices;
reed@google.comac10a2d2010-12-22 21:39:39 +0000401 }
402 return flush;
403}
404
405bool GrInOrderDrawBuffer::acquireGeometryHelper(GrVertexLayout vertexLayout,
406 void** vertices,
407 void** indices) {
bsalomon@google.com1c13c962011-02-14 16:51:21 +0000408 GrAssert(!fReservedGeometry.fLocked);
reed@google.comac10a2d2010-12-22 21:39:39 +0000409 if (fReservedGeometry.fVertexCount) {
bsalomon@google.com1c13c962011-02-14 16:51:21 +0000410 GrAssert(NULL != vertices);
411 GrAssert(0 == fReservedVertexBytes);
412 GrAssert(0 == fUsedReservedVertexBytes);
413
reed@google.comac10a2d2010-12-22 21:39:39 +0000414 fReservedVertexBytes = VertexSize(vertexLayout) *
415 fReservedGeometry.fVertexCount;
bsalomon@google.com1c13c962011-02-14 16:51:21 +0000416 *vertices = fVertexPool.makeSpace(vertexLayout,
417 fReservedGeometry.fVertexCount,
418 &fCurrPoolVertexBuffer,
419 &fCurrPoolStartVertex);
420 if (NULL == *vertices) {
reed@google.comac10a2d2010-12-22 21:39:39 +0000421 return false;
422 }
423 }
424 if (fReservedGeometry.fIndexCount) {
bsalomon@google.com1c13c962011-02-14 16:51:21 +0000425 GrAssert(NULL != indices);
426 GrAssert(0 == fReservedIndexBytes);
427 GrAssert(0 == fUsedReservedIndexBytes);
428
429 *indices = fIndexPool.makeSpace(fReservedGeometry.fIndexCount,
430 &fCurrPoolIndexBuffer,
431 &fCurrPoolStartIndex);
432 if (NULL == *indices) {
433 fVertexPool.putBack(fReservedVertexBytes);
434 fReservedVertexBytes = 0;
435 fCurrPoolVertexBuffer = NULL;
reed@google.comac10a2d2010-12-22 21:39:39 +0000436 return false;
437 }
438 }
439 return true;
440}
441
442void GrInOrderDrawBuffer::releaseGeometryHelper() {
443 GrAssert(fUsedReservedVertexBytes <= fReservedVertexBytes);
444 GrAssert(fUsedReservedIndexBytes <= fReservedIndexBytes);
445
446 size_t vertexSlack = fReservedVertexBytes - fUsedReservedVertexBytes;
bsalomon@google.com1c13c962011-02-14 16:51:21 +0000447 fVertexPool.putBack(vertexSlack);
reed@google.comac10a2d2010-12-22 21:39:39 +0000448
bsalomon@google.com1c13c962011-02-14 16:51:21 +0000449 size_t indexSlack = fReservedIndexBytes - fUsedReservedIndexBytes;
450 fIndexPool.putBack(indexSlack);
reed@google.comac10a2d2010-12-22 21:39:39 +0000451
reed@google.comac10a2d2010-12-22 21:39:39 +0000452 fReservedVertexBytes = 0;
453 fReservedIndexBytes = 0;
454 fUsedReservedVertexBytes = 0;
455 fUsedReservedIndexBytes = 0;
bsalomon@google.com1c13c962011-02-14 16:51:21 +0000456 fCurrPoolVertexBuffer = 0;
457 fCurrPoolStartVertex = 0;
458
459}
460
461void GrInOrderDrawBuffer::setVertexSourceToArrayHelper(const void* vertexArray,
462 int vertexCount) {
463 GrAssert(!fReservedGeometry.fLocked || !fReservedGeometry.fVertexCount);
464#if GR_DEBUG
465 bool success =
466#endif
467 fVertexPool.appendVertices(fGeometrySrc.fVertexLayout,
468 vertexCount,
469 vertexArray,
470 &fCurrPoolVertexBuffer,
471 &fCurrPoolStartVertex);
472 GR_DEBUGASSERT(success);
473}
474
475void GrInOrderDrawBuffer::setIndexSourceToArrayHelper(const void* indexArray,
476 int indexCount) {
477 GrAssert(!fReservedGeometry.fLocked || !fReservedGeometry.fIndexCount);
478#if GR_DEBUG
479 bool success =
480#endif
481 fIndexPool.appendIndices(indexCount,
482 indexArray,
483 &fCurrPoolIndexBuffer,
484 &fCurrPoolStartIndex);
485 GR_DEBUGASSERT(success);
reed@google.comac10a2d2010-12-22 21:39:39 +0000486}
487
bsalomon@google.com86afc2a2011-02-16 16:12:19 +0000488bool GrInOrderDrawBuffer::needsNewState() const {
489 if (fStates.empty()) {
490 return true;
491 } else {
492 const DrState& old = this->accessSavedDrawState(fStates.back());
493 return old != fCurrDrawState;
494 }
reed@google.comac10a2d2010-12-22 21:39:39 +0000495}
496
bsalomon@google.com86afc2a2011-02-16 16:12:19 +0000497void GrInOrderDrawBuffer::pushState() {
498 for (int s = 0; s < kNumStages; ++s) {
499 GrSafeRef(fCurrDrawState.fTextures[s]);
500 }
501 this->saveCurrentDrawState(&fStates.push_back());
502 }
503
504bool GrInOrderDrawBuffer::needsNewClip() const {
505 if (fCurrDrawState.fFlagBits & kClip_StateBit) {
506 if (fClips.empty() || (fClipSet && fClips.back() != fClip)) {
507 return true;
508 }
reed@google.comac10a2d2010-12-22 21:39:39 +0000509 }
510 return false;
511}
bsalomon@google.com86afc2a2011-02-16 16:12:19 +0000512
513void GrInOrderDrawBuffer::pushClip() {
514 fClips.push_back() = fClip;
515 fClipSet = false;
reed@google.comac10a2d2010-12-22 21:39:39 +0000516}
bsalomon@google.com86afc2a2011-02-16 16:12:19 +0000517
518void GrInOrderDrawBuffer::clipWillBeSet(const GrClip& newClip) {
519 fClipSet = true;
520}