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