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 "GrTextureProxy.h" 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.*/ 27 sk_sp<GrTextureProxy> refTextureProxySafeForParams(const GrSamplerParams&, SkIPoint* outOffset, 28 SkScalar scaleAdjust[2]); 29 30 sk_sp<GrFragmentProcessor> createFragmentProcessor( 31 const SkMatrix& textureMatrix, 32 const SkRect& constraintRect, 33 FilterConstraint, 34 bool coordsLimitedToConstraintRect, 35 const GrSamplerParams::FilterMode* filterOrNullForBicubic, 36 SkColorSpace* dstColorSpace) override; 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. 40 GrTextureAdjuster(GrContext*, sk_sp<GrTextureProxy>, SkAlphaType, const SkIRect& area, 41 uint32_t uniqueID, SkColorSpace*); 42 43 protected: alphaType()44 SkAlphaType alphaType() const override { return fAlphaType; } 45 void makeCopyKey(const CopyParams& params, GrUniqueKey* copyKey, 46 SkColorSpace* dstColorSpace) override; 47 void didCacheCopy(const GrUniqueKey& copyKey) override; 48 originalProxy()49 GrTextureProxy* originalProxy() const { return fOriginal.get(); } originalProxyRef()50 sk_sp<GrTextureProxy> originalProxyRef() const { return fOriginal; } 51 52 /** Returns the content area or null for the whole original texture */ contentAreaOrNull()53 const SkIRect* contentAreaOrNull() { return fContentArea.getMaybeNull(); } 54 55 private: 56 SkTLazy<SkIRect> fContentArea; 57 GrContext* fContext; 58 sk_sp<GrTextureProxy> fOriginal; 59 SkAlphaType fAlphaType; 60 SkColorSpace* fColorSpace; 61 uint32_t fUniqueID; 62 63 sk_sp<GrTextureProxy> refTextureProxyCopy(const CopyParams ©Params); 64 65 typedef GrTextureProducer INHERITED; 66 }; 67 68 #endif 69