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 | 67c18d6 | 2017-01-20 12:44:06 -0500 | [diff] [blame] | 26 | GrTexture* refTextureSafeForParams(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. |
| 39 | GrTextureAdjuster(GrTexture*, SkAlphaType, const SkIRect& area, uint32_t uniqueID, |
| 40 | SkColorSpace*); |
| 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 | |
| 48 | GrTexture* originalTexture() const { return fOriginal; } |
| 49 | |
| 50 | /** Returns the content area or null for the whole original texture */ |
| 51 | const SkIRect* contentAreaOrNull() { return fContentArea.getMaybeNull(); } |
| 52 | |
| 53 | private: |
| 54 | SkTLazy<SkIRect> fContentArea; |
| 55 | GrTexture* fOriginal; |
| 56 | SkAlphaType fAlphaType; |
| 57 | SkColorSpace* fColorSpace; |
| 58 | uint32_t fUniqueID; |
| 59 | |
| 60 | GrTexture* refCopy(const CopyParams ©Params); |
| 61 | |
| 62 | typedef GrTextureProducer INHERITED; |
| 63 | }; |
| 64 | |
| 65 | #endif |