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