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