blob: 9e0d21393e84c6cc504a6a8626ecee3c7b30255a [file] [log] [blame]
reed@google.comac10a2d2010-12-22 21:39:39 +00001/*
epoger@google.comec3ed6a2011-07-28 14:26:00 +00002 * Copyright 2011 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
reed@google.comac10a2d2010-12-22 21:39:39 +00006 */
7
reed@google.comac10a2d2010-12-22 21:39:39 +00008#include "GrInOrderDrawBuffer.h"
commit-bot@chromium.orgfd03d4a2013-07-17 21:39:42 +00009
bsalomon@google.comded4f4b2012-06-28 18:48:06 +000010#include "GrBufferAllocPool.h"
bsalomon@google.comc26d94f2013-03-25 18:19:00 +000011#include "GrDrawTargetCaps.h"
bsalomon@google.comded4f4b2012-06-28 18:48:06 +000012#include "GrGpu.h"
13#include "GrIndexBuffer.h"
14#include "GrPath.h"
commit-bot@chromium.orgfd03d4a2013-07-17 21:39:42 +000015#include "GrPoint.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)
commit-bot@chromium.orga8916ff2013-08-16 15:53:46 +000030 , fFlushing(false)
31 , fDrawID(0) {
bsalomon@google.com18c9c192011-09-22 21:01:31 +000032
bsalomon@google.com6e4e6502013-02-25 20:12:45 +000033 fDstGpu->ref();
bsalomon@google.combcce8922013-03-25 15:38:39 +000034 fCaps.reset(SkRef(fDstGpu->caps()));
bsalomon@google.com18c9c192011-09-22 21:01:31 +000035
bsalomon@google.com1c13c962011-02-14 16:51:21 +000036 GrAssert(NULL != vertexPool);
37 GrAssert(NULL != indexPool);
bsalomon@google.com25fb21f2011-06-21 18:17:25 +000038
39 GeometryPoolState& poolState = fGeoPoolStateStack.push_back();
40 poolState.fUsedPoolVertexBytes = 0;
41 poolState.fUsedPoolIndexBytes = 0;
42#if GR_DEBUG
43 poolState.fPoolVertexBuffer = (GrVertexBuffer*)~0;
44 poolState.fPoolStartVertex = ~0;
45 poolState.fPoolIndexBuffer = (GrIndexBuffer*)~0;
46 poolState.fPoolStartIndex = ~0;
47#endif
bsalomon@google.coma4f6b102012-06-26 21:04:22 +000048 this->reset();
reed@google.comac10a2d2010-12-22 21:39:39 +000049}
50
51GrInOrderDrawBuffer::~GrInOrderDrawBuffer() {
bsalomon@google.com86afc2a2011-02-16 16:12:19 +000052 this->reset();
bsalomon@google.com4a018bb2011-10-28 19:50:21 +000053 // This must be called by before the GrDrawTarget destructor
54 this->releaseGeometry();
bsalomon@google.com6e4e6502013-02-25 20:12:45 +000055 fDstGpu->unref();
reed@google.comac10a2d2010-12-22 21:39:39 +000056}
57
bsalomon@google.com934c5702012-03-20 21:17:58 +000058////////////////////////////////////////////////////////////////////////////////
59
bsalomon@google.comd62e88e2013-02-01 14:19:27 +000060namespace {
61void get_vertex_bounds(const void* vertices,
62 size_t vertexSize,
63 int vertexCount,
64 SkRect* bounds) {
65 GrAssert(vertexSize >= sizeof(GrPoint));
66 GrAssert(vertexCount > 0);
67 const GrPoint* point = static_cast<const GrPoint*>(vertices);
68 bounds->fLeft = bounds->fRight = point->fX;
69 bounds->fTop = bounds->fBottom = point->fY;
70 for (int i = 1; i < vertexCount; ++i) {
71 point = reinterpret_cast<GrPoint*>(reinterpret_cast<intptr_t>(point) + vertexSize);
72 bounds->growToInclude(point->fX, point->fY);
73 }
74}
bsalomon@google.com934c5702012-03-20 21:17:58 +000075}
76
robertphillips@google.com42903302013-04-20 12:26:07 +000077
78namespace {
79
80extern const GrVertexAttrib kRectPosColorUVAttribs[] = {
81 {kVec2f_GrVertexAttribType, 0, kPosition_GrVertexAttribBinding},
82 {kVec4ub_GrVertexAttribType, sizeof(GrPoint), kColor_GrVertexAttribBinding},
rmistry@google.comc9f3b382013-04-22 12:45:30 +000083 {kVec2f_GrVertexAttribType, sizeof(GrPoint)+sizeof(GrColor),
robertphillips@google.com42903302013-04-20 12:26:07 +000084 kLocalCoord_GrVertexAttribBinding},
85};
86
87extern const GrVertexAttrib kRectPosUVAttribs[] = {
88 {kVec2f_GrVertexAttribType, 0, kPosition_GrVertexAttribBinding},
89 {kVec2f_GrVertexAttribType, sizeof(GrPoint), kLocalCoord_GrVertexAttribBinding},
90};
91
92static void set_vertex_attributes(GrDrawState* drawState,
93 bool hasColor, bool hasUVs,
94 int* colorOffset, int* localOffset) {
95 *colorOffset = -1;
96 *localOffset = -1;
97
98 // Using per-vertex colors allows batching across colors. (A lot of rects in a row differing
99 // only in color is a common occurrence in tables). However, having per-vertex colors disables
100 // blending optimizations because we don't know if the color will be solid or not. These
101 // optimizations help determine whether coverage and color can be blended correctly when
102 // dual-source blending isn't available. This comes into play when there is coverage. If colors
103 // were a stage it could take a hint that every vertex's color will be opaque.
104 if (hasColor && hasUVs) {
105 *colorOffset = sizeof(GrPoint);
106 *localOffset = sizeof(GrPoint) + sizeof(GrColor);
107 drawState->setVertexAttribs<kRectPosColorUVAttribs>(3);
108 } else if (hasColor) {
109 *colorOffset = sizeof(GrPoint);
110 drawState->setVertexAttribs<kRectPosColorUVAttribs>(2);
111 } else if (hasUVs) {
112 *localOffset = sizeof(GrPoint);
113 drawState->setVertexAttribs<kRectPosUVAttribs>(2);
114 } else {
115 drawState->setVertexAttribs<kRectPosUVAttribs>(1);
116 }
117}
118
119};
120
commit-bot@chromium.orgfd03d4a2013-07-17 21:39:42 +0000121void GrInOrderDrawBuffer::onDrawRect(const SkRect& rect,
bsalomon@google.com0406b9e2013-04-02 21:00:15 +0000122 const SkMatrix* matrix,
commit-bot@chromium.orgfd03d4a2013-07-17 21:39:42 +0000123 const SkRect* localRect,
bsalomon@google.com0406b9e2013-04-02 21:00:15 +0000124 const SkMatrix* localMatrix) {
bsalomon@google.comd62e88e2013-02-01 14:19:27 +0000125 GrDrawState::AutoColorRestore acr;
jvanverth@google.com9b855c72013-03-01 18:21:22 +0000126
127 GrDrawState* drawState = this->drawState();
128
129 GrColor color = drawState->getColor();
jvanverth@google.com9b855c72013-03-01 18:21:22 +0000130
robertphillips@google.com42903302013-04-20 12:26:07 +0000131 int colorOffset, localOffset;
132 set_vertex_attributes(drawState,
133 this->caps()->dualSourceBlendingSupport() || drawState->hasSolidCoverage(),
134 NULL != localRect,
135 &colorOffset, &localOffset);
136 if (colorOffset >= 0) {
bsalomon@google.comd62e88e2013-02-01 14:19:27 +0000137 // We set the draw state's color to white here. This is done so that any batching performed
138 // in our subclass's onDraw() won't get a false from GrDrawState::op== due to a color
139 // mismatch. TODO: Once vertex layout is owned by GrDrawState it should skip comparing the
rmistry@google.comc9f3b382013-04-22 12:45:30 +0000140 // constant color in its op== when the kColor layout bit is set and then we can remove
robertphillips@google.com42903302013-04-20 12:26:07 +0000141 // this.
jvanverth@google.com9b855c72013-03-01 18:21:22 +0000142 acr.set(drawState, 0xFFFFFFFF);
bsalomon@google.com86afc2a2011-02-16 16:12:19 +0000143 }
bsalomon@google.com86afc2a2011-02-16 16:12:19 +0000144
jvanverth@google.comb75b0a02013-02-05 20:33:30 +0000145 AutoReleaseGeometry geo(this, 4, 0);
bsalomon@google.comd62e88e2013-02-01 14:19:27 +0000146 if (!geo.succeeded()) {
147 GrPrintf("Failed to get space for vertices!\n");
bsalomon@google.com934c5702012-03-20 21:17:58 +0000148 return;
149 }
150
bsalomon@google.comd62e88e2013-02-01 14:19:27 +0000151 // Go to device coords to allow batching across matrix changes
152 SkMatrix combinedMatrix;
153 if (NULL != matrix) {
154 combinedMatrix = *matrix;
155 } else {
156 combinedMatrix.reset();
157 }
jvanverth@google.com9b855c72013-03-01 18:21:22 +0000158 combinedMatrix.postConcat(drawState->getViewMatrix());
jvanverth@google.com39768252013-02-14 15:25:44 +0000159 // 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 +0000160 // modify that stage's matrix. Otherwise if the effect is generating its source rect from
161 // the vertex positions then we have to account for the view matrix change.
bsalomon@google.com137f1342013-05-29 21:27:53 +0000162 GrDrawState::AutoViewMatrixRestore avmr;
163 if (!avmr.setIdentity(drawState)) {
bsalomon@google.comd62e88e2013-02-01 14:19:27 +0000164 return;
165 }
166
jvanverth@google.com9b855c72013-03-01 18:21:22 +0000167 size_t vsize = drawState->getVertexSize();
bsalomon@google.comd62e88e2013-02-01 14:19:27 +0000168
169 geo.positions()->setRectFan(rect.fLeft, rect.fTop, rect.fRight, rect.fBottom, vsize);
170 combinedMatrix.mapPointsWithStride(geo.positions(), vsize, 4);
171
172 SkRect devBounds;
173 // since we already computed the dev verts, set the bounds hint. This will help us avoid
174 // unnecessary clipping in our onDraw().
175 get_vertex_bounds(geo.vertices(), vsize, 4, &devBounds);
176
bsalomon@google.comc7818882013-03-20 19:19:53 +0000177 if (localOffset >= 0) {
178 GrPoint* coords = GrTCast<GrPoint*>(GrTCast<intptr_t>(geo.vertices()) + localOffset);
179 coords->setRectFan(localRect->fLeft, localRect->fTop,
180 localRect->fRight, localRect->fBottom,
jvanverth@google.com9b855c72013-03-01 18:21:22 +0000181 vsize);
bsalomon@google.comc7818882013-03-20 19:19:53 +0000182 if (NULL != localMatrix) {
183 localMatrix->mapPointsWithStride(coords, vsize, 4);
bsalomon@google.comd62e88e2013-02-01 14:19:27 +0000184 }
185 }
186
187 if (colorOffset >= 0) {
188 GrColor* vertColor = GrTCast<GrColor*>(GrTCast<intptr_t>(geo.vertices()) + colorOffset);
189 for (int i = 0; i < 4; ++i) {
190 *vertColor = color;
191 vertColor = (GrColor*) ((intptr_t) vertColor + vsize);
192 }
193 }
194
bsalomon@google.com6e4e6502013-02-25 20:12:45 +0000195 this->setIndexSourceToBuffer(this->getContext()->getQuadIndexBuffer());
bsalomon@google.comd62e88e2013-02-01 14:19:27 +0000196 this->drawIndexedInstances(kTriangles_GrPrimitiveType, 1, 4, 6, &devBounds);
jvanverth@google.com9b855c72013-03-01 18:21:22 +0000197
198 // to ensure that stashing the drawState ptr is valid
199 GrAssert(this->drawState() == drawState);
bsalomon@google.comd62e88e2013-02-01 14:19:27 +0000200}
201
202bool GrInOrderDrawBuffer::quickInsideClip(const SkRect& devBounds) {
203 if (!this->getDrawState().isClipState()) {
204 return true;
205 }
206 if (kUnknown_ClipProxyState == fClipProxyState) {
207 SkIRect rect;
208 bool iior;
209 this->getClip()->getConservativeBounds(this->getDrawState().getRenderTarget(), &rect, &iior);
210 if (iior) {
211 // The clip is a rect. We will remember that in fProxyClip. It is common for an edge (or
212 // all edges) of the clip to be at the edge of the RT. However, we get that clipping for
213 // free via the viewport. We don't want to think that clipping must be enabled in this
214 // case. So we extend the clip outward from the edge to avoid these false negatives.
215 fClipProxyState = kValid_ClipProxyState;
216 fClipProxy = SkRect::MakeFromIRect(rect);
217
218 if (fClipProxy.fLeft <= 0) {
219 fClipProxy.fLeft = SK_ScalarMin;
220 }
221 if (fClipProxy.fTop <= 0) {
222 fClipProxy.fTop = SK_ScalarMin;
223 }
224 if (fClipProxy.fRight >= this->getDrawState().getRenderTarget()->width()) {
225 fClipProxy.fRight = SK_ScalarMax;
226 }
227 if (fClipProxy.fBottom >= this->getDrawState().getRenderTarget()->height()) {
228 fClipProxy.fBottom = SK_ScalarMax;
229 }
230 } else {
231 fClipProxyState = kInvalid_ClipProxyState;
232 }
233 }
234 if (kValid_ClipProxyState == fClipProxyState) {
235 return fClipProxy.contains(devBounds);
236 }
237 SkPoint originOffset = {SkIntToScalar(this->getClip()->fOrigin.fX),
238 SkIntToScalar(this->getClip()->fOrigin.fY)};
239 SkRect clipSpaceBounds = devBounds;
240 clipSpaceBounds.offset(originOffset);
241 return this->getClip()->fClipStack->quickContains(clipSpaceBounds);
242}
243
244int GrInOrderDrawBuffer::concatInstancedDraw(const DrawInfo& info) {
245 GrAssert(info.isInstanced());
246
bsalomon@google.com934c5702012-03-20 21:17:58 +0000247 const GeometrySrcState& geomSrc = this->getGeomSrc();
jvanverth@google.comb75b0a02013-02-05 20:33:30 +0000248 const GrDrawState& drawState = this->getDrawState();
bsalomon@google.com934c5702012-03-20 21:17:58 +0000249
bsalomon@google.comd62e88e2013-02-01 14:19:27 +0000250 // we only attempt to concat the case when reserved verts are used with a client-specified index
251 // buffer. To make this work with client-specified VBs we'd need to know if the VB was updated
252 // between draws.
253 if (kReserved_GeometrySrcType != geomSrc.fVertexSrc ||
254 kBuffer_GeometrySrcType != geomSrc.fIndexSrc) {
255 return 0;
bsalomon@google.com934c5702012-03-20 21:17:58 +0000256 }
bsalomon@google.comd62e88e2013-02-01 14:19:27 +0000257 // Check if there is a draw info that is compatible that uses the same VB from the pool and
258 // the same IB
259 if (kDraw_Cmd != fCmds.back()) {
260 return 0;
261 }
262
263 DrawRecord* draw = &fDraws.back();
264 GeometryPoolState& poolState = fGeoPoolStateStack.back();
265 const GrVertexBuffer* vertexBuffer = poolState.fPoolVertexBuffer;
266
267 if (!draw->isInstanced() ||
268 draw->verticesPerInstance() != info.verticesPerInstance() ||
269 draw->indicesPerInstance() != info.indicesPerInstance() ||
270 draw->fVertexBuffer != vertexBuffer ||
jvanverth@google.comb75b0a02013-02-05 20:33:30 +0000271 draw->fIndexBuffer != geomSrc.fIndexBuffer) {
bsalomon@google.comd62e88e2013-02-01 14:19:27 +0000272 return 0;
273 }
274 // info does not yet account for the offset from the start of the pool's VB while the previous
275 // draw record does.
276 int adjustedStartVertex = poolState.fPoolStartVertex + info.startVertex();
277 if (draw->startVertex() + draw->vertexCount() != adjustedStartVertex) {
278 return 0;
279 }
280
281 GrAssert(poolState.fPoolStartVertex == draw->startVertex() + draw->vertexCount());
282
283 // how many instances can be concat'ed onto draw given the size of the index buffer
284 int instancesToConcat = this->indexCountInCurrentSource() / info.indicesPerInstance();
285 instancesToConcat -= draw->instanceCount();
286 instancesToConcat = GrMin(instancesToConcat, info.instanceCount());
287
288 // update the amount of reserved vertex data actually referenced in draws
skia.committer@gmail.comae683922013-02-06 07:01:54 +0000289 size_t vertexBytes = instancesToConcat * info.verticesPerInstance() *
jvanverth@google.comb75b0a02013-02-05 20:33:30 +0000290 drawState.getVertexSize();
bsalomon@google.comd62e88e2013-02-01 14:19:27 +0000291 poolState.fUsedPoolVertexBytes = GrMax(poolState.fUsedPoolVertexBytes, vertexBytes);
292
293 draw->adjustInstanceCount(instancesToConcat);
294 return instancesToConcat;
bsalomon@google.com934c5702012-03-20 21:17:58 +0000295}
296
bsalomon@google.comd62e88e2013-02-01 14:19:27 +0000297class AutoClipReenable {
298public:
299 AutoClipReenable() : fDrawState(NULL) {}
300 ~AutoClipReenable() {
301 if (NULL != fDrawState) {
302 fDrawState->enableState(GrDrawState::kClip_StateBit);
303 }
304 }
305 void set(GrDrawState* drawState) {
306 if (drawState->isClipState()) {
307 fDrawState = drawState;
308 drawState->disableState(GrDrawState::kClip_StateBit);
309 }
310 }
311private:
312 GrDrawState* fDrawState;
313};
314
bsalomon@google.com74749cd2013-01-30 16:12:41 +0000315void GrInOrderDrawBuffer::onDraw(const DrawInfo& info) {
reed@google.comac10a2d2010-12-22 21:39:39 +0000316
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000317 GeometryPoolState& poolState = fGeoPoolStateStack.back();
jvanverth@google.comb75b0a02013-02-05 20:33:30 +0000318 const GrDrawState& drawState = this->getDrawState();
bsalomon@google.comd62e88e2013-02-01 14:19:27 +0000319 AutoClipReenable acr;
320
jvanverth@google.comb75b0a02013-02-05 20:33:30 +0000321 if (drawState.isClipState() &&
bsalomon@google.comd62e88e2013-02-01 14:19:27 +0000322 NULL != info.getDevBounds() &&
323 this->quickInsideClip(*info.getDevBounds())) {
324 acr.set(this->drawState());
325 }
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000326
bsalomon@google.coma4f6b102012-06-26 21:04:22 +0000327 if (this->needsNewClip()) {
328 this->recordClip();
329 }
330 if (this->needsNewState()) {
331 this->recordState();
bsalomon@google.com86afc2a2011-02-16 16:12:19 +0000332 }
333
bsalomon@google.comd62e88e2013-02-01 14:19:27 +0000334 DrawRecord* draw;
335 if (info.isInstanced()) {
336 int instancesConcated = this->concatInstancedDraw(info);
337 if (info.instanceCount() > instancesConcated) {
338 draw = this->recordDraw(info);
339 draw->adjustInstanceCount(-instancesConcated);
340 } else {
341 return;
342 }
343 } else {
344 draw = this->recordDraw(info);
345 }
bsalomon@google.com74749cd2013-01-30 16:12:41 +0000346
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000347 switch (this->getGeomSrc().fVertexSrc) {
bsalomon@google.com74749cd2013-01-30 16:12:41 +0000348 case kBuffer_GeometrySrcType:
349 draw->fVertexBuffer = this->getGeomSrc().fVertexBuffer;
350 break;
351 case kReserved_GeometrySrcType: // fallthrough
352 case kArray_GeometrySrcType: {
skia.committer@gmail.comae683922013-02-06 07:01:54 +0000353 size_t vertexBytes = (info.vertexCount() + info.startVertex()) *
jvanverth@google.comb75b0a02013-02-05 20:33:30 +0000354 drawState.getVertexSize();
bsalomon@google.com74749cd2013-01-30 16:12:41 +0000355 poolState.fUsedPoolVertexBytes = GrMax(poolState.fUsedPoolVertexBytes, vertexBytes);
356 draw->fVertexBuffer = poolState.fPoolVertexBuffer;
bsalomon@google.comd62e88e2013-02-01 14:19:27 +0000357 draw->adjustStartVertex(poolState.fPoolStartVertex);
bsalomon@google.com74749cd2013-01-30 16:12:41 +0000358 break;
359 }
360 default:
361 GrCrash("unknown geom src type");
reed@google.comac10a2d2010-12-22 21:39:39 +0000362 }
bsalomon@google.coma4f6b102012-06-26 21:04:22 +0000363 draw->fVertexBuffer->ref();
reed@google.comac10a2d2010-12-22 21:39:39 +0000364
bsalomon@google.com74749cd2013-01-30 16:12:41 +0000365 if (info.isIndexed()) {
366 switch (this->getGeomSrc().fIndexSrc) {
367 case kBuffer_GeometrySrcType:
368 draw->fIndexBuffer = this->getGeomSrc().fIndexBuffer;
369 break;
370 case kReserved_GeometrySrcType: // fallthrough
371 case kArray_GeometrySrcType: {
372 size_t indexBytes = (info.indexCount() + info.startIndex()) * sizeof(uint16_t);
373 poolState.fUsedPoolIndexBytes = GrMax(poolState.fUsedPoolIndexBytes, indexBytes);
374 draw->fIndexBuffer = poolState.fPoolIndexBuffer;
bsalomon@google.comd62e88e2013-02-01 14:19:27 +0000375 draw->adjustStartIndex(poolState.fPoolStartIndex);
bsalomon@google.com74749cd2013-01-30 16:12:41 +0000376 break;
377 }
378 default:
379 GrCrash("unknown geom src type");
380 }
381 draw->fIndexBuffer->ref();
382 } else {
383 draw->fIndexBuffer = NULL;
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000384 }
reed@google.comac10a2d2010-12-22 21:39:39 +0000385}
386
sugoi@google.com5f74cf82012-12-17 21:16:45 +0000387GrInOrderDrawBuffer::StencilPath::StencilPath() : fStroke(SkStrokeRec::kFill_InitStyle) {}
388
389void GrInOrderDrawBuffer::onStencilPath(const GrPath* path, const SkStrokeRec& stroke,
sugoi@google.com12b4e272012-12-06 20:13:11 +0000390 SkPath::FillType fill) {
bsalomon@google.comded4f4b2012-06-28 18:48:06 +0000391 if (this->needsNewClip()) {
392 this->recordClip();
393 }
394 // Only compare the subset of GrDrawState relevant to path stenciling?
395 if (this->needsNewState()) {
396 this->recordState();
397 }
398 StencilPath* sp = this->recordStencilPath();
399 sp->fPath.reset(path);
400 path->ref();
401 sp->fFill = fill;
sugoi@google.com12b4e272012-12-06 20:13:11 +0000402 sp->fStroke = stroke;
bsalomon@google.com64aef2b2012-06-11 15:36:13 +0000403}
404
commit-bot@chromium.orgfd03d4a2013-07-17 21:39:42 +0000405void GrInOrderDrawBuffer::clear(const SkIRect* rect, GrColor color, GrRenderTarget* renderTarget) {
406 SkIRect r;
bsalomon@google.com1b3ce472012-08-17 13:43:08 +0000407 if (NULL == renderTarget) {
408 renderTarget = this->drawState()->getRenderTarget();
409 GrAssert(NULL != renderTarget);
410 }
bsalomon@google.com6aa25c32011-04-27 19:55:29 +0000411 if (NULL == rect) {
412 // We could do something smart and remove previous draws and clears to
413 // the current render target. If we get that smart we have to make sure
414 // those draws aren't read before this clear (render-to-texture).
bsalomon@google.com1b3ce472012-08-17 13:43:08 +0000415 r.setLTRB(0, 0, renderTarget->width(), renderTarget->height());
bsalomon@google.com6aa25c32011-04-27 19:55:29 +0000416 rect = &r;
417 }
bsalomon@google.coma4f6b102012-06-26 21:04:22 +0000418 Clear* clr = this->recordClear();
419 clr->fColor = color;
420 clr->fRect = *rect;
421 clr->fRenderTarget = renderTarget;
bsalomon@google.com1b3ce472012-08-17 13:43:08 +0000422 renderTarget->ref();
bsalomon@google.com0b335c12011-04-25 19:17:44 +0000423}
424
reed@google.comac10a2d2010-12-22 21:39:39 +0000425void GrInOrderDrawBuffer::reset() {
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000426 GrAssert(1 == fGeoPoolStateStack.count());
427 this->resetVertexSource();
428 this->resetIndexSource();
bsalomon@google.com86afc2a2011-02-16 16:12:19 +0000429 int numDraws = fDraws.count();
430 for (int d = 0; d < numDraws; ++d) {
431 // we always have a VB, but not always an IB
432 GrAssert(NULL != fDraws[d].fVertexBuffer);
433 fDraws[d].fVertexBuffer->unref();
434 GrSafeUnref(fDraws[d].fIndexBuffer);
435 }
bsalomon@google.coma4f6b102012-06-26 21:04:22 +0000436 fCmds.reset();
reed@google.comac10a2d2010-12-22 21:39:39 +0000437 fDraws.reset();
bsalomon@google.comded4f4b2012-06-28 18:48:06 +0000438 fStencilPaths.reset();
reed@google.comac10a2d2010-12-22 21:39:39 +0000439 fStates.reset();
bsalomon@google.com0b335c12011-04-25 19:17:44 +0000440 fClears.reset();
bsalomon@google.com1c13c962011-02-14 16:51:21 +0000441 fVertexPool.reset();
442 fIndexPool.reset();
reed@google.comac10a2d2010-12-22 21:39:39 +0000443 fClips.reset();
robertphillips@google.combeb1af72012-07-26 18:52:16 +0000444 fClipOrigins.reset();
bsalomon@google.com116ad842013-04-09 15:38:19 +0000445 fCopySurfaces.reset();
bsalomon@google.coma4f6b102012-06-26 21:04:22 +0000446 fClipSet = true;
reed@google.comac10a2d2010-12-22 21:39:39 +0000447}
448
robertphillips@google.com1267fbd2013-07-03 18:37:27 +0000449void GrInOrderDrawBuffer::flush() {
450 if (fFlushing) {
451 return;
452 }
453
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000454 GrAssert(kReserved_GeometrySrcType != this->getGeomSrc().fVertexSrc);
455 GrAssert(kReserved_GeometrySrcType != this->getGeomSrc().fIndexSrc);
bsalomon@google.com3f5a95e2012-03-08 16:41:42 +0000456
bsalomon@google.coma4f6b102012-06-26 21:04:22 +0000457 int numCmds = fCmds.count();
bsalomon@google.com358e4272013-01-10 14:40:28 +0000458 if (0 == numCmds) {
robertphillips@google.com1267fbd2013-07-03 18:37:27 +0000459 return;
reed@google.comac10a2d2010-12-22 21:39:39 +0000460 }
bsalomon@google.com6e4e6502013-02-25 20:12:45 +0000461
462 GrAutoTRestore<bool> flushRestore(&fFlushing);
463 fFlushing = true;
reed@google.comac10a2d2010-12-22 21:39:39 +0000464
bsalomon@google.com1c13c962011-02-14 16:51:21 +0000465 fVertexPool.unlock();
466 fIndexPool.unlock();
reed@google.comac10a2d2010-12-22 21:39:39 +0000467
bsalomon@google.com6e4e6502013-02-25 20:12:45 +0000468 GrDrawTarget::AutoClipRestore acr(fDstGpu);
469 AutoGeometryAndStatePush agasp(fDstGpu, kPreserve_ASRInit);
bsalomon@google.comca432082013-01-23 19:53:46 +0000470
471 GrDrawState playbackState;
bsalomon@google.com6e4e6502013-02-25 20:12:45 +0000472 GrDrawState* prevDrawState = fDstGpu->drawState();
bsalomon@google.coma5d056a2012-03-27 15:59:58 +0000473 prevDrawState->ref();
bsalomon@google.com6e4e6502013-02-25 20:12:45 +0000474 fDstGpu->setDrawState(&playbackState);
reed@google.comac10a2d2010-12-22 21:39:39 +0000475
robertphillips@google.combeb1af72012-07-26 18:52:16 +0000476 GrClipData clipData;
477
bsalomon@google.comded4f4b2012-06-28 18:48:06 +0000478 int currState = 0;
479 int currClip = 0;
480 int currClear = 0;
481 int currDraw = 0;
482 int currStencilPath = 0;
bsalomon@google.com116ad842013-04-09 15:38:19 +0000483 int currCopySurface = 0;
reed@google.comac10a2d2010-12-22 21:39:39 +0000484
bsalomon@google.coma4f6b102012-06-26 21:04:22 +0000485 for (int c = 0; c < numCmds; ++c) {
486 switch (fCmds[c]) {
487 case kDraw_Cmd: {
bsalomon@google.com74749cd2013-01-30 16:12:41 +0000488 const DrawRecord& draw = fDraws[currDraw];
bsalomon@google.com6e4e6502013-02-25 20:12:45 +0000489 fDstGpu->setVertexSourceToBuffer(draw.fVertexBuffer);
bsalomon@google.comd62e88e2013-02-01 14:19:27 +0000490 if (draw.isIndexed()) {
bsalomon@google.com6e4e6502013-02-25 20:12:45 +0000491 fDstGpu->setIndexSourceToBuffer(draw.fIndexBuffer);
bsalomon@google.coma4f6b102012-06-26 21:04:22 +0000492 }
bsalomon@google.com6e4e6502013-02-25 20:12:45 +0000493 fDstGpu->executeDraw(draw);
bsalomon@google.com0b335c12011-04-25 19:17:44 +0000494
bsalomon@google.coma4f6b102012-06-26 21:04:22 +0000495 ++currDraw;
496 break;
497 }
bsalomon@google.comded4f4b2012-06-28 18:48:06 +0000498 case kStencilPath_Cmd: {
499 const StencilPath& sp = fStencilPaths[currStencilPath];
bsalomon@google.com6e4e6502013-02-25 20:12:45 +0000500 fDstGpu->stencilPath(sp.fPath.get(), sp.fStroke, sp.fFill);
bsalomon@google.comded4f4b2012-06-28 18:48:06 +0000501 ++currStencilPath;
502 break;
503 }
bsalomon@google.coma4f6b102012-06-26 21:04:22 +0000504 case kSetState_Cmd:
bsalomon@google.comca432082013-01-23 19:53:46 +0000505 fStates[currState].restoreTo(&playbackState);
bsalomon@google.coma4f6b102012-06-26 21:04:22 +0000506 ++currState;
507 break;
508 case kSetClip_Cmd:
robertphillips@google.combeb1af72012-07-26 18:52:16 +0000509 clipData.fClipStack = &fClips[currClip];
510 clipData.fOrigin = fClipOrigins[currClip];
bsalomon@google.com6e4e6502013-02-25 20:12:45 +0000511 fDstGpu->setClip(&clipData);
bsalomon@google.coma4f6b102012-06-26 21:04:22 +0000512 ++currClip;
513 break;
514 case kClear_Cmd:
bsalomon@google.com6e4e6502013-02-25 20:12:45 +0000515 fDstGpu->clear(&fClears[currClear].fRect,
516 fClears[currClear].fColor,
517 fClears[currClear].fRenderTarget);
bsalomon@google.coma4f6b102012-06-26 21:04:22 +0000518 ++currClear;
519 break;
bsalomon@google.com116ad842013-04-09 15:38:19 +0000520 case kCopySurface_Cmd:
521 fDstGpu->copySurface(fCopySurfaces[currCopySurface].fDst.get(),
522 fCopySurfaces[currCopySurface].fSrc.get(),
523 fCopySurfaces[currCopySurface].fSrcRect,
524 fCopySurfaces[currCopySurface].fDstPoint);
525 ++currCopySurface;
526 break;
reed@google.comac10a2d2010-12-22 21:39:39 +0000527 }
528 }
bsalomon@google.coma4f6b102012-06-26 21:04:22 +0000529 // we should have consumed all the states, clips, etc.
530 GrAssert(fStates.count() == currState);
531 GrAssert(fClips.count() == currClip);
robertphillips@google.combeb1af72012-07-26 18:52:16 +0000532 GrAssert(fClipOrigins.count() == currClip);
bsalomon@google.coma4f6b102012-06-26 21:04:22 +0000533 GrAssert(fClears.count() == currClear);
534 GrAssert(fDraws.count() == currDraw);
bsalomon@google.com116ad842013-04-09 15:38:19 +0000535 GrAssert(fCopySurfaces.count() == currCopySurface);
bsalomon@google.coma4f6b102012-06-26 21:04:22 +0000536
bsalomon@google.com6e4e6502013-02-25 20:12:45 +0000537 fDstGpu->setDrawState(prevDrawState);
bsalomon@google.coma5d056a2012-03-27 15:59:58 +0000538 prevDrawState->unref();
bsalomon@google.com55e4a202013-01-11 13:54:21 +0000539 this->reset();
commit-bot@chromium.orga8916ff2013-08-16 15:53:46 +0000540 ++fDrawID;
reed@google.comac10a2d2010-12-22 21:39:39 +0000541}
542
bsalomon@google.com116ad842013-04-09 15:38:19 +0000543bool GrInOrderDrawBuffer::onCopySurface(GrSurface* dst,
544 GrSurface* src,
545 const SkIRect& srcRect,
546 const SkIPoint& dstPoint) {
547 if (fDstGpu->canCopySurface(dst, src, srcRect, dstPoint)) {
548 CopySurface* cs = this->recordCopySurface();
549 cs->fDst.reset(SkRef(dst));
550 cs->fSrc.reset(SkRef(src));
551 cs->fSrcRect = srcRect;
552 cs->fDstPoint = dstPoint;
553 return true;
554 } else {
555 return false;
556 }
557}
558
559bool GrInOrderDrawBuffer::onCanCopySurface(GrSurface* dst,
560 GrSurface* src,
561 const SkIRect& srcRect,
562 const SkIPoint& dstPoint) {
563 return fDstGpu->canCopySurface(dst, src, srcRect, dstPoint);
564}
565
bsalomon@google.comeb851172013-04-15 13:51:00 +0000566void GrInOrderDrawBuffer::initCopySurfaceDstDesc(const GrSurface* src, GrTextureDesc* desc) {
567 fDstGpu->initCopySurfaceDstDesc(src, desc);
568}
569
bsalomon@google.com97805382012-03-13 14:32:07 +0000570void GrInOrderDrawBuffer::willReserveVertexAndIndexSpace(
bsalomon@google.com97805382012-03-13 14:32:07 +0000571 int vertexCount,
572 int indexCount) {
bsalomon@google.com6e4e6502013-02-25 20:12:45 +0000573 // We use geometryHints() to know whether to flush the draw buffer. We
574 // can't flush if we are inside an unbalanced pushGeometrySource.
575 // Moreover, flushing blows away vertex and index data that was
576 // previously reserved. So if the vertex or index data is pulled from
577 // reserved space and won't be released by this request then we can't
578 // flush.
579 bool insideGeoPush = fGeoPoolStateStack.count() > 1;
bsalomon@google.com97805382012-03-13 14:32:07 +0000580
bsalomon@google.com6e4e6502013-02-25 20:12:45 +0000581 bool unreleasedVertexSpace =
582 !vertexCount &&
583 kReserved_GeometrySrcType == this->getGeomSrc().fVertexSrc;
bsalomon@google.com97805382012-03-13 14:32:07 +0000584
bsalomon@google.com6e4e6502013-02-25 20:12:45 +0000585 bool unreleasedIndexSpace =
586 !indexCount &&
587 kReserved_GeometrySrcType == this->getGeomSrc().fIndexSrc;
bsalomon@google.com97805382012-03-13 14:32:07 +0000588
bsalomon@google.com6e4e6502013-02-25 20:12:45 +0000589 // we don't want to finalize any reserved geom on the target since
590 // we don't know that the client has finished writing to it.
591 bool targetHasReservedGeom = fDstGpu->hasReservedVerticesOrIndices();
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000592
bsalomon@google.com6e4e6502013-02-25 20:12:45 +0000593 int vcount = vertexCount;
594 int icount = indexCount;
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000595
bsalomon@google.com6e4e6502013-02-25 20:12:45 +0000596 if (!insideGeoPush &&
597 !unreleasedVertexSpace &&
598 !unreleasedIndexSpace &&
599 !targetHasReservedGeom &&
600 this->geometryHints(&vcount, &icount)) {
bsalomon@google.com97805382012-03-13 14:32:07 +0000601
bsalomon@google.com6e4e6502013-02-25 20:12:45 +0000602 this->flush();
bsalomon@google.com97805382012-03-13 14:32:07 +0000603 }
604}
605
jvanverth@google.comb75b0a02013-02-05 20:33:30 +0000606bool GrInOrderDrawBuffer::geometryHints(int* vertexCount,
bsalomon@google.com1c13c962011-02-14 16:51:21 +0000607 int* indexCount) const {
608 // we will recommend a flush if the data could fit in a single
609 // preallocated buffer but none are left and it can't fit
610 // in the current buffer (which may not be prealloced).
reed@google.comac10a2d2010-12-22 21:39:39 +0000611 bool flush = false;
612 if (NULL != indexCount) {
bsalomon@google.com1c13c962011-02-14 16:51:21 +0000613 int32_t currIndices = fIndexPool.currentBufferIndices();
614 if (*indexCount > currIndices &&
615 (!fIndexPool.preallocatedBuffersRemaining() &&
616 *indexCount <= fIndexPool.preallocatedBufferIndices())) {
617
618 flush = true;
619 }
620 *indexCount = currIndices;
reed@google.comac10a2d2010-12-22 21:39:39 +0000621 }
622 if (NULL != vertexCount) {
jvanverth@google.comb75b0a02013-02-05 20:33:30 +0000623 size_t vertexSize = this->getDrawState().getVertexSize();
jvanverth@google.coma6338982013-01-31 21:34:25 +0000624 int32_t currVertices = fVertexPool.currentBufferVertices(vertexSize);
bsalomon@google.com1c13c962011-02-14 16:51:21 +0000625 if (*vertexCount > currVertices &&
626 (!fVertexPool.preallocatedBuffersRemaining() &&
jvanverth@google.coma6338982013-01-31 21:34:25 +0000627 *vertexCount <= fVertexPool.preallocatedBufferVertices(vertexSize))) {
reed@google.comac10a2d2010-12-22 21:39:39 +0000628
bsalomon@google.com1c13c962011-02-14 16:51:21 +0000629 flush = true;
reed@google.comac10a2d2010-12-22 21:39:39 +0000630 }
bsalomon@google.com1c13c962011-02-14 16:51:21 +0000631 *vertexCount = currVertices;
reed@google.comac10a2d2010-12-22 21:39:39 +0000632 }
633 return flush;
634}
635
jvanverth@google.coma6338982013-01-31 21:34:25 +0000636bool GrInOrderDrawBuffer::onReserveVertexSpace(size_t vertexSize,
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000637 int vertexCount,
638 void** vertices) {
639 GeometryPoolState& poolState = fGeoPoolStateStack.back();
640 GrAssert(vertexCount > 0);
641 GrAssert(NULL != vertices);
642 GrAssert(0 == poolState.fUsedPoolVertexBytes);
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000643
jvanverth@google.coma6338982013-01-31 21:34:25 +0000644 *vertices = fVertexPool.makeSpace(vertexSize,
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000645 vertexCount,
646 &poolState.fPoolVertexBuffer,
647 &poolState.fPoolStartVertex);
648 return NULL != *vertices;
649}
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000650
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000651bool GrInOrderDrawBuffer::onReserveIndexSpace(int indexCount, void** indices) {
652 GeometryPoolState& poolState = fGeoPoolStateStack.back();
653 GrAssert(indexCount > 0);
654 GrAssert(NULL != indices);
655 GrAssert(0 == poolState.fUsedPoolIndexBytes);
bsalomon@google.com1c13c962011-02-14 16:51:21 +0000656
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000657 *indices = fIndexPool.makeSpace(indexCount,
658 &poolState.fPoolIndexBuffer,
659 &poolState.fPoolStartIndex);
660 return NULL != *indices;
reed@google.comac10a2d2010-12-22 21:39:39 +0000661}
662
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000663void GrInOrderDrawBuffer::releaseReservedVertexSpace() {
664 GeometryPoolState& poolState = fGeoPoolStateStack.back();
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000665 const GeometrySrcState& geoSrc = this->getGeomSrc();
bsalomon@google.comd57d71a2012-08-16 16:26:33 +0000666
667 // If we get a release vertex space call then our current source should either be reserved
668 // or array (which we copied into reserved space).
669 GrAssert(kReserved_GeometrySrcType == geoSrc.fVertexSrc ||
670 kArray_GeometrySrcType == geoSrc.fVertexSrc);
bsalomon@google.com3f5a95e2012-03-08 16:41:42 +0000671
672 // When the caller reserved vertex buffer space we gave it back a pointer
673 // provided by the vertex buffer pool. At each draw we tracked the largest
674 // offset into the pool's pointer that was referenced. Now we return to the
675 // pool any portion at the tail of the allocation that no draw referenced.
jvanverth@google.comb75b0a02013-02-05 20:33:30 +0000676 size_t reservedVertexBytes = geoSrc.fVertexSize * geoSrc.fVertexCount;
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000677 fVertexPool.putBack(reservedVertexBytes -
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000678 poolState.fUsedPoolVertexBytes);
679 poolState.fUsedPoolVertexBytes = 0;
bsalomon@google.com3f5a95e2012-03-08 16:41:42 +0000680 poolState.fPoolVertexBuffer = NULL;
681 poolState.fPoolStartVertex = 0;
bsalomon@google.com1c13c962011-02-14 16:51:21 +0000682}
683
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000684void GrInOrderDrawBuffer::releaseReservedIndexSpace() {
685 GeometryPoolState& poolState = fGeoPoolStateStack.back();
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000686 const GeometrySrcState& geoSrc = this->getGeomSrc();
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000687
bsalomon@google.comd57d71a2012-08-16 16:26:33 +0000688 // If we get a release index space call then our current source should either be reserved
689 // or array (which we copied into reserved space).
690 GrAssert(kReserved_GeometrySrcType == geoSrc.fIndexSrc ||
691 kArray_GeometrySrcType == geoSrc.fIndexSrc);
bsalomon@google.com3f5a95e2012-03-08 16:41:42 +0000692
693 // Similar to releaseReservedVertexSpace we return any unused portion at
694 // the tail
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000695 size_t reservedIndexBytes = sizeof(uint16_t) * geoSrc.fIndexCount;
696 fIndexPool.putBack(reservedIndexBytes - poolState.fUsedPoolIndexBytes);
697 poolState.fUsedPoolIndexBytes = 0;
bsalomon@google.com3f5a95e2012-03-08 16:41:42 +0000698 poolState.fPoolIndexBuffer = NULL;
699 poolState.fPoolStartIndex = 0;
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000700}
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000701
bsalomon@google.combcdbbe62011-04-12 15:40:00 +0000702void GrInOrderDrawBuffer::onSetVertexSourceToArray(const void* vertexArray,
703 int vertexCount) {
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000704
705 GeometryPoolState& poolState = fGeoPoolStateStack.back();
706 GrAssert(0 == poolState.fUsedPoolVertexBytes);
bsalomon@google.com1c13c962011-02-14 16:51:21 +0000707#if GR_DEBUG
708 bool success =
709#endif
jvanverth@google.comb75b0a02013-02-05 20:33:30 +0000710 fVertexPool.appendVertices(this->getVertexSize(),
bsalomon@google.com1c13c962011-02-14 16:51:21 +0000711 vertexCount,
712 vertexArray,
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000713 &poolState.fPoolVertexBuffer,
714 &poolState.fPoolStartVertex);
bsalomon@google.com1c13c962011-02-14 16:51:21 +0000715 GR_DEBUGASSERT(success);
716}
717
bsalomon@google.combcdbbe62011-04-12 15:40:00 +0000718void GrInOrderDrawBuffer::onSetIndexSourceToArray(const void* indexArray,
719 int indexCount) {
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000720 GeometryPoolState& poolState = fGeoPoolStateStack.back();
721 GrAssert(0 == poolState.fUsedPoolIndexBytes);
bsalomon@google.com1c13c962011-02-14 16:51:21 +0000722#if GR_DEBUG
723 bool success =
724#endif
725 fIndexPool.appendIndices(indexCount,
726 indexArray,
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000727 &poolState.fPoolIndexBuffer,
728 &poolState.fPoolStartIndex);
bsalomon@google.com1c13c962011-02-14 16:51:21 +0000729 GR_DEBUGASSERT(success);
reed@google.comac10a2d2010-12-22 21:39:39 +0000730}
731
bsalomon@google.com3f5a95e2012-03-08 16:41:42 +0000732void GrInOrderDrawBuffer::releaseVertexArray() {
733 // When the client provides an array as the vertex source we handled it
734 // by copying their array into reserved space.
735 this->GrInOrderDrawBuffer::releaseReservedVertexSpace();
736}
737
738void GrInOrderDrawBuffer::releaseIndexArray() {
739 // When the client provides an array as the index source we handled it
740 // by copying their array into reserved space.
741 this->GrInOrderDrawBuffer::releaseReservedIndexSpace();
742}
743
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000744void GrInOrderDrawBuffer::geometrySourceWillPush() {
745 GeometryPoolState& poolState = fGeoPoolStateStack.push_back();
746 poolState.fUsedPoolVertexBytes = 0;
747 poolState.fUsedPoolIndexBytes = 0;
748#if GR_DEBUG
749 poolState.fPoolVertexBuffer = (GrVertexBuffer*)~0;
750 poolState.fPoolStartVertex = ~0;
751 poolState.fPoolIndexBuffer = (GrIndexBuffer*)~0;
752 poolState.fPoolStartIndex = ~0;
753#endif
754}
755
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000756void GrInOrderDrawBuffer::geometrySourceWillPop(
757 const GeometrySrcState& restoredState) {
758 GrAssert(fGeoPoolStateStack.count() > 1);
759 fGeoPoolStateStack.pop_back();
760 GeometryPoolState& poolState = fGeoPoolStateStack.back();
761 // we have to assume that any slack we had in our vertex/index data
762 // is now unreleasable because data may have been appended later in the
763 // pool.
764 if (kReserved_GeometrySrcType == restoredState.fVertexSrc ||
765 kArray_GeometrySrcType == restoredState.fVertexSrc) {
jvanverth@google.comb75b0a02013-02-05 20:33:30 +0000766 poolState.fUsedPoolVertexBytes = restoredState.fVertexSize * restoredState.fVertexCount;
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000767 }
768 if (kReserved_GeometrySrcType == restoredState.fIndexSrc ||
769 kArray_GeometrySrcType == restoredState.fIndexSrc) {
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000770 poolState.fUsedPoolIndexBytes = sizeof(uint16_t) *
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000771 restoredState.fIndexCount;
772 }
773}
774
bsalomon@google.com86afc2a2011-02-16 16:12:19 +0000775bool GrInOrderDrawBuffer::needsNewState() const {
bsalomon@google.comca432082013-01-23 19:53:46 +0000776 return fStates.empty() || !fStates.back().isEqual(this->getDrawState());
reed@google.comac10a2d2010-12-22 21:39:39 +0000777}
778
bsalomon@google.com86afc2a2011-02-16 16:12:19 +0000779bool GrInOrderDrawBuffer::needsNewClip() const {
bsalomon@google.com358e4272013-01-10 14:40:28 +0000780 GrAssert(fClips.count() == fClipOrigins.count());
781 if (this->getDrawState().isClipState()) {
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000782 if (fClipSet &&
bsalomon@google.com358e4272013-01-10 14:40:28 +0000783 (fClips.empty() ||
bsalomon@google.com02ddc8b2013-01-28 15:35:28 +0000784 fClips.back() != *this->getClip()->fClipStack ||
785 fClipOrigins.back() != this->getClip()->fOrigin)) {
bsalomon@google.com86afc2a2011-02-16 16:12:19 +0000786 return true;
787 }
reed@google.comac10a2d2010-12-22 21:39:39 +0000788 }
789 return false;
790}
bsalomon@google.comd302f142011-03-03 13:54:13 +0000791
bsalomon@google.coma4f6b102012-06-26 21:04:22 +0000792void GrInOrderDrawBuffer::recordClip() {
bsalomon@google.com02ddc8b2013-01-28 15:35:28 +0000793 fClips.push_back() = *this->getClip()->fClipStack;
794 fClipOrigins.push_back() = this->getClip()->fOrigin;
bsalomon@google.com86afc2a2011-02-16 16:12:19 +0000795 fClipSet = false;
bsalomon@google.coma4f6b102012-06-26 21:04:22 +0000796 fCmds.push_back(kSetClip_Cmd);
797}
798
bsalomon@google.coma4f6b102012-06-26 21:04:22 +0000799void GrInOrderDrawBuffer::recordState() {
bsalomon@google.comca432082013-01-23 19:53:46 +0000800 fStates.push_back().saveFrom(this->getDrawState());
bsalomon@google.coma4f6b102012-06-26 21:04:22 +0000801 fCmds.push_back(kSetState_Cmd);
802}
803
bsalomon@google.com74749cd2013-01-30 16:12:41 +0000804GrInOrderDrawBuffer::DrawRecord* GrInOrderDrawBuffer::recordDraw(const DrawInfo& info) {
bsalomon@google.comd62e88e2013-02-01 14:19:27 +0000805 fCmds.push_back(kDraw_Cmd);
806 return &fDraws.push_back(info);
bsalomon@google.com74749cd2013-01-30 16:12:41 +0000807}
808
bsalomon@google.comded4f4b2012-06-28 18:48:06 +0000809GrInOrderDrawBuffer::StencilPath* GrInOrderDrawBuffer::recordStencilPath() {
810 fCmds.push_back(kStencilPath_Cmd);
811 return &fStencilPaths.push_back();
812}
813
bsalomon@google.coma4f6b102012-06-26 21:04:22 +0000814GrInOrderDrawBuffer::Clear* GrInOrderDrawBuffer::recordClear() {
815 fCmds.push_back(kClear_Cmd);
816 return &fClears.push_back();
reed@google.comac10a2d2010-12-22 21:39:39 +0000817}
bsalomon@google.comd302f142011-03-03 13:54:13 +0000818
bsalomon@google.com116ad842013-04-09 15:38:19 +0000819GrInOrderDrawBuffer::CopySurface* GrInOrderDrawBuffer::recordCopySurface() {
820 fCmds.push_back(kCopySurface_Cmd);
821 return &fCopySurfaces.push_back();
822}
823
824
robertphillips@google.combeb1af72012-07-26 18:52:16 +0000825void GrInOrderDrawBuffer::clipWillBeSet(const GrClipData* newClipData) {
826 INHERITED::clipWillBeSet(newClipData);
bsalomon@google.com86afc2a2011-02-16 16:12:19 +0000827 fClipSet = true;
bsalomon@google.comd62e88e2013-02-01 14:19:27 +0000828 fClipProxyState = kUnknown_ClipProxyState;
bsalomon@google.com86afc2a2011-02-16 16:12:19 +0000829}