epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 1 | |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 2 | /* |
epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 3 | * 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.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 7 | */ |
| 8 | |
epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 9 | |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 10 | #include "GrGpu.h" |
bsalomon@google.com | 558a75b | 2011-08-08 17:01:14 +0000 | [diff] [blame] | 11 | |
bsalomon@google.com | 81c3f8d | 2011-08-03 15:18:33 +0000 | [diff] [blame] | 12 | #include "GrBufferAllocPool.h" |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 13 | #include "GrClipIterator.h" |
bsalomon@google.com | 558a75b | 2011-08-08 17:01:14 +0000 | [diff] [blame] | 14 | #include "GrContext.h" |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 15 | #include "GrIndexBuffer.h" |
bsalomon@google.com | 4043ae2 | 2011-08-02 14:19:11 +0000 | [diff] [blame] | 16 | #include "GrPathRenderer.h" |
bsalomon@google.com | 81c3f8d | 2011-08-03 15:18:33 +0000 | [diff] [blame] | 17 | #include "GrGLStencilBuffer.h" |
| 18 | #include "GrVertexBuffer.h" |
bsalomon@google.com | 1c13c96 | 2011-02-14 16:51:21 +0000 | [diff] [blame] | 19 | |
| 20 | // probably makes no sense for this to be less than a page |
bsalomon@google.com | ee43512 | 2011-07-01 14:57:55 +0000 | [diff] [blame] | 21 | static const size_t VERTEX_POOL_VB_SIZE = 1 << 18; |
| 22 | static const int VERTEX_POOL_VB_COUNT = 4; |
bsalomon@google.com | 25fd36c | 2011-07-06 17:41:08 +0000 | [diff] [blame] | 23 | static const size_t INDEX_POOL_IB_SIZE = 1 << 16; |
| 24 | static const int INDEX_POOL_IB_COUNT = 4; |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 25 | |
bsalomon@google.com | d302f14 | 2011-03-03 13:54:13 +0000 | [diff] [blame] | 26 | //////////////////////////////////////////////////////////////////////////////// |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 27 | |
| 28 | extern void gr_run_unittests(); |
| 29 | |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 30 | #define DEBUG_INVAL_BUFFER 0xdeadcafe |
| 31 | #define DEBUG_INVAL_START_IDX -1 |
| 32 | |
bsalomon@google.com | 8fe7247 | 2011-03-30 21:26:44 +0000 | [diff] [blame] | 33 | GrGpu::GrGpu() |
bsalomon@google.com | 18c9c19 | 2011-09-22 21:01:31 +0000 | [diff] [blame] | 34 | : fContext(NULL) |
bsalomon@google.com | 979432b | 2011-11-05 21:38:22 +0000 | [diff] [blame] | 35 | , fResetTimestamp(kExpiredTimestamp+1) |
bsalomon@google.com | 8fe7247 | 2011-03-30 21:26:44 +0000 | [diff] [blame] | 36 | , fVertexPool(NULL) |
| 37 | , fIndexPool(NULL) |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 38 | , fVertexPoolUseCnt(0) |
| 39 | , fIndexPoolUseCnt(0) |
bsalomon@google.com | 8fe7247 | 2011-03-30 21:26:44 +0000 | [diff] [blame] | 40 | , fQuadIndexBuffer(NULL) |
| 41 | , fUnitSquareVertexBuffer(NULL) |
bsalomon@google.com | 3008519 | 2011-08-19 15:42:31 +0000 | [diff] [blame] | 42 | , fPathRendererChain(NULL) |
bsalomon@google.com | 8fe7247 | 2011-03-30 21:26:44 +0000 | [diff] [blame] | 43 | , fContextIsDirty(true) |
bsalomon@google.com | 8fe7247 | 2011-03-30 21:26:44 +0000 | [diff] [blame] | 44 | , fResourceHead(NULL) { |
bsalomon@google.com | 669fdc4 | 2011-04-05 17:08:27 +0000 | [diff] [blame] | 45 | |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 46 | #if GR_DEBUG |
bsalomon@google.com | 5aaa69e | 2011-03-04 20:29:08 +0000 | [diff] [blame] | 47 | //gr_run_unittests(); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 48 | #endif |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 49 | |
| 50 | fGeomPoolStateStack.push_back(); |
| 51 | #if GR_DEBUG |
| 52 | GeometryPoolState& poolState = fGeomPoolStateStack.back(); |
| 53 | poolState.fPoolVertexBuffer = (GrVertexBuffer*)DEBUG_INVAL_BUFFER; |
| 54 | poolState.fPoolStartVertex = DEBUG_INVAL_START_IDX; |
| 55 | poolState.fPoolIndexBuffer = (GrIndexBuffer*)DEBUG_INVAL_BUFFER; |
| 56 | poolState.fPoolStartIndex = DEBUG_INVAL_START_IDX; |
| 57 | #endif |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 58 | resetStats(); |
| 59 | } |
| 60 | |
| 61 | GrGpu::~GrGpu() { |
bsalomon@google.com | 558a75b | 2011-08-08 17:01:14 +0000 | [diff] [blame] | 62 | this->releaseResources(); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 63 | } |
| 64 | |
bsalomon@google.com | 8fe7247 | 2011-03-30 21:26:44 +0000 | [diff] [blame] | 65 | void GrGpu::abandonResources() { |
| 66 | |
| 67 | while (NULL != fResourceHead) { |
| 68 | fResourceHead->abandon(); |
| 69 | } |
| 70 | |
| 71 | GrAssert(NULL == fQuadIndexBuffer || !fQuadIndexBuffer->isValid()); |
| 72 | GrAssert(NULL == fUnitSquareVertexBuffer || |
| 73 | !fUnitSquareVertexBuffer->isValid()); |
| 74 | GrSafeSetNull(fQuadIndexBuffer); |
| 75 | GrSafeSetNull(fUnitSquareVertexBuffer); |
| 76 | delete fVertexPool; |
| 77 | fVertexPool = NULL; |
| 78 | delete fIndexPool; |
| 79 | fIndexPool = NULL; |
bsalomon@google.com | 3008519 | 2011-08-19 15:42:31 +0000 | [diff] [blame] | 80 | // in case path renderer has any GrResources, start from scratch |
| 81 | GrSafeSetNull(fPathRendererChain); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 82 | } |
| 83 | |
bsalomon@google.com | 8fe7247 | 2011-03-30 21:26:44 +0000 | [diff] [blame] | 84 | void GrGpu::releaseResources() { |
| 85 | |
| 86 | while (NULL != fResourceHead) { |
| 87 | fResourceHead->release(); |
| 88 | } |
| 89 | |
| 90 | GrAssert(NULL == fQuadIndexBuffer || !fQuadIndexBuffer->isValid()); |
| 91 | GrAssert(NULL == fUnitSquareVertexBuffer || |
| 92 | !fUnitSquareVertexBuffer->isValid()); |
| 93 | GrSafeSetNull(fQuadIndexBuffer); |
| 94 | GrSafeSetNull(fUnitSquareVertexBuffer); |
| 95 | delete fVertexPool; |
| 96 | fVertexPool = NULL; |
| 97 | delete fIndexPool; |
| 98 | fIndexPool = NULL; |
bsalomon@google.com | 3008519 | 2011-08-19 15:42:31 +0000 | [diff] [blame] | 99 | // in case path renderer has any GrResources, start from scratch |
| 100 | GrSafeSetNull(fPathRendererChain); |
bsalomon@google.com | 8fe7247 | 2011-03-30 21:26:44 +0000 | [diff] [blame] | 101 | } |
| 102 | |
| 103 | void 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 | |
| 117 | void 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.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 136 | void GrGpu::unimpl(const char msg[]) { |
bsalomon@google.com | 7d34d2e | 2011-01-24 17:41:47 +0000 | [diff] [blame] | 137 | #if GR_DEBUG |
| 138 | GrPrintf("--- GrGpu unimplemented(\"%s\")\n", msg); |
| 139 | #endif |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 140 | } |
| 141 | |
bsalomon@google.com | d302f14 | 2011-03-03 13:54:13 +0000 | [diff] [blame] | 142 | //////////////////////////////////////////////////////////////////////////////// |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 143 | |
bsalomon@google.com | fea37b5 | 2011-04-25 15:51:06 +0000 | [diff] [blame] | 144 | GrTexture* GrGpu::createTexture(const GrTextureDesc& desc, |
bsalomon@google.com | a7f84e1 | 2011-03-10 14:13:19 +0000 | [diff] [blame] | 145 | const void* srcData, size_t rowBytes) { |
| 146 | this->handleDirtyContext(); |
bsalomon@google.com | 81c3f8d | 2011-08-03 15:18:33 +0000 | [diff] [blame] | 147 | 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 | |
| 161 | bool GrGpu::attachStencilBufferToRenderTarget(GrRenderTarget* rt) { |
bsalomon@google.com | 558a75b | 2011-08-08 17:01:14 +0000 | [diff] [blame] | 162 | GrAssert(NULL == rt->getStencilBuffer()); |
| 163 | GrStencilBuffer* sb = |
bsalomon@google.com | 9962108 | 2011-11-15 16:47:16 +0000 | [diff] [blame] | 164 | this->getContext()->findStencilBuffer(rt->width(), |
| 165 | rt->height(), |
bsalomon@google.com | 558a75b | 2011-08-08 17:01:14 +0000 | [diff] [blame] | 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 | } |
bsalomon@google.com | 9962108 | 2011-11-15 16:47:16 +0000 | [diff] [blame] | 175 | if (this->createStencilBufferForRenderTarget(rt, |
| 176 | rt->width(), rt->height())) { |
bsalomon@google.com | 558a75b | 2011-08-08 17:01:14 +0000 | [diff] [blame] | 177 | rt->getStencilBuffer()->ref(); |
| 178 | rt->getStencilBuffer()->transferToCacheAndLock(); |
| 179 | |
bsalomon@google.com | edc177d | 2011-08-05 15:46:40 +0000 | [diff] [blame] | 180 | // 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. |
bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 188 | GrDrawState::AutoRenderTargetRestore artr(this->drawState(), rt); |
bsalomon@google.com | edc177d | 2011-08-05 15:46:40 +0000 | [diff] [blame] | 189 | this->clearStencil(); |
bsalomon@google.com | 558a75b | 2011-08-08 17:01:14 +0000 | [diff] [blame] | 190 | return true; |
| 191 | } else { |
| 192 | return false; |
bsalomon@google.com | edc177d | 2011-08-05 15:46:40 +0000 | [diff] [blame] | 193 | } |
bsalomon@google.com | a7f84e1 | 2011-03-10 14:13:19 +0000 | [diff] [blame] | 194 | } |
| 195 | |
bsalomon@google.com | e269f21 | 2011-11-07 13:29:52 +0000 | [diff] [blame] | 196 | GrTexture* GrGpu::createPlatformTexture(const GrPlatformTextureDesc& desc) { |
| 197 | this->handleDirtyContext(); |
| 198 | GrTexture* tex = this->onCreatePlatformTexture(desc); |
| 199 | // TODO: defer this and attach dynamically |
| 200 | GrRenderTarget* tgt = tex->asRenderTarget(); |
| 201 | if (NULL != tgt && |
| 202 | !this->attachStencilBufferToRenderTarget(tgt)) { |
| 203 | tex->unref(); |
| 204 | return NULL; |
| 205 | } else { |
| 206 | return tex; |
| 207 | } |
| 208 | } |
| 209 | |
| 210 | GrRenderTarget* GrGpu::createPlatformRenderTarget(const GrPlatformRenderTargetDesc& desc) { |
| 211 | this->handleDirtyContext(); |
| 212 | return this->onCreatePlatformRenderTarget(desc); |
| 213 | } |
| 214 | |
bsalomon@google.com | 5877ffd | 2011-04-11 17:58:48 +0000 | [diff] [blame] | 215 | GrResource* GrGpu::createPlatformSurface(const GrPlatformSurfaceDesc& desc) { |
| 216 | this->handleDirtyContext(); |
| 217 | return this->onCreatePlatformSurface(desc); |
| 218 | } |
| 219 | |
bsalomon@google.com | a7f84e1 | 2011-03-10 14:13:19 +0000 | [diff] [blame] | 220 | GrVertexBuffer* GrGpu::createVertexBuffer(uint32_t size, bool dynamic) { |
| 221 | this->handleDirtyContext(); |
bsalomon@google.com | bcdbbe6 | 2011-04-12 15:40:00 +0000 | [diff] [blame] | 222 | return this->onCreateVertexBuffer(size, dynamic); |
bsalomon@google.com | a7f84e1 | 2011-03-10 14:13:19 +0000 | [diff] [blame] | 223 | } |
| 224 | |
| 225 | GrIndexBuffer* GrGpu::createIndexBuffer(uint32_t size, bool dynamic) { |
| 226 | this->handleDirtyContext(); |
bsalomon@google.com | bcdbbe6 | 2011-04-12 15:40:00 +0000 | [diff] [blame] | 227 | return this->onCreateIndexBuffer(size, dynamic); |
bsalomon@google.com | a7f84e1 | 2011-03-10 14:13:19 +0000 | [diff] [blame] | 228 | } |
| 229 | |
bsalomon@google.com | 6aa25c3 | 2011-04-27 19:55:29 +0000 | [diff] [blame] | 230 | void GrGpu::clear(const GrIRect* rect, GrColor color) { |
bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 231 | if (NULL == this->getDrawState().getRenderTarget()) { |
bsalomon@google.com | 0ba52fc | 2011-11-10 22:16:06 +0000 | [diff] [blame] | 232 | return; |
| 233 | } |
bsalomon@google.com | a7f84e1 | 2011-03-10 14:13:19 +0000 | [diff] [blame] | 234 | this->handleDirtyContext(); |
bsalomon@google.com | 6aa25c3 | 2011-04-27 19:55:29 +0000 | [diff] [blame] | 235 | this->onClear(rect, color); |
bsalomon@google.com | a7f84e1 | 2011-03-10 14:13:19 +0000 | [diff] [blame] | 236 | } |
| 237 | |
| 238 | void GrGpu::forceRenderTargetFlush() { |
| 239 | this->handleDirtyContext(); |
bsalomon@google.com | bcdbbe6 | 2011-04-12 15:40:00 +0000 | [diff] [blame] | 240 | this->onForceRenderTargetFlush(); |
bsalomon@google.com | a7f84e1 | 2011-03-10 14:13:19 +0000 | [diff] [blame] | 241 | } |
| 242 | |
bsalomon@google.com | 669fdc4 | 2011-04-05 17:08:27 +0000 | [diff] [blame] | 243 | bool GrGpu::readPixels(GrRenderTarget* target, |
| 244 | int left, int top, int width, int height, |
bsalomon@google.com | c698097 | 2011-11-02 19:57:21 +0000 | [diff] [blame] | 245 | GrPixelConfig config, void* buffer, |
bsalomon@google.com | c436499 | 2011-11-07 15:54:49 +0000 | [diff] [blame] | 246 | size_t rowBytes, bool invertY) { |
| 247 | GrAssert(GrPixelConfigIsUnpremultiplied(config) == |
| 248 | GrPixelConfigIsUnpremultiplied(target->config())); |
bsalomon@google.com | a7f84e1 | 2011-03-10 14:13:19 +0000 | [diff] [blame] | 249 | this->handleDirtyContext(); |
bsalomon@google.com | c698097 | 2011-11-02 19:57:21 +0000 | [diff] [blame] | 250 | return this->onReadPixels(target, left, top, width, height, |
bsalomon@google.com | c436499 | 2011-11-07 15:54:49 +0000 | [diff] [blame] | 251 | config, buffer, rowBytes, invertY); |
bsalomon@google.com | a7f84e1 | 2011-03-10 14:13:19 +0000 | [diff] [blame] | 252 | } |
| 253 | |
bsalomon@google.com | 6f37951 | 2011-11-16 20:36:03 +0000 | [diff] [blame] | 254 | void GrGpu::writeTexturePixels(GrTexture* texture, |
| 255 | int left, int top, int width, int height, |
| 256 | GrPixelConfig config, const void* buffer, |
| 257 | size_t rowBytes) { |
| 258 | GrAssert(GrPixelConfigIsUnpremultiplied(config) == |
| 259 | GrPixelConfigIsUnpremultiplied(texture->config())); |
| 260 | this->handleDirtyContext(); |
| 261 | this->onWriteTexturePixels(texture, left, top, width, height, |
| 262 | config, buffer, rowBytes); |
| 263 | } |
| 264 | |
bsalomon@google.com | a7f84e1 | 2011-03-10 14:13:19 +0000 | [diff] [blame] | 265 | //////////////////////////////////////////////////////////////////////////////// |
| 266 | |
bsalomon@google.com | 1c13c96 | 2011-02-14 16:51:21 +0000 | [diff] [blame] | 267 | static const int MAX_QUADS = 1 << 12; // max possible: (1 << 14) - 1; |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 268 | |
reed@google.com | 8195f67 | 2011-01-12 18:14:28 +0000 | [diff] [blame] | 269 | GR_STATIC_ASSERT(4 * MAX_QUADS <= 65535); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 270 | |
bsalomon@google.com | 1c13c96 | 2011-02-14 16:51:21 +0000 | [diff] [blame] | 271 | static inline void fill_indices(uint16_t* indices, int quadCount) { |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 272 | for (int i = 0; i < quadCount; ++i) { |
| 273 | indices[6 * i + 0] = 4 * i + 0; |
| 274 | indices[6 * i + 1] = 4 * i + 1; |
| 275 | indices[6 * i + 2] = 4 * i + 2; |
| 276 | indices[6 * i + 3] = 4 * i + 0; |
| 277 | indices[6 * i + 4] = 4 * i + 2; |
| 278 | indices[6 * i + 5] = 4 * i + 3; |
| 279 | } |
| 280 | } |
| 281 | |
bsalomon@google.com | 86afc2a | 2011-02-16 16:12:19 +0000 | [diff] [blame] | 282 | const GrIndexBuffer* GrGpu::getQuadIndexBuffer() const { |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 283 | if (NULL == fQuadIndexBuffer) { |
| 284 | static const int SIZE = sizeof(uint16_t) * 6 * MAX_QUADS; |
| 285 | GrGpu* me = const_cast<GrGpu*>(this); |
| 286 | fQuadIndexBuffer = me->createIndexBuffer(SIZE, false); |
| 287 | if (NULL != fQuadIndexBuffer) { |
| 288 | uint16_t* indices = (uint16_t*)fQuadIndexBuffer->lock(); |
| 289 | if (NULL != indices) { |
bsalomon@google.com | 1c13c96 | 2011-02-14 16:51:21 +0000 | [diff] [blame] | 290 | fill_indices(indices, MAX_QUADS); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 291 | fQuadIndexBuffer->unlock(); |
| 292 | } else { |
| 293 | indices = (uint16_t*)GrMalloc(SIZE); |
bsalomon@google.com | 1c13c96 | 2011-02-14 16:51:21 +0000 | [diff] [blame] | 294 | fill_indices(indices, MAX_QUADS); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 295 | if (!fQuadIndexBuffer->updateData(indices, SIZE)) { |
| 296 | fQuadIndexBuffer->unref(); |
| 297 | fQuadIndexBuffer = NULL; |
bsalomon@google.com | 6f7fbc9 | 2011-02-01 19:12:40 +0000 | [diff] [blame] | 298 | GrCrash("Can't get indices into buffer!"); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 299 | } |
| 300 | GrFree(indices); |
| 301 | } |
| 302 | } |
| 303 | } |
| 304 | |
| 305 | return fQuadIndexBuffer; |
| 306 | } |
| 307 | |
bsalomon@google.com | 86afc2a | 2011-02-16 16:12:19 +0000 | [diff] [blame] | 308 | const GrVertexBuffer* GrGpu::getUnitSquareVertexBuffer() const { |
bsalomon@google.com | 6f7fbc9 | 2011-02-01 19:12:40 +0000 | [diff] [blame] | 309 | if (NULL == fUnitSquareVertexBuffer) { |
| 310 | |
| 311 | static const GrPoint DATA[] = { |
reed@google.com | 7744c20 | 2011-05-06 19:26:26 +0000 | [diff] [blame] | 312 | { 0, 0 }, |
| 313 | { GR_Scalar1, 0 }, |
| 314 | { GR_Scalar1, GR_Scalar1 }, |
| 315 | { 0, GR_Scalar1 } |
| 316 | #if 0 |
bsalomon@google.com | 6f7fbc9 | 2011-02-01 19:12:40 +0000 | [diff] [blame] | 317 | GrPoint(0, 0), |
| 318 | GrPoint(GR_Scalar1,0), |
| 319 | GrPoint(GR_Scalar1,GR_Scalar1), |
| 320 | GrPoint(0, GR_Scalar1) |
reed@google.com | 7744c20 | 2011-05-06 19:26:26 +0000 | [diff] [blame] | 321 | #endif |
bsalomon@google.com | 6f7fbc9 | 2011-02-01 19:12:40 +0000 | [diff] [blame] | 322 | }; |
| 323 | static const size_t SIZE = sizeof(DATA); |
| 324 | |
| 325 | GrGpu* me = const_cast<GrGpu*>(this); |
| 326 | fUnitSquareVertexBuffer = me->createVertexBuffer(SIZE, false); |
| 327 | if (NULL != fUnitSquareVertexBuffer) { |
| 328 | if (!fUnitSquareVertexBuffer->updateData(DATA, SIZE)) { |
| 329 | fUnitSquareVertexBuffer->unref(); |
| 330 | fUnitSquareVertexBuffer = NULL; |
| 331 | GrCrash("Can't get vertices into buffer!"); |
| 332 | } |
| 333 | } |
| 334 | } |
| 335 | |
| 336 | return fUnitSquareVertexBuffer; |
| 337 | } |
| 338 | |
bsalomon@google.com | d302f14 | 2011-03-03 13:54:13 +0000 | [diff] [blame] | 339 | //////////////////////////////////////////////////////////////////////////////// |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 340 | |
bsalomon@google.com | d302f14 | 2011-03-03 13:54:13 +0000 | [diff] [blame] | 341 | // stencil settings to use when clip is in stencil |
bsalomon@google.com | 6b2445e | 2011-12-15 19:47:46 +0000 | [diff] [blame] | 342 | GR_STATIC_CONST_SAME_STENCIL(gClipStencilSettings, |
| 343 | kKeep_StencilOp, |
| 344 | kKeep_StencilOp, |
| 345 | kAlwaysIfInClip_StencilFunc, |
| 346 | 0x0000, |
| 347 | 0x0000, |
| 348 | 0x0000); |
| 349 | const GrStencilSettings& GrGpu::gClipStencilSettings = ::gClipStencilSettings; |
bsalomon@google.com | d302f14 | 2011-03-03 13:54:13 +0000 | [diff] [blame] | 350 | |
bsalomon@google.com | a7f84e1 | 2011-03-10 14:13:19 +0000 | [diff] [blame] | 351 | // mapping of clip-respecting stencil funcs to normal stencil funcs |
| 352 | // mapping depends on whether stencil-clipping is in effect. |
bsalomon@google.com | d302f14 | 2011-03-03 13:54:13 +0000 | [diff] [blame] | 353 | static const GrStencilFunc gGrClipToNormalStencilFunc[2][kClipStencilFuncCount] = { |
| 354 | {// Stencil-Clipping is DISABLED, effectively always inside the clip |
| 355 | // In the Clip Funcs |
| 356 | kAlways_StencilFunc, // kAlwaysIfInClip_StencilFunc |
| 357 | kEqual_StencilFunc, // kEqualIfInClip_StencilFunc |
| 358 | kLess_StencilFunc, // kLessIfInClip_StencilFunc |
| 359 | kLEqual_StencilFunc, // kLEqualIfInClip_StencilFunc |
| 360 | // Special in the clip func that forces user's ref to be 0. |
| 361 | kNotEqual_StencilFunc, // kNonZeroIfInClip_StencilFunc |
| 362 | // make ref 0 and do normal nequal. |
| 363 | }, |
| 364 | {// Stencil-Clipping is ENABLED |
| 365 | // In the Clip Funcs |
| 366 | kEqual_StencilFunc, // kAlwaysIfInClip_StencilFunc |
| 367 | // eq stencil clip bit, mask |
| 368 | // out user bits. |
| 369 | |
| 370 | kEqual_StencilFunc, // kEqualIfInClip_StencilFunc |
| 371 | // add stencil bit to mask and ref |
| 372 | |
| 373 | kLess_StencilFunc, // kLessIfInClip_StencilFunc |
| 374 | kLEqual_StencilFunc, // kLEqualIfInClip_StencilFunc |
| 375 | // for both of these we can add |
| 376 | // the clip bit to the mask and |
| 377 | // ref and compare as normal |
| 378 | // Special in the clip func that forces user's ref to be 0. |
| 379 | kLess_StencilFunc, // kNonZeroIfInClip_StencilFunc |
| 380 | // make ref have only the clip bit set |
| 381 | // and make comparison be less |
| 382 | // 10..0 < 1..user_bits.. |
| 383 | } |
| 384 | }; |
| 385 | |
| 386 | GrStencilFunc GrGpu::ConvertStencilFunc(bool stencilInClip, GrStencilFunc func) { |
| 387 | GrAssert(func >= 0); |
| 388 | if (func >= kBasicStencilFuncCount) { |
| 389 | GrAssert(func < kStencilFuncCount); |
| 390 | func = gGrClipToNormalStencilFunc[stencilInClip ? 1 : 0][func - kBasicStencilFuncCount]; |
| 391 | GrAssert(func >= 0 && func < kBasicStencilFuncCount); |
| 392 | } |
| 393 | return func; |
| 394 | } |
| 395 | |
| 396 | void GrGpu::ConvertStencilFuncAndMask(GrStencilFunc func, |
| 397 | bool clipInStencil, |
| 398 | unsigned int clipBit, |
| 399 | unsigned int userBits, |
| 400 | unsigned int* ref, |
| 401 | unsigned int* mask) { |
| 402 | if (func < kBasicStencilFuncCount) { |
| 403 | *mask &= userBits; |
| 404 | *ref &= userBits; |
| 405 | } else { |
| 406 | if (clipInStencil) { |
| 407 | switch (func) { |
| 408 | case kAlwaysIfInClip_StencilFunc: |
| 409 | *mask = clipBit; |
| 410 | *ref = clipBit; |
| 411 | break; |
| 412 | case kEqualIfInClip_StencilFunc: |
| 413 | case kLessIfInClip_StencilFunc: |
| 414 | case kLEqualIfInClip_StencilFunc: |
| 415 | *mask = (*mask & userBits) | clipBit; |
| 416 | *ref = (*ref & userBits) | clipBit; |
| 417 | break; |
| 418 | case kNonZeroIfInClip_StencilFunc: |
| 419 | *mask = (*mask & userBits) | clipBit; |
| 420 | *ref = clipBit; |
| 421 | break; |
| 422 | default: |
| 423 | GrCrash("Unknown stencil func"); |
| 424 | } |
| 425 | } else { |
| 426 | *mask &= userBits; |
| 427 | *ref &= userBits; |
| 428 | } |
| 429 | } |
| 430 | } |
| 431 | |
| 432 | //////////////////////////////////////////////////////////////////////////////// |
| 433 | |
| 434 | #define VISUALIZE_COMPLEX_CLIP 0 |
| 435 | |
| 436 | #if VISUALIZE_COMPLEX_CLIP |
| 437 | #include "GrRandom.h" |
| 438 | GrRandom gRandom; |
| 439 | #define SET_RANDOM_COLOR this->setColor(0xff000000 | gRandom.nextU()); |
| 440 | #else |
| 441 | #define SET_RANDOM_COLOR |
| 442 | #endif |
| 443 | |
bsalomon@google.com | ab3dee5 | 2011-08-29 15:18:41 +0000 | [diff] [blame] | 444 | namespace { |
| 445 | // determines how many elements at the head of the clip can be skipped and |
| 446 | // whether the initial clear should be to the inside- or outside-the-clip value, |
| 447 | // and what op should be used to draw the first element that isn't skipped. |
| 448 | int process_initial_clip_elements(const GrClip& clip, |
bsalomon@google.com | 6b20c2d | 2011-12-09 21:23:46 +0000 | [diff] [blame] | 449 | const GrRect& bounds, |
bsalomon@google.com | ab3dee5 | 2011-08-29 15:18:41 +0000 | [diff] [blame] | 450 | bool* clearToInside, |
| 451 | GrSetOp* startOp) { |
| 452 | |
| 453 | // logically before the first element of the clip stack is |
| 454 | // processed the clip is entirely open. However, depending on the |
| 455 | // first set op we may prefer to clear to 0 for performance. We may |
| 456 | // also be able to skip the initial clip paths/rects. We loop until |
| 457 | // we cannot skip an element. |
| 458 | int curr; |
| 459 | bool done = false; |
| 460 | *clearToInside = true; |
| 461 | int count = clip.getElementCount(); |
| 462 | |
| 463 | for (curr = 0; curr < count && !done; ++curr) { |
| 464 | switch (clip.getOp(curr)) { |
| 465 | case kReplace_SetOp: |
| 466 | // replace ignores everything previous |
| 467 | *startOp = kReplace_SetOp; |
| 468 | *clearToInside = false; |
| 469 | done = true; |
| 470 | break; |
| 471 | case kIntersect_SetOp: |
bsalomon@google.com | 6b20c2d | 2011-12-09 21:23:46 +0000 | [diff] [blame] | 472 | // if this element contains the entire bounds then we |
| 473 | // can skip it. |
| 474 | if (kRect_ClipType == clip.getElementType(curr) |
| 475 | && clip.getRect(curr).contains(bounds)) { |
| 476 | break; |
| 477 | } |
bsalomon@google.com | ab3dee5 | 2011-08-29 15:18:41 +0000 | [diff] [blame] | 478 | // if everything is initially clearToInside then intersect is |
| 479 | // same as clear to 0 and treat as a replace. Otherwise, |
| 480 | // set stays empty. |
| 481 | if (*clearToInside) { |
| 482 | *startOp = kReplace_SetOp; |
| 483 | *clearToInside = false; |
| 484 | done = true; |
| 485 | } |
| 486 | break; |
| 487 | // we can skip a leading union. |
| 488 | case kUnion_SetOp: |
| 489 | // if everything is initially outside then union is |
| 490 | // same as replace. Otherwise, every pixel is still |
| 491 | // clearToInside |
| 492 | if (!*clearToInside) { |
| 493 | *startOp = kReplace_SetOp; |
| 494 | done = true; |
| 495 | } |
| 496 | break; |
| 497 | case kXor_SetOp: |
| 498 | // xor is same as difference or replace both of which |
| 499 | // can be 1-pass instead of 2 for xor. |
| 500 | if (*clearToInside) { |
| 501 | *startOp = kDifference_SetOp; |
| 502 | } else { |
| 503 | *startOp = kReplace_SetOp; |
| 504 | } |
| 505 | done = true; |
| 506 | break; |
| 507 | case kDifference_SetOp: |
| 508 | // if all pixels are clearToInside then we have to process the |
| 509 | // difference, otherwise it has no effect and all pixels |
| 510 | // remain outside. |
| 511 | if (*clearToInside) { |
| 512 | *startOp = kDifference_SetOp; |
| 513 | done = true; |
| 514 | } |
| 515 | break; |
| 516 | case kReverseDifference_SetOp: |
| 517 | // if all pixels are clearToInside then reverse difference |
| 518 | // produces empty set. Otherise it is same as replace |
| 519 | if (*clearToInside) { |
| 520 | *clearToInside = false; |
| 521 | } else { |
| 522 | *startOp = kReplace_SetOp; |
| 523 | done = true; |
| 524 | } |
| 525 | break; |
bsalomon@google.com | 2ec7280 | 2011-09-21 21:46:03 +0000 | [diff] [blame] | 526 | default: |
| 527 | GrCrash("Unknown set op."); |
bsalomon@google.com | ab3dee5 | 2011-08-29 15:18:41 +0000 | [diff] [blame] | 528 | } |
| 529 | } |
| 530 | return done ? curr-1 : count; |
| 531 | } |
| 532 | } |
| 533 | |
bsalomon@google.com | ffca400 | 2011-02-22 20:34:01 +0000 | [diff] [blame] | 534 | bool GrGpu::setupClipAndFlushState(GrPrimitiveType type) { |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 535 | const GrIRect* r = NULL; |
bsalomon@google.com | d302f14 | 2011-03-03 13:54:13 +0000 | [diff] [blame] | 536 | GrIRect clipRect; |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 537 | |
bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 538 | GrDrawState* drawState = this->drawState(); |
| 539 | const GrRenderTarget* rt = drawState->getRenderTarget(); |
bsalomon@google.com | 0fec61d | 2011-12-08 15:53:53 +0000 | [diff] [blame] | 540 | |
bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 541 | // GrDrawTarget should have filtered this for us |
| 542 | GrAssert(NULL != rt); |
| 543 | |
| 544 | if (drawState->isClipState()) { |
bsalomon@google.com | d302f14 | 2011-03-03 13:54:13 +0000 | [diff] [blame] | 545 | |
| 546 | GrRect bounds; |
| 547 | GrRect rtRect; |
| 548 | rtRect.setLTRB(0, 0, |
bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 549 | GrIntToScalar(rt->width()), GrIntToScalar(rt->height())); |
bsalomon@google.com | 0b50b2e | 2011-03-08 21:07:21 +0000 | [diff] [blame] | 550 | if (fClip.hasConservativeBounds()) { |
| 551 | bounds = fClip.getConservativeBounds(); |
reed@google.com | 20efde7 | 2011-05-09 17:00:02 +0000 | [diff] [blame] | 552 | if (!bounds.intersect(rtRect)) { |
| 553 | bounds.setEmpty(); |
| 554 | } |
bsalomon@google.com | d302f14 | 2011-03-03 13:54:13 +0000 | [diff] [blame] | 555 | } else { |
| 556 | bounds = rtRect; |
| 557 | } |
| 558 | |
| 559 | bounds.roundOut(&clipRect); |
| 560 | if (clipRect.isEmpty()) { |
| 561 | clipRect.setLTRB(0,0,0,0); |
| 562 | } |
| 563 | r = &clipRect; |
| 564 | |
bsalomon@google.com | dea2f8d | 2011-08-01 15:51:05 +0000 | [diff] [blame] | 565 | // use the stencil clip if we can't represent the clip as a rectangle. |
| 566 | fClipInStencil = !fClip.isRect() && !fClip.isEmpty() && |
| 567 | !bounds.isEmpty(); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 568 | |
bsalomon@google.com | 81c3f8d | 2011-08-03 15:18:33 +0000 | [diff] [blame] | 569 | // TODO: dynamically attach a SB when needed. |
bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 570 | GrStencilBuffer* stencilBuffer = rt->getStencilBuffer(); |
bsalomon@google.com | 81c3f8d | 2011-08-03 15:18:33 +0000 | [diff] [blame] | 571 | if (fClipInStencil && NULL == stencilBuffer) { |
| 572 | return false; |
| 573 | } |
bsalomon@google.com | a16d650 | 2011-08-02 14:07:52 +0000 | [diff] [blame] | 574 | |
bsalomon@google.com | 0fec61d | 2011-12-08 15:53:53 +0000 | [diff] [blame] | 575 | if (fClipInStencil && |
bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 576 | stencilBuffer->mustRenderClip(fClip, rt->width(), rt->height())) { |
bsalomon@google.com | 0fec61d | 2011-12-08 15:53:53 +0000 | [diff] [blame] | 577 | |
bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 578 | stencilBuffer->setLastClip(fClip, rt->width(), rt->height()); |
bsalomon@google.com | 81c3f8d | 2011-08-03 15:18:33 +0000 | [diff] [blame] | 579 | |
bsalomon@google.com | d302f14 | 2011-03-03 13:54:13 +0000 | [diff] [blame] | 580 | // we set the current clip to the bounds so that our recursive |
| 581 | // draws are scissored to them. We use the copy of the complex clip |
bsalomon@google.com | 81c3f8d | 2011-08-03 15:18:33 +0000 | [diff] [blame] | 582 | // we just stashed on the SB to render from. We set it back after |
| 583 | // we finish drawing it into the stencil. |
| 584 | const GrClip& clip = stencilBuffer->getLastClip(); |
bsalomon@google.com | d302f14 | 2011-03-03 13:54:13 +0000 | [diff] [blame] | 585 | fClip.setFromRect(bounds); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 586 | |
| 587 | AutoStateRestore asr(this); |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 588 | AutoGeometryPush agp(this); |
bsalomon@google.com | 1c13c96 | 2011-02-14 16:51:21 +0000 | [diff] [blame] | 589 | |
bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 590 | drawState->setViewMatrix(GrMatrix::I()); |
bsalomon@google.com | d302f14 | 2011-03-03 13:54:13 +0000 | [diff] [blame] | 591 | this->flushScissor(NULL); |
| 592 | #if !VISUALIZE_COMPLEX_CLIP |
bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 593 | drawState->enableState(GrDrawState::kNoColorWrites_StateBit); |
bsalomon@google.com | d302f14 | 2011-03-03 13:54:13 +0000 | [diff] [blame] | 594 | #else |
bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 595 | drawState->disableState(GrDrawState::kNoColorWrites_StateBit); |
bsalomon@google.com | d302f14 | 2011-03-03 13:54:13 +0000 | [diff] [blame] | 596 | #endif |
| 597 | int count = clip.getElementCount(); |
bsalomon@google.com | 81c3f8d | 2011-08-03 15:18:33 +0000 | [diff] [blame] | 598 | int clipBit = stencilBuffer->bits(); |
tomhudson@google.com | 62b0968 | 2011-11-09 16:39:17 +0000 | [diff] [blame] | 599 | SkASSERT((clipBit <= 16) && |
| 600 | "Ganesh only handles 16b or smaller stencil buffers"); |
bsalomon@google.com | d302f14 | 2011-03-03 13:54:13 +0000 | [diff] [blame] | 601 | clipBit = (1 << (clipBit-1)); |
bsalomon@google.com | ab3dee5 | 2011-08-29 15:18:41 +0000 | [diff] [blame] | 602 | |
| 603 | bool clearToInside; |
bsalomon@google.com | 2ec7280 | 2011-09-21 21:46:03 +0000 | [diff] [blame] | 604 | GrSetOp startOp = kReplace_SetOp; // suppress warning |
bsalomon@google.com | 6b20c2d | 2011-12-09 21:23:46 +0000 | [diff] [blame] | 605 | int start = process_initial_clip_elements(clip, |
| 606 | rtRect, |
| 607 | &clearToInside, |
bsalomon@google.com | ab3dee5 | 2011-08-29 15:18:41 +0000 | [diff] [blame] | 608 | &startOp); |
bsalomon@google.com | d302f14 | 2011-03-03 13:54:13 +0000 | [diff] [blame] | 609 | |
bsalomon@google.com | ab3dee5 | 2011-08-29 15:18:41 +0000 | [diff] [blame] | 610 | this->clearStencilClip(clipRect, clearToInside); |
bsalomon@google.com | 0b50b2e | 2011-03-08 21:07:21 +0000 | [diff] [blame] | 611 | |
bsalomon@google.com | d302f14 | 2011-03-03 13:54:13 +0000 | [diff] [blame] | 612 | // walk through each clip element and perform its set op |
| 613 | // with the existing clip. |
bsalomon@google.com | ab3dee5 | 2011-08-29 15:18:41 +0000 | [diff] [blame] | 614 | for (int c = start; c < count; ++c) { |
bsalomon@google.com | d302f14 | 2011-03-03 13:54:13 +0000 | [diff] [blame] | 615 | GrPathFill fill; |
bsalomon@google.com | ee43512 | 2011-07-01 14:57:55 +0000 | [diff] [blame] | 616 | bool fillInverted; |
bsalomon@google.com | d302f14 | 2011-03-03 13:54:13 +0000 | [diff] [blame] | 617 | // enabled at bottom of loop |
bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 618 | drawState->disableState(kModifyStencilClip_StateBit); |
bsalomon@google.com | d302f14 | 2011-03-03 13:54:13 +0000 | [diff] [blame] | 619 | |
bsalomon@google.com | 7f5875d | 2011-03-24 16:55:45 +0000 | [diff] [blame] | 620 | bool canRenderDirectToStencil; // can the clip element be drawn |
| 621 | // directly to the stencil buffer |
| 622 | // with a non-inverted fill rule |
| 623 | // without extra passes to |
bsalomon@google.com | dfe75bc | 2011-03-25 12:31:16 +0000 | [diff] [blame] | 624 | // resolve in/out status. |
| 625 | |
| 626 | GrPathRenderer* pr = NULL; |
reed@google.com | 07f3ee1 | 2011-05-16 17:21:57 +0000 | [diff] [blame] | 627 | const GrPath* clipPath = NULL; |
bsalomon@google.com | ee43512 | 2011-07-01 14:57:55 +0000 | [diff] [blame] | 628 | GrPathRenderer::AutoClearPath arp; |
bsalomon@google.com | d302f14 | 2011-03-03 13:54:13 +0000 | [diff] [blame] | 629 | if (kRect_ClipType == clip.getElementType(c)) { |
bsalomon@google.com | 7f5875d | 2011-03-24 16:55:45 +0000 | [diff] [blame] | 630 | canRenderDirectToStencil = true; |
bsalomon@google.com | d302f14 | 2011-03-03 13:54:13 +0000 | [diff] [blame] | 631 | fill = kEvenOdd_PathFill; |
bsalomon@google.com | ee43512 | 2011-07-01 14:57:55 +0000 | [diff] [blame] | 632 | fillInverted = false; |
bsalomon@google.com | 6b20c2d | 2011-12-09 21:23:46 +0000 | [diff] [blame] | 633 | // there is no point in intersecting a screen filling |
| 634 | // rectangle. |
| 635 | if (kIntersect_SetOp == clip.getOp(c) && |
| 636 | clip.getRect(c).contains(rtRect)) { |
| 637 | continue; |
| 638 | } |
bsalomon@google.com | d302f14 | 2011-03-03 13:54:13 +0000 | [diff] [blame] | 639 | } else { |
| 640 | fill = clip.getPathFill(c); |
bsalomon@google.com | fa6ac93 | 2011-10-05 19:57:55 +0000 | [diff] [blame] | 641 | fillInverted = GrIsFillInverted(fill); |
| 642 | fill = GrNonInvertedFill(fill); |
reed@google.com | 07f3ee1 | 2011-05-16 17:21:57 +0000 | [diff] [blame] | 643 | clipPath = &clip.getPath(c); |
bsalomon@google.com | ee43512 | 2011-07-01 14:57:55 +0000 | [diff] [blame] | 644 | pr = this->getClipPathRenderer(*clipPath, fill); |
bsalomon@google.com | 3008519 | 2011-08-19 15:42:31 +0000 | [diff] [blame] | 645 | if (NULL == pr) { |
| 646 | fClipInStencil = false; |
| 647 | fClip = clip; |
| 648 | return false; |
| 649 | } |
bsalomon@google.com | 11f0b51 | 2011-03-29 20:52:23 +0000 | [diff] [blame] | 650 | canRenderDirectToStencil = |
bsalomon@google.com | ee43512 | 2011-07-01 14:57:55 +0000 | [diff] [blame] | 651 | !pr->requiresStencilPass(this, *clipPath, fill); |
bsalomon@google.com | 289533a | 2011-10-27 12:34:25 +0000 | [diff] [blame] | 652 | arp.set(pr, this, clipPath, fill, false, NULL); |
bsalomon@google.com | d302f14 | 2011-03-03 13:54:13 +0000 | [diff] [blame] | 653 | } |
| 654 | |
bsalomon@google.com | ab3dee5 | 2011-08-29 15:18:41 +0000 | [diff] [blame] | 655 | GrSetOp op = (c == start) ? startOp : clip.getOp(c); |
bsalomon@google.com | d302f14 | 2011-03-03 13:54:13 +0000 | [diff] [blame] | 656 | int passes; |
| 657 | GrStencilSettings stencilSettings[GrStencilSettings::kMaxStencilClipPasses]; |
| 658 | |
bsalomon@google.com | 11f0b51 | 2011-03-29 20:52:23 +0000 | [diff] [blame] | 659 | bool canDrawDirectToClip; // Given the renderer, the element, |
bsalomon@google.com | 7f5875d | 2011-03-24 16:55:45 +0000 | [diff] [blame] | 660 | // fill rule, and set operation can |
| 661 | // we render the element directly to |
| 662 | // stencil bit used for clipping. |
bsalomon@google.com | 11f0b51 | 2011-03-29 20:52:23 +0000 | [diff] [blame] | 663 | canDrawDirectToClip = |
| 664 | GrStencilSettings::GetClipPasses(op, |
bsalomon@google.com | 7f5875d | 2011-03-24 16:55:45 +0000 | [diff] [blame] | 665 | canRenderDirectToStencil, |
bsalomon@google.com | 11f0b51 | 2011-03-29 20:52:23 +0000 | [diff] [blame] | 666 | clipBit, |
bsalomon@google.com | ee43512 | 2011-07-01 14:57:55 +0000 | [diff] [blame] | 667 | fillInverted, |
bsalomon@google.com | 7f5875d | 2011-03-24 16:55:45 +0000 | [diff] [blame] | 668 | &passes, stencilSettings); |
bsalomon@google.com | d302f14 | 2011-03-03 13:54:13 +0000 | [diff] [blame] | 669 | |
| 670 | // draw the element to the client stencil bits if necessary |
| 671 | if (!canDrawDirectToClip) { |
bsalomon@google.com | 6b2445e | 2011-12-15 19:47:46 +0000 | [diff] [blame] | 672 | GR_STATIC_CONST_SAME_STENCIL(gDrawToStencil, |
| 673 | kIncClamp_StencilOp, |
| 674 | kIncClamp_StencilOp, |
| 675 | kAlways_StencilFunc, |
| 676 | 0xffff, |
| 677 | 0x0000, |
| 678 | 0xffff); |
bsalomon@google.com | 7f5875d | 2011-03-24 16:55:45 +0000 | [diff] [blame] | 679 | SET_RANDOM_COLOR |
bsalomon@google.com | d302f14 | 2011-03-03 13:54:13 +0000 | [diff] [blame] | 680 | if (kRect_ClipType == clip.getElementType(c)) { |
bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 681 | *drawState->stencil() = gDrawToStencil; |
bsalomon@google.com | d302f14 | 2011-03-03 13:54:13 +0000 | [diff] [blame] | 682 | this->drawSimpleRect(clip.getRect(c), NULL, 0); |
| 683 | } else { |
bsalomon@google.com | 7f5875d | 2011-03-24 16:55:45 +0000 | [diff] [blame] | 684 | if (canRenderDirectToStencil) { |
bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 685 | *drawState->stencil() = gDrawToStencil; |
bsalomon@google.com | ee43512 | 2011-07-01 14:57:55 +0000 | [diff] [blame] | 686 | pr->drawPath(0); |
bsalomon@google.com | 7f5875d | 2011-03-24 16:55:45 +0000 | [diff] [blame] | 687 | } else { |
bsalomon@google.com | ee43512 | 2011-07-01 14:57:55 +0000 | [diff] [blame] | 688 | pr->drawPathToStencil(); |
bsalomon@google.com | 7f5875d | 2011-03-24 16:55:45 +0000 | [diff] [blame] | 689 | } |
bsalomon@google.com | d302f14 | 2011-03-03 13:54:13 +0000 | [diff] [blame] | 690 | } |
| 691 | } |
| 692 | |
| 693 | // now we modify the clip bit by rendering either the clip |
| 694 | // element directly or a bounding rect of the entire clip. |
bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 695 | drawState->enableState(kModifyStencilClip_StateBit); |
bsalomon@google.com | d302f14 | 2011-03-03 13:54:13 +0000 | [diff] [blame] | 696 | for (int p = 0; p < passes; ++p) { |
bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 697 | *drawState->stencil() = stencilSettings[p]; |
bsalomon@google.com | d302f14 | 2011-03-03 13:54:13 +0000 | [diff] [blame] | 698 | if (canDrawDirectToClip) { |
| 699 | if (kRect_ClipType == clip.getElementType(c)) { |
| 700 | SET_RANDOM_COLOR |
| 701 | this->drawSimpleRect(clip.getRect(c), NULL, 0); |
| 702 | } else { |
| 703 | SET_RANDOM_COLOR |
bsalomon@google.com | ee43512 | 2011-07-01 14:57:55 +0000 | [diff] [blame] | 704 | pr->drawPath(0); |
bsalomon@google.com | d302f14 | 2011-03-03 13:54:13 +0000 | [diff] [blame] | 705 | } |
| 706 | } else { |
| 707 | SET_RANDOM_COLOR |
thakis@chromium.org | 441d7da | 2011-06-07 04:03:17 +0000 | [diff] [blame] | 708 | this->drawSimpleRect(bounds, NULL, 0); |
bsalomon@google.com | d302f14 | 2011-03-03 13:54:13 +0000 | [diff] [blame] | 709 | } |
| 710 | } |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 711 | } |
bsalomon@google.com | dea2f8d | 2011-08-01 15:51:05 +0000 | [diff] [blame] | 712 | // restore clip |
bsalomon@google.com | d302f14 | 2011-03-03 13:54:13 +0000 | [diff] [blame] | 713 | fClip = clip; |
bsalomon@google.com | dea2f8d | 2011-08-01 15:51:05 +0000 | [diff] [blame] | 714 | // recusive draws would have disabled this since they drew with |
| 715 | // the clip bounds as clip. |
| 716 | fClipInStencil = true; |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 717 | } |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 718 | } |
bsalomon@google.com | d302f14 | 2011-03-03 13:54:13 +0000 | [diff] [blame] | 719 | |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 720 | // Must flush the scissor after graphics state |
bsalomon@google.com | d302f14 | 2011-03-03 13:54:13 +0000 | [diff] [blame] | 721 | if (!this->flushGraphicsState(type)) { |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 722 | return false; |
| 723 | } |
bsalomon@google.com | d302f14 | 2011-03-03 13:54:13 +0000 | [diff] [blame] | 724 | this->flushScissor(r); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 725 | return true; |
| 726 | } |
| 727 | |
reed@google.com | 07f3ee1 | 2011-05-16 17:21:57 +0000 | [diff] [blame] | 728 | GrPathRenderer* GrGpu::getClipPathRenderer(const GrPath& path, |
bsalomon@google.com | dfe75bc | 2011-03-25 12:31:16 +0000 | [diff] [blame] | 729 | GrPathFill fill) { |
bsalomon@google.com | 3008519 | 2011-08-19 15:42:31 +0000 | [diff] [blame] | 730 | if (NULL == fPathRendererChain) { |
| 731 | fPathRendererChain = |
| 732 | new GrPathRendererChain(this->getContext(), |
| 733 | GrPathRendererChain::kNonAAOnly_UsageFlag); |
bsalomon@google.com | dfe75bc | 2011-03-25 12:31:16 +0000 | [diff] [blame] | 734 | } |
bsalomon@google.com | 289533a | 2011-10-27 12:34:25 +0000 | [diff] [blame] | 735 | return fPathRendererChain->getPathRenderer(this->getCaps(), |
| 736 | path, fill, false); |
bsalomon@google.com | dfe75bc | 2011-03-25 12:31:16 +0000 | [diff] [blame] | 737 | } |
| 738 | |
| 739 | |
bsalomon@google.com | d302f14 | 2011-03-03 13:54:13 +0000 | [diff] [blame] | 740 | //////////////////////////////////////////////////////////////////////////////// |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 741 | |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 742 | void GrGpu::geometrySourceWillPush() { |
| 743 | const GeometrySrcState& geoSrc = this->getGeomSrc(); |
| 744 | if (kArray_GeometrySrcType == geoSrc.fVertexSrc || |
| 745 | kReserved_GeometrySrcType == geoSrc.fVertexSrc) { |
| 746 | this->finalizeReservedVertices(); |
| 747 | } |
| 748 | if (kArray_GeometrySrcType == geoSrc.fIndexSrc || |
| 749 | kReserved_GeometrySrcType == geoSrc.fIndexSrc) { |
| 750 | this->finalizeReservedIndices(); |
| 751 | } |
| 752 | GeometryPoolState& newState = fGeomPoolStateStack.push_back(); |
| 753 | #if GR_DEBUG |
| 754 | newState.fPoolVertexBuffer = (GrVertexBuffer*)DEBUG_INVAL_BUFFER; |
| 755 | newState.fPoolStartVertex = DEBUG_INVAL_START_IDX; |
| 756 | newState.fPoolIndexBuffer = (GrIndexBuffer*)DEBUG_INVAL_BUFFER; |
| 757 | newState.fPoolStartIndex = DEBUG_INVAL_START_IDX; |
| 758 | #endif |
| 759 | } |
| 760 | |
| 761 | void GrGpu::geometrySourceWillPop(const GeometrySrcState& restoredState) { |
| 762 | // if popping last entry then pops are unbalanced with pushes |
| 763 | GrAssert(fGeomPoolStateStack.count() > 1); |
| 764 | fGeomPoolStateStack.pop_back(); |
| 765 | } |
| 766 | |
| 767 | void GrGpu::onDrawIndexed(GrPrimitiveType type, |
| 768 | int startVertex, |
| 769 | int startIndex, |
| 770 | int vertexCount, |
| 771 | int indexCount) { |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 772 | |
bsalomon@google.com | a7f84e1 | 2011-03-10 14:13:19 +0000 | [diff] [blame] | 773 | this->handleDirtyContext(); |
| 774 | |
| 775 | if (!this->setupClipAndFlushState(type)) { |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 776 | return; |
| 777 | } |
| 778 | |
| 779 | #if GR_COLLECT_STATS |
| 780 | fStats.fVertexCnt += vertexCount; |
| 781 | fStats.fIndexCnt += indexCount; |
| 782 | fStats.fDrawCnt += 1; |
| 783 | #endif |
| 784 | |
bsalomon@google.com | 1c13c96 | 2011-02-14 16:51:21 +0000 | [diff] [blame] | 785 | int sVertex = startVertex; |
| 786 | int sIndex = startIndex; |
| 787 | setupGeometry(&sVertex, &sIndex, vertexCount, indexCount); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 788 | |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 789 | this->onGpuDrawIndexed(type, sVertex, sIndex, |
| 790 | vertexCount, indexCount); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 791 | } |
| 792 | |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 793 | void GrGpu::onDrawNonIndexed(GrPrimitiveType type, |
bsalomon@google.com | 1c13c96 | 2011-02-14 16:51:21 +0000 | [diff] [blame] | 794 | int startVertex, |
| 795 | int vertexCount) { |
bsalomon@google.com | a7f84e1 | 2011-03-10 14:13:19 +0000 | [diff] [blame] | 796 | this->handleDirtyContext(); |
| 797 | |
| 798 | if (!this->setupClipAndFlushState(type)) { |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 799 | return; |
| 800 | } |
| 801 | #if GR_COLLECT_STATS |
| 802 | fStats.fVertexCnt += vertexCount; |
| 803 | fStats.fDrawCnt += 1; |
| 804 | #endif |
| 805 | |
bsalomon@google.com | 1c13c96 | 2011-02-14 16:51:21 +0000 | [diff] [blame] | 806 | int sVertex = startVertex; |
| 807 | setupGeometry(&sVertex, NULL, vertexCount, 0); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 808 | |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 809 | this->onGpuDrawNonIndexed(type, sVertex, vertexCount); |
bsalomon@google.com | 1c13c96 | 2011-02-14 16:51:21 +0000 | [diff] [blame] | 810 | } |
| 811 | |
| 812 | void GrGpu::finalizeReservedVertices() { |
| 813 | GrAssert(NULL != fVertexPool); |
| 814 | fVertexPool->unlock(); |
| 815 | } |
| 816 | |
| 817 | void GrGpu::finalizeReservedIndices() { |
| 818 | GrAssert(NULL != fIndexPool); |
| 819 | fIndexPool->unlock(); |
| 820 | } |
| 821 | |
| 822 | void GrGpu::prepareVertexPool() { |
| 823 | if (NULL == fVertexPool) { |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 824 | GrAssert(0 == fVertexPoolUseCnt); |
bsalomon@google.com | d302f14 | 2011-03-03 13:54:13 +0000 | [diff] [blame] | 825 | fVertexPool = new GrVertexBufferAllocPool(this, true, |
| 826 | VERTEX_POOL_VB_SIZE, |
bsalomon@google.com | 7a5af8b | 2011-02-18 18:40:42 +0000 | [diff] [blame] | 827 | VERTEX_POOL_VB_COUNT); |
bsalomon@google.com | 11f0b51 | 2011-03-29 20:52:23 +0000 | [diff] [blame] | 828 | fVertexPool->releaseGpuRef(); |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 829 | } else if (!fVertexPoolUseCnt) { |
bsalomon@google.com | d302f14 | 2011-03-03 13:54:13 +0000 | [diff] [blame] | 830 | // the client doesn't have valid data in the pool |
bsalomon@google.com | 1c13c96 | 2011-02-14 16:51:21 +0000 | [diff] [blame] | 831 | fVertexPool->reset(); |
| 832 | } |
| 833 | } |
| 834 | |
| 835 | void GrGpu::prepareIndexPool() { |
senorblanco@chromium.org | 9d18b78 | 2011-03-28 20:47:09 +0000 | [diff] [blame] | 836 | if (NULL == fIndexPool) { |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 837 | GrAssert(0 == fIndexPoolUseCnt); |
bsalomon@google.com | 25fd36c | 2011-07-06 17:41:08 +0000 | [diff] [blame] | 838 | fIndexPool = new GrIndexBufferAllocPool(this, true, |
| 839 | INDEX_POOL_IB_SIZE, |
| 840 | INDEX_POOL_IB_COUNT); |
bsalomon@google.com | 11f0b51 | 2011-03-29 20:52:23 +0000 | [diff] [blame] | 841 | fIndexPool->releaseGpuRef(); |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 842 | } else if (!fIndexPoolUseCnt) { |
bsalomon@google.com | d302f14 | 2011-03-03 13:54:13 +0000 | [diff] [blame] | 843 | // the client doesn't have valid data in the pool |
bsalomon@google.com | 1c13c96 | 2011-02-14 16:51:21 +0000 | [diff] [blame] | 844 | fIndexPool->reset(); |
| 845 | } |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 846 | } |
| 847 | |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 848 | bool GrGpu::onReserveVertexSpace(GrVertexLayout vertexLayout, |
| 849 | int vertexCount, |
| 850 | void** vertices) { |
| 851 | GeometryPoolState& geomPoolState = fGeomPoolStateStack.back(); |
| 852 | |
| 853 | GrAssert(vertexCount > 0); |
| 854 | GrAssert(NULL != vertices); |
| 855 | |
| 856 | this->prepareVertexPool(); |
| 857 | |
| 858 | *vertices = fVertexPool->makeSpace(vertexLayout, |
| 859 | vertexCount, |
| 860 | &geomPoolState.fPoolVertexBuffer, |
| 861 | &geomPoolState.fPoolStartVertex); |
| 862 | if (NULL == *vertices) { |
| 863 | return false; |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 864 | } |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 865 | ++fVertexPoolUseCnt; |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 866 | return true; |
| 867 | } |
| 868 | |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 869 | bool GrGpu::onReserveIndexSpace(int indexCount, void** indices) { |
| 870 | GeometryPoolState& geomPoolState = fGeomPoolStateStack.back(); |
| 871 | |
| 872 | GrAssert(indexCount > 0); |
| 873 | GrAssert(NULL != indices); |
| 874 | |
| 875 | this->prepareIndexPool(); |
| 876 | |
| 877 | *indices = fIndexPool->makeSpace(indexCount, |
| 878 | &geomPoolState.fPoolIndexBuffer, |
| 879 | &geomPoolState.fPoolStartIndex); |
| 880 | if (NULL == *indices) { |
| 881 | return false; |
| 882 | } |
| 883 | ++fIndexPoolUseCnt; |
| 884 | return true; |
| 885 | } |
| 886 | |
| 887 | void GrGpu::releaseReservedVertexSpace() { |
| 888 | const GeometrySrcState& geoSrc = this->getGeomSrc(); |
| 889 | GrAssert(kReserved_GeometrySrcType == geoSrc.fVertexSrc); |
| 890 | size_t bytes = geoSrc.fVertexCount * VertexSize(geoSrc.fVertexLayout); |
| 891 | fVertexPool->putBack(bytes); |
| 892 | --fVertexPoolUseCnt; |
| 893 | } |
| 894 | |
| 895 | void GrGpu::releaseReservedIndexSpace() { |
| 896 | const GeometrySrcState& geoSrc = this->getGeomSrc(); |
| 897 | GrAssert(kReserved_GeometrySrcType == geoSrc.fIndexSrc); |
| 898 | size_t bytes = geoSrc.fIndexCount * sizeof(uint16_t); |
| 899 | fIndexPool->putBack(bytes); |
| 900 | --fIndexPoolUseCnt; |
| 901 | } |
bsalomon@google.com | 1c13c96 | 2011-02-14 16:51:21 +0000 | [diff] [blame] | 902 | |
bsalomon@google.com | bcdbbe6 | 2011-04-12 15:40:00 +0000 | [diff] [blame] | 903 | void GrGpu::onSetVertexSourceToArray(const void* vertexArray, int vertexCount) { |
bsalomon@google.com | bcdbbe6 | 2011-04-12 15:40:00 +0000 | [diff] [blame] | 904 | this->prepareVertexPool(); |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 905 | GeometryPoolState& geomPoolState = fGeomPoolStateStack.back(); |
bsalomon@google.com | 1c13c96 | 2011-02-14 16:51:21 +0000 | [diff] [blame] | 906 | #if GR_DEBUG |
| 907 | bool success = |
| 908 | #endif |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 909 | fVertexPool->appendVertices(this->getGeomSrc().fVertexLayout, |
bsalomon@google.com | 1c13c96 | 2011-02-14 16:51:21 +0000 | [diff] [blame] | 910 | vertexCount, |
| 911 | vertexArray, |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 912 | &geomPoolState.fPoolVertexBuffer, |
| 913 | &geomPoolState.fPoolStartVertex); |
| 914 | ++fVertexPoolUseCnt; |
bsalomon@google.com | 1c13c96 | 2011-02-14 16:51:21 +0000 | [diff] [blame] | 915 | GR_DEBUGASSERT(success); |
| 916 | } |
| 917 | |
bsalomon@google.com | bcdbbe6 | 2011-04-12 15:40:00 +0000 | [diff] [blame] | 918 | void GrGpu::onSetIndexSourceToArray(const void* indexArray, int indexCount) { |
bsalomon@google.com | bcdbbe6 | 2011-04-12 15:40:00 +0000 | [diff] [blame] | 919 | this->prepareIndexPool(); |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 920 | GeometryPoolState& geomPoolState = fGeomPoolStateStack.back(); |
bsalomon@google.com | 1c13c96 | 2011-02-14 16:51:21 +0000 | [diff] [blame] | 921 | #if GR_DEBUG |
| 922 | bool success = |
| 923 | #endif |
| 924 | fIndexPool->appendIndices(indexCount, |
| 925 | indexArray, |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 926 | &geomPoolState.fPoolIndexBuffer, |
| 927 | &geomPoolState.fPoolStartIndex); |
| 928 | ++fIndexPoolUseCnt; |
bsalomon@google.com | 1c13c96 | 2011-02-14 16:51:21 +0000 | [diff] [blame] | 929 | GR_DEBUGASSERT(success); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 930 | } |
| 931 | |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 932 | void GrGpu::releaseVertexArray() { |
| 933 | // if vertex source was array, we stowed data in the pool |
| 934 | const GeometrySrcState& geoSrc = this->getGeomSrc(); |
| 935 | GrAssert(kArray_GeometrySrcType == geoSrc.fVertexSrc); |
| 936 | size_t bytes = geoSrc.fVertexCount * VertexSize(geoSrc.fVertexLayout); |
| 937 | fVertexPool->putBack(bytes); |
| 938 | --fVertexPoolUseCnt; |
| 939 | } |
| 940 | |
| 941 | void GrGpu::releaseIndexArray() { |
| 942 | // if index source was array, we stowed data in the pool |
| 943 | const GeometrySrcState& geoSrc = this->getGeomSrc(); |
| 944 | GrAssert(kArray_GeometrySrcType == geoSrc.fIndexSrc); |
| 945 | size_t bytes = geoSrc.fIndexCount * sizeof(uint16_t); |
| 946 | fIndexPool->putBack(bytes); |
| 947 | --fIndexPoolUseCnt; |
| 948 | } |
| 949 | |
bsalomon@google.com | d302f14 | 2011-03-03 13:54:13 +0000 | [diff] [blame] | 950 | //////////////////////////////////////////////////////////////////////////////// |
| 951 | |
bsalomon@google.com | 05ef510 | 2011-05-02 21:14:59 +0000 | [diff] [blame] | 952 | const GrGpuStats& GrGpu::getStats() const { |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 953 | return fStats; |
| 954 | } |
| 955 | |
| 956 | void GrGpu::resetStats() { |
| 957 | memset(&fStats, 0, sizeof(fStats)); |
| 958 | } |
| 959 | |
| 960 | void GrGpu::printStats() const { |
| 961 | if (GR_COLLECT_STATS) { |
| 962 | GrPrintf( |
| 963 | "-v-------------------------GPU STATS----------------------------v-\n" |
| 964 | "Stats collection is: %s\n" |
| 965 | "Draws: %04d, Verts: %04d, Indices: %04d\n" |
| 966 | "ProgChanges: %04d, TexChanges: %04d, RTChanges: %04d\n" |
| 967 | "TexCreates: %04d, RTCreates:%04d\n" |
| 968 | "-^--------------------------------------------------------------^-\n", |
| 969 | (GR_COLLECT_STATS ? "ON" : "OFF"), |
| 970 | fStats.fDrawCnt, fStats.fVertexCnt, fStats.fIndexCnt, |
| 971 | fStats.fProgChngCnt, fStats.fTextureChngCnt, fStats.fRenderTargetChngCnt, |
| 972 | fStats.fTextureCreateCnt, fStats.fRenderTargetCreateCnt); |
| 973 | } |
| 974 | } |
| 975 | |