blob: 7744e6a129395224ffaec6afe66beda7404043c7 [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)
bsalomon@google.com30085192011-08-19 15:42:31 +000043 , fPathRendererChain(NULL)
bsalomon@google.com8fe72472011-03-30 21:26:44 +000044 , fContextIsDirty(true)
bsalomon@google.com8fe72472011-03-30 21:26:44 +000045 , fResourceHead(NULL) {
bsalomon@google.com669fdc42011-04-05 17:08:27 +000046
reed@google.comac10a2d2010-12-22 21:39:39 +000047#if GR_DEBUG
bsalomon@google.com5aaa69e2011-03-04 20:29:08 +000048 //gr_run_unittests();
reed@google.comac10a2d2010-12-22 21:39:39 +000049#endif
bsalomon@google.com25fb21f2011-06-21 18:17:25 +000050
51 fGeomPoolStateStack.push_back();
52#if GR_DEBUG
53 GeometryPoolState& poolState = fGeomPoolStateStack.back();
54 poolState.fPoolVertexBuffer = (GrVertexBuffer*)DEBUG_INVAL_BUFFER;
55 poolState.fPoolStartVertex = DEBUG_INVAL_START_IDX;
56 poolState.fPoolIndexBuffer = (GrIndexBuffer*)DEBUG_INVAL_BUFFER;
57 poolState.fPoolStartIndex = DEBUG_INVAL_START_IDX;
58#endif
reed@google.comac10a2d2010-12-22 21:39:39 +000059 resetStats();
60}
61
62GrGpu::~GrGpu() {
bsalomon@google.com558a75b2011-08-08 17:01:14 +000063 this->releaseResources();
reed@google.comac10a2d2010-12-22 21:39:39 +000064}
65
bsalomon@google.com8fe72472011-03-30 21:26:44 +000066void GrGpu::abandonResources() {
67
68 while (NULL != fResourceHead) {
69 fResourceHead->abandon();
70 }
71
72 GrAssert(NULL == fQuadIndexBuffer || !fQuadIndexBuffer->isValid());
73 GrAssert(NULL == fUnitSquareVertexBuffer ||
74 !fUnitSquareVertexBuffer->isValid());
75 GrSafeSetNull(fQuadIndexBuffer);
76 GrSafeSetNull(fUnitSquareVertexBuffer);
77 delete fVertexPool;
78 fVertexPool = NULL;
79 delete fIndexPool;
80 fIndexPool = NULL;
bsalomon@google.com30085192011-08-19 15:42:31 +000081 // in case path renderer has any GrResources, start from scratch
82 GrSafeSetNull(fPathRendererChain);
reed@google.comac10a2d2010-12-22 21:39:39 +000083}
84
bsalomon@google.com8fe72472011-03-30 21:26:44 +000085void GrGpu::releaseResources() {
86
87 while (NULL != fResourceHead) {
88 fResourceHead->release();
89 }
90
91 GrAssert(NULL == fQuadIndexBuffer || !fQuadIndexBuffer->isValid());
92 GrAssert(NULL == fUnitSquareVertexBuffer ||
93 !fUnitSquareVertexBuffer->isValid());
94 GrSafeSetNull(fQuadIndexBuffer);
95 GrSafeSetNull(fUnitSquareVertexBuffer);
96 delete fVertexPool;
97 fVertexPool = NULL;
98 delete fIndexPool;
99 fIndexPool = NULL;
bsalomon@google.com30085192011-08-19 15:42:31 +0000100 // in case path renderer has any GrResources, start from scratch
101 GrSafeSetNull(fPathRendererChain);
bsalomon@google.com8fe72472011-03-30 21:26:44 +0000102}
103
104void GrGpu::insertResource(GrResource* resource) {
105 GrAssert(NULL != resource);
106 GrAssert(this == resource->getGpu());
107 GrAssert(NULL == resource->fNext);
108 GrAssert(NULL == resource->fPrevious);
109
110 resource->fNext = fResourceHead;
111 if (NULL != fResourceHead) {
112 GrAssert(NULL == fResourceHead->fPrevious);
113 fResourceHead->fPrevious = resource;
114 }
115 fResourceHead = resource;
116}
117
118void GrGpu::removeResource(GrResource* resource) {
119 GrAssert(NULL != resource);
120 GrAssert(NULL != fResourceHead);
121
122 if (fResourceHead == resource) {
123 GrAssert(NULL == resource->fPrevious);
124 fResourceHead = resource->fNext;
125 } else {
126 GrAssert(NULL != fResourceHead);
127 resource->fPrevious->fNext = resource->fNext;
128 }
129 if (NULL != resource->fNext) {
130 resource->fNext->fPrevious = resource->fPrevious;
131 }
132 resource->fNext = NULL;
133 resource->fPrevious = NULL;
134}
135
136
reed@google.comac10a2d2010-12-22 21:39:39 +0000137void GrGpu::unimpl(const char msg[]) {
bsalomon@google.com7d34d2e2011-01-24 17:41:47 +0000138#if GR_DEBUG
139 GrPrintf("--- GrGpu unimplemented(\"%s\")\n", msg);
140#endif
reed@google.comac10a2d2010-12-22 21:39:39 +0000141}
142
bsalomon@google.comd302f142011-03-03 13:54:13 +0000143////////////////////////////////////////////////////////////////////////////////
reed@google.comac10a2d2010-12-22 21:39:39 +0000144
bsalomon@google.comfea37b52011-04-25 15:51:06 +0000145GrTexture* GrGpu::createTexture(const GrTextureDesc& desc,
bsalomon@google.coma7f84e12011-03-10 14:13:19 +0000146 const void* srcData, size_t rowBytes) {
147 this->handleDirtyContext();
bsalomon@google.com81c3f8d2011-08-03 15:18:33 +0000148 GrTexture* tex = this->onCreateTexture(desc, srcData, rowBytes);
149 if (NULL != tex &&
150 (kRenderTarget_GrTextureFlagBit & desc.fFlags) &&
151 !(kNoStencil_GrTextureFlagBit & desc.fFlags)) {
152 GrAssert(NULL != tex->asRenderTarget());
153 // TODO: defer this and attach dynamically
154 if (!this->attachStencilBufferToRenderTarget(tex->asRenderTarget())) {
155 tex->unref();
156 return NULL;
157 }
158 }
159 return tex;
160}
161
162bool GrGpu::attachStencilBufferToRenderTarget(GrRenderTarget* rt) {
bsalomon@google.com558a75b2011-08-08 17:01:14 +0000163 GrAssert(NULL == rt->getStencilBuffer());
164 GrStencilBuffer* sb =
165 this->getContext()->findStencilBuffer(rt->allocatedWidth(),
166 rt->allocatedHeight(),
167 rt->numSamples());
168 if (NULL != sb) {
169 rt->setStencilBuffer(sb);
170 bool attached = this->attachStencilBufferToRenderTarget(sb, rt);
171 if (!attached) {
172 rt->setStencilBuffer(NULL);
173 }
174 return attached;
175 }
176 if (this->createStencilBufferForRenderTarget(rt, rt->allocatedWidth(),
177 rt->allocatedHeight())) {
178 rt->getStencilBuffer()->ref();
179 rt->getStencilBuffer()->transferToCacheAndLock();
180
bsalomon@google.comedc177d2011-08-05 15:46:40 +0000181 // Right now we're clearing the stencil buffer here after it is
182 // attached to an RT for the first time. When we start matching
183 // stencil buffers with smaller color targets this will no longer
184 // be correct because it won't be guaranteed to clear the entire
185 // sb.
186 // We used to clear down in the GL subclass using a special purpose
187 // FBO. But iOS doesn't allow a stencil-only FBO. It reports unsupported
188 // FBO status.
189 GrRenderTarget* oldRT = fCurrDrawState.fRenderTarget;
190 fCurrDrawState.fRenderTarget = rt;
191 this->clearStencil();
192 fCurrDrawState.fRenderTarget = oldRT;
bsalomon@google.com558a75b2011-08-08 17:01:14 +0000193 return true;
194 } else {
195 return false;
bsalomon@google.comedc177d2011-08-05 15:46:40 +0000196 }
bsalomon@google.coma7f84e12011-03-10 14:13:19 +0000197}
198
bsalomon@google.coma7f84e12011-03-10 14:13:19 +0000199GrRenderTarget* GrGpu::createRenderTargetFrom3DApiState() {
200 this->handleDirtyContext();
bsalomon@google.combcdbbe62011-04-12 15:40:00 +0000201 return this->onCreateRenderTargetFrom3DApiState();
bsalomon@google.coma7f84e12011-03-10 14:13:19 +0000202}
203
bsalomon@google.com5877ffd2011-04-11 17:58:48 +0000204GrResource* GrGpu::createPlatformSurface(const GrPlatformSurfaceDesc& desc) {
205 this->handleDirtyContext();
206 return this->onCreatePlatformSurface(desc);
207}
208
bsalomon@google.coma7f84e12011-03-10 14:13:19 +0000209GrVertexBuffer* GrGpu::createVertexBuffer(uint32_t size, bool dynamic) {
210 this->handleDirtyContext();
bsalomon@google.combcdbbe62011-04-12 15:40:00 +0000211 return this->onCreateVertexBuffer(size, dynamic);
bsalomon@google.coma7f84e12011-03-10 14:13:19 +0000212}
213
214GrIndexBuffer* GrGpu::createIndexBuffer(uint32_t size, bool dynamic) {
215 this->handleDirtyContext();
bsalomon@google.combcdbbe62011-04-12 15:40:00 +0000216 return this->onCreateIndexBuffer(size, dynamic);
bsalomon@google.coma7f84e12011-03-10 14:13:19 +0000217}
218
bsalomon@google.com6aa25c32011-04-27 19:55:29 +0000219void GrGpu::clear(const GrIRect* rect, GrColor color) {
bsalomon@google.coma7f84e12011-03-10 14:13:19 +0000220 this->handleDirtyContext();
bsalomon@google.com6aa25c32011-04-27 19:55:29 +0000221 this->onClear(rect, color);
bsalomon@google.coma7f84e12011-03-10 14:13:19 +0000222}
223
224void GrGpu::forceRenderTargetFlush() {
225 this->handleDirtyContext();
bsalomon@google.combcdbbe62011-04-12 15:40:00 +0000226 this->onForceRenderTargetFlush();
bsalomon@google.coma7f84e12011-03-10 14:13:19 +0000227}
228
bsalomon@google.com669fdc42011-04-05 17:08:27 +0000229bool GrGpu::readPixels(GrRenderTarget* target,
230 int left, int top, int width, int height,
231 GrPixelConfig config, void* buffer) {
232
bsalomon@google.coma7f84e12011-03-10 14:13:19 +0000233 this->handleDirtyContext();
bsalomon@google.com5877ffd2011-04-11 17:58:48 +0000234 return this->onReadPixels(target, left, top, width, height, config, buffer);
bsalomon@google.coma7f84e12011-03-10 14:13:19 +0000235}
236
237////////////////////////////////////////////////////////////////////////////////
238
bsalomon@google.com1c13c962011-02-14 16:51:21 +0000239static const int MAX_QUADS = 1 << 12; // max possible: (1 << 14) - 1;
reed@google.comac10a2d2010-12-22 21:39:39 +0000240
reed@google.com8195f672011-01-12 18:14:28 +0000241GR_STATIC_ASSERT(4 * MAX_QUADS <= 65535);
reed@google.comac10a2d2010-12-22 21:39:39 +0000242
bsalomon@google.com1c13c962011-02-14 16:51:21 +0000243static inline void fill_indices(uint16_t* indices, int quadCount) {
reed@google.comac10a2d2010-12-22 21:39:39 +0000244 for (int i = 0; i < quadCount; ++i) {
245 indices[6 * i + 0] = 4 * i + 0;
246 indices[6 * i + 1] = 4 * i + 1;
247 indices[6 * i + 2] = 4 * i + 2;
248 indices[6 * i + 3] = 4 * i + 0;
249 indices[6 * i + 4] = 4 * i + 2;
250 indices[6 * i + 5] = 4 * i + 3;
251 }
252}
253
bsalomon@google.com86afc2a2011-02-16 16:12:19 +0000254const GrIndexBuffer* GrGpu::getQuadIndexBuffer() const {
reed@google.comac10a2d2010-12-22 21:39:39 +0000255 if (NULL == fQuadIndexBuffer) {
256 static const int SIZE = sizeof(uint16_t) * 6 * MAX_QUADS;
257 GrGpu* me = const_cast<GrGpu*>(this);
258 fQuadIndexBuffer = me->createIndexBuffer(SIZE, false);
259 if (NULL != fQuadIndexBuffer) {
260 uint16_t* indices = (uint16_t*)fQuadIndexBuffer->lock();
261 if (NULL != indices) {
bsalomon@google.com1c13c962011-02-14 16:51:21 +0000262 fill_indices(indices, MAX_QUADS);
reed@google.comac10a2d2010-12-22 21:39:39 +0000263 fQuadIndexBuffer->unlock();
264 } else {
265 indices = (uint16_t*)GrMalloc(SIZE);
bsalomon@google.com1c13c962011-02-14 16:51:21 +0000266 fill_indices(indices, MAX_QUADS);
reed@google.comac10a2d2010-12-22 21:39:39 +0000267 if (!fQuadIndexBuffer->updateData(indices, SIZE)) {
268 fQuadIndexBuffer->unref();
269 fQuadIndexBuffer = NULL;
bsalomon@google.com6f7fbc92011-02-01 19:12:40 +0000270 GrCrash("Can't get indices into buffer!");
reed@google.comac10a2d2010-12-22 21:39:39 +0000271 }
272 GrFree(indices);
273 }
274 }
275 }
276
277 return fQuadIndexBuffer;
278}
279
bsalomon@google.com86afc2a2011-02-16 16:12:19 +0000280const GrVertexBuffer* GrGpu::getUnitSquareVertexBuffer() const {
bsalomon@google.com6f7fbc92011-02-01 19:12:40 +0000281 if (NULL == fUnitSquareVertexBuffer) {
282
283 static const GrPoint DATA[] = {
reed@google.com7744c202011-05-06 19:26:26 +0000284 { 0, 0 },
285 { GR_Scalar1, 0 },
286 { GR_Scalar1, GR_Scalar1 },
287 { 0, GR_Scalar1 }
288#if 0
bsalomon@google.com6f7fbc92011-02-01 19:12:40 +0000289 GrPoint(0, 0),
290 GrPoint(GR_Scalar1,0),
291 GrPoint(GR_Scalar1,GR_Scalar1),
292 GrPoint(0, GR_Scalar1)
reed@google.com7744c202011-05-06 19:26:26 +0000293#endif
bsalomon@google.com6f7fbc92011-02-01 19:12:40 +0000294 };
295 static const size_t SIZE = sizeof(DATA);
296
297 GrGpu* me = const_cast<GrGpu*>(this);
298 fUnitSquareVertexBuffer = me->createVertexBuffer(SIZE, false);
299 if (NULL != fUnitSquareVertexBuffer) {
300 if (!fUnitSquareVertexBuffer->updateData(DATA, SIZE)) {
301 fUnitSquareVertexBuffer->unref();
302 fUnitSquareVertexBuffer = NULL;
303 GrCrash("Can't get vertices into buffer!");
304 }
305 }
306 }
307
308 return fUnitSquareVertexBuffer;
309}
310
bsalomon@google.comd302f142011-03-03 13:54:13 +0000311////////////////////////////////////////////////////////////////////////////////
reed@google.comac10a2d2010-12-22 21:39:39 +0000312
bsalomon@google.comd302f142011-03-03 13:54:13 +0000313// stencil settings to use when clip is in stencil
314const GrStencilSettings GrGpu::gClipStencilSettings = {
315 kKeep_StencilOp, kKeep_StencilOp,
316 kKeep_StencilOp, kKeep_StencilOp,
317 kAlwaysIfInClip_StencilFunc, kAlwaysIfInClip_StencilFunc,
318 0, 0,
319 0, 0,
320 0, 0
321};
322
bsalomon@google.coma7f84e12011-03-10 14:13:19 +0000323// mapping of clip-respecting stencil funcs to normal stencil funcs
324// mapping depends on whether stencil-clipping is in effect.
bsalomon@google.comd302f142011-03-03 13:54:13 +0000325static const GrStencilFunc gGrClipToNormalStencilFunc[2][kClipStencilFuncCount] = {
326 {// Stencil-Clipping is DISABLED, effectively always inside the clip
327 // In the Clip Funcs
328 kAlways_StencilFunc, // kAlwaysIfInClip_StencilFunc
329 kEqual_StencilFunc, // kEqualIfInClip_StencilFunc
330 kLess_StencilFunc, // kLessIfInClip_StencilFunc
331 kLEqual_StencilFunc, // kLEqualIfInClip_StencilFunc
332 // Special in the clip func that forces user's ref to be 0.
333 kNotEqual_StencilFunc, // kNonZeroIfInClip_StencilFunc
334 // make ref 0 and do normal nequal.
335 },
336 {// Stencil-Clipping is ENABLED
337 // In the Clip Funcs
338 kEqual_StencilFunc, // kAlwaysIfInClip_StencilFunc
339 // eq stencil clip bit, mask
340 // out user bits.
341
342 kEqual_StencilFunc, // kEqualIfInClip_StencilFunc
343 // add stencil bit to mask and ref
344
345 kLess_StencilFunc, // kLessIfInClip_StencilFunc
346 kLEqual_StencilFunc, // kLEqualIfInClip_StencilFunc
347 // for both of these we can add
348 // the clip bit to the mask and
349 // ref and compare as normal
350 // Special in the clip func that forces user's ref to be 0.
351 kLess_StencilFunc, // kNonZeroIfInClip_StencilFunc
352 // make ref have only the clip bit set
353 // and make comparison be less
354 // 10..0 < 1..user_bits..
355 }
356};
357
358GrStencilFunc GrGpu::ConvertStencilFunc(bool stencilInClip, GrStencilFunc func) {
359 GrAssert(func >= 0);
360 if (func >= kBasicStencilFuncCount) {
361 GrAssert(func < kStencilFuncCount);
362 func = gGrClipToNormalStencilFunc[stencilInClip ? 1 : 0][func - kBasicStencilFuncCount];
363 GrAssert(func >= 0 && func < kBasicStencilFuncCount);
364 }
365 return func;
366}
367
368void GrGpu::ConvertStencilFuncAndMask(GrStencilFunc func,
369 bool clipInStencil,
370 unsigned int clipBit,
371 unsigned int userBits,
372 unsigned int* ref,
373 unsigned int* mask) {
374 if (func < kBasicStencilFuncCount) {
375 *mask &= userBits;
376 *ref &= userBits;
377 } else {
378 if (clipInStencil) {
379 switch (func) {
380 case kAlwaysIfInClip_StencilFunc:
381 *mask = clipBit;
382 *ref = clipBit;
383 break;
384 case kEqualIfInClip_StencilFunc:
385 case kLessIfInClip_StencilFunc:
386 case kLEqualIfInClip_StencilFunc:
387 *mask = (*mask & userBits) | clipBit;
388 *ref = (*ref & userBits) | clipBit;
389 break;
390 case kNonZeroIfInClip_StencilFunc:
391 *mask = (*mask & userBits) | clipBit;
392 *ref = clipBit;
393 break;
394 default:
395 GrCrash("Unknown stencil func");
396 }
397 } else {
398 *mask &= userBits;
399 *ref &= userBits;
400 }
401 }
402}
403
404////////////////////////////////////////////////////////////////////////////////
405
406#define VISUALIZE_COMPLEX_CLIP 0
407
408#if VISUALIZE_COMPLEX_CLIP
409 #include "GrRandom.h"
410 GrRandom gRandom;
411 #define SET_RANDOM_COLOR this->setColor(0xff000000 | gRandom.nextU());
412#else
413 #define SET_RANDOM_COLOR
414#endif
415
bsalomon@google.comffca4002011-02-22 20:34:01 +0000416bool GrGpu::setupClipAndFlushState(GrPrimitiveType type) {
reed@google.comac10a2d2010-12-22 21:39:39 +0000417 const GrIRect* r = NULL;
bsalomon@google.comd302f142011-03-03 13:54:13 +0000418 GrIRect clipRect;
reed@google.comac10a2d2010-12-22 21:39:39 +0000419
bsalomon@google.com2e7b43d2011-01-18 20:57:22 +0000420 // we check this early because we need a valid
421 // render target to setup stencil clipping
422 // before even going into flushGraphicsState
423 if (NULL == fCurrDrawState.fRenderTarget) {
424 GrAssert(!"No render target bound.");
425 return false;
426 }
427
reed@google.comac10a2d2010-12-22 21:39:39 +0000428 if (fCurrDrawState.fFlagBits & kClip_StateBit) {
bsalomon@google.comd302f142011-03-03 13:54:13 +0000429 GrRenderTarget& rt = *fCurrDrawState.fRenderTarget;
430
431 GrRect bounds;
432 GrRect rtRect;
433 rtRect.setLTRB(0, 0,
434 GrIntToScalar(rt.width()), GrIntToScalar(rt.height()));
bsalomon@google.com0b50b2e2011-03-08 21:07:21 +0000435 if (fClip.hasConservativeBounds()) {
436 bounds = fClip.getConservativeBounds();
reed@google.com20efde72011-05-09 17:00:02 +0000437 if (!bounds.intersect(rtRect)) {
438 bounds.setEmpty();
439 }
bsalomon@google.comd302f142011-03-03 13:54:13 +0000440 } else {
441 bounds = rtRect;
442 }
443
444 bounds.roundOut(&clipRect);
445 if (clipRect.isEmpty()) {
446 clipRect.setLTRB(0,0,0,0);
447 }
448 r = &clipRect;
449
bsalomon@google.comdea2f8d2011-08-01 15:51:05 +0000450 // use the stencil clip if we can't represent the clip as a rectangle.
451 fClipInStencil = !fClip.isRect() && !fClip.isEmpty() &&
452 !bounds.isEmpty();
reed@google.comac10a2d2010-12-22 21:39:39 +0000453
bsalomon@google.com81c3f8d2011-08-03 15:18:33 +0000454 // TODO: dynamically attach a SB when needed.
455 GrStencilBuffer* stencilBuffer = rt.getStencilBuffer();
456 if (fClipInStencil && NULL == stencilBuffer) {
457 return false;
458 }
bsalomon@google.coma16d6502011-08-02 14:07:52 +0000459
bsalomon@google.com81c3f8d2011-08-03 15:18:33 +0000460 if (fClipInStencil &&
461 stencilBuffer->mustRenderClip(fClip, rt.width(), rt.height())) {
462
463 stencilBuffer->setLastClip(fClip, rt.width(), rt.height());
464
bsalomon@google.comd302f142011-03-03 13:54:13 +0000465 // we set the current clip to the bounds so that our recursive
466 // draws are scissored to them. We use the copy of the complex clip
bsalomon@google.com81c3f8d2011-08-03 15:18:33 +0000467 // we just stashed on the SB to render from. We set it back after
468 // we finish drawing it into the stencil.
469 const GrClip& clip = stencilBuffer->getLastClip();
bsalomon@google.comd302f142011-03-03 13:54:13 +0000470 fClip.setFromRect(bounds);
reed@google.comac10a2d2010-12-22 21:39:39 +0000471
472 AutoStateRestore asr(this);
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000473 AutoGeometryPush agp(this);
bsalomon@google.com1c13c962011-02-14 16:51:21 +0000474
bsalomon@google.com1c13c962011-02-14 16:51:21 +0000475 this->setViewMatrix(GrMatrix::I());
bsalomon@google.com398109c2011-04-14 18:40:27 +0000476 this->clearStencilClip(clipRect);
bsalomon@google.comd302f142011-03-03 13:54:13 +0000477 this->flushScissor(NULL);
478#if !VISUALIZE_COMPLEX_CLIP
479 this->enableState(kNoColorWrites_StateBit);
480#else
481 this->disableState(kNoColorWrites_StateBit);
482#endif
483 int count = clip.getElementCount();
bsalomon@google.com81c3f8d2011-08-03 15:18:33 +0000484 int clipBit = stencilBuffer->bits();
bsalomon@google.comd302f142011-03-03 13:54:13 +0000485 clipBit = (1 << (clipBit-1));
486
bsalomon@google.com5aaa69e2011-03-04 20:29:08 +0000487 // often we'll see the first two elements of the clip are
488 // the full rt size and another element intersected with it.
489 // We can skip the first full-size rect and save a big rect draw.
490 int firstElement = 0;
bsalomon@google.com0b50b2e2011-03-08 21:07:21 +0000491 if (clip.getElementCount() > 1 &&
bsalomon@google.com5aaa69e2011-03-04 20:29:08 +0000492 kRect_ClipType == clip.getElementType(0) &&
493 kIntersect_SetOp == clip.getOp(1)&&
494 clip.getRect(0).contains(bounds)) {
495 firstElement = 1;
496 }
bsalomon@google.com0b50b2e2011-03-08 21:07:21 +0000497
bsalomon@google.comd302f142011-03-03 13:54:13 +0000498 // walk through each clip element and perform its set op
499 // with the existing clip.
bsalomon@google.com5aaa69e2011-03-04 20:29:08 +0000500 for (int c = firstElement; c < count; ++c) {
bsalomon@google.comd302f142011-03-03 13:54:13 +0000501 GrPathFill fill;
bsalomon@google.comee435122011-07-01 14:57:55 +0000502 bool fillInverted;
bsalomon@google.comd302f142011-03-03 13:54:13 +0000503 // enabled at bottom of loop
504 this->disableState(kModifyStencilClip_StateBit);
505
bsalomon@google.com7f5875d2011-03-24 16:55:45 +0000506 bool canRenderDirectToStencil; // can the clip element be drawn
507 // directly to the stencil buffer
508 // with a non-inverted fill rule
509 // without extra passes to
bsalomon@google.comdfe75bc2011-03-25 12:31:16 +0000510 // resolve in/out status.
511
512 GrPathRenderer* pr = NULL;
reed@google.com07f3ee12011-05-16 17:21:57 +0000513 const GrPath* clipPath = NULL;
bsalomon@google.comee435122011-07-01 14:57:55 +0000514 GrPathRenderer::AutoClearPath arp;
bsalomon@google.comd302f142011-03-03 13:54:13 +0000515 if (kRect_ClipType == clip.getElementType(c)) {
bsalomon@google.com7f5875d2011-03-24 16:55:45 +0000516 canRenderDirectToStencil = true;
bsalomon@google.comd302f142011-03-03 13:54:13 +0000517 fill = kEvenOdd_PathFill;
bsalomon@google.comee435122011-07-01 14:57:55 +0000518 fillInverted = false;
bsalomon@google.comd302f142011-03-03 13:54:13 +0000519 } else {
520 fill = clip.getPathFill(c);
bsalomon@google.comee435122011-07-01 14:57:55 +0000521 fillInverted = IsFillInverted(fill);
522 fill = NonInvertedFill(fill);
reed@google.com07f3ee12011-05-16 17:21:57 +0000523 clipPath = &clip.getPath(c);
bsalomon@google.comee435122011-07-01 14:57:55 +0000524 pr = this->getClipPathRenderer(*clipPath, fill);
bsalomon@google.com30085192011-08-19 15:42:31 +0000525 if (NULL == pr) {
526 fClipInStencil = false;
527 fClip = clip;
528 return false;
529 }
bsalomon@google.com11f0b512011-03-29 20:52:23 +0000530 canRenderDirectToStencil =
bsalomon@google.comee435122011-07-01 14:57:55 +0000531 !pr->requiresStencilPass(this, *clipPath, fill);
532 arp.set(pr, this, clipPath, fill, NULL);
bsalomon@google.comd302f142011-03-03 13:54:13 +0000533 }
534
bsalomon@google.com5aaa69e2011-03-04 20:29:08 +0000535 GrSetOp op = firstElement == c ? kReplace_SetOp : clip.getOp(c);
bsalomon@google.comd302f142011-03-03 13:54:13 +0000536 int passes;
537 GrStencilSettings stencilSettings[GrStencilSettings::kMaxStencilClipPasses];
538
bsalomon@google.com11f0b512011-03-29 20:52:23 +0000539 bool canDrawDirectToClip; // Given the renderer, the element,
bsalomon@google.com7f5875d2011-03-24 16:55:45 +0000540 // fill rule, and set operation can
541 // we render the element directly to
542 // stencil bit used for clipping.
bsalomon@google.com11f0b512011-03-29 20:52:23 +0000543 canDrawDirectToClip =
544 GrStencilSettings::GetClipPasses(op,
bsalomon@google.com7f5875d2011-03-24 16:55:45 +0000545 canRenderDirectToStencil,
bsalomon@google.com11f0b512011-03-29 20:52:23 +0000546 clipBit,
bsalomon@google.comee435122011-07-01 14:57:55 +0000547 fillInverted,
bsalomon@google.com7f5875d2011-03-24 16:55:45 +0000548 &passes, stencilSettings);
bsalomon@google.comd302f142011-03-03 13:54:13 +0000549
550 // draw the element to the client stencil bits if necessary
551 if (!canDrawDirectToClip) {
bsalomon@google.com7f5875d2011-03-24 16:55:45 +0000552 static const GrStencilSettings gDrawToStencil = {
553 kIncClamp_StencilOp, kIncClamp_StencilOp,
554 kIncClamp_StencilOp, kIncClamp_StencilOp,
555 kAlways_StencilFunc, kAlways_StencilFunc,
556 0xffffffff, 0xffffffff,
557 0x00000000, 0x00000000,
558 0xffffffff, 0xffffffff,
559 };
560 SET_RANDOM_COLOR
bsalomon@google.comd302f142011-03-03 13:54:13 +0000561 if (kRect_ClipType == clip.getElementType(c)) {
bsalomon@google.comd302f142011-03-03 13:54:13 +0000562 this->setStencil(gDrawToStencil);
bsalomon@google.comd302f142011-03-03 13:54:13 +0000563 this->drawSimpleRect(clip.getRect(c), NULL, 0);
564 } else {
bsalomon@google.com7f5875d2011-03-24 16:55:45 +0000565 if (canRenderDirectToStencil) {
566 this->setStencil(gDrawToStencil);
bsalomon@google.comee435122011-07-01 14:57:55 +0000567 pr->drawPath(0);
bsalomon@google.com7f5875d2011-03-24 16:55:45 +0000568 } else {
bsalomon@google.comee435122011-07-01 14:57:55 +0000569 pr->drawPathToStencil();
bsalomon@google.com7f5875d2011-03-24 16:55:45 +0000570 }
bsalomon@google.comd302f142011-03-03 13:54:13 +0000571 }
572 }
573
574 // now we modify the clip bit by rendering either the clip
575 // element directly or a bounding rect of the entire clip.
576 this->enableState(kModifyStencilClip_StateBit);
577 for (int p = 0; p < passes; ++p) {
578 this->setStencil(stencilSettings[p]);
579 if (canDrawDirectToClip) {
580 if (kRect_ClipType == clip.getElementType(c)) {
581 SET_RANDOM_COLOR
582 this->drawSimpleRect(clip.getRect(c), NULL, 0);
583 } else {
584 SET_RANDOM_COLOR
bsalomon@google.comee435122011-07-01 14:57:55 +0000585 pr->drawPath(0);
bsalomon@google.comd302f142011-03-03 13:54:13 +0000586 }
587 } else {
588 SET_RANDOM_COLOR
thakis@chromium.org441d7da2011-06-07 04:03:17 +0000589 this->drawSimpleRect(bounds, NULL, 0);
bsalomon@google.comd302f142011-03-03 13:54:13 +0000590 }
591 }
reed@google.comac10a2d2010-12-22 21:39:39 +0000592 }
bsalomon@google.comdea2f8d2011-08-01 15:51:05 +0000593 // restore clip
bsalomon@google.comd302f142011-03-03 13:54:13 +0000594 fClip = clip;
bsalomon@google.comdea2f8d2011-08-01 15:51:05 +0000595 // recusive draws would have disabled this since they drew with
596 // the clip bounds as clip.
597 fClipInStencil = true;
reed@google.comac10a2d2010-12-22 21:39:39 +0000598 }
reed@google.comac10a2d2010-12-22 21:39:39 +0000599 }
bsalomon@google.comd302f142011-03-03 13:54:13 +0000600
reed@google.comac10a2d2010-12-22 21:39:39 +0000601 // Must flush the scissor after graphics state
bsalomon@google.comd302f142011-03-03 13:54:13 +0000602 if (!this->flushGraphicsState(type)) {
reed@google.comac10a2d2010-12-22 21:39:39 +0000603 return false;
604 }
bsalomon@google.comd302f142011-03-03 13:54:13 +0000605 this->flushScissor(r);
reed@google.comac10a2d2010-12-22 21:39:39 +0000606 return true;
607}
608
reed@google.com07f3ee12011-05-16 17:21:57 +0000609GrPathRenderer* GrGpu::getClipPathRenderer(const GrPath& path,
bsalomon@google.comdfe75bc2011-03-25 12:31:16 +0000610 GrPathFill fill) {
bsalomon@google.com30085192011-08-19 15:42:31 +0000611 if (NULL == fPathRendererChain) {
612 fPathRendererChain =
613 new GrPathRendererChain(this->getContext(),
614 GrPathRendererChain::kNonAAOnly_UsageFlag);
bsalomon@google.comdfe75bc2011-03-25 12:31:16 +0000615 }
bsalomon@google.com30085192011-08-19 15:42:31 +0000616 return fPathRendererChain->getPathRenderer(this, path, fill);
bsalomon@google.comdfe75bc2011-03-25 12:31:16 +0000617}
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