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 | |
bsalomon@google.com | d302f14 | 2011-03-03 13:54:13 +0000 | [diff] [blame] | 19 | //////////////////////////////////////////////////////////////////////////////// |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 20 | |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 21 | #define DEBUG_INVAL_BUFFER 0xdeadcafe |
| 22 | #define DEBUG_INVAL_START_IDX -1 |
| 23 | |
bsalomon@google.com | 6e4e650 | 2013-02-25 20:12:45 +0000 | [diff] [blame] | 24 | GrGpu::GrGpu(GrContext* context) |
joshualitt | 3322fa4 | 2014-11-07 08:48:51 -0800 | [diff] [blame] | 25 | : fResetTimestamp(kExpiredTimestamp+1) |
bsalomon@google.com | 0a208a1 | 2013-06-28 18:57:35 +0000 | [diff] [blame] | 26 | , fResetBits(kAll_GrBackendState) |
joshualitt | 3322fa4 | 2014-11-07 08:48:51 -0800 | [diff] [blame] | 27 | , fQuadIndexBuffer(NULL) |
| 28 | , fContext(context) { |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 29 | } |
| 30 | |
bsalomon | 1d89ddc | 2014-08-19 14:20:58 -0700 | [diff] [blame] | 31 | GrGpu::~GrGpu() { |
bsalomon | 1d89ddc | 2014-08-19 14:20:58 -0700 | [diff] [blame] | 32 | SkSafeSetNull(fQuadIndexBuffer); |
joshualitt | f4e5e33 | 2014-11-07 12:58:46 -0800 | [diff] [blame] | 33 | SkSafeUnref(fGeoSrcState.fVertexBuffer); |
| 34 | SkSafeUnref(fGeoSrcState.fIndexBuffer); |
bsalomon | 1d89ddc | 2014-08-19 14:20:58 -0700 | [diff] [blame] | 35 | } |
| 36 | |
robertphillips | e337130 | 2014-09-17 06:01:06 -0700 | [diff] [blame] | 37 | void GrGpu::contextAbandoned() {} |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 38 | |
bsalomon@google.com | d302f14 | 2011-03-03 13:54:13 +0000 | [diff] [blame] | 39 | //////////////////////////////////////////////////////////////////////////////// |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 40 | |
bsalomon | f2703d8 | 2014-10-28 14:33:06 -0700 | [diff] [blame] | 41 | GrTexture* GrGpu::createTexture(const GrSurfaceDesc& desc, |
bsalomon@google.com | a7f84e1 | 2011-03-10 14:13:19 +0000 | [diff] [blame] | 42 | const void* srcData, size_t rowBytes) { |
krajcevski | 9c0e629 | 2014-06-02 07:38:14 -0700 | [diff] [blame] | 43 | if (!this->caps()->isConfigTexturable(desc.fConfig)) { |
robertphillips@google.com | d3eb336 | 2012-10-31 13:56:35 +0000 | [diff] [blame] | 44 | return NULL; |
| 45 | } |
krajcevski | 9c0e629 | 2014-06-02 07:38:14 -0700 | [diff] [blame] | 46 | |
bsalomon | f2703d8 | 2014-10-28 14:33:06 -0700 | [diff] [blame] | 47 | if ((desc.fFlags & kRenderTarget_GrSurfaceFlag) && |
commit-bot@chromium.org | 6b7938f | 2013-10-15 14:18:16 +0000 | [diff] [blame] | 48 | !this->caps()->isConfigRenderable(desc.fConfig, desc.fSampleCnt > 0)) { |
| 49 | return NULL; |
| 50 | } |
robertphillips@google.com | d3eb336 | 2012-10-31 13:56:35 +0000 | [diff] [blame] | 51 | |
krajcevski | 9c0e629 | 2014-06-02 07:38:14 -0700 | [diff] [blame] | 52 | GrTexture *tex = NULL; |
| 53 | if (GrPixelConfigIsCompressed(desc.fConfig)) { |
| 54 | // We shouldn't be rendering into this |
bsalomon | f2703d8 | 2014-10-28 14:33:06 -0700 | [diff] [blame] | 55 | SkASSERT((desc.fFlags & kRenderTarget_GrSurfaceFlag) == 0); |
krajcevski | 9c0e629 | 2014-06-02 07:38:14 -0700 | [diff] [blame] | 56 | |
| 57 | if (!this->caps()->npotTextureTileSupport() && |
tfarina | f9dae78 | 2014-06-06 06:35:28 -0700 | [diff] [blame] | 58 | (!SkIsPow2(desc.fWidth) || !SkIsPow2(desc.fHeight))) { |
bsalomon@google.com | 81c3f8d | 2011-08-03 15:18:33 +0000 | [diff] [blame] | 59 | return NULL; |
| 60 | } |
tfarina | f9dae78 | 2014-06-06 06:35:28 -0700 | [diff] [blame] | 61 | |
krajcevski | 9c0e629 | 2014-06-02 07:38:14 -0700 | [diff] [blame] | 62 | this->handleDirtyContext(); |
| 63 | tex = this->onCreateCompressedTexture(desc, srcData); |
| 64 | } else { |
| 65 | this->handleDirtyContext(); |
| 66 | tex = this->onCreateTexture(desc, srcData, rowBytes); |
bsalomon | 49f085d | 2014-09-05 13:34:00 -0700 | [diff] [blame] | 67 | if (tex && |
bsalomon | f2703d8 | 2014-10-28 14:33:06 -0700 | [diff] [blame] | 68 | (kRenderTarget_GrSurfaceFlag & desc.fFlags) && |
| 69 | !(kNoStencil_GrSurfaceFlag & desc.fFlags)) { |
bsalomon | 49f085d | 2014-09-05 13:34:00 -0700 | [diff] [blame] | 70 | SkASSERT(tex->asRenderTarget()); |
krajcevski | 9c0e629 | 2014-06-02 07:38:14 -0700 | [diff] [blame] | 71 | // TODO: defer this and attach dynamically |
| 72 | if (!this->attachStencilBufferToRenderTarget(tex->asRenderTarget())) { |
| 73 | tex->unref(); |
| 74 | return NULL; |
| 75 | } |
| 76 | } |
bsalomon@google.com | 81c3f8d | 2011-08-03 15:18:33 +0000 | [diff] [blame] | 77 | } |
| 78 | return tex; |
| 79 | } |
| 80 | |
| 81 | bool GrGpu::attachStencilBufferToRenderTarget(GrRenderTarget* rt) { |
tfarina@chromium.org | f6de475 | 2013-08-17 00:02:59 +0000 | [diff] [blame] | 82 | SkASSERT(NULL == rt->getStencilBuffer()); |
bsalomon | 8b79d23 | 2014-11-10 10:19:06 -0800 | [diff] [blame] | 83 | SkAutoTUnref<GrStencilBuffer> sb( |
| 84 | this->getContext()->findAndRefStencilBuffer(rt->width(), rt->height(), rt->numSamples())); |
bsalomon | 49f085d | 2014-09-05 13:34:00 -0700 | [diff] [blame] | 85 | if (sb) { |
bsalomon@google.com | 558a75b | 2011-08-08 17:01:14 +0000 | [diff] [blame] | 86 | rt->setStencilBuffer(sb); |
| 87 | bool attached = this->attachStencilBufferToRenderTarget(sb, rt); |
| 88 | if (!attached) { |
| 89 | rt->setStencilBuffer(NULL); |
| 90 | } |
| 91 | return attached; |
| 92 | } |
bsalomon | 8b79d23 | 2014-11-10 10:19:06 -0800 | [diff] [blame] | 93 | if (this->createStencilBufferForRenderTarget(rt, rt->width(), rt->height())) { |
bsalomon@google.com | edc177d | 2011-08-05 15:46:40 +0000 | [diff] [blame] | 94 | // Right now we're clearing the stencil buffer here after it is |
| 95 | // attached to an RT for the first time. When we start matching |
| 96 | // stencil buffers with smaller color targets this will no longer |
| 97 | // be correct because it won't be guaranteed to clear the entire |
| 98 | // sb. |
| 99 | // We used to clear down in the GL subclass using a special purpose |
| 100 | // FBO. But iOS doesn't allow a stencil-only FBO. It reports unsupported |
| 101 | // FBO status. |
bsalomon | b0bd4f6 | 2014-09-03 07:19:50 -0700 | [diff] [blame] | 102 | this->clearStencil(rt); |
bsalomon@google.com | 558a75b | 2011-08-08 17:01:14 +0000 | [diff] [blame] | 103 | return true; |
| 104 | } else { |
| 105 | return false; |
bsalomon@google.com | edc177d | 2011-08-05 15:46:40 +0000 | [diff] [blame] | 106 | } |
bsalomon@google.com | a7f84e1 | 2011-03-10 14:13:19 +0000 | [diff] [blame] | 107 | } |
| 108 | |
bsalomon@google.com | 16e3dde | 2012-10-25 18:43:28 +0000 | [diff] [blame] | 109 | GrTexture* GrGpu::wrapBackendTexture(const GrBackendTextureDesc& desc) { |
bsalomon@google.com | e269f21 | 2011-11-07 13:29:52 +0000 | [diff] [blame] | 110 | this->handleDirtyContext(); |
bsalomon@google.com | 16e3dde | 2012-10-25 18:43:28 +0000 | [diff] [blame] | 111 | GrTexture* tex = this->onWrapBackendTexture(desc); |
bsalomon@google.com | a14dd6d | 2012-01-03 21:08:12 +0000 | [diff] [blame] | 112 | if (NULL == tex) { |
| 113 | return NULL; |
| 114 | } |
bsalomon@google.com | e269f21 | 2011-11-07 13:29:52 +0000 | [diff] [blame] | 115 | // TODO: defer this and attach dynamically |
| 116 | GrRenderTarget* tgt = tex->asRenderTarget(); |
bsalomon | 49f085d | 2014-09-05 13:34:00 -0700 | [diff] [blame] | 117 | if (tgt && |
bsalomon@google.com | e269f21 | 2011-11-07 13:29:52 +0000 | [diff] [blame] | 118 | !this->attachStencilBufferToRenderTarget(tgt)) { |
| 119 | tex->unref(); |
| 120 | return NULL; |
| 121 | } else { |
| 122 | return tex; |
| 123 | } |
| 124 | } |
| 125 | |
bsalomon@google.com | 16e3dde | 2012-10-25 18:43:28 +0000 | [diff] [blame] | 126 | GrRenderTarget* GrGpu::wrapBackendRenderTarget(const GrBackendRenderTargetDesc& desc) { |
bsalomon@google.com | e269f21 | 2011-11-07 13:29:52 +0000 | [diff] [blame] | 127 | this->handleDirtyContext(); |
bsalomon@google.com | 16e3dde | 2012-10-25 18:43:28 +0000 | [diff] [blame] | 128 | return this->onWrapBackendRenderTarget(desc); |
bsalomon@google.com | e269f21 | 2011-11-07 13:29:52 +0000 | [diff] [blame] | 129 | } |
| 130 | |
robertphillips@google.com | adacc70 | 2013-10-14 21:53:24 +0000 | [diff] [blame] | 131 | GrVertexBuffer* GrGpu::createVertexBuffer(size_t size, bool dynamic) { |
bsalomon@google.com | a7f84e1 | 2011-03-10 14:13:19 +0000 | [diff] [blame] | 132 | this->handleDirtyContext(); |
bsalomon@google.com | bcdbbe6 | 2011-04-12 15:40:00 +0000 | [diff] [blame] | 133 | return this->onCreateVertexBuffer(size, dynamic); |
bsalomon@google.com | a7f84e1 | 2011-03-10 14:13:19 +0000 | [diff] [blame] | 134 | } |
| 135 | |
robertphillips@google.com | adacc70 | 2013-10-14 21:53:24 +0000 | [diff] [blame] | 136 | GrIndexBuffer* GrGpu::createIndexBuffer(size_t size, bool dynamic) { |
bsalomon@google.com | a7f84e1 | 2011-03-10 14:13:19 +0000 | [diff] [blame] | 137 | this->handleDirtyContext(); |
bsalomon@google.com | bcdbbe6 | 2011-04-12 15:40:00 +0000 | [diff] [blame] | 138 | return this->onCreateIndexBuffer(size, dynamic); |
bsalomon@google.com | a7f84e1 | 2011-03-10 14:13:19 +0000 | [diff] [blame] | 139 | } |
| 140 | |
joshualitt | 5ead6da | 2014-10-22 16:00:29 -0700 | [diff] [blame] | 141 | GrIndexBuffer* GrGpu::createInstancedIndexBuffer(const uint16_t* pattern, |
| 142 | int patternSize, |
| 143 | int reps, |
| 144 | int vertCount, |
| 145 | bool isDynamic) { |
| 146 | size_t bufferSize = patternSize * reps * sizeof(uint16_t); |
| 147 | GrGpu* me = const_cast<GrGpu*>(this); |
| 148 | GrIndexBuffer* buffer = me->createIndexBuffer(bufferSize, isDynamic); |
| 149 | if (buffer) { |
| 150 | uint16_t* data = (uint16_t*) buffer->map(); |
| 151 | bool useTempData = (NULL == data); |
| 152 | if (useTempData) { |
| 153 | data = SkNEW_ARRAY(uint16_t, reps * patternSize); |
| 154 | } |
| 155 | for (int i = 0; i < reps; ++i) { |
| 156 | int baseIdx = i * patternSize; |
| 157 | uint16_t baseVert = (uint16_t)(i * vertCount); |
| 158 | for (int j = 0; j < patternSize; ++j) { |
| 159 | data[baseIdx+j] = baseVert + pattern[j]; |
| 160 | } |
| 161 | } |
| 162 | if (useTempData) { |
| 163 | if (!buffer->updateData(data, bufferSize)) { |
| 164 | SkFAIL("Can't get indices into buffer!"); |
| 165 | } |
| 166 | SkDELETE_ARRAY(data); |
| 167 | } else { |
| 168 | buffer->unmap(); |
| 169 | } |
| 170 | } |
| 171 | return buffer; |
| 172 | } |
| 173 | |
joshualitt | 3322fa4 | 2014-11-07 08:48:51 -0800 | [diff] [blame] | 174 | void GrGpu::clear(const SkIRect* rect, |
| 175 | GrColor color, |
| 176 | bool canIgnoreRect, |
| 177 | GrRenderTarget* renderTarget) { |
bsalomon | 89c6298 | 2014-11-03 12:08:42 -0800 | [diff] [blame] | 178 | SkASSERT(renderTarget); |
bsalomon@google.com | a7f84e1 | 2011-03-10 14:13:19 +0000 | [diff] [blame] | 179 | this->handleDirtyContext(); |
joshualitt | 4b68ec0 | 2014-11-07 14:11:45 -0800 | [diff] [blame] | 180 | this->onClear(renderTarget, rect, color, canIgnoreRect); |
bsalomon@google.com | a7f84e1 | 2011-03-10 14:13:19 +0000 | [diff] [blame] | 181 | } |
| 182 | |
joshualitt | 6db519c | 2014-10-29 08:48:18 -0700 | [diff] [blame] | 183 | void GrGpu::clearStencilClip(const SkIRect& rect, |
| 184 | bool insideClip, |
| 185 | GrRenderTarget* renderTarget) { |
joshualitt | d53a827 | 2014-11-10 16:03:14 -0800 | [diff] [blame^] | 186 | SkASSERT(renderTarget); |
joshualitt | 6db519c | 2014-10-29 08:48:18 -0700 | [diff] [blame] | 187 | this->handleDirtyContext(); |
| 188 | this->onClearStencilClip(renderTarget, rect, insideClip); |
| 189 | } |
| 190 | |
bsalomon@google.com | 669fdc4 | 2011-04-05 17:08:27 +0000 | [diff] [blame] | 191 | bool GrGpu::readPixels(GrRenderTarget* target, |
| 192 | int left, int top, int width, int height, |
bsalomon@google.com | c698097 | 2011-11-02 19:57:21 +0000 | [diff] [blame] | 193 | GrPixelConfig config, void* buffer, |
senorblanco@chromium.org | 3cb406b | 2013-02-05 19:50:46 +0000 | [diff] [blame] | 194 | size_t rowBytes) { |
bsalomon@google.com | a7f84e1 | 2011-03-10 14:13:19 +0000 | [diff] [blame] | 195 | this->handleDirtyContext(); |
bsalomon@google.com | c698097 | 2011-11-02 19:57:21 +0000 | [diff] [blame] | 196 | return this->onReadPixels(target, left, top, width, height, |
senorblanco@chromium.org | 3cb406b | 2013-02-05 19:50:46 +0000 | [diff] [blame] | 197 | config, buffer, rowBytes); |
bsalomon@google.com | a7f84e1 | 2011-03-10 14:13:19 +0000 | [diff] [blame] | 198 | } |
| 199 | |
bsalomon@google.com | 9c68058 | 2013-02-06 18:17:50 +0000 | [diff] [blame] | 200 | bool GrGpu::writeTexturePixels(GrTexture* texture, |
bsalomon@google.com | 6f37951 | 2011-11-16 20:36:03 +0000 | [diff] [blame] | 201 | int left, int top, int width, int height, |
| 202 | GrPixelConfig config, const void* buffer, |
| 203 | size_t rowBytes) { |
bsalomon@google.com | 6f37951 | 2011-11-16 20:36:03 +0000 | [diff] [blame] | 204 | this->handleDirtyContext(); |
bsalomon@google.com | 9c68058 | 2013-02-06 18:17:50 +0000 | [diff] [blame] | 205 | return this->onWriteTexturePixels(texture, left, top, width, height, |
| 206 | config, buffer, rowBytes); |
bsalomon@google.com | 6f37951 | 2011-11-16 20:36:03 +0000 | [diff] [blame] | 207 | } |
| 208 | |
bsalomon@google.com | 75f9f25 | 2012-01-31 13:35:56 +0000 | [diff] [blame] | 209 | void GrGpu::resolveRenderTarget(GrRenderTarget* target) { |
tfarina@chromium.org | f6de475 | 2013-08-17 00:02:59 +0000 | [diff] [blame] | 210 | SkASSERT(target); |
bsalomon@google.com | 75f9f25 | 2012-01-31 13:35:56 +0000 | [diff] [blame] | 211 | this->handleDirtyContext(); |
| 212 | this->onResolveRenderTarget(target); |
| 213 | } |
| 214 | |
joshualitt | 3322fa4 | 2014-11-07 08:48:51 -0800 | [diff] [blame] | 215 | void GrGpu::initCopySurfaceDstDesc(const GrSurface* src, GrSurfaceDesc* desc) { |
| 216 | // Make the dst of the copy be a render target because the default copySurface draws to the dst. |
| 217 | desc->fOrigin = kDefault_GrSurfaceOrigin; |
| 218 | desc->fFlags = kRenderTarget_GrSurfaceFlag | kNoStencil_GrSurfaceFlag; |
| 219 | desc->fConfig = src->config(); |
| 220 | } |
| 221 | |
| 222 | typedef GrTraceMarkerSet::Iter TMIter; |
| 223 | void GrGpu::saveActiveTraceMarkers() { |
| 224 | if (this->caps()->gpuTracingSupport()) { |
| 225 | SkASSERT(0 == fStoredTraceMarkers.count()); |
| 226 | fStoredTraceMarkers.addSet(fActiveTraceMarkers); |
| 227 | for (TMIter iter = fStoredTraceMarkers.begin(); iter != fStoredTraceMarkers.end(); ++iter) { |
| 228 | this->removeGpuTraceMarker(&(*iter)); |
| 229 | } |
| 230 | } |
| 231 | } |
| 232 | |
| 233 | void GrGpu::restoreActiveTraceMarkers() { |
| 234 | if (this->caps()->gpuTracingSupport()) { |
| 235 | SkASSERT(0 == fActiveTraceMarkers.count()); |
| 236 | for (TMIter iter = fStoredTraceMarkers.begin(); iter != fStoredTraceMarkers.end(); ++iter) { |
| 237 | this->addGpuTraceMarker(&(*iter)); |
| 238 | } |
| 239 | for (TMIter iter = fActiveTraceMarkers.begin(); iter != fActiveTraceMarkers.end(); ++iter) { |
| 240 | this->fStoredTraceMarkers.remove(*iter); |
| 241 | } |
| 242 | } |
| 243 | } |
| 244 | |
| 245 | void GrGpu::addGpuTraceMarker(const GrGpuTraceMarker* marker) { |
| 246 | if (this->caps()->gpuTracingSupport()) { |
| 247 | SkASSERT(fGpuTraceMarkerCount >= 0); |
| 248 | this->fActiveTraceMarkers.add(*marker); |
| 249 | this->didAddGpuTraceMarker(); |
| 250 | ++fGpuTraceMarkerCount; |
| 251 | } |
| 252 | } |
| 253 | |
| 254 | void GrGpu::removeGpuTraceMarker(const GrGpuTraceMarker* marker) { |
| 255 | if (this->caps()->gpuTracingSupport()) { |
| 256 | SkASSERT(fGpuTraceMarkerCount >= 1); |
| 257 | this->fActiveTraceMarkers.remove(*marker); |
| 258 | this->didRemoveGpuTraceMarker(); |
| 259 | --fGpuTraceMarkerCount; |
| 260 | } |
| 261 | } |
| 262 | |
joshualitt | d53a827 | 2014-11-10 16:03:14 -0800 | [diff] [blame^] | 263 | void GrGpu::setVertexSourceToBuffer(const GrVertexBuffer* buffer, size_t vertexStride) { |
joshualitt | f4e5e33 | 2014-11-07 12:58:46 -0800 | [diff] [blame] | 264 | SkSafeUnref(fGeoSrcState.fVertexBuffer); |
| 265 | fGeoSrcState.fVertexBuffer = buffer; |
joshualitt | 3322fa4 | 2014-11-07 08:48:51 -0800 | [diff] [blame] | 266 | buffer->ref(); |
joshualitt | d53a827 | 2014-11-10 16:03:14 -0800 | [diff] [blame^] | 267 | fGeoSrcState.fVertexSize = vertexStride; |
joshualitt | 3322fa4 | 2014-11-07 08:48:51 -0800 | [diff] [blame] | 268 | } |
| 269 | |
| 270 | void GrGpu::setIndexSourceToBuffer(const GrIndexBuffer* buffer) { |
joshualitt | f4e5e33 | 2014-11-07 12:58:46 -0800 | [diff] [blame] | 271 | SkSafeUnref(fGeoSrcState.fIndexBuffer); |
| 272 | fGeoSrcState.fIndexBuffer = buffer; |
joshualitt | 3322fa4 | 2014-11-07 08:48:51 -0800 | [diff] [blame] | 273 | buffer->ref(); |
| 274 | } |
| 275 | |
bsalomon@google.com | a7f84e1 | 2011-03-10 14:13:19 +0000 | [diff] [blame] | 276 | //////////////////////////////////////////////////////////////////////////////// |
| 277 | |
bsalomon@google.com | 1c13c96 | 2011-02-14 16:51:21 +0000 | [diff] [blame] | 278 | 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] | 279 | |
reed@google.com | 8195f67 | 2011-01-12 18:14:28 +0000 | [diff] [blame] | 280 | GR_STATIC_ASSERT(4 * MAX_QUADS <= 65535); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 281 | |
joshualitt | 5ead6da | 2014-10-22 16:00:29 -0700 | [diff] [blame] | 282 | static const uint16_t gQuadIndexPattern[] = { |
| 283 | 0, 1, 2, 0, 2, 3 |
| 284 | }; |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 285 | |
bsalomon@google.com | 86afc2a | 2011-02-16 16:12:19 +0000 | [diff] [blame] | 286 | const GrIndexBuffer* GrGpu::getQuadIndexBuffer() const { |
bsalomon | c8dc1f7 | 2014-08-21 13:02:13 -0700 | [diff] [blame] | 287 | if (NULL == fQuadIndexBuffer || fQuadIndexBuffer->wasDestroyed()) { |
| 288 | SkSafeUnref(fQuadIndexBuffer); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 289 | GrGpu* me = const_cast<GrGpu*>(this); |
joshualitt | 5ead6da | 2014-10-22 16:00:29 -0700 | [diff] [blame] | 290 | fQuadIndexBuffer = me->createInstancedIndexBuffer(gQuadIndexPattern, |
| 291 | 6, |
| 292 | MAX_QUADS, |
| 293 | 4); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 294 | } |
| 295 | |
| 296 | return fQuadIndexBuffer; |
| 297 | } |
| 298 | |
bsalomon@google.com | d302f14 | 2011-03-03 13:54:13 +0000 | [diff] [blame] | 299 | //////////////////////////////////////////////////////////////////////////////// |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 300 | |
joshualitt | d53a827 | 2014-11-10 16:03:14 -0800 | [diff] [blame^] | 301 | void GrGpu::draw(const GrOptDrawState& ds, |
| 302 | const GrDrawTarget::DrawInfo& info, |
| 303 | const GrClipMaskManager::ScissorState& scissorState) { |
bsalomon@google.com | a7f84e1 | 2011-03-10 14:13:19 +0000 | [diff] [blame] | 304 | this->handleDirtyContext(); |
joshualitt | d53a827 | 2014-11-10 16:03:14 -0800 | [diff] [blame^] | 305 | if (!this->flushGraphicsState(ds, |
| 306 | PrimTypeToDrawType(info.primitiveType()), |
joshualitt | 2c93efe | 2014-11-06 12:57:13 -0800 | [diff] [blame] | 307 | scissorState, |
| 308 | info.getDstCopy())) { |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 309 | return; |
| 310 | } |
joshualitt | d53a827 | 2014-11-10 16:03:14 -0800 | [diff] [blame^] | 311 | this->onDraw(ds, info); |
bsalomon@google.com | 1c13c96 | 2011-02-14 16:51:21 +0000 | [diff] [blame] | 312 | } |
| 313 | |
joshualitt | d53a827 | 2014-11-10 16:03:14 -0800 | [diff] [blame^] | 314 | void GrGpu::stencilPath(const GrOptDrawState& ds, |
| 315 | const GrPath* path, |
| 316 | const GrClipMaskManager::ScissorState& scissorState, |
| 317 | const GrStencilSettings& stencilSettings) { |
bsalomon@google.com | 64aef2b | 2012-06-11 15:36:13 +0000 | [diff] [blame] | 318 | this->handleDirtyContext(); |
| 319 | |
joshualitt | d53a827 | 2014-11-10 16:03:14 -0800 | [diff] [blame^] | 320 | if (!this->flushGraphicsState(ds, kStencilPath_DrawType, scissorState, NULL)) { |
bsalomon@google.com | 64aef2b | 2012-06-11 15:36:13 +0000 | [diff] [blame] | 321 | return; |
| 322 | } |
| 323 | |
joshualitt | 92e496f | 2014-10-31 13:56:50 -0700 | [diff] [blame] | 324 | this->pathRendering()->stencilPath(path, stencilSettings); |
bsalomon@google.com | 64aef2b | 2012-06-11 15:36:13 +0000 | [diff] [blame] | 325 | } |
| 326 | |
commit-bot@chromium.org | 32184d8 | 2013-10-09 15:14:18 +0000 | [diff] [blame] | 327 | |
joshualitt | d53a827 | 2014-11-10 16:03:14 -0800 | [diff] [blame^] | 328 | void GrGpu::drawPath(const GrOptDrawState& ds, |
| 329 | const GrPath* path, |
| 330 | const GrClipMaskManager::ScissorState& scissorState, |
| 331 | const GrStencilSettings& stencilSettings, |
| 332 | const GrDeviceCoordTexture* dstCopy) { |
commit-bot@chromium.org | c4dc0ad | 2013-10-09 14:11:33 +0000 | [diff] [blame] | 333 | this->handleDirtyContext(); |
| 334 | |
joshualitt | d53a827 | 2014-11-10 16:03:14 -0800 | [diff] [blame^] | 335 | if (!this->flushGraphicsState(ds, kDrawPath_DrawType, scissorState, dstCopy)) { |
commit-bot@chromium.org | c4dc0ad | 2013-10-09 14:11:33 +0000 | [diff] [blame] | 336 | return; |
| 337 | } |
| 338 | |
joshualitt | 92e496f | 2014-10-31 13:56:50 -0700 | [diff] [blame] | 339 | this->pathRendering()->drawPath(path, stencilSettings); |
commit-bot@chromium.org | c4dc0ad | 2013-10-09 14:11:33 +0000 | [diff] [blame] | 340 | } |
| 341 | |
joshualitt | d53a827 | 2014-11-10 16:03:14 -0800 | [diff] [blame^] | 342 | void GrGpu::drawPaths(const GrOptDrawState& ds, |
| 343 | const GrPathRange* pathRange, |
| 344 | const uint32_t indices[], |
| 345 | int count, |
| 346 | const float transforms[], |
| 347 | GrDrawTarget::PathTransformType transformsType, |
| 348 | const GrClipMaskManager::ScissorState& scissorState, |
| 349 | const GrStencilSettings& stencilSettings, |
| 350 | const GrDeviceCoordTexture* dstCopy) { |
commit-bot@chromium.org | 9b62aa1 | 2014-03-25 11:59:40 +0000 | [diff] [blame] | 351 | this->handleDirtyContext(); |
| 352 | |
joshualitt | d53a827 | 2014-11-10 16:03:14 -0800 | [diff] [blame^] | 353 | if (!this->flushGraphicsState(ds, kDrawPaths_DrawType, scissorState, dstCopy)) { |
commit-bot@chromium.org | 9b62aa1 | 2014-03-25 11:59:40 +0000 | [diff] [blame] | 354 | return; |
| 355 | } |
| 356 | |
cdalton | 855d83f | 2014-09-18 13:51:53 -0700 | [diff] [blame] | 357 | pathRange->willDrawPaths(indices, count); |
joshualitt | 92e496f | 2014-10-31 13:56:50 -0700 | [diff] [blame] | 358 | this->pathRendering()->drawPaths(pathRange, indices, count, transforms, transformsType, |
| 359 | stencilSettings); |
commit-bot@chromium.org | 9b62aa1 | 2014-03-25 11:59:40 +0000 | [diff] [blame] | 360 | } |