• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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     std::unique_ptr<GrFragmentProcessor> createFragmentProcessor(
24             const SkMatrix& textureMatrix,
25             const SkRect& constraintRect,
26             FilterConstraint,
27             bool coordsLimitedToConstraintRect,
28             const GrSamplerState::Filter* filterOrNullForBicubic,
29             SkColorSpace* dstColorSpace) override;
30 
31     // We do not ref the texture nor the colorspace, so the caller must keep them in scope while
32     // this Adjuster is alive.
33     GrTextureAdjuster(GrContext*, sk_sp<GrTextureProxy>, SkAlphaType, uint32_t uniqueID,
34                       SkColorSpace*);
35 
36 protected:
alphaType()37     SkAlphaType alphaType() const override { return fAlphaType; }
38     void makeCopyKey(const CopyParams& params, GrUniqueKey* copyKey,
39                      SkColorSpace* dstColorSpace) override;
40     void didCacheCopy(const GrUniqueKey& copyKey) override;
41 
originalProxy()42     GrTextureProxy* originalProxy() const { return fOriginal.get(); }
originalProxyRef()43     sk_sp<GrTextureProxy> originalProxyRef() const { return fOriginal; }
44 
45 private:
46     sk_sp<GrTextureProxy> onRefTextureProxyForParams(const GrSamplerState&,
47                                                      SkColorSpace* dstColorSpace,
48                                                      sk_sp<SkColorSpace>* proxyColorSpace,
49                                                      SkScalar scaleAdjust[2]) override;
50 
51     sk_sp<GrTextureProxy> refTextureProxyCopy(const CopyParams& copyParams, bool willBeMipped);
52 
53     GrContext*            fContext;
54     sk_sp<GrTextureProxy> fOriginal;
55     SkAlphaType           fAlphaType;
56     SkColorSpace*         fColorSpace;
57     uint32_t              fUniqueID;
58 
59     typedef GrTextureProducer INHERITED;
60 };
61 
62 #endif
63