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