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