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