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" |
Robert Phillips | 57ef680 | 2019-09-23 10:12:47 -0400 | [diff] [blame] | 15 | #include "src/core/SkMipMap.h" |
Greg Daniel | f91aeb2 | 2019-06-18 09:58:02 -0400 | [diff] [blame] | 16 | #include "src/gpu/GrAuditTrail.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 17 | #include "src/gpu/GrCaps.h" |
| 18 | #include "src/gpu/GrContextPriv.h" |
Brian Salomon | bb8dde8 | 2019-06-27 10:52:13 -0400 | [diff] [blame] | 19 | #include "src/gpu/GrDataUtils.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 20 | #include "src/gpu/GrGpuResourcePriv.h" |
| 21 | #include "src/gpu/GrMesh.h" |
Chris Dalton | 16a33c6 | 2019-09-24 22:19:17 -0600 | [diff] [blame] | 22 | #include "src/gpu/GrNativeRect.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 23 | #include "src/gpu/GrPathRendering.h" |
| 24 | #include "src/gpu/GrPipeline.h" |
| 25 | #include "src/gpu/GrRenderTargetPriv.h" |
| 26 | #include "src/gpu/GrResourceCache.h" |
| 27 | #include "src/gpu/GrResourceProvider.h" |
| 28 | #include "src/gpu/GrSemaphore.h" |
| 29 | #include "src/gpu/GrStencilAttachment.h" |
| 30 | #include "src/gpu/GrStencilSettings.h" |
| 31 | #include "src/gpu/GrSurfacePriv.h" |
| 32 | #include "src/gpu/GrTexturePriv.h" |
| 33 | #include "src/gpu/GrTextureProxyPriv.h" |
| 34 | #include "src/gpu/GrTracing.h" |
| 35 | #include "src/utils/SkJSONWriter.h" |
bsalomon | cb8979d | 2015-05-05 09:51:38 -0700 | [diff] [blame] | 36 | |
bsalomon@google.com | d302f14 | 2011-03-03 13:54:13 +0000 | [diff] [blame] | 37 | //////////////////////////////////////////////////////////////////////////////// |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 38 | |
Brian Salomon | e2826ab | 2019-06-04 15:58:31 -0400 | [diff] [blame] | 39 | GrGpu::GrGpu(GrContext* context) : fResetBits(kAll_GrBackendState), fContext(context) {} |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 40 | |
bsalomon | ed0bcad | 2015-05-04 10:36:42 -0700 | [diff] [blame] | 41 | GrGpu::~GrGpu() {} |
bsalomon | 1d89ddc | 2014-08-19 14:20:58 -0700 | [diff] [blame] | 42 | |
bsalomon | 6e2aad4 | 2016-04-01 11:54:31 -0700 | [diff] [blame] | 43 | void GrGpu::disconnect(DisconnectType) {} |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 44 | |
bsalomon@google.com | d302f14 | 2011-03-03 13:54:13 +0000 | [diff] [blame] | 45 | //////////////////////////////////////////////////////////////////////////////// |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 46 | |
Brian Salomon | 1a217eb | 2019-10-24 10:50:36 -0400 | [diff] [blame] | 47 | bool GrGpu::IsACopyNeededForRepeatWrapMode(const GrCaps* caps, |
| 48 | GrTextureProxy* texProxy, |
| 49 | SkISize dimensions, |
Greg Daniel | 8f5bbda | 2018-06-08 17:22:23 -0400 | [diff] [blame] | 50 | GrSamplerState::Filter filter, |
| 51 | GrTextureProducer::CopyParams* copyParams, |
| 52 | SkScalar scaleAdjust[2]) { |
| 53 | if (!caps->npotTextureTileSupport() && |
Brian Salomon | 1a217eb | 2019-10-24 10:50:36 -0400 | [diff] [blame] | 54 | (!SkIsPow2(dimensions.width()) || !SkIsPow2(dimensions.height()))) { |
Greg Daniel | 09c9400 | 2018-06-08 22:11:51 +0000 | [diff] [blame] | 55 | SkASSERT(scaleAdjust); |
Brian Salomon | 1a217eb | 2019-10-24 10:50:36 -0400 | [diff] [blame] | 56 | copyParams->fDimensions = {SkNextPow2(dimensions.width()), SkNextPow2(dimensions.height())}; |
Greg Daniel | 09c9400 | 2018-06-08 22:11:51 +0000 | [diff] [blame] | 57 | SkASSERT(scaleAdjust); |
Brian Salomon | 1a217eb | 2019-10-24 10:50:36 -0400 | [diff] [blame] | 58 | scaleAdjust[0] = ((SkScalar)copyParams->fDimensions.width()) / dimensions.width(); |
| 59 | scaleAdjust[1] = ((SkScalar)copyParams->fDimensions.height()) / dimensions.height(); |
Greg Daniel | 8f5bbda | 2018-06-08 17:22:23 -0400 | [diff] [blame] | 60 | switch (filter) { |
Greg Daniel | 09c9400 | 2018-06-08 22:11:51 +0000 | [diff] [blame] | 61 | case GrSamplerState::Filter::kNearest: |
| 62 | copyParams->fFilter = GrSamplerState::Filter::kNearest; |
| 63 | break; |
| 64 | case GrSamplerState::Filter::kBilerp: |
| 65 | case GrSamplerState::Filter::kMipMap: |
| 66 | // We are only ever scaling up so no reason to ever indicate kMipMap. |
| 67 | copyParams->fFilter = GrSamplerState::Filter::kBilerp; |
| 68 | break; |
| 69 | } |
| 70 | return true; |
| 71 | } |
Robert Phillips | abf7b76 | 2018-03-21 12:13:37 -0400 | [diff] [blame] | 72 | |
| 73 | if (texProxy) { |
| 74 | // If the texture format itself doesn't support repeat wrap mode or mipmapping (and |
| 75 | // those capabilities are required) force a copy. |
Brian Salomon | fd98c2c | 2018-07-31 17:25:29 -0400 | [diff] [blame] | 76 | if (texProxy->hasRestrictedSampling()) { |
Robert Phillips | abf7b76 | 2018-03-21 12:13:37 -0400 | [diff] [blame] | 77 | copyParams->fFilter = GrSamplerState::Filter::kNearest; |
Brian Salomon | 1a217eb | 2019-10-24 10:50:36 -0400 | [diff] [blame] | 78 | copyParams->fDimensions = texProxy->dimensions(); |
Robert Phillips | abf7b76 | 2018-03-21 12:13:37 -0400 | [diff] [blame] | 79 | return true; |
| 80 | } |
| 81 | } |
| 82 | |
bsalomon | 100b8f8 | 2015-10-28 08:37:44 -0700 | [diff] [blame] | 83 | return false; |
bsalomon | 045802d | 2015-10-20 07:58:01 -0700 | [diff] [blame] | 84 | } |
| 85 | |
Greg Daniel | 8f5bbda | 2018-06-08 17:22:23 -0400 | [diff] [blame] | 86 | bool GrGpu::IsACopyNeededForMips(const GrCaps* caps, const GrTextureProxy* texProxy, |
| 87 | GrSamplerState::Filter filter, |
| 88 | GrTextureProducer::CopyParams* copyParams) { |
| 89 | SkASSERT(texProxy); |
| 90 | bool willNeedMips = GrSamplerState::Filter::kMipMap == filter && caps->mipMapSupport(); |
| 91 | // If the texture format itself doesn't support mipmapping (and those capabilities are required) |
| 92 | // force a copy. |
| 93 | if (willNeedMips && texProxy->mipMapped() == GrMipMapped::kNo) { |
| 94 | copyParams->fFilter = GrSamplerState::Filter::kNearest; |
Brian Salomon | 1a217eb | 2019-10-24 10:50:36 -0400 | [diff] [blame] | 95 | copyParams->fDimensions = texProxy->dimensions(); |
Greg Daniel | 8f5bbda | 2018-06-08 17:22:23 -0400 | [diff] [blame] | 96 | return true; |
| 97 | } |
| 98 | |
| 99 | return false; |
| 100 | } |
| 101 | |
Brian Salomon | a90382f | 2019-09-17 09:01:56 -0400 | [diff] [blame] | 102 | static bool validate_texel_levels(int w, int h, GrColorType texelColorType, |
| 103 | const GrMipLevel* texels, int mipLevelCount, 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; |
Brian Salomon | a90382f | 2019-09-17 09:01:56 -0400 | [diff] [blame] | 107 | auto bpp = GrColorTypeBytesPerPixel(texelColorType); |
Brian Salomon | 1047a49 | 2019-07-02 12:25:21 -0400 | [diff] [blame] | 108 | for (int currentMipLevel = 0; currentMipLevel < mipLevelCount; ++currentMipLevel) { |
| 109 | if (texels[currentMipLevel].fPixels) { |
| 110 | const size_t minRowBytes = w * bpp; |
| 111 | if (caps->writePixelsRowBytesSupport()) { |
| 112 | if (texels[currentMipLevel].fRowBytes < minRowBytes) { |
| 113 | return false; |
| 114 | } |
| 115 | if (texels[currentMipLevel].fRowBytes % bpp) { |
| 116 | return false; |
| 117 | } |
| 118 | } else { |
| 119 | if (texels[currentMipLevel].fRowBytes != minRowBytes) { |
| 120 | return false; |
| 121 | } |
| 122 | } |
| 123 | ++levelsWithPixelsCnt; |
| 124 | } |
| 125 | if (w == 1 && h == 1) { |
| 126 | if (currentMipLevel != mipLevelCount - 1) { |
| 127 | return false; |
| 128 | } |
| 129 | } else { |
| 130 | w = std::max(w / 2, 1); |
| 131 | h = std::max(h / 2, 1); |
| 132 | } |
| 133 | } |
| 134 | // Either just a base layer or a full stack is required. |
| 135 | if (mipLevelCount != 1 && (w != 1 || h != 1)) { |
| 136 | return false; |
| 137 | } |
| 138 | // Can specify just the base, all levels, or no levels. |
| 139 | if (!hasBasePixels) { |
| 140 | return levelsWithPixelsCnt == 0; |
| 141 | } |
Brian Salomon | d2a8ae2 | 2019-09-10 16:03:59 -0400 | [diff] [blame] | 142 | return levelsWithPixelsCnt == 1 || levelsWithPixelsCnt == mipLevelCount; |
Brian Salomon | 1047a49 | 2019-07-02 12:25:21 -0400 | [diff] [blame] | 143 | } |
| 144 | |
Brian Salomon | a90382f | 2019-09-17 09:01:56 -0400 | [diff] [blame] | 145 | sk_sp<GrTexture> GrGpu::createTextureCommon(const GrSurfaceDesc& desc, |
| 146 | const GrBackendFormat& format, |
| 147 | GrRenderable renderable, |
| 148 | int renderTargetSampleCnt, |
| 149 | SkBudgeted budgeted, |
| 150 | GrProtected isProtected, |
| 151 | int mipLevelCount, |
| 152 | uint32_t levelClearMask) { |
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 | a90382f | 2019-09-17 09:01:56 -0400 | [diff] [blame] | 158 | GrMipMapped mipMapped = mipLevelCount > 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 | a90382f | 2019-09-17 09:01:56 -0400 | [diff] [blame] | 170 | this->handleDirtyContext(); |
| 171 | auto tex = this->onCreateTexture(desc, |
| 172 | format, |
| 173 | renderable, |
| 174 | renderTargetSampleCnt, |
| 175 | budgeted, |
| 176 | isProtected, |
| 177 | mipLevelCount, |
| 178 | levelClearMask); |
| 179 | if (tex) { |
| 180 | SkASSERT(tex->backendFormat() == format); |
| 181 | SkASSERT(GrRenderable::kNo == renderable || tex->asRenderTarget()); |
| 182 | if (!this->caps()->reuseScratchTextures() && renderable == GrRenderable::kNo) { |
| 183 | tex->resourcePriv().removeScratchKey(); |
| 184 | } |
| 185 | fStats.incTextureCreates(); |
| 186 | if (renderTargetSampleCnt > 1 && !this->caps()->msaaResolvesAutomatically()) { |
| 187 | SkASSERT(GrRenderable::kYes == renderable); |
| 188 | tex->asRenderTarget()->setRequiresManualMSAAResolve(); |
| 189 | } |
| 190 | } |
| 191 | return tex; |
| 192 | } |
| 193 | |
| 194 | sk_sp<GrTexture> GrGpu::createTexture(const GrSurfaceDesc& desc, |
| 195 | const GrBackendFormat& format, |
| 196 | GrRenderable renderable, |
| 197 | int renderTargetSampleCnt, |
| 198 | GrMipMapped mipMapped, |
| 199 | SkBudgeted budgeted, |
| 200 | GrProtected isProtected) { |
| 201 | int mipLevelCount = 1; |
| 202 | if (mipMapped == GrMipMapped::kYes) { |
| 203 | mipLevelCount = 32 - SkCLZ(static_cast<uint32_t>(SkTMax(desc.fWidth, desc.fHeight))); |
| 204 | } |
| 205 | uint32_t levelClearMask = |
| 206 | this->caps()->shouldInitializeTextures() ? (1 << mipLevelCount) - 1 : 0; |
| 207 | auto tex = this->createTextureCommon(desc, format, renderable, renderTargetSampleCnt, budgeted, |
| 208 | isProtected, mipLevelCount, levelClearMask); |
| 209 | if (tex && mipMapped == GrMipMapped::kYes && levelClearMask) { |
| 210 | tex->texturePriv().markMipMapsClean(); |
| 211 | } |
| 212 | return tex; |
| 213 | } |
| 214 | |
| 215 | sk_sp<GrTexture> GrGpu::createTexture(const GrSurfaceDesc& desc, |
| 216 | const GrBackendFormat& format, |
| 217 | GrRenderable renderable, |
| 218 | int renderTargetSampleCnt, |
| 219 | SkBudgeted budgeted, |
| 220 | GrProtected isProtected, |
| 221 | GrColorType textureColorType, |
| 222 | GrColorType srcColorType, |
| 223 | const GrMipLevel texels[], |
| 224 | int texelLevelCount) { |
| 225 | TRACE_EVENT0("skia.gpu", TRACE_FUNC); |
Brian Salomon | d2a8ae2 | 2019-09-10 16:03:59 -0400 | [diff] [blame] | 226 | if (texelLevelCount) { |
Brian Salomon | a90382f | 2019-09-17 09:01:56 -0400 | [diff] [blame] | 227 | if (!validate_texel_levels(desc.fWidth, desc.fHeight, srcColorType, texels, texelLevelCount, |
Brian Salomon | d2a8ae2 | 2019-09-10 16:03:59 -0400 | [diff] [blame] | 228 | this->caps())) { |
Brian Salomon | 1047a49 | 2019-07-02 12:25:21 -0400 | [diff] [blame] | 229 | return nullptr; |
| 230 | } |
Brian Salomon | d2a8ae2 | 2019-09-10 16:03:59 -0400 | [diff] [blame] | 231 | } |
| 232 | |
| 233 | int mipLevelCount = SkTMax(1, texelLevelCount); |
| 234 | uint32_t levelClearMask = 0; |
| 235 | if (this->caps()->shouldInitializeTextures()) { |
| 236 | if (texelLevelCount) { |
| 237 | for (int i = 0; i < mipLevelCount; ++i) { |
| 238 | if (!texels->fPixels) { |
| 239 | levelClearMask |= static_cast<uint32_t>(1 << i); |
| 240 | } |
| 241 | } |
| 242 | } else { |
| 243 | levelClearMask = static_cast<uint32_t>((1 << mipLevelCount) - 1); |
| 244 | } |
Brian Salomon | d17b4a6 | 2017-05-23 16:53:47 -0400 | [diff] [blame] | 245 | } |
| 246 | |
Brian Salomon | a90382f | 2019-09-17 09:01:56 -0400 | [diff] [blame] | 247 | auto tex = this->createTextureCommon(desc, format, renderable, renderTargetSampleCnt, budgeted, |
| 248 | isProtected, texelLevelCount, levelClearMask); |
bsalomon | b12ea41 | 2015-02-02 21:19:50 -0800 | [diff] [blame] | 249 | if (tex) { |
Brian Salomon | d2a8ae2 | 2019-09-10 16:03:59 -0400 | [diff] [blame] | 250 | bool markMipLevelsClean = false; |
| 251 | // Currently if level 0 does not have pixels then no other level may, as enforced by |
| 252 | // validate_texel_levels. |
| 253 | if (texelLevelCount && texels[0].fPixels) { |
Brian Salomon | d2a8ae2 | 2019-09-10 16:03:59 -0400 | [diff] [blame] | 254 | if (!this->writePixels(tex.get(), 0, 0, desc.fWidth, desc.fHeight, textureColorType, |
Brian Salomon | a90382f | 2019-09-17 09:01:56 -0400 | [diff] [blame] | 255 | srcColorType, texels, texelLevelCount)) { |
Brian Salomon | d2a8ae2 | 2019-09-10 16:03:59 -0400 | [diff] [blame] | 256 | return nullptr; |
cblume | 55f2d2d | 2016-02-26 13:20:48 -0800 | [diff] [blame] | 257 | } |
Brian Salomon | d2a8ae2 | 2019-09-10 16:03:59 -0400 | [diff] [blame] | 258 | // Currently if level[1] of mip map has pixel data then so must all other levels. |
| 259 | // as enforced by validate_texel_levels. |
| 260 | markMipLevelsClean = (texelLevelCount > 1 && !levelClearMask && texels[1].fPixels); |
| 261 | fStats.incTextureUploads(); |
| 262 | } else if (levelClearMask && mipLevelCount > 1) { |
| 263 | markMipLevelsClean = true; |
bsalomon | b12ea41 | 2015-02-02 21:19:50 -0800 | [diff] [blame] | 264 | } |
Brian Salomon | d2a8ae2 | 2019-09-10 16:03:59 -0400 | [diff] [blame] | 265 | if (markMipLevelsClean) { |
| 266 | tex->texturePriv().markMipMapsClean(); |
| 267 | } |
bsalomon | b12ea41 | 2015-02-02 21:19:50 -0800 | [diff] [blame] | 268 | } |
bsalomon@google.com | 81c3f8d | 2011-08-03 15:18:33 +0000 | [diff] [blame] | 269 | return tex; |
| 270 | } |
| 271 | |
Robert Phillips | 9f744f7 | 2019-12-19 19:14:33 -0500 | [diff] [blame^] | 272 | sk_sp<GrTexture> GrGpu::createCompressedTexture(SkISize dimensions, |
Greg Daniel | 7bfc913 | 2019-08-14 14:23:53 -0400 | [diff] [blame] | 273 | const GrBackendFormat& format, |
Robert Phillips | 42716d4 | 2019-12-16 12:19:54 -0500 | [diff] [blame] | 274 | SkBudgeted budgeted, |
| 275 | const void* data, |
Brian Salomon | bb8dde8 | 2019-06-27 10:52:13 -0400 | [diff] [blame] | 276 | size_t dataSize) { |
| 277 | this->handleDirtyContext(); |
Robert Phillips | 9f744f7 | 2019-12-19 19:14:33 -0500 | [diff] [blame^] | 278 | if (dimensions.width() < 1 || dimensions.width() > this->caps()->maxTextureSize() || |
| 279 | dimensions.height() < 1 || dimensions.height() > this->caps()->maxTextureSize()) { |
Brian Salomon | bb8dde8 | 2019-06-27 10:52:13 -0400 | [diff] [blame] | 280 | return nullptr; |
| 281 | } |
Brian Salomon | a3e2996 | 2019-07-16 11:52:08 -0400 | [diff] [blame] | 282 | // Note if we relax the requirement that data must be provided then we must check |
| 283 | // caps()->shouldInitializeTextures() here. |
Brian Salomon | bb8dde8 | 2019-06-27 10:52:13 -0400 | [diff] [blame] | 284 | if (!data) { |
| 285 | return nullptr; |
| 286 | } |
Greg Daniel | 7bfc913 | 2019-08-14 14:23:53 -0400 | [diff] [blame] | 287 | if (!this->caps()->isFormatTexturable(format)) { |
Brian Salomon | bb8dde8 | 2019-06-27 10:52:13 -0400 | [diff] [blame] | 288 | return nullptr; |
| 289 | } |
Robert Phillips | 9f744f7 | 2019-12-19 19:14:33 -0500 | [diff] [blame^] | 290 | |
| 291 | // TODO: expand CompressedDataIsCorrect to work here too |
| 292 | SkImage::CompressionType compressionType = this->caps()->compressionType(format); |
| 293 | |
| 294 | if (dataSize < GrCompressedDataSize(compressionType, dimensions, |
Robert Phillips | 0d7e2f1 | 2019-12-18 13:01:04 -0500 | [diff] [blame] | 295 | nullptr, GrMipMapped::kNo)) { |
Brian Salomon | bb8dde8 | 2019-06-27 10:52:13 -0400 | [diff] [blame] | 296 | return nullptr; |
| 297 | } |
Robert Phillips | 9f744f7 | 2019-12-19 19:14:33 -0500 | [diff] [blame^] | 298 | return this->onCreateCompressedTexture(dimensions, format, budgeted, data, dataSize); |
Brian Salomon | bb8dde8 | 2019-06-27 10:52:13 -0400 | [diff] [blame] | 299 | } |
| 300 | |
Greg Daniel | 7ef28f3 | 2017-04-20 16:41:55 +0000 | [diff] [blame] | 301 | sk_sp<GrTexture> GrGpu::wrapBackendTexture(const GrBackendTexture& backendTex, |
Robert Phillips | c80b0e9 | 2019-07-23 10:27:09 -0400 | [diff] [blame] | 302 | GrColorType colorType, |
Brian Salomon | fa2ebea | 2019-01-24 15:58:58 -0500 | [diff] [blame] | 303 | GrWrapOwnership ownership, GrWrapCacheable cacheable, |
| 304 | GrIOType ioType) { |
Brian Salomon | c67c31c | 2018-12-06 10:00:03 -0500 | [diff] [blame] | 305 | SkASSERT(ioType != kWrite_GrIOType); |
bsalomon@google.com | e269f21 | 2011-11-07 13:29:52 +0000 | [diff] [blame] | 306 | this->handleDirtyContext(); |
Robert Phillips | c80b0e9 | 2019-07-23 10:27:09 -0400 | [diff] [blame] | 307 | |
| 308 | const GrCaps* caps = this->caps(); |
| 309 | SkASSERT(caps); |
| 310 | |
Greg Daniel | 7bfc913 | 2019-08-14 14:23:53 -0400 | [diff] [blame] | 311 | if (!caps->isFormatTexturable(backendTex.getBackendFormat())) { |
bsalomon | 5b30c6f | 2015-12-17 14:17:34 -0800 | [diff] [blame] | 312 | return nullptr; |
| 313 | } |
Robert Phillips | c80b0e9 | 2019-07-23 10:27:09 -0400 | [diff] [blame] | 314 | if (backendTex.width() > caps->maxTextureSize() || |
| 315 | backendTex.height() > caps->maxTextureSize()) { |
bsalomon | 5b30c6f | 2015-12-17 14:17:34 -0800 | [diff] [blame] | 316 | return nullptr; |
| 317 | } |
Robert Phillips | c80b0e9 | 2019-07-23 10:27:09 -0400 | [diff] [blame] | 318 | |
Robert Phillips | c80b0e9 | 2019-07-23 10:27:09 -0400 | [diff] [blame] | 319 | return this->onWrapBackendTexture(backendTex, colorType, ownership, cacheable, ioType); |
Brian Salomon | d17f658 | 2017-07-19 18:28:58 -0400 | [diff] [blame] | 320 | } |
Eric Karl | 5c77975 | 2017-05-08 12:02:07 -0700 | [diff] [blame] | 321 | |
Robert Phillips | b915c94 | 2019-12-17 14:44:37 -0500 | [diff] [blame] | 322 | sk_sp<GrTexture> GrGpu::wrapCompressedBackendTexture(const GrBackendTexture& backendTex, |
| 323 | GrWrapOwnership ownership, |
| 324 | GrWrapCacheable cacheable) { |
| 325 | this->handleDirtyContext(); |
| 326 | |
| 327 | const GrCaps* caps = this->caps(); |
| 328 | SkASSERT(caps); |
| 329 | |
| 330 | if (!caps->isFormatTexturable(backendTex.getBackendFormat())) { |
| 331 | return nullptr; |
| 332 | } |
| 333 | if (backendTex.width() > caps->maxTextureSize() || |
| 334 | backendTex.height() > caps->maxTextureSize()) { |
| 335 | return nullptr; |
| 336 | } |
| 337 | |
| 338 | return this->onWrapCompressedBackendTexture(backendTex, ownership, cacheable); |
| 339 | } |
| 340 | |
| 341 | |
Brian Salomon | d17f658 | 2017-07-19 18:28:58 -0400 | [diff] [blame] | 342 | sk_sp<GrTexture> GrGpu::wrapRenderableBackendTexture(const GrBackendTexture& backendTex, |
Robert Phillips | 0902c98 | 2019-07-16 07:47:56 -0400 | [diff] [blame] | 343 | int sampleCnt, GrColorType colorType, |
| 344 | GrWrapOwnership ownership, |
Brian Salomon | aa6ca0a | 2019-01-24 16:03:07 -0500 | [diff] [blame] | 345 | GrWrapCacheable cacheable) { |
Brian Salomon | d17f658 | 2017-07-19 18:28:58 -0400 | [diff] [blame] | 346 | this->handleDirtyContext(); |
Brian Salomon | bdecacf | 2018-02-02 20:32:49 -0500 | [diff] [blame] | 347 | if (sampleCnt < 1) { |
| 348 | return nullptr; |
| 349 | } |
Robert Phillips | 0902c98 | 2019-07-16 07:47:56 -0400 | [diff] [blame] | 350 | |
| 351 | const GrCaps* caps = this->caps(); |
| 352 | |
Greg Daniel | 7bfc913 | 2019-08-14 14:23:53 -0400 | [diff] [blame] | 353 | if (!caps->isFormatTexturable(backendTex.getBackendFormat()) || |
Greg Daniel | 6fa62e2 | 2019-08-07 15:52:37 -0400 | [diff] [blame] | 354 | !caps->isFormatRenderable(backendTex.getBackendFormat(), sampleCnt)) { |
Brian Salomon | d17f658 | 2017-07-19 18:28:58 -0400 | [diff] [blame] | 355 | return nullptr; |
| 356 | } |
| 357 | |
Robert Phillips | 0902c98 | 2019-07-16 07:47:56 -0400 | [diff] [blame] | 358 | if (backendTex.width() > caps->maxRenderTargetSize() || |
| 359 | backendTex.height() > caps->maxRenderTargetSize()) { |
Brian Salomon | d17f658 | 2017-07-19 18:28:58 -0400 | [diff] [blame] | 360 | return nullptr; |
| 361 | } |
Robert Phillips | 0902c98 | 2019-07-16 07:47:56 -0400 | [diff] [blame] | 362 | sk_sp<GrTexture> tex = this->onWrapRenderableBackendTexture(backendTex, sampleCnt, colorType, |
| 363 | ownership, cacheable); |
Greg Daniel | e320486 | 2018-04-16 11:24:10 -0400 | [diff] [blame] | 364 | SkASSERT(!tex || tex->asRenderTarget()); |
Chris Dalton | 3f7932e | 2019-08-19 00:39:13 -0600 | [diff] [blame] | 365 | if (tex && sampleCnt > 1 && !caps->msaaResolvesAutomatically()) { |
| 366 | tex->asRenderTarget()->setRequiresManualMSAAResolve(); |
| 367 | } |
bungeman | 6bd5284 | 2016-10-27 09:30:08 -0700 | [diff] [blame] | 368 | return tex; |
bsalomon@google.com | e269f21 | 2011-11-07 13:29:52 +0000 | [diff] [blame] | 369 | } |
| 370 | |
Robert Phillips | c80b0e9 | 2019-07-23 10:27:09 -0400 | [diff] [blame] | 371 | sk_sp<GrRenderTarget> GrGpu::wrapBackendRenderTarget(const GrBackendRenderTarget& backendRT, |
| 372 | GrColorType colorType) { |
| 373 | this->handleDirtyContext(); |
| 374 | |
| 375 | const GrCaps* caps = this->caps(); |
| 376 | |
Greg Daniel | 6fa62e2 | 2019-08-07 15:52:37 -0400 | [diff] [blame] | 377 | if (!caps->isFormatRenderable(backendRT.getBackendFormat(), backendRT.sampleCnt())) { |
bsalomon | 5b30c6f | 2015-12-17 14:17:34 -0800 | [diff] [blame] | 378 | return nullptr; |
| 379 | } |
Robert Phillips | c80b0e9 | 2019-07-23 10:27:09 -0400 | [diff] [blame] | 380 | |
| 381 | return this->onWrapBackendRenderTarget(backendRT, colorType); |
bsalomon@google.com | e269f21 | 2011-11-07 13:29:52 +0000 | [diff] [blame] | 382 | } |
| 383 | |
Robert Phillips | c80b0e9 | 2019-07-23 10:27:09 -0400 | [diff] [blame] | 384 | sk_sp<GrRenderTarget> GrGpu::wrapBackendTextureAsRenderTarget(const GrBackendTexture& backendTex, |
| 385 | int sampleCnt, |
| 386 | GrColorType colorType) { |
Brian Salomon | bdecacf | 2018-02-02 20:32:49 -0500 | [diff] [blame] | 387 | this->handleDirtyContext(); |
Robert Phillips | c80b0e9 | 2019-07-23 10:27:09 -0400 | [diff] [blame] | 388 | |
| 389 | const GrCaps* caps = this->caps(); |
| 390 | |
| 391 | int maxSize = caps->maxTextureSize(); |
| 392 | if (backendTex.width() > maxSize || backendTex.height() > maxSize) { |
| 393 | return nullptr; |
| 394 | } |
| 395 | |
Greg Daniel | 6fa62e2 | 2019-08-07 15:52:37 -0400 | [diff] [blame] | 396 | if (!caps->isFormatRenderable(backendTex.getBackendFormat(), sampleCnt)) { |
Robert Phillips | c80b0e9 | 2019-07-23 10:27:09 -0400 | [diff] [blame] | 397 | return nullptr; |
| 398 | } |
Robert Phillips | 1cd1ed8 | 2019-07-23 13:21:01 -0400 | [diff] [blame] | 399 | |
Chris Dalton | 3f7932e | 2019-08-19 00:39:13 -0600 | [diff] [blame] | 400 | auto rt = this->onWrapBackendTextureAsRenderTarget(backendTex, sampleCnt, colorType); |
| 401 | if (rt && sampleCnt > 1 && !this->caps()->msaaResolvesAutomatically()) { |
| 402 | rt->setRequiresManualMSAAResolve(); |
| 403 | } |
| 404 | return rt; |
ericrk | f7b8b8a | 2016-02-24 14:49:51 -0800 | [diff] [blame] | 405 | } |
| 406 | |
Greg Daniel | b46add8 | 2019-01-02 14:51:29 -0500 | [diff] [blame] | 407 | sk_sp<GrRenderTarget> GrGpu::wrapVulkanSecondaryCBAsRenderTarget(const SkImageInfo& imageInfo, |
| 408 | const GrVkDrawableInfo& vkInfo) { |
| 409 | return this->onWrapVulkanSecondaryCBAsRenderTarget(imageInfo, vkInfo); |
| 410 | } |
| 411 | |
| 412 | sk_sp<GrRenderTarget> GrGpu::onWrapVulkanSecondaryCBAsRenderTarget(const SkImageInfo& imageInfo, |
| 413 | const GrVkDrawableInfo& vkInfo) { |
| 414 | // This is only supported on Vulkan so we default to returning nullptr here |
| 415 | return nullptr; |
| 416 | } |
| 417 | |
Brian Salomon | dbf7072 | 2019-02-07 11:31:24 -0500 | [diff] [blame] | 418 | sk_sp<GrGpuBuffer> GrGpu::createBuffer(size_t size, GrGpuBufferType intendedType, |
| 419 | GrAccessPattern accessPattern, const void* data) { |
Brian Salomon | e39526b | 2019-06-24 16:35:53 -0400 | [diff] [blame] | 420 | TRACE_EVENT0("skia.gpu", TRACE_FUNC); |
bsalomon@google.com | a7f84e1 | 2011-03-10 14:13:19 +0000 | [diff] [blame] | 421 | this->handleDirtyContext(); |
Brian Salomon | dbf7072 | 2019-02-07 11:31:24 -0500 | [diff] [blame] | 422 | sk_sp<GrGpuBuffer> buffer = this->onCreateBuffer(size, intendedType, accessPattern, data); |
robertphillips | 1b8e1b5 | 2015-06-24 06:54:10 -0700 | [diff] [blame] | 423 | if (!this->caps()->reuseScratchBuffers()) { |
cdalton | 397536c | 2016-03-25 12:15:03 -0700 | [diff] [blame] | 424 | buffer->resourcePriv().removeScratchKey(); |
robertphillips | 1b8e1b5 | 2015-06-24 06:54:10 -0700 | [diff] [blame] | 425 | } |
cdalton | 397536c | 2016-03-25 12:15:03 -0700 | [diff] [blame] | 426 | return buffer; |
jvanverth | 73063dc | 2015-12-03 09:15:47 -0800 | [diff] [blame] | 427 | } |
| 428 | |
Greg Daniel | 46cfbc6 | 2019-06-07 11:43:30 -0400 | [diff] [blame] | 429 | bool GrGpu::copySurface(GrSurface* dst, GrSurface* src, const SkIRect& srcRect, |
Greg Daniel | e227fe4 | 2019-08-21 13:52:24 -0400 | [diff] [blame] | 430 | const SkIPoint& dstPoint) { |
Brian Salomon | e39526b | 2019-06-24 16:35:53 -0400 | [diff] [blame] | 431 | TRACE_EVENT0("skia.gpu", TRACE_FUNC); |
joshualitt | 1cbdcde | 2015-08-21 11:53:29 -0700 | [diff] [blame] | 432 | SkASSERT(dst && src); |
Brian Salomon | c67c31c | 2018-12-06 10:00:03 -0500 | [diff] [blame] | 433 | |
| 434 | if (dst->readOnly()) { |
| 435 | return false; |
| 436 | } |
| 437 | |
joshualitt | 1cbdcde | 2015-08-21 11:53:29 -0700 | [diff] [blame] | 438 | this->handleDirtyContext(); |
Brian Salomon | c67c31c | 2018-12-06 10:00:03 -0500 | [diff] [blame] | 439 | |
Greg Daniel | e227fe4 | 2019-08-21 13:52:24 -0400 | [diff] [blame] | 440 | return this->onCopySurface(dst, src, srcRect, dstPoint); |
joshualitt | 1cbdcde | 2015-08-21 11:53:29 -0700 | [diff] [blame] | 441 | } |
| 442 | |
Brian Salomon | a694870 | 2018-06-01 15:33:20 -0400 | [diff] [blame] | 443 | 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] | 444 | GrColorType surfaceColorType, GrColorType dstColorType, void* buffer, |
| 445 | size_t rowBytes) { |
Brian Salomon | e39526b | 2019-06-24 16:35:53 -0400 | [diff] [blame] | 446 | TRACE_EVENT0("skia.gpu", TRACE_FUNC); |
Brian Salomon | bf7b620 | 2016-11-11 16:08:03 -0500 | [diff] [blame] | 447 | SkASSERT(surface); |
Greg Daniel | 7bfc913 | 2019-08-14 14:23:53 -0400 | [diff] [blame] | 448 | SkASSERT(this->caps()->isFormatTexturable(surface->backendFormat())); |
Brian Salomon | bf7b620 | 2016-11-11 16:08:03 -0500 | [diff] [blame] | 449 | |
Brian Salomon | 1d43530 | 2019-07-01 13:05:28 -0400 | [diff] [blame] | 450 | auto subRect = SkIRect::MakeXYWH(left, top, width, height); |
| 451 | auto bounds = SkIRect::MakeWH(surface->width(), surface->height()); |
| 452 | if (!bounds.contains(subRect)) { |
egdaniel | 6d901da | 2015-07-30 12:02:15 -0700 | [diff] [blame] | 453 | return false; |
| 454 | } |
| 455 | |
Brian Salomon | 1047a49 | 2019-07-02 12:25:21 -0400 | [diff] [blame] | 456 | size_t minRowBytes = SkToSizeT(GrColorTypeBytesPerPixel(dstColorType) * width); |
| 457 | if (!this->caps()->readPixelsRowBytesSupport()) { |
| 458 | if (rowBytes != minRowBytes) { |
| 459 | return false; |
| 460 | } |
| 461 | } else { |
| 462 | if (rowBytes < minRowBytes) { |
| 463 | return false; |
| 464 | } |
| 465 | if (rowBytes % GrColorTypeBytesPerPixel(dstColorType)) { |
| 466 | return false; |
| 467 | } |
| 468 | } |
| 469 | |
Brian Salomon | 1c53a9f | 2019-08-12 14:10:12 -0400 | [diff] [blame] | 470 | if (this->caps()->isFormatCompressed(surface->backendFormat())) { |
Jim Van Verth | 1676cb9 | 2019-01-15 13:24:45 -0500 | [diff] [blame] | 471 | return false; |
| 472 | } |
| 473 | |
Brian Salomon | bf7b620 | 2016-11-11 16:08:03 -0500 | [diff] [blame] | 474 | this->handleDirtyContext(); |
| 475 | |
Brian Salomon | f77c146 | 2019-08-01 15:19:29 -0400 | [diff] [blame] | 476 | return this->onReadPixels(surface, left, top, width, height, surfaceColorType, dstColorType, |
| 477 | buffer, rowBytes); |
bsalomon@google.com | a7f84e1 | 2011-03-10 14:13:19 +0000 | [diff] [blame] | 478 | } |
| 479 | |
Brian Salomon | a9b04b9 | 2018-06-01 15:04:28 -0400 | [diff] [blame] | 480 | 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] | 481 | GrColorType surfaceColorType, GrColorType srcColorType, |
Greg Daniel | b20d7e5 | 2019-09-03 13:54:39 -0400 | [diff] [blame] | 482 | const GrMipLevel texels[], int mipLevelCount, bool prepForTexSampling) { |
Brian Salomon | e39526b | 2019-06-24 16:35:53 -0400 | [diff] [blame] | 483 | TRACE_EVENT0("skia.gpu", TRACE_FUNC); |
Brian Salomon | bf7b620 | 2016-11-11 16:08:03 -0500 | [diff] [blame] | 484 | SkASSERT(surface); |
Greg Daniel | 7bfc913 | 2019-08-14 14:23:53 -0400 | [diff] [blame] | 485 | SkASSERT(this->caps()->isFormatTexturableAndUploadable(surfaceColorType, |
| 486 | surface->backendFormat())); |
Brian Salomon | c67c31c | 2018-12-06 10:00:03 -0500 | [diff] [blame] | 487 | |
| 488 | if (surface->readOnly()) { |
| 489 | return false; |
| 490 | } |
| 491 | |
Brian Salomon | 1047a49 | 2019-07-02 12:25:21 -0400 | [diff] [blame] | 492 | if (mipLevelCount == 0) { |
| 493 | return false; |
| 494 | } else if (mipLevelCount == 1) { |
Greg Daniel | 660cc99 | 2017-06-26 14:55:05 -0400 | [diff] [blame] | 495 | // 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] | 496 | auto subRect = SkIRect::MakeXYWH(left, top, width, height); |
| 497 | auto bounds = SkIRect::MakeWH(surface->width(), surface->height()); |
Greg Daniel | 660cc99 | 2017-06-26 14:55:05 -0400 | [diff] [blame] | 498 | if (!bounds.contains(subRect)) { |
| 499 | return false; |
| 500 | } |
| 501 | } else if (0 != left || 0 != top || width != surface->width() || height != surface->height()) { |
| 502 | // We require that if the texels are mipped, than the write region is the entire surface |
| 503 | return false; |
| 504 | } |
Robert Phillips | b7b7e5f | 2017-05-22 13:23:19 -0400 | [diff] [blame] | 505 | |
Brian Salomon | a90382f | 2019-09-17 09:01:56 -0400 | [diff] [blame] | 506 | if (!validate_texel_levels(width, height, srcColorType, texels, mipLevelCount, this->caps())) { |
Brian Salomon | 1047a49 | 2019-07-02 12:25:21 -0400 | [diff] [blame] | 507 | return false; |
cblume | 55f2d2d | 2016-02-26 13:20:48 -0800 | [diff] [blame] | 508 | } |
jvanverth | 2dc2994 | 2015-09-01 07:16:46 -0700 | [diff] [blame] | 509 | |
bsalomon@google.com | 6f37951 | 2011-11-16 20:36:03 +0000 | [diff] [blame] | 510 | this->handleDirtyContext(); |
Brian Salomon | f77c146 | 2019-08-01 15:19:29 -0400 | [diff] [blame] | 511 | if (this->onWritePixels(surface, left, top, width, height, surfaceColorType, srcColorType, |
Greg Daniel | b20d7e5 | 2019-09-03 13:54:39 -0400 | [diff] [blame] | 512 | texels, mipLevelCount, prepForTexSampling)) { |
jvanverth | 900bd4a | 2016-04-29 13:53:12 -0700 | [diff] [blame] | 513 | SkIRect rect = SkIRect::MakeXYWH(left, top, width, height); |
Brian Salomon | a9b04b9 | 2018-06-01 15:04:28 -0400 | [diff] [blame] | 514 | this->didWriteToSurface(surface, kTopLeft_GrSurfaceOrigin, &rect, mipLevelCount); |
bsalomon | b12ea41 | 2015-02-02 21:19:50 -0800 | [diff] [blame] | 515 | fStats.incTextureUploads(); |
| 516 | return true; |
| 517 | } |
| 518 | return false; |
bsalomon@google.com | 6f37951 | 2011-11-16 20:36:03 +0000 | [diff] [blame] | 519 | } |
| 520 | |
Brian Salomon | e05ba5a | 2019-04-08 11:59:07 -0400 | [diff] [blame] | 521 | 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] | 522 | GrColorType textureColorType, GrColorType bufferColorType, |
| 523 | GrGpuBuffer* transferBuffer, size_t offset, size_t rowBytes) { |
Brian Salomon | e39526b | 2019-06-24 16:35:53 -0400 | [diff] [blame] | 524 | TRACE_EVENT0("skia.gpu", TRACE_FUNC); |
Brian Salomon | c67c31c | 2018-12-06 10:00:03 -0500 | [diff] [blame] | 525 | SkASSERT(texture); |
cdalton | 397536c | 2016-03-25 12:15:03 -0700 | [diff] [blame] | 526 | SkASSERT(transferBuffer); |
Greg Daniel | 7bfc913 | 2019-08-14 14:23:53 -0400 | [diff] [blame] | 527 | SkASSERT(this->caps()->isFormatTexturableAndUploadable(textureColorType, |
| 528 | texture->backendFormat())); |
jvanverth | 17aa047 | 2016-01-05 10:41:27 -0800 | [diff] [blame] | 529 | |
Brian Salomon | c67c31c | 2018-12-06 10:00:03 -0500 | [diff] [blame] | 530 | if (texture->readOnly()) { |
| 531 | return false; |
| 532 | } |
| 533 | |
Greg Daniel | 660cc99 | 2017-06-26 14:55:05 -0400 | [diff] [blame] | 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(texture->width(), texture->height()); |
| 537 | if (!bounds.contains(subRect)) { |
| 538 | return false; |
| 539 | } |
| 540 | |
Brian Salomon | b28cb68 | 2019-07-26 12:48:47 -0400 | [diff] [blame] | 541 | size_t bpp = GrColorTypeBytesPerPixel(bufferColorType); |
Brian Salomon | 1047a49 | 2019-07-02 12:25:21 -0400 | [diff] [blame] | 542 | if (this->caps()->writePixelsRowBytesSupport()) { |
| 543 | if (rowBytes < SkToSizeT(bpp * width)) { |
| 544 | return false; |
| 545 | } |
| 546 | if (rowBytes % bpp) { |
| 547 | return false; |
| 548 | } |
| 549 | } else { |
| 550 | if (rowBytes != SkToSizeT(bpp * width)) { |
| 551 | return false; |
| 552 | } |
| 553 | } |
| 554 | |
jvanverth | 17aa047 | 2016-01-05 10:41:27 -0800 | [diff] [blame] | 555 | this->handleDirtyContext(); |
Brian Salomon | f77c146 | 2019-08-01 15:19:29 -0400 | [diff] [blame] | 556 | if (this->onTransferPixelsTo(texture, left, top, width, height, textureColorType, |
| 557 | bufferColorType, transferBuffer, offset, rowBytes)) { |
jvanverth | 900bd4a | 2016-04-29 13:53:12 -0700 | [diff] [blame] | 558 | SkIRect rect = SkIRect::MakeXYWH(left, top, width, height); |
Brian Salomon | 1fabd51 | 2018-02-09 09:54:25 -0500 | [diff] [blame] | 559 | this->didWriteToSurface(texture, kTopLeft_GrSurfaceOrigin, &rect); |
jvanverth | 17aa047 | 2016-01-05 10:41:27 -0800 | [diff] [blame] | 560 | fStats.incTransfersToTexture(); |
jvanverth | 84741b3 | 2016-09-30 08:39:02 -0700 | [diff] [blame] | 561 | |
jvanverth | 17aa047 | 2016-01-05 10:41:27 -0800 | [diff] [blame] | 562 | return true; |
| 563 | } |
| 564 | return false; |
| 565 | } |
| 566 | |
Brian Salomon | 26de56e | 2019-04-10 12:14:26 -0400 | [diff] [blame] | 567 | 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] | 568 | GrColorType surfaceColorType, GrColorType bufferColorType, |
| 569 | GrGpuBuffer* transferBuffer, size_t offset) { |
Brian Salomon | e39526b | 2019-06-24 16:35:53 -0400 | [diff] [blame] | 570 | TRACE_EVENT0("skia.gpu", TRACE_FUNC); |
Brian Salomon | e05ba5a | 2019-04-08 11:59:07 -0400 | [diff] [blame] | 571 | SkASSERT(surface); |
| 572 | SkASSERT(transferBuffer); |
Greg Daniel | 7bfc913 | 2019-08-14 14:23:53 -0400 | [diff] [blame] | 573 | SkASSERT(this->caps()->isFormatTexturable(surface->backendFormat())); |
Brian Salomon | f77c146 | 2019-08-01 15:19:29 -0400 | [diff] [blame] | 574 | |
Greg Daniel | ba88ab6 | 2019-07-26 09:14:01 -0400 | [diff] [blame] | 575 | #ifdef SK_DEBUG |
Brian Salomon | 1c53a9f | 2019-08-12 14:10:12 -0400 | [diff] [blame] | 576 | auto supportedRead = this->caps()->supportedReadPixelsColorType( |
| 577 | surfaceColorType, surface->backendFormat(), bufferColorType); |
Greg Daniel | ba88ab6 | 2019-07-26 09:14:01 -0400 | [diff] [blame] | 578 | SkASSERT(supportedRead.fOffsetAlignmentForTransferBuffer); |
| 579 | SkASSERT(offset % supportedRead.fOffsetAlignmentForTransferBuffer == 0); |
| 580 | #endif |
Brian Salomon | e05ba5a | 2019-04-08 11:59:07 -0400 | [diff] [blame] | 581 | |
| 582 | // We require that the write region is contained in the texture |
| 583 | SkIRect subRect = SkIRect::MakeXYWH(left, top, width, height); |
| 584 | SkIRect bounds = SkIRect::MakeWH(surface->width(), surface->height()); |
| 585 | if (!bounds.contains(subRect)) { |
| 586 | return false; |
| 587 | } |
| 588 | |
| 589 | this->handleDirtyContext(); |
Brian Salomon | f77c146 | 2019-08-01 15:19:29 -0400 | [diff] [blame] | 590 | if (this->onTransferPixelsFrom(surface, left, top, width, height, surfaceColorType, |
| 591 | bufferColorType, transferBuffer, offset)) { |
Brian Salomon | e05ba5a | 2019-04-08 11:59:07 -0400 | [diff] [blame] | 592 | fStats.incTransfersFromSurface(); |
Brian Salomon | 26de56e | 2019-04-10 12:14:26 -0400 | [diff] [blame] | 593 | return true; |
Brian Salomon | e05ba5a | 2019-04-08 11:59:07 -0400 | [diff] [blame] | 594 | } |
Brian Salomon | 26de56e | 2019-04-10 12:14:26 -0400 | [diff] [blame] | 595 | return false; |
Brian Salomon | e05ba5a | 2019-04-08 11:59:07 -0400 | [diff] [blame] | 596 | } |
| 597 | |
Brian Salomon | 930f939 | 2018-06-20 16:25:26 -0400 | [diff] [blame] | 598 | bool GrGpu::regenerateMipMapLevels(GrTexture* texture) { |
Brian Salomon | e39526b | 2019-06-24 16:35:53 -0400 | [diff] [blame] | 599 | TRACE_EVENT0("skia.gpu", TRACE_FUNC); |
Brian Salomon | 930f939 | 2018-06-20 16:25:26 -0400 | [diff] [blame] | 600 | SkASSERT(texture); |
| 601 | SkASSERT(this->caps()->mipMapSupport()); |
| 602 | SkASSERT(texture->texturePriv().mipMapped() == GrMipMapped::kYes); |
Chris Dalton | 16a33c6 | 2019-09-24 22:19:17 -0600 | [diff] [blame] | 603 | if (!texture->texturePriv().mipMapsAreDirty()) { |
| 604 | // This can happen when the proxy expects mipmaps to be dirty, but they are not dirty on the |
| 605 | // actual target. This may be caused by things that the drawingManager could not predict, |
| 606 | // i.e., ops that don't draw anything, aborting a draw for exceptional circumstances, etc. |
| 607 | // NOTE: This goes away once we quit tracking mipmap state on the actual texture. |
| 608 | return true; |
| 609 | } |
Brian Salomon | c67c31c | 2018-12-06 10:00:03 -0500 | [diff] [blame] | 610 | if (texture->readOnly()) { |
| 611 | return false; |
| 612 | } |
Brian Salomon | 930f939 | 2018-06-20 16:25:26 -0400 | [diff] [blame] | 613 | if (this->onRegenerateMipMapLevels(texture)) { |
| 614 | texture->texturePriv().markMipMapsClean(); |
| 615 | return true; |
| 616 | } |
| 617 | return false; |
| 618 | } |
| 619 | |
Brian Salomon | 1f05d45 | 2019-02-08 12:33:08 -0500 | [diff] [blame] | 620 | void GrGpu::resetTextureBindings() { |
| 621 | this->handleDirtyContext(); |
| 622 | this->onResetTextureBindings(); |
| 623 | } |
| 624 | |
Chris Dalton | 16a33c6 | 2019-09-24 22:19:17 -0600 | [diff] [blame] | 625 | void GrGpu::resolveRenderTarget(GrRenderTarget* target, const SkIRect& resolveRect, |
| 626 | GrSurfaceOrigin origin, ForExternalIO forExternalIO) { |
tfarina@chromium.org | f6de475 | 2013-08-17 00:02:59 +0000 | [diff] [blame] | 627 | SkASSERT(target); |
bsalomon@google.com | 75f9f25 | 2012-01-31 13:35:56 +0000 | [diff] [blame] | 628 | this->handleDirtyContext(); |
Chris Dalton | 16a33c6 | 2019-09-24 22:19:17 -0600 | [diff] [blame] | 629 | this->onResolveRenderTarget(target, resolveRect, origin, forExternalIO); |
bsalomon@google.com | 75f9f25 | 2012-01-31 13:35:56 +0000 | [diff] [blame] | 630 | } |
| 631 | |
Brian Salomon | 1fabd51 | 2018-02-09 09:54:25 -0500 | [diff] [blame] | 632 | void GrGpu::didWriteToSurface(GrSurface* surface, GrSurfaceOrigin origin, const SkIRect* bounds, |
| 633 | uint32_t mipLevels) const { |
jvanverth | 900bd4a | 2016-04-29 13:53:12 -0700 | [diff] [blame] | 634 | SkASSERT(surface); |
Brian Salomon | c67c31c | 2018-12-06 10:00:03 -0500 | [diff] [blame] | 635 | SkASSERT(!surface->readOnly()); |
jvanverth | 900bd4a | 2016-04-29 13:53:12 -0700 | [diff] [blame] | 636 | // Mark any MIP chain and resolve buffer as dirty if and only if there is a non-empty bounds. |
| 637 | if (nullptr == bounds || !bounds->isEmpty()) { |
jvanverth | 900bd4a | 2016-04-29 13:53:12 -0700 | [diff] [blame] | 638 | GrTexture* texture = surface->asTexture(); |
| 639 | if (texture && 1 == mipLevels) { |
Greg Daniel | 0fc4d2d | 2017-10-12 11:23:36 -0400 | [diff] [blame] | 640 | texture->texturePriv().markMipMapsDirty(); |
jvanverth | 900bd4a | 2016-04-29 13:53:12 -0700 | [diff] [blame] | 641 | } |
| 642 | } |
| 643 | } |
| 644 | |
Chris Dalton | 8c4cafd | 2019-04-15 19:14:36 -0600 | [diff] [blame] | 645 | int GrGpu::findOrAssignSamplePatternKey(GrRenderTarget* renderTarget) { |
Chris Dalton | d7291ba | 2019-03-07 14:17:03 -0700 | [diff] [blame] | 646 | SkASSERT(this->caps()->sampleLocationsSupport()); |
Chris Dalton | effee20 | 2019-07-01 22:28:03 -0600 | [diff] [blame] | 647 | SkASSERT(renderTarget->numSamples() > 1 || |
| 648 | (renderTarget->renderTargetPriv().getStencilAttachment() && |
| 649 | renderTarget->renderTargetPriv().getStencilAttachment()->numSamples() > 1)); |
Chris Dalton | d7291ba | 2019-03-07 14:17:03 -0700 | [diff] [blame] | 650 | |
| 651 | SkSTArray<16, SkPoint> sampleLocations; |
Chris Dalton | 8c4cafd | 2019-04-15 19:14:36 -0600 | [diff] [blame] | 652 | this->querySampleLocations(renderTarget, &sampleLocations); |
Chris Dalton | d7291ba | 2019-03-07 14:17:03 -0700 | [diff] [blame] | 653 | return fSamplePatternDictionary.findOrAssignSamplePatternKey(sampleLocations); |
| 654 | } |
| 655 | |
Brian Salomon | f9a1fdf | 2019-05-09 10:30:12 -0400 | [diff] [blame] | 656 | GrSemaphoresSubmitted GrGpu::finishFlush(GrSurfaceProxy* proxies[], |
| 657 | int n, |
Greg Daniel | bae7121 | 2019-03-01 15:24:35 -0500 | [diff] [blame] | 658 | SkSurface::BackendSurfaceAccess access, |
Greg Daniel | 797efca | 2019-05-09 14:04:20 -0400 | [diff] [blame] | 659 | const GrFlushInfo& info, |
| 660 | const GrPrepareForExternalIORequests& externalRequests) { |
Brian Salomon | e39526b | 2019-06-24 16:35:53 -0400 | [diff] [blame] | 661 | TRACE_EVENT0("skia.gpu", TRACE_FUNC); |
Greg Daniel | d207345 | 2018-12-07 11:20:33 -0500 | [diff] [blame] | 662 | this->stats()->incNumFinishFlushes(); |
Robert Phillips | 9da87e0 | 2019-02-04 13:26:26 -0500 | [diff] [blame] | 663 | GrResourceProvider* resourceProvider = fContext->priv().resourceProvider(); |
Robert Phillips | 6be756b | 2018-01-16 15:07:54 -0500 | [diff] [blame] | 664 | |
Greg Daniel | 30a35e8 | 2019-11-19 14:12:25 -0500 | [diff] [blame] | 665 | struct SemaphoreInfo { |
| 666 | std::unique_ptr<GrSemaphore> fSemaphore; |
| 667 | bool fDidCreate = false; |
| 668 | }; |
| 669 | |
| 670 | bool failedSemaphoreCreation = false; |
| 671 | std::unique_ptr<SemaphoreInfo[]> semaphoreInfos(new SemaphoreInfo[info.fNumSemaphores]); |
| 672 | if (this->caps()->semaphoreSupport() && info.fNumSemaphores) { |
| 673 | for (int i = 0; i < info.fNumSemaphores && !failedSemaphoreCreation; ++i) { |
Greg Daniel | e6bfb7d | 2019-04-17 15:26:11 -0400 | [diff] [blame] | 674 | if (info.fSignalSemaphores[i].isInitialized()) { |
Greg Daniel | 30a35e8 | 2019-11-19 14:12:25 -0500 | [diff] [blame] | 675 | semaphoreInfos[i].fSemaphore = resourceProvider->wrapBackendSemaphore( |
Greg Daniel | e6bfb7d | 2019-04-17 15:26:11 -0400 | [diff] [blame] | 676 | info.fSignalSemaphores[i], |
| 677 | GrResourceProvider::SemaphoreWrapType::kWillSignal, |
Greg Daniel | 17b7c05 | 2018-01-09 13:55:33 -0500 | [diff] [blame] | 678 | kBorrow_GrWrapOwnership); |
Greg Daniel | 5131678 | 2017-08-02 15:10:09 +0000 | [diff] [blame] | 679 | } else { |
Greg Daniel | 30a35e8 | 2019-11-19 14:12:25 -0500 | [diff] [blame] | 680 | semaphoreInfos[i].fSemaphore = resourceProvider->makeSemaphore(false); |
| 681 | semaphoreInfos[i].fDidCreate = true; |
Greg Daniel | 5131678 | 2017-08-02 15:10:09 +0000 | [diff] [blame] | 682 | } |
Greg Daniel | 30a35e8 | 2019-11-19 14:12:25 -0500 | [diff] [blame] | 683 | if (!semaphoreInfos[i].fSemaphore) { |
| 684 | semaphoreInfos[i].fDidCreate = false; |
| 685 | failedSemaphoreCreation = true; |
| 686 | } |
| 687 | } |
| 688 | if (!failedSemaphoreCreation) { |
| 689 | for (int i = 0; i < info.fNumSemaphores && !failedSemaphoreCreation; ++i) { |
| 690 | this->insertSemaphore(semaphoreInfos[i].fSemaphore.get()); |
Greg Daniel | 5131678 | 2017-08-02 15:10:09 +0000 | [diff] [blame] | 691 | } |
| 692 | } |
| 693 | } |
Greg Daniel | 30a35e8 | 2019-11-19 14:12:25 -0500 | [diff] [blame] | 694 | |
| 695 | // We always want to try flushing, so do that before checking if we failed semaphore creation. |
| 696 | if (!this->onFinishFlush(proxies, n, access, info, externalRequests) || |
| 697 | failedSemaphoreCreation) { |
| 698 | // If we didn't do the flush or failed semaphore creations then none of the semaphores were |
| 699 | // submitted. Therefore the client can't wait on any of the semaphores. Additionally any |
| 700 | // semaphores we created here the client is not responsible for deleting so we must make |
| 701 | // sure they get deleted. We do this by changing the ownership from borrowed to owned. |
| 702 | for (int i = 0; i < info.fNumSemaphores; ++i) { |
| 703 | if (semaphoreInfos[i].fDidCreate) { |
| 704 | SkASSERT(semaphoreInfos[i].fSemaphore); |
| 705 | semaphoreInfos[i].fSemaphore->setIsOwned(); |
| 706 | } |
| 707 | } |
| 708 | return GrSemaphoresSubmitted::kNo; |
| 709 | } |
| 710 | |
| 711 | for (int i = 0; i < info.fNumSemaphores; ++i) { |
| 712 | if (!info.fSignalSemaphores[i].isInitialized()) { |
| 713 | SkASSERT(semaphoreInfos[i].fSemaphore); |
| 714 | info.fSignalSemaphores[i] = semaphoreInfos[i].fSemaphore->backendSemaphore(); |
| 715 | } |
| 716 | } |
| 717 | |
Brian Salomon | 9ff5acb | 2019-05-08 09:04:47 -0400 | [diff] [blame] | 718 | return this->caps()->semaphoreSupport() ? GrSemaphoresSubmitted::kYes |
Greg Daniel | 5131678 | 2017-08-02 15:10:09 +0000 | [diff] [blame] | 719 | : GrSemaphoresSubmitted::kNo; |
| 720 | } |
Brian Osman | 71a1889 | 2017-08-10 10:23:25 -0400 | [diff] [blame] | 721 | |
Kevin Lubick | f4def34 | 2018-10-04 12:52:50 -0400 | [diff] [blame] | 722 | #ifdef SK_ENABLE_DUMP_GPU |
Brian Osman | 71a1889 | 2017-08-10 10:23:25 -0400 | [diff] [blame] | 723 | void GrGpu::dumpJSON(SkJSONWriter* writer) const { |
| 724 | writer->beginObject(); |
| 725 | |
| 726 | // TODO: Is there anything useful in the base class to dump here? |
| 727 | |
| 728 | this->onDumpJSON(writer); |
| 729 | |
| 730 | writer->endObject(); |
| 731 | } |
Kevin Lubick | f4def34 | 2018-10-04 12:52:50 -0400 | [diff] [blame] | 732 | #else |
| 733 | void GrGpu::dumpJSON(SkJSONWriter* writer) const { } |
| 734 | #endif |
Robert Phillips | 646f637 | 2018-09-25 09:31:10 -0400 | [diff] [blame] | 735 | |
Robert Phillips | f0ced62 | 2019-05-16 09:06:25 -0400 | [diff] [blame] | 736 | #if GR_TEST_UTILS |
| 737 | |
Robert Phillips | dbaf317 | 2019-02-06 15:12:53 -0500 | [diff] [blame] | 738 | #if GR_GPU_STATS |
| 739 | void GrGpu::Stats::dump(SkString* out) { |
| 740 | out->appendf("Render Target Binds: %d\n", fRenderTargetBinds); |
| 741 | out->appendf("Shader Compilations: %d\n", fShaderCompilations); |
| 742 | out->appendf("Textures Created: %d\n", fTextureCreates); |
| 743 | out->appendf("Texture Uploads: %d\n", fTextureUploads); |
| 744 | out->appendf("Transfers to Texture: %d\n", fTransfersToTexture); |
Brian Salomon | e05ba5a | 2019-04-08 11:59:07 -0400 | [diff] [blame] | 745 | out->appendf("Transfers from Surface: %d\n", fTransfersFromSurface); |
Robert Phillips | dbaf317 | 2019-02-06 15:12:53 -0500 | [diff] [blame] | 746 | out->appendf("Stencil Buffer Creates: %d\n", fStencilAttachmentCreates); |
| 747 | out->appendf("Number of draws: %d\n", fNumDraws); |
Robert Phillips | f9fcf7f | 2019-07-11 09:03:27 -0400 | [diff] [blame] | 748 | out->appendf("Number of Scratch Textures reused %d\n", fNumScratchTexturesReused); |
Robert Phillips | dbaf317 | 2019-02-06 15:12:53 -0500 | [diff] [blame] | 749 | } |
| 750 | |
| 751 | void GrGpu::Stats::dumpKeyValuePairs(SkTArray<SkString>* keys, SkTArray<double>* values) { |
| 752 | keys->push_back(SkString("render_target_binds")); values->push_back(fRenderTargetBinds); |
| 753 | keys->push_back(SkString("shader_compilations")); values->push_back(fShaderCompilations); |
Robert Phillips | dbaf317 | 2019-02-06 15:12:53 -0500 | [diff] [blame] | 754 | } |
| 755 | |
Robert Phillips | 57ef680 | 2019-09-23 10:12:47 -0400 | [diff] [blame] | 756 | #endif // GR_GPU_STATS |
| 757 | #endif // GR_TEST_UTILS |
Robert Phillips | dbaf317 | 2019-02-06 15:12:53 -0500 | [diff] [blame] | 758 | |
Brian Salomon | 85c3d68 | 2019-11-04 15:04:54 -0500 | [diff] [blame] | 759 | bool GrGpu::MipMapsAreCorrect(SkISize dimensions, const BackendTextureData* data, int numLevels) { |
| 760 | if (numLevels != 1 && |
| 761 | numLevels != SkMipMap::ComputeLevelCount(dimensions.width(), dimensions.height()) + 1) { |
| 762 | return false; |
| 763 | } |
Robert Phillips | 57ef680 | 2019-09-23 10:12:47 -0400 | [diff] [blame] | 764 | |
Robert Phillips | 42716d4 | 2019-12-16 12:19:54 -0500 | [diff] [blame] | 765 | if (!data || data->type() == BackendTextureData::Type::kColor) { |
Robert Phillips | 57ef680 | 2019-09-23 10:12:47 -0400 | [diff] [blame] | 766 | return true; |
| 767 | } |
| 768 | |
Robert Phillips | 42716d4 | 2019-12-16 12:19:54 -0500 | [diff] [blame] | 769 | if (data->type() == BackendTextureData::Type::kCompressed) { |
| 770 | return false; |
| 771 | } |
| 772 | |
| 773 | SkASSERT(data->type() == BackendTextureData::Type::kPixmaps); |
| 774 | |
Brian Salomon | 85c3d68 | 2019-11-04 15:04:54 -0500 | [diff] [blame] | 775 | if (data->pixmap(0).dimensions() != dimensions) { |
Robert Phillips | 57ef680 | 2019-09-23 10:12:47 -0400 | [diff] [blame] | 776 | return false; |
| 777 | } |
| 778 | |
Brian Salomon | 85c3d68 | 2019-11-04 15:04:54 -0500 | [diff] [blame] | 779 | SkColorType colorType = data->pixmap(0).colorType(); |
| 780 | for (int i = 1; i < numLevels; ++i) { |
| 781 | dimensions = {SkTMax(1, dimensions.width() /2), |
| 782 | SkTMax(1, dimensions.height()/2)}; |
| 783 | if (dimensions != data->pixmap(i).dimensions()) { |
Robert Phillips | 57ef680 | 2019-09-23 10:12:47 -0400 | [diff] [blame] | 784 | return false; |
| 785 | } |
Brian Salomon | 85c3d68 | 2019-11-04 15:04:54 -0500 | [diff] [blame] | 786 | if (colorType != data->pixmap(i).colorType()) { |
| 787 | return false; |
Robert Phillips | 57ef680 | 2019-09-23 10:12:47 -0400 | [diff] [blame] | 788 | } |
Robert Phillips | 57ef680 | 2019-09-23 10:12:47 -0400 | [diff] [blame] | 789 | } |
Robert Phillips | 57ef680 | 2019-09-23 10:12:47 -0400 | [diff] [blame] | 790 | return true; |
| 791 | } |
| 792 | |
Robert Phillips | b915c94 | 2019-12-17 14:44:37 -0500 | [diff] [blame] | 793 | bool GrGpu::CompressedDataIsCorrect(SkISize dimensions, SkImage::CompressionType compressionType, |
| 794 | GrMipMapped mipMapped, const BackendTextureData* data) { |
| 795 | |
| 796 | if (!data || data->type() == BackendTextureData::Type::kColor) { |
| 797 | return true; |
| 798 | } |
| 799 | |
| 800 | if (data->type() == BackendTextureData::Type::kPixmaps) { |
| 801 | return false; |
| 802 | } |
| 803 | |
| 804 | SkASSERT(data->type() == BackendTextureData::Type::kCompressed); |
| 805 | |
Robert Phillips | 0d7e2f1 | 2019-12-18 13:01:04 -0500 | [diff] [blame] | 806 | size_t computedSize = GrCompressedDataSize(compressionType, dimensions, |
| 807 | nullptr, mipMapped); |
Robert Phillips | b915c94 | 2019-12-17 14:44:37 -0500 | [diff] [blame] | 808 | |
| 809 | return computedSize == data->compressedSize(); |
| 810 | } |
| 811 | |
Brian Salomon | 85c3d68 | 2019-11-04 15:04:54 -0500 | [diff] [blame] | 812 | GrBackendTexture GrGpu::createBackendTexture(SkISize dimensions, |
| 813 | const GrBackendFormat& format, |
| 814 | GrRenderable renderable, |
| 815 | const BackendTextureData* data, |
| 816 | int numMipLevels, |
| 817 | GrProtected isProtected) { |
Robert Phillips | 57ef680 | 2019-09-23 10:12:47 -0400 | [diff] [blame] | 818 | const GrCaps* caps = this->caps(); |
| 819 | |
| 820 | if (!format.isValid()) { |
| 821 | return {}; |
| 822 | } |
| 823 | |
Robert Phillips | d34691b | 2019-09-24 13:38:43 -0400 | [diff] [blame] | 824 | if (caps->isFormatCompressed(format)) { |
| 825 | // Compressed formats must go through the createCompressedBackendTexture API |
| 826 | return {}; |
| 827 | } |
Robert Phillips | 57ef680 | 2019-09-23 10:12:47 -0400 | [diff] [blame] | 828 | |
Brian Salomon | 85c3d68 | 2019-11-04 15:04:54 -0500 | [diff] [blame] | 829 | if (data && data->type() == BackendTextureData::Type::kPixmaps) { |
| 830 | auto ct = SkColorTypeToGrColorType(data->pixmap(0).colorType()); |
| 831 | if (!caps->areColorTypeAndFormatCompatible(ct, format)) { |
| 832 | return {}; |
| 833 | } |
| 834 | } |
| 835 | |
| 836 | if (dimensions.isEmpty() || dimensions.width() > caps->maxTextureSize() || |
| 837 | dimensions.height() > caps->maxTextureSize()) { |
Robert Phillips | 57ef680 | 2019-09-23 10:12:47 -0400 | [diff] [blame] | 838 | return {}; |
| 839 | } |
| 840 | |
Brian Salomon | 85c3d68 | 2019-11-04 15:04:54 -0500 | [diff] [blame] | 841 | if (numMipLevels > 1 && !this->caps()->mipMapSupport()) { |
Robert Phillips | 57ef680 | 2019-09-23 10:12:47 -0400 | [diff] [blame] | 842 | return {}; |
| 843 | } |
| 844 | |
Brian Salomon | 85c3d68 | 2019-11-04 15:04:54 -0500 | [diff] [blame] | 845 | if (!MipMapsAreCorrect(dimensions, data, numMipLevels)) { |
Robert Phillips | 57ef680 | 2019-09-23 10:12:47 -0400 | [diff] [blame] | 846 | return {}; |
| 847 | } |
| 848 | |
Robert Phillips | 0d7e2f1 | 2019-12-18 13:01:04 -0500 | [diff] [blame] | 849 | return this->onCreateBackendTexture(dimensions, format, renderable, data, |
| 850 | numMipLevels > 1 ? GrMipMapped::kYes : GrMipMapped::kNo, |
Brian Salomon | 85c3d68 | 2019-11-04 15:04:54 -0500 | [diff] [blame] | 851 | isProtected); |
Robert Phillips | 57ef680 | 2019-09-23 10:12:47 -0400 | [diff] [blame] | 852 | } |
Robert Phillips | b915c94 | 2019-12-17 14:44:37 -0500 | [diff] [blame] | 853 | |
| 854 | GrBackendTexture GrGpu::createCompressedBackendTexture(SkISize dimensions, |
| 855 | const GrBackendFormat& format, |
| 856 | const BackendTextureData* data, |
| 857 | GrMipMapped mipMapped, |
| 858 | GrProtected isProtected) { |
| 859 | const GrCaps* caps = this->caps(); |
| 860 | |
| 861 | if (!format.isValid()) { |
| 862 | return {}; |
| 863 | } |
| 864 | |
| 865 | SkImage::CompressionType compressionType = caps->compressionType(format); |
| 866 | if (compressionType == SkImage::CompressionType::kNone) { |
| 867 | // Uncompressed formats must go through the createBackendTexture API |
| 868 | return {}; |
| 869 | } |
| 870 | |
| 871 | if (dimensions.isEmpty() || |
| 872 | dimensions.width() > caps->maxTextureSize() || |
| 873 | dimensions.height() > caps->maxTextureSize()) { |
| 874 | return {}; |
| 875 | } |
| 876 | |
| 877 | if (mipMapped == GrMipMapped::kYes && !this->caps()->mipMapSupport()) { |
| 878 | return {}; |
| 879 | } |
| 880 | |
| 881 | if (!CompressedDataIsCorrect(dimensions, compressionType, mipMapped, data)) { |
| 882 | return {}; |
| 883 | } |
| 884 | |
| 885 | return this->onCreateCompressedBackendTexture(dimensions, format, data, mipMapped, |
| 886 | isProtected); |
| 887 | } |