blob: cde851d49fb8d1a4a05e73246ce33c4bf4c1e18d [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 2010 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
epoger@google.comec3ed6a2011-07-28 14:26:00 +00009
reed@google.comac10a2d2010-12-22 21:39:39 +000010#include "GrGpu.h"
bsalomon@google.com558a75b2011-08-08 17:01:14 +000011
bsalomon@google.com81c3f8d2011-08-03 15:18:33 +000012#include "GrBufferAllocPool.h"
reed@google.comac10a2d2010-12-22 21:39:39 +000013#include "GrClipIterator.h"
bsalomon@google.com558a75b2011-08-08 17:01:14 +000014#include "GrContext.h"
reed@google.comac10a2d2010-12-22 21:39:39 +000015#include "GrIndexBuffer.h"
bsalomon@google.com4043ae22011-08-02 14:19:11 +000016#include "GrPathRenderer.h"
bsalomon@google.com81c3f8d2011-08-03 15:18:33 +000017#include "GrGLStencilBuffer.h"
18#include "GrVertexBuffer.h"
bsalomon@google.com1c13c962011-02-14 16:51:21 +000019
20// probably makes no sense for this to be less than a page
bsalomon@google.comee435122011-07-01 14:57:55 +000021static const size_t VERTEX_POOL_VB_SIZE = 1 << 18;
22static const int VERTEX_POOL_VB_COUNT = 4;
bsalomon@google.com25fd36c2011-07-06 17:41:08 +000023static const size_t INDEX_POOL_IB_SIZE = 1 << 16;
24static const int INDEX_POOL_IB_COUNT = 4;
reed@google.comac10a2d2010-12-22 21:39:39 +000025
bsalomon@google.comd302f142011-03-03 13:54:13 +000026////////////////////////////////////////////////////////////////////////////////
reed@google.comac10a2d2010-12-22 21:39:39 +000027
28extern void gr_run_unittests();
29
bsalomon@google.com25fb21f2011-06-21 18:17:25 +000030#define DEBUG_INVAL_BUFFER 0xdeadcafe
31#define DEBUG_INVAL_START_IDX -1
32
bsalomon@google.com8fe72472011-03-30 21:26:44 +000033GrGpu::GrGpu()
34 : f8bitPaletteSupport(false)
bsalomon@google.com669fdc42011-04-05 17:08:27 +000035 , fContext(NULL)
bsalomon@google.com8fe72472011-03-30 21:26:44 +000036 , fVertexPool(NULL)
37 , fIndexPool(NULL)
bsalomon@google.com25fb21f2011-06-21 18:17:25 +000038 , fVertexPoolUseCnt(0)
39 , fIndexPoolUseCnt(0)
40 , fGeomPoolStateStack(&fGeoSrcStateStackStorage)
bsalomon@google.com8fe72472011-03-30 21:26:44 +000041 , fQuadIndexBuffer(NULL)
42 , fUnitSquareVertexBuffer(NULL)
43 , fDefaultPathRenderer(NULL)
44 , fClientPathRenderer(NULL)
45 , fContextIsDirty(true)
bsalomon@google.com8fe72472011-03-30 21:26:44 +000046 , fResourceHead(NULL) {
bsalomon@google.com669fdc42011-04-05 17:08:27 +000047
reed@google.comac10a2d2010-12-22 21:39:39 +000048#if GR_DEBUG
bsalomon@google.com5aaa69e2011-03-04 20:29:08 +000049 //gr_run_unittests();
reed@google.comac10a2d2010-12-22 21:39:39 +000050#endif
bsalomon@google.com25fb21f2011-06-21 18:17:25 +000051
52 fGeomPoolStateStack.push_back();
53#if GR_DEBUG
54 GeometryPoolState& poolState = fGeomPoolStateStack.back();
55 poolState.fPoolVertexBuffer = (GrVertexBuffer*)DEBUG_INVAL_BUFFER;
56 poolState.fPoolStartVertex = DEBUG_INVAL_START_IDX;
57 poolState.fPoolIndexBuffer = (GrIndexBuffer*)DEBUG_INVAL_BUFFER;
58 poolState.fPoolStartIndex = DEBUG_INVAL_START_IDX;
59#endif
reed@google.comac10a2d2010-12-22 21:39:39 +000060 resetStats();
61}
62
63GrGpu::~GrGpu() {
bsalomon@google.com558a75b2011-08-08 17:01:14 +000064 this->releaseResources();
bsalomon@google.com583a1e32011-08-17 13:42:46 +000065 GrSafeUnref(fDefaultPathRenderer);
66 GrSafeUnref(fClientPathRenderer);
reed@google.comac10a2d2010-12-22 21:39:39 +000067}
68
bsalomon@google.com8fe72472011-03-30 21:26:44 +000069void GrGpu::abandonResources() {
70
71 while (NULL != fResourceHead) {
72 fResourceHead->abandon();
73 }
74
75 GrAssert(NULL == fQuadIndexBuffer || !fQuadIndexBuffer->isValid());
76 GrAssert(NULL == fUnitSquareVertexBuffer ||
77 !fUnitSquareVertexBuffer->isValid());
78 GrSafeSetNull(fQuadIndexBuffer);
79 GrSafeSetNull(fUnitSquareVertexBuffer);
80 delete fVertexPool;
81 fVertexPool = NULL;
82 delete fIndexPool;
83 fIndexPool = NULL;
reed@google.comac10a2d2010-12-22 21:39:39 +000084}
85
bsalomon@google.com8fe72472011-03-30 21:26:44 +000086void GrGpu::releaseResources() {
87
88 while (NULL != fResourceHead) {
89 fResourceHead->release();
90 }
91
92 GrAssert(NULL == fQuadIndexBuffer || !fQuadIndexBuffer->isValid());
93 GrAssert(NULL == fUnitSquareVertexBuffer ||
94 !fUnitSquareVertexBuffer->isValid());
95 GrSafeSetNull(fQuadIndexBuffer);
96 GrSafeSetNull(fUnitSquareVertexBuffer);
97 delete fVertexPool;
98 fVertexPool = NULL;
99 delete fIndexPool;
100 fIndexPool = NULL;
101}
102
103void GrGpu::insertResource(GrResource* resource) {
104 GrAssert(NULL != resource);
105 GrAssert(this == resource->getGpu());
106 GrAssert(NULL == resource->fNext);
107 GrAssert(NULL == resource->fPrevious);
108
109 resource->fNext = fResourceHead;
110 if (NULL != fResourceHead) {
111 GrAssert(NULL == fResourceHead->fPrevious);
112 fResourceHead->fPrevious = resource;
113 }
114 fResourceHead = resource;
115}
116
117void GrGpu::removeResource(GrResource* resource) {
118 GrAssert(NULL != resource);
119 GrAssert(NULL != fResourceHead);
120
121 if (fResourceHead == resource) {
122 GrAssert(NULL == resource->fPrevious);
123 fResourceHead = resource->fNext;
124 } else {
125 GrAssert(NULL != fResourceHead);
126 resource->fPrevious->fNext = resource->fNext;
127 }
128 if (NULL != resource->fNext) {
129 resource->fNext->fPrevious = resource->fPrevious;
130 }
131 resource->fNext = NULL;
132 resource->fPrevious = NULL;
133}
134
135
reed@google.comac10a2d2010-12-22 21:39:39 +0000136void GrGpu::unimpl(const char msg[]) {
bsalomon@google.com7d34d2e2011-01-24 17:41:47 +0000137#if GR_DEBUG
138 GrPrintf("--- GrGpu unimplemented(\"%s\")\n", msg);
139#endif
reed@google.comac10a2d2010-12-22 21:39:39 +0000140}
141
bsalomon@google.comd302f142011-03-03 13:54:13 +0000142////////////////////////////////////////////////////////////////////////////////
reed@google.comac10a2d2010-12-22 21:39:39 +0000143
bsalomon@google.comfea37b52011-04-25 15:51:06 +0000144GrTexture* GrGpu::createTexture(const GrTextureDesc& desc,
bsalomon@google.coma7f84e12011-03-10 14:13:19 +0000145 const void* srcData, size_t rowBytes) {
146 this->handleDirtyContext();
bsalomon@google.com81c3f8d2011-08-03 15:18:33 +0000147 GrTexture* tex = this->onCreateTexture(desc, srcData, rowBytes);
148 if (NULL != tex &&
149 (kRenderTarget_GrTextureFlagBit & desc.fFlags) &&
150 !(kNoStencil_GrTextureFlagBit & desc.fFlags)) {
151 GrAssert(NULL != tex->asRenderTarget());
152 // TODO: defer this and attach dynamically
153 if (!this->attachStencilBufferToRenderTarget(tex->asRenderTarget())) {
154 tex->unref();
155 return NULL;
156 }
157 }
158 return tex;
159}
160
161bool GrGpu::attachStencilBufferToRenderTarget(GrRenderTarget* rt) {
bsalomon@google.com558a75b2011-08-08 17:01:14 +0000162 GrAssert(NULL == rt->getStencilBuffer());
163 GrStencilBuffer* sb =
164 this->getContext()->findStencilBuffer(rt->allocatedWidth(),
165 rt->allocatedHeight(),
166 rt->numSamples());
167 if (NULL != sb) {
168 rt->setStencilBuffer(sb);
169 bool attached = this->attachStencilBufferToRenderTarget(sb, rt);
170 if (!attached) {
171 rt->setStencilBuffer(NULL);
172 }
173 return attached;
174 }
175 if (this->createStencilBufferForRenderTarget(rt, rt->allocatedWidth(),
176 rt->allocatedHeight())) {
177 rt->getStencilBuffer()->ref();
178 rt->getStencilBuffer()->transferToCacheAndLock();
179
bsalomon@google.comedc177d2011-08-05 15:46:40 +0000180 // Right now we're clearing the stencil buffer here after it is
181 // attached to an RT for the first time. When we start matching
182 // stencil buffers with smaller color targets this will no longer
183 // be correct because it won't be guaranteed to clear the entire
184 // sb.
185 // We used to clear down in the GL subclass using a special purpose
186 // FBO. But iOS doesn't allow a stencil-only FBO. It reports unsupported
187 // FBO status.
188 GrRenderTarget* oldRT = fCurrDrawState.fRenderTarget;
189 fCurrDrawState.fRenderTarget = rt;
190 this->clearStencil();
191 fCurrDrawState.fRenderTarget = oldRT;
bsalomon@google.com558a75b2011-08-08 17:01:14 +0000192 return true;
193 } else {
194 return false;
bsalomon@google.comedc177d2011-08-05 15:46:40 +0000195 }
bsalomon@google.coma7f84e12011-03-10 14:13:19 +0000196}
197
bsalomon@google.coma7f84e12011-03-10 14:13:19 +0000198GrRenderTarget* GrGpu::createRenderTargetFrom3DApiState() {
199 this->handleDirtyContext();
bsalomon@google.combcdbbe62011-04-12 15:40:00 +0000200 return this->onCreateRenderTargetFrom3DApiState();
bsalomon@google.coma7f84e12011-03-10 14:13:19 +0000201}
202
bsalomon@google.com5877ffd2011-04-11 17:58:48 +0000203GrResource* GrGpu::createPlatformSurface(const GrPlatformSurfaceDesc& desc) {
204 this->handleDirtyContext();
205 return this->onCreatePlatformSurface(desc);
206}
207
bsalomon@google.coma7f84e12011-03-10 14:13:19 +0000208GrVertexBuffer* GrGpu::createVertexBuffer(uint32_t size, bool dynamic) {
209 this->handleDirtyContext();
bsalomon@google.combcdbbe62011-04-12 15:40:00 +0000210 return this->onCreateVertexBuffer(size, dynamic);
bsalomon@google.coma7f84e12011-03-10 14:13:19 +0000211}
212
213GrIndexBuffer* GrGpu::createIndexBuffer(uint32_t size, bool dynamic) {
214 this->handleDirtyContext();
bsalomon@google.combcdbbe62011-04-12 15:40:00 +0000215 return this->onCreateIndexBuffer(size, dynamic);
bsalomon@google.coma7f84e12011-03-10 14:13:19 +0000216}
217
bsalomon@google.com6aa25c32011-04-27 19:55:29 +0000218void GrGpu::clear(const GrIRect* rect, GrColor color) {
bsalomon@google.coma7f84e12011-03-10 14:13:19 +0000219 this->handleDirtyContext();
bsalomon@google.com6aa25c32011-04-27 19:55:29 +0000220 this->onClear(rect, color);
bsalomon@google.coma7f84e12011-03-10 14:13:19 +0000221}
222
223void GrGpu::forceRenderTargetFlush() {
224 this->handleDirtyContext();
bsalomon@google.combcdbbe62011-04-12 15:40:00 +0000225 this->onForceRenderTargetFlush();
bsalomon@google.coma7f84e12011-03-10 14:13:19 +0000226}
227
bsalomon@google.com669fdc42011-04-05 17:08:27 +0000228bool GrGpu::readPixels(GrRenderTarget* target,
229 int left, int top, int width, int height,
230 GrPixelConfig config, void* buffer) {
231
bsalomon@google.coma7f84e12011-03-10 14:13:19 +0000232 this->handleDirtyContext();
bsalomon@google.com5877ffd2011-04-11 17:58:48 +0000233 return this->onReadPixels(target, left, top, width, height, config, buffer);
bsalomon@google.coma7f84e12011-03-10 14:13:19 +0000234}
235
236////////////////////////////////////////////////////////////////////////////////
237
bsalomon@google.com1c13c962011-02-14 16:51:21 +0000238static const int MAX_QUADS = 1 << 12; // max possible: (1 << 14) - 1;
reed@google.comac10a2d2010-12-22 21:39:39 +0000239
reed@google.com8195f672011-01-12 18:14:28 +0000240GR_STATIC_ASSERT(4 * MAX_QUADS <= 65535);
reed@google.comac10a2d2010-12-22 21:39:39 +0000241
bsalomon@google.com1c13c962011-02-14 16:51:21 +0000242static inline void fill_indices(uint16_t* indices, int quadCount) {
reed@google.comac10a2d2010-12-22 21:39:39 +0000243 for (int i = 0; i < quadCount; ++i) {
244 indices[6 * i + 0] = 4 * i + 0;
245 indices[6 * i + 1] = 4 * i + 1;
246 indices[6 * i + 2] = 4 * i + 2;
247 indices[6 * i + 3] = 4 * i + 0;
248 indices[6 * i + 4] = 4 * i + 2;
249 indices[6 * i + 5] = 4 * i + 3;
250 }
251}
252
bsalomon@google.com86afc2a2011-02-16 16:12:19 +0000253const GrIndexBuffer* GrGpu::getQuadIndexBuffer() const {
reed@google.comac10a2d2010-12-22 21:39:39 +0000254 if (NULL == fQuadIndexBuffer) {
255 static const int SIZE = sizeof(uint16_t) * 6 * MAX_QUADS;
256 GrGpu* me = const_cast<GrGpu*>(this);
257 fQuadIndexBuffer = me->createIndexBuffer(SIZE, false);
258 if (NULL != fQuadIndexBuffer) {
259 uint16_t* indices = (uint16_t*)fQuadIndexBuffer->lock();
260 if (NULL != indices) {
bsalomon@google.com1c13c962011-02-14 16:51:21 +0000261 fill_indices(indices, MAX_QUADS);
reed@google.comac10a2d2010-12-22 21:39:39 +0000262 fQuadIndexBuffer->unlock();
263 } else {
264 indices = (uint16_t*)GrMalloc(SIZE);
bsalomon@google.com1c13c962011-02-14 16:51:21 +0000265 fill_indices(indices, MAX_QUADS);
reed@google.comac10a2d2010-12-22 21:39:39 +0000266 if (!fQuadIndexBuffer->updateData(indices, SIZE)) {
267 fQuadIndexBuffer->unref();
268 fQuadIndexBuffer = NULL;
bsalomon@google.com6f7fbc92011-02-01 19:12:40 +0000269 GrCrash("Can't get indices into buffer!");
reed@google.comac10a2d2010-12-22 21:39:39 +0000270 }
271 GrFree(indices);
272 }
273 }
274 }
275
276 return fQuadIndexBuffer;
277}
278
bsalomon@google.com86afc2a2011-02-16 16:12:19 +0000279const GrVertexBuffer* GrGpu::getUnitSquareVertexBuffer() const {
bsalomon@google.com6f7fbc92011-02-01 19:12:40 +0000280 if (NULL == fUnitSquareVertexBuffer) {
281
282 static const GrPoint DATA[] = {
reed@google.com7744c202011-05-06 19:26:26 +0000283 { 0, 0 },
284 { GR_Scalar1, 0 },
285 { GR_Scalar1, GR_Scalar1 },
286 { 0, GR_Scalar1 }
287#if 0
bsalomon@google.com6f7fbc92011-02-01 19:12:40 +0000288 GrPoint(0, 0),
289 GrPoint(GR_Scalar1,0),
290 GrPoint(GR_Scalar1,GR_Scalar1),
291 GrPoint(0, GR_Scalar1)
reed@google.com7744c202011-05-06 19:26:26 +0000292#endif
bsalomon@google.com6f7fbc92011-02-01 19:12:40 +0000293 };
294 static const size_t SIZE = sizeof(DATA);
295
296 GrGpu* me = const_cast<GrGpu*>(this);
297 fUnitSquareVertexBuffer = me->createVertexBuffer(SIZE, false);
298 if (NULL != fUnitSquareVertexBuffer) {
299 if (!fUnitSquareVertexBuffer->updateData(DATA, SIZE)) {
300 fUnitSquareVertexBuffer->unref();
301 fUnitSquareVertexBuffer = NULL;
302 GrCrash("Can't get vertices into buffer!");
303 }
304 }
305 }
306
307 return fUnitSquareVertexBuffer;
308}
309
bsalomon@google.comd302f142011-03-03 13:54:13 +0000310////////////////////////////////////////////////////////////////////////////////
reed@google.comac10a2d2010-12-22 21:39:39 +0000311
bsalomon@google.comd302f142011-03-03 13:54:13 +0000312// stencil settings to use when clip is in stencil
313const GrStencilSettings GrGpu::gClipStencilSettings = {
314 kKeep_StencilOp, kKeep_StencilOp,
315 kKeep_StencilOp, kKeep_StencilOp,
316 kAlwaysIfInClip_StencilFunc, kAlwaysIfInClip_StencilFunc,
317 0, 0,
318 0, 0,
319 0, 0
320};
321
bsalomon@google.coma7f84e12011-03-10 14:13:19 +0000322// mapping of clip-respecting stencil funcs to normal stencil funcs
323// mapping depends on whether stencil-clipping is in effect.
bsalomon@google.comd302f142011-03-03 13:54:13 +0000324static const GrStencilFunc gGrClipToNormalStencilFunc[2][kClipStencilFuncCount] = {
325 {// Stencil-Clipping is DISABLED, effectively always inside the clip
326 // In the Clip Funcs
327 kAlways_StencilFunc, // kAlwaysIfInClip_StencilFunc
328 kEqual_StencilFunc, // kEqualIfInClip_StencilFunc
329 kLess_StencilFunc, // kLessIfInClip_StencilFunc
330 kLEqual_StencilFunc, // kLEqualIfInClip_StencilFunc
331 // Special in the clip func that forces user's ref to be 0.
332 kNotEqual_StencilFunc, // kNonZeroIfInClip_StencilFunc
333 // make ref 0 and do normal nequal.
334 },
335 {// Stencil-Clipping is ENABLED
336 // In the Clip Funcs
337 kEqual_StencilFunc, // kAlwaysIfInClip_StencilFunc
338 // eq stencil clip bit, mask
339 // out user bits.
340
341 kEqual_StencilFunc, // kEqualIfInClip_StencilFunc
342 // add stencil bit to mask and ref
343
344 kLess_StencilFunc, // kLessIfInClip_StencilFunc
345 kLEqual_StencilFunc, // kLEqualIfInClip_StencilFunc
346 // for both of these we can add
347 // the clip bit to the mask and
348 // ref and compare as normal
349 // Special in the clip func that forces user's ref to be 0.
350 kLess_StencilFunc, // kNonZeroIfInClip_StencilFunc
351 // make ref have only the clip bit set
352 // and make comparison be less
353 // 10..0 < 1..user_bits..
354 }
355};
356
357GrStencilFunc GrGpu::ConvertStencilFunc(bool stencilInClip, GrStencilFunc func) {
358 GrAssert(func >= 0);
359 if (func >= kBasicStencilFuncCount) {
360 GrAssert(func < kStencilFuncCount);
361 func = gGrClipToNormalStencilFunc[stencilInClip ? 1 : 0][func - kBasicStencilFuncCount];
362 GrAssert(func >= 0 && func < kBasicStencilFuncCount);
363 }
364 return func;
365}
366
367void GrGpu::ConvertStencilFuncAndMask(GrStencilFunc func,
368 bool clipInStencil,
369 unsigned int clipBit,
370 unsigned int userBits,
371 unsigned int* ref,
372 unsigned int* mask) {
373 if (func < kBasicStencilFuncCount) {
374 *mask &= userBits;
375 *ref &= userBits;
376 } else {
377 if (clipInStencil) {
378 switch (func) {
379 case kAlwaysIfInClip_StencilFunc:
380 *mask = clipBit;
381 *ref = clipBit;
382 break;
383 case kEqualIfInClip_StencilFunc:
384 case kLessIfInClip_StencilFunc:
385 case kLEqualIfInClip_StencilFunc:
386 *mask = (*mask & userBits) | clipBit;
387 *ref = (*ref & userBits) | clipBit;
388 break;
389 case kNonZeroIfInClip_StencilFunc:
390 *mask = (*mask & userBits) | clipBit;
391 *ref = clipBit;
392 break;
393 default:
394 GrCrash("Unknown stencil func");
395 }
396 } else {
397 *mask &= userBits;
398 *ref &= userBits;
399 }
400 }
401}
402
403////////////////////////////////////////////////////////////////////////////////
404
405#define VISUALIZE_COMPLEX_CLIP 0
406
407#if VISUALIZE_COMPLEX_CLIP
408 #include "GrRandom.h"
409 GrRandom gRandom;
410 #define SET_RANDOM_COLOR this->setColor(0xff000000 | gRandom.nextU());
411#else
412 #define SET_RANDOM_COLOR
413#endif
414
bsalomon@google.comffca4002011-02-22 20:34:01 +0000415bool GrGpu::setupClipAndFlushState(GrPrimitiveType type) {
reed@google.comac10a2d2010-12-22 21:39:39 +0000416 const GrIRect* r = NULL;
bsalomon@google.comd302f142011-03-03 13:54:13 +0000417 GrIRect clipRect;
reed@google.comac10a2d2010-12-22 21:39:39 +0000418
bsalomon@google.com2e7b43d2011-01-18 20:57:22 +0000419 // we check this early because we need a valid
420 // render target to setup stencil clipping
421 // before even going into flushGraphicsState
422 if (NULL == fCurrDrawState.fRenderTarget) {
423 GrAssert(!"No render target bound.");
424 return false;
425 }
426
reed@google.comac10a2d2010-12-22 21:39:39 +0000427 if (fCurrDrawState.fFlagBits & kClip_StateBit) {
bsalomon@google.comd302f142011-03-03 13:54:13 +0000428 GrRenderTarget& rt = *fCurrDrawState.fRenderTarget;
429
430 GrRect bounds;
431 GrRect rtRect;
432 rtRect.setLTRB(0, 0,
433 GrIntToScalar(rt.width()), GrIntToScalar(rt.height()));
bsalomon@google.com0b50b2e2011-03-08 21:07:21 +0000434 if (fClip.hasConservativeBounds()) {
435 bounds = fClip.getConservativeBounds();
reed@google.com20efde72011-05-09 17:00:02 +0000436 if (!bounds.intersect(rtRect)) {
437 bounds.setEmpty();
438 }
bsalomon@google.comd302f142011-03-03 13:54:13 +0000439 } else {
440 bounds = rtRect;
441 }
442
443 bounds.roundOut(&clipRect);
444 if (clipRect.isEmpty()) {
445 clipRect.setLTRB(0,0,0,0);
446 }
447 r = &clipRect;
448
bsalomon@google.comdea2f8d2011-08-01 15:51:05 +0000449 // use the stencil clip if we can't represent the clip as a rectangle.
450 fClipInStencil = !fClip.isRect() && !fClip.isEmpty() &&
451 !bounds.isEmpty();
reed@google.comac10a2d2010-12-22 21:39:39 +0000452
bsalomon@google.com81c3f8d2011-08-03 15:18:33 +0000453 // TODO: dynamically attach a SB when needed.
454 GrStencilBuffer* stencilBuffer = rt.getStencilBuffer();
455 if (fClipInStencil && NULL == stencilBuffer) {
456 return false;
457 }
bsalomon@google.coma16d6502011-08-02 14:07:52 +0000458
bsalomon@google.com81c3f8d2011-08-03 15:18:33 +0000459 if (fClipInStencil &&
460 stencilBuffer->mustRenderClip(fClip, rt.width(), rt.height())) {
461
462 stencilBuffer->setLastClip(fClip, rt.width(), rt.height());
463
bsalomon@google.comd302f142011-03-03 13:54:13 +0000464 // we set the current clip to the bounds so that our recursive
465 // draws are scissored to them. We use the copy of the complex clip
bsalomon@google.com81c3f8d2011-08-03 15:18:33 +0000466 // we just stashed on the SB to render from. We set it back after
467 // we finish drawing it into the stencil.
468 const GrClip& clip = stencilBuffer->getLastClip();
bsalomon@google.comd302f142011-03-03 13:54:13 +0000469 fClip.setFromRect(bounds);
reed@google.comac10a2d2010-12-22 21:39:39 +0000470
471 AutoStateRestore asr(this);
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000472 AutoGeometryPush agp(this);
bsalomon@google.com1c13c962011-02-14 16:51:21 +0000473
bsalomon@google.com1c13c962011-02-14 16:51:21 +0000474 this->setViewMatrix(GrMatrix::I());
bsalomon@google.com398109c2011-04-14 18:40:27 +0000475 this->clearStencilClip(clipRect);
bsalomon@google.comd302f142011-03-03 13:54:13 +0000476 this->flushScissor(NULL);
477#if !VISUALIZE_COMPLEX_CLIP
478 this->enableState(kNoColorWrites_StateBit);
479#else
480 this->disableState(kNoColorWrites_StateBit);
481#endif
482 int count = clip.getElementCount();
bsalomon@google.com81c3f8d2011-08-03 15:18:33 +0000483 int clipBit = stencilBuffer->bits();
bsalomon@google.comd302f142011-03-03 13:54:13 +0000484 clipBit = (1 << (clipBit-1));
485
bsalomon@google.com5aaa69e2011-03-04 20:29:08 +0000486 // often we'll see the first two elements of the clip are
487 // the full rt size and another element intersected with it.
488 // We can skip the first full-size rect and save a big rect draw.
489 int firstElement = 0;
bsalomon@google.com0b50b2e2011-03-08 21:07:21 +0000490 if (clip.getElementCount() > 1 &&
bsalomon@google.com5aaa69e2011-03-04 20:29:08 +0000491 kRect_ClipType == clip.getElementType(0) &&
492 kIntersect_SetOp == clip.getOp(1)&&
493 clip.getRect(0).contains(bounds)) {
494 firstElement = 1;
495 }
bsalomon@google.com0b50b2e2011-03-08 21:07:21 +0000496
bsalomon@google.comd302f142011-03-03 13:54:13 +0000497 // walk through each clip element and perform its set op
498 // with the existing clip.
bsalomon@google.com5aaa69e2011-03-04 20:29:08 +0000499 for (int c = firstElement; c < count; ++c) {
bsalomon@google.comd302f142011-03-03 13:54:13 +0000500 GrPathFill fill;
bsalomon@google.comee435122011-07-01 14:57:55 +0000501 bool fillInverted;
bsalomon@google.comd302f142011-03-03 13:54:13 +0000502 // enabled at bottom of loop
503 this->disableState(kModifyStencilClip_StateBit);
504
bsalomon@google.com7f5875d2011-03-24 16:55:45 +0000505 bool canRenderDirectToStencil; // can the clip element be drawn
506 // directly to the stencil buffer
507 // with a non-inverted fill rule
508 // without extra passes to
bsalomon@google.comdfe75bc2011-03-25 12:31:16 +0000509 // resolve in/out status.
510
511 GrPathRenderer* pr = NULL;
reed@google.com07f3ee12011-05-16 17:21:57 +0000512 const GrPath* clipPath = NULL;
bsalomon@google.comee435122011-07-01 14:57:55 +0000513 GrPathRenderer::AutoClearPath arp;
bsalomon@google.comd302f142011-03-03 13:54:13 +0000514 if (kRect_ClipType == clip.getElementType(c)) {
bsalomon@google.com7f5875d2011-03-24 16:55:45 +0000515 canRenderDirectToStencil = true;
bsalomon@google.comd302f142011-03-03 13:54:13 +0000516 fill = kEvenOdd_PathFill;
bsalomon@google.comee435122011-07-01 14:57:55 +0000517 fillInverted = false;
bsalomon@google.comd302f142011-03-03 13:54:13 +0000518 } else {
519 fill = clip.getPathFill(c);
bsalomon@google.comee435122011-07-01 14:57:55 +0000520 fillInverted = IsFillInverted(fill);
521 fill = NonInvertedFill(fill);
reed@google.com07f3ee12011-05-16 17:21:57 +0000522 clipPath = &clip.getPath(c);
bsalomon@google.comee435122011-07-01 14:57:55 +0000523 pr = this->getClipPathRenderer(*clipPath, fill);
bsalomon@google.com11f0b512011-03-29 20:52:23 +0000524 canRenderDirectToStencil =
bsalomon@google.comee435122011-07-01 14:57:55 +0000525 !pr->requiresStencilPass(this, *clipPath, fill);
526 arp.set(pr, this, clipPath, fill, NULL);
bsalomon@google.comd302f142011-03-03 13:54:13 +0000527 }
528
bsalomon@google.com5aaa69e2011-03-04 20:29:08 +0000529 GrSetOp op = firstElement == c ? kReplace_SetOp : clip.getOp(c);
bsalomon@google.comd302f142011-03-03 13:54:13 +0000530 int passes;
531 GrStencilSettings stencilSettings[GrStencilSettings::kMaxStencilClipPasses];
532
bsalomon@google.com11f0b512011-03-29 20:52:23 +0000533 bool canDrawDirectToClip; // Given the renderer, the element,
bsalomon@google.com7f5875d2011-03-24 16:55:45 +0000534 // fill rule, and set operation can
535 // we render the element directly to
536 // stencil bit used for clipping.
bsalomon@google.com11f0b512011-03-29 20:52:23 +0000537 canDrawDirectToClip =
538 GrStencilSettings::GetClipPasses(op,
bsalomon@google.com7f5875d2011-03-24 16:55:45 +0000539 canRenderDirectToStencil,
bsalomon@google.com11f0b512011-03-29 20:52:23 +0000540 clipBit,
bsalomon@google.comee435122011-07-01 14:57:55 +0000541 fillInverted,
bsalomon@google.com7f5875d2011-03-24 16:55:45 +0000542 &passes, stencilSettings);
bsalomon@google.comd302f142011-03-03 13:54:13 +0000543
544 // draw the element to the client stencil bits if necessary
545 if (!canDrawDirectToClip) {
bsalomon@google.com7f5875d2011-03-24 16:55:45 +0000546 static const GrStencilSettings gDrawToStencil = {
547 kIncClamp_StencilOp, kIncClamp_StencilOp,
548 kIncClamp_StencilOp, kIncClamp_StencilOp,
549 kAlways_StencilFunc, kAlways_StencilFunc,
550 0xffffffff, 0xffffffff,
551 0x00000000, 0x00000000,
552 0xffffffff, 0xffffffff,
553 };
554 SET_RANDOM_COLOR
bsalomon@google.comd302f142011-03-03 13:54:13 +0000555 if (kRect_ClipType == clip.getElementType(c)) {
bsalomon@google.comd302f142011-03-03 13:54:13 +0000556 this->setStencil(gDrawToStencil);
bsalomon@google.comd302f142011-03-03 13:54:13 +0000557 this->drawSimpleRect(clip.getRect(c), NULL, 0);
558 } else {
bsalomon@google.com7f5875d2011-03-24 16:55:45 +0000559 if (canRenderDirectToStencil) {
560 this->setStencil(gDrawToStencil);
bsalomon@google.comee435122011-07-01 14:57:55 +0000561 pr->drawPath(0);
bsalomon@google.com7f5875d2011-03-24 16:55:45 +0000562 } else {
bsalomon@google.comee435122011-07-01 14:57:55 +0000563 pr->drawPathToStencil();
bsalomon@google.com7f5875d2011-03-24 16:55:45 +0000564 }
bsalomon@google.comd302f142011-03-03 13:54:13 +0000565 }
566 }
567
568 // now we modify the clip bit by rendering either the clip
569 // element directly or a bounding rect of the entire clip.
570 this->enableState(kModifyStencilClip_StateBit);
571 for (int p = 0; p < passes; ++p) {
572 this->setStencil(stencilSettings[p]);
573 if (canDrawDirectToClip) {
574 if (kRect_ClipType == clip.getElementType(c)) {
575 SET_RANDOM_COLOR
576 this->drawSimpleRect(clip.getRect(c), NULL, 0);
577 } else {
578 SET_RANDOM_COLOR
bsalomon@google.comee435122011-07-01 14:57:55 +0000579 pr->drawPath(0);
bsalomon@google.comd302f142011-03-03 13:54:13 +0000580 }
581 } else {
582 SET_RANDOM_COLOR
thakis@chromium.org441d7da2011-06-07 04:03:17 +0000583 this->drawSimpleRect(bounds, NULL, 0);
bsalomon@google.comd302f142011-03-03 13:54:13 +0000584 }
585 }
reed@google.comac10a2d2010-12-22 21:39:39 +0000586 }
bsalomon@google.comdea2f8d2011-08-01 15:51:05 +0000587 // restore clip
bsalomon@google.comd302f142011-03-03 13:54:13 +0000588 fClip = clip;
bsalomon@google.comdea2f8d2011-08-01 15:51:05 +0000589 // recusive draws would have disabled this since they drew with
590 // the clip bounds as clip.
591 fClipInStencil = true;
reed@google.comac10a2d2010-12-22 21:39:39 +0000592 }
reed@google.comac10a2d2010-12-22 21:39:39 +0000593 }
bsalomon@google.comd302f142011-03-03 13:54:13 +0000594
reed@google.comac10a2d2010-12-22 21:39:39 +0000595 // Must flush the scissor after graphics state
bsalomon@google.comd302f142011-03-03 13:54:13 +0000596 if (!this->flushGraphicsState(type)) {
reed@google.comac10a2d2010-12-22 21:39:39 +0000597 return false;
598 }
bsalomon@google.comd302f142011-03-03 13:54:13 +0000599 this->flushScissor(r);
reed@google.comac10a2d2010-12-22 21:39:39 +0000600 return true;
601}
602
reed@google.com07f3ee12011-05-16 17:21:57 +0000603GrPathRenderer* GrGpu::getClipPathRenderer(const GrPath& path,
bsalomon@google.comdfe75bc2011-03-25 12:31:16 +0000604 GrPathFill fill) {
bsalomon@google.com11f0b512011-03-29 20:52:23 +0000605 if (NULL != fClientPathRenderer &&
bsalomon@google.comee435122011-07-01 14:57:55 +0000606 fClientPathRenderer->canDrawPath(path, fill)) {
bsalomon@google.comdfe75bc2011-03-25 12:31:16 +0000607 return fClientPathRenderer;
608 } else {
609 if (NULL == fDefaultPathRenderer) {
bsalomon@google.com11f0b512011-03-29 20:52:23 +0000610 fDefaultPathRenderer =
bsalomon@google.comdfe75bc2011-03-25 12:31:16 +0000611 new GrDefaultPathRenderer(this->supportsTwoSidedStencil(),
612 this->supportsStencilWrapOps());
613 }
bsalomon@google.comee435122011-07-01 14:57:55 +0000614 GrAssert(fDefaultPathRenderer->canDrawPath(path, fill));
bsalomon@google.comdfe75bc2011-03-25 12:31:16 +0000615 return fDefaultPathRenderer;
616 }
617}
618
619
bsalomon@google.comd302f142011-03-03 13:54:13 +0000620////////////////////////////////////////////////////////////////////////////////
reed@google.comac10a2d2010-12-22 21:39:39 +0000621
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000622void GrGpu::geometrySourceWillPush() {
623 const GeometrySrcState& geoSrc = this->getGeomSrc();
624 if (kArray_GeometrySrcType == geoSrc.fVertexSrc ||
625 kReserved_GeometrySrcType == geoSrc.fVertexSrc) {
626 this->finalizeReservedVertices();
627 }
628 if (kArray_GeometrySrcType == geoSrc.fIndexSrc ||
629 kReserved_GeometrySrcType == geoSrc.fIndexSrc) {
630 this->finalizeReservedIndices();
631 }
632 GeometryPoolState& newState = fGeomPoolStateStack.push_back();
633#if GR_DEBUG
634 newState.fPoolVertexBuffer = (GrVertexBuffer*)DEBUG_INVAL_BUFFER;
635 newState.fPoolStartVertex = DEBUG_INVAL_START_IDX;
636 newState.fPoolIndexBuffer = (GrIndexBuffer*)DEBUG_INVAL_BUFFER;
637 newState.fPoolStartIndex = DEBUG_INVAL_START_IDX;
638#endif
639}
640
641void GrGpu::geometrySourceWillPop(const GeometrySrcState& restoredState) {
642 // if popping last entry then pops are unbalanced with pushes
643 GrAssert(fGeomPoolStateStack.count() > 1);
644 fGeomPoolStateStack.pop_back();
645}
646
647void GrGpu::onDrawIndexed(GrPrimitiveType type,
648 int startVertex,
649 int startIndex,
650 int vertexCount,
651 int indexCount) {
reed@google.comac10a2d2010-12-22 21:39:39 +0000652
bsalomon@google.coma7f84e12011-03-10 14:13:19 +0000653 this->handleDirtyContext();
654
655 if (!this->setupClipAndFlushState(type)) {
reed@google.comac10a2d2010-12-22 21:39:39 +0000656 return;
657 }
658
659#if GR_COLLECT_STATS
660 fStats.fVertexCnt += vertexCount;
661 fStats.fIndexCnt += indexCount;
662 fStats.fDrawCnt += 1;
663#endif
664
bsalomon@google.com1c13c962011-02-14 16:51:21 +0000665 int sVertex = startVertex;
666 int sIndex = startIndex;
667 setupGeometry(&sVertex, &sIndex, vertexCount, indexCount);
reed@google.comac10a2d2010-12-22 21:39:39 +0000668
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000669 this->onGpuDrawIndexed(type, sVertex, sIndex,
670 vertexCount, indexCount);
reed@google.comac10a2d2010-12-22 21:39:39 +0000671}
672
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000673void GrGpu::onDrawNonIndexed(GrPrimitiveType type,
bsalomon@google.com1c13c962011-02-14 16:51:21 +0000674 int startVertex,
675 int vertexCount) {
bsalomon@google.coma7f84e12011-03-10 14:13:19 +0000676 this->handleDirtyContext();
677
678 if (!this->setupClipAndFlushState(type)) {
reed@google.comac10a2d2010-12-22 21:39:39 +0000679 return;
680 }
681#if GR_COLLECT_STATS
682 fStats.fVertexCnt += vertexCount;
683 fStats.fDrawCnt += 1;
684#endif
685
bsalomon@google.com1c13c962011-02-14 16:51:21 +0000686 int sVertex = startVertex;
687 setupGeometry(&sVertex, NULL, vertexCount, 0);
reed@google.comac10a2d2010-12-22 21:39:39 +0000688
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000689 this->onGpuDrawNonIndexed(type, sVertex, vertexCount);
bsalomon@google.com1c13c962011-02-14 16:51:21 +0000690}
691
692void GrGpu::finalizeReservedVertices() {
693 GrAssert(NULL != fVertexPool);
694 fVertexPool->unlock();
695}
696
697void GrGpu::finalizeReservedIndices() {
698 GrAssert(NULL != fIndexPool);
699 fIndexPool->unlock();
700}
701
702void GrGpu::prepareVertexPool() {
703 if (NULL == fVertexPool) {
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000704 GrAssert(0 == fVertexPoolUseCnt);
bsalomon@google.comd302f142011-03-03 13:54:13 +0000705 fVertexPool = new GrVertexBufferAllocPool(this, true,
706 VERTEX_POOL_VB_SIZE,
bsalomon@google.com7a5af8b2011-02-18 18:40:42 +0000707 VERTEX_POOL_VB_COUNT);
bsalomon@google.com11f0b512011-03-29 20:52:23 +0000708 fVertexPool->releaseGpuRef();
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000709 } else if (!fVertexPoolUseCnt) {
bsalomon@google.comd302f142011-03-03 13:54:13 +0000710 // the client doesn't have valid data in the pool
bsalomon@google.com1c13c962011-02-14 16:51:21 +0000711 fVertexPool->reset();
712 }
713}
714
715void GrGpu::prepareIndexPool() {
senorblanco@chromium.org9d18b782011-03-28 20:47:09 +0000716 if (NULL == fIndexPool) {
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000717 GrAssert(0 == fIndexPoolUseCnt);
bsalomon@google.com25fd36c2011-07-06 17:41:08 +0000718 fIndexPool = new GrIndexBufferAllocPool(this, true,
719 INDEX_POOL_IB_SIZE,
720 INDEX_POOL_IB_COUNT);
bsalomon@google.com11f0b512011-03-29 20:52:23 +0000721 fIndexPool->releaseGpuRef();
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000722 } else if (!fIndexPoolUseCnt) {
bsalomon@google.comd302f142011-03-03 13:54:13 +0000723 // the client doesn't have valid data in the pool
bsalomon@google.com1c13c962011-02-14 16:51:21 +0000724 fIndexPool->reset();
725 }
reed@google.comac10a2d2010-12-22 21:39:39 +0000726}
727
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000728bool GrGpu::onReserveVertexSpace(GrVertexLayout vertexLayout,
729 int vertexCount,
730 void** vertices) {
731 GeometryPoolState& geomPoolState = fGeomPoolStateStack.back();
732
733 GrAssert(vertexCount > 0);
734 GrAssert(NULL != vertices);
735
736 this->prepareVertexPool();
737
738 *vertices = fVertexPool->makeSpace(vertexLayout,
739 vertexCount,
740 &geomPoolState.fPoolVertexBuffer,
741 &geomPoolState.fPoolStartVertex);
742 if (NULL == *vertices) {
743 return false;
reed@google.comac10a2d2010-12-22 21:39:39 +0000744 }
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000745 ++fVertexPoolUseCnt;
reed@google.comac10a2d2010-12-22 21:39:39 +0000746 return true;
747}
748
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000749bool GrGpu::onReserveIndexSpace(int indexCount, void** indices) {
750 GeometryPoolState& geomPoolState = fGeomPoolStateStack.back();
751
752 GrAssert(indexCount > 0);
753 GrAssert(NULL != indices);
754
755 this->prepareIndexPool();
756
757 *indices = fIndexPool->makeSpace(indexCount,
758 &geomPoolState.fPoolIndexBuffer,
759 &geomPoolState.fPoolStartIndex);
760 if (NULL == *indices) {
761 return false;
762 }
763 ++fIndexPoolUseCnt;
764 return true;
765}
766
767void GrGpu::releaseReservedVertexSpace() {
768 const GeometrySrcState& geoSrc = this->getGeomSrc();
769 GrAssert(kReserved_GeometrySrcType == geoSrc.fVertexSrc);
770 size_t bytes = geoSrc.fVertexCount * VertexSize(geoSrc.fVertexLayout);
771 fVertexPool->putBack(bytes);
772 --fVertexPoolUseCnt;
773}
774
775void GrGpu::releaseReservedIndexSpace() {
776 const GeometrySrcState& geoSrc = this->getGeomSrc();
777 GrAssert(kReserved_GeometrySrcType == geoSrc.fIndexSrc);
778 size_t bytes = geoSrc.fIndexCount * sizeof(uint16_t);
779 fIndexPool->putBack(bytes);
780 --fIndexPoolUseCnt;
781}
bsalomon@google.com1c13c962011-02-14 16:51:21 +0000782
bsalomon@google.combcdbbe62011-04-12 15:40:00 +0000783void GrGpu::onSetVertexSourceToArray(const void* vertexArray, int vertexCount) {
bsalomon@google.combcdbbe62011-04-12 15:40:00 +0000784 this->prepareVertexPool();
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000785 GeometryPoolState& geomPoolState = fGeomPoolStateStack.back();
bsalomon@google.com1c13c962011-02-14 16:51:21 +0000786#if GR_DEBUG
787 bool success =
788#endif
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000789 fVertexPool->appendVertices(this->getGeomSrc().fVertexLayout,
bsalomon@google.com1c13c962011-02-14 16:51:21 +0000790 vertexCount,
791 vertexArray,
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000792 &geomPoolState.fPoolVertexBuffer,
793 &geomPoolState.fPoolStartVertex);
794 ++fVertexPoolUseCnt;
bsalomon@google.com1c13c962011-02-14 16:51:21 +0000795 GR_DEBUGASSERT(success);
796}
797
bsalomon@google.combcdbbe62011-04-12 15:40:00 +0000798void GrGpu::onSetIndexSourceToArray(const void* indexArray, int indexCount) {
bsalomon@google.combcdbbe62011-04-12 15:40:00 +0000799 this->prepareIndexPool();
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000800 GeometryPoolState& geomPoolState = fGeomPoolStateStack.back();
bsalomon@google.com1c13c962011-02-14 16:51:21 +0000801#if GR_DEBUG
802 bool success =
803#endif
804 fIndexPool->appendIndices(indexCount,
805 indexArray,
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000806 &geomPoolState.fPoolIndexBuffer,
807 &geomPoolState.fPoolStartIndex);
808 ++fIndexPoolUseCnt;
bsalomon@google.com1c13c962011-02-14 16:51:21 +0000809 GR_DEBUGASSERT(success);
reed@google.comac10a2d2010-12-22 21:39:39 +0000810}
811
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000812void GrGpu::releaseVertexArray() {
813 // if vertex source was array, we stowed data in the pool
814 const GeometrySrcState& geoSrc = this->getGeomSrc();
815 GrAssert(kArray_GeometrySrcType == geoSrc.fVertexSrc);
816 size_t bytes = geoSrc.fVertexCount * VertexSize(geoSrc.fVertexLayout);
817 fVertexPool->putBack(bytes);
818 --fVertexPoolUseCnt;
819}
820
821void GrGpu::releaseIndexArray() {
822 // if index source was array, we stowed data in the pool
823 const GeometrySrcState& geoSrc = this->getGeomSrc();
824 GrAssert(kArray_GeometrySrcType == geoSrc.fIndexSrc);
825 size_t bytes = geoSrc.fIndexCount * sizeof(uint16_t);
826 fIndexPool->putBack(bytes);
827 --fIndexPoolUseCnt;
828}
829
bsalomon@google.comd302f142011-03-03 13:54:13 +0000830////////////////////////////////////////////////////////////////////////////////
831
bsalomon@google.com05ef5102011-05-02 21:14:59 +0000832const GrGpuStats& GrGpu::getStats() const {
reed@google.comac10a2d2010-12-22 21:39:39 +0000833 return fStats;
834}
835
836void GrGpu::resetStats() {
837 memset(&fStats, 0, sizeof(fStats));
838}
839
840void GrGpu::printStats() const {
841 if (GR_COLLECT_STATS) {
842 GrPrintf(
843 "-v-------------------------GPU STATS----------------------------v-\n"
844 "Stats collection is: %s\n"
845 "Draws: %04d, Verts: %04d, Indices: %04d\n"
846 "ProgChanges: %04d, TexChanges: %04d, RTChanges: %04d\n"
847 "TexCreates: %04d, RTCreates:%04d\n"
848 "-^--------------------------------------------------------------^-\n",
849 (GR_COLLECT_STATS ? "ON" : "OFF"),
850 fStats.fDrawCnt, fStats.fVertexCnt, fStats.fIndexCnt,
851 fStats.fProgChngCnt, fStats.fTextureChngCnt, fStats.fRenderTargetChngCnt,
852 fStats.fTextureCreateCnt, fStats.fRenderTargetCreateCnt);
853 }
854}
855
856////////////////////////////////////////////////////////////////////////////////
reed@google.comac10a2d2010-12-22 21:39:39 +0000857const GrSamplerState GrSamplerState::gClampNoFilter(
858 GrSamplerState::kClamp_WrapMode,
859 GrSamplerState::kClamp_WrapMode,
860 GrSamplerState::kNormal_SampleMode,
bsalomon@google.comc6cf7232011-02-17 16:43:10 +0000861 GrMatrix::I(),
bsalomon@google.com6aef1fb2011-05-05 12:33:22 +0000862 GrSamplerState::kNearest_Filter);
reed@google.comac10a2d2010-12-22 21:39:39 +0000863
864
865
866