blob: 392af44439cc6c644b1365bcb2e05e9c1fe337d4 [file] [log] [blame]
Brian Osmane8e54582016-11-28 10:06:27 -05001/*
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 */
20class GrTextureAdjuster : public GrTextureProducer {
21public:
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.*/
Robert Phillips3798c862017-03-27 11:08:16 -040026 sk_sp<GrTextureProxy> refTextureProxySafeForParams(const GrSamplerParams&, SkIPoint* outOffset,
27 SkScalar scaleAdjust[2]);
Brian Osmane8e54582016-11-28 10:06:27 -050028
29 sk_sp<GrFragmentProcessor> createFragmentProcessor(
30 const SkMatrix& textureMatrix,
31 const SkRect& constraintRect,
32 FilterConstraint,
33 bool coordsLimitedToConstraintRect,
34 const GrSamplerParams::FilterMode* filterOrNullForBicubic,
Brian Osman61624f02016-12-09 14:51:59 -050035 SkColorSpace* dstColorSpace) override;
Brian Osmane8e54582016-11-28 10:06:27 -050036
37 // We do not ref the texture nor the colorspace, so the caller must keep them in scope while
38 // this Adjuster is alive.
Robert Phillips3798c862017-03-27 11:08:16 -040039 GrTextureAdjuster(GrContext*, sk_sp<GrTextureProxy>, SkAlphaType, const SkIRect& area,
Robert Phillips0c984a02017-03-16 07:51:56 -040040 uint32_t uniqueID, SkColorSpace*);
Brian Osmane8e54582016-11-28 10:06:27 -050041
42protected:
43 SkAlphaType alphaType() const override { return fAlphaType; }
44 void makeCopyKey(const CopyParams& params, GrUniqueKey* copyKey,
Brian Osman61624f02016-12-09 14:51:59 -050045 SkColorSpace* dstColorSpace) override;
Brian Osmane8e54582016-11-28 10:06:27 -050046 void didCacheCopy(const GrUniqueKey& copyKey) override;
47
Robert Phillips3798c862017-03-27 11:08:16 -040048 GrTextureProxy* originalProxy() const { return fOriginal.get(); }
49 sk_sp<GrTextureProxy> originalProxyRef() const { return fOriginal; }
Brian Osmane8e54582016-11-28 10:06:27 -050050
51 /** Returns the content area or null for the whole original texture */
52 const SkIRect* contentAreaOrNull() { return fContentArea.getMaybeNull(); }
53
54private:
Robert Phillips3798c862017-03-27 11:08:16 -040055 SkTLazy<SkIRect> fContentArea;
56 GrContext* fContext;
57 sk_sp<GrTextureProxy> fOriginal;
58 SkAlphaType fAlphaType;
59 SkColorSpace* fColorSpace;
60 uint32_t fUniqueID;
Brian Osmane8e54582016-11-28 10:06:27 -050061
Robert Phillips0c984a02017-03-16 07:51:56 -040062 sk_sp<GrTextureProxy> refTextureProxyCopy(const CopyParams &copyParams);
Brian Osmane8e54582016-11-28 10:06:27 -050063
64 typedef GrTextureProducer INHERITED;
65};
66
67#endif