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 | |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 8 | #include "src/gpu/GrTextureMaker.h" |
Brian Osman | e8e5458 | 2016-11-28 10:06:27 -0500 | [diff] [blame] | 9 | |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 10 | #include "include/private/GrRecordingContext.h" |
| 11 | #include "src/gpu/GrColorSpaceXform.h" |
| 12 | #include "src/gpu/GrGpu.h" |
| 13 | #include "src/gpu/GrProxyProvider.h" |
| 14 | #include "src/gpu/GrRecordingContextPriv.h" |
Brian Salomon | adc9bbb | 2020-02-20 20:10:31 -0500 | [diff] [blame] | 15 | #include "src/gpu/SkGr.h" |
Brian Osman | e8e5458 | 2016-11-28 10:06:27 -0500 | [diff] [blame] | 16 | |
Greg Daniel | cc104db | 2020-02-03 14:17:08 -0500 | [diff] [blame] | 17 | GrSurfaceProxyView GrTextureMaker::onRefTextureProxyViewForParams(GrSamplerState params, |
Brian Salomon | c8d092a | 2020-02-24 10:14:21 -0500 | [diff] [blame] | 18 | bool willBeMipped) { |
Robert Phillips | 9338c60 | 2019-02-19 12:52:29 -0500 | [diff] [blame] | 19 | if (this->width() > this->context()->priv().caps()->maxTextureSize() || |
| 20 | this->height() > this->context()->priv().caps()->maxTextureSize()) { |
Greg Daniel | cc104db | 2020-02-03 14:17:08 -0500 | [diff] [blame] | 21 | return {}; |
Brian Osman | 875f785 | 2018-04-12 13:29:08 -0400 | [diff] [blame] | 22 | } |
| 23 | |
Brian Salomon | 6066b75 | 2020-02-26 15:34:27 -0500 | [diff] [blame] | 24 | GrSurfaceProxyView original = this->refOriginalTextureProxyView(willBeMipped); |
Brian Salomon | c8d092a | 2020-02-24 10:14:21 -0500 | [diff] [blame] | 25 | if (!original) { |
Brian Salomon | 6066b75 | 2020-02-26 15:34:27 -0500 | [diff] [blame] | 26 | return {}; |
Brian Salomon | c8d092a | 2020-02-24 10:14:21 -0500 | [diff] [blame] | 27 | } |
Brian Salomon | 6066b75 | 2020-02-26 15:34:27 -0500 | [diff] [blame] | 28 | SkASSERT(original.asTextureProxy()); |
Brian Salomon | c8d092a | 2020-02-24 10:14:21 -0500 | [diff] [blame] | 29 | |
| 30 | GrTextureProxy* texProxy = original.asTextureProxy(); |
| 31 | if (!GrGpu::IsACopyNeededForMips(this->context()->priv().caps(), texProxy, params.filter())) { |
| 32 | return original; |
Brian Osman | e8e5458 | 2016-11-28 10:06:27 -0500 | [diff] [blame] | 33 | } |
Stan Iliev | ba81af2 | 2017-06-08 15:16:53 -0400 | [diff] [blame] | 34 | |
Robert Phillips | 9338c60 | 2019-02-19 12:52:29 -0500 | [diff] [blame] | 35 | GrProxyProvider* proxyProvider = this->context()->priv().proxyProvider(); |
Robert Phillips | 1afd4cd | 2018-01-08 13:40:32 -0500 | [diff] [blame] | 36 | |
Greg Daniel | cc104db | 2020-02-03 14:17:08 -0500 | [diff] [blame] | 37 | GrSurfaceOrigin origOrigin = original.proxy() ? original.origin() : kTopLeft_GrSurfaceOrigin; |
Brian Salomon | c8d092a | 2020-02-24 10:14:21 -0500 | [diff] [blame] | 38 | GrUniqueKey mipMappedKey; |
| 39 | this->makeMipMappedKey(&mipMappedKey); |
| 40 | if (mipMappedKey.isValid()) { |
| 41 | auto cachedProxy = |
| 42 | proxyProvider->findOrCreateProxyByUniqueKey(mipMappedKey, this->colorType()); |
Greg Daniel | cc104db | 2020-02-03 14:17:08 -0500 | [diff] [blame] | 43 | if (cachedProxy) { |
Brian Salomon | c8d092a | 2020-02-24 10:14:21 -0500 | [diff] [blame] | 44 | SkASSERT(cachedProxy->mipMapped() == GrMipMapped::kYes); |
Brian Salomon | adc9bbb | 2020-02-20 20:10:31 -0500 | [diff] [blame] | 45 | return GrSurfaceProxyView(std::move(cachedProxy), origOrigin, original.swizzle()); |
Brian Osman | e8e5458 | 2016-11-28 10:06:27 -0500 | [diff] [blame] | 46 | } |
| 47 | } |
| 48 | |
Brian Salomon | 6066b75 | 2020-02-26 15:34:27 -0500 | [diff] [blame] | 49 | GrSurfaceProxyView result = GrCopyBaseMipMapToTextureProxy( |
| 50 | this->context(), original.proxy(), original.origin(), this->colorType()); |
Brian Salomon | c8d092a | 2020-02-24 10:14:21 -0500 | [diff] [blame] | 51 | if (!result) { |
Greg Daniel | 8f5bbda | 2018-06-08 17:22:23 -0400 | [diff] [blame] | 52 | // If we were unable to make a copy and we only needed a copy for mips, then we will return |
| 53 | // the source texture here and require that the GPU backend is able to fall back to using |
| 54 | // bilerp if mips are required. |
Brian Salomon | 6066b75 | 2020-02-26 15:34:27 -0500 | [diff] [blame] | 55 | return original; |
Brian Osman | e8e5458 | 2016-11-28 10:06:27 -0500 | [diff] [blame] | 56 | } |
| 57 | |
Brian Salomon | dffe2ab | 2020-02-26 16:52:17 -0500 | [diff] [blame^] | 58 | // We believe all Makers already have tried to add MIP maps in refOriginalTextureProxyView() |
| 59 | // if willBeMipped was true and therefore we should never get here. |
| 60 | SkASSERT(false); |
| 61 | |
Brian Salomon | c8d092a | 2020-02-24 10:14:21 -0500 | [diff] [blame] | 62 | if (mipMappedKey.isValid()) { |
Greg Daniel | cc104db | 2020-02-03 14:17:08 -0500 | [diff] [blame] | 63 | SkASSERT(result.origin() == origOrigin); |
Brian Salomon | c8d092a | 2020-02-24 10:14:21 -0500 | [diff] [blame] | 64 | proxyProvider->assignUniqueKeyToProxy(mipMappedKey, result.asTextureProxy()); |
| 65 | this->didCacheMipMappedCopy(mipMappedKey, proxyProvider->contextID()); |
Brian Osman | e8e5458 | 2016-11-28 10:06:27 -0500 | [diff] [blame] | 66 | } |
| 67 | return result; |
| 68 | } |
| 69 | |
Brian Salomon | aff329b | 2017-08-11 09:40:37 -0400 | [diff] [blame] | 70 | std::unique_ptr<GrFragmentProcessor> GrTextureMaker::createFragmentProcessor( |
| 71 | const SkMatrix& textureMatrix, |
| 72 | const SkRect& constraintRect, |
| 73 | FilterConstraint filterConstraint, |
| 74 | bool coordsLimitedToConstraintRect, |
Brian Osman | 05c8f46 | 2018-10-22 17:13:36 -0400 | [diff] [blame] | 75 | const GrSamplerState::Filter* filterOrNullForBicubic) { |
Brian Salomon | 2bbdcc4 | 2017-09-07 12:36:34 -0400 | [diff] [blame] | 76 | const GrSamplerState::Filter* fmForDetermineDomain = filterOrNullForBicubic; |
| 77 | if (filterOrNullForBicubic && GrSamplerState::Filter::kMipMap == *filterOrNullForBicubic && |
Brian Osman | e8e5458 | 2016-11-28 10:06:27 -0500 | [diff] [blame] | 78 | kYes_FilterConstraint == filterConstraint) { |
Michael Ludwig | ddeed37 | 2019-02-20 16:50:10 -0500 | [diff] [blame] | 79 | // TODO: Here we should force a copy restricted to the constraintRect since MIP maps will |
Brian Osman | e8e5458 | 2016-11-28 10:06:27 -0500 | [diff] [blame] | 80 | // read outside the constraint rect. However, as in the adjuster case, we aren't currently |
| 81 | // doing that. |
| 82 | // We instead we compute the domain as though were bilerping which is only correct if we |
| 83 | // only sample level 0. |
Brian Salomon | 2bbdcc4 | 2017-09-07 12:36:34 -0400 | [diff] [blame] | 84 | static const GrSamplerState::Filter kBilerp = GrSamplerState::Filter::kBilerp; |
Brian Osman | e8e5458 | 2016-11-28 10:06:27 -0500 | [diff] [blame] | 85 | fmForDetermineDomain = &kBilerp; |
| 86 | } |
| 87 | |
Brian Salomon | c8d092a | 2020-02-24 10:14:21 -0500 | [diff] [blame] | 88 | GrSurfaceProxyView view = this->viewForParams(filterOrNullForBicubic); |
| 89 | if (!view) { |
Brian Osman | e8e5458 | 2016-11-28 10:06:27 -0500 | [diff] [blame] | 90 | return nullptr; |
| 91 | } |
Michael Ludwig | ddeed37 | 2019-02-20 16:50:10 -0500 | [diff] [blame] | 92 | |
Brian Osman | e8e5458 | 2016-11-28 10:06:27 -0500 | [diff] [blame] | 93 | SkRect domain; |
| 94 | DomainMode domainMode = |
Brian Salomon | 4df0092 | 2017-09-07 16:34:11 +0000 | [diff] [blame] | 95 | DetermineDomainMode(constraintRect, filterConstraint, coordsLimitedToConstraintRect, |
Greg Daniel | cc104db | 2020-02-03 14:17:08 -0500 | [diff] [blame] | 96 | view.proxy(), fmForDetermineDomain, &domain); |
Brian Osman | e8e5458 | 2016-11-28 10:06:27 -0500 | [diff] [blame] | 97 | SkASSERT(kTightCopy_DomainMode != domainMode); |
Michael Ludwig | ddeed37 | 2019-02-20 16:50:10 -0500 | [diff] [blame] | 98 | return this->createFragmentProcessorForDomainAndFilter( |
Brian Salomon | c8d092a | 2020-02-24 10:14:21 -0500 | [diff] [blame] | 99 | std::move(view), textureMatrix, domainMode, domain, filterOrNullForBicubic); |
Brian Osman | e8e5458 | 2016-11-28 10:06:27 -0500 | [diff] [blame] | 100 | } |