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 | |
| 8 | #ifndef GrTextureAdjuster_DEFINED |
| 9 | #define GrTextureAdjuster_DEFINED |
| 10 | |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 11 | #include "src/core/SkTLazy.h" |
| 12 | #include "src/gpu/GrTextureProducer.h" |
Greg Daniel | f91aeb2 | 2019-06-18 09:58:02 -0400 | [diff] [blame^] | 13 | #include "src/gpu/GrTextureProxy.h" |
Brian Osman | e8e5458 | 2016-11-28 10:06:27 -0500 | [diff] [blame] | 14 | |
Robert Phillips | 9338c60 | 2019-02-19 12:52:29 -0500 | [diff] [blame] | 15 | class GrRecordingContext; |
| 16 | |
Brian Osman | e8e5458 | 2016-11-28 10:06:27 -0500 | [diff] [blame] | 17 | /** |
| 18 | * Base class for sources that start out as textures. Optionally allows for a content area subrect. |
| 19 | * The intent is not to use content area for subrect rendering. Rather, the pixels outside the |
| 20 | * content area have undefined values and shouldn't be read *regardless* of filtering mode or |
| 21 | * the SkCanvas::SrcRectConstraint used for subrect draws. |
| 22 | */ |
| 23 | class GrTextureAdjuster : public GrTextureProducer { |
| 24 | public: |
Brian Salomon | aff329b | 2017-08-11 09:40:37 -0400 | [diff] [blame] | 25 | std::unique_ptr<GrFragmentProcessor> createFragmentProcessor( |
| 26 | const SkMatrix& textureMatrix, |
| 27 | const SkRect& constraintRect, |
| 28 | FilterConstraint, |
| 29 | bool coordsLimitedToConstraintRect, |
Brian Osman | 05c8f46 | 2018-10-22 17:13:36 -0400 | [diff] [blame] | 30 | const GrSamplerState::Filter* filterOrNullForBicubic) override; |
Brian Osman | e8e5458 | 2016-11-28 10:06:27 -0500 | [diff] [blame] | 31 | |
| 32 | // We do not ref the texture nor the colorspace, so the caller must keep them in scope while |
| 33 | // this Adjuster is alive. |
Michael Ludwig | ddeed37 | 2019-02-20 16:50:10 -0500 | [diff] [blame] | 34 | GrTextureAdjuster(GrRecordingContext*, sk_sp<GrTextureProxy>, SkAlphaType, |
| 35 | uint32_t uniqueID, SkColorSpace*, bool useDecal = false); |
Brian Osman | e8e5458 | 2016-11-28 10:06:27 -0500 | [diff] [blame] | 36 | |
| 37 | protected: |
| 38 | SkAlphaType alphaType() const override { return fAlphaType; } |
Brian Osman | 6064e1c | 2018-10-19 14:27:54 -0400 | [diff] [blame] | 39 | SkColorSpace* colorSpace() const override { return fColorSpace; } |
Brian Osman | b3f3830 | 2018-09-07 15:24:44 -0400 | [diff] [blame] | 40 | void makeCopyKey(const CopyParams& params, GrUniqueKey* copyKey) override; |
Brian Salomon | 238069b | 2018-07-11 15:58:57 -0400 | [diff] [blame] | 41 | void didCacheCopy(const GrUniqueKey& copyKey, uint32_t contextUniqueID) override; |
Brian Osman | e8e5458 | 2016-11-28 10:06:27 -0500 | [diff] [blame] | 42 | |
Robert Phillips | 3798c86 | 2017-03-27 11:08:16 -0400 | [diff] [blame] | 43 | GrTextureProxy* originalProxy() const { return fOriginal.get(); } |
| 44 | sk_sp<GrTextureProxy> originalProxyRef() const { return fOriginal; } |
Brian Osman | e8e5458 | 2016-11-28 10:06:27 -0500 | [diff] [blame] | 45 | |
Brian Osman | e8e5458 | 2016-11-28 10:06:27 -0500 | [diff] [blame] | 46 | private: |
Brian Salomon | 2a943df | 2018-05-04 13:43:19 -0400 | [diff] [blame] | 47 | sk_sp<GrTextureProxy> onRefTextureProxyForParams(const GrSamplerState&, |
Greg Daniel | 8e9b4c4 | 2018-07-20 10:30:48 -0400 | [diff] [blame] | 48 | bool willBeMipped, |
Brian Salomon | 2a943df | 2018-05-04 13:43:19 -0400 | [diff] [blame] | 49 | SkScalar scaleAdjust[2]) override; |
| 50 | |
| 51 | sk_sp<GrTextureProxy> refTextureProxyCopy(const CopyParams& copyParams, bool willBeMipped); |
| 52 | |
Robert Phillips | 3798c86 | 2017-03-27 11:08:16 -0400 | [diff] [blame] | 53 | sk_sp<GrTextureProxy> fOriginal; |
| 54 | SkAlphaType fAlphaType; |
| 55 | SkColorSpace* fColorSpace; |
| 56 | uint32_t fUniqueID; |
Brian Osman | e8e5458 | 2016-11-28 10:06:27 -0500 | [diff] [blame] | 57 | |
Brian Osman | e8e5458 | 2016-11-28 10:06:27 -0500 | [diff] [blame] | 58 | typedef GrTextureProducer INHERITED; |
| 59 | }; |
| 60 | |
| 61 | #endif |