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 | |
Robert Phillips | b7bfbc2 | 2020-07-01 12:55:01 -0400 | [diff] [blame] | 10 | #include "include/gpu/GrRecordingContext.h" |
Mike Reed | 13711eb | 2020-07-14 17:16:32 -0400 | [diff] [blame] | 11 | #include "src/core/SkMipmap.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 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" |
Brian Salomon | b8f098d | 2020-01-07 11:15:44 -0500 | [diff] [blame] | 21 | #include "src/gpu/effects/GrTextureEffect.h" |
Brian Osman | e8e5458 | 2016-11-28 10:06:27 -0500 | [diff] [blame] | 22 | |
Brian Salomon | 0ea3307 | 2020-07-14 10:43:42 -0400 | [diff] [blame] | 23 | std::unique_ptr<GrFragmentProcessor> GrTextureProducer::createFragmentProcessorForView( |
Greg Daniel | cc104db | 2020-02-03 14:17:08 -0500 | [diff] [blame] | 24 | GrSurfaceProxyView view, |
Brian Salomon | aff329b | 2017-08-11 09:40:37 -0400 | [diff] [blame] | 25 | const SkMatrix& textureMatrix, |
Brian Salomon | 0ea3307 | 2020-07-14 10:43:42 -0400 | [diff] [blame] | 26 | const SkRect* subset, |
| 27 | const SkRect* domain, |
| 28 | GrSamplerState samplerState) { |
| 29 | if (!view) { |
| 30 | return nullptr; |
| 31 | } |
Brian Salomon | f990b6a | 2020-07-13 10:44:22 -0400 | [diff] [blame] | 32 | SkRect tempSubset; |
| 33 | |
Brian Salomon | 0ea3307 | 2020-07-14 10:43:42 -0400 | [diff] [blame] | 34 | if (!subset && !view.proxy()->isFullyLazy() && !view.proxy()->isFunctionallyExact()) { |
Brian Salomon | f990b6a | 2020-07-13 10:44:22 -0400 | [diff] [blame] | 35 | tempSubset = view.proxy()->getBoundsRect(); |
| 36 | subset = &tempSubset; |
| 37 | } |
| 38 | |
Brian Salomon | ca6b2f4 | 2020-01-24 11:31:21 -0500 | [diff] [blame] | 39 | const auto& caps = *fContext->priv().caps(); |
Brian Salomon | 0ea3307 | 2020-07-14 10:43:42 -0400 | [diff] [blame] | 40 | if (subset) { |
| 41 | if (domain) { |
| 42 | return GrTextureEffect::MakeSubset(std::move(view), this->alphaType(), textureMatrix, |
| 43 | samplerState, *subset, *domain, caps); |
Brian Salomon | f990b6a | 2020-07-13 10:44:22 -0400 | [diff] [blame] | 44 | } else { |
Brian Salomon | 0ea3307 | 2020-07-14 10:43:42 -0400 | [diff] [blame] | 45 | return GrTextureEffect::MakeSubset(std::move(view), this->alphaType(), textureMatrix, |
| 46 | samplerState, *subset, caps); |
Robert Phillips | b66b42f | 2017-03-14 08:53:02 -0400 | [diff] [blame] | 47 | } |
| 48 | } else { |
Brian Salomon | 0ea3307 | 2020-07-14 10:43:42 -0400 | [diff] [blame] | 49 | return GrTextureEffect::Make(std::move(view), this->alphaType(), textureMatrix, |
| 50 | samplerState, caps); |
| 51 | } |
| 52 | } |
| 53 | |
| 54 | std::unique_ptr<GrFragmentProcessor> GrTextureProducer::createBicubicFragmentProcessorForView( |
| 55 | GrSurfaceProxyView view, |
| 56 | const SkMatrix& textureMatrix, |
| 57 | const SkRect* subset, |
| 58 | const SkRect* domain, |
| 59 | GrSamplerState::WrapMode wrapX, |
Mike Reed | 3867c70 | 2020-09-01 13:28:10 -0400 | [diff] [blame] | 60 | GrSamplerState::WrapMode wrapY, |
| 61 | SkImage::CubicResampler kernel) { |
Brian Salomon | 0ea3307 | 2020-07-14 10:43:42 -0400 | [diff] [blame] | 62 | if (!view) { |
| 63 | return nullptr; |
| 64 | } |
| 65 | SkRect tempSubset; |
| 66 | |
| 67 | if (!subset && !view.proxy()->isFullyLazy() && !view.proxy()->isFunctionallyExact()) { |
| 68 | tempSubset = view.proxy()->getBoundsRect(); |
| 69 | subset = &tempSubset; |
| 70 | } |
| 71 | |
| 72 | const auto& caps = *fContext->priv().caps(); |
| 73 | static constexpr auto kDir = GrBicubicEffect::Direction::kXY; |
Brian Salomon | 0ea3307 | 2020-07-14 10:43:42 -0400 | [diff] [blame] | 74 | if (subset) { |
| 75 | if (domain) { |
| 76 | return GrBicubicEffect::MakeSubset(std::move(view), this->alphaType(), textureMatrix, |
Mike Reed | 3867c70 | 2020-09-01 13:28:10 -0400 | [diff] [blame] | 77 | wrapX, wrapY, *subset, *domain, kernel, kDir, caps); |
Robert Phillips | b66b42f | 2017-03-14 08:53:02 -0400 | [diff] [blame] | 78 | } else { |
Brian Salomon | 0ea3307 | 2020-07-14 10:43:42 -0400 | [diff] [blame] | 79 | return GrBicubicEffect::MakeSubset(std::move(view), this->alphaType(), textureMatrix, |
Mike Reed | 3867c70 | 2020-09-01 13:28:10 -0400 | [diff] [blame] | 80 | wrapX, wrapY, *subset, kernel, kDir, caps); |
Robert Phillips | b66b42f | 2017-03-14 08:53:02 -0400 | [diff] [blame] | 81 | } |
Brian Salomon | 0ea3307 | 2020-07-14 10:43:42 -0400 | [diff] [blame] | 82 | } else { |
| 83 | return GrBicubicEffect::Make(std::move(view), this->alphaType(), textureMatrix, wrapX, |
Mike Reed | 3867c70 | 2020-09-01 13:28:10 -0400 | [diff] [blame] | 84 | wrapY, kernel, kDir, caps); |
Robert Phillips | b66b42f | 2017-03-14 08:53:02 -0400 | [diff] [blame] | 85 | } |
| 86 | } |
Brian Salomon | 2a943df | 2018-05-04 13:43:19 -0400 | [diff] [blame] | 87 | |
Brian Salomon | 7e67dca | 2020-07-21 09:27:25 -0400 | [diff] [blame] | 88 | GrSurfaceProxyView GrTextureProducer::view(GrMipmapped mipMapped) { |
Brian Salomon | ecbb0fb | 2020-02-28 18:07:32 -0500 | [diff] [blame] | 89 | const GrCaps* caps = this->context()->priv().caps(); |
| 90 | // Sanitize the MIP map request. |
Brian Salomon | 7e67dca | 2020-07-21 09:27:25 -0400 | [diff] [blame] | 91 | if (mipMapped == GrMipmapped::kYes) { |
Brian Salomon | 69100f0 | 2020-07-21 10:49:25 -0400 | [diff] [blame] | 92 | if ((this->width() == 1 && this->height() == 1) || !caps->mipmapSupport()) { |
Brian Salomon | 7e67dca | 2020-07-21 09:27:25 -0400 | [diff] [blame] | 93 | mipMapped = GrMipmapped::kNo; |
Michael Ludwig | ddeed37 | 2019-02-20 16:50:10 -0500 | [diff] [blame] | 94 | } |
| 95 | } |
Brian Salomon | ecbb0fb | 2020-02-28 18:07:32 -0500 | [diff] [blame] | 96 | auto result = this->onView(mipMapped); |
| 97 | // Check to make sure if we requested MIPs that the returned texture has MIP maps or the format |
| 98 | // is not copyable. |
Brian Salomon | 7e67dca | 2020-07-21 09:27:25 -0400 | [diff] [blame] | 99 | SkASSERT(!result || mipMapped == GrMipmapped::kNo || |
Brian Salomon | 8c82a87 | 2020-07-21 12:09:58 -0400 | [diff] [blame] | 100 | result.asTextureProxy()->mipmapped() == GrMipmapped::kYes || |
Greg Daniel | cc104db | 2020-02-03 14:17:08 -0500 | [diff] [blame] | 101 | !caps->isFormatCopyable(result.proxy()->backendFormat())); |
Brian Salomon | 2a943df | 2018-05-04 13:43:19 -0400 | [diff] [blame] | 102 | return result; |
| 103 | } |