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