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