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