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