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 | |
| 11 | #include "GrTextureProducer.h" |
Hal Canary | e80e618 | 2017-04-05 12:55:32 -0400 | [diff] [blame] | 12 | #include "GrTextureProxy.h" |
Brian Osman | e8e5458 | 2016-11-28 10:06:27 -0500 | [diff] [blame] | 13 | #include "SkTLazy.h" |
| 14 | |
| 15 | /** |
| 16 | * Base class for sources that start out as textures. Optionally allows for a content area subrect. |
| 17 | * The intent is not to use content area for subrect rendering. Rather, the pixels outside the |
| 18 | * content area have undefined values and shouldn't be read *regardless* of filtering mode or |
| 19 | * the SkCanvas::SrcRectConstraint used for subrect draws. |
| 20 | */ |
| 21 | class GrTextureAdjuster : public GrTextureProducer { |
| 22 | public: |
Greg Daniel | 4faa040 | 2017-09-29 15:21:28 -0400 | [diff] [blame] | 23 | /** Makes the subset of the texture safe to use with the given texture parameters. If the copy's |
| 24 | size does not match subset's dimensions then the contents are scaled to fit the copy.*/ |
| 25 | sk_sp<GrTextureProxy> refTextureProxySafeForParams(const GrSamplerState&, |
Robert Phillips | 3798c86 | 2017-03-27 11:08:16 -0400 | [diff] [blame] | 26 | SkScalar scaleAdjust[2]); |
Brian Osman | e8e5458 | 2016-11-28 10:06:27 -0500 | [diff] [blame] | 27 | |
Brian Salomon | aff329b | 2017-08-11 09:40:37 -0400 | [diff] [blame] | 28 | std::unique_ptr<GrFragmentProcessor> createFragmentProcessor( |
| 29 | const SkMatrix& textureMatrix, |
| 30 | const SkRect& constraintRect, |
| 31 | FilterConstraint, |
| 32 | bool coordsLimitedToConstraintRect, |
Brian Salomon | 2bbdcc4 | 2017-09-07 12:36:34 -0400 | [diff] [blame] | 33 | const GrSamplerState::Filter* filterOrNullForBicubic, |
Brian Salomon | aff329b | 2017-08-11 09:40:37 -0400 | [diff] [blame] | 34 | SkColorSpace* dstColorSpace) override; |
Brian Osman | e8e5458 | 2016-11-28 10:06:27 -0500 | [diff] [blame] | 35 | |
| 36 | // We do not ref the texture nor the colorspace, so the caller must keep them in scope while |
| 37 | // this Adjuster is alive. |
Greg Daniel | c77085d | 2017-11-01 16:38:48 -0400 | [diff] [blame] | 38 | GrTextureAdjuster(GrContext*, sk_sp<GrTextureProxy>, SkAlphaType, uint32_t uniqueID, |
| 39 | SkColorSpace*); |
Brian Osman | e8e5458 | 2016-11-28 10:06:27 -0500 | [diff] [blame] | 40 | |
| 41 | protected: |
| 42 | SkAlphaType alphaType() const override { return fAlphaType; } |
| 43 | void makeCopyKey(const CopyParams& params, GrUniqueKey* copyKey, |
Brian Osman | 61624f0 | 2016-12-09 14:51:59 -0500 | [diff] [blame] | 44 | SkColorSpace* dstColorSpace) override; |
Brian Osman | e8e5458 | 2016-11-28 10:06:27 -0500 | [diff] [blame] | 45 | void didCacheCopy(const GrUniqueKey& copyKey) override; |
| 46 | |
Robert Phillips | 3798c86 | 2017-03-27 11:08:16 -0400 | [diff] [blame] | 47 | GrTextureProxy* originalProxy() const { return fOriginal.get(); } |
| 48 | sk_sp<GrTextureProxy> originalProxyRef() const { return fOriginal; } |
Brian Osman | e8e5458 | 2016-11-28 10:06:27 -0500 | [diff] [blame] | 49 | |
Brian Osman | e8e5458 | 2016-11-28 10:06:27 -0500 | [diff] [blame] | 50 | private: |
Robert Phillips | 3798c86 | 2017-03-27 11:08:16 -0400 | [diff] [blame] | 51 | GrContext* fContext; |
| 52 | sk_sp<GrTextureProxy> fOriginal; |
| 53 | SkAlphaType fAlphaType; |
| 54 | SkColorSpace* fColorSpace; |
| 55 | uint32_t fUniqueID; |
Brian Osman | e8e5458 | 2016-11-28 10:06:27 -0500 | [diff] [blame] | 56 | |
Greg Daniel | e1da1d9 | 2017-10-06 15:59:27 -0400 | [diff] [blame] | 57 | sk_sp<GrTextureProxy> refTextureProxyCopy(const CopyParams ©Params, bool willBeMipped); |
Brian Osman | e8e5458 | 2016-11-28 10:06:27 -0500 | [diff] [blame] | 58 | |
| 59 | typedef GrTextureProducer INHERITED; |
| 60 | }; |
| 61 | |
| 62 | #endif |