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