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