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 | |
Robert Phillips | b7bfbc2 | 2020-07-01 12:55:01 -0400 | [diff] [blame^] | 10 | #include "include/gpu/GrRecordingContext.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 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 | |
Brian Salomon | ecbb0fb | 2020-02-28 18:07:32 -0500 | [diff] [blame] | 17 | GrSurfaceProxyView GrTextureMaker::onView(GrMipMapped mipMapped) { |
Robert Phillips | 9338c60 | 2019-02-19 12:52:29 -0500 | [diff] [blame] | 18 | if (this->width() > this->context()->priv().caps()->maxTextureSize() || |
| 19 | this->height() > this->context()->priv().caps()->maxTextureSize()) { |
Greg Daniel | cc104db | 2020-02-03 14:17:08 -0500 | [diff] [blame] | 20 | return {}; |
Brian Osman | 875f785 | 2018-04-12 13:29:08 -0400 | [diff] [blame] | 21 | } |
Brian Salomon | ecbb0fb | 2020-02-28 18:07:32 -0500 | [diff] [blame] | 22 | return this->refOriginalTextureProxyView(mipMapped); |
Brian Osman | e8e5458 | 2016-11-28 10:06:27 -0500 | [diff] [blame] | 23 | } |
| 24 | |
Brian Salomon | aff329b | 2017-08-11 09:40:37 -0400 | [diff] [blame] | 25 | std::unique_ptr<GrFragmentProcessor> GrTextureMaker::createFragmentProcessor( |
| 26 | const SkMatrix& textureMatrix, |
| 27 | const SkRect& constraintRect, |
| 28 | FilterConstraint filterConstraint, |
| 29 | bool coordsLimitedToConstraintRect, |
Brian Salomon | 777e146 | 2020-02-28 21:10:31 -0500 | [diff] [blame] | 30 | GrSamplerState::WrapMode wrapX, |
| 31 | GrSamplerState::WrapMode wrapY, |
Brian Osman | 05c8f46 | 2018-10-22 17:13:36 -0400 | [diff] [blame] | 32 | const GrSamplerState::Filter* filterOrNullForBicubic) { |
Brian Salomon | 2bbdcc4 | 2017-09-07 12:36:34 -0400 | [diff] [blame] | 33 | const GrSamplerState::Filter* fmForDetermineDomain = filterOrNullForBicubic; |
| 34 | if (filterOrNullForBicubic && GrSamplerState::Filter::kMipMap == *filterOrNullForBicubic && |
Brian Osman | e8e5458 | 2016-11-28 10:06:27 -0500 | [diff] [blame] | 35 | kYes_FilterConstraint == filterConstraint) { |
Michael Ludwig | ddeed37 | 2019-02-20 16:50:10 -0500 | [diff] [blame] | 36 | // 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] | 37 | // read outside the constraint rect. However, as in the adjuster case, we aren't currently |
| 38 | // doing that. |
| 39 | // We instead we compute the domain as though were bilerping which is only correct if we |
| 40 | // only sample level 0. |
Brian Salomon | 2bbdcc4 | 2017-09-07 12:36:34 -0400 | [diff] [blame] | 41 | static const GrSamplerState::Filter kBilerp = GrSamplerState::Filter::kBilerp; |
Brian Osman | e8e5458 | 2016-11-28 10:06:27 -0500 | [diff] [blame] | 42 | fmForDetermineDomain = &kBilerp; |
| 43 | } |
| 44 | |
Brian Salomon | ecbb0fb | 2020-02-28 18:07:32 -0500 | [diff] [blame] | 45 | GrSurfaceProxyView view; |
| 46 | if (filterOrNullForBicubic) { |
| 47 | view = this->view(*filterOrNullForBicubic); |
| 48 | } else { |
| 49 | view = this->view(GrMipMapped::kNo); |
| 50 | } |
Brian Salomon | c8d092a | 2020-02-24 10:14:21 -0500 | [diff] [blame] | 51 | if (!view) { |
Brian Osman | e8e5458 | 2016-11-28 10:06:27 -0500 | [diff] [blame] | 52 | return nullptr; |
| 53 | } |
Michael Ludwig | ddeed37 | 2019-02-20 16:50:10 -0500 | [diff] [blame] | 54 | |
Brian Osman | e8e5458 | 2016-11-28 10:06:27 -0500 | [diff] [blame] | 55 | SkRect domain; |
| 56 | DomainMode domainMode = |
Brian Salomon | 4df0092 | 2017-09-07 16:34:11 +0000 | [diff] [blame] | 57 | DetermineDomainMode(constraintRect, filterConstraint, coordsLimitedToConstraintRect, |
Greg Daniel | cc104db | 2020-02-03 14:17:08 -0500 | [diff] [blame] | 58 | view.proxy(), fmForDetermineDomain, &domain); |
Brian Osman | e8e5458 | 2016-11-28 10:06:27 -0500 | [diff] [blame] | 59 | SkASSERT(kTightCopy_DomainMode != domainMode); |
Brian Salomon | 777e146 | 2020-02-28 21:10:31 -0500 | [diff] [blame] | 60 | return this->createFragmentProcessorForSubsetAndFilter(std::move(view), textureMatrix, |
| 61 | domainMode, domain, wrapX, wrapY, |
| 62 | filterOrNullForBicubic); |
Brian Osman | e8e5458 | 2016-11-28 10:06:27 -0500 | [diff] [blame] | 63 | } |