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 | d2a8ae2 | 2019-09-10 16:03:59 -0400 | [diff] [blame] | 102 | static bool validate_texel_levels(int w, int h, const GrMipLevel* texels, int mipLevelCount, |
| 103 | int bpp, const GrCaps* caps) { |
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 | d2a8ae2 | 2019-09-10 16:03:59 -0400 | [diff] [blame] | 141 | return levelsWithPixelsCnt == 1 || levelsWithPixelsCnt == mipLevelCount; |
Brian Salomon | 1047a49 | 2019-07-02 12:25:21 -0400 | [diff] [blame] | 142 | } |
| 143 | |
Brian Salomon | 81536f2 | 2019-08-08 16:30:49 -0400 | [diff] [blame] | 144 | sk_sp<GrTexture> GrGpu::createTexture(const GrSurfaceDesc& desc, |
| 145 | const GrBackendFormat& format, |
| 146 | GrRenderable renderable, |
| 147 | int renderTargetSampleCnt, |
| 148 | SkBudgeted budgeted, |
| 149 | GrProtected isProtected, |
| 150 | const GrMipLevel texels[], |
Brian Salomon | d2a8ae2 | 2019-09-10 16:03:59 -0400 | [diff] [blame] | 151 | int texelLevelCount) { |
Brian Salomon | e39526b | 2019-06-24 16:35:53 -0400 | [diff] [blame] | 152 | TRACE_EVENT0("skia.gpu", TRACE_FUNC); |
Brian Salomon | 81536f2 | 2019-08-08 16:30:49 -0400 | [diff] [blame] | 153 | if (this->caps()->isFormatCompressed(format)) { |
Brian Salomon | bb8dde8 | 2019-06-27 10:52:13 -0400 | [diff] [blame] | 154 | // Call GrGpu::createCompressedTexture. |
| 155 | return nullptr; |
| 156 | } |
cblume | 55f2d2d | 2016-02-26 13:20:48 -0800 | [diff] [blame] | 157 | |
Brian Salomon | d2a8ae2 | 2019-09-10 16:03:59 -0400 | [diff] [blame] | 158 | GrMipMapped mipMapped = texelLevelCount > 1 ? GrMipMapped::kYes : GrMipMapped::kNo; |
Greg Daniel | 6fa62e2 | 2019-08-07 15:52:37 -0400 | [diff] [blame] | 159 | if (!this->caps()->validateSurfaceParams({desc.fWidth, desc.fHeight}, format, desc.fConfig, |
| 160 | renderable, renderTargetSampleCnt, mipMapped)) { |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 161 | return nullptr; |
egdaniel | 8c9b6f1 | 2015-05-12 13:36:30 -0700 | [diff] [blame] | 162 | } |
| 163 | |
Brian Salomon | f2c2ba9 | 2019-07-17 09:59:59 -0400 | [diff] [blame] | 164 | if (renderable == GrRenderable::kYes) { |
Brian Salomon | 27b4d8d | 2019-07-22 14:23:45 -0400 | [diff] [blame] | 165 | renderTargetSampleCnt = |
Greg Daniel | 6fa62e2 | 2019-08-07 15:52:37 -0400 | [diff] [blame] | 166 | this->caps()->getRenderTargetSampleCount(renderTargetSampleCnt, format); |
Brian Salomon | bdecacf | 2018-02-02 20:32:49 -0500 | [diff] [blame] | 167 | } |
Brian Salomon | d17b4a6 | 2017-05-23 16:53:47 -0400 | [diff] [blame] | 168 | // Attempt to catch un- or wrongly initialized sample counts. |
Brian Salomon | 27b4d8d | 2019-07-22 14:23:45 -0400 | [diff] [blame] | 169 | SkASSERT(renderTargetSampleCnt > 0 && renderTargetSampleCnt <= 64); |
Brian Salomon | d2a8ae2 | 2019-09-10 16:03:59 -0400 | [diff] [blame] | 170 | if (texelLevelCount) { |
Brian Salomon | 1047a49 | 2019-07-02 12:25:21 -0400 | [diff] [blame] | 171 | int bpp = GrBytesPerPixel(desc.fConfig); |
Brian Salomon | d2a8ae2 | 2019-09-10 16:03:59 -0400 | [diff] [blame] | 172 | if (!validate_texel_levels(desc.fWidth, desc.fHeight, texels, texelLevelCount, bpp, |
| 173 | this->caps())) { |
Brian Salomon | 1047a49 | 2019-07-02 12:25:21 -0400 | [diff] [blame] | 174 | return nullptr; |
| 175 | } |
Brian Salomon | d2a8ae2 | 2019-09-10 16:03:59 -0400 | [diff] [blame] | 176 | } |
| 177 | |
| 178 | int mipLevelCount = SkTMax(1, texelLevelCount); |
| 179 | uint32_t levelClearMask = 0; |
| 180 | if (this->caps()->shouldInitializeTextures()) { |
| 181 | if (texelLevelCount) { |
| 182 | for (int i = 0; i < mipLevelCount; ++i) { |
| 183 | if (!texels->fPixels) { |
| 184 | levelClearMask |= static_cast<uint32_t>(1 << i); |
| 185 | } |
| 186 | } |
| 187 | } else { |
| 188 | levelClearMask = static_cast<uint32_t>((1 << mipLevelCount) - 1); |
| 189 | } |
Brian Salomon | d17b4a6 | 2017-05-23 16:53:47 -0400 | [diff] [blame] | 190 | } |
| 191 | |
Robert Phillips | 92de631 | 2017-05-23 07:43:48 -0400 | [diff] [blame] | 192 | this->handleDirtyContext(); |
Brian Salomon | 81536f2 | 2019-08-08 16:30:49 -0400 | [diff] [blame] | 193 | sk_sp<GrTexture> tex = this->onCreateTexture(desc, |
| 194 | format, |
| 195 | renderable, |
| 196 | renderTargetSampleCnt, |
| 197 | budgeted, |
| 198 | isProtected, |
Brian Salomon | d2a8ae2 | 2019-09-10 16:03:59 -0400 | [diff] [blame] | 199 | mipLevelCount, |
| 200 | levelClearMask); |
| 201 | |
bsalomon | b12ea41 | 2015-02-02 21:19:50 -0800 | [diff] [blame] | 202 | if (tex) { |
Brian Salomon | d2a8ae2 | 2019-09-10 16:03:59 -0400 | [diff] [blame] | 203 | SkASSERT(tex->backendFormat() == format); |
| 204 | SkASSERT(GrRenderable::kNo == renderable || tex->asRenderTarget()); |
Brian Salomon | f2c2ba9 | 2019-07-17 09:59:59 -0400 | [diff] [blame] | 205 | if (!this->caps()->reuseScratchTextures() && renderable == GrRenderable::kNo) { |
cblume | 55f2d2d | 2016-02-26 13:20:48 -0800 | [diff] [blame] | 206 | tex->resourcePriv().removeScratchKey(); |
| 207 | } |
bsalomon | b12ea41 | 2015-02-02 21:19:50 -0800 | [diff] [blame] | 208 | fStats.incTextureCreates(); |
Brian Salomon | d2a8ae2 | 2019-09-10 16:03:59 -0400 | [diff] [blame] | 209 | bool markMipLevelsClean = false; |
| 210 | // Currently if level 0 does not have pixels then no other level may, as enforced by |
| 211 | // validate_texel_levels. |
| 212 | if (texelLevelCount && texels[0].fPixels) { |
| 213 | auto textureColorType = GrPixelConfigToColorType(desc.fConfig); |
| 214 | auto dataColorType = textureColorType; |
| 215 | if (!this->writePixels(tex.get(), 0, 0, desc.fWidth, desc.fHeight, textureColorType, |
| 216 | dataColorType, texels, texelLevelCount)) { |
| 217 | return nullptr; |
cblume | 55f2d2d | 2016-02-26 13:20:48 -0800 | [diff] [blame] | 218 | } |
Brian Salomon | d2a8ae2 | 2019-09-10 16:03:59 -0400 | [diff] [blame] | 219 | // Currently if level[1] of mip map has pixel data then so must all other levels. |
| 220 | // as enforced by validate_texel_levels. |
| 221 | markMipLevelsClean = (texelLevelCount > 1 && !levelClearMask && texels[1].fPixels); |
| 222 | fStats.incTextureUploads(); |
| 223 | } else if (levelClearMask && mipLevelCount > 1) { |
| 224 | markMipLevelsClean = true; |
bsalomon | b12ea41 | 2015-02-02 21:19:50 -0800 | [diff] [blame] | 225 | } |
Brian Salomon | d2a8ae2 | 2019-09-10 16:03:59 -0400 | [diff] [blame] | 226 | if (markMipLevelsClean) { |
| 227 | tex->texturePriv().markMipMapsClean(); |
| 228 | } |
Chris Dalton | 3f7932e | 2019-08-19 00:39:13 -0600 | [diff] [blame] | 229 | if (renderTargetSampleCnt > 1 && !this->caps()->msaaResolvesAutomatically()) { |
| 230 | SkASSERT(GrRenderable::kYes == renderable); |
| 231 | tex->asRenderTarget()->setRequiresManualMSAAResolve(); |
| 232 | } |
bsalomon | b12ea41 | 2015-02-02 21:19:50 -0800 | [diff] [blame] | 233 | } |
bsalomon@google.com | 81c3f8d | 2011-08-03 15:18:33 +0000 | [diff] [blame] | 234 | return tex; |
| 235 | } |
| 236 | |
Brian Salomon | 4eb38b7 | 2019-08-05 12:58:39 -0400 | [diff] [blame] | 237 | sk_sp<GrTexture> GrGpu::createTexture(const GrSurfaceDesc& desc, const GrBackendFormat& format, |
| 238 | GrRenderable renderable, int renderTargetSampleCnt, |
| 239 | SkBudgeted budgeted, GrProtected isProtected) { |
| 240 | return this->createTexture(desc, format, renderable, renderTargetSampleCnt, budgeted, |
| 241 | isProtected, nullptr, 0); |
Brian Salomon | c7dced5 | 2019-07-18 15:02:01 +0000 | [diff] [blame] | 242 | } |
| 243 | |
Brian Salomon | bb8dde8 | 2019-06-27 10:52:13 -0400 | [diff] [blame] | 244 | sk_sp<GrTexture> GrGpu::createCompressedTexture(int width, int height, |
Greg Daniel | 7bfc913 | 2019-08-14 14:23:53 -0400 | [diff] [blame] | 245 | const GrBackendFormat& format, |
Brian Salomon | bb8dde8 | 2019-06-27 10:52:13 -0400 | [diff] [blame] | 246 | SkImage::CompressionType compressionType, |
| 247 | SkBudgeted budgeted, const void* data, |
| 248 | size_t dataSize) { |
Greg Daniel | 7bfc913 | 2019-08-14 14:23:53 -0400 | [diff] [blame] | 249 | // If we ever add a new CompressionType, we should add a check here to make sure the |
| 250 | // GrBackendFormat and CompressionType are compatible with eachother. |
| 251 | SkASSERT(compressionType == SkImage::kETC1_CompressionType); |
| 252 | |
Brian Salomon | bb8dde8 | 2019-06-27 10:52:13 -0400 | [diff] [blame] | 253 | this->handleDirtyContext(); |
| 254 | if (width < 1 || width > this->caps()->maxTextureSize() || |
| 255 | height < 1 || height > this->caps()->maxTextureSize()) { |
| 256 | return nullptr; |
| 257 | } |
Brian Salomon | a3e2996 | 2019-07-16 11:52:08 -0400 | [diff] [blame] | 258 | // Note if we relax the requirement that data must be provided then we must check |
| 259 | // caps()->shouldInitializeTextures() here. |
Brian Salomon | bb8dde8 | 2019-06-27 10:52:13 -0400 | [diff] [blame] | 260 | if (!data) { |
| 261 | return nullptr; |
| 262 | } |
Greg Daniel | 7bfc913 | 2019-08-14 14:23:53 -0400 | [diff] [blame] | 263 | if (!this->caps()->isFormatTexturable(format)) { |
Brian Salomon | bb8dde8 | 2019-06-27 10:52:13 -0400 | [diff] [blame] | 264 | return nullptr; |
| 265 | } |
| 266 | if (dataSize < GrCompressedDataSize(compressionType, width, height)) { |
| 267 | return nullptr; |
| 268 | } |
Greg Daniel | 7bfc913 | 2019-08-14 14:23:53 -0400 | [diff] [blame] | 269 | return this->onCreateCompressedTexture(width, height, format, compressionType, budgeted, data); |
Brian Salomon | bb8dde8 | 2019-06-27 10:52:13 -0400 | [diff] [blame] | 270 | } |
| 271 | |
Greg Daniel | 7ef28f3 | 2017-04-20 16:41:55 +0000 | [diff] [blame] | 272 | sk_sp<GrTexture> GrGpu::wrapBackendTexture(const GrBackendTexture& backendTex, |
Robert Phillips | c80b0e9 | 2019-07-23 10:27:09 -0400 | [diff] [blame] | 273 | GrColorType colorType, |
Brian Salomon | fa2ebea | 2019-01-24 15:58:58 -0500 | [diff] [blame] | 274 | GrWrapOwnership ownership, GrWrapCacheable cacheable, |
| 275 | GrIOType ioType) { |
Brian Salomon | c67c31c | 2018-12-06 10:00:03 -0500 | [diff] [blame] | 276 | SkASSERT(ioType != kWrite_GrIOType); |
bsalomon@google.com | e269f21 | 2011-11-07 13:29:52 +0000 | [diff] [blame] | 277 | this->handleDirtyContext(); |
Robert Phillips | c80b0e9 | 2019-07-23 10:27:09 -0400 | [diff] [blame] | 278 | |
| 279 | const GrCaps* caps = this->caps(); |
| 280 | SkASSERT(caps); |
| 281 | |
Greg Daniel | 7bfc913 | 2019-08-14 14:23:53 -0400 | [diff] [blame] | 282 | if (!caps->isFormatTexturable(backendTex.getBackendFormat())) { |
bsalomon | 5b30c6f | 2015-12-17 14:17:34 -0800 | [diff] [blame] | 283 | return nullptr; |
| 284 | } |
Robert Phillips | c80b0e9 | 2019-07-23 10:27:09 -0400 | [diff] [blame] | 285 | if (backendTex.width() > caps->maxTextureSize() || |
| 286 | backendTex.height() > caps->maxTextureSize()) { |
bsalomon | 5b30c6f | 2015-12-17 14:17:34 -0800 | [diff] [blame] | 287 | return nullptr; |
| 288 | } |
Robert Phillips | c80b0e9 | 2019-07-23 10:27:09 -0400 | [diff] [blame] | 289 | |
Robert Phillips | c80b0e9 | 2019-07-23 10:27:09 -0400 | [diff] [blame] | 290 | return this->onWrapBackendTexture(backendTex, colorType, ownership, cacheable, ioType); |
Brian Salomon | d17f658 | 2017-07-19 18:28:58 -0400 | [diff] [blame] | 291 | } |
Eric Karl | 5c77975 | 2017-05-08 12:02:07 -0700 | [diff] [blame] | 292 | |
Brian Salomon | d17f658 | 2017-07-19 18:28:58 -0400 | [diff] [blame] | 293 | sk_sp<GrTexture> GrGpu::wrapRenderableBackendTexture(const GrBackendTexture& backendTex, |
Robert Phillips | 0902c98 | 2019-07-16 07:47:56 -0400 | [diff] [blame] | 294 | int sampleCnt, GrColorType colorType, |
| 295 | GrWrapOwnership ownership, |
Brian Salomon | aa6ca0a | 2019-01-24 16:03:07 -0500 | [diff] [blame] | 296 | GrWrapCacheable cacheable) { |
Brian Salomon | d17f658 | 2017-07-19 18:28:58 -0400 | [diff] [blame] | 297 | this->handleDirtyContext(); |
Brian Salomon | bdecacf | 2018-02-02 20:32:49 -0500 | [diff] [blame] | 298 | if (sampleCnt < 1) { |
| 299 | return nullptr; |
| 300 | } |
Robert Phillips | 0902c98 | 2019-07-16 07:47:56 -0400 | [diff] [blame] | 301 | |
| 302 | const GrCaps* caps = this->caps(); |
| 303 | |
Greg Daniel | 7bfc913 | 2019-08-14 14:23:53 -0400 | [diff] [blame] | 304 | if (!caps->isFormatTexturable(backendTex.getBackendFormat()) || |
Greg Daniel | 6fa62e2 | 2019-08-07 15:52:37 -0400 | [diff] [blame] | 305 | !caps->isFormatRenderable(backendTex.getBackendFormat(), sampleCnt)) { |
Brian Salomon | d17f658 | 2017-07-19 18:28:58 -0400 | [diff] [blame] | 306 | return nullptr; |
| 307 | } |
| 308 | |
Robert Phillips | 0902c98 | 2019-07-16 07:47:56 -0400 | [diff] [blame] | 309 | if (backendTex.width() > caps->maxRenderTargetSize() || |
| 310 | backendTex.height() > caps->maxRenderTargetSize()) { |
Brian Salomon | d17f658 | 2017-07-19 18:28:58 -0400 | [diff] [blame] | 311 | return nullptr; |
| 312 | } |
Robert Phillips | 0902c98 | 2019-07-16 07:47:56 -0400 | [diff] [blame] | 313 | sk_sp<GrTexture> tex = this->onWrapRenderableBackendTexture(backendTex, sampleCnt, colorType, |
| 314 | ownership, cacheable); |
Greg Daniel | e320486 | 2018-04-16 11:24:10 -0400 | [diff] [blame] | 315 | SkASSERT(!tex || tex->asRenderTarget()); |
Chris Dalton | 3f7932e | 2019-08-19 00:39:13 -0600 | [diff] [blame] | 316 | if (tex && sampleCnt > 1 && !caps->msaaResolvesAutomatically()) { |
| 317 | tex->asRenderTarget()->setRequiresManualMSAAResolve(); |
| 318 | } |
bungeman | 6bd5284 | 2016-10-27 09:30:08 -0700 | [diff] [blame] | 319 | return tex; |
bsalomon@google.com | e269f21 | 2011-11-07 13:29:52 +0000 | [diff] [blame] | 320 | } |
| 321 | |
Robert Phillips | c80b0e9 | 2019-07-23 10:27:09 -0400 | [diff] [blame] | 322 | sk_sp<GrRenderTarget> GrGpu::wrapBackendRenderTarget(const GrBackendRenderTarget& backendRT, |
| 323 | GrColorType colorType) { |
| 324 | this->handleDirtyContext(); |
| 325 | |
| 326 | const GrCaps* caps = this->caps(); |
| 327 | |
Greg Daniel | 6fa62e2 | 2019-08-07 15:52:37 -0400 | [diff] [blame] | 328 | if (!caps->isFormatRenderable(backendRT.getBackendFormat(), backendRT.sampleCnt())) { |
bsalomon | 5b30c6f | 2015-12-17 14:17:34 -0800 | [diff] [blame] | 329 | return nullptr; |
| 330 | } |
Robert Phillips | c80b0e9 | 2019-07-23 10:27:09 -0400 | [diff] [blame] | 331 | |
| 332 | return this->onWrapBackendRenderTarget(backendRT, colorType); |
bsalomon@google.com | e269f21 | 2011-11-07 13:29:52 +0000 | [diff] [blame] | 333 | } |
| 334 | |
Robert Phillips | c80b0e9 | 2019-07-23 10:27:09 -0400 | [diff] [blame] | 335 | sk_sp<GrRenderTarget> GrGpu::wrapBackendTextureAsRenderTarget(const GrBackendTexture& backendTex, |
| 336 | int sampleCnt, |
| 337 | GrColorType colorType) { |
Brian Salomon | bdecacf | 2018-02-02 20:32:49 -0500 | [diff] [blame] | 338 | this->handleDirtyContext(); |
Robert Phillips | c80b0e9 | 2019-07-23 10:27:09 -0400 | [diff] [blame] | 339 | |
| 340 | const GrCaps* caps = this->caps(); |
| 341 | |
| 342 | int maxSize = caps->maxTextureSize(); |
| 343 | if (backendTex.width() > maxSize || backendTex.height() > maxSize) { |
| 344 | return nullptr; |
| 345 | } |
| 346 | |
Greg Daniel | 6fa62e2 | 2019-08-07 15:52:37 -0400 | [diff] [blame] | 347 | if (!caps->isFormatRenderable(backendTex.getBackendFormat(), sampleCnt)) { |
Robert Phillips | c80b0e9 | 2019-07-23 10:27:09 -0400 | [diff] [blame] | 348 | return nullptr; |
| 349 | } |
Robert Phillips | 1cd1ed8 | 2019-07-23 13:21:01 -0400 | [diff] [blame] | 350 | |
Chris Dalton | 3f7932e | 2019-08-19 00:39:13 -0600 | [diff] [blame] | 351 | auto rt = this->onWrapBackendTextureAsRenderTarget(backendTex, sampleCnt, colorType); |
| 352 | if (rt && sampleCnt > 1 && !this->caps()->msaaResolvesAutomatically()) { |
| 353 | rt->setRequiresManualMSAAResolve(); |
| 354 | } |
| 355 | return rt; |
ericrk | f7b8b8a | 2016-02-24 14:49:51 -0800 | [diff] [blame] | 356 | } |
| 357 | |
Greg Daniel | b46add8 | 2019-01-02 14:51:29 -0500 | [diff] [blame] | 358 | sk_sp<GrRenderTarget> GrGpu::wrapVulkanSecondaryCBAsRenderTarget(const SkImageInfo& imageInfo, |
| 359 | const GrVkDrawableInfo& vkInfo) { |
| 360 | return this->onWrapVulkanSecondaryCBAsRenderTarget(imageInfo, vkInfo); |
| 361 | } |
| 362 | |
| 363 | sk_sp<GrRenderTarget> GrGpu::onWrapVulkanSecondaryCBAsRenderTarget(const SkImageInfo& imageInfo, |
| 364 | const GrVkDrawableInfo& vkInfo) { |
| 365 | // This is only supported on Vulkan so we default to returning nullptr here |
| 366 | return nullptr; |
| 367 | } |
| 368 | |
Brian Salomon | dbf7072 | 2019-02-07 11:31:24 -0500 | [diff] [blame] | 369 | sk_sp<GrGpuBuffer> GrGpu::createBuffer(size_t size, GrGpuBufferType intendedType, |
| 370 | GrAccessPattern accessPattern, const void* data) { |
Brian Salomon | e39526b | 2019-06-24 16:35:53 -0400 | [diff] [blame] | 371 | TRACE_EVENT0("skia.gpu", TRACE_FUNC); |
bsalomon@google.com | a7f84e1 | 2011-03-10 14:13:19 +0000 | [diff] [blame] | 372 | this->handleDirtyContext(); |
Brian Salomon | dbf7072 | 2019-02-07 11:31:24 -0500 | [diff] [blame] | 373 | sk_sp<GrGpuBuffer> buffer = this->onCreateBuffer(size, intendedType, accessPattern, data); |
robertphillips | 1b8e1b5 | 2015-06-24 06:54:10 -0700 | [diff] [blame] | 374 | if (!this->caps()->reuseScratchBuffers()) { |
cdalton | 397536c | 2016-03-25 12:15:03 -0700 | [diff] [blame] | 375 | buffer->resourcePriv().removeScratchKey(); |
robertphillips | 1b8e1b5 | 2015-06-24 06:54:10 -0700 | [diff] [blame] | 376 | } |
cdalton | 397536c | 2016-03-25 12:15:03 -0700 | [diff] [blame] | 377 | return buffer; |
jvanverth | 73063dc | 2015-12-03 09:15:47 -0800 | [diff] [blame] | 378 | } |
| 379 | |
Greg Daniel | 46cfbc6 | 2019-06-07 11:43:30 -0400 | [diff] [blame] | 380 | bool GrGpu::copySurface(GrSurface* dst, GrSurface* src, const SkIRect& srcRect, |
Greg Daniel | e227fe4 | 2019-08-21 13:52:24 -0400 | [diff] [blame] | 381 | const SkIPoint& dstPoint) { |
Brian Salomon | e39526b | 2019-06-24 16:35:53 -0400 | [diff] [blame] | 382 | TRACE_EVENT0("skia.gpu", TRACE_FUNC); |
joshualitt | 1cbdcde | 2015-08-21 11:53:29 -0700 | [diff] [blame] | 383 | SkASSERT(dst && src); |
Brian Salomon | c67c31c | 2018-12-06 10:00:03 -0500 | [diff] [blame] | 384 | |
| 385 | if (dst->readOnly()) { |
| 386 | return false; |
| 387 | } |
| 388 | |
joshualitt | 1cbdcde | 2015-08-21 11:53:29 -0700 | [diff] [blame] | 389 | this->handleDirtyContext(); |
Brian Salomon | c67c31c | 2018-12-06 10:00:03 -0500 | [diff] [blame] | 390 | |
Greg Daniel | e227fe4 | 2019-08-21 13:52:24 -0400 | [diff] [blame] | 391 | return this->onCopySurface(dst, src, srcRect, dstPoint); |
joshualitt | 1cbdcde | 2015-08-21 11:53:29 -0700 | [diff] [blame] | 392 | } |
| 393 | |
Brian Salomon | a694870 | 2018-06-01 15:33:20 -0400 | [diff] [blame] | 394 | bool GrGpu::readPixels(GrSurface* surface, int left, int top, int width, int height, |
Brian Salomon | f77c146 | 2019-08-01 15:19:29 -0400 | [diff] [blame] | 395 | GrColorType surfaceColorType, GrColorType dstColorType, void* buffer, |
| 396 | size_t rowBytes) { |
Brian Salomon | e39526b | 2019-06-24 16:35:53 -0400 | [diff] [blame] | 397 | TRACE_EVENT0("skia.gpu", TRACE_FUNC); |
Brian Salomon | bf7b620 | 2016-11-11 16:08:03 -0500 | [diff] [blame] | 398 | SkASSERT(surface); |
Greg Daniel | 7bfc913 | 2019-08-14 14:23:53 -0400 | [diff] [blame] | 399 | SkASSERT(this->caps()->isFormatTexturable(surface->backendFormat())); |
Brian Salomon | bf7b620 | 2016-11-11 16:08:03 -0500 | [diff] [blame] | 400 | |
Brian Salomon | 1d43530 | 2019-07-01 13:05:28 -0400 | [diff] [blame] | 401 | auto subRect = SkIRect::MakeXYWH(left, top, width, height); |
| 402 | auto bounds = SkIRect::MakeWH(surface->width(), surface->height()); |
| 403 | if (!bounds.contains(subRect)) { |
egdaniel | 6d901da | 2015-07-30 12:02:15 -0700 | [diff] [blame] | 404 | return false; |
| 405 | } |
| 406 | |
Brian Salomon | 1047a49 | 2019-07-02 12:25:21 -0400 | [diff] [blame] | 407 | size_t minRowBytes = SkToSizeT(GrColorTypeBytesPerPixel(dstColorType) * width); |
| 408 | if (!this->caps()->readPixelsRowBytesSupport()) { |
| 409 | if (rowBytes != minRowBytes) { |
| 410 | return false; |
| 411 | } |
| 412 | } else { |
| 413 | if (rowBytes < minRowBytes) { |
| 414 | return false; |
| 415 | } |
| 416 | if (rowBytes % GrColorTypeBytesPerPixel(dstColorType)) { |
| 417 | return false; |
| 418 | } |
| 419 | } |
| 420 | |
Brian Salomon | 1c53a9f | 2019-08-12 14:10:12 -0400 | [diff] [blame] | 421 | if (this->caps()->isFormatCompressed(surface->backendFormat())) { |
Jim Van Verth | 1676cb9 | 2019-01-15 13:24:45 -0500 | [diff] [blame] | 422 | return false; |
| 423 | } |
| 424 | |
Brian Salomon | bf7b620 | 2016-11-11 16:08:03 -0500 | [diff] [blame] | 425 | this->handleDirtyContext(); |
| 426 | |
Brian Salomon | f77c146 | 2019-08-01 15:19:29 -0400 | [diff] [blame] | 427 | return this->onReadPixels(surface, left, top, width, height, surfaceColorType, dstColorType, |
| 428 | buffer, rowBytes); |
bsalomon@google.com | a7f84e1 | 2011-03-10 14:13:19 +0000 | [diff] [blame] | 429 | } |
| 430 | |
Brian Salomon | a9b04b9 | 2018-06-01 15:04:28 -0400 | [diff] [blame] | 431 | bool GrGpu::writePixels(GrSurface* surface, int left, int top, int width, int height, |
Brian Salomon | f77c146 | 2019-08-01 15:19:29 -0400 | [diff] [blame] | 432 | GrColorType surfaceColorType, GrColorType srcColorType, |
Greg Daniel | b20d7e5 | 2019-09-03 13:54:39 -0400 | [diff] [blame] | 433 | const GrMipLevel texels[], int mipLevelCount, bool prepForTexSampling) { |
Brian Salomon | e39526b | 2019-06-24 16:35:53 -0400 | [diff] [blame] | 434 | TRACE_EVENT0("skia.gpu", TRACE_FUNC); |
Brian Salomon | bf7b620 | 2016-11-11 16:08:03 -0500 | [diff] [blame] | 435 | SkASSERT(surface); |
Greg Daniel | 7bfc913 | 2019-08-14 14:23:53 -0400 | [diff] [blame] | 436 | SkASSERT(this->caps()->isFormatTexturableAndUploadable(surfaceColorType, |
| 437 | surface->backendFormat())); |
Brian Salomon | c67c31c | 2018-12-06 10:00:03 -0500 | [diff] [blame] | 438 | |
| 439 | if (surface->readOnly()) { |
| 440 | return false; |
| 441 | } |
| 442 | |
Brian Salomon | 1047a49 | 2019-07-02 12:25:21 -0400 | [diff] [blame] | 443 | if (mipLevelCount == 0) { |
| 444 | return false; |
| 445 | } else if (mipLevelCount == 1) { |
Greg Daniel | 660cc99 | 2017-06-26 14:55:05 -0400 | [diff] [blame] | 446 | // 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] | 447 | auto subRect = SkIRect::MakeXYWH(left, top, width, height); |
| 448 | auto bounds = SkIRect::MakeWH(surface->width(), surface->height()); |
Greg Daniel | 660cc99 | 2017-06-26 14:55:05 -0400 | [diff] [blame] | 449 | if (!bounds.contains(subRect)) { |
| 450 | return false; |
| 451 | } |
| 452 | } else if (0 != left || 0 != top || width != surface->width() || height != surface->height()) { |
| 453 | // We require that if the texels are mipped, than the write region is the entire surface |
| 454 | return false; |
| 455 | } |
Robert Phillips | b7b7e5f | 2017-05-22 13:23:19 -0400 | [diff] [blame] | 456 | |
Brian Salomon | b28cb68 | 2019-07-26 12:48:47 -0400 | [diff] [blame] | 457 | size_t bpp = GrColorTypeBytesPerPixel(srcColorType); |
Brian Salomon | d2a8ae2 | 2019-09-10 16:03:59 -0400 | [diff] [blame] | 458 | if (!validate_texel_levels(width, height, texels, mipLevelCount, bpp, this->caps())) { |
Brian Salomon | 1047a49 | 2019-07-02 12:25:21 -0400 | [diff] [blame] | 459 | return false; |
cblume | 55f2d2d | 2016-02-26 13:20:48 -0800 | [diff] [blame] | 460 | } |
jvanverth | 2dc2994 | 2015-09-01 07:16:46 -0700 | [diff] [blame] | 461 | |
bsalomon@google.com | 6f37951 | 2011-11-16 20:36:03 +0000 | [diff] [blame] | 462 | this->handleDirtyContext(); |
Brian Salomon | f77c146 | 2019-08-01 15:19:29 -0400 | [diff] [blame] | 463 | if (this->onWritePixels(surface, left, top, width, height, surfaceColorType, srcColorType, |
Greg Daniel | b20d7e5 | 2019-09-03 13:54:39 -0400 | [diff] [blame] | 464 | texels, mipLevelCount, prepForTexSampling)) { |
jvanverth | 900bd4a | 2016-04-29 13:53:12 -0700 | [diff] [blame] | 465 | SkIRect rect = SkIRect::MakeXYWH(left, top, width, height); |
Brian Salomon | a9b04b9 | 2018-06-01 15:04:28 -0400 | [diff] [blame] | 466 | this->didWriteToSurface(surface, kTopLeft_GrSurfaceOrigin, &rect, mipLevelCount); |
bsalomon | b12ea41 | 2015-02-02 21:19:50 -0800 | [diff] [blame] | 467 | fStats.incTextureUploads(); |
| 468 | return true; |
| 469 | } |
| 470 | return false; |
bsalomon@google.com | 6f37951 | 2011-11-16 20:36:03 +0000 | [diff] [blame] | 471 | } |
| 472 | |
Brian Salomon | e05ba5a | 2019-04-08 11:59:07 -0400 | [diff] [blame] | 473 | bool GrGpu::transferPixelsTo(GrTexture* texture, int left, int top, int width, int height, |
Brian Salomon | f77c146 | 2019-08-01 15:19:29 -0400 | [diff] [blame] | 474 | GrColorType textureColorType, GrColorType bufferColorType, |
| 475 | GrGpuBuffer* transferBuffer, size_t offset, size_t rowBytes) { |
Brian Salomon | e39526b | 2019-06-24 16:35:53 -0400 | [diff] [blame] | 476 | TRACE_EVENT0("skia.gpu", TRACE_FUNC); |
Brian Salomon | c67c31c | 2018-12-06 10:00:03 -0500 | [diff] [blame] | 477 | SkASSERT(texture); |
cdalton | 397536c | 2016-03-25 12:15:03 -0700 | [diff] [blame] | 478 | SkASSERT(transferBuffer); |
Greg Daniel | 7bfc913 | 2019-08-14 14:23:53 -0400 | [diff] [blame] | 479 | SkASSERT(this->caps()->isFormatTexturableAndUploadable(textureColorType, |
| 480 | texture->backendFormat())); |
jvanverth | 17aa047 | 2016-01-05 10:41:27 -0800 | [diff] [blame] | 481 | |
Brian Salomon | c67c31c | 2018-12-06 10:00:03 -0500 | [diff] [blame] | 482 | if (texture->readOnly()) { |
| 483 | return false; |
| 484 | } |
| 485 | |
Greg Daniel | 660cc99 | 2017-06-26 14:55:05 -0400 | [diff] [blame] | 486 | // We require that the write region is contained in the texture |
| 487 | SkIRect subRect = SkIRect::MakeXYWH(left, top, width, height); |
| 488 | SkIRect bounds = SkIRect::MakeWH(texture->width(), texture->height()); |
| 489 | if (!bounds.contains(subRect)) { |
| 490 | return false; |
| 491 | } |
| 492 | |
Brian Salomon | b28cb68 | 2019-07-26 12:48:47 -0400 | [diff] [blame] | 493 | size_t bpp = GrColorTypeBytesPerPixel(bufferColorType); |
Brian Salomon | 1047a49 | 2019-07-02 12:25:21 -0400 | [diff] [blame] | 494 | if (this->caps()->writePixelsRowBytesSupport()) { |
| 495 | if (rowBytes < SkToSizeT(bpp * width)) { |
| 496 | return false; |
| 497 | } |
| 498 | if (rowBytes % bpp) { |
| 499 | return false; |
| 500 | } |
| 501 | } else { |
| 502 | if (rowBytes != SkToSizeT(bpp * width)) { |
| 503 | return false; |
| 504 | } |
| 505 | } |
| 506 | |
jvanverth | 17aa047 | 2016-01-05 10:41:27 -0800 | [diff] [blame] | 507 | this->handleDirtyContext(); |
Brian Salomon | f77c146 | 2019-08-01 15:19:29 -0400 | [diff] [blame] | 508 | if (this->onTransferPixelsTo(texture, left, top, width, height, textureColorType, |
| 509 | bufferColorType, transferBuffer, offset, rowBytes)) { |
jvanverth | 900bd4a | 2016-04-29 13:53:12 -0700 | [diff] [blame] | 510 | SkIRect rect = SkIRect::MakeXYWH(left, top, width, height); |
Brian Salomon | 1fabd51 | 2018-02-09 09:54:25 -0500 | [diff] [blame] | 511 | this->didWriteToSurface(texture, kTopLeft_GrSurfaceOrigin, &rect); |
jvanverth | 17aa047 | 2016-01-05 10:41:27 -0800 | [diff] [blame] | 512 | fStats.incTransfersToTexture(); |
jvanverth | 84741b3 | 2016-09-30 08:39:02 -0700 | [diff] [blame] | 513 | |
jvanverth | 17aa047 | 2016-01-05 10:41:27 -0800 | [diff] [blame] | 514 | return true; |
| 515 | } |
| 516 | return false; |
| 517 | } |
| 518 | |
Brian Salomon | 26de56e | 2019-04-10 12:14:26 -0400 | [diff] [blame] | 519 | bool GrGpu::transferPixelsFrom(GrSurface* surface, int left, int top, int width, int height, |
Brian Salomon | f77c146 | 2019-08-01 15:19:29 -0400 | [diff] [blame] | 520 | GrColorType surfaceColorType, GrColorType bufferColorType, |
| 521 | GrGpuBuffer* transferBuffer, size_t offset) { |
Brian Salomon | e39526b | 2019-06-24 16:35:53 -0400 | [diff] [blame] | 522 | TRACE_EVENT0("skia.gpu", TRACE_FUNC); |
Brian Salomon | e05ba5a | 2019-04-08 11:59:07 -0400 | [diff] [blame] | 523 | SkASSERT(surface); |
| 524 | SkASSERT(transferBuffer); |
Greg Daniel | 7bfc913 | 2019-08-14 14:23:53 -0400 | [diff] [blame] | 525 | SkASSERT(this->caps()->isFormatTexturable(surface->backendFormat())); |
Brian Salomon | f77c146 | 2019-08-01 15:19:29 -0400 | [diff] [blame] | 526 | |
Greg Daniel | ba88ab6 | 2019-07-26 09:14:01 -0400 | [diff] [blame] | 527 | #ifdef SK_DEBUG |
Brian Salomon | 1c53a9f | 2019-08-12 14:10:12 -0400 | [diff] [blame] | 528 | auto supportedRead = this->caps()->supportedReadPixelsColorType( |
| 529 | surfaceColorType, surface->backendFormat(), bufferColorType); |
Greg Daniel | ba88ab6 | 2019-07-26 09:14:01 -0400 | [diff] [blame] | 530 | SkASSERT(supportedRead.fOffsetAlignmentForTransferBuffer); |
| 531 | SkASSERT(offset % supportedRead.fOffsetAlignmentForTransferBuffer == 0); |
| 532 | #endif |
Brian Salomon | e05ba5a | 2019-04-08 11:59:07 -0400 | [diff] [blame] | 533 | |
| 534 | // We require that the write region is contained in the texture |
| 535 | SkIRect subRect = SkIRect::MakeXYWH(left, top, width, height); |
| 536 | SkIRect bounds = SkIRect::MakeWH(surface->width(), surface->height()); |
| 537 | if (!bounds.contains(subRect)) { |
| 538 | return false; |
| 539 | } |
| 540 | |
| 541 | this->handleDirtyContext(); |
Brian Salomon | f77c146 | 2019-08-01 15:19:29 -0400 | [diff] [blame] | 542 | if (this->onTransferPixelsFrom(surface, left, top, width, height, surfaceColorType, |
| 543 | bufferColorType, transferBuffer, offset)) { |
Brian Salomon | e05ba5a | 2019-04-08 11:59:07 -0400 | [diff] [blame] | 544 | fStats.incTransfersFromSurface(); |
Brian Salomon | 26de56e | 2019-04-10 12:14:26 -0400 | [diff] [blame] | 545 | return true; |
Brian Salomon | e05ba5a | 2019-04-08 11:59:07 -0400 | [diff] [blame] | 546 | } |
Brian Salomon | 26de56e | 2019-04-10 12:14:26 -0400 | [diff] [blame] | 547 | return false; |
Brian Salomon | e05ba5a | 2019-04-08 11:59:07 -0400 | [diff] [blame] | 548 | } |
| 549 | |
Brian Salomon | 930f939 | 2018-06-20 16:25:26 -0400 | [diff] [blame] | 550 | bool GrGpu::regenerateMipMapLevels(GrTexture* texture) { |
Brian Salomon | e39526b | 2019-06-24 16:35:53 -0400 | [diff] [blame] | 551 | TRACE_EVENT0("skia.gpu", TRACE_FUNC); |
Brian Salomon | 930f939 | 2018-06-20 16:25:26 -0400 | [diff] [blame] | 552 | SkASSERT(texture); |
| 553 | SkASSERT(this->caps()->mipMapSupport()); |
| 554 | SkASSERT(texture->texturePriv().mipMapped() == GrMipMapped::kYes); |
| 555 | SkASSERT(texture->texturePriv().mipMapsAreDirty()); |
| 556 | SkASSERT(!texture->asRenderTarget() || !texture->asRenderTarget()->needsResolve()); |
Brian Salomon | c67c31c | 2018-12-06 10:00:03 -0500 | [diff] [blame] | 557 | if (texture->readOnly()) { |
| 558 | return false; |
| 559 | } |
Brian Salomon | 930f939 | 2018-06-20 16:25:26 -0400 | [diff] [blame] | 560 | if (this->onRegenerateMipMapLevels(texture)) { |
| 561 | texture->texturePriv().markMipMapsClean(); |
| 562 | return true; |
| 563 | } |
| 564 | return false; |
| 565 | } |
| 566 | |
Brian Salomon | 1f05d45 | 2019-02-08 12:33:08 -0500 | [diff] [blame] | 567 | void GrGpu::resetTextureBindings() { |
| 568 | this->handleDirtyContext(); |
| 569 | this->onResetTextureBindings(); |
| 570 | } |
| 571 | |
Brian Salomon | 1fabd51 | 2018-02-09 09:54:25 -0500 | [diff] [blame] | 572 | void GrGpu::resolveRenderTarget(GrRenderTarget* target) { |
tfarina@chromium.org | f6de475 | 2013-08-17 00:02:59 +0000 | [diff] [blame] | 573 | SkASSERT(target); |
bsalomon@google.com | 75f9f25 | 2012-01-31 13:35:56 +0000 | [diff] [blame] | 574 | this->handleDirtyContext(); |
Brian Salomon | 1fabd51 | 2018-02-09 09:54:25 -0500 | [diff] [blame] | 575 | this->onResolveRenderTarget(target); |
bsalomon@google.com | 75f9f25 | 2012-01-31 13:35:56 +0000 | [diff] [blame] | 576 | } |
| 577 | |
Brian Salomon | 1fabd51 | 2018-02-09 09:54:25 -0500 | [diff] [blame] | 578 | void GrGpu::didWriteToSurface(GrSurface* surface, GrSurfaceOrigin origin, const SkIRect* bounds, |
| 579 | uint32_t mipLevels) const { |
jvanverth | 900bd4a | 2016-04-29 13:53:12 -0700 | [diff] [blame] | 580 | SkASSERT(surface); |
Brian Salomon | c67c31c | 2018-12-06 10:00:03 -0500 | [diff] [blame] | 581 | SkASSERT(!surface->readOnly()); |
jvanverth | 900bd4a | 2016-04-29 13:53:12 -0700 | [diff] [blame] | 582 | // Mark any MIP chain and resolve buffer as dirty if and only if there is a non-empty bounds. |
| 583 | if (nullptr == bounds || !bounds->isEmpty()) { |
| 584 | if (GrRenderTarget* target = surface->asRenderTarget()) { |
Brian Salomon | 1fabd51 | 2018-02-09 09:54:25 -0500 | [diff] [blame] | 585 | SkIRect flippedBounds; |
| 586 | if (kBottomLeft_GrSurfaceOrigin == origin && bounds) { |
| 587 | flippedBounds = {bounds->fLeft, surface->height() - bounds->fBottom, |
| 588 | bounds->fRight, surface->height() - bounds->fTop}; |
| 589 | bounds = &flippedBounds; |
| 590 | } |
jvanverth | 900bd4a | 2016-04-29 13:53:12 -0700 | [diff] [blame] | 591 | target->flagAsNeedingResolve(bounds); |
| 592 | } |
| 593 | GrTexture* texture = surface->asTexture(); |
| 594 | if (texture && 1 == mipLevels) { |
Greg Daniel | 0fc4d2d | 2017-10-12 11:23:36 -0400 | [diff] [blame] | 595 | texture->texturePriv().markMipMapsDirty(); |
jvanverth | 900bd4a | 2016-04-29 13:53:12 -0700 | [diff] [blame] | 596 | } |
| 597 | } |
| 598 | } |
| 599 | |
Chris Dalton | 8c4cafd | 2019-04-15 19:14:36 -0600 | [diff] [blame] | 600 | int GrGpu::findOrAssignSamplePatternKey(GrRenderTarget* renderTarget) { |
Chris Dalton | d7291ba | 2019-03-07 14:17:03 -0700 | [diff] [blame] | 601 | SkASSERT(this->caps()->sampleLocationsSupport()); |
Chris Dalton | effee20 | 2019-07-01 22:28:03 -0600 | [diff] [blame] | 602 | SkASSERT(renderTarget->numSamples() > 1 || |
| 603 | (renderTarget->renderTargetPriv().getStencilAttachment() && |
| 604 | renderTarget->renderTargetPriv().getStencilAttachment()->numSamples() > 1)); |
Chris Dalton | d7291ba | 2019-03-07 14:17:03 -0700 | [diff] [blame] | 605 | |
| 606 | SkSTArray<16, SkPoint> sampleLocations; |
Chris Dalton | 8c4cafd | 2019-04-15 19:14:36 -0600 | [diff] [blame] | 607 | this->querySampleLocations(renderTarget, &sampleLocations); |
Chris Dalton | d7291ba | 2019-03-07 14:17:03 -0700 | [diff] [blame] | 608 | return fSamplePatternDictionary.findOrAssignSamplePatternKey(sampleLocations); |
| 609 | } |
| 610 | |
Brian Salomon | f9a1fdf | 2019-05-09 10:30:12 -0400 | [diff] [blame] | 611 | GrSemaphoresSubmitted GrGpu::finishFlush(GrSurfaceProxy* proxies[], |
| 612 | int n, |
Greg Daniel | bae7121 | 2019-03-01 15:24:35 -0500 | [diff] [blame] | 613 | SkSurface::BackendSurfaceAccess access, |
Greg Daniel | 797efca | 2019-05-09 14:04:20 -0400 | [diff] [blame] | 614 | const GrFlushInfo& info, |
| 615 | const GrPrepareForExternalIORequests& externalRequests) { |
Brian Salomon | e39526b | 2019-06-24 16:35:53 -0400 | [diff] [blame] | 616 | TRACE_EVENT0("skia.gpu", TRACE_FUNC); |
Greg Daniel | d207345 | 2018-12-07 11:20:33 -0500 | [diff] [blame] | 617 | this->stats()->incNumFinishFlushes(); |
Robert Phillips | 9da87e0 | 2019-02-04 13:26:26 -0500 | [diff] [blame] | 618 | GrResourceProvider* resourceProvider = fContext->priv().resourceProvider(); |
Robert Phillips | 6be756b | 2018-01-16 15:07:54 -0500 | [diff] [blame] | 619 | |
Brian Salomon | 9ff5acb | 2019-05-08 09:04:47 -0400 | [diff] [blame] | 620 | if (this->caps()->semaphoreSupport()) { |
Greg Daniel | e6bfb7d | 2019-04-17 15:26:11 -0400 | [diff] [blame] | 621 | for (int i = 0; i < info.fNumSemaphores; ++i) { |
Greg Daniel | 5131678 | 2017-08-02 15:10:09 +0000 | [diff] [blame] | 622 | sk_sp<GrSemaphore> semaphore; |
Greg Daniel | e6bfb7d | 2019-04-17 15:26:11 -0400 | [diff] [blame] | 623 | if (info.fSignalSemaphores[i].isInitialized()) { |
Robert Phillips | 6be756b | 2018-01-16 15:07:54 -0500 | [diff] [blame] | 624 | semaphore = resourceProvider->wrapBackendSemaphore( |
Greg Daniel | e6bfb7d | 2019-04-17 15:26:11 -0400 | [diff] [blame] | 625 | info.fSignalSemaphores[i], |
| 626 | GrResourceProvider::SemaphoreWrapType::kWillSignal, |
Greg Daniel | 17b7c05 | 2018-01-09 13:55:33 -0500 | [diff] [blame] | 627 | kBorrow_GrWrapOwnership); |
Greg Daniel | 5131678 | 2017-08-02 15:10:09 +0000 | [diff] [blame] | 628 | } else { |
Robert Phillips | 6be756b | 2018-01-16 15:07:54 -0500 | [diff] [blame] | 629 | semaphore = resourceProvider->makeSemaphore(false); |
Greg Daniel | 5131678 | 2017-08-02 15:10:09 +0000 | [diff] [blame] | 630 | } |
Greg Daniel | 858e12c | 2018-12-06 11:11:37 -0500 | [diff] [blame] | 631 | this->insertSemaphore(semaphore); |
Greg Daniel | 5131678 | 2017-08-02 15:10:09 +0000 | [diff] [blame] | 632 | |
Greg Daniel | e6bfb7d | 2019-04-17 15:26:11 -0400 | [diff] [blame] | 633 | if (!info.fSignalSemaphores[i].isInitialized()) { |
| 634 | info.fSignalSemaphores[i] = semaphore->backendSemaphore(); |
Greg Daniel | 5131678 | 2017-08-02 15:10:09 +0000 | [diff] [blame] | 635 | } |
| 636 | } |
| 637 | } |
Greg Daniel | 797efca | 2019-05-09 14:04:20 -0400 | [diff] [blame] | 638 | this->onFinishFlush(proxies, n, access, info, externalRequests); |
Brian Salomon | 9ff5acb | 2019-05-08 09:04:47 -0400 | [diff] [blame] | 639 | return this->caps()->semaphoreSupport() ? GrSemaphoresSubmitted::kYes |
Greg Daniel | 5131678 | 2017-08-02 15:10:09 +0000 | [diff] [blame] | 640 | : GrSemaphoresSubmitted::kNo; |
| 641 | } |
Brian Osman | 71a1889 | 2017-08-10 10:23:25 -0400 | [diff] [blame] | 642 | |
Kevin Lubick | f4def34 | 2018-10-04 12:52:50 -0400 | [diff] [blame] | 643 | #ifdef SK_ENABLE_DUMP_GPU |
Brian Osman | 71a1889 | 2017-08-10 10:23:25 -0400 | [diff] [blame] | 644 | void GrGpu::dumpJSON(SkJSONWriter* writer) const { |
| 645 | writer->beginObject(); |
| 646 | |
| 647 | // TODO: Is there anything useful in the base class to dump here? |
| 648 | |
| 649 | this->onDumpJSON(writer); |
| 650 | |
| 651 | writer->endObject(); |
| 652 | } |
Kevin Lubick | f4def34 | 2018-10-04 12:52:50 -0400 | [diff] [blame] | 653 | #else |
| 654 | void GrGpu::dumpJSON(SkJSONWriter* writer) const { } |
| 655 | #endif |
Robert Phillips | 646f637 | 2018-09-25 09:31:10 -0400 | [diff] [blame] | 656 | |
Robert Phillips | f0ced62 | 2019-05-16 09:06:25 -0400 | [diff] [blame] | 657 | #if GR_TEST_UTILS |
| 658 | |
Robert Phillips | dbaf317 | 2019-02-06 15:12:53 -0500 | [diff] [blame] | 659 | #if GR_GPU_STATS |
| 660 | void GrGpu::Stats::dump(SkString* out) { |
| 661 | out->appendf("Render Target Binds: %d\n", fRenderTargetBinds); |
| 662 | out->appendf("Shader Compilations: %d\n", fShaderCompilations); |
| 663 | out->appendf("Textures Created: %d\n", fTextureCreates); |
| 664 | out->appendf("Texture Uploads: %d\n", fTextureUploads); |
| 665 | out->appendf("Transfers to Texture: %d\n", fTransfersToTexture); |
Brian Salomon | e05ba5a | 2019-04-08 11:59:07 -0400 | [diff] [blame] | 666 | out->appendf("Transfers from Surface: %d\n", fTransfersFromSurface); |
Robert Phillips | dbaf317 | 2019-02-06 15:12:53 -0500 | [diff] [blame] | 667 | out->appendf("Stencil Buffer Creates: %d\n", fStencilAttachmentCreates); |
| 668 | out->appendf("Number of draws: %d\n", fNumDraws); |
Robert Phillips | f9fcf7f | 2019-07-11 09:03:27 -0400 | [diff] [blame] | 669 | out->appendf("Number of Scratch Textures reused %d\n", fNumScratchTexturesReused); |
Robert Phillips | dbaf317 | 2019-02-06 15:12:53 -0500 | [diff] [blame] | 670 | } |
| 671 | |
| 672 | void GrGpu::Stats::dumpKeyValuePairs(SkTArray<SkString>* keys, SkTArray<double>* values) { |
| 673 | keys->push_back(SkString("render_target_binds")); values->push_back(fRenderTargetBinds); |
| 674 | keys->push_back(SkString("shader_compilations")); values->push_back(fShaderCompilations); |
Robert Phillips | dbaf317 | 2019-02-06 15:12:53 -0500 | [diff] [blame] | 675 | } |
| 676 | |
| 677 | #endif |
| 678 | |
Robert Phillips | 646f637 | 2018-09-25 09:31:10 -0400 | [diff] [blame] | 679 | #endif |