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