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