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