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" |
bsalomon@google.com | 558a75b | 2011-08-08 17:01:14 +0000 | [diff] [blame] | 13 | #include "GrContext.h" |
bsalomon@google.com | c26d94f | 2013-03-25 18:19:00 +0000 | [diff] [blame] | 14 | #include "GrDrawTargetCaps.h" |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 15 | #include "GrIndexBuffer.h" |
tomhudson@google.com | dd182cb | 2012-02-10 21:01:00 +0000 | [diff] [blame] | 16 | #include "GrStencilBuffer.h" |
bsalomon@google.com | 81c3f8d | 2011-08-03 15:18:33 +0000 | [diff] [blame] | 17 | #include "GrVertexBuffer.h" |
bsalomon@google.com | 1c13c96 | 2011-02-14 16:51:21 +0000 | [diff] [blame] | 18 | |
| 19 | // probably makes no sense for this to be less than a page |
bsalomon@google.com | ee43512 | 2011-07-01 14:57:55 +0000 | [diff] [blame] | 20 | static const size_t VERTEX_POOL_VB_SIZE = 1 << 18; |
| 21 | static const int VERTEX_POOL_VB_COUNT = 4; |
bsalomon@google.com | 25fd36c | 2011-07-06 17:41:08 +0000 | [diff] [blame] | 22 | static const size_t INDEX_POOL_IB_SIZE = 1 << 16; |
| 23 | static const int INDEX_POOL_IB_COUNT = 4; |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 24 | |
bsalomon@google.com | d302f14 | 2011-03-03 13:54:13 +0000 | [diff] [blame] | 25 | //////////////////////////////////////////////////////////////////////////////// |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 26 | |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 27 | #define DEBUG_INVAL_BUFFER 0xdeadcafe |
| 28 | #define DEBUG_INVAL_START_IDX -1 |
| 29 | |
bsalomon@google.com | 6e4e650 | 2013-02-25 20:12:45 +0000 | [diff] [blame] | 30 | GrGpu::GrGpu(GrContext* context) |
joshualitt | 6db519c | 2014-10-29 08:48:18 -0700 | [diff] [blame] | 31 | : INHERITED(context) |
bsalomon@google.com | 979432b | 2011-11-05 21:38:22 +0000 | [diff] [blame] | 32 | , fResetTimestamp(kExpiredTimestamp+1) |
bsalomon@google.com | 0a208a1 | 2013-06-28 18:57:35 +0000 | [diff] [blame] | 33 | , fResetBits(kAll_GrBackendState) |
bsalomon@google.com | 8fe7247 | 2011-03-30 21:26:44 +0000 | [diff] [blame] | 34 | , fVertexPool(NULL) |
| 35 | , fIndexPool(NULL) |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 36 | , fVertexPoolUseCnt(0) |
| 37 | , fIndexPoolUseCnt(0) |
bsalomon@google.com | 0a208a1 | 2013-06-28 18:57:35 +0000 | [diff] [blame] | 38 | , fQuadIndexBuffer(NULL) { |
bsalomon@google.com | 669fdc4 | 2011-04-05 17:08:27 +0000 | [diff] [blame] | 39 | |
robertphillips@google.com | 5d8d186 | 2012-08-15 14:36:41 +0000 | [diff] [blame] | 40 | fClipMaskManager.setGpu(this); |
| 41 | |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 42 | fGeomPoolStateStack.push_back(); |
commit-bot@chromium.org | 515dcd3 | 2013-08-28 14:17:03 +0000 | [diff] [blame] | 43 | #ifdef SK_DEBUG |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 44 | GeometryPoolState& poolState = fGeomPoolStateStack.back(); |
| 45 | poolState.fPoolVertexBuffer = (GrVertexBuffer*)DEBUG_INVAL_BUFFER; |
| 46 | poolState.fPoolStartVertex = DEBUG_INVAL_START_IDX; |
| 47 | poolState.fPoolIndexBuffer = (GrIndexBuffer*)DEBUG_INVAL_BUFFER; |
| 48 | poolState.fPoolStartIndex = DEBUG_INVAL_START_IDX; |
| 49 | #endif |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 50 | } |
| 51 | |
bsalomon | 1d89ddc | 2014-08-19 14:20:58 -0700 | [diff] [blame] | 52 | GrGpu::~GrGpu() { |
bsalomon | 1d89ddc | 2014-08-19 14:20:58 -0700 | [diff] [blame] | 53 | SkSafeSetNull(fQuadIndexBuffer); |
| 54 | delete fVertexPool; |
| 55 | fVertexPool = NULL; |
| 56 | delete fIndexPool; |
| 57 | fIndexPool = NULL; |
| 58 | } |
| 59 | |
robertphillips | e337130 | 2014-09-17 06:01:06 -0700 | [diff] [blame] | 60 | void GrGpu::contextAbandoned() {} |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 61 | |
bsalomon@google.com | d302f14 | 2011-03-03 13:54:13 +0000 | [diff] [blame] | 62 | //////////////////////////////////////////////////////////////////////////////// |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 63 | |
bsalomon | f2703d8 | 2014-10-28 14:33:06 -0700 | [diff] [blame] | 64 | GrTexture* GrGpu::createTexture(const GrSurfaceDesc& desc, |
bsalomon@google.com | a7f84e1 | 2011-03-10 14:13:19 +0000 | [diff] [blame] | 65 | const void* srcData, size_t rowBytes) { |
krajcevski | 9c0e629 | 2014-06-02 07:38:14 -0700 | [diff] [blame] | 66 | if (!this->caps()->isConfigTexturable(desc.fConfig)) { |
robertphillips@google.com | d3eb336 | 2012-10-31 13:56:35 +0000 | [diff] [blame] | 67 | return NULL; |
| 68 | } |
krajcevski | 9c0e629 | 2014-06-02 07:38:14 -0700 | [diff] [blame] | 69 | |
bsalomon | f2703d8 | 2014-10-28 14:33:06 -0700 | [diff] [blame] | 70 | if ((desc.fFlags & kRenderTarget_GrSurfaceFlag) && |
commit-bot@chromium.org | 6b7938f | 2013-10-15 14:18:16 +0000 | [diff] [blame] | 71 | !this->caps()->isConfigRenderable(desc.fConfig, desc.fSampleCnt > 0)) { |
| 72 | return NULL; |
| 73 | } |
robertphillips@google.com | d3eb336 | 2012-10-31 13:56:35 +0000 | [diff] [blame] | 74 | |
krajcevski | 9c0e629 | 2014-06-02 07:38:14 -0700 | [diff] [blame] | 75 | GrTexture *tex = NULL; |
| 76 | if (GrPixelConfigIsCompressed(desc.fConfig)) { |
| 77 | // We shouldn't be rendering into this |
bsalomon | f2703d8 | 2014-10-28 14:33:06 -0700 | [diff] [blame] | 78 | SkASSERT((desc.fFlags & kRenderTarget_GrSurfaceFlag) == 0); |
krajcevski | 9c0e629 | 2014-06-02 07:38:14 -0700 | [diff] [blame] | 79 | |
| 80 | if (!this->caps()->npotTextureTileSupport() && |
tfarina | f9dae78 | 2014-06-06 06:35:28 -0700 | [diff] [blame] | 81 | (!SkIsPow2(desc.fWidth) || !SkIsPow2(desc.fHeight))) { |
bsalomon@google.com | 81c3f8d | 2011-08-03 15:18:33 +0000 | [diff] [blame] | 82 | return NULL; |
| 83 | } |
tfarina | f9dae78 | 2014-06-06 06:35:28 -0700 | [diff] [blame] | 84 | |
krajcevski | 9c0e629 | 2014-06-02 07:38:14 -0700 | [diff] [blame] | 85 | this->handleDirtyContext(); |
| 86 | tex = this->onCreateCompressedTexture(desc, srcData); |
| 87 | } else { |
| 88 | this->handleDirtyContext(); |
| 89 | tex = this->onCreateTexture(desc, srcData, rowBytes); |
bsalomon | 49f085d | 2014-09-05 13:34:00 -0700 | [diff] [blame] | 90 | if (tex && |
bsalomon | f2703d8 | 2014-10-28 14:33:06 -0700 | [diff] [blame] | 91 | (kRenderTarget_GrSurfaceFlag & desc.fFlags) && |
| 92 | !(kNoStencil_GrSurfaceFlag & desc.fFlags)) { |
bsalomon | 49f085d | 2014-09-05 13:34:00 -0700 | [diff] [blame] | 93 | SkASSERT(tex->asRenderTarget()); |
krajcevski | 9c0e629 | 2014-06-02 07:38:14 -0700 | [diff] [blame] | 94 | // TODO: defer this and attach dynamically |
| 95 | if (!this->attachStencilBufferToRenderTarget(tex->asRenderTarget())) { |
| 96 | tex->unref(); |
| 97 | return NULL; |
| 98 | } |
| 99 | } |
bsalomon@google.com | 81c3f8d | 2011-08-03 15:18:33 +0000 | [diff] [blame] | 100 | } |
| 101 | return tex; |
| 102 | } |
| 103 | |
| 104 | bool GrGpu::attachStencilBufferToRenderTarget(GrRenderTarget* rt) { |
tfarina@chromium.org | f6de475 | 2013-08-17 00:02:59 +0000 | [diff] [blame] | 105 | SkASSERT(NULL == rt->getStencilBuffer()); |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 106 | GrStencilBuffer* sb = |
robertphillips@google.com | 9fbcad0 | 2012-09-09 14:44:15 +0000 | [diff] [blame] | 107 | this->getContext()->findStencilBuffer(rt->width(), |
| 108 | rt->height(), |
| 109 | rt->numSamples()); |
bsalomon | 49f085d | 2014-09-05 13:34:00 -0700 | [diff] [blame] | 110 | if (sb) { |
bsalomon@google.com | 558a75b | 2011-08-08 17:01:14 +0000 | [diff] [blame] | 111 | rt->setStencilBuffer(sb); |
| 112 | bool attached = this->attachStencilBufferToRenderTarget(sb, rt); |
| 113 | if (!attached) { |
| 114 | rt->setStencilBuffer(NULL); |
| 115 | } |
| 116 | return attached; |
| 117 | } |
bsalomon@google.com | 9962108 | 2011-11-15 16:47:16 +0000 | [diff] [blame] | 118 | if (this->createStencilBufferForRenderTarget(rt, |
| 119 | rt->width(), rt->height())) { |
bsalomon@google.com | edc177d | 2011-08-05 15:46:40 +0000 | [diff] [blame] | 120 | // Right now we're clearing the stencil buffer here after it is |
| 121 | // attached to an RT for the first time. When we start matching |
| 122 | // stencil buffers with smaller color targets this will no longer |
| 123 | // be correct because it won't be guaranteed to clear the entire |
| 124 | // sb. |
| 125 | // We used to clear down in the GL subclass using a special purpose |
| 126 | // FBO. But iOS doesn't allow a stencil-only FBO. It reports unsupported |
| 127 | // FBO status. |
bsalomon | b0bd4f6 | 2014-09-03 07:19:50 -0700 | [diff] [blame] | 128 | this->clearStencil(rt); |
bsalomon@google.com | 558a75b | 2011-08-08 17:01:14 +0000 | [diff] [blame] | 129 | return true; |
| 130 | } else { |
| 131 | return false; |
bsalomon@google.com | edc177d | 2011-08-05 15:46:40 +0000 | [diff] [blame] | 132 | } |
bsalomon@google.com | a7f84e1 | 2011-03-10 14:13:19 +0000 | [diff] [blame] | 133 | } |
| 134 | |
bsalomon@google.com | 16e3dde | 2012-10-25 18:43:28 +0000 | [diff] [blame] | 135 | GrTexture* GrGpu::wrapBackendTexture(const GrBackendTextureDesc& desc) { |
bsalomon@google.com | e269f21 | 2011-11-07 13:29:52 +0000 | [diff] [blame] | 136 | this->handleDirtyContext(); |
bsalomon@google.com | 16e3dde | 2012-10-25 18:43:28 +0000 | [diff] [blame] | 137 | GrTexture* tex = this->onWrapBackendTexture(desc); |
bsalomon@google.com | a14dd6d | 2012-01-03 21:08:12 +0000 | [diff] [blame] | 138 | if (NULL == tex) { |
| 139 | return NULL; |
| 140 | } |
bsalomon@google.com | e269f21 | 2011-11-07 13:29:52 +0000 | [diff] [blame] | 141 | // TODO: defer this and attach dynamically |
| 142 | GrRenderTarget* tgt = tex->asRenderTarget(); |
bsalomon | 49f085d | 2014-09-05 13:34:00 -0700 | [diff] [blame] | 143 | if (tgt && |
bsalomon@google.com | e269f21 | 2011-11-07 13:29:52 +0000 | [diff] [blame] | 144 | !this->attachStencilBufferToRenderTarget(tgt)) { |
| 145 | tex->unref(); |
| 146 | return NULL; |
| 147 | } else { |
| 148 | return tex; |
| 149 | } |
| 150 | } |
| 151 | |
bsalomon@google.com | 16e3dde | 2012-10-25 18:43:28 +0000 | [diff] [blame] | 152 | GrRenderTarget* GrGpu::wrapBackendRenderTarget(const GrBackendRenderTargetDesc& desc) { |
bsalomon@google.com | e269f21 | 2011-11-07 13:29:52 +0000 | [diff] [blame] | 153 | this->handleDirtyContext(); |
bsalomon@google.com | 16e3dde | 2012-10-25 18:43:28 +0000 | [diff] [blame] | 154 | return this->onWrapBackendRenderTarget(desc); |
bsalomon@google.com | e269f21 | 2011-11-07 13:29:52 +0000 | [diff] [blame] | 155 | } |
| 156 | |
robertphillips@google.com | adacc70 | 2013-10-14 21:53:24 +0000 | [diff] [blame] | 157 | GrVertexBuffer* GrGpu::createVertexBuffer(size_t size, bool dynamic) { |
bsalomon@google.com | a7f84e1 | 2011-03-10 14:13:19 +0000 | [diff] [blame] | 158 | this->handleDirtyContext(); |
bsalomon@google.com | bcdbbe6 | 2011-04-12 15:40:00 +0000 | [diff] [blame] | 159 | return this->onCreateVertexBuffer(size, dynamic); |
bsalomon@google.com | a7f84e1 | 2011-03-10 14:13:19 +0000 | [diff] [blame] | 160 | } |
| 161 | |
robertphillips@google.com | adacc70 | 2013-10-14 21:53:24 +0000 | [diff] [blame] | 162 | GrIndexBuffer* GrGpu::createIndexBuffer(size_t size, bool dynamic) { |
bsalomon@google.com | a7f84e1 | 2011-03-10 14:13:19 +0000 | [diff] [blame] | 163 | this->handleDirtyContext(); |
bsalomon@google.com | bcdbbe6 | 2011-04-12 15:40:00 +0000 | [diff] [blame] | 164 | return this->onCreateIndexBuffer(size, dynamic); |
bsalomon@google.com | a7f84e1 | 2011-03-10 14:13:19 +0000 | [diff] [blame] | 165 | } |
| 166 | |
joshualitt | 5ead6da | 2014-10-22 16:00:29 -0700 | [diff] [blame] | 167 | GrIndexBuffer* GrGpu::createInstancedIndexBuffer(const uint16_t* pattern, |
| 168 | int patternSize, |
| 169 | int reps, |
| 170 | int vertCount, |
| 171 | bool isDynamic) { |
| 172 | size_t bufferSize = patternSize * reps * sizeof(uint16_t); |
| 173 | GrGpu* me = const_cast<GrGpu*>(this); |
| 174 | GrIndexBuffer* buffer = me->createIndexBuffer(bufferSize, isDynamic); |
| 175 | if (buffer) { |
| 176 | uint16_t* data = (uint16_t*) buffer->map(); |
| 177 | bool useTempData = (NULL == data); |
| 178 | if (useTempData) { |
| 179 | data = SkNEW_ARRAY(uint16_t, reps * patternSize); |
| 180 | } |
| 181 | for (int i = 0; i < reps; ++i) { |
| 182 | int baseIdx = i * patternSize; |
| 183 | uint16_t baseVert = (uint16_t)(i * vertCount); |
| 184 | for (int j = 0; j < patternSize; ++j) { |
| 185 | data[baseIdx+j] = baseVert + pattern[j]; |
| 186 | } |
| 187 | } |
| 188 | if (useTempData) { |
| 189 | if (!buffer->updateData(data, bufferSize)) { |
| 190 | SkFAIL("Can't get indices into buffer!"); |
| 191 | } |
| 192 | SkDELETE_ARRAY(data); |
| 193 | } else { |
| 194 | buffer->unmap(); |
| 195 | } |
| 196 | } |
| 197 | return buffer; |
| 198 | } |
| 199 | |
commit-bot@chromium.org | fd03d4a | 2013-07-17 21:39:42 +0000 | [diff] [blame] | 200 | void GrGpu::clear(const SkIRect* rect, |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 201 | GrColor color, |
robertphillips@google.com | 56ce48a | 2013-10-31 21:44:25 +0000 | [diff] [blame] | 202 | bool canIgnoreRect, |
robertphillips@google.com | c82a8b7 | 2012-06-21 20:15:48 +0000 | [diff] [blame] | 203 | GrRenderTarget* renderTarget) { |
bsalomon | b0bd4f6 | 2014-09-03 07:19:50 -0700 | [diff] [blame] | 204 | if (NULL == renderTarget) { |
| 205 | renderTarget = this->getDrawState().getRenderTarget(); |
robertphillips@google.com | c82a8b7 | 2012-06-21 20:15:48 +0000 | [diff] [blame] | 206 | } |
bsalomon | b0bd4f6 | 2014-09-03 07:19:50 -0700 | [diff] [blame] | 207 | if (NULL == renderTarget) { |
tfarina@chromium.org | f6de475 | 2013-08-17 00:02:59 +0000 | [diff] [blame] | 208 | SkASSERT(0); |
bsalomon@google.com | 0ba52fc | 2011-11-10 22:16:06 +0000 | [diff] [blame] | 209 | return; |
| 210 | } |
bsalomon@google.com | a7f84e1 | 2011-03-10 14:13:19 +0000 | [diff] [blame] | 211 | this->handleDirtyContext(); |
bsalomon | b0bd4f6 | 2014-09-03 07:19:50 -0700 | [diff] [blame] | 212 | this->onClear(renderTarget, rect, color, canIgnoreRect); |
bsalomon@google.com | a7f84e1 | 2011-03-10 14:13:19 +0000 | [diff] [blame] | 213 | } |
| 214 | |
joshualitt | 6db519c | 2014-10-29 08:48:18 -0700 | [diff] [blame] | 215 | void GrGpu::clearStencilClip(const SkIRect& rect, |
| 216 | bool insideClip, |
| 217 | GrRenderTarget* renderTarget) { |
| 218 | if (NULL == renderTarget) { |
| 219 | renderTarget = this->getDrawState().getRenderTarget(); |
| 220 | } |
| 221 | if (NULL == renderTarget) { |
| 222 | SkASSERT(0); |
| 223 | return; |
| 224 | } |
| 225 | this->handleDirtyContext(); |
| 226 | this->onClearStencilClip(renderTarget, rect, insideClip); |
| 227 | } |
| 228 | |
bsalomon@google.com | 669fdc4 | 2011-04-05 17:08:27 +0000 | [diff] [blame] | 229 | bool GrGpu::readPixels(GrRenderTarget* target, |
| 230 | int left, int top, int width, int height, |
bsalomon@google.com | c698097 | 2011-11-02 19:57:21 +0000 | [diff] [blame] | 231 | GrPixelConfig config, void* buffer, |
senorblanco@chromium.org | 3cb406b | 2013-02-05 19:50:46 +0000 | [diff] [blame] | 232 | size_t rowBytes) { |
bsalomon@google.com | a7f84e1 | 2011-03-10 14:13:19 +0000 | [diff] [blame] | 233 | this->handleDirtyContext(); |
bsalomon@google.com | c698097 | 2011-11-02 19:57:21 +0000 | [diff] [blame] | 234 | return this->onReadPixels(target, left, top, width, height, |
senorblanco@chromium.org | 3cb406b | 2013-02-05 19:50:46 +0000 | [diff] [blame] | 235 | config, buffer, rowBytes); |
bsalomon@google.com | a7f84e1 | 2011-03-10 14:13:19 +0000 | [diff] [blame] | 236 | } |
| 237 | |
bsalomon@google.com | 9c68058 | 2013-02-06 18:17:50 +0000 | [diff] [blame] | 238 | bool GrGpu::writeTexturePixels(GrTexture* texture, |
bsalomon@google.com | 6f37951 | 2011-11-16 20:36:03 +0000 | [diff] [blame] | 239 | int left, int top, int width, int height, |
| 240 | GrPixelConfig config, const void* buffer, |
| 241 | size_t rowBytes) { |
bsalomon@google.com | 6f37951 | 2011-11-16 20:36:03 +0000 | [diff] [blame] | 242 | this->handleDirtyContext(); |
bsalomon@google.com | 9c68058 | 2013-02-06 18:17:50 +0000 | [diff] [blame] | 243 | return this->onWriteTexturePixels(texture, left, top, width, height, |
| 244 | config, buffer, rowBytes); |
bsalomon@google.com | 6f37951 | 2011-11-16 20:36:03 +0000 | [diff] [blame] | 245 | } |
| 246 | |
bsalomon@google.com | 75f9f25 | 2012-01-31 13:35:56 +0000 | [diff] [blame] | 247 | void GrGpu::resolveRenderTarget(GrRenderTarget* target) { |
tfarina@chromium.org | f6de475 | 2013-08-17 00:02:59 +0000 | [diff] [blame] | 248 | SkASSERT(target); |
bsalomon@google.com | 75f9f25 | 2012-01-31 13:35:56 +0000 | [diff] [blame] | 249 | this->handleDirtyContext(); |
| 250 | this->onResolveRenderTarget(target); |
| 251 | } |
| 252 | |
commit-bot@chromium.org | c4dc0ad | 2013-10-09 14:11:33 +0000 | [diff] [blame] | 253 | static const GrStencilSettings& winding_path_stencil_settings() { |
| 254 | GR_STATIC_CONST_SAME_STENCIL_STRUCT(gSettings, |
| 255 | kIncClamp_StencilOp, |
| 256 | kIncClamp_StencilOp, |
| 257 | kAlwaysIfInClip_StencilFunc, |
| 258 | 0xFFFF, 0xFFFF, 0xFFFF); |
| 259 | return *GR_CONST_STENCIL_SETTINGS_PTR_FROM_STRUCT_PTR(&gSettings); |
| 260 | } |
| 261 | |
| 262 | static const GrStencilSettings& even_odd_path_stencil_settings() { |
| 263 | GR_STATIC_CONST_SAME_STENCIL_STRUCT(gSettings, |
| 264 | kInvert_StencilOp, |
| 265 | kInvert_StencilOp, |
| 266 | kAlwaysIfInClip_StencilFunc, |
| 267 | 0xFFFF, 0xFFFF, 0xFFFF); |
| 268 | return *GR_CONST_STENCIL_SETTINGS_PTR_FROM_STRUCT_PTR(&gSettings); |
| 269 | } |
| 270 | |
| 271 | void GrGpu::getPathStencilSettingsForFillType(SkPath::FillType fill, GrStencilSettings* outStencilSettings) { |
| 272 | |
| 273 | switch (fill) { |
| 274 | default: |
commit-bot@chromium.org | 88cb22b | 2014-04-30 14:17:00 +0000 | [diff] [blame] | 275 | SkFAIL("Unexpected path fill."); |
commit-bot@chromium.org | c4dc0ad | 2013-10-09 14:11:33 +0000 | [diff] [blame] | 276 | /* fallthrough */; |
| 277 | case SkPath::kWinding_FillType: |
| 278 | case SkPath::kInverseWinding_FillType: |
| 279 | *outStencilSettings = winding_path_stencil_settings(); |
| 280 | break; |
| 281 | case SkPath::kEvenOdd_FillType: |
| 282 | case SkPath::kInverseEvenOdd_FillType: |
| 283 | *outStencilSettings = even_odd_path_stencil_settings(); |
| 284 | break; |
| 285 | } |
| 286 | fClipMaskManager.adjustPathStencilParams(outStencilSettings); |
| 287 | } |
| 288 | |
bsalomon@google.com | 75f9f25 | 2012-01-31 13:35:56 +0000 | [diff] [blame] | 289 | |
bsalomon@google.com | a7f84e1 | 2011-03-10 14:13:19 +0000 | [diff] [blame] | 290 | //////////////////////////////////////////////////////////////////////////////// |
| 291 | |
bsalomon@google.com | 1c13c96 | 2011-02-14 16:51:21 +0000 | [diff] [blame] | 292 | 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] | 293 | |
reed@google.com | 8195f67 | 2011-01-12 18:14:28 +0000 | [diff] [blame] | 294 | GR_STATIC_ASSERT(4 * MAX_QUADS <= 65535); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 295 | |
joshualitt | 5ead6da | 2014-10-22 16:00:29 -0700 | [diff] [blame] | 296 | static const uint16_t gQuadIndexPattern[] = { |
| 297 | 0, 1, 2, 0, 2, 3 |
| 298 | }; |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 299 | |
bsalomon@google.com | 86afc2a | 2011-02-16 16:12:19 +0000 | [diff] [blame] | 300 | const GrIndexBuffer* GrGpu::getQuadIndexBuffer() const { |
bsalomon | c8dc1f7 | 2014-08-21 13:02:13 -0700 | [diff] [blame] | 301 | if (NULL == fQuadIndexBuffer || fQuadIndexBuffer->wasDestroyed()) { |
| 302 | SkSafeUnref(fQuadIndexBuffer); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 303 | GrGpu* me = const_cast<GrGpu*>(this); |
joshualitt | 5ead6da | 2014-10-22 16:00:29 -0700 | [diff] [blame] | 304 | fQuadIndexBuffer = me->createInstancedIndexBuffer(gQuadIndexPattern, |
| 305 | 6, |
| 306 | MAX_QUADS, |
| 307 | 4); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 308 | } |
| 309 | |
| 310 | return fQuadIndexBuffer; |
| 311 | } |
| 312 | |
bsalomon@google.com | d302f14 | 2011-03-03 13:54:13 +0000 | [diff] [blame] | 313 | //////////////////////////////////////////////////////////////////////////////// |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 314 | |
joshualitt | a58fe35 | 2014-10-27 08:39:00 -0700 | [diff] [blame] | 315 | bool GrGpu::setupClipAndFlushState(DrawType type, |
| 316 | const GrDeviceCoordTexture* dstCopy, |
joshualitt | 77b1307 | 2014-10-27 14:51:01 -0700 | [diff] [blame] | 317 | const SkRect* devBounds, |
| 318 | GrDrawState::AutoRestoreEffects* are) { |
joshualitt | 6db519c | 2014-10-29 08:48:18 -0700 | [diff] [blame] | 319 | GrClipMaskManager::ScissorState scissorState; |
joshualitt | 77b1307 | 2014-10-27 14:51:01 -0700 | [diff] [blame] | 320 | GrDrawState::AutoRestoreStencil ars; |
| 321 | if (!fClipMaskManager.setupClipping(this->getClip(), |
| 322 | devBounds, |
| 323 | are, |
| 324 | &ars, |
| 325 | &scissorState)) { |
robertphillips@google.com | 730ebe5 | 2012-04-16 16:33:13 +0000 | [diff] [blame] | 326 | return false; |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 327 | } |
bsalomon@google.com | d302f14 | 2011-03-03 13:54:13 +0000 | [diff] [blame] | 328 | |
joshualitt | 77b1307 | 2014-10-27 14:51:01 -0700 | [diff] [blame] | 329 | if (!this->flushGraphicsState(type, scissorState, dstCopy)) { |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 330 | return false; |
| 331 | } |
robertphillips@google.com | 730ebe5 | 2012-04-16 16:33:13 +0000 | [diff] [blame] | 332 | |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 333 | return true; |
| 334 | } |
| 335 | |
bsalomon@google.com | d302f14 | 2011-03-03 13:54:13 +0000 | [diff] [blame] | 336 | //////////////////////////////////////////////////////////////////////////////// |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 337 | |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 338 | void GrGpu::geometrySourceWillPush() { |
| 339 | const GeometrySrcState& geoSrc = this->getGeomSrc(); |
| 340 | if (kArray_GeometrySrcType == geoSrc.fVertexSrc || |
| 341 | kReserved_GeometrySrcType == geoSrc.fVertexSrc) { |
| 342 | this->finalizeReservedVertices(); |
| 343 | } |
| 344 | if (kArray_GeometrySrcType == geoSrc.fIndexSrc || |
| 345 | kReserved_GeometrySrcType == geoSrc.fIndexSrc) { |
| 346 | this->finalizeReservedIndices(); |
| 347 | } |
| 348 | GeometryPoolState& newState = fGeomPoolStateStack.push_back(); |
commit-bot@chromium.org | 515dcd3 | 2013-08-28 14:17:03 +0000 | [diff] [blame] | 349 | #ifdef SK_DEBUG |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 350 | newState.fPoolVertexBuffer = (GrVertexBuffer*)DEBUG_INVAL_BUFFER; |
| 351 | newState.fPoolStartVertex = DEBUG_INVAL_START_IDX; |
| 352 | newState.fPoolIndexBuffer = (GrIndexBuffer*)DEBUG_INVAL_BUFFER; |
| 353 | newState.fPoolStartIndex = DEBUG_INVAL_START_IDX; |
humper@google.com | 0e51577 | 2013-01-07 19:54:40 +0000 | [diff] [blame] | 354 | #else |
| 355 | (void) newState; // silence compiler warning |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 356 | #endif |
| 357 | } |
| 358 | |
| 359 | void GrGpu::geometrySourceWillPop(const GeometrySrcState& restoredState) { |
| 360 | // if popping last entry then pops are unbalanced with pushes |
tfarina@chromium.org | f6de475 | 2013-08-17 00:02:59 +0000 | [diff] [blame] | 361 | SkASSERT(fGeomPoolStateStack.count() > 1); |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 362 | fGeomPoolStateStack.pop_back(); |
| 363 | } |
| 364 | |
bsalomon@google.com | 74749cd | 2013-01-30 16:12:41 +0000 | [diff] [blame] | 365 | void GrGpu::onDraw(const DrawInfo& info) { |
bsalomon@google.com | a7f84e1 | 2011-03-10 14:13:19 +0000 | [diff] [blame] | 366 | this->handleDirtyContext(); |
bsalomon@google.com | eb6879f | 2013-06-13 19:34:18 +0000 | [diff] [blame] | 367 | GrDrawState::AutoRestoreEffects are; |
bsalomon@google.com | 26e18b5 | 2013-03-29 19:22:36 +0000 | [diff] [blame] | 368 | if (!this->setupClipAndFlushState(PrimTypeToDrawType(info.primitiveType()), |
joshualitt | 77b1307 | 2014-10-27 14:51:01 -0700 | [diff] [blame] | 369 | info.getDstCopy(), |
| 370 | info.getDevBounds(), |
| 371 | &are)) { |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 372 | return; |
| 373 | } |
bsalomon@google.com | 74749cd | 2013-01-30 16:12:41 +0000 | [diff] [blame] | 374 | this->onGpuDraw(info); |
bsalomon@google.com | 1c13c96 | 2011-02-14 16:51:21 +0000 | [diff] [blame] | 375 | } |
| 376 | |
commit-bot@chromium.org | 32184d8 | 2013-10-09 15:14:18 +0000 | [diff] [blame] | 377 | void GrGpu::onStencilPath(const GrPath* path, SkPath::FillType fill) { |
bsalomon@google.com | 64aef2b | 2012-06-11 15:36:13 +0000 | [diff] [blame] | 378 | this->handleDirtyContext(); |
| 379 | |
bsalomon@google.com | eb6879f | 2013-06-13 19:34:18 +0000 | [diff] [blame] | 380 | GrDrawState::AutoRestoreEffects are; |
joshualitt | 77b1307 | 2014-10-27 14:51:01 -0700 | [diff] [blame] | 381 | if (!this->setupClipAndFlushState(kStencilPath_DrawType, NULL, NULL, &are)) { |
bsalomon@google.com | 64aef2b | 2012-06-11 15:36:13 +0000 | [diff] [blame] | 382 | return; |
| 383 | } |
| 384 | |
kkinnunen | ccdaa04 | 2014-08-20 01:36:23 -0700 | [diff] [blame] | 385 | this->pathRendering()->stencilPath(path, fill); |
bsalomon@google.com | 64aef2b | 2012-06-11 15:36:13 +0000 | [diff] [blame] | 386 | } |
| 387 | |
commit-bot@chromium.org | 32184d8 | 2013-10-09 15:14:18 +0000 | [diff] [blame] | 388 | |
| 389 | void GrGpu::onDrawPath(const GrPath* path, SkPath::FillType fill, |
commit-bot@chromium.org | c4dc0ad | 2013-10-09 14:11:33 +0000 | [diff] [blame] | 390 | const GrDeviceCoordTexture* dstCopy) { |
| 391 | this->handleDirtyContext(); |
| 392 | |
| 393 | drawState()->setDefaultVertexAttribs(); |
| 394 | |
| 395 | GrDrawState::AutoRestoreEffects are; |
joshualitt | 77b1307 | 2014-10-27 14:51:01 -0700 | [diff] [blame] | 396 | if (!this->setupClipAndFlushState(kDrawPath_DrawType, dstCopy, NULL, &are)) { |
commit-bot@chromium.org | c4dc0ad | 2013-10-09 14:11:33 +0000 | [diff] [blame] | 397 | return; |
| 398 | } |
| 399 | |
kkinnunen | ccdaa04 | 2014-08-20 01:36:23 -0700 | [diff] [blame] | 400 | this->pathRendering()->drawPath(path, fill); |
commit-bot@chromium.org | c4dc0ad | 2013-10-09 14:11:33 +0000 | [diff] [blame] | 401 | } |
| 402 | |
cdalton | b85a0aa | 2014-07-21 15:32:44 -0700 | [diff] [blame] | 403 | void GrGpu::onDrawPaths(const GrPathRange* pathRange, |
| 404 | const uint32_t indices[], int count, |
| 405 | const float transforms[], PathTransformType transformsType, |
| 406 | SkPath::FillType fill, const GrDeviceCoordTexture* dstCopy) { |
commit-bot@chromium.org | 9b62aa1 | 2014-03-25 11:59:40 +0000 | [diff] [blame] | 407 | this->handleDirtyContext(); |
| 408 | |
| 409 | drawState()->setDefaultVertexAttribs(); |
| 410 | |
| 411 | GrDrawState::AutoRestoreEffects are; |
joshualitt | 77b1307 | 2014-10-27 14:51:01 -0700 | [diff] [blame] | 412 | if (!this->setupClipAndFlushState(kDrawPaths_DrawType, dstCopy, NULL, &are)) { |
commit-bot@chromium.org | 9b62aa1 | 2014-03-25 11:59:40 +0000 | [diff] [blame] | 413 | return; |
| 414 | } |
| 415 | |
cdalton | 855d83f | 2014-09-18 13:51:53 -0700 | [diff] [blame] | 416 | pathRange->willDrawPaths(indices, count); |
kkinnunen | ccdaa04 | 2014-08-20 01:36:23 -0700 | [diff] [blame] | 417 | this->pathRendering()->drawPaths(pathRange, indices, count, transforms, transformsType, fill); |
commit-bot@chromium.org | 9b62aa1 | 2014-03-25 11:59:40 +0000 | [diff] [blame] | 418 | } |
| 419 | |
bsalomon@google.com | 1c13c96 | 2011-02-14 16:51:21 +0000 | [diff] [blame] | 420 | void GrGpu::finalizeReservedVertices() { |
bsalomon | 49f085d | 2014-09-05 13:34:00 -0700 | [diff] [blame] | 421 | SkASSERT(fVertexPool); |
commit-bot@chromium.org | 8341eb7 | 2014-05-07 20:51:05 +0000 | [diff] [blame] | 422 | fVertexPool->unmap(); |
bsalomon@google.com | 1c13c96 | 2011-02-14 16:51:21 +0000 | [diff] [blame] | 423 | } |
| 424 | |
| 425 | void GrGpu::finalizeReservedIndices() { |
bsalomon | 49f085d | 2014-09-05 13:34:00 -0700 | [diff] [blame] | 426 | SkASSERT(fIndexPool); |
commit-bot@chromium.org | 8341eb7 | 2014-05-07 20:51:05 +0000 | [diff] [blame] | 427 | fIndexPool->unmap(); |
bsalomon@google.com | 1c13c96 | 2011-02-14 16:51:21 +0000 | [diff] [blame] | 428 | } |
| 429 | |
| 430 | void GrGpu::prepareVertexPool() { |
| 431 | if (NULL == fVertexPool) { |
tfarina@chromium.org | f6de475 | 2013-08-17 00:02:59 +0000 | [diff] [blame] | 432 | SkASSERT(0 == fVertexPoolUseCnt); |
tomhudson@google.com | c377baf | 2012-07-09 20:17:56 +0000 | [diff] [blame] | 433 | fVertexPool = SkNEW_ARGS(GrVertexBufferAllocPool, (this, true, |
bsalomon@google.com | d302f14 | 2011-03-03 13:54:13 +0000 | [diff] [blame] | 434 | VERTEX_POOL_VB_SIZE, |
tomhudson@google.com | c377baf | 2012-07-09 20:17:56 +0000 | [diff] [blame] | 435 | VERTEX_POOL_VB_COUNT)); |
bsalomon@google.com | 11f0b51 | 2011-03-29 20:52:23 +0000 | [diff] [blame] | 436 | fVertexPool->releaseGpuRef(); |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 437 | } else if (!fVertexPoolUseCnt) { |
bsalomon@google.com | d302f14 | 2011-03-03 13:54:13 +0000 | [diff] [blame] | 438 | // the client doesn't have valid data in the pool |
bsalomon@google.com | 1c13c96 | 2011-02-14 16:51:21 +0000 | [diff] [blame] | 439 | fVertexPool->reset(); |
| 440 | } |
| 441 | } |
| 442 | |
| 443 | void GrGpu::prepareIndexPool() { |
senorblanco@chromium.org | 9d18b78 | 2011-03-28 20:47:09 +0000 | [diff] [blame] | 444 | if (NULL == fIndexPool) { |
tfarina@chromium.org | f6de475 | 2013-08-17 00:02:59 +0000 | [diff] [blame] | 445 | SkASSERT(0 == fIndexPoolUseCnt); |
tomhudson@google.com | c377baf | 2012-07-09 20:17:56 +0000 | [diff] [blame] | 446 | fIndexPool = SkNEW_ARGS(GrIndexBufferAllocPool, (this, true, |
bsalomon@google.com | 25fd36c | 2011-07-06 17:41:08 +0000 | [diff] [blame] | 447 | INDEX_POOL_IB_SIZE, |
tomhudson@google.com | c377baf | 2012-07-09 20:17:56 +0000 | [diff] [blame] | 448 | INDEX_POOL_IB_COUNT)); |
bsalomon@google.com | 11f0b51 | 2011-03-29 20:52:23 +0000 | [diff] [blame] | 449 | fIndexPool->releaseGpuRef(); |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 450 | } else if (!fIndexPoolUseCnt) { |
bsalomon@google.com | d302f14 | 2011-03-03 13:54:13 +0000 | [diff] [blame] | 451 | // the client doesn't have valid data in the pool |
bsalomon@google.com | 1c13c96 | 2011-02-14 16:51:21 +0000 | [diff] [blame] | 452 | fIndexPool->reset(); |
| 453 | } |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 454 | } |
| 455 | |
jvanverth@google.com | a633898 | 2013-01-31 21:34:25 +0000 | [diff] [blame] | 456 | bool GrGpu::onReserveVertexSpace(size_t vertexSize, |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 457 | int vertexCount, |
| 458 | void** vertices) { |
| 459 | GeometryPoolState& geomPoolState = fGeomPoolStateStack.back(); |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 460 | |
tfarina@chromium.org | f6de475 | 2013-08-17 00:02:59 +0000 | [diff] [blame] | 461 | SkASSERT(vertexCount > 0); |
bsalomon | 49f085d | 2014-09-05 13:34:00 -0700 | [diff] [blame] | 462 | SkASSERT(vertices); |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 463 | |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 464 | this->prepareVertexPool(); |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 465 | |
jvanverth@google.com | a633898 | 2013-01-31 21:34:25 +0000 | [diff] [blame] | 466 | *vertices = fVertexPool->makeSpace(vertexSize, |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 467 | vertexCount, |
| 468 | &geomPoolState.fPoolVertexBuffer, |
| 469 | &geomPoolState.fPoolStartVertex); |
| 470 | if (NULL == *vertices) { |
| 471 | return false; |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 472 | } |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 473 | ++fVertexPoolUseCnt; |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 474 | return true; |
| 475 | } |
| 476 | |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 477 | bool GrGpu::onReserveIndexSpace(int indexCount, void** indices) { |
| 478 | GeometryPoolState& geomPoolState = fGeomPoolStateStack.back(); |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 479 | |
tfarina@chromium.org | f6de475 | 2013-08-17 00:02:59 +0000 | [diff] [blame] | 480 | SkASSERT(indexCount > 0); |
bsalomon | 49f085d | 2014-09-05 13:34:00 -0700 | [diff] [blame] | 481 | SkASSERT(indices); |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 482 | |
| 483 | this->prepareIndexPool(); |
| 484 | |
| 485 | *indices = fIndexPool->makeSpace(indexCount, |
| 486 | &geomPoolState.fPoolIndexBuffer, |
| 487 | &geomPoolState.fPoolStartIndex); |
| 488 | if (NULL == *indices) { |
| 489 | return false; |
| 490 | } |
| 491 | ++fIndexPoolUseCnt; |
| 492 | return true; |
| 493 | } |
| 494 | |
| 495 | void GrGpu::releaseReservedVertexSpace() { |
| 496 | const GeometrySrcState& geoSrc = this->getGeomSrc(); |
tfarina@chromium.org | f6de475 | 2013-08-17 00:02:59 +0000 | [diff] [blame] | 497 | SkASSERT(kReserved_GeometrySrcType == geoSrc.fVertexSrc); |
jvanverth@google.com | b75b0a0 | 2013-02-05 20:33:30 +0000 | [diff] [blame] | 498 | size_t bytes = geoSrc.fVertexCount * geoSrc.fVertexSize; |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 499 | fVertexPool->putBack(bytes); |
| 500 | --fVertexPoolUseCnt; |
| 501 | } |
| 502 | |
| 503 | void GrGpu::releaseReservedIndexSpace() { |
| 504 | const GeometrySrcState& geoSrc = this->getGeomSrc(); |
tfarina@chromium.org | f6de475 | 2013-08-17 00:02:59 +0000 | [diff] [blame] | 505 | SkASSERT(kReserved_GeometrySrcType == geoSrc.fIndexSrc); |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 506 | size_t bytes = geoSrc.fIndexCount * sizeof(uint16_t); |
| 507 | fIndexPool->putBack(bytes); |
| 508 | --fIndexPoolUseCnt; |
| 509 | } |
bsalomon@google.com | 1c13c96 | 2011-02-14 16:51:21 +0000 | [diff] [blame] | 510 | |
bsalomon@google.com | bcdbbe6 | 2011-04-12 15:40:00 +0000 | [diff] [blame] | 511 | void GrGpu::onSetVertexSourceToArray(const void* vertexArray, int vertexCount) { |
bsalomon@google.com | bcdbbe6 | 2011-04-12 15:40:00 +0000 | [diff] [blame] | 512 | this->prepareVertexPool(); |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 513 | GeometryPoolState& geomPoolState = fGeomPoolStateStack.back(); |
commit-bot@chromium.org | 515dcd3 | 2013-08-28 14:17:03 +0000 | [diff] [blame] | 514 | #ifdef SK_DEBUG |
bsalomon@google.com | 1c13c96 | 2011-02-14 16:51:21 +0000 | [diff] [blame] | 515 | bool success = |
| 516 | #endif |
jvanverth@google.com | b75b0a0 | 2013-02-05 20:33:30 +0000 | [diff] [blame] | 517 | fVertexPool->appendVertices(this->getVertexSize(), |
bsalomon@google.com | 1c13c96 | 2011-02-14 16:51:21 +0000 | [diff] [blame] | 518 | vertexCount, |
| 519 | vertexArray, |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 520 | &geomPoolState.fPoolVertexBuffer, |
| 521 | &geomPoolState.fPoolStartVertex); |
| 522 | ++fVertexPoolUseCnt; |
bsalomon@google.com | 1c13c96 | 2011-02-14 16:51:21 +0000 | [diff] [blame] | 523 | GR_DEBUGASSERT(success); |
| 524 | } |
| 525 | |
bsalomon@google.com | bcdbbe6 | 2011-04-12 15:40:00 +0000 | [diff] [blame] | 526 | void GrGpu::onSetIndexSourceToArray(const void* indexArray, int indexCount) { |
bsalomon@google.com | bcdbbe6 | 2011-04-12 15:40:00 +0000 | [diff] [blame] | 527 | this->prepareIndexPool(); |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 528 | GeometryPoolState& geomPoolState = fGeomPoolStateStack.back(); |
commit-bot@chromium.org | 515dcd3 | 2013-08-28 14:17:03 +0000 | [diff] [blame] | 529 | #ifdef SK_DEBUG |
bsalomon@google.com | 1c13c96 | 2011-02-14 16:51:21 +0000 | [diff] [blame] | 530 | bool success = |
| 531 | #endif |
| 532 | fIndexPool->appendIndices(indexCount, |
| 533 | indexArray, |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 534 | &geomPoolState.fPoolIndexBuffer, |
| 535 | &geomPoolState.fPoolStartIndex); |
| 536 | ++fIndexPoolUseCnt; |
bsalomon@google.com | 1c13c96 | 2011-02-14 16:51:21 +0000 | [diff] [blame] | 537 | GR_DEBUGASSERT(success); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 538 | } |
| 539 | |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 540 | void GrGpu::releaseVertexArray() { |
| 541 | // if vertex source was array, we stowed data in the pool |
| 542 | const GeometrySrcState& geoSrc = this->getGeomSrc(); |
tfarina@chromium.org | f6de475 | 2013-08-17 00:02:59 +0000 | [diff] [blame] | 543 | SkASSERT(kArray_GeometrySrcType == geoSrc.fVertexSrc); |
jvanverth@google.com | b75b0a0 | 2013-02-05 20:33:30 +0000 | [diff] [blame] | 544 | size_t bytes = geoSrc.fVertexCount * geoSrc.fVertexSize; |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 545 | fVertexPool->putBack(bytes); |
| 546 | --fVertexPoolUseCnt; |
| 547 | } |
| 548 | |
| 549 | void GrGpu::releaseIndexArray() { |
| 550 | // if index source was array, we stowed data in the pool |
| 551 | const GeometrySrcState& geoSrc = this->getGeomSrc(); |
tfarina@chromium.org | f6de475 | 2013-08-17 00:02:59 +0000 | [diff] [blame] | 552 | SkASSERT(kArray_GeometrySrcType == geoSrc.fIndexSrc); |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 553 | size_t bytes = geoSrc.fIndexCount * sizeof(uint16_t); |
| 554 | fIndexPool->putBack(bytes); |
| 555 | --fIndexPoolUseCnt; |
| 556 | } |