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