GrTextureAdjuster.h 2.1 KB

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