reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 1 | /* |
epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 2 | * Copyright 2010 Google Inc. |
| 3 | * |
| 4 | * Use of this source code is governed by a BSD-style license that can be |
| 5 | * found in the LICENSE file. |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 6 | */ |
| 7 | |
epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 8 | |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 9 | #include "src/gpu/GrGpu.h" |
bsalomon@google.com | 558a75b | 2011-08-08 17:01:14 +0000 | [diff] [blame] | 10 | |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 11 | #include "include/gpu/GrBackendSemaphore.h" |
| 12 | #include "include/gpu/GrBackendSurface.h" |
| 13 | #include "include/gpu/GrContext.h" |
| 14 | #include "src/core/SkMathPriv.h" |
Greg Daniel | f91aeb2 | 2019-06-18 09:58:02 -0400 | [diff] [blame] | 15 | #include "src/gpu/GrAuditTrail.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 16 | #include "src/gpu/GrCaps.h" |
| 17 | #include "src/gpu/GrContextPriv.h" |
Brian Salomon | bb8dde8 | 2019-06-27 10:52:13 -0400 | [diff] [blame] | 18 | #include "src/gpu/GrDataUtils.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 19 | #include "src/gpu/GrGpuResourcePriv.h" |
| 20 | #include "src/gpu/GrMesh.h" |
| 21 | #include "src/gpu/GrPathRendering.h" |
| 22 | #include "src/gpu/GrPipeline.h" |
| 23 | #include "src/gpu/GrRenderTargetPriv.h" |
| 24 | #include "src/gpu/GrResourceCache.h" |
| 25 | #include "src/gpu/GrResourceProvider.h" |
| 26 | #include "src/gpu/GrSemaphore.h" |
| 27 | #include "src/gpu/GrStencilAttachment.h" |
| 28 | #include "src/gpu/GrStencilSettings.h" |
| 29 | #include "src/gpu/GrSurfacePriv.h" |
| 30 | #include "src/gpu/GrTexturePriv.h" |
| 31 | #include "src/gpu/GrTextureProxyPriv.h" |
| 32 | #include "src/gpu/GrTracing.h" |
| 33 | #include "src/utils/SkJSONWriter.h" |
bsalomon | cb8979d | 2015-05-05 09:51:38 -0700 | [diff] [blame] | 34 | |
bsalomon@google.com | d302f14 | 2011-03-03 13:54:13 +0000 | [diff] [blame] | 35 | //////////////////////////////////////////////////////////////////////////////// |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 36 | |
Brian Salomon | e2826ab | 2019-06-04 15:58:31 -0400 | [diff] [blame] | 37 | GrGpu::GrGpu(GrContext* context) : fResetBits(kAll_GrBackendState), fContext(context) {} |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 38 | |
bsalomon | ed0bcad | 2015-05-04 10:36:42 -0700 | [diff] [blame] | 39 | GrGpu::~GrGpu() {} |
bsalomon | 1d89ddc | 2014-08-19 14:20:58 -0700 | [diff] [blame] | 40 | |
bsalomon | 6e2aad4 | 2016-04-01 11:54:31 -0700 | [diff] [blame] | 41 | void GrGpu::disconnect(DisconnectType) {} |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +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 | |
Greg Daniel | 8f5bbda | 2018-06-08 17:22:23 -0400 | [diff] [blame] | 45 | bool GrGpu::IsACopyNeededForRepeatWrapMode(const GrCaps* caps, GrTextureProxy* texProxy, |
| 46 | int width, int height, |
| 47 | GrSamplerState::Filter filter, |
| 48 | GrTextureProducer::CopyParams* copyParams, |
| 49 | SkScalar scaleAdjust[2]) { |
| 50 | if (!caps->npotTextureTileSupport() && |
Greg Daniel | 09c9400 | 2018-06-08 22:11:51 +0000 | [diff] [blame] | 51 | (!SkIsPow2(width) || !SkIsPow2(height))) { |
| 52 | SkASSERT(scaleAdjust); |
| 53 | copyParams->fWidth = GrNextPow2(width); |
| 54 | copyParams->fHeight = GrNextPow2(height); |
| 55 | SkASSERT(scaleAdjust); |
| 56 | scaleAdjust[0] = ((SkScalar)copyParams->fWidth) / width; |
| 57 | scaleAdjust[1] = ((SkScalar)copyParams->fHeight) / height; |
Greg Daniel | 8f5bbda | 2018-06-08 17:22:23 -0400 | [diff] [blame] | 58 | switch (filter) { |
Greg Daniel | 09c9400 | 2018-06-08 22:11:51 +0000 | [diff] [blame] | 59 | case GrSamplerState::Filter::kNearest: |
| 60 | copyParams->fFilter = GrSamplerState::Filter::kNearest; |
| 61 | break; |
| 62 | case GrSamplerState::Filter::kBilerp: |
| 63 | case GrSamplerState::Filter::kMipMap: |
| 64 | // We are only ever scaling up so no reason to ever indicate kMipMap. |
| 65 | copyParams->fFilter = GrSamplerState::Filter::kBilerp; |
| 66 | break; |
| 67 | } |
| 68 | return true; |
| 69 | } |
Robert Phillips | abf7b76 | 2018-03-21 12:13:37 -0400 | [diff] [blame] | 70 | |
| 71 | if (texProxy) { |
| 72 | // If the texture format itself doesn't support repeat wrap mode or mipmapping (and |
| 73 | // those capabilities are required) force a copy. |
Brian Salomon | fd98c2c | 2018-07-31 17:25:29 -0400 | [diff] [blame] | 74 | if (texProxy->hasRestrictedSampling()) { |
Robert Phillips | abf7b76 | 2018-03-21 12:13:37 -0400 | [diff] [blame] | 75 | copyParams->fFilter = GrSamplerState::Filter::kNearest; |
| 76 | copyParams->fWidth = texProxy->width(); |
| 77 | copyParams->fHeight = texProxy->height(); |
| 78 | return true; |
| 79 | } |
| 80 | } |
| 81 | |
bsalomon | 100b8f8 | 2015-10-28 08:37:44 -0700 | [diff] [blame] | 82 | return false; |
bsalomon | 045802d | 2015-10-20 07:58:01 -0700 | [diff] [blame] | 83 | } |
| 84 | |
Greg Daniel | 8f5bbda | 2018-06-08 17:22:23 -0400 | [diff] [blame] | 85 | bool GrGpu::IsACopyNeededForMips(const GrCaps* caps, const GrTextureProxy* texProxy, |
| 86 | GrSamplerState::Filter filter, |
| 87 | GrTextureProducer::CopyParams* copyParams) { |
| 88 | SkASSERT(texProxy); |
| 89 | bool willNeedMips = GrSamplerState::Filter::kMipMap == filter && caps->mipMapSupport(); |
| 90 | // If the texture format itself doesn't support mipmapping (and those capabilities are required) |
| 91 | // force a copy. |
| 92 | if (willNeedMips && texProxy->mipMapped() == GrMipMapped::kNo) { |
| 93 | copyParams->fFilter = GrSamplerState::Filter::kNearest; |
| 94 | copyParams->fWidth = texProxy->width(); |
| 95 | copyParams->fHeight = texProxy->height(); |
| 96 | return true; |
| 97 | } |
| 98 | |
| 99 | return false; |
| 100 | } |
| 101 | |
Brian Salomon | 1047a49 | 2019-07-02 12:25:21 -0400 | [diff] [blame] | 102 | static bool validate_levels(int w, int h, const GrMipLevel texels[], int mipLevelCount, int bpp, |
Brian Salomon | a3e2996 | 2019-07-16 11:52:08 -0400 | [diff] [blame] | 103 | const GrCaps* caps, bool mustHaveDataForAllLevels = false) { |
Brian Salomon | 1047a49 | 2019-07-02 12:25:21 -0400 | [diff] [blame] | 104 | SkASSERT(mipLevelCount > 0); |
| 105 | bool hasBasePixels = texels[0].fPixels; |
| 106 | int levelsWithPixelsCnt = 0; |
| 107 | for (int currentMipLevel = 0; currentMipLevel < mipLevelCount; ++currentMipLevel) { |
| 108 | if (texels[currentMipLevel].fPixels) { |
| 109 | const size_t minRowBytes = w * bpp; |
| 110 | if (caps->writePixelsRowBytesSupport()) { |
| 111 | if (texels[currentMipLevel].fRowBytes < minRowBytes) { |
| 112 | return false; |
| 113 | } |
| 114 | if (texels[currentMipLevel].fRowBytes % bpp) { |
| 115 | return false; |
| 116 | } |
| 117 | } else { |
| 118 | if (texels[currentMipLevel].fRowBytes != minRowBytes) { |
| 119 | return false; |
| 120 | } |
| 121 | } |
| 122 | ++levelsWithPixelsCnt; |
| 123 | } |
| 124 | if (w == 1 && h == 1) { |
| 125 | if (currentMipLevel != mipLevelCount - 1) { |
| 126 | return false; |
| 127 | } |
| 128 | } else { |
| 129 | w = std::max(w / 2, 1); |
| 130 | h = std::max(h / 2, 1); |
| 131 | } |
| 132 | } |
| 133 | // Either just a base layer or a full stack is required. |
| 134 | if (mipLevelCount != 1 && (w != 1 || h != 1)) { |
| 135 | return false; |
| 136 | } |
| 137 | // Can specify just the base, all levels, or no levels. |
| 138 | if (!hasBasePixels) { |
| 139 | return levelsWithPixelsCnt == 0; |
| 140 | } |
Brian Salomon | a3e2996 | 2019-07-16 11:52:08 -0400 | [diff] [blame] | 141 | if (levelsWithPixelsCnt == 1 && !mustHaveDataForAllLevels) { |
| 142 | return true; |
| 143 | } |
| 144 | return levelsWithPixelsCnt == mipLevelCount; |
Brian Salomon | 1047a49 | 2019-07-02 12:25:21 -0400 | [diff] [blame] | 145 | } |
| 146 | |
Brian Salomon | f2c2ba9 | 2019-07-17 09:59:59 -0400 | [diff] [blame] | 147 | sk_sp<GrTexture> GrGpu::createTexture(const GrSurfaceDesc& origDesc, GrRenderable renderable, |
Brian Salomon | 27b4d8d | 2019-07-22 14:23:45 -0400 | [diff] [blame^] | 148 | int renderTargetSampleCnt, SkBudgeted budgeted, |
| 149 | GrProtected isProtected, const GrMipLevel texels[], |
| 150 | int mipLevelCount) { |
Brian Salomon | e39526b | 2019-06-24 16:35:53 -0400 | [diff] [blame] | 151 | TRACE_EVENT0("skia.gpu", TRACE_FUNC); |
Brian Salomon | bb8dde8 | 2019-06-27 10:52:13 -0400 | [diff] [blame] | 152 | if (GrPixelConfigIsCompressed(origDesc.fConfig)) { |
| 153 | // Call GrGpu::createCompressedTexture. |
| 154 | return nullptr; |
| 155 | } |
cblume | 55f2d2d | 2016-02-26 13:20:48 -0800 | [diff] [blame] | 156 | GrSurfaceDesc desc = origDesc; |
| 157 | |
Brian Salomon | bdecacf | 2018-02-02 20:32:49 -0500 | [diff] [blame] | 158 | GrMipMapped mipMapped = mipLevelCount > 1 ? GrMipMapped::kYes : GrMipMapped::kNo; |
Brian Salomon | 27b4d8d | 2019-07-22 14:23:45 -0400 | [diff] [blame^] | 159 | if (!this->caps()->validateSurfaceDesc(desc, renderable, renderTargetSampleCnt, mipMapped)) { |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 160 | return nullptr; |
egdaniel | 8c9b6f1 | 2015-05-12 13:36:30 -0700 | [diff] [blame] | 161 | } |
| 162 | |
Brian Salomon | f2c2ba9 | 2019-07-17 09:59:59 -0400 | [diff] [blame] | 163 | if (renderable == GrRenderable::kYes) { |
Brian Salomon | 27b4d8d | 2019-07-22 14:23:45 -0400 | [diff] [blame^] | 164 | renderTargetSampleCnt = |
| 165 | this->caps()->getRenderTargetSampleCount(renderTargetSampleCnt, desc.fConfig); |
Brian Salomon | bdecacf | 2018-02-02 20:32:49 -0500 | [diff] [blame] | 166 | } |
Brian Salomon | d17b4a6 | 2017-05-23 16:53:47 -0400 | [diff] [blame] | 167 | // Attempt to catch un- or wrongly initialized sample counts. |
Brian Salomon | 27b4d8d | 2019-07-22 14:23:45 -0400 | [diff] [blame^] | 168 | SkASSERT(renderTargetSampleCnt > 0 && renderTargetSampleCnt <= 64); |
egdaniel | b0e1be2 | 2015-04-22 13:27:39 -0700 | [diff] [blame] | 169 | |
Brian Salomon | a3e2996 | 2019-07-16 11:52:08 -0400 | [diff] [blame] | 170 | bool mustHaveDataForAllLevels = this->caps()->createTextureMustSpecifyAllLevels(); |
Brian Salomon | 1047a49 | 2019-07-02 12:25:21 -0400 | [diff] [blame] | 171 | if (mipLevelCount) { |
Brian Salomon | 1047a49 | 2019-07-02 12:25:21 -0400 | [diff] [blame] | 172 | int bpp = GrBytesPerPixel(desc.fConfig); |
Brian Salomon | a3e2996 | 2019-07-16 11:52:08 -0400 | [diff] [blame] | 173 | if (!validate_levels(desc.fWidth, desc.fHeight, texels, mipLevelCount, bpp, this->caps(), |
| 174 | mustHaveDataForAllLevels)) { |
Brian Salomon | 1047a49 | 2019-07-02 12:25:21 -0400 | [diff] [blame] | 175 | return nullptr; |
| 176 | } |
Brian Salomon | a3e2996 | 2019-07-16 11:52:08 -0400 | [diff] [blame] | 177 | } else if (mustHaveDataForAllLevels) { |
| 178 | return nullptr; |
Brian Salomon | d17b4a6 | 2017-05-23 16:53:47 -0400 | [diff] [blame] | 179 | } |
| 180 | |
Robert Phillips | 92de631 | 2017-05-23 07:43:48 -0400 | [diff] [blame] | 181 | this->handleDirtyContext(); |
Brian Salomon | 27b4d8d | 2019-07-22 14:23:45 -0400 | [diff] [blame^] | 182 | sk_sp<GrTexture> tex = this->onCreateTexture(desc, renderable, renderTargetSampleCnt, budgeted, |
| 183 | isProtected, texels, mipLevelCount); |
bsalomon | b12ea41 | 2015-02-02 21:19:50 -0800 | [diff] [blame] | 184 | if (tex) { |
Brian Salomon | f2c2ba9 | 2019-07-17 09:59:59 -0400 | [diff] [blame] | 185 | if (!this->caps()->reuseScratchTextures() && renderable == GrRenderable::kNo) { |
cblume | 55f2d2d | 2016-02-26 13:20:48 -0800 | [diff] [blame] | 186 | tex->resourcePriv().removeScratchKey(); |
| 187 | } |
bsalomon | b12ea41 | 2015-02-02 21:19:50 -0800 | [diff] [blame] | 188 | fStats.incTextureCreates(); |
Robert Phillips | 590533f | 2017-07-11 14:22:35 -0400 | [diff] [blame] | 189 | if (mipLevelCount) { |
cblume | 55f2d2d | 2016-02-26 13:20:48 -0800 | [diff] [blame] | 190 | if (texels[0].fPixels) { |
| 191 | fStats.incTextureUploads(); |
| 192 | } |
bsalomon | b12ea41 | 2015-02-02 21:19:50 -0800 | [diff] [blame] | 193 | } |
| 194 | } |
bsalomon@google.com | 81c3f8d | 2011-08-03 15:18:33 +0000 | [diff] [blame] | 195 | return tex; |
| 196 | } |
| 197 | |
Brian Salomon | c7dced5 | 2019-07-18 15:02:01 +0000 | [diff] [blame] | 198 | sk_sp<GrTexture> GrGpu::createTexture(const GrSurfaceDesc& desc, GrRenderable renderable, |
Brian Salomon | 27b4d8d | 2019-07-22 14:23:45 -0400 | [diff] [blame^] | 199 | int renderTargetSampleCnt, SkBudgeted budgeted, |
| 200 | GrProtected isProtected) { |
| 201 | return this->createTexture(desc, renderable, renderTargetSampleCnt, budgeted, isProtected, |
| 202 | nullptr, 0); |
Brian Salomon | c7dced5 | 2019-07-18 15:02:01 +0000 | [diff] [blame] | 203 | } |
| 204 | |
Brian Salomon | bb8dde8 | 2019-06-27 10:52:13 -0400 | [diff] [blame] | 205 | sk_sp<GrTexture> GrGpu::createCompressedTexture(int width, int height, |
| 206 | SkImage::CompressionType compressionType, |
| 207 | SkBudgeted budgeted, const void* data, |
| 208 | size_t dataSize) { |
| 209 | this->handleDirtyContext(); |
| 210 | if (width < 1 || width > this->caps()->maxTextureSize() || |
| 211 | height < 1 || height > this->caps()->maxTextureSize()) { |
| 212 | return nullptr; |
| 213 | } |
Brian Salomon | a3e2996 | 2019-07-16 11:52:08 -0400 | [diff] [blame] | 214 | // Note if we relax the requirement that data must be provided then we must check |
| 215 | // caps()->shouldInitializeTextures() here. |
Brian Salomon | bb8dde8 | 2019-06-27 10:52:13 -0400 | [diff] [blame] | 216 | if (!data) { |
| 217 | return nullptr; |
| 218 | } |
| 219 | if (!this->caps()->isConfigTexturable(GrCompressionTypePixelConfig(compressionType))) { |
| 220 | return nullptr; |
| 221 | } |
| 222 | if (dataSize < GrCompressedDataSize(compressionType, width, height)) { |
| 223 | return nullptr; |
| 224 | } |
| 225 | return this->onCreateCompressedTexture(width, height, compressionType, budgeted, data); |
| 226 | } |
| 227 | |
Greg Daniel | 7ef28f3 | 2017-04-20 16:41:55 +0000 | [diff] [blame] | 228 | sk_sp<GrTexture> GrGpu::wrapBackendTexture(const GrBackendTexture& backendTex, |
Brian Salomon | fa2ebea | 2019-01-24 15:58:58 -0500 | [diff] [blame] | 229 | GrWrapOwnership ownership, GrWrapCacheable cacheable, |
| 230 | GrIOType ioType) { |
Brian Salomon | c67c31c | 2018-12-06 10:00:03 -0500 | [diff] [blame] | 231 | SkASSERT(ioType != kWrite_GrIOType); |
bsalomon@google.com | e269f21 | 2011-11-07 13:29:52 +0000 | [diff] [blame] | 232 | this->handleDirtyContext(); |
Robert Phillips | dd39980 | 2019-07-18 12:28:00 +0000 | [diff] [blame] | 233 | SkASSERT(this->caps()); |
| 234 | if (!this->caps()->isConfigTexturable(backendTex.config())) { |
bsalomon | 5b30c6f | 2015-12-17 14:17:34 -0800 | [diff] [blame] | 235 | return nullptr; |
| 236 | } |
Robert Phillips | dd39980 | 2019-07-18 12:28:00 +0000 | [diff] [blame] | 237 | if (backendTex.width() > this->caps()->maxTextureSize() || |
| 238 | backendTex.height() > this->caps()->maxTextureSize()) { |
bsalomon | 5b30c6f | 2015-12-17 14:17:34 -0800 | [diff] [blame] | 239 | return nullptr; |
| 240 | } |
Robert Phillips | dd39980 | 2019-07-18 12:28:00 +0000 | [diff] [blame] | 241 | return this->onWrapBackendTexture(backendTex, ownership, cacheable, ioType); |
Brian Salomon | d17f658 | 2017-07-19 18:28:58 -0400 | [diff] [blame] | 242 | } |
Eric Karl | 5c77975 | 2017-05-08 12:02:07 -0700 | [diff] [blame] | 243 | |
Brian Salomon | d17f658 | 2017-07-19 18:28:58 -0400 | [diff] [blame] | 244 | sk_sp<GrTexture> GrGpu::wrapRenderableBackendTexture(const GrBackendTexture& backendTex, |
Robert Phillips | 0902c98 | 2019-07-16 07:47:56 -0400 | [diff] [blame] | 245 | int sampleCnt, GrColorType colorType, |
| 246 | GrWrapOwnership ownership, |
Brian Salomon | aa6ca0a | 2019-01-24 16:03:07 -0500 | [diff] [blame] | 247 | GrWrapCacheable cacheable) { |
Brian Salomon | d17f658 | 2017-07-19 18:28:58 -0400 | [diff] [blame] | 248 | this->handleDirtyContext(); |
Brian Salomon | bdecacf | 2018-02-02 20:32:49 -0500 | [diff] [blame] | 249 | if (sampleCnt < 1) { |
| 250 | return nullptr; |
| 251 | } |
Robert Phillips | 0902c98 | 2019-07-16 07:47:56 -0400 | [diff] [blame] | 252 | |
| 253 | const GrCaps* caps = this->caps(); |
| 254 | |
| 255 | SkASSERT(GrCaps::AreConfigsCompatible(backendTex.config(), |
| 256 | caps->getConfigFromBackendFormat( |
| 257 | backendTex.getBackendFormat(), |
| 258 | colorType))); |
| 259 | |
| 260 | if (!caps->isFormatTexturable(colorType, backendTex.getBackendFormat()) || |
| 261 | !caps->getRenderTargetSampleCount(sampleCnt, colorType, backendTex.getBackendFormat())) { |
Brian Salomon | d17f658 | 2017-07-19 18:28:58 -0400 | [diff] [blame] | 262 | return nullptr; |
| 263 | } |
| 264 | |
Robert Phillips | 0902c98 | 2019-07-16 07:47:56 -0400 | [diff] [blame] | 265 | if (backendTex.width() > caps->maxRenderTargetSize() || |
| 266 | backendTex.height() > caps->maxRenderTargetSize()) { |
Brian Salomon | d17f658 | 2017-07-19 18:28:58 -0400 | [diff] [blame] | 267 | return nullptr; |
| 268 | } |
Robert Phillips | 0902c98 | 2019-07-16 07:47:56 -0400 | [diff] [blame] | 269 | sk_sp<GrTexture> tex = this->onWrapRenderableBackendTexture(backendTex, sampleCnt, colorType, |
| 270 | ownership, cacheable); |
Greg Daniel | e320486 | 2018-04-16 11:24:10 -0400 | [diff] [blame] | 271 | SkASSERT(!tex || tex->asRenderTarget()); |
bungeman | 6bd5284 | 2016-10-27 09:30:08 -0700 | [diff] [blame] | 272 | return tex; |
bsalomon@google.com | e269f21 | 2011-11-07 13:29:52 +0000 | [diff] [blame] | 273 | } |
| 274 | |
Robert Phillips | dd39980 | 2019-07-18 12:28:00 +0000 | [diff] [blame] | 275 | sk_sp<GrRenderTarget> GrGpu::wrapBackendRenderTarget(const GrBackendRenderTarget& backendRT) { |
| 276 | if (0 == this->caps()->getRenderTargetSampleCount(backendRT.sampleCnt(), backendRT.config())) { |
bsalomon | 5b30c6f | 2015-12-17 14:17:34 -0800 | [diff] [blame] | 277 | return nullptr; |
| 278 | } |
Robert Phillips | dd39980 | 2019-07-18 12:28:00 +0000 | [diff] [blame] | 279 | this->handleDirtyContext(); |
| 280 | return this->onWrapBackendRenderTarget(backendRT); |
bsalomon@google.com | e269f21 | 2011-11-07 13:29:52 +0000 | [diff] [blame] | 281 | } |
| 282 | |
Robert Phillips | dd39980 | 2019-07-18 12:28:00 +0000 | [diff] [blame] | 283 | sk_sp<GrRenderTarget> GrGpu::wrapBackendTextureAsRenderTarget(const GrBackendTexture& tex, |
| 284 | int sampleCnt) { |
| 285 | if (0 == this->caps()->getRenderTargetSampleCount(sampleCnt, tex.config())) { |
| 286 | return nullptr; |
| 287 | } |
| 288 | int maxSize = this->caps()->maxTextureSize(); |
| 289 | if (tex.width() > maxSize || tex.height() > maxSize) { |
| 290 | return nullptr; |
| 291 | } |
Brian Salomon | bdecacf | 2018-02-02 20:32:49 -0500 | [diff] [blame] | 292 | this->handleDirtyContext(); |
Robert Phillips | dd39980 | 2019-07-18 12:28:00 +0000 | [diff] [blame] | 293 | return this->onWrapBackendTextureAsRenderTarget(tex, sampleCnt); |
ericrk | f7b8b8a | 2016-02-24 14:49:51 -0800 | [diff] [blame] | 294 | } |
| 295 | |
Greg Daniel | b46add8 | 2019-01-02 14:51:29 -0500 | [diff] [blame] | 296 | sk_sp<GrRenderTarget> GrGpu::wrapVulkanSecondaryCBAsRenderTarget(const SkImageInfo& imageInfo, |
| 297 | const GrVkDrawableInfo& vkInfo) { |
| 298 | return this->onWrapVulkanSecondaryCBAsRenderTarget(imageInfo, vkInfo); |
| 299 | } |
| 300 | |
| 301 | sk_sp<GrRenderTarget> GrGpu::onWrapVulkanSecondaryCBAsRenderTarget(const SkImageInfo& imageInfo, |
| 302 | const GrVkDrawableInfo& vkInfo) { |
| 303 | // This is only supported on Vulkan so we default to returning nullptr here |
| 304 | return nullptr; |
| 305 | } |
| 306 | |
Brian Salomon | dbf7072 | 2019-02-07 11:31:24 -0500 | [diff] [blame] | 307 | sk_sp<GrGpuBuffer> GrGpu::createBuffer(size_t size, GrGpuBufferType intendedType, |
| 308 | GrAccessPattern accessPattern, const void* data) { |
Brian Salomon | e39526b | 2019-06-24 16:35:53 -0400 | [diff] [blame] | 309 | TRACE_EVENT0("skia.gpu", TRACE_FUNC); |
bsalomon@google.com | a7f84e1 | 2011-03-10 14:13:19 +0000 | [diff] [blame] | 310 | this->handleDirtyContext(); |
Brian Salomon | dbf7072 | 2019-02-07 11:31:24 -0500 | [diff] [blame] | 311 | sk_sp<GrGpuBuffer> buffer = this->onCreateBuffer(size, intendedType, accessPattern, data); |
robertphillips | 1b8e1b5 | 2015-06-24 06:54:10 -0700 | [diff] [blame] | 312 | if (!this->caps()->reuseScratchBuffers()) { |
cdalton | 397536c | 2016-03-25 12:15:03 -0700 | [diff] [blame] | 313 | buffer->resourcePriv().removeScratchKey(); |
robertphillips | 1b8e1b5 | 2015-06-24 06:54:10 -0700 | [diff] [blame] | 314 | } |
cdalton | 397536c | 2016-03-25 12:15:03 -0700 | [diff] [blame] | 315 | return buffer; |
jvanverth | 73063dc | 2015-12-03 09:15:47 -0800 | [diff] [blame] | 316 | } |
| 317 | |
Greg Daniel | 46cfbc6 | 2019-06-07 11:43:30 -0400 | [diff] [blame] | 318 | bool GrGpu::copySurface(GrSurface* dst, GrSurface* src, const SkIRect& srcRect, |
| 319 | const SkIPoint& dstPoint, bool canDiscardOutsideDstRect) { |
Brian Salomon | e39526b | 2019-06-24 16:35:53 -0400 | [diff] [blame] | 320 | TRACE_EVENT0("skia.gpu", TRACE_FUNC); |
joshualitt | 1cbdcde | 2015-08-21 11:53:29 -0700 | [diff] [blame] | 321 | SkASSERT(dst && src); |
Brian Salomon | c67c31c | 2018-12-06 10:00:03 -0500 | [diff] [blame] | 322 | |
| 323 | if (dst->readOnly()) { |
| 324 | return false; |
| 325 | } |
| 326 | |
joshualitt | 1cbdcde | 2015-08-21 11:53:29 -0700 | [diff] [blame] | 327 | this->handleDirtyContext(); |
Brian Salomon | c67c31c | 2018-12-06 10:00:03 -0500 | [diff] [blame] | 328 | |
Greg Daniel | 46cfbc6 | 2019-06-07 11:43:30 -0400 | [diff] [blame] | 329 | return this->onCopySurface(dst, src, srcRect, dstPoint, canDiscardOutsideDstRect); |
joshualitt | 1cbdcde | 2015-08-21 11:53:29 -0700 | [diff] [blame] | 330 | } |
| 331 | |
Brian Salomon | a694870 | 2018-06-01 15:33:20 -0400 | [diff] [blame] | 332 | bool GrGpu::readPixels(GrSurface* surface, int left, int top, int width, int height, |
| 333 | GrColorType dstColorType, void* buffer, size_t rowBytes) { |
Brian Salomon | e39526b | 2019-06-24 16:35:53 -0400 | [diff] [blame] | 334 | TRACE_EVENT0("skia.gpu", TRACE_FUNC); |
Brian Salomon | bf7b620 | 2016-11-11 16:08:03 -0500 | [diff] [blame] | 335 | SkASSERT(surface); |
| 336 | |
Brian Salomon | 1d43530 | 2019-07-01 13:05:28 -0400 | [diff] [blame] | 337 | auto subRect = SkIRect::MakeXYWH(left, top, width, height); |
| 338 | auto bounds = SkIRect::MakeWH(surface->width(), surface->height()); |
| 339 | if (!bounds.contains(subRect)) { |
egdaniel | 6d901da | 2015-07-30 12:02:15 -0700 | [diff] [blame] | 340 | return false; |
| 341 | } |
| 342 | |
Brian Salomon | 1047a49 | 2019-07-02 12:25:21 -0400 | [diff] [blame] | 343 | size_t minRowBytes = SkToSizeT(GrColorTypeBytesPerPixel(dstColorType) * width); |
| 344 | if (!this->caps()->readPixelsRowBytesSupport()) { |
| 345 | if (rowBytes != minRowBytes) { |
| 346 | return false; |
| 347 | } |
| 348 | } else { |
| 349 | if (rowBytes < minRowBytes) { |
| 350 | return false; |
| 351 | } |
| 352 | if (rowBytes % GrColorTypeBytesPerPixel(dstColorType)) { |
| 353 | return false; |
| 354 | } |
| 355 | } |
| 356 | |
Jim Van Verth | 1676cb9 | 2019-01-15 13:24:45 -0500 | [diff] [blame] | 357 | if (GrPixelConfigIsCompressed(surface->config())) { |
| 358 | return false; |
| 359 | } |
| 360 | |
Brian Salomon | bf7b620 | 2016-11-11 16:08:03 -0500 | [diff] [blame] | 361 | this->handleDirtyContext(); |
| 362 | |
Brian Salomon | a694870 | 2018-06-01 15:33:20 -0400 | [diff] [blame] | 363 | return this->onReadPixels(surface, left, top, width, height, dstColorType, buffer, rowBytes); |
bsalomon@google.com | a7f84e1 | 2011-03-10 14:13:19 +0000 | [diff] [blame] | 364 | } |
| 365 | |
Brian Salomon | a9b04b9 | 2018-06-01 15:04:28 -0400 | [diff] [blame] | 366 | bool GrGpu::writePixels(GrSurface* surface, int left, int top, int width, int height, |
| 367 | GrColorType srcColorType, const GrMipLevel texels[], int mipLevelCount) { |
Brian Salomon | e39526b | 2019-06-24 16:35:53 -0400 | [diff] [blame] | 368 | TRACE_EVENT0("skia.gpu", TRACE_FUNC); |
Brian Salomon | bf7b620 | 2016-11-11 16:08:03 -0500 | [diff] [blame] | 369 | SkASSERT(surface); |
Brian Salomon | c67c31c | 2018-12-06 10:00:03 -0500 | [diff] [blame] | 370 | |
| 371 | if (surface->readOnly()) { |
| 372 | return false; |
| 373 | } |
| 374 | |
Brian Salomon | 1047a49 | 2019-07-02 12:25:21 -0400 | [diff] [blame] | 375 | if (mipLevelCount == 0) { |
| 376 | return false; |
| 377 | } else if (mipLevelCount == 1) { |
Greg Daniel | 660cc99 | 2017-06-26 14:55:05 -0400 | [diff] [blame] | 378 | // We require that if we are not mipped, then the write region is contained in the surface |
Brian Salomon | 1d43530 | 2019-07-01 13:05:28 -0400 | [diff] [blame] | 379 | auto subRect = SkIRect::MakeXYWH(left, top, width, height); |
| 380 | auto bounds = SkIRect::MakeWH(surface->width(), surface->height()); |
Greg Daniel | 660cc99 | 2017-06-26 14:55:05 -0400 | [diff] [blame] | 381 | if (!bounds.contains(subRect)) { |
| 382 | return false; |
| 383 | } |
| 384 | } else if (0 != left || 0 != top || width != surface->width() || height != surface->height()) { |
| 385 | // We require that if the texels are mipped, than the write region is the entire surface |
| 386 | return false; |
| 387 | } |
Robert Phillips | b7b7e5f | 2017-05-22 13:23:19 -0400 | [diff] [blame] | 388 | |
Brian Salomon | 1047a49 | 2019-07-02 12:25:21 -0400 | [diff] [blame] | 389 | int bpp = GrColorTypeBytesPerPixel(srcColorType); |
| 390 | if (!validate_levels(width, height, texels, mipLevelCount, bpp, this->caps())) { |
| 391 | return false; |
cblume | 55f2d2d | 2016-02-26 13:20:48 -0800 | [diff] [blame] | 392 | } |
jvanverth | 2dc2994 | 2015-09-01 07:16:46 -0700 | [diff] [blame] | 393 | |
bsalomon@google.com | 6f37951 | 2011-11-16 20:36:03 +0000 | [diff] [blame] | 394 | this->handleDirtyContext(); |
Brian Salomon | a9b04b9 | 2018-06-01 15:04:28 -0400 | [diff] [blame] | 395 | if (this->onWritePixels(surface, left, top, width, height, srcColorType, texels, |
Brian Salomon | c320b15 | 2018-02-20 14:05:36 -0500 | [diff] [blame] | 396 | mipLevelCount)) { |
jvanverth | 900bd4a | 2016-04-29 13:53:12 -0700 | [diff] [blame] | 397 | SkIRect rect = SkIRect::MakeXYWH(left, top, width, height); |
Brian Salomon | a9b04b9 | 2018-06-01 15:04:28 -0400 | [diff] [blame] | 398 | this->didWriteToSurface(surface, kTopLeft_GrSurfaceOrigin, &rect, mipLevelCount); |
bsalomon | b12ea41 | 2015-02-02 21:19:50 -0800 | [diff] [blame] | 399 | fStats.incTextureUploads(); |
| 400 | return true; |
| 401 | } |
| 402 | return false; |
bsalomon@google.com | 6f37951 | 2011-11-16 20:36:03 +0000 | [diff] [blame] | 403 | } |
| 404 | |
Brian Salomon | e05ba5a | 2019-04-08 11:59:07 -0400 | [diff] [blame] | 405 | bool GrGpu::transferPixelsTo(GrTexture* texture, int left, int top, int width, int height, |
| 406 | GrColorType bufferColorType, GrGpuBuffer* transferBuffer, |
| 407 | size_t offset, size_t rowBytes) { |
Brian Salomon | e39526b | 2019-06-24 16:35:53 -0400 | [diff] [blame] | 408 | TRACE_EVENT0("skia.gpu", TRACE_FUNC); |
Brian Salomon | c67c31c | 2018-12-06 10:00:03 -0500 | [diff] [blame] | 409 | SkASSERT(texture); |
cdalton | 397536c | 2016-03-25 12:15:03 -0700 | [diff] [blame] | 410 | SkASSERT(transferBuffer); |
jvanverth | 17aa047 | 2016-01-05 10:41:27 -0800 | [diff] [blame] | 411 | |
Brian Salomon | c67c31c | 2018-12-06 10:00:03 -0500 | [diff] [blame] | 412 | if (texture->readOnly()) { |
| 413 | return false; |
| 414 | } |
| 415 | |
Greg Daniel | 660cc99 | 2017-06-26 14:55:05 -0400 | [diff] [blame] | 416 | // We require that the write region is contained in the texture |
| 417 | SkIRect subRect = SkIRect::MakeXYWH(left, top, width, height); |
| 418 | SkIRect bounds = SkIRect::MakeWH(texture->width(), texture->height()); |
| 419 | if (!bounds.contains(subRect)) { |
| 420 | return false; |
| 421 | } |
| 422 | |
Brian Salomon | 1047a49 | 2019-07-02 12:25:21 -0400 | [diff] [blame] | 423 | int bpp = GrColorTypeBytesPerPixel(bufferColorType); |
| 424 | if (this->caps()->writePixelsRowBytesSupport()) { |
| 425 | if (rowBytes < SkToSizeT(bpp * width)) { |
| 426 | return false; |
| 427 | } |
| 428 | if (rowBytes % bpp) { |
| 429 | return false; |
| 430 | } |
| 431 | } else { |
| 432 | if (rowBytes != SkToSizeT(bpp * width)) { |
| 433 | return false; |
| 434 | } |
| 435 | } |
| 436 | |
jvanverth | 17aa047 | 2016-01-05 10:41:27 -0800 | [diff] [blame] | 437 | this->handleDirtyContext(); |
Brian Salomon | e05ba5a | 2019-04-08 11:59:07 -0400 | [diff] [blame] | 438 | if (this->onTransferPixelsTo(texture, left, top, width, height, bufferColorType, transferBuffer, |
| 439 | offset, rowBytes)) { |
jvanverth | 900bd4a | 2016-04-29 13:53:12 -0700 | [diff] [blame] | 440 | SkIRect rect = SkIRect::MakeXYWH(left, top, width, height); |
Brian Salomon | 1fabd51 | 2018-02-09 09:54:25 -0500 | [diff] [blame] | 441 | this->didWriteToSurface(texture, kTopLeft_GrSurfaceOrigin, &rect); |
jvanverth | 17aa047 | 2016-01-05 10:41:27 -0800 | [diff] [blame] | 442 | fStats.incTransfersToTexture(); |
jvanverth | 84741b3 | 2016-09-30 08:39:02 -0700 | [diff] [blame] | 443 | |
jvanverth | 17aa047 | 2016-01-05 10:41:27 -0800 | [diff] [blame] | 444 | return true; |
| 445 | } |
| 446 | return false; |
| 447 | } |
| 448 | |
Brian Salomon | 26de56e | 2019-04-10 12:14:26 -0400 | [diff] [blame] | 449 | bool GrGpu::transferPixelsFrom(GrSurface* surface, int left, int top, int width, int height, |
| 450 | GrColorType bufferColorType, GrGpuBuffer* transferBuffer, |
| 451 | size_t offset) { |
Brian Salomon | e39526b | 2019-06-24 16:35:53 -0400 | [diff] [blame] | 452 | TRACE_EVENT0("skia.gpu", TRACE_FUNC); |
Brian Salomon | e05ba5a | 2019-04-08 11:59:07 -0400 | [diff] [blame] | 453 | SkASSERT(surface); |
| 454 | SkASSERT(transferBuffer); |
Brian Salomon | 26de56e | 2019-04-10 12:14:26 -0400 | [diff] [blame] | 455 | SkASSERT(this->caps()->transferFromOffsetAlignment(bufferColorType)); |
| 456 | SkASSERT(offset % this->caps()->transferFromOffsetAlignment(bufferColorType) == 0); |
Brian Salomon | e05ba5a | 2019-04-08 11:59:07 -0400 | [diff] [blame] | 457 | |
| 458 | // We require that the write region is contained in the texture |
| 459 | SkIRect subRect = SkIRect::MakeXYWH(left, top, width, height); |
| 460 | SkIRect bounds = SkIRect::MakeWH(surface->width(), surface->height()); |
| 461 | if (!bounds.contains(subRect)) { |
| 462 | return false; |
| 463 | } |
| 464 | |
| 465 | this->handleDirtyContext(); |
Brian Salomon | 26de56e | 2019-04-10 12:14:26 -0400 | [diff] [blame] | 466 | if (this->onTransferPixelsFrom(surface, left, top, width, height, bufferColorType, |
| 467 | transferBuffer, offset)) { |
Brian Salomon | e05ba5a | 2019-04-08 11:59:07 -0400 | [diff] [blame] | 468 | fStats.incTransfersFromSurface(); |
Brian Salomon | 26de56e | 2019-04-10 12:14:26 -0400 | [diff] [blame] | 469 | return true; |
Brian Salomon | e05ba5a | 2019-04-08 11:59:07 -0400 | [diff] [blame] | 470 | } |
Brian Salomon | 26de56e | 2019-04-10 12:14:26 -0400 | [diff] [blame] | 471 | return false; |
Brian Salomon | e05ba5a | 2019-04-08 11:59:07 -0400 | [diff] [blame] | 472 | } |
| 473 | |
Brian Salomon | 930f939 | 2018-06-20 16:25:26 -0400 | [diff] [blame] | 474 | bool GrGpu::regenerateMipMapLevels(GrTexture* texture) { |
Brian Salomon | e39526b | 2019-06-24 16:35:53 -0400 | [diff] [blame] | 475 | TRACE_EVENT0("skia.gpu", TRACE_FUNC); |
Brian Salomon | 930f939 | 2018-06-20 16:25:26 -0400 | [diff] [blame] | 476 | SkASSERT(texture); |
| 477 | SkASSERT(this->caps()->mipMapSupport()); |
| 478 | SkASSERT(texture->texturePriv().mipMapped() == GrMipMapped::kYes); |
| 479 | SkASSERT(texture->texturePriv().mipMapsAreDirty()); |
| 480 | SkASSERT(!texture->asRenderTarget() || !texture->asRenderTarget()->needsResolve()); |
Brian Salomon | c67c31c | 2018-12-06 10:00:03 -0500 | [diff] [blame] | 481 | if (texture->readOnly()) { |
| 482 | return false; |
| 483 | } |
Brian Salomon | 930f939 | 2018-06-20 16:25:26 -0400 | [diff] [blame] | 484 | if (this->onRegenerateMipMapLevels(texture)) { |
| 485 | texture->texturePriv().markMipMapsClean(); |
| 486 | return true; |
| 487 | } |
| 488 | return false; |
| 489 | } |
| 490 | |
Brian Salomon | 1f05d45 | 2019-02-08 12:33:08 -0500 | [diff] [blame] | 491 | void GrGpu::resetTextureBindings() { |
| 492 | this->handleDirtyContext(); |
| 493 | this->onResetTextureBindings(); |
| 494 | } |
| 495 | |
Brian Salomon | 1fabd51 | 2018-02-09 09:54:25 -0500 | [diff] [blame] | 496 | void GrGpu::resolveRenderTarget(GrRenderTarget* target) { |
tfarina@chromium.org | f6de475 | 2013-08-17 00:02:59 +0000 | [diff] [blame] | 497 | SkASSERT(target); |
bsalomon@google.com | 75f9f25 | 2012-01-31 13:35:56 +0000 | [diff] [blame] | 498 | this->handleDirtyContext(); |
Brian Salomon | 1fabd51 | 2018-02-09 09:54:25 -0500 | [diff] [blame] | 499 | this->onResolveRenderTarget(target); |
bsalomon@google.com | 75f9f25 | 2012-01-31 13:35:56 +0000 | [diff] [blame] | 500 | } |
| 501 | |
Brian Salomon | 1fabd51 | 2018-02-09 09:54:25 -0500 | [diff] [blame] | 502 | void GrGpu::didWriteToSurface(GrSurface* surface, GrSurfaceOrigin origin, const SkIRect* bounds, |
| 503 | uint32_t mipLevels) const { |
jvanverth | 900bd4a | 2016-04-29 13:53:12 -0700 | [diff] [blame] | 504 | SkASSERT(surface); |
Brian Salomon | c67c31c | 2018-12-06 10:00:03 -0500 | [diff] [blame] | 505 | SkASSERT(!surface->readOnly()); |
jvanverth | 900bd4a | 2016-04-29 13:53:12 -0700 | [diff] [blame] | 506 | // Mark any MIP chain and resolve buffer as dirty if and only if there is a non-empty bounds. |
| 507 | if (nullptr == bounds || !bounds->isEmpty()) { |
| 508 | if (GrRenderTarget* target = surface->asRenderTarget()) { |
Brian Salomon | 1fabd51 | 2018-02-09 09:54:25 -0500 | [diff] [blame] | 509 | SkIRect flippedBounds; |
| 510 | if (kBottomLeft_GrSurfaceOrigin == origin && bounds) { |
| 511 | flippedBounds = {bounds->fLeft, surface->height() - bounds->fBottom, |
| 512 | bounds->fRight, surface->height() - bounds->fTop}; |
| 513 | bounds = &flippedBounds; |
| 514 | } |
jvanverth | 900bd4a | 2016-04-29 13:53:12 -0700 | [diff] [blame] | 515 | target->flagAsNeedingResolve(bounds); |
| 516 | } |
| 517 | GrTexture* texture = surface->asTexture(); |
| 518 | if (texture && 1 == mipLevels) { |
Greg Daniel | 0fc4d2d | 2017-10-12 11:23:36 -0400 | [diff] [blame] | 519 | texture->texturePriv().markMipMapsDirty(); |
jvanverth | 900bd4a | 2016-04-29 13:53:12 -0700 | [diff] [blame] | 520 | } |
| 521 | } |
| 522 | } |
| 523 | |
Chris Dalton | 8c4cafd | 2019-04-15 19:14:36 -0600 | [diff] [blame] | 524 | int GrGpu::findOrAssignSamplePatternKey(GrRenderTarget* renderTarget) { |
Chris Dalton | d7291ba | 2019-03-07 14:17:03 -0700 | [diff] [blame] | 525 | SkASSERT(this->caps()->sampleLocationsSupport()); |
Chris Dalton | effee20 | 2019-07-01 22:28:03 -0600 | [diff] [blame] | 526 | SkASSERT(renderTarget->numSamples() > 1 || |
| 527 | (renderTarget->renderTargetPriv().getStencilAttachment() && |
| 528 | renderTarget->renderTargetPriv().getStencilAttachment()->numSamples() > 1)); |
Chris Dalton | d7291ba | 2019-03-07 14:17:03 -0700 | [diff] [blame] | 529 | |
| 530 | SkSTArray<16, SkPoint> sampleLocations; |
Chris Dalton | 8c4cafd | 2019-04-15 19:14:36 -0600 | [diff] [blame] | 531 | this->querySampleLocations(renderTarget, &sampleLocations); |
Chris Dalton | d7291ba | 2019-03-07 14:17:03 -0700 | [diff] [blame] | 532 | return fSamplePatternDictionary.findOrAssignSamplePatternKey(sampleLocations); |
| 533 | } |
| 534 | |
Brian Salomon | f9a1fdf | 2019-05-09 10:30:12 -0400 | [diff] [blame] | 535 | GrSemaphoresSubmitted GrGpu::finishFlush(GrSurfaceProxy* proxies[], |
| 536 | int n, |
Greg Daniel | bae7121 | 2019-03-01 15:24:35 -0500 | [diff] [blame] | 537 | SkSurface::BackendSurfaceAccess access, |
Greg Daniel | 797efca | 2019-05-09 14:04:20 -0400 | [diff] [blame] | 538 | const GrFlushInfo& info, |
| 539 | const GrPrepareForExternalIORequests& externalRequests) { |
Brian Salomon | e39526b | 2019-06-24 16:35:53 -0400 | [diff] [blame] | 540 | TRACE_EVENT0("skia.gpu", TRACE_FUNC); |
Greg Daniel | d207345 | 2018-12-07 11:20:33 -0500 | [diff] [blame] | 541 | this->stats()->incNumFinishFlushes(); |
Robert Phillips | 9da87e0 | 2019-02-04 13:26:26 -0500 | [diff] [blame] | 542 | GrResourceProvider* resourceProvider = fContext->priv().resourceProvider(); |
Robert Phillips | 6be756b | 2018-01-16 15:07:54 -0500 | [diff] [blame] | 543 | |
Brian Salomon | 9ff5acb | 2019-05-08 09:04:47 -0400 | [diff] [blame] | 544 | if (this->caps()->semaphoreSupport()) { |
Greg Daniel | e6bfb7d | 2019-04-17 15:26:11 -0400 | [diff] [blame] | 545 | for (int i = 0; i < info.fNumSemaphores; ++i) { |
Greg Daniel | 5131678 | 2017-08-02 15:10:09 +0000 | [diff] [blame] | 546 | sk_sp<GrSemaphore> semaphore; |
Greg Daniel | e6bfb7d | 2019-04-17 15:26:11 -0400 | [diff] [blame] | 547 | if (info.fSignalSemaphores[i].isInitialized()) { |
Robert Phillips | 6be756b | 2018-01-16 15:07:54 -0500 | [diff] [blame] | 548 | semaphore = resourceProvider->wrapBackendSemaphore( |
Greg Daniel | e6bfb7d | 2019-04-17 15:26:11 -0400 | [diff] [blame] | 549 | info.fSignalSemaphores[i], |
| 550 | GrResourceProvider::SemaphoreWrapType::kWillSignal, |
Greg Daniel | 17b7c05 | 2018-01-09 13:55:33 -0500 | [diff] [blame] | 551 | kBorrow_GrWrapOwnership); |
Greg Daniel | 5131678 | 2017-08-02 15:10:09 +0000 | [diff] [blame] | 552 | } else { |
Robert Phillips | 6be756b | 2018-01-16 15:07:54 -0500 | [diff] [blame] | 553 | semaphore = resourceProvider->makeSemaphore(false); |
Greg Daniel | 5131678 | 2017-08-02 15:10:09 +0000 | [diff] [blame] | 554 | } |
Greg Daniel | 858e12c | 2018-12-06 11:11:37 -0500 | [diff] [blame] | 555 | this->insertSemaphore(semaphore); |
Greg Daniel | 5131678 | 2017-08-02 15:10:09 +0000 | [diff] [blame] | 556 | |
Greg Daniel | e6bfb7d | 2019-04-17 15:26:11 -0400 | [diff] [blame] | 557 | if (!info.fSignalSemaphores[i].isInitialized()) { |
| 558 | info.fSignalSemaphores[i] = semaphore->backendSemaphore(); |
Greg Daniel | 5131678 | 2017-08-02 15:10:09 +0000 | [diff] [blame] | 559 | } |
| 560 | } |
| 561 | } |
Greg Daniel | 797efca | 2019-05-09 14:04:20 -0400 | [diff] [blame] | 562 | this->onFinishFlush(proxies, n, access, info, externalRequests); |
Brian Salomon | 9ff5acb | 2019-05-08 09:04:47 -0400 | [diff] [blame] | 563 | return this->caps()->semaphoreSupport() ? GrSemaphoresSubmitted::kYes |
Greg Daniel | 5131678 | 2017-08-02 15:10:09 +0000 | [diff] [blame] | 564 | : GrSemaphoresSubmitted::kNo; |
| 565 | } |
Brian Osman | 71a1889 | 2017-08-10 10:23:25 -0400 | [diff] [blame] | 566 | |
Kevin Lubick | f4def34 | 2018-10-04 12:52:50 -0400 | [diff] [blame] | 567 | #ifdef SK_ENABLE_DUMP_GPU |
Brian Osman | 71a1889 | 2017-08-10 10:23:25 -0400 | [diff] [blame] | 568 | void GrGpu::dumpJSON(SkJSONWriter* writer) const { |
| 569 | writer->beginObject(); |
| 570 | |
| 571 | // TODO: Is there anything useful in the base class to dump here? |
| 572 | |
| 573 | this->onDumpJSON(writer); |
| 574 | |
| 575 | writer->endObject(); |
| 576 | } |
Kevin Lubick | f4def34 | 2018-10-04 12:52:50 -0400 | [diff] [blame] | 577 | #else |
| 578 | void GrGpu::dumpJSON(SkJSONWriter* writer) const { } |
| 579 | #endif |
Robert Phillips | 646f637 | 2018-09-25 09:31:10 -0400 | [diff] [blame] | 580 | |
Robert Phillips | f0ced62 | 2019-05-16 09:06:25 -0400 | [diff] [blame] | 581 | #if GR_TEST_UTILS |
| 582 | |
Robert Phillips | dbaf317 | 2019-02-06 15:12:53 -0500 | [diff] [blame] | 583 | #if GR_GPU_STATS |
| 584 | void GrGpu::Stats::dump(SkString* out) { |
| 585 | out->appendf("Render Target Binds: %d\n", fRenderTargetBinds); |
| 586 | out->appendf("Shader Compilations: %d\n", fShaderCompilations); |
| 587 | out->appendf("Textures Created: %d\n", fTextureCreates); |
| 588 | out->appendf("Texture Uploads: %d\n", fTextureUploads); |
| 589 | out->appendf("Transfers to Texture: %d\n", fTransfersToTexture); |
Brian Salomon | e05ba5a | 2019-04-08 11:59:07 -0400 | [diff] [blame] | 590 | out->appendf("Transfers from Surface: %d\n", fTransfersFromSurface); |
Robert Phillips | dbaf317 | 2019-02-06 15:12:53 -0500 | [diff] [blame] | 591 | out->appendf("Stencil Buffer Creates: %d\n", fStencilAttachmentCreates); |
| 592 | out->appendf("Number of draws: %d\n", fNumDraws); |
Robert Phillips | f9fcf7f | 2019-07-11 09:03:27 -0400 | [diff] [blame] | 593 | out->appendf("Number of Scratch Textures reused %d\n", fNumScratchTexturesReused); |
Robert Phillips | dbaf317 | 2019-02-06 15:12:53 -0500 | [diff] [blame] | 594 | } |
| 595 | |
| 596 | void GrGpu::Stats::dumpKeyValuePairs(SkTArray<SkString>* keys, SkTArray<double>* values) { |
| 597 | keys->push_back(SkString("render_target_binds")); values->push_back(fRenderTargetBinds); |
| 598 | keys->push_back(SkString("shader_compilations")); values->push_back(fShaderCompilations); |
Robert Phillips | dbaf317 | 2019-02-06 15:12:53 -0500 | [diff] [blame] | 599 | } |
| 600 | |
| 601 | #endif |
| 602 | |
Robert Phillips | 646f637 | 2018-09-25 09:31:10 -0400 | [diff] [blame] | 603 | #endif |