blob: 991d858174f5949a61485fd55d5ef527bbcac21f [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"
reed@google.comac10a2d2010-12-22 21:39:39 +000016#include "GrTexture.h"
bsalomon@google.com86afc2a2011-02-16 16:12:19 +000017#include "GrVertexBuffer.h"
reed@google.comac10a2d2010-12-22 21:39:39 +000018
bsalomon@google.com471d4712011-08-23 15:45:25 +000019GrInOrderDrawBuffer::GrInOrderDrawBuffer(const GrGpu* gpu,
20 GrVertexBufferAllocPool* vertexPool,
bsalomon@google.com25fb21f2011-06-21 18:17:25 +000021 GrIndexBufferAllocPool* indexPool)
bsalomon@google.com97805382012-03-13 14:32:07 +000022 : fAutoFlushTarget(NULL)
23 , fClipSet(true)
bsalomon@google.comd62e88e2013-02-01 14:19:27 +000024 , fClipProxyState(kUnknown_ClipProxyState)
robertphillips@google.com69705572012-03-21 19:46:50 +000025 , fVertexPool(*vertexPool)
26 , fIndexPool(*indexPool)
robertphillips@google.comc82a8b72012-06-21 20:15:48 +000027 , fFlushing(false) {
bsalomon@google.com18c9c192011-09-22 21:01:31 +000028
bsalomon@google.comd62e88e2013-02-01 14:19:27 +000029 fGpu.reset(SkRef(gpu));
bsalomon@google.com18c9c192011-09-22 21:01:31 +000030 fCaps = gpu->getCaps();
31
bsalomon@google.com1c13c962011-02-14 16:51:21 +000032 GrAssert(NULL != vertexPool);
33 GrAssert(NULL != indexPool);
bsalomon@google.com25fb21f2011-06-21 18:17:25 +000034
35 GeometryPoolState& poolState = fGeoPoolStateStack.push_back();
36 poolState.fUsedPoolVertexBytes = 0;
37 poolState.fUsedPoolIndexBytes = 0;
38#if GR_DEBUG
39 poolState.fPoolVertexBuffer = (GrVertexBuffer*)~0;
40 poolState.fPoolStartVertex = ~0;
41 poolState.fPoolIndexBuffer = (GrIndexBuffer*)~0;
42 poolState.fPoolStartIndex = ~0;
43#endif
bsalomon@google.coma4f6b102012-06-26 21:04:22 +000044 this->reset();
reed@google.comac10a2d2010-12-22 21:39:39 +000045}
46
47GrInOrderDrawBuffer::~GrInOrderDrawBuffer() {
bsalomon@google.com86afc2a2011-02-16 16:12:19 +000048 this->reset();
bsalomon@google.com4a018bb2011-10-28 19:50:21 +000049 // This must be called by before the GrDrawTarget destructor
50 this->releaseGeometry();
bsalomon@google.com97805382012-03-13 14:32:07 +000051 GrSafeUnref(fAutoFlushTarget);
reed@google.comac10a2d2010-12-22 21:39:39 +000052}
53
bsalomon@google.com934c5702012-03-20 21:17:58 +000054////////////////////////////////////////////////////////////////////////////////
55
bsalomon@google.comd62e88e2013-02-01 14:19:27 +000056namespace {
57void get_vertex_bounds(const void* vertices,
58 size_t vertexSize,
59 int vertexCount,
60 SkRect* bounds) {
61 GrAssert(vertexSize >= sizeof(GrPoint));
62 GrAssert(vertexCount > 0);
63 const GrPoint* point = static_cast<const GrPoint*>(vertices);
64 bounds->fLeft = bounds->fRight = point->fX;
65 bounds->fTop = bounds->fBottom = point->fY;
66 for (int i = 1; i < vertexCount; ++i) {
67 point = reinterpret_cast<GrPoint*>(reinterpret_cast<intptr_t>(point) + vertexSize);
68 bounds->growToInclude(point->fX, point->fY);
69 }
70}
bsalomon@google.com934c5702012-03-20 21:17:58 +000071}
72
bsalomon@google.comd302f142011-03-03 13:54:13 +000073void GrInOrderDrawBuffer::drawRect(const GrRect& rect,
bsalomon@google.comb9086a02012-11-01 18:02:54 +000074 const SkMatrix* matrix,
bsalomon@google.com86afc2a2011-02-16 16:12:19 +000075 const GrRect* srcRects[],
bsalomon@google.comb9086a02012-11-01 18:02:54 +000076 const SkMatrix* srcMatrices[]) {
bsalomon@google.comd302f142011-03-03 13:54:13 +000077
bsalomon@google.comd62e88e2013-02-01 14:19:27 +000078 GrVertexLayout layout = 0;
79 GrDrawState::AutoColorRestore acr;
80 GrColor color = this->drawState()->getColor();
bsalomon@google.com86afc2a2011-02-16 16:12:19 +000081
bsalomon@google.comd62e88e2013-02-01 14:19:27 +000082 // Using per-vertex colors allows batching across colors. (A lot of rects in a row differing
83 // only in color is a common occurrence in tables). However, having per-vertex colors disables
84 // blending optimizations because we don't know if the color will be solid or not. These
85 // optimizations help determine whether coverage and color can be blended correctly when
86 // dual-source blending isn't available. This comes into play when there is coverage. If colors
87 // were a stage it could take a hint that every vertex's color will be opaque.
88 if (this->getCaps().dualSourceBlendingSupport() ||
jvanverth@google.comb75b0a02013-02-05 20:33:30 +000089 this->getDrawState().hasSolidCoverage(this->getDrawState().getVertexLayout())) {
bsalomon@google.comd62e88e2013-02-01 14:19:27 +000090 layout |= GrDrawState::kColor_VertexLayoutBit;;
91 // We set the draw state's color to white here. This is done so that any batching performed
92 // in our subclass's onDraw() won't get a false from GrDrawState::op== due to a color
93 // mismatch. TODO: Once vertex layout is owned by GrDrawState it should skip comparing the
94 // constant color in its op== when the kColor layout bit is set and then we can remove this.
95 acr.set(this->drawState(), 0xFFFFFFFF);
bsalomon@google.com86afc2a2011-02-16 16:12:19 +000096 }
bsalomon@google.com86afc2a2011-02-16 16:12:19 +000097
bsalomon@google.comd62e88e2013-02-01 14:19:27 +000098 uint32_t explicitCoordMask = 0;
99 if (NULL != srcRects) {
100 for (int s = 0; s < GrDrawState::kNumStages; ++s) {
101 int numTC = 0;
102 if (NULL != srcRects[s]) {
103 layout |= GrDrawState::StageTexCoordVertexLayoutBit(s, numTC);
104 ++numTC;
105 explicitCoordMask |= (1 << s);
106 }
107 }
108 }
109
jvanverth@google.comb75b0a02013-02-05 20:33:30 +0000110 this->drawState()->setVertexLayout(layout);
111 AutoReleaseGeometry geo(this, 4, 0);
bsalomon@google.comd62e88e2013-02-01 14:19:27 +0000112 if (!geo.succeeded()) {
113 GrPrintf("Failed to get space for vertices!\n");
bsalomon@google.com934c5702012-03-20 21:17:58 +0000114 return;
115 }
116
bsalomon@google.comd62e88e2013-02-01 14:19:27 +0000117 // Go to device coords to allow batching across matrix changes
118 SkMatrix combinedMatrix;
119 if (NULL != matrix) {
120 combinedMatrix = *matrix;
121 } else {
122 combinedMatrix.reset();
123 }
124 combinedMatrix.postConcat(this->drawState()->getViewMatrix());
125 // When the caller has provided an explicit source rects for a stage then we don't want to
126 // modify that stage's matrix. Otherwise if the effect is generating its source rect from
127 // the vertex positions then we have to account for the view matrix change.
128 GrDrawState::AutoDeviceCoordDraw adcd(this->drawState(), explicitCoordMask);
129 if (!adcd.succeeded()) {
130 return;
131 }
132
133 int stageOffsets[GrDrawState::kNumStages], colorOffset;
134 int vsize = GrDrawState::VertexSizeAndOffsetsByStage(layout, stageOffsets,
135 &colorOffset, NULL, NULL);
136
137 geo.positions()->setRectFan(rect.fLeft, rect.fTop, rect.fRight, rect.fBottom, vsize);
138 combinedMatrix.mapPointsWithStride(geo.positions(), vsize, 4);
139
140 SkRect devBounds;
141 // since we already computed the dev verts, set the bounds hint. This will help us avoid
142 // unnecessary clipping in our onDraw().
143 get_vertex_bounds(geo.vertices(), vsize, 4, &devBounds);
144
145 for (int i = 0; i < GrDrawState::kNumStages; ++i) {
146 if (explicitCoordMask & (1 << i)) {
reed@google.com009dfe22013-02-01 15:05:18 +0000147 GrAssert(0 != stageOffsets[i]);
bsalomon@google.comd62e88e2013-02-01 14:19:27 +0000148 GrPoint* coords = GrTCast<GrPoint*>(GrTCast<intptr_t>(geo.vertices()) +
149 stageOffsets[i]);
150 coords->setRectFan(srcRects[i]->fLeft, srcRects[i]->fTop,
151 srcRects[i]->fRight, srcRects[i]->fBottom,
152 vsize);
153 if (NULL != srcMatrices && NULL != srcMatrices[i]) {
154 srcMatrices[i]->mapPointsWithStride(coords, vsize, 4);
155 }
156 } else {
reed@google.com009dfe22013-02-01 15:05:18 +0000157 GrAssert(0 == stageOffsets[i]);
bsalomon@google.comd62e88e2013-02-01 14:19:27 +0000158 }
159 }
160
161 if (colorOffset >= 0) {
162 GrColor* vertColor = GrTCast<GrColor*>(GrTCast<intptr_t>(geo.vertices()) + colorOffset);
163 for (int i = 0; i < 4; ++i) {
164 *vertColor = color;
165 vertColor = (GrColor*) ((intptr_t) vertColor + vsize);
166 }
167 }
168
169 this->setIndexSourceToBuffer(fGpu->getQuadIndexBuffer());
170 this->drawIndexedInstances(kTriangles_GrPrimitiveType, 1, 4, 6, &devBounds);
171}
172
173bool GrInOrderDrawBuffer::quickInsideClip(const SkRect& devBounds) {
174 if (!this->getDrawState().isClipState()) {
175 return true;
176 }
177 if (kUnknown_ClipProxyState == fClipProxyState) {
178 SkIRect rect;
179 bool iior;
180 this->getClip()->getConservativeBounds(this->getDrawState().getRenderTarget(), &rect, &iior);
181 if (iior) {
182 // The clip is a rect. We will remember that in fProxyClip. It is common for an edge (or
183 // all edges) of the clip to be at the edge of the RT. However, we get that clipping for
184 // free via the viewport. We don't want to think that clipping must be enabled in this
185 // case. So we extend the clip outward from the edge to avoid these false negatives.
186 fClipProxyState = kValid_ClipProxyState;
187 fClipProxy = SkRect::MakeFromIRect(rect);
188
189 if (fClipProxy.fLeft <= 0) {
190 fClipProxy.fLeft = SK_ScalarMin;
191 }
192 if (fClipProxy.fTop <= 0) {
193 fClipProxy.fTop = SK_ScalarMin;
194 }
195 if (fClipProxy.fRight >= this->getDrawState().getRenderTarget()->width()) {
196 fClipProxy.fRight = SK_ScalarMax;
197 }
198 if (fClipProxy.fBottom >= this->getDrawState().getRenderTarget()->height()) {
199 fClipProxy.fBottom = SK_ScalarMax;
200 }
201 } else {
202 fClipProxyState = kInvalid_ClipProxyState;
203 }
204 }
205 if (kValid_ClipProxyState == fClipProxyState) {
206 return fClipProxy.contains(devBounds);
207 }
208 SkPoint originOffset = {SkIntToScalar(this->getClip()->fOrigin.fX),
209 SkIntToScalar(this->getClip()->fOrigin.fY)};
210 SkRect clipSpaceBounds = devBounds;
211 clipSpaceBounds.offset(originOffset);
212 return this->getClip()->fClipStack->quickContains(clipSpaceBounds);
213}
214
215int GrInOrderDrawBuffer::concatInstancedDraw(const DrawInfo& info) {
216 GrAssert(info.isInstanced());
217
bsalomon@google.com934c5702012-03-20 21:17:58 +0000218 const GeometrySrcState& geomSrc = this->getGeomSrc();
jvanverth@google.comb75b0a02013-02-05 20:33:30 +0000219 const GrDrawState& drawState = this->getDrawState();
bsalomon@google.com934c5702012-03-20 21:17:58 +0000220
bsalomon@google.comd62e88e2013-02-01 14:19:27 +0000221 // we only attempt to concat the case when reserved verts are used with a client-specified index
222 // buffer. To make this work with client-specified VBs we'd need to know if the VB was updated
223 // between draws.
224 if (kReserved_GeometrySrcType != geomSrc.fVertexSrc ||
225 kBuffer_GeometrySrcType != geomSrc.fIndexSrc) {
226 return 0;
bsalomon@google.com934c5702012-03-20 21:17:58 +0000227 }
bsalomon@google.comd62e88e2013-02-01 14:19:27 +0000228 // Check if there is a draw info that is compatible that uses the same VB from the pool and
229 // the same IB
230 if (kDraw_Cmd != fCmds.back()) {
231 return 0;
232 }
233
234 DrawRecord* draw = &fDraws.back();
235 GeometryPoolState& poolState = fGeoPoolStateStack.back();
236 const GrVertexBuffer* vertexBuffer = poolState.fPoolVertexBuffer;
237
238 if (!draw->isInstanced() ||
239 draw->verticesPerInstance() != info.verticesPerInstance() ||
240 draw->indicesPerInstance() != info.indicesPerInstance() ||
241 draw->fVertexBuffer != vertexBuffer ||
jvanverth@google.comb75b0a02013-02-05 20:33:30 +0000242 draw->fIndexBuffer != geomSrc.fIndexBuffer) {
bsalomon@google.comd62e88e2013-02-01 14:19:27 +0000243 return 0;
244 }
245 // info does not yet account for the offset from the start of the pool's VB while the previous
246 // draw record does.
247 int adjustedStartVertex = poolState.fPoolStartVertex + info.startVertex();
248 if (draw->startVertex() + draw->vertexCount() != adjustedStartVertex) {
249 return 0;
250 }
251
252 GrAssert(poolState.fPoolStartVertex == draw->startVertex() + draw->vertexCount());
253
254 // how many instances can be concat'ed onto draw given the size of the index buffer
255 int instancesToConcat = this->indexCountInCurrentSource() / info.indicesPerInstance();
256 instancesToConcat -= draw->instanceCount();
257 instancesToConcat = GrMin(instancesToConcat, info.instanceCount());
258
259 // update the amount of reserved vertex data actually referenced in draws
skia.committer@gmail.comae683922013-02-06 07:01:54 +0000260 size_t vertexBytes = instancesToConcat * info.verticesPerInstance() *
jvanverth@google.comb75b0a02013-02-05 20:33:30 +0000261 drawState.getVertexSize();
bsalomon@google.comd62e88e2013-02-01 14:19:27 +0000262 poolState.fUsedPoolVertexBytes = GrMax(poolState.fUsedPoolVertexBytes, vertexBytes);
263
264 draw->adjustInstanceCount(instancesToConcat);
265 return instancesToConcat;
bsalomon@google.com934c5702012-03-20 21:17:58 +0000266}
267
bsalomon@google.comd62e88e2013-02-01 14:19:27 +0000268class AutoClipReenable {
269public:
270 AutoClipReenable() : fDrawState(NULL) {}
271 ~AutoClipReenable() {
272 if (NULL != fDrawState) {
273 fDrawState->enableState(GrDrawState::kClip_StateBit);
274 }
275 }
276 void set(GrDrawState* drawState) {
277 if (drawState->isClipState()) {
278 fDrawState = drawState;
279 drawState->disableState(GrDrawState::kClip_StateBit);
280 }
281 }
282private:
283 GrDrawState* fDrawState;
284};
285
bsalomon@google.com74749cd2013-01-30 16:12:41 +0000286void GrInOrderDrawBuffer::onDraw(const DrawInfo& info) {
reed@google.comac10a2d2010-12-22 21:39:39 +0000287
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000288 GeometryPoolState& poolState = fGeoPoolStateStack.back();
jvanverth@google.comb75b0a02013-02-05 20:33:30 +0000289 const GrDrawState& drawState = this->getDrawState();
bsalomon@google.comd62e88e2013-02-01 14:19:27 +0000290 AutoClipReenable acr;
291
jvanverth@google.comb75b0a02013-02-05 20:33:30 +0000292 if (drawState.isClipState() &&
bsalomon@google.comd62e88e2013-02-01 14:19:27 +0000293 NULL != info.getDevBounds() &&
294 this->quickInsideClip(*info.getDevBounds())) {
295 acr.set(this->drawState());
296 }
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000297
bsalomon@google.coma4f6b102012-06-26 21:04:22 +0000298 if (this->needsNewClip()) {
299 this->recordClip();
300 }
301 if (this->needsNewState()) {
302 this->recordState();
bsalomon@google.com86afc2a2011-02-16 16:12:19 +0000303 }
304
bsalomon@google.comd62e88e2013-02-01 14:19:27 +0000305 DrawRecord* draw;
306 if (info.isInstanced()) {
307 int instancesConcated = this->concatInstancedDraw(info);
308 if (info.instanceCount() > instancesConcated) {
309 draw = this->recordDraw(info);
310 draw->adjustInstanceCount(-instancesConcated);
311 } else {
312 return;
313 }
314 } else {
315 draw = this->recordDraw(info);
316 }
bsalomon@google.com74749cd2013-01-30 16:12:41 +0000317
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000318 switch (this->getGeomSrc().fVertexSrc) {
bsalomon@google.com74749cd2013-01-30 16:12:41 +0000319 case kBuffer_GeometrySrcType:
320 draw->fVertexBuffer = this->getGeomSrc().fVertexBuffer;
321 break;
322 case kReserved_GeometrySrcType: // fallthrough
323 case kArray_GeometrySrcType: {
skia.committer@gmail.comae683922013-02-06 07:01:54 +0000324 size_t vertexBytes = (info.vertexCount() + info.startVertex()) *
jvanverth@google.comb75b0a02013-02-05 20:33:30 +0000325 drawState.getVertexSize();
bsalomon@google.com74749cd2013-01-30 16:12:41 +0000326 poolState.fUsedPoolVertexBytes = GrMax(poolState.fUsedPoolVertexBytes, vertexBytes);
327 draw->fVertexBuffer = poolState.fPoolVertexBuffer;
bsalomon@google.comd62e88e2013-02-01 14:19:27 +0000328 draw->adjustStartVertex(poolState.fPoolStartVertex);
bsalomon@google.com74749cd2013-01-30 16:12:41 +0000329 break;
330 }
331 default:
332 GrCrash("unknown geom src type");
reed@google.comac10a2d2010-12-22 21:39:39 +0000333 }
bsalomon@google.coma4f6b102012-06-26 21:04:22 +0000334 draw->fVertexBuffer->ref();
reed@google.comac10a2d2010-12-22 21:39:39 +0000335
bsalomon@google.com74749cd2013-01-30 16:12:41 +0000336 if (info.isIndexed()) {
337 switch (this->getGeomSrc().fIndexSrc) {
338 case kBuffer_GeometrySrcType:
339 draw->fIndexBuffer = this->getGeomSrc().fIndexBuffer;
340 break;
341 case kReserved_GeometrySrcType: // fallthrough
342 case kArray_GeometrySrcType: {
343 size_t indexBytes = (info.indexCount() + info.startIndex()) * sizeof(uint16_t);
344 poolState.fUsedPoolIndexBytes = GrMax(poolState.fUsedPoolIndexBytes, indexBytes);
345 draw->fIndexBuffer = poolState.fPoolIndexBuffer;
bsalomon@google.comd62e88e2013-02-01 14:19:27 +0000346 draw->adjustStartIndex(poolState.fPoolStartIndex);
bsalomon@google.com74749cd2013-01-30 16:12:41 +0000347 break;
348 }
349 default:
350 GrCrash("unknown geom src type");
351 }
352 draw->fIndexBuffer->ref();
353 } else {
354 draw->fIndexBuffer = NULL;
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000355 }
reed@google.comac10a2d2010-12-22 21:39:39 +0000356}
357
sugoi@google.com5f74cf82012-12-17 21:16:45 +0000358GrInOrderDrawBuffer::StencilPath::StencilPath() : fStroke(SkStrokeRec::kFill_InitStyle) {}
359
360void GrInOrderDrawBuffer::onStencilPath(const GrPath* path, const SkStrokeRec& stroke,
sugoi@google.com12b4e272012-12-06 20:13:11 +0000361 SkPath::FillType fill) {
bsalomon@google.comded4f4b2012-06-28 18:48:06 +0000362 if (this->needsNewClip()) {
363 this->recordClip();
364 }
365 // Only compare the subset of GrDrawState relevant to path stenciling?
366 if (this->needsNewState()) {
367 this->recordState();
368 }
369 StencilPath* sp = this->recordStencilPath();
370 sp->fPath.reset(path);
371 path->ref();
372 sp->fFill = fill;
sugoi@google.com12b4e272012-12-06 20:13:11 +0000373 sp->fStroke = stroke;
bsalomon@google.com64aef2b2012-06-11 15:36:13 +0000374}
375
bsalomon@google.comd62e88e2013-02-01 14:19:27 +0000376void GrInOrderDrawBuffer::clear(const GrIRect* rect, GrColor color, GrRenderTarget* renderTarget) {
bsalomon@google.com6aa25c32011-04-27 19:55:29 +0000377 GrIRect r;
bsalomon@google.com1b3ce472012-08-17 13:43:08 +0000378 if (NULL == renderTarget) {
379 renderTarget = this->drawState()->getRenderTarget();
380 GrAssert(NULL != renderTarget);
381 }
bsalomon@google.com6aa25c32011-04-27 19:55:29 +0000382 if (NULL == rect) {
383 // We could do something smart and remove previous draws and clears to
384 // the current render target. If we get that smart we have to make sure
385 // those draws aren't read before this clear (render-to-texture).
bsalomon@google.com1b3ce472012-08-17 13:43:08 +0000386 r.setLTRB(0, 0, renderTarget->width(), renderTarget->height());
bsalomon@google.com6aa25c32011-04-27 19:55:29 +0000387 rect = &r;
388 }
bsalomon@google.coma4f6b102012-06-26 21:04:22 +0000389 Clear* clr = this->recordClear();
390 clr->fColor = color;
391 clr->fRect = *rect;
392 clr->fRenderTarget = renderTarget;
bsalomon@google.com1b3ce472012-08-17 13:43:08 +0000393 renderTarget->ref();
bsalomon@google.com0b335c12011-04-25 19:17:44 +0000394}
395
reed@google.comac10a2d2010-12-22 21:39:39 +0000396void GrInOrderDrawBuffer::reset() {
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000397 GrAssert(1 == fGeoPoolStateStack.count());
398 this->resetVertexSource();
399 this->resetIndexSource();
bsalomon@google.com86afc2a2011-02-16 16:12:19 +0000400 int numDraws = fDraws.count();
401 for (int d = 0; d < numDraws; ++d) {
402 // we always have a VB, but not always an IB
403 GrAssert(NULL != fDraws[d].fVertexBuffer);
404 fDraws[d].fVertexBuffer->unref();
405 GrSafeUnref(fDraws[d].fIndexBuffer);
406 }
bsalomon@google.coma4f6b102012-06-26 21:04:22 +0000407 fCmds.reset();
reed@google.comac10a2d2010-12-22 21:39:39 +0000408 fDraws.reset();
bsalomon@google.comded4f4b2012-06-28 18:48:06 +0000409 fStencilPaths.reset();
reed@google.comac10a2d2010-12-22 21:39:39 +0000410 fStates.reset();
bsalomon@google.com0b335c12011-04-25 19:17:44 +0000411 fClears.reset();
bsalomon@google.com1c13c962011-02-14 16:51:21 +0000412 fVertexPool.reset();
413 fIndexPool.reset();
reed@google.comac10a2d2010-12-22 21:39:39 +0000414 fClips.reset();
robertphillips@google.combeb1af72012-07-26 18:52:16 +0000415 fClipOrigins.reset();
bsalomon@google.coma4f6b102012-06-26 21:04:22 +0000416 fClipSet = true;
reed@google.comac10a2d2010-12-22 21:39:39 +0000417}
418
bsalomon@google.com55e4a202013-01-11 13:54:21 +0000419bool GrInOrderDrawBuffer::flushTo(GrDrawTarget* target) {
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000420 GrAssert(kReserved_GeometrySrcType != this->getGeomSrc().fVertexSrc);
421 GrAssert(kReserved_GeometrySrcType != this->getGeomSrc().fIndexSrc);
bsalomon@google.com3f5a95e2012-03-08 16:41:42 +0000422
reed@google.comac10a2d2010-12-22 21:39:39 +0000423 GrAssert(NULL != target);
424 GrAssert(target != this); // not considered and why?
425
bsalomon@google.coma4f6b102012-06-26 21:04:22 +0000426 int numCmds = fCmds.count();
bsalomon@google.com358e4272013-01-10 14:40:28 +0000427 if (0 == numCmds) {
bsalomon@google.coma4f6b102012-06-26 21:04:22 +0000428 return false;
reed@google.comac10a2d2010-12-22 21:39:39 +0000429 }
430
bsalomon@google.com1c13c962011-02-14 16:51:21 +0000431 fVertexPool.unlock();
432 fIndexPool.unlock();
reed@google.comac10a2d2010-12-22 21:39:39 +0000433
reed@google.comac10a2d2010-12-22 21:39:39 +0000434 GrDrawTarget::AutoClipRestore acr(target);
jvanverth@google.comb75b0a02013-02-05 20:33:30 +0000435 AutoGeometryAndStatePush agasp(target, kPreserve_ASRInit);
bsalomon@google.comca432082013-01-23 19:53:46 +0000436
437 GrDrawState playbackState;
bsalomon@google.coma5d056a2012-03-27 15:59:58 +0000438 GrDrawState* prevDrawState = target->drawState();
439 prevDrawState->ref();
bsalomon@google.comca432082013-01-23 19:53:46 +0000440 target->setDrawState(&playbackState);
reed@google.comac10a2d2010-12-22 21:39:39 +0000441
robertphillips@google.combeb1af72012-07-26 18:52:16 +0000442 GrClipData clipData;
443
bsalomon@google.comded4f4b2012-06-28 18:48:06 +0000444 int currState = 0;
445 int currClip = 0;
446 int currClear = 0;
447 int currDraw = 0;
448 int currStencilPath = 0;
reed@google.comac10a2d2010-12-22 21:39:39 +0000449
bsalomon@google.comca432082013-01-23 19:53:46 +0000450
bsalomon@google.coma4f6b102012-06-26 21:04:22 +0000451 for (int c = 0; c < numCmds; ++c) {
452 switch (fCmds[c]) {
453 case kDraw_Cmd: {
bsalomon@google.com74749cd2013-01-30 16:12:41 +0000454 const DrawRecord& draw = fDraws[currDraw];
jvanverth@google.comb75b0a02013-02-05 20:33:30 +0000455 target->setVertexSourceToBuffer(draw.fVertexBuffer);
bsalomon@google.comd62e88e2013-02-01 14:19:27 +0000456 if (draw.isIndexed()) {
bsalomon@google.coma4f6b102012-06-26 21:04:22 +0000457 target->setIndexSourceToBuffer(draw.fIndexBuffer);
458 }
bsalomon@google.comd62e88e2013-02-01 14:19:27 +0000459 target->executeDraw(draw);
bsalomon@google.com0b335c12011-04-25 19:17:44 +0000460
bsalomon@google.coma4f6b102012-06-26 21:04:22 +0000461 ++currDraw;
462 break;
463 }
bsalomon@google.comded4f4b2012-06-28 18:48:06 +0000464 case kStencilPath_Cmd: {
465 const StencilPath& sp = fStencilPaths[currStencilPath];
sugoi@google.com12b4e272012-12-06 20:13:11 +0000466 target->stencilPath(sp.fPath.get(), sp.fStroke, sp.fFill);
bsalomon@google.comded4f4b2012-06-28 18:48:06 +0000467 ++currStencilPath;
468 break;
469 }
bsalomon@google.coma4f6b102012-06-26 21:04:22 +0000470 case kSetState_Cmd:
bsalomon@google.comca432082013-01-23 19:53:46 +0000471 fStates[currState].restoreTo(&playbackState);
bsalomon@google.coma4f6b102012-06-26 21:04:22 +0000472 ++currState;
473 break;
474 case kSetClip_Cmd:
robertphillips@google.combeb1af72012-07-26 18:52:16 +0000475 clipData.fClipStack = &fClips[currClip];
476 clipData.fOrigin = fClipOrigins[currClip];
477 target->setClip(&clipData);
bsalomon@google.coma4f6b102012-06-26 21:04:22 +0000478 ++currClip;
479 break;
480 case kClear_Cmd:
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000481 target->clear(&fClears[currClear].fRect,
bsalomon@google.coma4f6b102012-06-26 21:04:22 +0000482 fClears[currClear].fColor,
483 fClears[currClear].fRenderTarget);
484 ++currClear;
485 break;
reed@google.comac10a2d2010-12-22 21:39:39 +0000486 }
487 }
bsalomon@google.coma4f6b102012-06-26 21:04:22 +0000488 // we should have consumed all the states, clips, etc.
489 GrAssert(fStates.count() == currState);
490 GrAssert(fClips.count() == currClip);
robertphillips@google.combeb1af72012-07-26 18:52:16 +0000491 GrAssert(fClipOrigins.count() == currClip);
bsalomon@google.coma4f6b102012-06-26 21:04:22 +0000492 GrAssert(fClears.count() == currClear);
493 GrAssert(fDraws.count() == currDraw);
494
bsalomon@google.coma5d056a2012-03-27 15:59:58 +0000495 target->setDrawState(prevDrawState);
496 prevDrawState->unref();
bsalomon@google.com55e4a202013-01-11 13:54:21 +0000497 this->reset();
bsalomon@google.coma4f6b102012-06-26 21:04:22 +0000498 return true;
reed@google.comac10a2d2010-12-22 21:39:39 +0000499}
500
bsalomon@google.com97805382012-03-13 14:32:07 +0000501void GrInOrderDrawBuffer::setAutoFlushTarget(GrDrawTarget* target) {
502 GrSafeAssign(fAutoFlushTarget, target);
503}
504
505void GrInOrderDrawBuffer::willReserveVertexAndIndexSpace(
bsalomon@google.com97805382012-03-13 14:32:07 +0000506 int vertexCount,
507 int indexCount) {
508 if (NULL != fAutoFlushTarget) {
509 // We use geometryHints() to know whether to flush the draw buffer. We
510 // can't flush if we are inside an unbalanced pushGeometrySource.
511 // Moreover, flushing blows away vertex and index data that was
512 // previously reserved. So if the vertex or index data is pulled from
513 // reserved space and won't be released by this request then we can't
514 // flush.
515 bool insideGeoPush = fGeoPoolStateStack.count() > 1;
516
517 bool unreleasedVertexSpace =
518 !vertexCount &&
519 kReserved_GeometrySrcType == this->getGeomSrc().fVertexSrc;
520
521 bool unreleasedIndexSpace =
522 !indexCount &&
523 kReserved_GeometrySrcType == this->getGeomSrc().fIndexSrc;
524
525 // we don't want to finalize any reserved geom on the target since
526 // we don't know that the client has finished writing to it.
527 bool targetHasReservedGeom =
528 fAutoFlushTarget->hasReservedVerticesOrIndices();
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000529
bsalomon@google.com97805382012-03-13 14:32:07 +0000530 int vcount = vertexCount;
531 int icount = indexCount;
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000532
bsalomon@google.com97805382012-03-13 14:32:07 +0000533 if (!insideGeoPush &&
534 !unreleasedVertexSpace &&
535 !unreleasedIndexSpace &&
536 !targetHasReservedGeom &&
jvanverth@google.comb75b0a02013-02-05 20:33:30 +0000537 this->geometryHints(&vcount, &icount)) {
bsalomon@google.com97805382012-03-13 14:32:07 +0000538
539 this->flushTo(fAutoFlushTarget);
540 }
541 }
542}
543
jvanverth@google.comb75b0a02013-02-05 20:33:30 +0000544bool GrInOrderDrawBuffer::geometryHints(int* vertexCount,
bsalomon@google.com1c13c962011-02-14 16:51:21 +0000545 int* indexCount) const {
546 // we will recommend a flush if the data could fit in a single
547 // preallocated buffer but none are left and it can't fit
548 // in the current buffer (which may not be prealloced).
reed@google.comac10a2d2010-12-22 21:39:39 +0000549 bool flush = false;
550 if (NULL != indexCount) {
bsalomon@google.com1c13c962011-02-14 16:51:21 +0000551 int32_t currIndices = fIndexPool.currentBufferIndices();
552 if (*indexCount > currIndices &&
553 (!fIndexPool.preallocatedBuffersRemaining() &&
554 *indexCount <= fIndexPool.preallocatedBufferIndices())) {
555
556 flush = true;
557 }
558 *indexCount = currIndices;
reed@google.comac10a2d2010-12-22 21:39:39 +0000559 }
560 if (NULL != vertexCount) {
jvanverth@google.comb75b0a02013-02-05 20:33:30 +0000561 size_t vertexSize = this->getDrawState().getVertexSize();
jvanverth@google.coma6338982013-01-31 21:34:25 +0000562 int32_t currVertices = fVertexPool.currentBufferVertices(vertexSize);
bsalomon@google.com1c13c962011-02-14 16:51:21 +0000563 if (*vertexCount > currVertices &&
564 (!fVertexPool.preallocatedBuffersRemaining() &&
jvanverth@google.coma6338982013-01-31 21:34:25 +0000565 *vertexCount <= fVertexPool.preallocatedBufferVertices(vertexSize))) {
reed@google.comac10a2d2010-12-22 21:39:39 +0000566
bsalomon@google.com1c13c962011-02-14 16:51:21 +0000567 flush = true;
reed@google.comac10a2d2010-12-22 21:39:39 +0000568 }
bsalomon@google.com1c13c962011-02-14 16:51:21 +0000569 *vertexCount = currVertices;
reed@google.comac10a2d2010-12-22 21:39:39 +0000570 }
571 return flush;
572}
573
jvanverth@google.coma6338982013-01-31 21:34:25 +0000574bool GrInOrderDrawBuffer::onReserveVertexSpace(size_t vertexSize,
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000575 int vertexCount,
576 void** vertices) {
577 GeometryPoolState& poolState = fGeoPoolStateStack.back();
578 GrAssert(vertexCount > 0);
579 GrAssert(NULL != vertices);
580 GrAssert(0 == poolState.fUsedPoolVertexBytes);
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000581
jvanverth@google.coma6338982013-01-31 21:34:25 +0000582 *vertices = fVertexPool.makeSpace(vertexSize,
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000583 vertexCount,
584 &poolState.fPoolVertexBuffer,
585 &poolState.fPoolStartVertex);
586 return NULL != *vertices;
587}
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000588
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000589bool GrInOrderDrawBuffer::onReserveIndexSpace(int indexCount, void** indices) {
590 GeometryPoolState& poolState = fGeoPoolStateStack.back();
591 GrAssert(indexCount > 0);
592 GrAssert(NULL != indices);
593 GrAssert(0 == poolState.fUsedPoolIndexBytes);
bsalomon@google.com1c13c962011-02-14 16:51:21 +0000594
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000595 *indices = fIndexPool.makeSpace(indexCount,
596 &poolState.fPoolIndexBuffer,
597 &poolState.fPoolStartIndex);
598 return NULL != *indices;
reed@google.comac10a2d2010-12-22 21:39:39 +0000599}
600
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000601void GrInOrderDrawBuffer::releaseReservedVertexSpace() {
602 GeometryPoolState& poolState = fGeoPoolStateStack.back();
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000603 const GeometrySrcState& geoSrc = this->getGeomSrc();
bsalomon@google.comd57d71a2012-08-16 16:26:33 +0000604
605 // If we get a release vertex space call then our current source should either be reserved
606 // or array (which we copied into reserved space).
607 GrAssert(kReserved_GeometrySrcType == geoSrc.fVertexSrc ||
608 kArray_GeometrySrcType == geoSrc.fVertexSrc);
bsalomon@google.com3f5a95e2012-03-08 16:41:42 +0000609
610 // When the caller reserved vertex buffer space we gave it back a pointer
611 // provided by the vertex buffer pool. At each draw we tracked the largest
612 // offset into the pool's pointer that was referenced. Now we return to the
613 // pool any portion at the tail of the allocation that no draw referenced.
jvanverth@google.comb75b0a02013-02-05 20:33:30 +0000614 size_t reservedVertexBytes = geoSrc.fVertexSize * geoSrc.fVertexCount;
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000615 fVertexPool.putBack(reservedVertexBytes -
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000616 poolState.fUsedPoolVertexBytes);
617 poolState.fUsedPoolVertexBytes = 0;
bsalomon@google.com3f5a95e2012-03-08 16:41:42 +0000618 poolState.fPoolVertexBuffer = NULL;
619 poolState.fPoolStartVertex = 0;
bsalomon@google.com1c13c962011-02-14 16:51:21 +0000620}
621
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000622void GrInOrderDrawBuffer::releaseReservedIndexSpace() {
623 GeometryPoolState& poolState = fGeoPoolStateStack.back();
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000624 const GeometrySrcState& geoSrc = this->getGeomSrc();
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000625
bsalomon@google.comd57d71a2012-08-16 16:26:33 +0000626 // If we get a release index space call then our current source should either be reserved
627 // or array (which we copied into reserved space).
628 GrAssert(kReserved_GeometrySrcType == geoSrc.fIndexSrc ||
629 kArray_GeometrySrcType == geoSrc.fIndexSrc);
bsalomon@google.com3f5a95e2012-03-08 16:41:42 +0000630
631 // Similar to releaseReservedVertexSpace we return any unused portion at
632 // the tail
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000633 size_t reservedIndexBytes = sizeof(uint16_t) * geoSrc.fIndexCount;
634 fIndexPool.putBack(reservedIndexBytes - poolState.fUsedPoolIndexBytes);
635 poolState.fUsedPoolIndexBytes = 0;
bsalomon@google.com3f5a95e2012-03-08 16:41:42 +0000636 poolState.fPoolIndexBuffer = NULL;
637 poolState.fPoolStartIndex = 0;
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000638}
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000639
bsalomon@google.combcdbbe62011-04-12 15:40:00 +0000640void GrInOrderDrawBuffer::onSetVertexSourceToArray(const void* vertexArray,
641 int vertexCount) {
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000642
643 GeometryPoolState& poolState = fGeoPoolStateStack.back();
644 GrAssert(0 == poolState.fUsedPoolVertexBytes);
bsalomon@google.com1c13c962011-02-14 16:51:21 +0000645#if GR_DEBUG
646 bool success =
647#endif
jvanverth@google.comb75b0a02013-02-05 20:33:30 +0000648 fVertexPool.appendVertices(this->getVertexSize(),
bsalomon@google.com1c13c962011-02-14 16:51:21 +0000649 vertexCount,
650 vertexArray,
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000651 &poolState.fPoolVertexBuffer,
652 &poolState.fPoolStartVertex);
bsalomon@google.com1c13c962011-02-14 16:51:21 +0000653 GR_DEBUGASSERT(success);
654}
655
bsalomon@google.combcdbbe62011-04-12 15:40:00 +0000656void GrInOrderDrawBuffer::onSetIndexSourceToArray(const void* indexArray,
657 int indexCount) {
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000658 GeometryPoolState& poolState = fGeoPoolStateStack.back();
659 GrAssert(0 == poolState.fUsedPoolIndexBytes);
bsalomon@google.com1c13c962011-02-14 16:51:21 +0000660#if GR_DEBUG
661 bool success =
662#endif
663 fIndexPool.appendIndices(indexCount,
664 indexArray,
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000665 &poolState.fPoolIndexBuffer,
666 &poolState.fPoolStartIndex);
bsalomon@google.com1c13c962011-02-14 16:51:21 +0000667 GR_DEBUGASSERT(success);
reed@google.comac10a2d2010-12-22 21:39:39 +0000668}
669
bsalomon@google.com3f5a95e2012-03-08 16:41:42 +0000670void GrInOrderDrawBuffer::releaseVertexArray() {
671 // When the client provides an array as the vertex source we handled it
672 // by copying their array into reserved space.
673 this->GrInOrderDrawBuffer::releaseReservedVertexSpace();
674}
675
676void GrInOrderDrawBuffer::releaseIndexArray() {
677 // When the client provides an array as the index source we handled it
678 // by copying their array into reserved space.
679 this->GrInOrderDrawBuffer::releaseReservedIndexSpace();
680}
681
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000682void GrInOrderDrawBuffer::geometrySourceWillPush() {
683 GeometryPoolState& poolState = fGeoPoolStateStack.push_back();
684 poolState.fUsedPoolVertexBytes = 0;
685 poolState.fUsedPoolIndexBytes = 0;
686#if GR_DEBUG
687 poolState.fPoolVertexBuffer = (GrVertexBuffer*)~0;
688 poolState.fPoolStartVertex = ~0;
689 poolState.fPoolIndexBuffer = (GrIndexBuffer*)~0;
690 poolState.fPoolStartIndex = ~0;
691#endif
692}
693
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000694void GrInOrderDrawBuffer::geometrySourceWillPop(
695 const GeometrySrcState& restoredState) {
696 GrAssert(fGeoPoolStateStack.count() > 1);
697 fGeoPoolStateStack.pop_back();
698 GeometryPoolState& poolState = fGeoPoolStateStack.back();
699 // we have to assume that any slack we had in our vertex/index data
700 // is now unreleasable because data may have been appended later in the
701 // pool.
702 if (kReserved_GeometrySrcType == restoredState.fVertexSrc ||
703 kArray_GeometrySrcType == restoredState.fVertexSrc) {
jvanverth@google.comb75b0a02013-02-05 20:33:30 +0000704 poolState.fUsedPoolVertexBytes = restoredState.fVertexSize * restoredState.fVertexCount;
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000705 }
706 if (kReserved_GeometrySrcType == restoredState.fIndexSrc ||
707 kArray_GeometrySrcType == restoredState.fIndexSrc) {
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000708 poolState.fUsedPoolIndexBytes = sizeof(uint16_t) *
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000709 restoredState.fIndexCount;
710 }
711}
712
bsalomon@google.com86afc2a2011-02-16 16:12:19 +0000713bool GrInOrderDrawBuffer::needsNewState() const {
bsalomon@google.comca432082013-01-23 19:53:46 +0000714 return fStates.empty() || !fStates.back().isEqual(this->getDrawState());
reed@google.comac10a2d2010-12-22 21:39:39 +0000715}
716
bsalomon@google.com86afc2a2011-02-16 16:12:19 +0000717bool GrInOrderDrawBuffer::needsNewClip() const {
bsalomon@google.com358e4272013-01-10 14:40:28 +0000718 GrAssert(fClips.count() == fClipOrigins.count());
719 if (this->getDrawState().isClipState()) {
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000720 if (fClipSet &&
bsalomon@google.com358e4272013-01-10 14:40:28 +0000721 (fClips.empty() ||
bsalomon@google.com02ddc8b2013-01-28 15:35:28 +0000722 fClips.back() != *this->getClip()->fClipStack ||
723 fClipOrigins.back() != this->getClip()->fOrigin)) {
bsalomon@google.com86afc2a2011-02-16 16:12:19 +0000724 return true;
725 }
reed@google.comac10a2d2010-12-22 21:39:39 +0000726 }
727 return false;
728}
bsalomon@google.comd302f142011-03-03 13:54:13 +0000729
bsalomon@google.coma4f6b102012-06-26 21:04:22 +0000730void GrInOrderDrawBuffer::recordClip() {
bsalomon@google.com02ddc8b2013-01-28 15:35:28 +0000731 fClips.push_back() = *this->getClip()->fClipStack;
732 fClipOrigins.push_back() = this->getClip()->fOrigin;
bsalomon@google.com86afc2a2011-02-16 16:12:19 +0000733 fClipSet = false;
bsalomon@google.coma4f6b102012-06-26 21:04:22 +0000734 fCmds.push_back(kSetClip_Cmd);
735}
736
bsalomon@google.coma4f6b102012-06-26 21:04:22 +0000737void GrInOrderDrawBuffer::recordState() {
bsalomon@google.comca432082013-01-23 19:53:46 +0000738 fStates.push_back().saveFrom(this->getDrawState());
bsalomon@google.coma4f6b102012-06-26 21:04:22 +0000739 fCmds.push_back(kSetState_Cmd);
740}
741
bsalomon@google.com74749cd2013-01-30 16:12:41 +0000742GrInOrderDrawBuffer::DrawRecord* GrInOrderDrawBuffer::recordDraw(const DrawInfo& info) {
bsalomon@google.comd62e88e2013-02-01 14:19:27 +0000743 fCmds.push_back(kDraw_Cmd);
744 return &fDraws.push_back(info);
bsalomon@google.com74749cd2013-01-30 16:12:41 +0000745}
746
bsalomon@google.comded4f4b2012-06-28 18:48:06 +0000747GrInOrderDrawBuffer::StencilPath* GrInOrderDrawBuffer::recordStencilPath() {
748 fCmds.push_back(kStencilPath_Cmd);
749 return &fStencilPaths.push_back();
750}
751
bsalomon@google.coma4f6b102012-06-26 21:04:22 +0000752GrInOrderDrawBuffer::Clear* GrInOrderDrawBuffer::recordClear() {
753 fCmds.push_back(kClear_Cmd);
754 return &fClears.push_back();
reed@google.comac10a2d2010-12-22 21:39:39 +0000755}
bsalomon@google.comd302f142011-03-03 13:54:13 +0000756
robertphillips@google.combeb1af72012-07-26 18:52:16 +0000757void GrInOrderDrawBuffer::clipWillBeSet(const GrClipData* newClipData) {
758 INHERITED::clipWillBeSet(newClipData);
bsalomon@google.com86afc2a2011-02-16 16:12:19 +0000759 fClipSet = true;
bsalomon@google.comd62e88e2013-02-01 14:19:27 +0000760 fClipProxyState = kUnknown_ClipProxyState;
bsalomon@google.com86afc2a2011-02-16 16:12:19 +0000761}