Line data Source code
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 "SkTLazy.h"
13 :
14 : /**
15 : * Base class for sources that start out as textures. Optionally allows for a content area subrect.
16 : * The intent is not to use content area for subrect rendering. Rather, the pixels outside the
17 : * content area have undefined values and shouldn't be read *regardless* of filtering mode or
18 : * the SkCanvas::SrcRectConstraint used for subrect draws.
19 : */
20 0 : class GrTextureAdjuster : public GrTextureProducer {
21 : public:
22 : /** Makes the subset of the texture safe to use with the given texture parameters.
23 : outOffset will be the top-left corner of the subset if a copy is not made. Otherwise,
24 : the copy will be tight to the contents and outOffset will be (0, 0). If the copy's size
25 : does not match subset's dimensions then the contents are scaled to fit the copy.*/
26 : sk_sp<GrTextureProxy> refTextureProxySafeForParams(const GrSamplerParams&, SkIPoint* outOffset,
27 : SkScalar scaleAdjust[2]);
28 :
29 : sk_sp<GrFragmentProcessor> createFragmentProcessor(
30 : const SkMatrix& textureMatrix,
31 : const SkRect& constraintRect,
32 : FilterConstraint,
33 : bool coordsLimitedToConstraintRect,
34 : const GrSamplerParams::FilterMode* filterOrNullForBicubic,
35 : SkColorSpace* dstColorSpace) override;
36 :
37 : // We do not ref the texture nor the colorspace, so the caller must keep them in scope while
38 : // this Adjuster is alive.
39 : GrTextureAdjuster(GrContext*, sk_sp<GrTextureProxy>, SkAlphaType, const SkIRect& area,
40 : uint32_t uniqueID, SkColorSpace*);
41 :
42 : protected:
43 0 : SkAlphaType alphaType() const override { return fAlphaType; }
44 : void makeCopyKey(const CopyParams& params, GrUniqueKey* copyKey,
45 : SkColorSpace* dstColorSpace) override;
46 : void didCacheCopy(const GrUniqueKey& copyKey) override;
47 :
48 0 : GrTextureProxy* originalProxy() const { return fOriginal.get(); }
49 0 : sk_sp<GrTextureProxy> originalProxyRef() const { return fOriginal; }
50 :
51 : /** Returns the content area or null for the whole original texture */
52 0 : const SkIRect* contentAreaOrNull() { return fContentArea.getMaybeNull(); }
53 :
54 : private:
55 : SkTLazy<SkIRect> fContentArea;
56 : GrContext* fContext;
57 : sk_sp<GrTextureProxy> fOriginal;
58 : SkAlphaType fAlphaType;
59 : SkColorSpace* fColorSpace;
60 : uint32_t fUniqueID;
61 :
62 : sk_sp<GrTextureProxy> refTextureProxyCopy(const CopyParams ©Params);
63 :
64 : typedef GrTextureProducer INHERITED;
65 : };
66 :
67 : #endif
|