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 "src/core/SkTLazy.h" 12 #include "src/gpu/GrTextureProducer.h" 13 #include "src/gpu/GrTextureProxy.h" 14 15 class GrRecordingContext; 16 17 /** 18 * Base class for sources that start out as textures. Optionally allows for a content area subrect. 19 * The intent is not to use content area for subrect rendering. Rather, the pixels outside the 20 * content area have undefined values and shouldn't be read *regardless* of filtering mode or 21 * the SkCanvas::SrcRectConstraint used for subrect draws. 22 */ 23 class GrTextureAdjuster : public GrTextureProducer { 24 public: 25 std::unique_ptr<GrFragmentProcessor> createFragmentProcessor( 26 const SkMatrix& textureMatrix, 27 const SkRect& constraintRect, 28 FilterConstraint, 29 bool coordsLimitedToConstraintRect, 30 const GrSamplerState::Filter* filterOrNullForBicubic) override; 31 32 // We do not ref the texture nor the colorspace, so the caller must keep them in scope while 33 // this Adjuster is alive. 34 GrTextureAdjuster(GrRecordingContext*, sk_sp<GrTextureProxy>, GrColorType, SkAlphaType, 35 uint32_t uniqueID, SkColorSpace*, bool useDecal = false); 36 37 protected: 38 void makeCopyKey(const CopyParams& params, GrUniqueKey* copyKey) override; 39 void didCacheCopy(const GrUniqueKey& copyKey, uint32_t contextUniqueID) override; 40 originalProxy()41 GrTextureProxy* originalProxy() const { return fOriginal.get(); } originalProxyRef()42 sk_sp<GrTextureProxy> originalProxyRef() const { return fOriginal; } 43 44 private: 45 sk_sp<GrTextureProxy> onRefTextureProxyForParams(const GrSamplerState&, 46 bool willBeMipped, 47 SkScalar scaleAdjust[2]) override; 48 49 sk_sp<GrTextureProxy> refTextureProxyCopy(const CopyParams& copyParams, bool willBeMipped); 50 51 sk_sp<GrTextureProxy> fOriginal; 52 uint32_t fUniqueID; 53 54 typedef GrTextureProducer INHERITED; 55 }; 56 57 #endif 58