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