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" |
tomhudson@google.com | dd182cb | 2012-02-10 21:01:00 +0000 | [diff] [blame] | 16 | #include "GrStencilBuffer.h" |
bsalomon@google.com | 81c3f8d | 2011-08-03 15:18:33 +0000 | [diff] [blame] | 17 | #include "GrVertexBuffer.h" |
bsalomon@google.com | 1c13c96 | 2011-02-14 16:51:21 +0000 | [diff] [blame] | 18 | |
| 19 | // 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] | 20 | static const size_t VERTEX_POOL_VB_SIZE = 1 << 18; |
| 21 | static const int VERTEX_POOL_VB_COUNT = 4; |
bsalomon@google.com | 25fd36c | 2011-07-06 17:41:08 +0000 | [diff] [blame] | 22 | static const size_t INDEX_POOL_IB_SIZE = 1 << 16; |
| 23 | static const int INDEX_POOL_IB_COUNT = 4; |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 24 | |
bsalomon@google.com | d302f14 | 2011-03-03 13:54:13 +0000 | [diff] [blame] | 25 | //////////////////////////////////////////////////////////////////////////////// |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 26 | |
| 27 | extern void gr_run_unittests(); |
| 28 | |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 29 | #define DEBUG_INVAL_BUFFER 0xdeadcafe |
| 30 | #define DEBUG_INVAL_START_IDX -1 |
| 31 | |
bsalomon@google.com | 8fe7247 | 2011-03-30 21:26:44 +0000 | [diff] [blame] | 32 | GrGpu::GrGpu() |
robertphillips@google.com | 730ebe5 | 2012-04-16 16:33:13 +0000 | [diff] [blame] | 33 | : fContext(NULL) |
bsalomon@google.com | 979432b | 2011-11-05 21:38:22 +0000 | [diff] [blame] | 34 | , fResetTimestamp(kExpiredTimestamp+1) |
bsalomon@google.com | 8fe7247 | 2011-03-30 21:26:44 +0000 | [diff] [blame] | 35 | , fVertexPool(NULL) |
| 36 | , fIndexPool(NULL) |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 37 | , fVertexPoolUseCnt(0) |
| 38 | , fIndexPoolUseCnt(0) |
bsalomon@google.com | 8fe7247 | 2011-03-30 21:26:44 +0000 | [diff] [blame] | 39 | , fQuadIndexBuffer(NULL) |
| 40 | , fUnitSquareVertexBuffer(NULL) |
bsalomon@google.com | 8fe7247 | 2011-03-30 21:26:44 +0000 | [diff] [blame] | 41 | , fContextIsDirty(true) |
bsalomon@google.com | 8fe7247 | 2011-03-30 21:26:44 +0000 | [diff] [blame] | 42 | , fResourceHead(NULL) { |
bsalomon@google.com | 669fdc4 | 2011-04-05 17:08:27 +0000 | [diff] [blame] | 43 | |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 44 | #if GR_DEBUG |
bsalomon@google.com | 5aaa69e | 2011-03-04 20:29:08 +0000 | [diff] [blame] | 45 | //gr_run_unittests(); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 46 | #endif |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 47 | |
| 48 | fGeomPoolStateStack.push_back(); |
| 49 | #if GR_DEBUG |
| 50 | GeometryPoolState& poolState = fGeomPoolStateStack.back(); |
| 51 | poolState.fPoolVertexBuffer = (GrVertexBuffer*)DEBUG_INVAL_BUFFER; |
| 52 | poolState.fPoolStartVertex = DEBUG_INVAL_START_IDX; |
| 53 | poolState.fPoolIndexBuffer = (GrIndexBuffer*)DEBUG_INVAL_BUFFER; |
| 54 | poolState.fPoolStartIndex = DEBUG_INVAL_START_IDX; |
| 55 | #endif |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 56 | resetStats(); |
robertphillips@google.com | 99a5ac0 | 2012-04-10 19:26:38 +0000 | [diff] [blame] | 57 | |
| 58 | for (int i = 0; i < kGrPixelConfigCount; ++i) { |
| 59 | fConfigRenderSupport[i] = false; |
| 60 | }; |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 61 | } |
| 62 | |
| 63 | GrGpu::~GrGpu() { |
bsalomon@google.com | 558a75b | 2011-08-08 17:01:14 +0000 | [diff] [blame] | 64 | this->releaseResources(); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 65 | } |
| 66 | |
bsalomon@google.com | 8fe7247 | 2011-03-30 21:26:44 +0000 | [diff] [blame] | 67 | void GrGpu::abandonResources() { |
| 68 | |
robertphillips@google.com | f105b10 | 2012-05-14 12:18:26 +0000 | [diff] [blame^] | 69 | fClipMaskManager.releaseResources(); |
| 70 | |
bsalomon@google.com | 8fe7247 | 2011-03-30 21:26:44 +0000 | [diff] [blame] | 71 | while (NULL != fResourceHead) { |
| 72 | fResourceHead->abandon(); |
| 73 | } |
| 74 | |
| 75 | GrAssert(NULL == fQuadIndexBuffer || !fQuadIndexBuffer->isValid()); |
| 76 | GrAssert(NULL == fUnitSquareVertexBuffer || |
| 77 | !fUnitSquareVertexBuffer->isValid()); |
| 78 | GrSafeSetNull(fQuadIndexBuffer); |
| 79 | GrSafeSetNull(fUnitSquareVertexBuffer); |
| 80 | delete fVertexPool; |
| 81 | fVertexPool = NULL; |
| 82 | delete fIndexPool; |
| 83 | fIndexPool = NULL; |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 84 | } |
| 85 | |
bsalomon@google.com | 8fe7247 | 2011-03-30 21:26:44 +0000 | [diff] [blame] | 86 | void GrGpu::releaseResources() { |
| 87 | |
robertphillips@google.com | f105b10 | 2012-05-14 12:18:26 +0000 | [diff] [blame^] | 88 | fClipMaskManager.releaseResources(); |
| 89 | |
bsalomon@google.com | 8fe7247 | 2011-03-30 21:26:44 +0000 | [diff] [blame] | 90 | while (NULL != fResourceHead) { |
| 91 | fResourceHead->release(); |
| 92 | } |
| 93 | |
| 94 | GrAssert(NULL == fQuadIndexBuffer || !fQuadIndexBuffer->isValid()); |
| 95 | GrAssert(NULL == fUnitSquareVertexBuffer || |
| 96 | !fUnitSquareVertexBuffer->isValid()); |
| 97 | GrSafeSetNull(fQuadIndexBuffer); |
| 98 | GrSafeSetNull(fUnitSquareVertexBuffer); |
| 99 | delete fVertexPool; |
| 100 | fVertexPool = NULL; |
| 101 | delete fIndexPool; |
| 102 | fIndexPool = NULL; |
| 103 | } |
| 104 | |
| 105 | void GrGpu::insertResource(GrResource* resource) { |
| 106 | GrAssert(NULL != resource); |
| 107 | GrAssert(this == resource->getGpu()); |
| 108 | GrAssert(NULL == resource->fNext); |
| 109 | GrAssert(NULL == resource->fPrevious); |
| 110 | |
| 111 | resource->fNext = fResourceHead; |
| 112 | if (NULL != fResourceHead) { |
| 113 | GrAssert(NULL == fResourceHead->fPrevious); |
| 114 | fResourceHead->fPrevious = resource; |
| 115 | } |
| 116 | fResourceHead = resource; |
| 117 | } |
| 118 | |
| 119 | void GrGpu::removeResource(GrResource* resource) { |
| 120 | GrAssert(NULL != resource); |
| 121 | GrAssert(NULL != fResourceHead); |
| 122 | |
| 123 | if (fResourceHead == resource) { |
| 124 | GrAssert(NULL == resource->fPrevious); |
| 125 | fResourceHead = resource->fNext; |
| 126 | } else { |
| 127 | GrAssert(NULL != fResourceHead); |
| 128 | resource->fPrevious->fNext = resource->fNext; |
| 129 | } |
| 130 | if (NULL != resource->fNext) { |
| 131 | resource->fNext->fPrevious = resource->fPrevious; |
| 132 | } |
| 133 | resource->fNext = NULL; |
| 134 | resource->fPrevious = NULL; |
| 135 | } |
| 136 | |
| 137 | |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 138 | void GrGpu::unimpl(const char msg[]) { |
bsalomon@google.com | 7d34d2e | 2011-01-24 17:41:47 +0000 | [diff] [blame] | 139 | #if GR_DEBUG |
| 140 | GrPrintf("--- GrGpu unimplemented(\"%s\")\n", msg); |
| 141 | #endif |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 142 | } |
| 143 | |
bsalomon@google.com | d302f14 | 2011-03-03 13:54:13 +0000 | [diff] [blame] | 144 | //////////////////////////////////////////////////////////////////////////////// |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 145 | |
bsalomon@google.com | fea37b5 | 2011-04-25 15:51:06 +0000 | [diff] [blame] | 146 | GrTexture* GrGpu::createTexture(const GrTextureDesc& desc, |
bsalomon@google.com | a7f84e1 | 2011-03-10 14:13:19 +0000 | [diff] [blame] | 147 | const void* srcData, size_t rowBytes) { |
| 148 | this->handleDirtyContext(); |
bsalomon@google.com | 81c3f8d | 2011-08-03 15:18:33 +0000 | [diff] [blame] | 149 | GrTexture* tex = this->onCreateTexture(desc, srcData, rowBytes); |
| 150 | if (NULL != tex && |
| 151 | (kRenderTarget_GrTextureFlagBit & desc.fFlags) && |
| 152 | !(kNoStencil_GrTextureFlagBit & desc.fFlags)) { |
| 153 | GrAssert(NULL != tex->asRenderTarget()); |
| 154 | // TODO: defer this and attach dynamically |
| 155 | if (!this->attachStencilBufferToRenderTarget(tex->asRenderTarget())) { |
| 156 | tex->unref(); |
| 157 | return NULL; |
| 158 | } |
| 159 | } |
| 160 | return tex; |
| 161 | } |
| 162 | |
| 163 | bool GrGpu::attachStencilBufferToRenderTarget(GrRenderTarget* rt) { |
bsalomon@google.com | 558a75b | 2011-08-08 17:01:14 +0000 | [diff] [blame] | 164 | GrAssert(NULL == rt->getStencilBuffer()); |
| 165 | GrStencilBuffer* sb = |
bsalomon@google.com | 9962108 | 2011-11-15 16:47:16 +0000 | [diff] [blame] | 166 | this->getContext()->findStencilBuffer(rt->width(), |
| 167 | rt->height(), |
bsalomon@google.com | 558a75b | 2011-08-08 17:01:14 +0000 | [diff] [blame] | 168 | rt->numSamples()); |
| 169 | if (NULL != sb) { |
| 170 | rt->setStencilBuffer(sb); |
| 171 | bool attached = this->attachStencilBufferToRenderTarget(sb, rt); |
| 172 | if (!attached) { |
| 173 | rt->setStencilBuffer(NULL); |
| 174 | } |
| 175 | return attached; |
| 176 | } |
bsalomon@google.com | 9962108 | 2011-11-15 16:47:16 +0000 | [diff] [blame] | 177 | if (this->createStencilBufferForRenderTarget(rt, |
| 178 | rt->width(), rt->height())) { |
bsalomon@google.com | 558a75b | 2011-08-08 17:01:14 +0000 | [diff] [blame] | 179 | rt->getStencilBuffer()->ref(); |
| 180 | rt->getStencilBuffer()->transferToCacheAndLock(); |
| 181 | |
bsalomon@google.com | edc177d | 2011-08-05 15:46:40 +0000 | [diff] [blame] | 182 | // Right now we're clearing the stencil buffer here after it is |
| 183 | // attached to an RT for the first time. When we start matching |
| 184 | // stencil buffers with smaller color targets this will no longer |
| 185 | // be correct because it won't be guaranteed to clear the entire |
| 186 | // sb. |
| 187 | // We used to clear down in the GL subclass using a special purpose |
| 188 | // FBO. But iOS doesn't allow a stencil-only FBO. It reports unsupported |
| 189 | // FBO status. |
bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 190 | GrDrawState::AutoRenderTargetRestore artr(this->drawState(), rt); |
bsalomon@google.com | edc177d | 2011-08-05 15:46:40 +0000 | [diff] [blame] | 191 | this->clearStencil(); |
bsalomon@google.com | 558a75b | 2011-08-08 17:01:14 +0000 | [diff] [blame] | 192 | return true; |
| 193 | } else { |
| 194 | return false; |
bsalomon@google.com | edc177d | 2011-08-05 15:46:40 +0000 | [diff] [blame] | 195 | } |
bsalomon@google.com | a7f84e1 | 2011-03-10 14:13:19 +0000 | [diff] [blame] | 196 | } |
| 197 | |
bsalomon@google.com | e269f21 | 2011-11-07 13:29:52 +0000 | [diff] [blame] | 198 | GrTexture* GrGpu::createPlatformTexture(const GrPlatformTextureDesc& desc) { |
| 199 | this->handleDirtyContext(); |
| 200 | GrTexture* tex = this->onCreatePlatformTexture(desc); |
bsalomon@google.com | a14dd6d | 2012-01-03 21:08:12 +0000 | [diff] [blame] | 201 | if (NULL == tex) { |
| 202 | return NULL; |
| 203 | } |
bsalomon@google.com | e269f21 | 2011-11-07 13:29:52 +0000 | [diff] [blame] | 204 | // TODO: defer this and attach dynamically |
| 205 | GrRenderTarget* tgt = tex->asRenderTarget(); |
| 206 | if (NULL != tgt && |
| 207 | !this->attachStencilBufferToRenderTarget(tgt)) { |
| 208 | tex->unref(); |
| 209 | return NULL; |
| 210 | } else { |
| 211 | return tex; |
| 212 | } |
| 213 | } |
| 214 | |
| 215 | GrRenderTarget* GrGpu::createPlatformRenderTarget(const GrPlatformRenderTargetDesc& desc) { |
| 216 | this->handleDirtyContext(); |
| 217 | return this->onCreatePlatformRenderTarget(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 | 75f9f25 | 2012-01-31 13:35:56 +0000 | [diff] [blame] | 265 | void GrGpu::resolveRenderTarget(GrRenderTarget* target) { |
| 266 | GrAssert(target); |
| 267 | this->handleDirtyContext(); |
| 268 | this->onResolveRenderTarget(target); |
| 269 | } |
| 270 | |
| 271 | |
bsalomon@google.com | a7f84e1 | 2011-03-10 14:13:19 +0000 | [diff] [blame] | 272 | //////////////////////////////////////////////////////////////////////////////// |
| 273 | |
bsalomon@google.com | 1c13c96 | 2011-02-14 16:51:21 +0000 | [diff] [blame] | 274 | 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] | 275 | |
reed@google.com | 8195f67 | 2011-01-12 18:14:28 +0000 | [diff] [blame] | 276 | GR_STATIC_ASSERT(4 * MAX_QUADS <= 65535); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 277 | |
bsalomon@google.com | 1c13c96 | 2011-02-14 16:51:21 +0000 | [diff] [blame] | 278 | static inline void fill_indices(uint16_t* indices, int quadCount) { |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 279 | for (int i = 0; i < quadCount; ++i) { |
| 280 | indices[6 * i + 0] = 4 * i + 0; |
| 281 | indices[6 * i + 1] = 4 * i + 1; |
| 282 | indices[6 * i + 2] = 4 * i + 2; |
| 283 | indices[6 * i + 3] = 4 * i + 0; |
| 284 | indices[6 * i + 4] = 4 * i + 2; |
| 285 | indices[6 * i + 5] = 4 * i + 3; |
| 286 | } |
| 287 | } |
| 288 | |
bsalomon@google.com | 86afc2a | 2011-02-16 16:12:19 +0000 | [diff] [blame] | 289 | const GrIndexBuffer* GrGpu::getQuadIndexBuffer() const { |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 290 | if (NULL == fQuadIndexBuffer) { |
| 291 | static const int SIZE = sizeof(uint16_t) * 6 * MAX_QUADS; |
| 292 | GrGpu* me = const_cast<GrGpu*>(this); |
| 293 | fQuadIndexBuffer = me->createIndexBuffer(SIZE, false); |
| 294 | if (NULL != fQuadIndexBuffer) { |
| 295 | uint16_t* indices = (uint16_t*)fQuadIndexBuffer->lock(); |
| 296 | if (NULL != indices) { |
bsalomon@google.com | 1c13c96 | 2011-02-14 16:51:21 +0000 | [diff] [blame] | 297 | fill_indices(indices, MAX_QUADS); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 298 | fQuadIndexBuffer->unlock(); |
| 299 | } else { |
| 300 | indices = (uint16_t*)GrMalloc(SIZE); |
bsalomon@google.com | 1c13c96 | 2011-02-14 16:51:21 +0000 | [diff] [blame] | 301 | fill_indices(indices, MAX_QUADS); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 302 | if (!fQuadIndexBuffer->updateData(indices, SIZE)) { |
| 303 | fQuadIndexBuffer->unref(); |
| 304 | fQuadIndexBuffer = NULL; |
bsalomon@google.com | 6f7fbc9 | 2011-02-01 19:12:40 +0000 | [diff] [blame] | 305 | GrCrash("Can't get indices into buffer!"); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 306 | } |
| 307 | GrFree(indices); |
| 308 | } |
| 309 | } |
| 310 | } |
| 311 | |
| 312 | return fQuadIndexBuffer; |
| 313 | } |
| 314 | |
bsalomon@google.com | 86afc2a | 2011-02-16 16:12:19 +0000 | [diff] [blame] | 315 | const GrVertexBuffer* GrGpu::getUnitSquareVertexBuffer() const { |
bsalomon@google.com | 6f7fbc9 | 2011-02-01 19:12:40 +0000 | [diff] [blame] | 316 | if (NULL == fUnitSquareVertexBuffer) { |
| 317 | |
| 318 | static const GrPoint DATA[] = { |
reed@google.com | 7744c20 | 2011-05-06 19:26:26 +0000 | [diff] [blame] | 319 | { 0, 0 }, |
| 320 | { GR_Scalar1, 0 }, |
| 321 | { GR_Scalar1, GR_Scalar1 }, |
| 322 | { 0, GR_Scalar1 } |
| 323 | #if 0 |
bsalomon@google.com | 6f7fbc9 | 2011-02-01 19:12:40 +0000 | [diff] [blame] | 324 | GrPoint(0, 0), |
| 325 | GrPoint(GR_Scalar1,0), |
| 326 | GrPoint(GR_Scalar1,GR_Scalar1), |
| 327 | GrPoint(0, GR_Scalar1) |
reed@google.com | 7744c20 | 2011-05-06 19:26:26 +0000 | [diff] [blame] | 328 | #endif |
bsalomon@google.com | 6f7fbc9 | 2011-02-01 19:12:40 +0000 | [diff] [blame] | 329 | }; |
| 330 | static const size_t SIZE = sizeof(DATA); |
| 331 | |
| 332 | GrGpu* me = const_cast<GrGpu*>(this); |
| 333 | fUnitSquareVertexBuffer = me->createVertexBuffer(SIZE, false); |
| 334 | if (NULL != fUnitSquareVertexBuffer) { |
| 335 | if (!fUnitSquareVertexBuffer->updateData(DATA, SIZE)) { |
| 336 | fUnitSquareVertexBuffer->unref(); |
| 337 | fUnitSquareVertexBuffer = NULL; |
| 338 | GrCrash("Can't get vertices into buffer!"); |
| 339 | } |
| 340 | } |
| 341 | } |
| 342 | |
| 343 | return fUnitSquareVertexBuffer; |
| 344 | } |
| 345 | |
bsalomon@google.com | d302f14 | 2011-03-03 13:54:13 +0000 | [diff] [blame] | 346 | //////////////////////////////////////////////////////////////////////////////// |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 347 | |
digit@google.com | 9b482c4 | 2012-02-16 22:03:26 +0000 | [diff] [blame] | 348 | const GrStencilSettings* GrGpu::GetClipStencilSettings(void) { |
| 349 | // stencil settings to use when clip is in stencil |
| 350 | GR_STATIC_CONST_SAME_STENCIL_STRUCT(sClipStencilSettings, |
| 351 | kKeep_StencilOp, |
| 352 | kKeep_StencilOp, |
| 353 | kAlwaysIfInClip_StencilFunc, |
| 354 | 0x0000, |
| 355 | 0x0000, |
| 356 | 0x0000); |
| 357 | return GR_CONST_STENCIL_SETTINGS_PTR_FROM_STRUCT_PTR(&sClipStencilSettings); |
| 358 | } |
bsalomon@google.com | d302f14 | 2011-03-03 13:54:13 +0000 | [diff] [blame] | 359 | |
bsalomon@google.com | a7f84e1 | 2011-03-10 14:13:19 +0000 | [diff] [blame] | 360 | // mapping of clip-respecting stencil funcs to normal stencil funcs |
| 361 | // mapping depends on whether stencil-clipping is in effect. |
bsalomon@google.com | d302f14 | 2011-03-03 13:54:13 +0000 | [diff] [blame] | 362 | static const GrStencilFunc gGrClipToNormalStencilFunc[2][kClipStencilFuncCount] = { |
| 363 | {// Stencil-Clipping is DISABLED, effectively always inside the clip |
| 364 | // In the Clip Funcs |
| 365 | kAlways_StencilFunc, // kAlwaysIfInClip_StencilFunc |
| 366 | kEqual_StencilFunc, // kEqualIfInClip_StencilFunc |
| 367 | kLess_StencilFunc, // kLessIfInClip_StencilFunc |
| 368 | kLEqual_StencilFunc, // kLEqualIfInClip_StencilFunc |
| 369 | // Special in the clip func that forces user's ref to be 0. |
| 370 | kNotEqual_StencilFunc, // kNonZeroIfInClip_StencilFunc |
| 371 | // make ref 0 and do normal nequal. |
| 372 | }, |
| 373 | {// Stencil-Clipping is ENABLED |
| 374 | // In the Clip Funcs |
| 375 | kEqual_StencilFunc, // kAlwaysIfInClip_StencilFunc |
| 376 | // eq stencil clip bit, mask |
| 377 | // out user bits. |
| 378 | |
| 379 | kEqual_StencilFunc, // kEqualIfInClip_StencilFunc |
| 380 | // add stencil bit to mask and ref |
| 381 | |
| 382 | kLess_StencilFunc, // kLessIfInClip_StencilFunc |
| 383 | kLEqual_StencilFunc, // kLEqualIfInClip_StencilFunc |
| 384 | // for both of these we can add |
| 385 | // the clip bit to the mask and |
| 386 | // ref and compare as normal |
| 387 | // Special in the clip func that forces user's ref to be 0. |
| 388 | kLess_StencilFunc, // kNonZeroIfInClip_StencilFunc |
| 389 | // make ref have only the clip bit set |
| 390 | // and make comparison be less |
| 391 | // 10..0 < 1..user_bits.. |
| 392 | } |
| 393 | }; |
| 394 | |
| 395 | GrStencilFunc GrGpu::ConvertStencilFunc(bool stencilInClip, GrStencilFunc func) { |
| 396 | GrAssert(func >= 0); |
| 397 | if (func >= kBasicStencilFuncCount) { |
| 398 | GrAssert(func < kStencilFuncCount); |
| 399 | func = gGrClipToNormalStencilFunc[stencilInClip ? 1 : 0][func - kBasicStencilFuncCount]; |
| 400 | GrAssert(func >= 0 && func < kBasicStencilFuncCount); |
| 401 | } |
| 402 | return func; |
| 403 | } |
| 404 | |
| 405 | void GrGpu::ConvertStencilFuncAndMask(GrStencilFunc func, |
| 406 | bool clipInStencil, |
| 407 | unsigned int clipBit, |
| 408 | unsigned int userBits, |
| 409 | unsigned int* ref, |
| 410 | unsigned int* mask) { |
| 411 | if (func < kBasicStencilFuncCount) { |
| 412 | *mask &= userBits; |
| 413 | *ref &= userBits; |
| 414 | } else { |
| 415 | if (clipInStencil) { |
| 416 | switch (func) { |
| 417 | case kAlwaysIfInClip_StencilFunc: |
| 418 | *mask = clipBit; |
| 419 | *ref = clipBit; |
| 420 | break; |
| 421 | case kEqualIfInClip_StencilFunc: |
| 422 | case kLessIfInClip_StencilFunc: |
| 423 | case kLEqualIfInClip_StencilFunc: |
| 424 | *mask = (*mask & userBits) | clipBit; |
| 425 | *ref = (*ref & userBits) | clipBit; |
| 426 | break; |
| 427 | case kNonZeroIfInClip_StencilFunc: |
| 428 | *mask = (*mask & userBits) | clipBit; |
| 429 | *ref = clipBit; |
| 430 | break; |
| 431 | default: |
| 432 | GrCrash("Unknown stencil func"); |
| 433 | } |
| 434 | } else { |
| 435 | *mask &= userBits; |
| 436 | *ref &= userBits; |
| 437 | } |
| 438 | } |
| 439 | } |
| 440 | |
| 441 | //////////////////////////////////////////////////////////////////////////////// |
| 442 | |
robertphillips@google.com | 730ebe5 | 2012-04-16 16:33:13 +0000 | [diff] [blame] | 443 | bool GrGpu::setupClipAndFlushState(GrPrimitiveType type) { |
| 444 | |
| 445 | ScissoringSettings scissoringSettings; |
| 446 | |
| 447 | if (!fClipMaskManager.createClipMask(this, fClip, &scissoringSettings)) { |
| 448 | return false; |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 449 | } |
bsalomon@google.com | d302f14 | 2011-03-03 13:54:13 +0000 | [diff] [blame] | 450 | |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 451 | // Must flush the scissor after graphics state |
bsalomon@google.com | d302f14 | 2011-03-03 13:54:13 +0000 | [diff] [blame] | 452 | if (!this->flushGraphicsState(type)) { |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 453 | return false; |
| 454 | } |
robertphillips@google.com | 730ebe5 | 2012-04-16 16:33:13 +0000 | [diff] [blame] | 455 | |
| 456 | scissoringSettings.setupScissoring(this); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 457 | return true; |
| 458 | } |
| 459 | |
bsalomon@google.com | d302f14 | 2011-03-03 13:54:13 +0000 | [diff] [blame] | 460 | //////////////////////////////////////////////////////////////////////////////// |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 461 | |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 462 | void GrGpu::geometrySourceWillPush() { |
| 463 | const GeometrySrcState& geoSrc = this->getGeomSrc(); |
| 464 | if (kArray_GeometrySrcType == geoSrc.fVertexSrc || |
| 465 | kReserved_GeometrySrcType == geoSrc.fVertexSrc) { |
| 466 | this->finalizeReservedVertices(); |
| 467 | } |
| 468 | if (kArray_GeometrySrcType == geoSrc.fIndexSrc || |
| 469 | kReserved_GeometrySrcType == geoSrc.fIndexSrc) { |
| 470 | this->finalizeReservedIndices(); |
| 471 | } |
| 472 | GeometryPoolState& newState = fGeomPoolStateStack.push_back(); |
| 473 | #if GR_DEBUG |
| 474 | newState.fPoolVertexBuffer = (GrVertexBuffer*)DEBUG_INVAL_BUFFER; |
| 475 | newState.fPoolStartVertex = DEBUG_INVAL_START_IDX; |
| 476 | newState.fPoolIndexBuffer = (GrIndexBuffer*)DEBUG_INVAL_BUFFER; |
| 477 | newState.fPoolStartIndex = DEBUG_INVAL_START_IDX; |
| 478 | #endif |
| 479 | } |
| 480 | |
| 481 | void GrGpu::geometrySourceWillPop(const GeometrySrcState& restoredState) { |
| 482 | // if popping last entry then pops are unbalanced with pushes |
| 483 | GrAssert(fGeomPoolStateStack.count() > 1); |
| 484 | fGeomPoolStateStack.pop_back(); |
| 485 | } |
| 486 | |
| 487 | void GrGpu::onDrawIndexed(GrPrimitiveType type, |
| 488 | int startVertex, |
| 489 | int startIndex, |
| 490 | int vertexCount, |
| 491 | int indexCount) { |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 492 | |
bsalomon@google.com | a7f84e1 | 2011-03-10 14:13:19 +0000 | [diff] [blame] | 493 | this->handleDirtyContext(); |
| 494 | |
| 495 | if (!this->setupClipAndFlushState(type)) { |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 496 | return; |
| 497 | } |
| 498 | |
| 499 | #if GR_COLLECT_STATS |
| 500 | fStats.fVertexCnt += vertexCount; |
| 501 | fStats.fIndexCnt += indexCount; |
| 502 | fStats.fDrawCnt += 1; |
| 503 | #endif |
| 504 | |
bsalomon@google.com | 1c13c96 | 2011-02-14 16:51:21 +0000 | [diff] [blame] | 505 | int sVertex = startVertex; |
| 506 | int sIndex = startIndex; |
| 507 | setupGeometry(&sVertex, &sIndex, vertexCount, indexCount); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 508 | |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 509 | this->onGpuDrawIndexed(type, sVertex, sIndex, |
| 510 | vertexCount, indexCount); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 511 | } |
| 512 | |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 513 | void GrGpu::onDrawNonIndexed(GrPrimitiveType type, |
bsalomon@google.com | 1c13c96 | 2011-02-14 16:51:21 +0000 | [diff] [blame] | 514 | int startVertex, |
| 515 | int vertexCount) { |
bsalomon@google.com | a7f84e1 | 2011-03-10 14:13:19 +0000 | [diff] [blame] | 516 | this->handleDirtyContext(); |
| 517 | |
| 518 | if (!this->setupClipAndFlushState(type)) { |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 519 | return; |
| 520 | } |
| 521 | #if GR_COLLECT_STATS |
| 522 | fStats.fVertexCnt += vertexCount; |
| 523 | fStats.fDrawCnt += 1; |
| 524 | #endif |
| 525 | |
bsalomon@google.com | 1c13c96 | 2011-02-14 16:51:21 +0000 | [diff] [blame] | 526 | int sVertex = startVertex; |
| 527 | setupGeometry(&sVertex, NULL, vertexCount, 0); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 528 | |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 529 | this->onGpuDrawNonIndexed(type, sVertex, vertexCount); |
bsalomon@google.com | 1c13c96 | 2011-02-14 16:51:21 +0000 | [diff] [blame] | 530 | } |
| 531 | |
| 532 | void GrGpu::finalizeReservedVertices() { |
| 533 | GrAssert(NULL != fVertexPool); |
| 534 | fVertexPool->unlock(); |
| 535 | } |
| 536 | |
| 537 | void GrGpu::finalizeReservedIndices() { |
| 538 | GrAssert(NULL != fIndexPool); |
| 539 | fIndexPool->unlock(); |
| 540 | } |
| 541 | |
| 542 | void GrGpu::prepareVertexPool() { |
| 543 | if (NULL == fVertexPool) { |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 544 | GrAssert(0 == fVertexPoolUseCnt); |
bsalomon@google.com | d302f14 | 2011-03-03 13:54:13 +0000 | [diff] [blame] | 545 | fVertexPool = new GrVertexBufferAllocPool(this, true, |
| 546 | VERTEX_POOL_VB_SIZE, |
bsalomon@google.com | 7a5af8b | 2011-02-18 18:40:42 +0000 | [diff] [blame] | 547 | VERTEX_POOL_VB_COUNT); |
bsalomon@google.com | 11f0b51 | 2011-03-29 20:52:23 +0000 | [diff] [blame] | 548 | fVertexPool->releaseGpuRef(); |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 549 | } else if (!fVertexPoolUseCnt) { |
bsalomon@google.com | d302f14 | 2011-03-03 13:54:13 +0000 | [diff] [blame] | 550 | // the client doesn't have valid data in the pool |
bsalomon@google.com | 1c13c96 | 2011-02-14 16:51:21 +0000 | [diff] [blame] | 551 | fVertexPool->reset(); |
| 552 | } |
| 553 | } |
| 554 | |
| 555 | void GrGpu::prepareIndexPool() { |
senorblanco@chromium.org | 9d18b78 | 2011-03-28 20:47:09 +0000 | [diff] [blame] | 556 | if (NULL == fIndexPool) { |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 557 | GrAssert(0 == fIndexPoolUseCnt); |
bsalomon@google.com | 25fd36c | 2011-07-06 17:41:08 +0000 | [diff] [blame] | 558 | fIndexPool = new GrIndexBufferAllocPool(this, true, |
| 559 | INDEX_POOL_IB_SIZE, |
| 560 | INDEX_POOL_IB_COUNT); |
bsalomon@google.com | 11f0b51 | 2011-03-29 20:52:23 +0000 | [diff] [blame] | 561 | fIndexPool->releaseGpuRef(); |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 562 | } else if (!fIndexPoolUseCnt) { |
bsalomon@google.com | d302f14 | 2011-03-03 13:54:13 +0000 | [diff] [blame] | 563 | // the client doesn't have valid data in the pool |
bsalomon@google.com | 1c13c96 | 2011-02-14 16:51:21 +0000 | [diff] [blame] | 564 | fIndexPool->reset(); |
| 565 | } |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 566 | } |
| 567 | |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 568 | bool GrGpu::onReserveVertexSpace(GrVertexLayout vertexLayout, |
| 569 | int vertexCount, |
| 570 | void** vertices) { |
| 571 | GeometryPoolState& geomPoolState = fGeomPoolStateStack.back(); |
| 572 | |
| 573 | GrAssert(vertexCount > 0); |
| 574 | GrAssert(NULL != vertices); |
| 575 | |
| 576 | this->prepareVertexPool(); |
| 577 | |
| 578 | *vertices = fVertexPool->makeSpace(vertexLayout, |
| 579 | vertexCount, |
| 580 | &geomPoolState.fPoolVertexBuffer, |
| 581 | &geomPoolState.fPoolStartVertex); |
| 582 | if (NULL == *vertices) { |
| 583 | return false; |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 584 | } |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 585 | ++fVertexPoolUseCnt; |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 586 | return true; |
| 587 | } |
| 588 | |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 589 | bool GrGpu::onReserveIndexSpace(int indexCount, void** indices) { |
| 590 | GeometryPoolState& geomPoolState = fGeomPoolStateStack.back(); |
| 591 | |
| 592 | GrAssert(indexCount > 0); |
| 593 | GrAssert(NULL != indices); |
| 594 | |
| 595 | this->prepareIndexPool(); |
| 596 | |
| 597 | *indices = fIndexPool->makeSpace(indexCount, |
| 598 | &geomPoolState.fPoolIndexBuffer, |
| 599 | &geomPoolState.fPoolStartIndex); |
| 600 | if (NULL == *indices) { |
| 601 | return false; |
| 602 | } |
| 603 | ++fIndexPoolUseCnt; |
| 604 | return true; |
| 605 | } |
| 606 | |
| 607 | void GrGpu::releaseReservedVertexSpace() { |
| 608 | const GeometrySrcState& geoSrc = this->getGeomSrc(); |
| 609 | GrAssert(kReserved_GeometrySrcType == geoSrc.fVertexSrc); |
| 610 | size_t bytes = geoSrc.fVertexCount * VertexSize(geoSrc.fVertexLayout); |
| 611 | fVertexPool->putBack(bytes); |
| 612 | --fVertexPoolUseCnt; |
| 613 | } |
| 614 | |
| 615 | void GrGpu::releaseReservedIndexSpace() { |
| 616 | const GeometrySrcState& geoSrc = this->getGeomSrc(); |
| 617 | GrAssert(kReserved_GeometrySrcType == geoSrc.fIndexSrc); |
| 618 | size_t bytes = geoSrc.fIndexCount * sizeof(uint16_t); |
| 619 | fIndexPool->putBack(bytes); |
| 620 | --fIndexPoolUseCnt; |
| 621 | } |
bsalomon@google.com | 1c13c96 | 2011-02-14 16:51:21 +0000 | [diff] [blame] | 622 | |
bsalomon@google.com | bcdbbe6 | 2011-04-12 15:40:00 +0000 | [diff] [blame] | 623 | void GrGpu::onSetVertexSourceToArray(const void* vertexArray, int vertexCount) { |
bsalomon@google.com | bcdbbe6 | 2011-04-12 15:40:00 +0000 | [diff] [blame] | 624 | this->prepareVertexPool(); |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 625 | GeometryPoolState& geomPoolState = fGeomPoolStateStack.back(); |
bsalomon@google.com | 1c13c96 | 2011-02-14 16:51:21 +0000 | [diff] [blame] | 626 | #if GR_DEBUG |
| 627 | bool success = |
| 628 | #endif |
bsalomon@google.com | e79c815 | 2012-03-29 19:07:12 +0000 | [diff] [blame] | 629 | fVertexPool->appendVertices(this->getVertexLayout(), |
bsalomon@google.com | 1c13c96 | 2011-02-14 16:51:21 +0000 | [diff] [blame] | 630 | vertexCount, |
| 631 | vertexArray, |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 632 | &geomPoolState.fPoolVertexBuffer, |
| 633 | &geomPoolState.fPoolStartVertex); |
| 634 | ++fVertexPoolUseCnt; |
bsalomon@google.com | 1c13c96 | 2011-02-14 16:51:21 +0000 | [diff] [blame] | 635 | GR_DEBUGASSERT(success); |
| 636 | } |
| 637 | |
bsalomon@google.com | bcdbbe6 | 2011-04-12 15:40:00 +0000 | [diff] [blame] | 638 | void GrGpu::onSetIndexSourceToArray(const void* indexArray, int indexCount) { |
bsalomon@google.com | bcdbbe6 | 2011-04-12 15:40:00 +0000 | [diff] [blame] | 639 | this->prepareIndexPool(); |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 640 | GeometryPoolState& geomPoolState = fGeomPoolStateStack.back(); |
bsalomon@google.com | 1c13c96 | 2011-02-14 16:51:21 +0000 | [diff] [blame] | 641 | #if GR_DEBUG |
| 642 | bool success = |
| 643 | #endif |
| 644 | fIndexPool->appendIndices(indexCount, |
| 645 | indexArray, |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 646 | &geomPoolState.fPoolIndexBuffer, |
| 647 | &geomPoolState.fPoolStartIndex); |
| 648 | ++fIndexPoolUseCnt; |
bsalomon@google.com | 1c13c96 | 2011-02-14 16:51:21 +0000 | [diff] [blame] | 649 | GR_DEBUGASSERT(success); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 650 | } |
| 651 | |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 652 | void GrGpu::releaseVertexArray() { |
| 653 | // if vertex source was array, we stowed data in the pool |
| 654 | const GeometrySrcState& geoSrc = this->getGeomSrc(); |
| 655 | GrAssert(kArray_GeometrySrcType == geoSrc.fVertexSrc); |
| 656 | size_t bytes = geoSrc.fVertexCount * VertexSize(geoSrc.fVertexLayout); |
| 657 | fVertexPool->putBack(bytes); |
| 658 | --fVertexPoolUseCnt; |
| 659 | } |
| 660 | |
| 661 | void GrGpu::releaseIndexArray() { |
| 662 | // if index source was array, we stowed data in the pool |
| 663 | const GeometrySrcState& geoSrc = this->getGeomSrc(); |
| 664 | GrAssert(kArray_GeometrySrcType == geoSrc.fIndexSrc); |
| 665 | size_t bytes = geoSrc.fIndexCount * sizeof(uint16_t); |
| 666 | fIndexPool->putBack(bytes); |
| 667 | --fIndexPoolUseCnt; |
| 668 | } |
| 669 | |
bsalomon@google.com | d302f14 | 2011-03-03 13:54:13 +0000 | [diff] [blame] | 670 | //////////////////////////////////////////////////////////////////////////////// |
| 671 | |
bsalomon@google.com | 05ef510 | 2011-05-02 21:14:59 +0000 | [diff] [blame] | 672 | const GrGpuStats& GrGpu::getStats() const { |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 673 | return fStats; |
| 674 | } |
| 675 | |
| 676 | void GrGpu::resetStats() { |
| 677 | memset(&fStats, 0, sizeof(fStats)); |
| 678 | } |
| 679 | |
| 680 | void GrGpu::printStats() const { |
| 681 | if (GR_COLLECT_STATS) { |
| 682 | GrPrintf( |
| 683 | "-v-------------------------GPU STATS----------------------------v-\n" |
| 684 | "Stats collection is: %s\n" |
| 685 | "Draws: %04d, Verts: %04d, Indices: %04d\n" |
| 686 | "ProgChanges: %04d, TexChanges: %04d, RTChanges: %04d\n" |
| 687 | "TexCreates: %04d, RTCreates:%04d\n" |
| 688 | "-^--------------------------------------------------------------^-\n", |
| 689 | (GR_COLLECT_STATS ? "ON" : "OFF"), |
| 690 | fStats.fDrawCnt, fStats.fVertexCnt, fStats.fIndexCnt, |
| 691 | fStats.fProgChngCnt, fStats.fTextureChngCnt, fStats.fRenderTargetChngCnt, |
| 692 | fStats.fTextureCreateCnt, fStats.fRenderTargetCreateCnt); |
| 693 | } |
| 694 | } |
| 695 | |
robertphillips@google.com | 730ebe5 | 2012-04-16 16:33:13 +0000 | [diff] [blame] | 696 | |