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