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