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