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