blob: a090dcf823ea8ad78afd5f8ef5327f3972f7cbd3 [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"
bsalomon@google.comc26d94f2013-03-25 18:19:00 +000012#include "GrDrawTargetCaps.h"
bsalomon@google.comded4f4b2012-06-28 18:48:06 +000013#include "GrGpu.h"
14#include "GrIndexBuffer.h"
15#include "GrPath.h"
bsalomon@google.com8f9cbd62011-12-09 15:55:34 +000016#include "GrRenderTarget.h"
bsalomon@google.com6e4e6502013-02-25 20:12:45 +000017#include "GrTemplates.h"
reed@google.comac10a2d2010-12-22 21:39:39 +000018#include "GrTexture.h"
bsalomon@google.com86afc2a2011-02-16 16:12:19 +000019#include "GrVertexBuffer.h"
reed@google.comac10a2d2010-12-22 21:39:39 +000020
bsalomon@google.com6e4e6502013-02-25 20:12:45 +000021GrInOrderDrawBuffer::GrInOrderDrawBuffer(GrGpu* gpu,
bsalomon@google.com471d4712011-08-23 15:45:25 +000022 GrVertexBufferAllocPool* vertexPool,
bsalomon@google.com25fb21f2011-06-21 18:17:25 +000023 GrIndexBufferAllocPool* indexPool)
bsalomon@google.com6e4e6502013-02-25 20:12:45 +000024 : GrDrawTarget(gpu->getContext())
25 , fDstGpu(gpu)
bsalomon@google.com97805382012-03-13 14:32:07 +000026 , fClipSet(true)
bsalomon@google.comd62e88e2013-02-01 14:19:27 +000027 , fClipProxyState(kUnknown_ClipProxyState)
robertphillips@google.com69705572012-03-21 19:46:50 +000028 , fVertexPool(*vertexPool)
29 , fIndexPool(*indexPool)
robertphillips@google.comc82a8b72012-06-21 20:15:48 +000030 , fFlushing(false) {
bsalomon@google.com18c9c192011-09-22 21:01:31 +000031
bsalomon@google.com6e4e6502013-02-25 20:12:45 +000032 fDstGpu->ref();
bsalomon@google.combcce8922013-03-25 15:38:39 +000033 fCaps.reset(SkRef(fDstGpu->caps()));
bsalomon@google.com18c9c192011-09-22 21:01:31 +000034
bsalomon@google.com1c13c962011-02-14 16:51:21 +000035 GrAssert(NULL != vertexPool);
36 GrAssert(NULL != indexPool);
bsalomon@google.com25fb21f2011-06-21 18:17:25 +000037
38 GeometryPoolState& poolState = fGeoPoolStateStack.push_back();
39 poolState.fUsedPoolVertexBytes = 0;
40 poolState.fUsedPoolIndexBytes = 0;
41#if GR_DEBUG
42 poolState.fPoolVertexBuffer = (GrVertexBuffer*)~0;
43 poolState.fPoolStartVertex = ~0;
44 poolState.fPoolIndexBuffer = (GrIndexBuffer*)~0;
45 poolState.fPoolStartIndex = ~0;
46#endif
bsalomon@google.coma4f6b102012-06-26 21:04:22 +000047 this->reset();
reed@google.comac10a2d2010-12-22 21:39:39 +000048}
49
50GrInOrderDrawBuffer::~GrInOrderDrawBuffer() {
bsalomon@google.com86afc2a2011-02-16 16:12:19 +000051 this->reset();
bsalomon@google.com4a018bb2011-10-28 19:50:21 +000052 // This must be called by before the GrDrawTarget destructor
53 this->releaseGeometry();
bsalomon@google.com6e4e6502013-02-25 20:12:45 +000054 fDstGpu->unref();
reed@google.comac10a2d2010-12-22 21:39:39 +000055}
56
bsalomon@google.com934c5702012-03-20 21:17:58 +000057////////////////////////////////////////////////////////////////////////////////
58
bsalomon@google.comd62e88e2013-02-01 14:19:27 +000059namespace {
60void get_vertex_bounds(const void* vertices,
61 size_t vertexSize,
62 int vertexCount,
63 SkRect* bounds) {
64 GrAssert(vertexSize >= sizeof(GrPoint));
65 GrAssert(vertexCount > 0);
66 const GrPoint* point = static_cast<const GrPoint*>(vertices);
67 bounds->fLeft = bounds->fRight = point->fX;
68 bounds->fTop = bounds->fBottom = point->fY;
69 for (int i = 1; i < vertexCount; ++i) {
70 point = reinterpret_cast<GrPoint*>(reinterpret_cast<intptr_t>(point) + vertexSize);
71 bounds->growToInclude(point->fX, point->fY);
72 }
73}
bsalomon@google.com934c5702012-03-20 21:17:58 +000074}
75
bsalomon@google.comd302f142011-03-03 13:54:13 +000076void GrInOrderDrawBuffer::drawRect(const GrRect& rect,
bsalomon@google.comb9086a02012-11-01 18:02:54 +000077 const SkMatrix* matrix,
bsalomon@google.comc7818882013-03-20 19:19:53 +000078 const GrRect* localRect,
79 const SkMatrix* localMatrix) {
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;
bsalomon@google.comc7818882013-03-20 19:19:53 +000089 int colorOffset = -1, localOffset = -1;
jvanverth@google.com9b855c72013-03-01 18:21:22 +000090
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.
bsalomon@google.combcce8922013-03-25 15:38:39 +0000103 if (this->caps()->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.comc7818882013-03-20 19:19:53 +0000118 if (NULL != localRect) {
119 bindings |= GrDrawState::kLocalCoords_AttribBindingsBit;
120 drawState->setAttribIndex(GrDrawState::kLocalCoords_AttribIndex, attribs.count());
jvanverth@google.com3b0d6312013-03-01 20:30:01 +0000121 currAttrib.set(kVec2f_GrVertexAttribType, currentOffset);
122 attribs.push_back(currAttrib);
bsalomon@google.comc7818882013-03-20 19:19:53 +0000123 localOffset = currentOffset;
jvanverth@google.com9b855c72013-03-01 18:21:22 +0000124 currentOffset += sizeof(GrPoint);
bsalomon@google.comd62e88e2013-02-01 14:19:27 +0000125 }
126
jvanverth@google.com9b855c72013-03-01 18:21:22 +0000127 drawState->setVertexAttribs(attribs.begin(), attribs.count());
128 drawState->setAttribBindings(bindings);
jvanverth@google.comb75b0a02013-02-05 20:33:30 +0000129 AutoReleaseGeometry geo(this, 4, 0);
bsalomon@google.comd62e88e2013-02-01 14:19:27 +0000130 if (!geo.succeeded()) {
131 GrPrintf("Failed to get space for vertices!\n");
bsalomon@google.com934c5702012-03-20 21:17:58 +0000132 return;
133 }
134
bsalomon@google.comd62e88e2013-02-01 14:19:27 +0000135 // Go to device coords to allow batching across matrix changes
136 SkMatrix combinedMatrix;
137 if (NULL != matrix) {
138 combinedMatrix = *matrix;
139 } else {
140 combinedMatrix.reset();
141 }
jvanverth@google.com9b855c72013-03-01 18:21:22 +0000142 combinedMatrix.postConcat(drawState->getViewMatrix());
jvanverth@google.com39768252013-02-14 15:25:44 +0000143 // 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 +0000144 // modify that stage's matrix. Otherwise if the effect is generating its source rect from
145 // the vertex positions then we have to account for the view matrix change.
bsalomon@google.comc7818882013-03-20 19:19:53 +0000146 GrDrawState::AutoDeviceCoordDraw adcd(drawState);
bsalomon@google.comd62e88e2013-02-01 14:19:27 +0000147 if (!adcd.succeeded()) {
148 return;
149 }
150
jvanverth@google.com9b855c72013-03-01 18:21:22 +0000151 size_t vsize = drawState->getVertexSize();
152 GrAssert(vsize == currentOffset);
bsalomon@google.comd62e88e2013-02-01 14:19:27 +0000153
154 geo.positions()->setRectFan(rect.fLeft, rect.fTop, rect.fRight, rect.fBottom, vsize);
155 combinedMatrix.mapPointsWithStride(geo.positions(), vsize, 4);
156
157 SkRect devBounds;
158 // since we already computed the dev verts, set the bounds hint. This will help us avoid
159 // unnecessary clipping in our onDraw().
160 get_vertex_bounds(geo.vertices(), vsize, 4, &devBounds);
161
bsalomon@google.comc7818882013-03-20 19:19:53 +0000162 if (localOffset >= 0) {
163 GrPoint* coords = GrTCast<GrPoint*>(GrTCast<intptr_t>(geo.vertices()) + localOffset);
164 coords->setRectFan(localRect->fLeft, localRect->fTop,
165 localRect->fRight, localRect->fBottom,
jvanverth@google.com9b855c72013-03-01 18:21:22 +0000166 vsize);
bsalomon@google.comc7818882013-03-20 19:19:53 +0000167 if (NULL != localMatrix) {
168 localMatrix->mapPointsWithStride(coords, vsize, 4);
bsalomon@google.comd62e88e2013-02-01 14:19:27 +0000169 }
170 }
171
172 if (colorOffset >= 0) {
173 GrColor* vertColor = GrTCast<GrColor*>(GrTCast<intptr_t>(geo.vertices()) + colorOffset);
174 for (int i = 0; i < 4; ++i) {
175 *vertColor = color;
176 vertColor = (GrColor*) ((intptr_t) vertColor + vsize);
177 }
178 }
179
bsalomon@google.com6e4e6502013-02-25 20:12:45 +0000180 this->setIndexSourceToBuffer(this->getContext()->getQuadIndexBuffer());
bsalomon@google.comd62e88e2013-02-01 14:19:27 +0000181 this->drawIndexedInstances(kTriangles_GrPrimitiveType, 1, 4, 6, &devBounds);
jvanverth@google.com9b855c72013-03-01 18:21:22 +0000182
183 // to ensure that stashing the drawState ptr is valid
184 GrAssert(this->drawState() == drawState);
bsalomon@google.comd62e88e2013-02-01 14:19:27 +0000185}
186
187bool GrInOrderDrawBuffer::quickInsideClip(const SkRect& devBounds) {
188 if (!this->getDrawState().isClipState()) {
189 return true;
190 }
191 if (kUnknown_ClipProxyState == fClipProxyState) {
192 SkIRect rect;
193 bool iior;
194 this->getClip()->getConservativeBounds(this->getDrawState().getRenderTarget(), &rect, &iior);
195 if (iior) {
196 // The clip is a rect. We will remember that in fProxyClip. It is common for an edge (or
197 // all edges) of the clip to be at the edge of the RT. However, we get that clipping for
198 // free via the viewport. We don't want to think that clipping must be enabled in this
199 // case. So we extend the clip outward from the edge to avoid these false negatives.
200 fClipProxyState = kValid_ClipProxyState;
201 fClipProxy = SkRect::MakeFromIRect(rect);
202
203 if (fClipProxy.fLeft <= 0) {
204 fClipProxy.fLeft = SK_ScalarMin;
205 }
206 if (fClipProxy.fTop <= 0) {
207 fClipProxy.fTop = SK_ScalarMin;
208 }
209 if (fClipProxy.fRight >= this->getDrawState().getRenderTarget()->width()) {
210 fClipProxy.fRight = SK_ScalarMax;
211 }
212 if (fClipProxy.fBottom >= this->getDrawState().getRenderTarget()->height()) {
213 fClipProxy.fBottom = SK_ScalarMax;
214 }
215 } else {
216 fClipProxyState = kInvalid_ClipProxyState;
217 }
218 }
219 if (kValid_ClipProxyState == fClipProxyState) {
220 return fClipProxy.contains(devBounds);
221 }
222 SkPoint originOffset = {SkIntToScalar(this->getClip()->fOrigin.fX),
223 SkIntToScalar(this->getClip()->fOrigin.fY)};
224 SkRect clipSpaceBounds = devBounds;
225 clipSpaceBounds.offset(originOffset);
226 return this->getClip()->fClipStack->quickContains(clipSpaceBounds);
227}
228
229int GrInOrderDrawBuffer::concatInstancedDraw(const DrawInfo& info) {
230 GrAssert(info.isInstanced());
231
bsalomon@google.com934c5702012-03-20 21:17:58 +0000232 const GeometrySrcState& geomSrc = this->getGeomSrc();
jvanverth@google.comb75b0a02013-02-05 20:33:30 +0000233 const GrDrawState& drawState = this->getDrawState();
bsalomon@google.com934c5702012-03-20 21:17:58 +0000234
bsalomon@google.comd62e88e2013-02-01 14:19:27 +0000235 // we only attempt to concat the case when reserved verts are used with a client-specified index
236 // buffer. To make this work with client-specified VBs we'd need to know if the VB was updated
237 // between draws.
238 if (kReserved_GeometrySrcType != geomSrc.fVertexSrc ||
239 kBuffer_GeometrySrcType != geomSrc.fIndexSrc) {
240 return 0;
bsalomon@google.com934c5702012-03-20 21:17:58 +0000241 }
bsalomon@google.comd62e88e2013-02-01 14:19:27 +0000242 // Check if there is a draw info that is compatible that uses the same VB from the pool and
243 // the same IB
244 if (kDraw_Cmd != fCmds.back()) {
245 return 0;
246 }
247
248 DrawRecord* draw = &fDraws.back();
249 GeometryPoolState& poolState = fGeoPoolStateStack.back();
250 const GrVertexBuffer* vertexBuffer = poolState.fPoolVertexBuffer;
251
252 if (!draw->isInstanced() ||
253 draw->verticesPerInstance() != info.verticesPerInstance() ||
254 draw->indicesPerInstance() != info.indicesPerInstance() ||
255 draw->fVertexBuffer != vertexBuffer ||
jvanverth@google.comb75b0a02013-02-05 20:33:30 +0000256 draw->fIndexBuffer != geomSrc.fIndexBuffer) {
bsalomon@google.comd62e88e2013-02-01 14:19:27 +0000257 return 0;
258 }
259 // info does not yet account for the offset from the start of the pool's VB while the previous
260 // draw record does.
261 int adjustedStartVertex = poolState.fPoolStartVertex + info.startVertex();
262 if (draw->startVertex() + draw->vertexCount() != adjustedStartVertex) {
263 return 0;
264 }
265
266 GrAssert(poolState.fPoolStartVertex == draw->startVertex() + draw->vertexCount());
267
268 // how many instances can be concat'ed onto draw given the size of the index buffer
269 int instancesToConcat = this->indexCountInCurrentSource() / info.indicesPerInstance();
270 instancesToConcat -= draw->instanceCount();
271 instancesToConcat = GrMin(instancesToConcat, info.instanceCount());
272
273 // update the amount of reserved vertex data actually referenced in draws
skia.committer@gmail.comae683922013-02-06 07:01:54 +0000274 size_t vertexBytes = instancesToConcat * info.verticesPerInstance() *
jvanverth@google.comb75b0a02013-02-05 20:33:30 +0000275 drawState.getVertexSize();
bsalomon@google.comd62e88e2013-02-01 14:19:27 +0000276 poolState.fUsedPoolVertexBytes = GrMax(poolState.fUsedPoolVertexBytes, vertexBytes);
277
278 draw->adjustInstanceCount(instancesToConcat);
279 return instancesToConcat;
bsalomon@google.com934c5702012-03-20 21:17:58 +0000280}
281
bsalomon@google.comd62e88e2013-02-01 14:19:27 +0000282class AutoClipReenable {
283public:
284 AutoClipReenable() : fDrawState(NULL) {}
285 ~AutoClipReenable() {
286 if (NULL != fDrawState) {
287 fDrawState->enableState(GrDrawState::kClip_StateBit);
288 }
289 }
290 void set(GrDrawState* drawState) {
291 if (drawState->isClipState()) {
292 fDrawState = drawState;
293 drawState->disableState(GrDrawState::kClip_StateBit);
294 }
295 }
296private:
297 GrDrawState* fDrawState;
298};
299
bsalomon@google.com74749cd2013-01-30 16:12:41 +0000300void GrInOrderDrawBuffer::onDraw(const DrawInfo& info) {
reed@google.comac10a2d2010-12-22 21:39:39 +0000301
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000302 GeometryPoolState& poolState = fGeoPoolStateStack.back();
jvanverth@google.comb75b0a02013-02-05 20:33:30 +0000303 const GrDrawState& drawState = this->getDrawState();
bsalomon@google.comd62e88e2013-02-01 14:19:27 +0000304 AutoClipReenable acr;
305
jvanverth@google.comb75b0a02013-02-05 20:33:30 +0000306 if (drawState.isClipState() &&
bsalomon@google.comd62e88e2013-02-01 14:19:27 +0000307 NULL != info.getDevBounds() &&
308 this->quickInsideClip(*info.getDevBounds())) {
309 acr.set(this->drawState());
310 }
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000311
bsalomon@google.coma4f6b102012-06-26 21:04:22 +0000312 if (this->needsNewClip()) {
313 this->recordClip();
314 }
315 if (this->needsNewState()) {
316 this->recordState();
bsalomon@google.com86afc2a2011-02-16 16:12:19 +0000317 }
318
bsalomon@google.comd62e88e2013-02-01 14:19:27 +0000319 DrawRecord* draw;
320 if (info.isInstanced()) {
321 int instancesConcated = this->concatInstancedDraw(info);
322 if (info.instanceCount() > instancesConcated) {
323 draw = this->recordDraw(info);
324 draw->adjustInstanceCount(-instancesConcated);
325 } else {
326 return;
327 }
328 } else {
329 draw = this->recordDraw(info);
330 }
bsalomon@google.com74749cd2013-01-30 16:12:41 +0000331
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000332 switch (this->getGeomSrc().fVertexSrc) {
bsalomon@google.com74749cd2013-01-30 16:12:41 +0000333 case kBuffer_GeometrySrcType:
334 draw->fVertexBuffer = this->getGeomSrc().fVertexBuffer;
335 break;
336 case kReserved_GeometrySrcType: // fallthrough
337 case kArray_GeometrySrcType: {
skia.committer@gmail.comae683922013-02-06 07:01:54 +0000338 size_t vertexBytes = (info.vertexCount() + info.startVertex()) *
jvanverth@google.comb75b0a02013-02-05 20:33:30 +0000339 drawState.getVertexSize();
bsalomon@google.com74749cd2013-01-30 16:12:41 +0000340 poolState.fUsedPoolVertexBytes = GrMax(poolState.fUsedPoolVertexBytes, vertexBytes);
341 draw->fVertexBuffer = poolState.fPoolVertexBuffer;
bsalomon@google.comd62e88e2013-02-01 14:19:27 +0000342 draw->adjustStartVertex(poolState.fPoolStartVertex);
bsalomon@google.com74749cd2013-01-30 16:12:41 +0000343 break;
344 }
345 default:
346 GrCrash("unknown geom src type");
reed@google.comac10a2d2010-12-22 21:39:39 +0000347 }
bsalomon@google.coma4f6b102012-06-26 21:04:22 +0000348 draw->fVertexBuffer->ref();
reed@google.comac10a2d2010-12-22 21:39:39 +0000349
bsalomon@google.com74749cd2013-01-30 16:12:41 +0000350 if (info.isIndexed()) {
351 switch (this->getGeomSrc().fIndexSrc) {
352 case kBuffer_GeometrySrcType:
353 draw->fIndexBuffer = this->getGeomSrc().fIndexBuffer;
354 break;
355 case kReserved_GeometrySrcType: // fallthrough
356 case kArray_GeometrySrcType: {
357 size_t indexBytes = (info.indexCount() + info.startIndex()) * sizeof(uint16_t);
358 poolState.fUsedPoolIndexBytes = GrMax(poolState.fUsedPoolIndexBytes, indexBytes);
359 draw->fIndexBuffer = poolState.fPoolIndexBuffer;
bsalomon@google.comd62e88e2013-02-01 14:19:27 +0000360 draw->adjustStartIndex(poolState.fPoolStartIndex);
bsalomon@google.com74749cd2013-01-30 16:12:41 +0000361 break;
362 }
363 default:
364 GrCrash("unknown geom src type");
365 }
366 draw->fIndexBuffer->ref();
367 } else {
368 draw->fIndexBuffer = NULL;
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000369 }
reed@google.comac10a2d2010-12-22 21:39:39 +0000370}
371
sugoi@google.com5f74cf82012-12-17 21:16:45 +0000372GrInOrderDrawBuffer::StencilPath::StencilPath() : fStroke(SkStrokeRec::kFill_InitStyle) {}
373
374void GrInOrderDrawBuffer::onStencilPath(const GrPath* path, const SkStrokeRec& stroke,
sugoi@google.com12b4e272012-12-06 20:13:11 +0000375 SkPath::FillType fill) {
bsalomon@google.comded4f4b2012-06-28 18:48:06 +0000376 if (this->needsNewClip()) {
377 this->recordClip();
378 }
379 // Only compare the subset of GrDrawState relevant to path stenciling?
380 if (this->needsNewState()) {
381 this->recordState();
382 }
383 StencilPath* sp = this->recordStencilPath();
384 sp->fPath.reset(path);
385 path->ref();
386 sp->fFill = fill;
sugoi@google.com12b4e272012-12-06 20:13:11 +0000387 sp->fStroke = stroke;
bsalomon@google.com64aef2b2012-06-11 15:36:13 +0000388}
389
bsalomon@google.comd62e88e2013-02-01 14:19:27 +0000390void GrInOrderDrawBuffer::clear(const GrIRect* rect, GrColor color, GrRenderTarget* renderTarget) {
bsalomon@google.com6aa25c32011-04-27 19:55:29 +0000391 GrIRect r;
bsalomon@google.com1b3ce472012-08-17 13:43:08 +0000392 if (NULL == renderTarget) {
393 renderTarget = this->drawState()->getRenderTarget();
394 GrAssert(NULL != renderTarget);
395 }
bsalomon@google.com6aa25c32011-04-27 19:55:29 +0000396 if (NULL == rect) {
397 // We could do something smart and remove previous draws and clears to
398 // the current render target. If we get that smart we have to make sure
399 // those draws aren't read before this clear (render-to-texture).
bsalomon@google.com1b3ce472012-08-17 13:43:08 +0000400 r.setLTRB(0, 0, renderTarget->width(), renderTarget->height());
bsalomon@google.com6aa25c32011-04-27 19:55:29 +0000401 rect = &r;
402 }
bsalomon@google.coma4f6b102012-06-26 21:04:22 +0000403 Clear* clr = this->recordClear();
404 clr->fColor = color;
405 clr->fRect = *rect;
406 clr->fRenderTarget = renderTarget;
bsalomon@google.com1b3ce472012-08-17 13:43:08 +0000407 renderTarget->ref();
bsalomon@google.com0b335c12011-04-25 19:17:44 +0000408}
409
reed@google.comac10a2d2010-12-22 21:39:39 +0000410void GrInOrderDrawBuffer::reset() {
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000411 GrAssert(1 == fGeoPoolStateStack.count());
412 this->resetVertexSource();
413 this->resetIndexSource();
bsalomon@google.com86afc2a2011-02-16 16:12:19 +0000414 int numDraws = fDraws.count();
415 for (int d = 0; d < numDraws; ++d) {
416 // we always have a VB, but not always an IB
417 GrAssert(NULL != fDraws[d].fVertexBuffer);
418 fDraws[d].fVertexBuffer->unref();
419 GrSafeUnref(fDraws[d].fIndexBuffer);
420 }
bsalomon@google.coma4f6b102012-06-26 21:04:22 +0000421 fCmds.reset();
reed@google.comac10a2d2010-12-22 21:39:39 +0000422 fDraws.reset();
bsalomon@google.comded4f4b2012-06-28 18:48:06 +0000423 fStencilPaths.reset();
reed@google.comac10a2d2010-12-22 21:39:39 +0000424 fStates.reset();
bsalomon@google.com0b335c12011-04-25 19:17:44 +0000425 fClears.reset();
bsalomon@google.com1c13c962011-02-14 16:51:21 +0000426 fVertexPool.reset();
427 fIndexPool.reset();
reed@google.comac10a2d2010-12-22 21:39:39 +0000428 fClips.reset();
robertphillips@google.combeb1af72012-07-26 18:52:16 +0000429 fClipOrigins.reset();
bsalomon@google.coma4f6b102012-06-26 21:04:22 +0000430 fClipSet = true;
reed@google.comac10a2d2010-12-22 21:39:39 +0000431}
432
bsalomon@google.com6e4e6502013-02-25 20:12:45 +0000433bool GrInOrderDrawBuffer::flush() {
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000434 GrAssert(kReserved_GeometrySrcType != this->getGeomSrc().fVertexSrc);
435 GrAssert(kReserved_GeometrySrcType != this->getGeomSrc().fIndexSrc);
bsalomon@google.com3f5a95e2012-03-08 16:41:42 +0000436
bsalomon@google.coma4f6b102012-06-26 21:04:22 +0000437 int numCmds = fCmds.count();
bsalomon@google.com358e4272013-01-10 14:40:28 +0000438 if (0 == numCmds) {
bsalomon@google.coma4f6b102012-06-26 21:04:22 +0000439 return false;
reed@google.comac10a2d2010-12-22 21:39:39 +0000440 }
bsalomon@google.com6e4e6502013-02-25 20:12:45 +0000441 GrAssert(!fFlushing);
442
443 GrAutoTRestore<bool> flushRestore(&fFlushing);
444 fFlushing = true;
reed@google.comac10a2d2010-12-22 21:39:39 +0000445
bsalomon@google.com1c13c962011-02-14 16:51:21 +0000446 fVertexPool.unlock();
447 fIndexPool.unlock();
reed@google.comac10a2d2010-12-22 21:39:39 +0000448
bsalomon@google.com6e4e6502013-02-25 20:12:45 +0000449 GrDrawTarget::AutoClipRestore acr(fDstGpu);
450 AutoGeometryAndStatePush agasp(fDstGpu, kPreserve_ASRInit);
bsalomon@google.comca432082013-01-23 19:53:46 +0000451
452 GrDrawState playbackState;
bsalomon@google.com6e4e6502013-02-25 20:12:45 +0000453 GrDrawState* prevDrawState = fDstGpu->drawState();
bsalomon@google.coma5d056a2012-03-27 15:59:58 +0000454 prevDrawState->ref();
bsalomon@google.com6e4e6502013-02-25 20:12:45 +0000455 fDstGpu->setDrawState(&playbackState);
reed@google.comac10a2d2010-12-22 21:39:39 +0000456
robertphillips@google.combeb1af72012-07-26 18:52:16 +0000457 GrClipData clipData;
458
bsalomon@google.comded4f4b2012-06-28 18:48:06 +0000459 int currState = 0;
460 int currClip = 0;
461 int currClear = 0;
462 int currDraw = 0;
463 int currStencilPath = 0;
reed@google.comac10a2d2010-12-22 21:39:39 +0000464
bsalomon@google.coma4f6b102012-06-26 21:04:22 +0000465 for (int c = 0; c < numCmds; ++c) {
466 switch (fCmds[c]) {
467 case kDraw_Cmd: {
bsalomon@google.com74749cd2013-01-30 16:12:41 +0000468 const DrawRecord& draw = fDraws[currDraw];
bsalomon@google.com6e4e6502013-02-25 20:12:45 +0000469 fDstGpu->setVertexSourceToBuffer(draw.fVertexBuffer);
bsalomon@google.comd62e88e2013-02-01 14:19:27 +0000470 if (draw.isIndexed()) {
bsalomon@google.com6e4e6502013-02-25 20:12:45 +0000471 fDstGpu->setIndexSourceToBuffer(draw.fIndexBuffer);
bsalomon@google.coma4f6b102012-06-26 21:04:22 +0000472 }
bsalomon@google.com6e4e6502013-02-25 20:12:45 +0000473 fDstGpu->executeDraw(draw);
bsalomon@google.com0b335c12011-04-25 19:17:44 +0000474
bsalomon@google.coma4f6b102012-06-26 21:04:22 +0000475 ++currDraw;
476 break;
477 }
bsalomon@google.comded4f4b2012-06-28 18:48:06 +0000478 case kStencilPath_Cmd: {
479 const StencilPath& sp = fStencilPaths[currStencilPath];
bsalomon@google.com6e4e6502013-02-25 20:12:45 +0000480 fDstGpu->stencilPath(sp.fPath.get(), sp.fStroke, sp.fFill);
bsalomon@google.comded4f4b2012-06-28 18:48:06 +0000481 ++currStencilPath;
482 break;
483 }
bsalomon@google.coma4f6b102012-06-26 21:04:22 +0000484 case kSetState_Cmd:
bsalomon@google.comca432082013-01-23 19:53:46 +0000485 fStates[currState].restoreTo(&playbackState);
bsalomon@google.coma4f6b102012-06-26 21:04:22 +0000486 ++currState;
487 break;
488 case kSetClip_Cmd:
robertphillips@google.combeb1af72012-07-26 18:52:16 +0000489 clipData.fClipStack = &fClips[currClip];
490 clipData.fOrigin = fClipOrigins[currClip];
bsalomon@google.com6e4e6502013-02-25 20:12:45 +0000491 fDstGpu->setClip(&clipData);
bsalomon@google.coma4f6b102012-06-26 21:04:22 +0000492 ++currClip;
493 break;
494 case kClear_Cmd:
bsalomon@google.com6e4e6502013-02-25 20:12:45 +0000495 fDstGpu->clear(&fClears[currClear].fRect,
496 fClears[currClear].fColor,
497 fClears[currClear].fRenderTarget);
bsalomon@google.coma4f6b102012-06-26 21:04:22 +0000498 ++currClear;
499 break;
reed@google.comac10a2d2010-12-22 21:39:39 +0000500 }
501 }
bsalomon@google.coma4f6b102012-06-26 21:04:22 +0000502 // we should have consumed all the states, clips, etc.
503 GrAssert(fStates.count() == currState);
504 GrAssert(fClips.count() == currClip);
robertphillips@google.combeb1af72012-07-26 18:52:16 +0000505 GrAssert(fClipOrigins.count() == currClip);
bsalomon@google.coma4f6b102012-06-26 21:04:22 +0000506 GrAssert(fClears.count() == currClear);
507 GrAssert(fDraws.count() == currDraw);
508
bsalomon@google.com6e4e6502013-02-25 20:12:45 +0000509 fDstGpu->setDrawState(prevDrawState);
bsalomon@google.coma5d056a2012-03-27 15:59:58 +0000510 prevDrawState->unref();
bsalomon@google.com55e4a202013-01-11 13:54:21 +0000511 this->reset();
bsalomon@google.coma4f6b102012-06-26 21:04:22 +0000512 return true;
reed@google.comac10a2d2010-12-22 21:39:39 +0000513}
514
bsalomon@google.com97805382012-03-13 14:32:07 +0000515void GrInOrderDrawBuffer::willReserveVertexAndIndexSpace(
bsalomon@google.com97805382012-03-13 14:32:07 +0000516 int vertexCount,
517 int indexCount) {
bsalomon@google.com6e4e6502013-02-25 20:12:45 +0000518 // We use geometryHints() to know whether to flush the draw buffer. We
519 // can't flush if we are inside an unbalanced pushGeometrySource.
520 // Moreover, flushing blows away vertex and index data that was
521 // previously reserved. So if the vertex or index data is pulled from
522 // reserved space and won't be released by this request then we can't
523 // flush.
524 bool insideGeoPush = fGeoPoolStateStack.count() > 1;
bsalomon@google.com97805382012-03-13 14:32:07 +0000525
bsalomon@google.com6e4e6502013-02-25 20:12:45 +0000526 bool unreleasedVertexSpace =
527 !vertexCount &&
528 kReserved_GeometrySrcType == this->getGeomSrc().fVertexSrc;
bsalomon@google.com97805382012-03-13 14:32:07 +0000529
bsalomon@google.com6e4e6502013-02-25 20:12:45 +0000530 bool unreleasedIndexSpace =
531 !indexCount &&
532 kReserved_GeometrySrcType == this->getGeomSrc().fIndexSrc;
bsalomon@google.com97805382012-03-13 14:32:07 +0000533
bsalomon@google.com6e4e6502013-02-25 20:12:45 +0000534 // we don't want to finalize any reserved geom on the target since
535 // we don't know that the client has finished writing to it.
536 bool targetHasReservedGeom = fDstGpu->hasReservedVerticesOrIndices();
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000537
bsalomon@google.com6e4e6502013-02-25 20:12:45 +0000538 int vcount = vertexCount;
539 int icount = indexCount;
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000540
bsalomon@google.com6e4e6502013-02-25 20:12:45 +0000541 if (!insideGeoPush &&
542 !unreleasedVertexSpace &&
543 !unreleasedIndexSpace &&
544 !targetHasReservedGeom &&
545 this->geometryHints(&vcount, &icount)) {
bsalomon@google.com97805382012-03-13 14:32:07 +0000546
bsalomon@google.com6e4e6502013-02-25 20:12:45 +0000547 this->flush();
bsalomon@google.com97805382012-03-13 14:32:07 +0000548 }
549}
550
jvanverth@google.comb75b0a02013-02-05 20:33:30 +0000551bool GrInOrderDrawBuffer::geometryHints(int* vertexCount,
bsalomon@google.com1c13c962011-02-14 16:51:21 +0000552 int* indexCount) const {
553 // we will recommend a flush if the data could fit in a single
554 // preallocated buffer but none are left and it can't fit
555 // in the current buffer (which may not be prealloced).
reed@google.comac10a2d2010-12-22 21:39:39 +0000556 bool flush = false;
557 if (NULL != indexCount) {
bsalomon@google.com1c13c962011-02-14 16:51:21 +0000558 int32_t currIndices = fIndexPool.currentBufferIndices();
559 if (*indexCount > currIndices &&
560 (!fIndexPool.preallocatedBuffersRemaining() &&
561 *indexCount <= fIndexPool.preallocatedBufferIndices())) {
562
563 flush = true;
564 }
565 *indexCount = currIndices;
reed@google.comac10a2d2010-12-22 21:39:39 +0000566 }
567 if (NULL != vertexCount) {
jvanverth@google.comb75b0a02013-02-05 20:33:30 +0000568 size_t vertexSize = this->getDrawState().getVertexSize();
jvanverth@google.coma6338982013-01-31 21:34:25 +0000569 int32_t currVertices = fVertexPool.currentBufferVertices(vertexSize);
bsalomon@google.com1c13c962011-02-14 16:51:21 +0000570 if (*vertexCount > currVertices &&
571 (!fVertexPool.preallocatedBuffersRemaining() &&
jvanverth@google.coma6338982013-01-31 21:34:25 +0000572 *vertexCount <= fVertexPool.preallocatedBufferVertices(vertexSize))) {
reed@google.comac10a2d2010-12-22 21:39:39 +0000573
bsalomon@google.com1c13c962011-02-14 16:51:21 +0000574 flush = true;
reed@google.comac10a2d2010-12-22 21:39:39 +0000575 }
bsalomon@google.com1c13c962011-02-14 16:51:21 +0000576 *vertexCount = currVertices;
reed@google.comac10a2d2010-12-22 21:39:39 +0000577 }
578 return flush;
579}
580
jvanverth@google.coma6338982013-01-31 21:34:25 +0000581bool GrInOrderDrawBuffer::onReserveVertexSpace(size_t vertexSize,
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000582 int vertexCount,
583 void** vertices) {
584 GeometryPoolState& poolState = fGeoPoolStateStack.back();
585 GrAssert(vertexCount > 0);
586 GrAssert(NULL != vertices);
587 GrAssert(0 == poolState.fUsedPoolVertexBytes);
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000588
jvanverth@google.coma6338982013-01-31 21:34:25 +0000589 *vertices = fVertexPool.makeSpace(vertexSize,
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000590 vertexCount,
591 &poolState.fPoolVertexBuffer,
592 &poolState.fPoolStartVertex);
593 return NULL != *vertices;
594}
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000595
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000596bool GrInOrderDrawBuffer::onReserveIndexSpace(int indexCount, void** indices) {
597 GeometryPoolState& poolState = fGeoPoolStateStack.back();
598 GrAssert(indexCount > 0);
599 GrAssert(NULL != indices);
600 GrAssert(0 == poolState.fUsedPoolIndexBytes);
bsalomon@google.com1c13c962011-02-14 16:51:21 +0000601
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000602 *indices = fIndexPool.makeSpace(indexCount,
603 &poolState.fPoolIndexBuffer,
604 &poolState.fPoolStartIndex);
605 return NULL != *indices;
reed@google.comac10a2d2010-12-22 21:39:39 +0000606}
607
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000608void GrInOrderDrawBuffer::releaseReservedVertexSpace() {
609 GeometryPoolState& poolState = fGeoPoolStateStack.back();
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000610 const GeometrySrcState& geoSrc = this->getGeomSrc();
bsalomon@google.comd57d71a2012-08-16 16:26:33 +0000611
612 // If we get a release vertex space call then our current source should either be reserved
613 // or array (which we copied into reserved space).
614 GrAssert(kReserved_GeometrySrcType == geoSrc.fVertexSrc ||
615 kArray_GeometrySrcType == geoSrc.fVertexSrc);
bsalomon@google.com3f5a95e2012-03-08 16:41:42 +0000616
617 // When the caller reserved vertex buffer space we gave it back a pointer
618 // provided by the vertex buffer pool. At each draw we tracked the largest
619 // offset into the pool's pointer that was referenced. Now we return to the
620 // pool any portion at the tail of the allocation that no draw referenced.
jvanverth@google.comb75b0a02013-02-05 20:33:30 +0000621 size_t reservedVertexBytes = geoSrc.fVertexSize * geoSrc.fVertexCount;
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000622 fVertexPool.putBack(reservedVertexBytes -
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000623 poolState.fUsedPoolVertexBytes);
624 poolState.fUsedPoolVertexBytes = 0;
bsalomon@google.com3f5a95e2012-03-08 16:41:42 +0000625 poolState.fPoolVertexBuffer = NULL;
626 poolState.fPoolStartVertex = 0;
bsalomon@google.com1c13c962011-02-14 16:51:21 +0000627}
628
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000629void GrInOrderDrawBuffer::releaseReservedIndexSpace() {
630 GeometryPoolState& poolState = fGeoPoolStateStack.back();
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000631 const GeometrySrcState& geoSrc = this->getGeomSrc();
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000632
bsalomon@google.comd57d71a2012-08-16 16:26:33 +0000633 // If we get a release index space call then our current source should either be reserved
634 // or array (which we copied into reserved space).
635 GrAssert(kReserved_GeometrySrcType == geoSrc.fIndexSrc ||
636 kArray_GeometrySrcType == geoSrc.fIndexSrc);
bsalomon@google.com3f5a95e2012-03-08 16:41:42 +0000637
638 // Similar to releaseReservedVertexSpace we return any unused portion at
639 // the tail
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000640 size_t reservedIndexBytes = sizeof(uint16_t) * geoSrc.fIndexCount;
641 fIndexPool.putBack(reservedIndexBytes - poolState.fUsedPoolIndexBytes);
642 poolState.fUsedPoolIndexBytes = 0;
bsalomon@google.com3f5a95e2012-03-08 16:41:42 +0000643 poolState.fPoolIndexBuffer = NULL;
644 poolState.fPoolStartIndex = 0;
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000645}
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000646
bsalomon@google.combcdbbe62011-04-12 15:40:00 +0000647void GrInOrderDrawBuffer::onSetVertexSourceToArray(const void* vertexArray,
648 int vertexCount) {
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000649
650 GeometryPoolState& poolState = fGeoPoolStateStack.back();
651 GrAssert(0 == poolState.fUsedPoolVertexBytes);
bsalomon@google.com1c13c962011-02-14 16:51:21 +0000652#if GR_DEBUG
653 bool success =
654#endif
jvanverth@google.comb75b0a02013-02-05 20:33:30 +0000655 fVertexPool.appendVertices(this->getVertexSize(),
bsalomon@google.com1c13c962011-02-14 16:51:21 +0000656 vertexCount,
657 vertexArray,
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000658 &poolState.fPoolVertexBuffer,
659 &poolState.fPoolStartVertex);
bsalomon@google.com1c13c962011-02-14 16:51:21 +0000660 GR_DEBUGASSERT(success);
661}
662
bsalomon@google.combcdbbe62011-04-12 15:40:00 +0000663void GrInOrderDrawBuffer::onSetIndexSourceToArray(const void* indexArray,
664 int indexCount) {
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000665 GeometryPoolState& poolState = fGeoPoolStateStack.back();
666 GrAssert(0 == poolState.fUsedPoolIndexBytes);
bsalomon@google.com1c13c962011-02-14 16:51:21 +0000667#if GR_DEBUG
668 bool success =
669#endif
670 fIndexPool.appendIndices(indexCount,
671 indexArray,
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000672 &poolState.fPoolIndexBuffer,
673 &poolState.fPoolStartIndex);
bsalomon@google.com1c13c962011-02-14 16:51:21 +0000674 GR_DEBUGASSERT(success);
reed@google.comac10a2d2010-12-22 21:39:39 +0000675}
676
bsalomon@google.com3f5a95e2012-03-08 16:41:42 +0000677void GrInOrderDrawBuffer::releaseVertexArray() {
678 // When the client provides an array as the vertex source we handled it
679 // by copying their array into reserved space.
680 this->GrInOrderDrawBuffer::releaseReservedVertexSpace();
681}
682
683void GrInOrderDrawBuffer::releaseIndexArray() {
684 // When the client provides an array as the index source we handled it
685 // by copying their array into reserved space.
686 this->GrInOrderDrawBuffer::releaseReservedIndexSpace();
687}
688
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000689void GrInOrderDrawBuffer::geometrySourceWillPush() {
690 GeometryPoolState& poolState = fGeoPoolStateStack.push_back();
691 poolState.fUsedPoolVertexBytes = 0;
692 poolState.fUsedPoolIndexBytes = 0;
693#if GR_DEBUG
694 poolState.fPoolVertexBuffer = (GrVertexBuffer*)~0;
695 poolState.fPoolStartVertex = ~0;
696 poolState.fPoolIndexBuffer = (GrIndexBuffer*)~0;
697 poolState.fPoolStartIndex = ~0;
698#endif
699}
700
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000701void GrInOrderDrawBuffer::geometrySourceWillPop(
702 const GeometrySrcState& restoredState) {
703 GrAssert(fGeoPoolStateStack.count() > 1);
704 fGeoPoolStateStack.pop_back();
705 GeometryPoolState& poolState = fGeoPoolStateStack.back();
706 // we have to assume that any slack we had in our vertex/index data
707 // is now unreleasable because data may have been appended later in the
708 // pool.
709 if (kReserved_GeometrySrcType == restoredState.fVertexSrc ||
710 kArray_GeometrySrcType == restoredState.fVertexSrc) {
jvanverth@google.comb75b0a02013-02-05 20:33:30 +0000711 poolState.fUsedPoolVertexBytes = restoredState.fVertexSize * restoredState.fVertexCount;
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000712 }
713 if (kReserved_GeometrySrcType == restoredState.fIndexSrc ||
714 kArray_GeometrySrcType == restoredState.fIndexSrc) {
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000715 poolState.fUsedPoolIndexBytes = sizeof(uint16_t) *
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000716 restoredState.fIndexCount;
717 }
718}
719
bsalomon@google.com86afc2a2011-02-16 16:12:19 +0000720bool GrInOrderDrawBuffer::needsNewState() const {
bsalomon@google.comca432082013-01-23 19:53:46 +0000721 return fStates.empty() || !fStates.back().isEqual(this->getDrawState());
reed@google.comac10a2d2010-12-22 21:39:39 +0000722}
723
bsalomon@google.com86afc2a2011-02-16 16:12:19 +0000724bool GrInOrderDrawBuffer::needsNewClip() const {
bsalomon@google.com358e4272013-01-10 14:40:28 +0000725 GrAssert(fClips.count() == fClipOrigins.count());
726 if (this->getDrawState().isClipState()) {
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000727 if (fClipSet &&
bsalomon@google.com358e4272013-01-10 14:40:28 +0000728 (fClips.empty() ||
bsalomon@google.com02ddc8b2013-01-28 15:35:28 +0000729 fClips.back() != *this->getClip()->fClipStack ||
730 fClipOrigins.back() != this->getClip()->fOrigin)) {
bsalomon@google.com86afc2a2011-02-16 16:12:19 +0000731 return true;
732 }
reed@google.comac10a2d2010-12-22 21:39:39 +0000733 }
734 return false;
735}
bsalomon@google.comd302f142011-03-03 13:54:13 +0000736
bsalomon@google.coma4f6b102012-06-26 21:04:22 +0000737void GrInOrderDrawBuffer::recordClip() {
bsalomon@google.com02ddc8b2013-01-28 15:35:28 +0000738 fClips.push_back() = *this->getClip()->fClipStack;
739 fClipOrigins.push_back() = this->getClip()->fOrigin;
bsalomon@google.com86afc2a2011-02-16 16:12:19 +0000740 fClipSet = false;
bsalomon@google.coma4f6b102012-06-26 21:04:22 +0000741 fCmds.push_back(kSetClip_Cmd);
742}
743
bsalomon@google.coma4f6b102012-06-26 21:04:22 +0000744void GrInOrderDrawBuffer::recordState() {
bsalomon@google.comca432082013-01-23 19:53:46 +0000745 fStates.push_back().saveFrom(this->getDrawState());
bsalomon@google.coma4f6b102012-06-26 21:04:22 +0000746 fCmds.push_back(kSetState_Cmd);
747}
748
bsalomon@google.com74749cd2013-01-30 16:12:41 +0000749GrInOrderDrawBuffer::DrawRecord* GrInOrderDrawBuffer::recordDraw(const DrawInfo& info) {
bsalomon@google.comd62e88e2013-02-01 14:19:27 +0000750 fCmds.push_back(kDraw_Cmd);
751 return &fDraws.push_back(info);
bsalomon@google.com74749cd2013-01-30 16:12:41 +0000752}
753
bsalomon@google.comded4f4b2012-06-28 18:48:06 +0000754GrInOrderDrawBuffer::StencilPath* GrInOrderDrawBuffer::recordStencilPath() {
755 fCmds.push_back(kStencilPath_Cmd);
756 return &fStencilPaths.push_back();
757}
758
bsalomon@google.coma4f6b102012-06-26 21:04:22 +0000759GrInOrderDrawBuffer::Clear* GrInOrderDrawBuffer::recordClear() {
760 fCmds.push_back(kClear_Cmd);
761 return &fClears.push_back();
reed@google.comac10a2d2010-12-22 21:39:39 +0000762}
bsalomon@google.comd302f142011-03-03 13:54:13 +0000763
robertphillips@google.combeb1af72012-07-26 18:52:16 +0000764void GrInOrderDrawBuffer::clipWillBeSet(const GrClipData* newClipData) {
765 INHERITED::clipWillBeSet(newClipData);
bsalomon@google.com86afc2a2011-02-16 16:12:19 +0000766 fClipSet = true;
bsalomon@google.comd62e88e2013-02-01 14:19:27 +0000767 fClipProxyState = kUnknown_ClipProxyState;
bsalomon@google.com86afc2a2011-02-16 16:12:19 +0000768}