Brian Osman | 3b66ab6 | 2016-11-28 09:26:31 -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/GrImageTextureMaker.h" |
Brian Salomon | e7499c7 | 2019-06-24 12:12:36 -0400 | [diff] [blame] | 9 | |
| 10 | #include "src/gpu/GrColorSpaceXform.h" |
Brian Salomon | ca6b2f4 | 2020-01-24 11:31:21 -0500 | [diff] [blame] | 11 | #include "src/gpu/GrContextPriv.h" |
Greg Daniel | 82c6b10 | 2020-01-21 10:33:22 -0500 | [diff] [blame] | 12 | #include "src/gpu/GrRecordingContextPriv.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 13 | #include "src/gpu/SkGr.h" |
Brian Salomon | 5c4c61e | 2020-03-25 14:26:01 -0400 | [diff] [blame^] | 14 | #include "src/gpu/effects/GrBicubicEffect.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 15 | #include "src/gpu/effects/GrYUVtoRGBEffect.h" |
| 16 | #include "src/image/SkImage_GpuYUVA.h" |
| 17 | #include "src/image/SkImage_Lazy.h" |
Brian Osman | 3b66ab6 | 2016-11-28 09:26:31 -0500 | [diff] [blame] | 18 | |
Greg Daniel | 82c6b10 | 2020-01-21 10:33:22 -0500 | [diff] [blame] | 19 | static GrImageInfo get_image_info(GrRecordingContext* context, const SkImage* client) { |
| 20 | SkASSERT(client->isLazyGenerated()); |
| 21 | const SkImage_Lazy* lazyImage = static_cast<const SkImage_Lazy*>(client); |
| 22 | |
| 23 | GrColorType ct = lazyImage->colorTypeOfLockTextureProxy(context->priv().caps()); |
| 24 | |
| 25 | return {ct, client->alphaType(), client->refColorSpace(), client->dimensions()}; |
| 26 | } |
| 27 | |
Brian Salomon | bc074a6 | 2020-03-18 10:06:13 -0400 | [diff] [blame] | 28 | GrImageTextureMaker::GrImageTextureMaker(GrRecordingContext* context, |
| 29 | const SkImage* client, |
| 30 | GrImageTexGenPolicy texGenPolicy) |
Brian Salomon | 777e146 | 2020-02-28 21:10:31 -0500 | [diff] [blame] | 31 | : INHERITED(context, get_image_info(context, client)) |
Brian Osman | bd65955 | 2018-09-11 10:03:19 -0400 | [diff] [blame] | 32 | , fImage(static_cast<const SkImage_Lazy*>(client)) |
Brian Salomon | bc074a6 | 2020-03-18 10:06:13 -0400 | [diff] [blame] | 33 | , fTexGenPolicy(texGenPolicy) { |
Brian Osman | bd65955 | 2018-09-11 10:03:19 -0400 | [diff] [blame] | 34 | SkASSERT(client->isLazyGenerated()); |
Brian Osman | 3b66ab6 | 2016-11-28 09:26:31 -0500 | [diff] [blame] | 35 | } |
| 36 | |
Brian Salomon | ecbb0fb | 2020-02-28 18:07:32 -0500 | [diff] [blame] | 37 | GrSurfaceProxyView GrImageTextureMaker::refOriginalTextureProxyView(GrMipMapped mipMapped) { |
Brian Salomon | bc074a6 | 2020-03-18 10:06:13 -0400 | [diff] [blame] | 38 | return fImage->lockTextureProxyView(this->context(), fTexGenPolicy, mipMapped); |
Robert Phillips | 0c984a0 | 2017-03-16 07:51:56 -0400 | [diff] [blame] | 39 | } |
| 40 | |
Jim Van Verth | 30e0d7f | 2018-11-02 13:36:42 -0400 | [diff] [blame] | 41 | ///////////////////////////////////////////////////////////////////////////////////////////////// |
| 42 | |
Brian Salomon | 777e146 | 2020-02-28 21:10:31 -0500 | [diff] [blame] | 43 | GrYUVAImageTextureMaker::GrYUVAImageTextureMaker(GrContext* context, const SkImage* client) |
| 44 | : INHERITED(context, client->imageInfo()) |
Brian Salomon | e7499c7 | 2019-06-24 12:12:36 -0400 | [diff] [blame] | 45 | , fImage(static_cast<const SkImage_GpuYUVA*>(client)) { |
Jim Van Verth | 30e0d7f | 2018-11-02 13:36:42 -0400 | [diff] [blame] | 46 | SkASSERT(as_IB(client)->isYUVA()); |
Jim Van Verth | 30e0d7f | 2018-11-02 13:36:42 -0400 | [diff] [blame] | 47 | } |
| 48 | |
Brian Salomon | ecbb0fb | 2020-02-28 18:07:32 -0500 | [diff] [blame] | 49 | GrSurfaceProxyView GrYUVAImageTextureMaker::refOriginalTextureProxyView(GrMipMapped mipMapped) { |
| 50 | if (mipMapped == GrMipMapped::kYes) { |
Greg Daniel | 37c127f | 2020-02-05 10:37:27 -0500 | [diff] [blame] | 51 | return fImage->refMippedView(this->context()); |
Jim Van Verth | 803a502 | 2018-11-05 15:55:53 -0500 | [diff] [blame] | 52 | } else { |
Greg Daniel | 37c127f | 2020-02-05 10:37:27 -0500 | [diff] [blame] | 53 | if (const GrSurfaceProxyView* view = fImage->view(this->context())) { |
| 54 | return *view; |
| 55 | } else { |
| 56 | return {}; |
| 57 | } |
Jim Van Verth | 7da4676 | 2018-11-05 14:24:23 -0500 | [diff] [blame] | 58 | } |
Jim Van Verth | 30e0d7f | 2018-11-02 13:36:42 -0400 | [diff] [blame] | 59 | } |
| 60 | |
Jim Van Verth | 30e0d7f | 2018-11-02 13:36:42 -0400 | [diff] [blame] | 61 | std::unique_ptr<GrFragmentProcessor> GrYUVAImageTextureMaker::createFragmentProcessor( |
Brian Salomon | 777e146 | 2020-02-28 21:10:31 -0500 | [diff] [blame] | 62 | const SkMatrix& textureMatrix, |
| 63 | const SkRect& constraintRect, |
| 64 | FilterConstraint filterConstraint, |
| 65 | bool coordsLimitedToConstraintRect, |
| 66 | GrSamplerState::WrapMode wrapX, |
| 67 | GrSamplerState::WrapMode wrapY, |
| 68 | const GrSamplerState::Filter* filterOrNullForBicubic) { |
Brian Salomon | 5c4c61e | 2020-03-25 14:26:01 -0400 | [diff] [blame^] | 69 | // Check whether it's already been flattened. |
| 70 | if (fImage->fRGBView.proxy()) { |
Brian Salomon | 777e146 | 2020-02-28 21:10:31 -0500 | [diff] [blame] | 71 | return this->INHERITED::createFragmentProcessor( |
| 72 | textureMatrix, constraintRect, filterConstraint, coordsLimitedToConstraintRect, |
| 73 | wrapX, wrapY, filterOrNullForBicubic); |
Jim Van Verth | 30e0d7f | 2018-11-02 13:36:42 -0400 | [diff] [blame] | 74 | } |
| 75 | |
Brian Salomon | 5c4c61e | 2020-03-25 14:26:01 -0400 | [diff] [blame^] | 76 | GrSamplerState::Filter filter = |
| 77 | filterOrNullForBicubic ? *filterOrNullForBicubic : GrSamplerState::Filter::kNearest; |
| 78 | |
Jim Van Verth | f542cab | 2018-11-07 12:08:21 -0500 | [diff] [blame] | 79 | // Check to see if the client has given us pre-mipped textures or we can generate them |
Michael Ludwig | a6a8400 | 2019-04-12 15:03:02 -0400 | [diff] [blame] | 80 | // If not, fall back to bilerp. Also fall back to bilerp when a domain is requested |
Robert Phillips | 8defcc1 | 2019-03-05 15:58:59 -0500 | [diff] [blame] | 81 | if (GrSamplerState::Filter::kMipMap == filter && |
Michael Ludwig | a6a8400 | 2019-04-12 15:03:02 -0400 | [diff] [blame] | 82 | (filterConstraint == GrTextureProducer::kYes_FilterConstraint || |
| 83 | !fImage->setupMipmapsForPlanes(this->context()))) { |
Jim Van Verth | 30e0d7f | 2018-11-02 13:36:42 -0400 | [diff] [blame] | 84 | filter = GrSamplerState::Filter::kBilerp; |
| 85 | } |
| 86 | |
Michael Ludwig | a6a8400 | 2019-04-12 15:03:02 -0400 | [diff] [blame] | 87 | // Cannot rely on GrTextureProducer's domain infrastructure since we need to calculate domain's |
| 88 | // per plane, which may be different, so respect the filterConstraint without any additional |
| 89 | // analysis. |
| 90 | const SkRect* domain = nullptr; |
| 91 | if (filterConstraint == GrTextureProducer::kYes_FilterConstraint) { |
| 92 | domain = &constraintRect; |
| 93 | } |
| 94 | |
Brian Salomon | ca6b2f4 | 2020-01-24 11:31:21 -0500 | [diff] [blame] | 95 | const auto& caps = *fImage->context()->priv().caps(); |
Brian Salomon | 5c4c61e | 2020-03-25 14:26:01 -0400 | [diff] [blame^] | 96 | const SkMatrix& m = filterOrNullForBicubic ? textureMatrix : SkMatrix::I(); |
Greg Daniel | c767209 | 2020-02-06 14:32:54 -0500 | [diff] [blame] | 97 | auto fp = GrYUVtoRGBEffect::Make(fImage->fViews, fImage->fYUVAIndices, fImage->fYUVColorSpace, |
Brian Salomon | 5c4c61e | 2020-03-25 14:26:01 -0400 | [diff] [blame^] | 98 | filter, caps, m, domain); |
| 99 | if (!filterOrNullForBicubic) { |
| 100 | fp = GrBicubicEffect::Make(std::move(fp), fImage->alphaType(), textureMatrix, |
| 101 | GrBicubicEffect::Direction::kXY); |
| 102 | } |
Brian Salomon | 5ad6fd3 | 2019-03-21 15:30:08 -0400 | [diff] [blame] | 103 | if (fImage->fFromColorSpace) { |
| 104 | fp = GrColorSpaceXformEffect::Make(std::move(fp), fImage->fFromColorSpace.get(), |
| 105 | fImage->alphaType(), fImage->colorSpace()); |
Brian Osman | e956049 | 2019-02-05 17:00:03 -0500 | [diff] [blame] | 106 | } |
| 107 | return fp; |
Jim Van Verth | 30e0d7f | 2018-11-02 13:36:42 -0400 | [diff] [blame] | 108 | } |