blob: 1738d60ea8256f5b107ed38616905ee8d51360df [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 Phillips67c18d62017-01-20 12:44:06 -050026 GrTexture* refTextureSafeForParams(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.
39 GrTextureAdjuster(GrTexture*, SkAlphaType, const SkIRect& area, uint32_t uniqueID,
40 SkColorSpace*);
41
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
48 GrTexture* originalTexture() const { return fOriginal; }
49
50 /** Returns the content area or null for the whole original texture */
51 const SkIRect* contentAreaOrNull() { return fContentArea.getMaybeNull(); }
52
53private:
54 SkTLazy<SkIRect> fContentArea;
55 GrTexture* fOriginal;
56 SkAlphaType fAlphaType;
57 SkColorSpace* fColorSpace;
58 uint32_t fUniqueID;
59
60 GrTexture* refCopy(const CopyParams &copyParams);
61
62 typedef GrTextureProducer INHERITED;
63};
64
65#endif