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