blob: b2705a4b9bee4f9bd2e9cdd859acbb808ed8a138 [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());
93 attribs.push_back(GrVertexAttrib(kVec2f_GrVertexAttribType, currentOffset));
94 currentOffset += sizeof(GrPoint);
bsalomon@google.com86afc2a2011-02-16 16:12:19 +000095
bsalomon@google.comd62e88e2013-02-01 14:19:27 +000096 // Using per-vertex colors allows batching across colors. (A lot of rects in a row differing
97 // only in color is a common occurrence in tables). However, having per-vertex colors disables
98 // blending optimizations because we don't know if the color will be solid or not. These
99 // optimizations help determine whether coverage and color can be blended correctly when
100 // dual-source blending isn't available. This comes into play when there is coverage. If colors
101 // were a stage it could take a hint that every vertex's color will be opaque.
102 if (this->getCaps().dualSourceBlendingSupport() ||
jvanverth@google.com9b855c72013-03-01 18:21:22 +0000103 drawState->hasSolidCoverage(drawState->getAttribBindings())) {
104 bindings |= GrDrawState::kColor_AttribBindingsBit;
105 drawState->setAttribIndex(GrDrawState::kColor_AttribIndex, attribs.count());
106 attribs.push_back(GrVertexAttrib(kVec4ub_GrVertexAttribType, currentOffset));
107 colorOffset = currentOffset;
108 currentOffset += sizeof(GrColor);
bsalomon@google.comd62e88e2013-02-01 14:19:27 +0000109 // We set the draw state's color to white here. This is done so that any batching performed
110 // in our subclass's onDraw() won't get a false from GrDrawState::op== due to a color
111 // mismatch. TODO: Once vertex layout is owned by GrDrawState it should skip comparing the
112 // 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 +0000113 acr.set(drawState, 0xFFFFFFFF);
bsalomon@google.com86afc2a2011-02-16 16:12:19 +0000114 }
bsalomon@google.com86afc2a2011-02-16 16:12:19 +0000115
bsalomon@google.comd62e88e2013-02-01 14:19:27 +0000116 uint32_t explicitCoordMask = 0;
jvanverth@google.com39768252013-02-14 15:25:44 +0000117 if (NULL != srcRect) {
jvanverth@google.com9b855c72013-03-01 18:21:22 +0000118 bindings |= GrDrawState::ExplicitTexCoordAttribBindingsBit(stage);
119 drawState->setAttribIndex(GrDrawState::kTexCoord_AttribIndex, attribs.count());
120 attribs.push_back(GrVertexAttrib(kVec2f_GrVertexAttribType, currentOffset));
121 texOffset = currentOffset;
122 currentOffset += sizeof(GrPoint);
jvanverth@google.com39768252013-02-14 15:25:44 +0000123 explicitCoordMask = (1 << stage);
bsalomon@google.comd62e88e2013-02-01 14:19:27 +0000124 }
125
jvanverth@google.com9b855c72013-03-01 18:21:22 +0000126 drawState->setVertexAttribs(attribs.begin(), attribs.count());
127 drawState->setAttribBindings(bindings);
jvanverth@google.comb75b0a02013-02-05 20:33:30 +0000128 AutoReleaseGeometry geo(this, 4, 0);
bsalomon@google.comd62e88e2013-02-01 14:19:27 +0000129 if (!geo.succeeded()) {
130 GrPrintf("Failed to get space for vertices!\n");
bsalomon@google.com934c5702012-03-20 21:17:58 +0000131 return;
132 }
133
bsalomon@google.comd62e88e2013-02-01 14:19:27 +0000134 // Go to device coords to allow batching across matrix changes
135 SkMatrix combinedMatrix;
136 if (NULL != matrix) {
137 combinedMatrix = *matrix;
138 } else {
139 combinedMatrix.reset();
140 }
jvanverth@google.com9b855c72013-03-01 18:21:22 +0000141 combinedMatrix.postConcat(drawState->getViewMatrix());
jvanverth@google.com39768252013-02-14 15:25:44 +0000142 // When the caller has provided an explicit source rect for a stage then we don't want to
bsalomon@google.comd62e88e2013-02-01 14:19:27 +0000143 // modify that stage's matrix. Otherwise if the effect is generating its source rect from
144 // the vertex positions then we have to account for the view matrix change.
jvanverth@google.com9b855c72013-03-01 18:21:22 +0000145 GrDrawState::AutoDeviceCoordDraw adcd(drawState, explicitCoordMask);
bsalomon@google.comd62e88e2013-02-01 14:19:27 +0000146 if (!adcd.succeeded()) {
147 return;
148 }
149
jvanverth@google.com9b855c72013-03-01 18:21:22 +0000150 size_t vsize = drawState->getVertexSize();
151 GrAssert(vsize == currentOffset);
bsalomon@google.comd62e88e2013-02-01 14:19:27 +0000152
153 geo.positions()->setRectFan(rect.fLeft, rect.fTop, rect.fRight, rect.fBottom, vsize);
154 combinedMatrix.mapPointsWithStride(geo.positions(), vsize, 4);
155
156 SkRect devBounds;
157 // since we already computed the dev verts, set the bounds hint. This will help us avoid
158 // unnecessary clipping in our onDraw().
159 get_vertex_bounds(geo.vertices(), vsize, 4, &devBounds);
160
jvanverth@google.com9b855c72013-03-01 18:21:22 +0000161 if (texOffset >= 0) {
162 GrAssert(explicitCoordMask != 0);
163 GrPoint* coords = GrTCast<GrPoint*>(GrTCast<intptr_t>(geo.vertices()) +
164 texOffset);
165 coords->setRectFan(srcRect->fLeft, srcRect->fTop,
166 srcRect->fRight, srcRect->fBottom,
167 vsize);
168 if (NULL != srcMatrix) {
169 srcMatrix->mapPointsWithStride(coords, vsize, 4);
bsalomon@google.comd62e88e2013-02-01 14:19:27 +0000170 }
171 }
172
173 if (colorOffset >= 0) {
174 GrColor* vertColor = GrTCast<GrColor*>(GrTCast<intptr_t>(geo.vertices()) + colorOffset);
175 for (int i = 0; i < 4; ++i) {
176 *vertColor = color;
177 vertColor = (GrColor*) ((intptr_t) vertColor + vsize);
178 }
179 }
180
bsalomon@google.com6e4e6502013-02-25 20:12:45 +0000181 this->setIndexSourceToBuffer(this->getContext()->getQuadIndexBuffer());
bsalomon@google.comd62e88e2013-02-01 14:19:27 +0000182 this->drawIndexedInstances(kTriangles_GrPrimitiveType, 1, 4, 6, &devBounds);
jvanverth@google.com9b855c72013-03-01 18:21:22 +0000183
184 // to ensure that stashing the drawState ptr is valid
185 GrAssert(this->drawState() == drawState);
bsalomon@google.comd62e88e2013-02-01 14:19:27 +0000186}
187
188bool GrInOrderDrawBuffer::quickInsideClip(const SkRect& devBounds) {
189 if (!this->getDrawState().isClipState()) {
190 return true;
191 }
192 if (kUnknown_ClipProxyState == fClipProxyState) {
193 SkIRect rect;
194 bool iior;
195 this->getClip()->getConservativeBounds(this->getDrawState().getRenderTarget(), &rect, &iior);
196 if (iior) {
197 // The clip is a rect. We will remember that in fProxyClip. It is common for an edge (or
198 // all edges) of the clip to be at the edge of the RT. However, we get that clipping for
199 // free via the viewport. We don't want to think that clipping must be enabled in this
200 // case. So we extend the clip outward from the edge to avoid these false negatives.
201 fClipProxyState = kValid_ClipProxyState;
202 fClipProxy = SkRect::MakeFromIRect(rect);
203
204 if (fClipProxy.fLeft <= 0) {
205 fClipProxy.fLeft = SK_ScalarMin;
206 }
207 if (fClipProxy.fTop <= 0) {
208 fClipProxy.fTop = SK_ScalarMin;
209 }
210 if (fClipProxy.fRight >= this->getDrawState().getRenderTarget()->width()) {
211 fClipProxy.fRight = SK_ScalarMax;
212 }
213 if (fClipProxy.fBottom >= this->getDrawState().getRenderTarget()->height()) {
214 fClipProxy.fBottom = SK_ScalarMax;
215 }
216 } else {
217 fClipProxyState = kInvalid_ClipProxyState;
218 }
219 }
220 if (kValid_ClipProxyState == fClipProxyState) {
221 return fClipProxy.contains(devBounds);
222 }
223 SkPoint originOffset = {SkIntToScalar(this->getClip()->fOrigin.fX),
224 SkIntToScalar(this->getClip()->fOrigin.fY)};
225 SkRect clipSpaceBounds = devBounds;
226 clipSpaceBounds.offset(originOffset);
227 return this->getClip()->fClipStack->quickContains(clipSpaceBounds);
228}
229
230int GrInOrderDrawBuffer::concatInstancedDraw(const DrawInfo& info) {
231 GrAssert(info.isInstanced());
232
bsalomon@google.com934c5702012-03-20 21:17:58 +0000233 const GeometrySrcState& geomSrc = this->getGeomSrc();
jvanverth@google.comb75b0a02013-02-05 20:33:30 +0000234 const GrDrawState& drawState = this->getDrawState();
bsalomon@google.com934c5702012-03-20 21:17:58 +0000235
bsalomon@google.comd62e88e2013-02-01 14:19:27 +0000236 // we only attempt to concat the case when reserved verts are used with a client-specified index
237 // buffer. To make this work with client-specified VBs we'd need to know if the VB was updated
238 // between draws.
239 if (kReserved_GeometrySrcType != geomSrc.fVertexSrc ||
240 kBuffer_GeometrySrcType != geomSrc.fIndexSrc) {
241 return 0;
bsalomon@google.com934c5702012-03-20 21:17:58 +0000242 }
bsalomon@google.comd62e88e2013-02-01 14:19:27 +0000243 // Check if there is a draw info that is compatible that uses the same VB from the pool and
244 // the same IB
245 if (kDraw_Cmd != fCmds.back()) {
246 return 0;
247 }
248
249 DrawRecord* draw = &fDraws.back();
250 GeometryPoolState& poolState = fGeoPoolStateStack.back();
251 const GrVertexBuffer* vertexBuffer = poolState.fPoolVertexBuffer;
252
253 if (!draw->isInstanced() ||
254 draw->verticesPerInstance() != info.verticesPerInstance() ||
255 draw->indicesPerInstance() != info.indicesPerInstance() ||
256 draw->fVertexBuffer != vertexBuffer ||
jvanverth@google.comb75b0a02013-02-05 20:33:30 +0000257 draw->fIndexBuffer != geomSrc.fIndexBuffer) {
bsalomon@google.comd62e88e2013-02-01 14:19:27 +0000258 return 0;
259 }
260 // info does not yet account for the offset from the start of the pool's VB while the previous
261 // draw record does.
262 int adjustedStartVertex = poolState.fPoolStartVertex + info.startVertex();
263 if (draw->startVertex() + draw->vertexCount() != adjustedStartVertex) {
264 return 0;
265 }
266
267 GrAssert(poolState.fPoolStartVertex == draw->startVertex() + draw->vertexCount());
268
269 // how many instances can be concat'ed onto draw given the size of the index buffer
270 int instancesToConcat = this->indexCountInCurrentSource() / info.indicesPerInstance();
271 instancesToConcat -= draw->instanceCount();
272 instancesToConcat = GrMin(instancesToConcat, info.instanceCount());
273
274 // update the amount of reserved vertex data actually referenced in draws
skia.committer@gmail.comae683922013-02-06 07:01:54 +0000275 size_t vertexBytes = instancesToConcat * info.verticesPerInstance() *
jvanverth@google.comb75b0a02013-02-05 20:33:30 +0000276 drawState.getVertexSize();
bsalomon@google.comd62e88e2013-02-01 14:19:27 +0000277 poolState.fUsedPoolVertexBytes = GrMax(poolState.fUsedPoolVertexBytes, vertexBytes);
278
279 draw->adjustInstanceCount(instancesToConcat);
280 return instancesToConcat;
bsalomon@google.com934c5702012-03-20 21:17:58 +0000281}
282
bsalomon@google.comd62e88e2013-02-01 14:19:27 +0000283class AutoClipReenable {
284public:
285 AutoClipReenable() : fDrawState(NULL) {}
286 ~AutoClipReenable() {
287 if (NULL != fDrawState) {
288 fDrawState->enableState(GrDrawState::kClip_StateBit);
289 }
290 }
291 void set(GrDrawState* drawState) {
292 if (drawState->isClipState()) {
293 fDrawState = drawState;
294 drawState->disableState(GrDrawState::kClip_StateBit);
295 }
296 }
297private:
298 GrDrawState* fDrawState;
299};
300
bsalomon@google.com74749cd2013-01-30 16:12:41 +0000301void GrInOrderDrawBuffer::onDraw(const DrawInfo& info) {
reed@google.comac10a2d2010-12-22 21:39:39 +0000302
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000303 GeometryPoolState& poolState = fGeoPoolStateStack.back();
jvanverth@google.comb75b0a02013-02-05 20:33:30 +0000304 const GrDrawState& drawState = this->getDrawState();
bsalomon@google.comd62e88e2013-02-01 14:19:27 +0000305 AutoClipReenable acr;
306
jvanverth@google.comb75b0a02013-02-05 20:33:30 +0000307 if (drawState.isClipState() &&
bsalomon@google.comd62e88e2013-02-01 14:19:27 +0000308 NULL != info.getDevBounds() &&
309 this->quickInsideClip(*info.getDevBounds())) {
310 acr.set(this->drawState());
311 }
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000312
bsalomon@google.coma4f6b102012-06-26 21:04:22 +0000313 if (this->needsNewClip()) {
314 this->recordClip();
315 }
316 if (this->needsNewState()) {
317 this->recordState();
bsalomon@google.com86afc2a2011-02-16 16:12:19 +0000318 }
319
bsalomon@google.comd62e88e2013-02-01 14:19:27 +0000320 DrawRecord* draw;
321 if (info.isInstanced()) {
322 int instancesConcated = this->concatInstancedDraw(info);
323 if (info.instanceCount() > instancesConcated) {
324 draw = this->recordDraw(info);
325 draw->adjustInstanceCount(-instancesConcated);
326 } else {
327 return;
328 }
329 } else {
330 draw = this->recordDraw(info);
331 }
bsalomon@google.com74749cd2013-01-30 16:12:41 +0000332
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000333 switch (this->getGeomSrc().fVertexSrc) {
bsalomon@google.com74749cd2013-01-30 16:12:41 +0000334 case kBuffer_GeometrySrcType:
335 draw->fVertexBuffer = this->getGeomSrc().fVertexBuffer;
336 break;
337 case kReserved_GeometrySrcType: // fallthrough
338 case kArray_GeometrySrcType: {
skia.committer@gmail.comae683922013-02-06 07:01:54 +0000339 size_t vertexBytes = (info.vertexCount() + info.startVertex()) *
jvanverth@google.comb75b0a02013-02-05 20:33:30 +0000340 drawState.getVertexSize();
bsalomon@google.com74749cd2013-01-30 16:12:41 +0000341 poolState.fUsedPoolVertexBytes = GrMax(poolState.fUsedPoolVertexBytes, vertexBytes);
342 draw->fVertexBuffer = poolState.fPoolVertexBuffer;
bsalomon@google.comd62e88e2013-02-01 14:19:27 +0000343 draw->adjustStartVertex(poolState.fPoolStartVertex);
bsalomon@google.com74749cd2013-01-30 16:12:41 +0000344 break;
345 }
346 default:
347 GrCrash("unknown geom src type");
reed@google.comac10a2d2010-12-22 21:39:39 +0000348 }
bsalomon@google.coma4f6b102012-06-26 21:04:22 +0000349 draw->fVertexBuffer->ref();
reed@google.comac10a2d2010-12-22 21:39:39 +0000350
bsalomon@google.com74749cd2013-01-30 16:12:41 +0000351 if (info.isIndexed()) {
352 switch (this->getGeomSrc().fIndexSrc) {
353 case kBuffer_GeometrySrcType:
354 draw->fIndexBuffer = this->getGeomSrc().fIndexBuffer;
355 break;
356 case kReserved_GeometrySrcType: // fallthrough
357 case kArray_GeometrySrcType: {
358 size_t indexBytes = (info.indexCount() + info.startIndex()) * sizeof(uint16_t);
359 poolState.fUsedPoolIndexBytes = GrMax(poolState.fUsedPoolIndexBytes, indexBytes);
360 draw->fIndexBuffer = poolState.fPoolIndexBuffer;
bsalomon@google.comd62e88e2013-02-01 14:19:27 +0000361 draw->adjustStartIndex(poolState.fPoolStartIndex);
bsalomon@google.com74749cd2013-01-30 16:12:41 +0000362 break;
363 }
364 default:
365 GrCrash("unknown geom src type");
366 }
367 draw->fIndexBuffer->ref();
368 } else {
369 draw->fIndexBuffer = NULL;
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000370 }
reed@google.comac10a2d2010-12-22 21:39:39 +0000371}
372
sugoi@google.com5f74cf82012-12-17 21:16:45 +0000373GrInOrderDrawBuffer::StencilPath::StencilPath() : fStroke(SkStrokeRec::kFill_InitStyle) {}
374
375void GrInOrderDrawBuffer::onStencilPath(const GrPath* path, const SkStrokeRec& stroke,
sugoi@google.com12b4e272012-12-06 20:13:11 +0000376 SkPath::FillType fill) {
bsalomon@google.comded4f4b2012-06-28 18:48:06 +0000377 if (this->needsNewClip()) {
378 this->recordClip();
379 }
380 // Only compare the subset of GrDrawState relevant to path stenciling?
381 if (this->needsNewState()) {
382 this->recordState();
383 }
384 StencilPath* sp = this->recordStencilPath();
385 sp->fPath.reset(path);
386 path->ref();
387 sp->fFill = fill;
sugoi@google.com12b4e272012-12-06 20:13:11 +0000388 sp->fStroke = stroke;
bsalomon@google.com64aef2b2012-06-11 15:36:13 +0000389}
390
bsalomon@google.comd62e88e2013-02-01 14:19:27 +0000391void GrInOrderDrawBuffer::clear(const GrIRect* rect, GrColor color, GrRenderTarget* renderTarget) {
bsalomon@google.com6aa25c32011-04-27 19:55:29 +0000392 GrIRect r;
bsalomon@google.com1b3ce472012-08-17 13:43:08 +0000393 if (NULL == renderTarget) {
394 renderTarget = this->drawState()->getRenderTarget();
395 GrAssert(NULL != renderTarget);
396 }
bsalomon@google.com6aa25c32011-04-27 19:55:29 +0000397 if (NULL == rect) {
398 // We could do something smart and remove previous draws and clears to
399 // the current render target. If we get that smart we have to make sure
400 // those draws aren't read before this clear (render-to-texture).
bsalomon@google.com1b3ce472012-08-17 13:43:08 +0000401 r.setLTRB(0, 0, renderTarget->width(), renderTarget->height());
bsalomon@google.com6aa25c32011-04-27 19:55:29 +0000402 rect = &r;
403 }
bsalomon@google.coma4f6b102012-06-26 21:04:22 +0000404 Clear* clr = this->recordClear();
405 clr->fColor = color;
406 clr->fRect = *rect;
407 clr->fRenderTarget = renderTarget;
bsalomon@google.com1b3ce472012-08-17 13:43:08 +0000408 renderTarget->ref();
bsalomon@google.com0b335c12011-04-25 19:17:44 +0000409}
410
reed@google.comac10a2d2010-12-22 21:39:39 +0000411void GrInOrderDrawBuffer::reset() {
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000412 GrAssert(1 == fGeoPoolStateStack.count());
413 this->resetVertexSource();
414 this->resetIndexSource();
bsalomon@google.com86afc2a2011-02-16 16:12:19 +0000415 int numDraws = fDraws.count();
416 for (int d = 0; d < numDraws; ++d) {
417 // we always have a VB, but not always an IB
418 GrAssert(NULL != fDraws[d].fVertexBuffer);
419 fDraws[d].fVertexBuffer->unref();
420 GrSafeUnref(fDraws[d].fIndexBuffer);
421 }
bsalomon@google.coma4f6b102012-06-26 21:04:22 +0000422 fCmds.reset();
reed@google.comac10a2d2010-12-22 21:39:39 +0000423 fDraws.reset();
bsalomon@google.comded4f4b2012-06-28 18:48:06 +0000424 fStencilPaths.reset();
reed@google.comac10a2d2010-12-22 21:39:39 +0000425 fStates.reset();
bsalomon@google.com0b335c12011-04-25 19:17:44 +0000426 fClears.reset();
bsalomon@google.com1c13c962011-02-14 16:51:21 +0000427 fVertexPool.reset();
428 fIndexPool.reset();
reed@google.comac10a2d2010-12-22 21:39:39 +0000429 fClips.reset();
robertphillips@google.combeb1af72012-07-26 18:52:16 +0000430 fClipOrigins.reset();
bsalomon@google.coma4f6b102012-06-26 21:04:22 +0000431 fClipSet = true;
reed@google.comac10a2d2010-12-22 21:39:39 +0000432}
433
bsalomon@google.com6e4e6502013-02-25 20:12:45 +0000434bool GrInOrderDrawBuffer::flush() {
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000435 GrAssert(kReserved_GeometrySrcType != this->getGeomSrc().fVertexSrc);
436 GrAssert(kReserved_GeometrySrcType != this->getGeomSrc().fIndexSrc);
bsalomon@google.com3f5a95e2012-03-08 16:41:42 +0000437
bsalomon@google.coma4f6b102012-06-26 21:04:22 +0000438 int numCmds = fCmds.count();
bsalomon@google.com358e4272013-01-10 14:40:28 +0000439 if (0 == numCmds) {
bsalomon@google.coma4f6b102012-06-26 21:04:22 +0000440 return false;
reed@google.comac10a2d2010-12-22 21:39:39 +0000441 }
bsalomon@google.com6e4e6502013-02-25 20:12:45 +0000442 GrAssert(!fFlushing);
443
444 GrAutoTRestore<bool> flushRestore(&fFlushing);
445 fFlushing = true;
reed@google.comac10a2d2010-12-22 21:39:39 +0000446
bsalomon@google.com1c13c962011-02-14 16:51:21 +0000447 fVertexPool.unlock();
448 fIndexPool.unlock();
reed@google.comac10a2d2010-12-22 21:39:39 +0000449
bsalomon@google.com6e4e6502013-02-25 20:12:45 +0000450 GrDrawTarget::AutoClipRestore acr(fDstGpu);
451 AutoGeometryAndStatePush agasp(fDstGpu, kPreserve_ASRInit);
bsalomon@google.comca432082013-01-23 19:53:46 +0000452
453 GrDrawState playbackState;
bsalomon@google.com6e4e6502013-02-25 20:12:45 +0000454 GrDrawState* prevDrawState = fDstGpu->drawState();
bsalomon@google.coma5d056a2012-03-27 15:59:58 +0000455 prevDrawState->ref();
bsalomon@google.com6e4e6502013-02-25 20:12:45 +0000456 fDstGpu->setDrawState(&playbackState);
reed@google.comac10a2d2010-12-22 21:39:39 +0000457
robertphillips@google.combeb1af72012-07-26 18:52:16 +0000458 GrClipData clipData;
459
bsalomon@google.comded4f4b2012-06-28 18:48:06 +0000460 int currState = 0;
461 int currClip = 0;
462 int currClear = 0;
463 int currDraw = 0;
464 int currStencilPath = 0;
reed@google.comac10a2d2010-12-22 21:39:39 +0000465
bsalomon@google.coma4f6b102012-06-26 21:04:22 +0000466 for (int c = 0; c < numCmds; ++c) {
467 switch (fCmds[c]) {
468 case kDraw_Cmd: {
bsalomon@google.com74749cd2013-01-30 16:12:41 +0000469 const DrawRecord& draw = fDraws[currDraw];
bsalomon@google.com6e4e6502013-02-25 20:12:45 +0000470 fDstGpu->setVertexSourceToBuffer(draw.fVertexBuffer);
bsalomon@google.comd62e88e2013-02-01 14:19:27 +0000471 if (draw.isIndexed()) {
bsalomon@google.com6e4e6502013-02-25 20:12:45 +0000472 fDstGpu->setIndexSourceToBuffer(draw.fIndexBuffer);
bsalomon@google.coma4f6b102012-06-26 21:04:22 +0000473 }
bsalomon@google.com6e4e6502013-02-25 20:12:45 +0000474 fDstGpu->executeDraw(draw);
bsalomon@google.com0b335c12011-04-25 19:17:44 +0000475
bsalomon@google.coma4f6b102012-06-26 21:04:22 +0000476 ++currDraw;
477 break;
478 }
bsalomon@google.comded4f4b2012-06-28 18:48:06 +0000479 case kStencilPath_Cmd: {
480 const StencilPath& sp = fStencilPaths[currStencilPath];
bsalomon@google.com6e4e6502013-02-25 20:12:45 +0000481 fDstGpu->stencilPath(sp.fPath.get(), sp.fStroke, sp.fFill);
bsalomon@google.comded4f4b2012-06-28 18:48:06 +0000482 ++currStencilPath;
483 break;
484 }
bsalomon@google.coma4f6b102012-06-26 21:04:22 +0000485 case kSetState_Cmd:
bsalomon@google.comca432082013-01-23 19:53:46 +0000486 fStates[currState].restoreTo(&playbackState);
bsalomon@google.coma4f6b102012-06-26 21:04:22 +0000487 ++currState;
488 break;
489 case kSetClip_Cmd:
robertphillips@google.combeb1af72012-07-26 18:52:16 +0000490 clipData.fClipStack = &fClips[currClip];
491 clipData.fOrigin = fClipOrigins[currClip];
bsalomon@google.com6e4e6502013-02-25 20:12:45 +0000492 fDstGpu->setClip(&clipData);
bsalomon@google.coma4f6b102012-06-26 21:04:22 +0000493 ++currClip;
494 break;
495 case kClear_Cmd:
bsalomon@google.com6e4e6502013-02-25 20:12:45 +0000496 fDstGpu->clear(&fClears[currClear].fRect,
497 fClears[currClear].fColor,
498 fClears[currClear].fRenderTarget);
bsalomon@google.coma4f6b102012-06-26 21:04:22 +0000499 ++currClear;
500 break;
reed@google.comac10a2d2010-12-22 21:39:39 +0000501 }
502 }
bsalomon@google.coma4f6b102012-06-26 21:04:22 +0000503 // we should have consumed all the states, clips, etc.
504 GrAssert(fStates.count() == currState);
505 GrAssert(fClips.count() == currClip);
robertphillips@google.combeb1af72012-07-26 18:52:16 +0000506 GrAssert(fClipOrigins.count() == currClip);
bsalomon@google.coma4f6b102012-06-26 21:04:22 +0000507 GrAssert(fClears.count() == currClear);
508 GrAssert(fDraws.count() == currDraw);
509
bsalomon@google.com6e4e6502013-02-25 20:12:45 +0000510 fDstGpu->setDrawState(prevDrawState);
bsalomon@google.coma5d056a2012-03-27 15:59:58 +0000511 prevDrawState->unref();
bsalomon@google.com55e4a202013-01-11 13:54:21 +0000512 this->reset();
bsalomon@google.coma4f6b102012-06-26 21:04:22 +0000513 return true;
reed@google.comac10a2d2010-12-22 21:39:39 +0000514}
515
bsalomon@google.com97805382012-03-13 14:32:07 +0000516void GrInOrderDrawBuffer::willReserveVertexAndIndexSpace(
bsalomon@google.com97805382012-03-13 14:32:07 +0000517 int vertexCount,
518 int indexCount) {
bsalomon@google.com6e4e6502013-02-25 20:12:45 +0000519 // We use geometryHints() to know whether to flush the draw buffer. We
520 // can't flush if we are inside an unbalanced pushGeometrySource.
521 // Moreover, flushing blows away vertex and index data that was
522 // previously reserved. So if the vertex or index data is pulled from
523 // reserved space and won't be released by this request then we can't
524 // flush.
525 bool insideGeoPush = fGeoPoolStateStack.count() > 1;
bsalomon@google.com97805382012-03-13 14:32:07 +0000526
bsalomon@google.com6e4e6502013-02-25 20:12:45 +0000527 bool unreleasedVertexSpace =
528 !vertexCount &&
529 kReserved_GeometrySrcType == this->getGeomSrc().fVertexSrc;
bsalomon@google.com97805382012-03-13 14:32:07 +0000530
bsalomon@google.com6e4e6502013-02-25 20:12:45 +0000531 bool unreleasedIndexSpace =
532 !indexCount &&
533 kReserved_GeometrySrcType == this->getGeomSrc().fIndexSrc;
bsalomon@google.com97805382012-03-13 14:32:07 +0000534
bsalomon@google.com6e4e6502013-02-25 20:12:45 +0000535 // we don't want to finalize any reserved geom on the target since
536 // we don't know that the client has finished writing to it.
537 bool targetHasReservedGeom = fDstGpu->hasReservedVerticesOrIndices();
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000538
bsalomon@google.com6e4e6502013-02-25 20:12:45 +0000539 int vcount = vertexCount;
540 int icount = indexCount;
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000541
bsalomon@google.com6e4e6502013-02-25 20:12:45 +0000542 if (!insideGeoPush &&
543 !unreleasedVertexSpace &&
544 !unreleasedIndexSpace &&
545 !targetHasReservedGeom &&
546 this->geometryHints(&vcount, &icount)) {
bsalomon@google.com97805382012-03-13 14:32:07 +0000547
bsalomon@google.com6e4e6502013-02-25 20:12:45 +0000548 this->flush();
bsalomon@google.com97805382012-03-13 14:32:07 +0000549 }
550}
551
jvanverth@google.comb75b0a02013-02-05 20:33:30 +0000552bool GrInOrderDrawBuffer::geometryHints(int* vertexCount,
bsalomon@google.com1c13c962011-02-14 16:51:21 +0000553 int* indexCount) const {
554 // we will recommend a flush if the data could fit in a single
555 // preallocated buffer but none are left and it can't fit
556 // in the current buffer (which may not be prealloced).
reed@google.comac10a2d2010-12-22 21:39:39 +0000557 bool flush = false;
558 if (NULL != indexCount) {
bsalomon@google.com1c13c962011-02-14 16:51:21 +0000559 int32_t currIndices = fIndexPool.currentBufferIndices();
560 if (*indexCount > currIndices &&
561 (!fIndexPool.preallocatedBuffersRemaining() &&
562 *indexCount <= fIndexPool.preallocatedBufferIndices())) {
563
564 flush = true;
565 }
566 *indexCount = currIndices;
reed@google.comac10a2d2010-12-22 21:39:39 +0000567 }
568 if (NULL != vertexCount) {
jvanverth@google.comb75b0a02013-02-05 20:33:30 +0000569 size_t vertexSize = this->getDrawState().getVertexSize();
jvanverth@google.coma6338982013-01-31 21:34:25 +0000570 int32_t currVertices = fVertexPool.currentBufferVertices(vertexSize);
bsalomon@google.com1c13c962011-02-14 16:51:21 +0000571 if (*vertexCount > currVertices &&
572 (!fVertexPool.preallocatedBuffersRemaining() &&
jvanverth@google.coma6338982013-01-31 21:34:25 +0000573 *vertexCount <= fVertexPool.preallocatedBufferVertices(vertexSize))) {
reed@google.comac10a2d2010-12-22 21:39:39 +0000574
bsalomon@google.com1c13c962011-02-14 16:51:21 +0000575 flush = true;
reed@google.comac10a2d2010-12-22 21:39:39 +0000576 }
bsalomon@google.com1c13c962011-02-14 16:51:21 +0000577 *vertexCount = currVertices;
reed@google.comac10a2d2010-12-22 21:39:39 +0000578 }
579 return flush;
580}
581
jvanverth@google.coma6338982013-01-31 21:34:25 +0000582bool GrInOrderDrawBuffer::onReserveVertexSpace(size_t vertexSize,
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000583 int vertexCount,
584 void** vertices) {
585 GeometryPoolState& poolState = fGeoPoolStateStack.back();
586 GrAssert(vertexCount > 0);
587 GrAssert(NULL != vertices);
588 GrAssert(0 == poolState.fUsedPoolVertexBytes);
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000589
jvanverth@google.coma6338982013-01-31 21:34:25 +0000590 *vertices = fVertexPool.makeSpace(vertexSize,
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000591 vertexCount,
592 &poolState.fPoolVertexBuffer,
593 &poolState.fPoolStartVertex);
594 return NULL != *vertices;
595}
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000596
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000597bool GrInOrderDrawBuffer::onReserveIndexSpace(int indexCount, void** indices) {
598 GeometryPoolState& poolState = fGeoPoolStateStack.back();
599 GrAssert(indexCount > 0);
600 GrAssert(NULL != indices);
601 GrAssert(0 == poolState.fUsedPoolIndexBytes);
bsalomon@google.com1c13c962011-02-14 16:51:21 +0000602
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000603 *indices = fIndexPool.makeSpace(indexCount,
604 &poolState.fPoolIndexBuffer,
605 &poolState.fPoolStartIndex);
606 return NULL != *indices;
reed@google.comac10a2d2010-12-22 21:39:39 +0000607}
608
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000609void GrInOrderDrawBuffer::releaseReservedVertexSpace() {
610 GeometryPoolState& poolState = fGeoPoolStateStack.back();
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000611 const GeometrySrcState& geoSrc = this->getGeomSrc();
bsalomon@google.comd57d71a2012-08-16 16:26:33 +0000612
613 // If we get a release vertex space call then our current source should either be reserved
614 // or array (which we copied into reserved space).
615 GrAssert(kReserved_GeometrySrcType == geoSrc.fVertexSrc ||
616 kArray_GeometrySrcType == geoSrc.fVertexSrc);
bsalomon@google.com3f5a95e2012-03-08 16:41:42 +0000617
618 // When the caller reserved vertex buffer space we gave it back a pointer
619 // provided by the vertex buffer pool. At each draw we tracked the largest
620 // offset into the pool's pointer that was referenced. Now we return to the
621 // pool any portion at the tail of the allocation that no draw referenced.
jvanverth@google.comb75b0a02013-02-05 20:33:30 +0000622 size_t reservedVertexBytes = geoSrc.fVertexSize * geoSrc.fVertexCount;
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000623 fVertexPool.putBack(reservedVertexBytes -
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000624 poolState.fUsedPoolVertexBytes);
625 poolState.fUsedPoolVertexBytes = 0;
bsalomon@google.com3f5a95e2012-03-08 16:41:42 +0000626 poolState.fPoolVertexBuffer = NULL;
627 poolState.fPoolStartVertex = 0;
bsalomon@google.com1c13c962011-02-14 16:51:21 +0000628}
629
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000630void GrInOrderDrawBuffer::releaseReservedIndexSpace() {
631 GeometryPoolState& poolState = fGeoPoolStateStack.back();
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000632 const GeometrySrcState& geoSrc = this->getGeomSrc();
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000633
bsalomon@google.comd57d71a2012-08-16 16:26:33 +0000634 // If we get a release index space call then our current source should either be reserved
635 // or array (which we copied into reserved space).
636 GrAssert(kReserved_GeometrySrcType == geoSrc.fIndexSrc ||
637 kArray_GeometrySrcType == geoSrc.fIndexSrc);
bsalomon@google.com3f5a95e2012-03-08 16:41:42 +0000638
639 // Similar to releaseReservedVertexSpace we return any unused portion at
640 // the tail
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000641 size_t reservedIndexBytes = sizeof(uint16_t) * geoSrc.fIndexCount;
642 fIndexPool.putBack(reservedIndexBytes - poolState.fUsedPoolIndexBytes);
643 poolState.fUsedPoolIndexBytes = 0;
bsalomon@google.com3f5a95e2012-03-08 16:41:42 +0000644 poolState.fPoolIndexBuffer = NULL;
645 poolState.fPoolStartIndex = 0;
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000646}
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000647
bsalomon@google.combcdbbe62011-04-12 15:40:00 +0000648void GrInOrderDrawBuffer::onSetVertexSourceToArray(const void* vertexArray,
649 int vertexCount) {
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000650
651 GeometryPoolState& poolState = fGeoPoolStateStack.back();
652 GrAssert(0 == poolState.fUsedPoolVertexBytes);
bsalomon@google.com1c13c962011-02-14 16:51:21 +0000653#if GR_DEBUG
654 bool success =
655#endif
jvanverth@google.comb75b0a02013-02-05 20:33:30 +0000656 fVertexPool.appendVertices(this->getVertexSize(),
bsalomon@google.com1c13c962011-02-14 16:51:21 +0000657 vertexCount,
658 vertexArray,
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000659 &poolState.fPoolVertexBuffer,
660 &poolState.fPoolStartVertex);
bsalomon@google.com1c13c962011-02-14 16:51:21 +0000661 GR_DEBUGASSERT(success);
662}
663
bsalomon@google.combcdbbe62011-04-12 15:40:00 +0000664void GrInOrderDrawBuffer::onSetIndexSourceToArray(const void* indexArray,
665 int indexCount) {
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000666 GeometryPoolState& poolState = fGeoPoolStateStack.back();
667 GrAssert(0 == poolState.fUsedPoolIndexBytes);
bsalomon@google.com1c13c962011-02-14 16:51:21 +0000668#if GR_DEBUG
669 bool success =
670#endif
671 fIndexPool.appendIndices(indexCount,
672 indexArray,
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000673 &poolState.fPoolIndexBuffer,
674 &poolState.fPoolStartIndex);
bsalomon@google.com1c13c962011-02-14 16:51:21 +0000675 GR_DEBUGASSERT(success);
reed@google.comac10a2d2010-12-22 21:39:39 +0000676}
677
bsalomon@google.com3f5a95e2012-03-08 16:41:42 +0000678void GrInOrderDrawBuffer::releaseVertexArray() {
679 // When the client provides an array as the vertex source we handled it
680 // by copying their array into reserved space.
681 this->GrInOrderDrawBuffer::releaseReservedVertexSpace();
682}
683
684void GrInOrderDrawBuffer::releaseIndexArray() {
685 // When the client provides an array as the index source we handled it
686 // by copying their array into reserved space.
687 this->GrInOrderDrawBuffer::releaseReservedIndexSpace();
688}
689
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000690void GrInOrderDrawBuffer::geometrySourceWillPush() {
691 GeometryPoolState& poolState = fGeoPoolStateStack.push_back();
692 poolState.fUsedPoolVertexBytes = 0;
693 poolState.fUsedPoolIndexBytes = 0;
694#if GR_DEBUG
695 poolState.fPoolVertexBuffer = (GrVertexBuffer*)~0;
696 poolState.fPoolStartVertex = ~0;
697 poolState.fPoolIndexBuffer = (GrIndexBuffer*)~0;
698 poolState.fPoolStartIndex = ~0;
699#endif
700}
701
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000702void GrInOrderDrawBuffer::geometrySourceWillPop(
703 const GeometrySrcState& restoredState) {
704 GrAssert(fGeoPoolStateStack.count() > 1);
705 fGeoPoolStateStack.pop_back();
706 GeometryPoolState& poolState = fGeoPoolStateStack.back();
707 // we have to assume that any slack we had in our vertex/index data
708 // is now unreleasable because data may have been appended later in the
709 // pool.
710 if (kReserved_GeometrySrcType == restoredState.fVertexSrc ||
711 kArray_GeometrySrcType == restoredState.fVertexSrc) {
jvanverth@google.comb75b0a02013-02-05 20:33:30 +0000712 poolState.fUsedPoolVertexBytes = restoredState.fVertexSize * restoredState.fVertexCount;
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000713 }
714 if (kReserved_GeometrySrcType == restoredState.fIndexSrc ||
715 kArray_GeometrySrcType == restoredState.fIndexSrc) {
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000716 poolState.fUsedPoolIndexBytes = sizeof(uint16_t) *
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000717 restoredState.fIndexCount;
718 }
719}
720
bsalomon@google.com86afc2a2011-02-16 16:12:19 +0000721bool GrInOrderDrawBuffer::needsNewState() const {
bsalomon@google.comca432082013-01-23 19:53:46 +0000722 return fStates.empty() || !fStates.back().isEqual(this->getDrawState());
reed@google.comac10a2d2010-12-22 21:39:39 +0000723}
724
bsalomon@google.com86afc2a2011-02-16 16:12:19 +0000725bool GrInOrderDrawBuffer::needsNewClip() const {
bsalomon@google.com358e4272013-01-10 14:40:28 +0000726 GrAssert(fClips.count() == fClipOrigins.count());
727 if (this->getDrawState().isClipState()) {
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000728 if (fClipSet &&
bsalomon@google.com358e4272013-01-10 14:40:28 +0000729 (fClips.empty() ||
bsalomon@google.com02ddc8b2013-01-28 15:35:28 +0000730 fClips.back() != *this->getClip()->fClipStack ||
731 fClipOrigins.back() != this->getClip()->fOrigin)) {
bsalomon@google.com86afc2a2011-02-16 16:12:19 +0000732 return true;
733 }
reed@google.comac10a2d2010-12-22 21:39:39 +0000734 }
735 return false;
736}
bsalomon@google.comd302f142011-03-03 13:54:13 +0000737
bsalomon@google.coma4f6b102012-06-26 21:04:22 +0000738void GrInOrderDrawBuffer::recordClip() {
bsalomon@google.com02ddc8b2013-01-28 15:35:28 +0000739 fClips.push_back() = *this->getClip()->fClipStack;
740 fClipOrigins.push_back() = this->getClip()->fOrigin;
bsalomon@google.com86afc2a2011-02-16 16:12:19 +0000741 fClipSet = false;
bsalomon@google.coma4f6b102012-06-26 21:04:22 +0000742 fCmds.push_back(kSetClip_Cmd);
743}
744
bsalomon@google.coma4f6b102012-06-26 21:04:22 +0000745void GrInOrderDrawBuffer::recordState() {
bsalomon@google.comca432082013-01-23 19:53:46 +0000746 fStates.push_back().saveFrom(this->getDrawState());
bsalomon@google.coma4f6b102012-06-26 21:04:22 +0000747 fCmds.push_back(kSetState_Cmd);
748}
749
bsalomon@google.com74749cd2013-01-30 16:12:41 +0000750GrInOrderDrawBuffer::DrawRecord* GrInOrderDrawBuffer::recordDraw(const DrawInfo& info) {
bsalomon@google.comd62e88e2013-02-01 14:19:27 +0000751 fCmds.push_back(kDraw_Cmd);
752 return &fDraws.push_back(info);
bsalomon@google.com74749cd2013-01-30 16:12:41 +0000753}
754
bsalomon@google.comded4f4b2012-06-28 18:48:06 +0000755GrInOrderDrawBuffer::StencilPath* GrInOrderDrawBuffer::recordStencilPath() {
756 fCmds.push_back(kStencilPath_Cmd);
757 return &fStencilPaths.push_back();
758}
759
bsalomon@google.coma4f6b102012-06-26 21:04:22 +0000760GrInOrderDrawBuffer::Clear* GrInOrderDrawBuffer::recordClear() {
761 fCmds.push_back(kClear_Cmd);
762 return &fClears.push_back();
reed@google.comac10a2d2010-12-22 21:39:39 +0000763}
bsalomon@google.comd302f142011-03-03 13:54:13 +0000764
robertphillips@google.combeb1af72012-07-26 18:52:16 +0000765void GrInOrderDrawBuffer::clipWillBeSet(const GrClipData* newClipData) {
766 INHERITED::clipWillBeSet(newClipData);
bsalomon@google.com86afc2a2011-02-16 16:12:19 +0000767 fClipSet = true;
bsalomon@google.comd62e88e2013-02-01 14:19:27 +0000768 fClipProxyState = kUnknown_ClipProxyState;
bsalomon@google.com86afc2a2011-02-16 16:12:19 +0000769}