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