Brian Osman | e8e5458 | 2016-11-28 10:06:27 -0500 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2016 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. |
| 6 | */ |
| 7 | |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 8 | #include "include/private/GrRecordingContext.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 9 | #include "src/core/SkMipMap.h" |
| 10 | #include "src/core/SkRectPriv.h" |
| 11 | #include "src/gpu/GrClip.h" |
| 12 | #include "src/gpu/GrContextPriv.h" |
| 13 | #include "src/gpu/GrProxyProvider.h" |
| 14 | #include "src/gpu/GrRecordingContextPriv.h" |
| 15 | #include "src/gpu/GrRenderTargetContext.h" |
| 16 | #include "src/gpu/GrTextureProducer.h" |
Greg Daniel | f91aeb2 | 2019-06-18 09:58:02 -0400 | [diff] [blame] | 17 | #include "src/gpu/GrTextureProxy.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 18 | #include "src/gpu/SkGr.h" |
| 19 | #include "src/gpu/effects/GrBicubicEffect.h" |
| 20 | #include "src/gpu/effects/GrTextureDomain.h" |
| 21 | #include "src/gpu/effects/generated/GrSimpleTextureEffect.h" |
Brian Osman | e8e5458 | 2016-11-28 10:06:27 -0500 | [diff] [blame] | 22 | |
Robert Phillips | 9338c60 | 2019-02-19 12:52:29 -0500 | [diff] [blame] | 23 | sk_sp<GrTextureProxy> GrTextureProducer::CopyOnGpu(GrRecordingContext* context, |
Robert Phillips | b66b42f | 2017-03-14 08:53:02 -0400 | [diff] [blame] | 24 | sk_sp<GrTextureProxy> inputProxy, |
Brian Salomon | d628747 | 2019-06-24 15:50:07 -0400 | [diff] [blame] | 25 | GrColorType colorType, |
Greg Daniel | e1da1d9 | 2017-10-06 15:59:27 -0400 | [diff] [blame] | 26 | const CopyParams& copyParams, |
| 27 | bool dstWillRequireMipMaps) { |
Robert Phillips | b66b42f | 2017-03-14 08:53:02 -0400 | [diff] [blame] | 28 | SkASSERT(context); |
| 29 | |
Robert Phillips | b66b42f | 2017-03-14 08:53:02 -0400 | [diff] [blame] | 30 | const SkRect dstRect = SkRect::MakeIWH(copyParams.fWidth, copyParams.fHeight); |
Greg Daniel | 45d6303 | 2017-10-30 13:41:26 -0400 | [diff] [blame] | 31 | GrMipMapped mipMapped = dstWillRequireMipMaps ? GrMipMapped::kYes : GrMipMapped::kNo; |
Robert Phillips | b66b42f | 2017-03-14 08:53:02 -0400 | [diff] [blame] | 32 | |
Greg Daniel | 09c9400 | 2018-06-08 22:11:51 +0000 | [diff] [blame] | 33 | SkRect localRect = SkRect::MakeWH(inputProxy->width(), inputProxy->height()); |
| 34 | |
| 35 | bool needsDomain = false; |
| 36 | bool resizing = false; |
| 37 | if (copyParams.fFilter != GrSamplerState::Filter::kNearest) { |
| 38 | bool resizing = localRect.width() != dstRect.width() || |
| 39 | localRect.height() != dstRect.height(); |
| 40 | needsDomain = resizing && !GrProxyProvider::IsFunctionallyExact(inputProxy.get()); |
| 41 | } |
| 42 | |
| 43 | if (copyParams.fFilter == GrSamplerState::Filter::kNearest && !needsDomain && !resizing && |
| 44 | dstWillRequireMipMaps) { |
| 45 | sk_sp<GrTextureProxy> proxy = GrCopyBaseMipMapToTextureProxy(context, inputProxy.get()); |
| 46 | if (proxy) { |
| 47 | return proxy; |
| 48 | } |
| 49 | } |
| 50 | |
Brian Salomon | bf6b979 | 2019-08-21 09:38:10 -0400 | [diff] [blame] | 51 | auto copyRTC = context->priv().makeDeferredRenderTargetContextWithFallback( |
| 52 | SkBackingFit::kExact, dstRect.width(), dstRect.height(), colorType, nullptr, 1, |
| 53 | mipMapped, inputProxy->origin()); |
Robert Phillips | b66b42f | 2017-03-14 08:53:02 -0400 | [diff] [blame] | 54 | if (!copyRTC) { |
| 55 | return nullptr; |
| 56 | } |
| 57 | |
| 58 | GrPaint paint; |
Robert Phillips | b66b42f | 2017-03-14 08:53:02 -0400 | [diff] [blame] | 59 | |
| 60 | if (needsDomain) { |
| 61 | const SkRect domain = localRect.makeInset(0.5f, 0.5f); |
| 62 | // This would cause us to read values from outside the subset. Surely, the caller knows |
| 63 | // better! |
Brian Salomon | 2bbdcc4 | 2017-09-07 12:36:34 -0400 | [diff] [blame] | 64 | SkASSERT(copyParams.fFilter != GrSamplerState::Filter::kMipMap); |
Robert Phillips | b66b42f | 2017-03-14 08:53:02 -0400 | [diff] [blame] | 65 | paint.addColorFragmentProcessor( |
Brian Osman | 2240be9 | 2017-10-18 13:15:13 -0400 | [diff] [blame] | 66 | GrTextureDomainEffect::Make(std::move(inputProxy), SkMatrix::I(), domain, |
| 67 | GrTextureDomain::kClamp_Mode, copyParams.fFilter)); |
Robert Phillips | b66b42f | 2017-03-14 08:53:02 -0400 | [diff] [blame] | 68 | } else { |
Brian Salomon | 2bbdcc4 | 2017-09-07 12:36:34 -0400 | [diff] [blame] | 69 | GrSamplerState samplerState(GrSamplerState::WrapMode::kClamp, copyParams.fFilter); |
Brian Osman | 2240be9 | 2017-10-18 13:15:13 -0400 | [diff] [blame] | 70 | paint.addColorTextureProcessor(std::move(inputProxy), SkMatrix::I(), samplerState); |
Robert Phillips | b66b42f | 2017-03-14 08:53:02 -0400 | [diff] [blame] | 71 | } |
| 72 | paint.setPorterDuffXPFactory(SkBlendMode::kSrc); |
| 73 | |
| 74 | copyRTC->fillRectToRect(GrNoClip(), std::move(paint), GrAA::kNo, SkMatrix::I(), dstRect, |
| 75 | localRect); |
| 76 | return copyRTC->asTextureProxyRef(); |
| 77 | } |
| 78 | |
Brian Osman | e8e5458 | 2016-11-28 10:06:27 -0500 | [diff] [blame] | 79 | /** Determines whether a texture domain is necessary and if so what domain to use. There are two |
| 80 | * rectangles to consider: |
Robert Phillips | 3798c86 | 2017-03-27 11:08:16 -0400 | [diff] [blame] | 81 | * - The first is the content area specified by the texture adjuster (i.e., textureContentArea). |
| 82 | * We can *never* allow filtering to cause bleed of pixels outside this rectangle. |
| 83 | * - The second rectangle is the constraint rectangle (i.e., constraintRect), which is known to |
| 84 | * be contained by the content area. The filterConstraint specifies whether we are allowed to |
| 85 | * bleed across this rect. |
Brian Osman | e8e5458 | 2016-11-28 10:06:27 -0500 | [diff] [blame] | 86 | * |
| 87 | * We want to avoid using a domain if possible. We consider the above rectangles, the filter type, |
| 88 | * and whether the coords generated by the draw would all fall within the constraint rect. If the |
| 89 | * latter is true we only need to consider whether the filter would extend beyond the rects. |
| 90 | */ |
| 91 | GrTextureProducer::DomainMode GrTextureProducer::DetermineDomainMode( |
Brian Salomon | 2bbdcc4 | 2017-09-07 12:36:34 -0400 | [diff] [blame] | 92 | const SkRect& constraintRect, |
| 93 | FilterConstraint filterConstraint, |
| 94 | bool coordsLimitedToConstraintRect, |
| 95 | GrTextureProxy* proxy, |
Brian Salomon | 2bbdcc4 | 2017-09-07 12:36:34 -0400 | [diff] [blame] | 96 | const GrSamplerState::Filter* filterModeOrNullForBicubic, |
| 97 | SkRect* domainRect) { |
Robert Phillips | 51e7ca3 | 2017-03-27 10:14:08 -0400 | [diff] [blame] | 98 | const SkIRect proxyBounds = SkIRect::MakeWH(proxy->width(), proxy->height()); |
| 99 | |
| 100 | SkASSERT(proxyBounds.contains(constraintRect)); |
Robert Phillips | 51e7ca3 | 2017-03-27 10:14:08 -0400 | [diff] [blame] | 101 | |
Robert Phillips | 1afd4cd | 2018-01-08 13:40:32 -0500 | [diff] [blame] | 102 | const bool proxyIsExact = GrProxyProvider::IsFunctionallyExact(proxy); |
Brian Salomon | 4df0092 | 2017-09-07 16:34:11 +0000 | [diff] [blame] | 103 | |
Robert Phillips | 51e7ca3 | 2017-03-27 10:14:08 -0400 | [diff] [blame] | 104 | // If the constraint rectangle contains the whole proxy then no need for a domain. |
| 105 | if (constraintRect.contains(proxyBounds) && proxyIsExact) { |
| 106 | return kNoDomain_DomainMode; |
| 107 | } |
| 108 | |
Robert Phillips | 51e7ca3 | 2017-03-27 10:14:08 -0400 | [diff] [blame] | 109 | bool restrictFilterToRect = (filterConstraint == GrTextureProducer::kYes_FilterConstraint); |
| 110 | |
| 111 | // If we can filter outside the constraint rect, and there is no non-content area of the |
| 112 | // proxy, and we aren't going to generate sample coords outside the constraint rect then we |
| 113 | // don't need a domain. |
Greg Daniel | c77085d | 2017-11-01 16:38:48 -0400 | [diff] [blame] | 114 | if (!restrictFilterToRect && proxyIsExact && coordsLimitedToConstraintRect) { |
Robert Phillips | 51e7ca3 | 2017-03-27 10:14:08 -0400 | [diff] [blame] | 115 | return kNoDomain_DomainMode; |
| 116 | } |
| 117 | |
| 118 | // Get the domain inset based on sampling mode (or bail if mipped) |
Brian Salomon | 4df0092 | 2017-09-07 16:34:11 +0000 | [diff] [blame] | 119 | SkScalar filterHalfWidth = 0.f; |
Robert Phillips | 51e7ca3 | 2017-03-27 10:14:08 -0400 | [diff] [blame] | 120 | if (filterModeOrNullForBicubic) { |
| 121 | switch (*filterModeOrNullForBicubic) { |
Brian Salomon | 2bbdcc4 | 2017-09-07 12:36:34 -0400 | [diff] [blame] | 122 | case GrSamplerState::Filter::kNearest: |
Robert Phillips | 51e7ca3 | 2017-03-27 10:14:08 -0400 | [diff] [blame] | 123 | if (coordsLimitedToConstraintRect) { |
| 124 | return kNoDomain_DomainMode; |
Brian Salomon | 4df0092 | 2017-09-07 16:34:11 +0000 | [diff] [blame] | 125 | } else { |
| 126 | filterHalfWidth = 0.f; |
Robert Phillips | 51e7ca3 | 2017-03-27 10:14:08 -0400 | [diff] [blame] | 127 | } |
| 128 | break; |
Brian Salomon | 2bbdcc4 | 2017-09-07 12:36:34 -0400 | [diff] [blame] | 129 | case GrSamplerState::Filter::kBilerp: |
Brian Salomon | 4df0092 | 2017-09-07 16:34:11 +0000 | [diff] [blame] | 130 | filterHalfWidth = .5f; |
Robert Phillips | 51e7ca3 | 2017-03-27 10:14:08 -0400 | [diff] [blame] | 131 | break; |
Brian Salomon | 2bbdcc4 | 2017-09-07 12:36:34 -0400 | [diff] [blame] | 132 | case GrSamplerState::Filter::kMipMap: |
Greg Daniel | c77085d | 2017-11-01 16:38:48 -0400 | [diff] [blame] | 133 | if (restrictFilterToRect || !proxyIsExact) { |
Brian Salomon | 4df0092 | 2017-09-07 16:34:11 +0000 | [diff] [blame] | 134 | // No domain can save us here. |
| 135 | return kTightCopy_DomainMode; |
| 136 | } |
| 137 | return kNoDomain_DomainMode; |
Robert Phillips | 51e7ca3 | 2017-03-27 10:14:08 -0400 | [diff] [blame] | 138 | } |
Brian Salomon | 4df0092 | 2017-09-07 16:34:11 +0000 | [diff] [blame] | 139 | } else { |
| 140 | // bicubic does nearest filtering internally. |
| 141 | filterHalfWidth = 1.5f; |
Robert Phillips | 51e7ca3 | 2017-03-27 10:14:08 -0400 | [diff] [blame] | 142 | } |
| 143 | |
| 144 | // Both bilerp and bicubic use bilinear filtering and so need to be clamped to the center |
| 145 | // of the edge texel. Pinning to the texel center has no impact on nearest mode and MIP-maps |
| 146 | |
| 147 | static const SkScalar kDomainInset = 0.5f; |
| 148 | // Figure out the limits of pixels we're allowed to sample from. |
| 149 | // Unless we know the amount of outset and the texture matrix we have to conservatively enforce |
| 150 | // the domain. |
| 151 | if (restrictFilterToRect) { |
| 152 | *domainRect = constraintRect.makeInset(kDomainInset, kDomainInset); |
Greg Daniel | c77085d | 2017-11-01 16:38:48 -0400 | [diff] [blame] | 153 | } else if (!proxyIsExact) { |
| 154 | // If we got here then: proxy is not exact, the coords are limited to the |
Brian Salomon | 4df0092 | 2017-09-07 16:34:11 +0000 | [diff] [blame] | 155 | // constraint rect, and we're allowed to filter across the constraint rect boundary. So |
Greg Daniel | c77085d | 2017-11-01 16:38:48 -0400 | [diff] [blame] | 156 | // we check whether the filter would reach across the edge of the proxy. |
Brian Salomon | 4df0092 | 2017-09-07 16:34:11 +0000 | [diff] [blame] | 157 | // We will only set the sides that are required. |
| 158 | |
Mike Reed | 274218e | 2018-01-08 15:05:02 -0500 | [diff] [blame] | 159 | *domainRect = SkRectPriv::MakeLargest(); |
Brian Salomon | 4df0092 | 2017-09-07 16:34:11 +0000 | [diff] [blame] | 160 | if (coordsLimitedToConstraintRect) { |
| 161 | // We may be able to use the fact that the texture coords are limited to the constraint |
| 162 | // rect in order to avoid having to add a domain. |
| 163 | bool needContentAreaConstraint = false; |
Greg Daniel | c77085d | 2017-11-01 16:38:48 -0400 | [diff] [blame] | 164 | if (proxyBounds.fRight - filterHalfWidth < constraintRect.fRight) { |
| 165 | domainRect->fRight = proxyBounds.fRight - kDomainInset; |
Brian Salomon | 4df0092 | 2017-09-07 16:34:11 +0000 | [diff] [blame] | 166 | needContentAreaConstraint = true; |
| 167 | } |
Greg Daniel | c77085d | 2017-11-01 16:38:48 -0400 | [diff] [blame] | 168 | if (proxyBounds.fBottom - filterHalfWidth < constraintRect.fBottom) { |
| 169 | domainRect->fBottom = proxyBounds.fBottom - kDomainInset; |
Brian Salomon | 4df0092 | 2017-09-07 16:34:11 +0000 | [diff] [blame] | 170 | needContentAreaConstraint = true; |
| 171 | } |
| 172 | if (!needContentAreaConstraint) { |
| 173 | return kNoDomain_DomainMode; |
| 174 | } |
| 175 | } else { |
| 176 | // Our sample coords for the texture are allowed to be outside the constraintRect so we |
| 177 | // don't consider it when computing the domain. |
Greg Daniel | c77085d | 2017-11-01 16:38:48 -0400 | [diff] [blame] | 178 | domainRect->fRight = proxyBounds.fRight - kDomainInset; |
| 179 | domainRect->fBottom = proxyBounds.fBottom - kDomainInset; |
Robert Phillips | 51e7ca3 | 2017-03-27 10:14:08 -0400 | [diff] [blame] | 180 | } |
Brian Salomon | 4df0092 | 2017-09-07 16:34:11 +0000 | [diff] [blame] | 181 | } else { |
| 182 | return kNoDomain_DomainMode; |
Robert Phillips | 51e7ca3 | 2017-03-27 10:14:08 -0400 | [diff] [blame] | 183 | } |
Brian Salomon | 4df0092 | 2017-09-07 16:34:11 +0000 | [diff] [blame] | 184 | |
| 185 | if (domainRect->fLeft > domainRect->fRight) { |
| 186 | domainRect->fLeft = domainRect->fRight = SkScalarAve(domainRect->fLeft, domainRect->fRight); |
| 187 | } |
| 188 | if (domainRect->fTop > domainRect->fBottom) { |
| 189 | domainRect->fTop = domainRect->fBottom = SkScalarAve(domainRect->fTop, domainRect->fBottom); |
| 190 | } |
| 191 | return kDomain_DomainMode; |
Robert Phillips | 51e7ca3 | 2017-03-27 10:14:08 -0400 | [diff] [blame] | 192 | } |
| 193 | |
Michael Ludwig | ddeed37 | 2019-02-20 16:50:10 -0500 | [diff] [blame] | 194 | std::unique_ptr<GrFragmentProcessor> GrTextureProducer::createFragmentProcessorForDomainAndFilter( |
Brian Salomon | aff329b | 2017-08-11 09:40:37 -0400 | [diff] [blame] | 195 | sk_sp<GrTextureProxy> proxy, |
Brian Salomon | aff329b | 2017-08-11 09:40:37 -0400 | [diff] [blame] | 196 | const SkMatrix& textureMatrix, |
| 197 | DomainMode domainMode, |
| 198 | const SkRect& domain, |
Brian Salomon | 2bbdcc4 | 2017-09-07 12:36:34 -0400 | [diff] [blame] | 199 | const GrSamplerState::Filter* filterOrNullForBicubic) { |
Robert Phillips | b66b42f | 2017-03-14 08:53:02 -0400 | [diff] [blame] | 200 | SkASSERT(kTightCopy_DomainMode != domainMode); |
Michael Ludwig | ddeed37 | 2019-02-20 16:50:10 -0500 | [diff] [blame] | 201 | bool clampToBorderSupport = fContext->priv().caps()->clampToBorderSupport(); |
Robert Phillips | b66b42f | 2017-03-14 08:53:02 -0400 | [diff] [blame] | 202 | if (filterOrNullForBicubic) { |
Michael Ludwig | ddeed37 | 2019-02-20 16:50:10 -0500 | [diff] [blame] | 203 | if (kDomain_DomainMode == domainMode || (fDomainNeedsDecal && !clampToBorderSupport)) { |
| 204 | GrTextureDomain::Mode wrapMode = fDomainNeedsDecal ? GrTextureDomain::kDecal_Mode |
| 205 | : GrTextureDomain::kClamp_Mode; |
Brian Osman | 2240be9 | 2017-10-18 13:15:13 -0400 | [diff] [blame] | 206 | return GrTextureDomainEffect::Make(std::move(proxy), textureMatrix, domain, |
Michael Ludwig | ddeed37 | 2019-02-20 16:50:10 -0500 | [diff] [blame] | 207 | wrapMode, *filterOrNullForBicubic); |
Robert Phillips | b66b42f | 2017-03-14 08:53:02 -0400 | [diff] [blame] | 208 | } else { |
Michael Ludwig | ddeed37 | 2019-02-20 16:50:10 -0500 | [diff] [blame] | 209 | GrSamplerState::WrapMode wrapMode = |
| 210 | fDomainNeedsDecal ? GrSamplerState::WrapMode::kClampToBorder |
| 211 | : GrSamplerState::WrapMode::kClamp; |
| 212 | GrSamplerState samplerState(wrapMode, *filterOrNullForBicubic); |
Brian Osman | 2240be9 | 2017-10-18 13:15:13 -0400 | [diff] [blame] | 213 | return GrSimpleTextureEffect::Make(std::move(proxy), textureMatrix, samplerState); |
Robert Phillips | b66b42f | 2017-03-14 08:53:02 -0400 | [diff] [blame] | 214 | } |
| 215 | } else { |
Michael Ludwig | ddeed37 | 2019-02-20 16:50:10 -0500 | [diff] [blame] | 216 | static const GrSamplerState::WrapMode kClampClamp[] = { |
| 217 | GrSamplerState::WrapMode::kClamp, GrSamplerState::WrapMode::kClamp}; |
| 218 | static const GrSamplerState::WrapMode kDecalDecal[] = { |
| 219 | GrSamplerState::WrapMode::kClampToBorder, GrSamplerState::WrapMode::kClampToBorder}; |
| 220 | |
Brian Salomon | a86fc7a | 2019-05-28 20:42:58 -0400 | [diff] [blame] | 221 | static constexpr auto kDir = GrBicubicEffect::Direction::kXY; |
Michael Ludwig | ddeed37 | 2019-02-20 16:50:10 -0500 | [diff] [blame] | 222 | if (kDomain_DomainMode == domainMode || (fDomainNeedsDecal && !clampToBorderSupport)) { |
| 223 | GrTextureDomain::Mode wrapMode = fDomainNeedsDecal ? GrTextureDomain::kDecal_Mode |
| 224 | : GrTextureDomain::kClamp_Mode; |
Brian Salomon | a86fc7a | 2019-05-28 20:42:58 -0400 | [diff] [blame] | 225 | return GrBicubicEffect::Make(std::move(proxy), textureMatrix, kClampClamp, wrapMode, |
Brian Salomon | 1127c0b | 2019-06-13 20:22:10 +0000 | [diff] [blame] | 226 | wrapMode, kDir, this->alphaType(), |
Michael Ludwig | ddeed37 | 2019-02-20 16:50:10 -0500 | [diff] [blame] | 227 | kDomain_DomainMode == domainMode ? &domain : nullptr); |
Robert Phillips | b66b42f | 2017-03-14 08:53:02 -0400 | [diff] [blame] | 228 | } else { |
Michael Ludwig | ddeed37 | 2019-02-20 16:50:10 -0500 | [diff] [blame] | 229 | return GrBicubicEffect::Make(std::move(proxy), textureMatrix, |
Brian Salomon | 1127c0b | 2019-06-13 20:22:10 +0000 | [diff] [blame] | 230 | fDomainNeedsDecal ? kDecalDecal : kClampClamp, kDir, |
| 231 | this->alphaType()); |
Robert Phillips | b66b42f | 2017-03-14 08:53:02 -0400 | [diff] [blame] | 232 | } |
| 233 | } |
| 234 | } |
Brian Salomon | 2a943df | 2018-05-04 13:43:19 -0400 | [diff] [blame] | 235 | |
| 236 | sk_sp<GrTextureProxy> GrTextureProducer::refTextureProxyForParams( |
Michael Ludwig | ddeed37 | 2019-02-20 16:50:10 -0500 | [diff] [blame] | 237 | const GrSamplerState::Filter* filterOrNullForBicubic, |
| 238 | SkScalar scaleAdjust[2]) { |
| 239 | GrSamplerState sampler; // Default is nearest + clamp |
| 240 | if (filterOrNullForBicubic) { |
| 241 | sampler.setFilterMode(*filterOrNullForBicubic); |
| 242 | } |
| 243 | if (fDomainNeedsDecal) { |
| 244 | // Assuming hardware support, switch to clamp-to-border instead of clamp |
| 245 | if (fContext->priv().caps()->clampToBorderSupport()) { |
| 246 | sampler.setWrapModeX(GrSamplerState::WrapMode::kClampToBorder); |
| 247 | sampler.setWrapModeY(GrSamplerState::WrapMode::kClampToBorder); |
| 248 | } |
| 249 | } |
| 250 | return this->refTextureProxyForParams(sampler, scaleAdjust); |
| 251 | } |
| 252 | |
| 253 | sk_sp<GrTextureProxy> GrTextureProducer::refTextureProxyForParams( |
Brian Salomon | 2a943df | 2018-05-04 13:43:19 -0400 | [diff] [blame] | 254 | const GrSamplerState& sampler, |
Brian Salomon | 2a943df | 2018-05-04 13:43:19 -0400 | [diff] [blame] | 255 | SkScalar scaleAdjust[2]) { |
| 256 | // Check that the caller pre-initialized scaleAdjust |
| 257 | SkASSERT(!scaleAdjust || (scaleAdjust[0] == 1 && scaleAdjust[1] == 1)); |
| 258 | // Check that if the caller passed nullptr for scaleAdjust that we're in the case where there |
| 259 | // can be no scaling. |
| 260 | SkDEBUGCODE(bool expectNoScale = (sampler.filter() != GrSamplerState::Filter::kMipMap && |
| 261 | !sampler.isRepeated())); |
| 262 | SkASSERT(scaleAdjust || expectNoScale); |
Greg Daniel | 8e9b4c4 | 2018-07-20 10:30:48 -0400 | [diff] [blame] | 263 | |
| 264 | int mipCount = SkMipMap::ComputeLevelCount(this->width(), this->height()); |
| 265 | bool willBeMipped = GrSamplerState::Filter::kMipMap == sampler.filter() && mipCount && |
Robert Phillips | 9338c60 | 2019-02-19 12:52:29 -0500 | [diff] [blame] | 266 | this->context()->priv().caps()->mipMapSupport(); |
Greg Daniel | 8e9b4c4 | 2018-07-20 10:30:48 -0400 | [diff] [blame] | 267 | |
Brian Osman | 6064e1c | 2018-10-19 14:27:54 -0400 | [diff] [blame] | 268 | auto result = this->onRefTextureProxyForParams(sampler, willBeMipped, scaleAdjust); |
Brian Salomon | 2a943df | 2018-05-04 13:43:19 -0400 | [diff] [blame] | 269 | |
Greg Daniel | 022b1e0 | 2018-07-20 14:54:00 -0400 | [diff] [blame] | 270 | // Check to make sure that if we say the texture willBeMipped that the returned texture has mip |
| 271 | // maps, unless the config is not copyable. |
| 272 | SkASSERT(!result || !willBeMipped || result->mipMapped() == GrMipMapped::kYes || |
Greg Daniel | 6980c4e | 2019-07-30 16:18:18 -0400 | [diff] [blame] | 273 | !this->context()->priv().caps()->isFormatCopyable(result->backendFormat())); |
Greg Daniel | 022b1e0 | 2018-07-20 14:54:00 -0400 | [diff] [blame] | 274 | |
Brian Salomon | 2a943df | 2018-05-04 13:43:19 -0400 | [diff] [blame] | 275 | // Check that the "no scaling expected" case always returns a proxy of the same size as the |
| 276 | // producer. |
| 277 | SkASSERT(!result || !expectNoScale || |
| 278 | (result->width() == this->width() && result->height() == this->height())); |
| 279 | return result; |
| 280 | } |
Greg Daniel | 5f4b09d | 2018-06-12 16:39:59 -0400 | [diff] [blame] | 281 | |
Brian Osman | 6064e1c | 2018-10-19 14:27:54 -0400 | [diff] [blame] | 282 | sk_sp<GrTextureProxy> GrTextureProducer::refTextureProxy(GrMipMapped willNeedMips) { |
Greg Daniel | 5f4b09d | 2018-06-12 16:39:59 -0400 | [diff] [blame] | 283 | GrSamplerState::Filter filter = |
| 284 | GrMipMapped::kNo == willNeedMips ? GrSamplerState::Filter::kNearest |
| 285 | : GrSamplerState::Filter::kMipMap; |
| 286 | GrSamplerState sampler(GrSamplerState::WrapMode::kClamp, filter); |
Greg Daniel | 8e9b4c4 | 2018-07-20 10:30:48 -0400 | [diff] [blame] | 287 | |
| 288 | int mipCount = SkMipMap::ComputeLevelCount(this->width(), this->height()); |
| 289 | bool willBeMipped = GrSamplerState::Filter::kMipMap == sampler.filter() && mipCount && |
Robert Phillips | 9338c60 | 2019-02-19 12:52:29 -0500 | [diff] [blame] | 290 | this->context()->priv().caps()->mipMapSupport(); |
Greg Daniel | 8e9b4c4 | 2018-07-20 10:30:48 -0400 | [diff] [blame] | 291 | |
Brian Osman | 6064e1c | 2018-10-19 14:27:54 -0400 | [diff] [blame] | 292 | auto result = this->onRefTextureProxyForParams(sampler, willBeMipped, nullptr); |
Greg Daniel | 5f4b09d | 2018-06-12 16:39:59 -0400 | [diff] [blame] | 293 | |
Greg Daniel | 022b1e0 | 2018-07-20 14:54:00 -0400 | [diff] [blame] | 294 | // Check to make sure that if we say the texture willBeMipped that the returned texture has mip |
| 295 | // maps, unless the config is not copyable. |
| 296 | SkASSERT(!result || !willBeMipped || result->mipMapped() == GrMipMapped::kYes || |
Greg Daniel | 6980c4e | 2019-07-30 16:18:18 -0400 | [diff] [blame] | 297 | !this->context()->priv().caps()->isFormatCopyable(result->backendFormat())); |
Greg Daniel | 022b1e0 | 2018-07-20 14:54:00 -0400 | [diff] [blame] | 298 | |
Greg Daniel | 5f4b09d | 2018-06-12 16:39:59 -0400 | [diff] [blame] | 299 | // Check that no scaling occured and we returned a proxy of the same size as the producer. |
| 300 | SkASSERT(!result || (result->width() == this->width() && result->height() == this->height())); |
| 301 | return result; |
| 302 | } |