blob: ad02ae06c82ba0bb13e6a10b21b8d675c849e39d [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"
Hal Canarye80e6182017-04-05 12:55:32 -040012#include "GrTextureProxy.h"
Brian Osmane8e54582016-11-28 10:06:27 -050013#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 */
21class GrTextureAdjuster : public GrTextureProducer {
22public:
Brian Salomonaff329b2017-08-11 09:40:37 -040023 std::unique_ptr<GrFragmentProcessor> createFragmentProcessor(
24 const SkMatrix& textureMatrix,
25 const SkRect& constraintRect,
26 FilterConstraint,
27 bool coordsLimitedToConstraintRect,
Brian Salomon2bbdcc42017-09-07 12:36:34 -040028 const GrSamplerState::Filter* filterOrNullForBicubic,
Brian Salomonaff329b2017-08-11 09:40:37 -040029 SkColorSpace* dstColorSpace) override;
Brian Osmane8e54582016-11-28 10:06:27 -050030
31 // We do not ref the texture nor the colorspace, so the caller must keep them in scope while
32 // this Adjuster is alive.
Greg Danielc77085d2017-11-01 16:38:48 -040033 GrTextureAdjuster(GrContext*, sk_sp<GrTextureProxy>, SkAlphaType, uint32_t uniqueID,
34 SkColorSpace*);
Brian Osmane8e54582016-11-28 10:06:27 -050035
36protected:
37 SkAlphaType alphaType() const override { return fAlphaType; }
38 void makeCopyKey(const CopyParams& params, GrUniqueKey* copyKey,
Brian Osman61624f02016-12-09 14:51:59 -050039 SkColorSpace* dstColorSpace) override;
Brian Salomon238069b2018-07-11 15:58:57 -040040 void didCacheCopy(const GrUniqueKey& copyKey, uint32_t contextUniqueID) override;
Brian Osmane8e54582016-11-28 10:06:27 -050041
Robert Phillips3798c862017-03-27 11:08:16 -040042 GrTextureProxy* originalProxy() const { return fOriginal.get(); }
43 sk_sp<GrTextureProxy> originalProxyRef() const { return fOriginal; }
Brian Osmane8e54582016-11-28 10:06:27 -050044
Brian Osmane8e54582016-11-28 10:06:27 -050045private:
Brian Salomon2a943df2018-05-04 13:43:19 -040046 sk_sp<GrTextureProxy> onRefTextureProxyForParams(const GrSamplerState&,
47 SkColorSpace* dstColorSpace,
48 sk_sp<SkColorSpace>* proxyColorSpace,
Greg Daniel8e9b4c42018-07-20 10:30:48 -040049 bool willBeMipped,
Brian Salomon2a943df2018-05-04 13:43:19 -040050 SkScalar scaleAdjust[2]) override;
51
52 sk_sp<GrTextureProxy> refTextureProxyCopy(const CopyParams& copyParams, bool willBeMipped);
53
Robert Phillips3798c862017-03-27 11:08:16 -040054 sk_sp<GrTextureProxy> fOriginal;
55 SkAlphaType fAlphaType;
56 SkColorSpace* fColorSpace;
57 uint32_t fUniqueID;
Brian Osmane8e54582016-11-28 10:06:27 -050058
Brian Osmane8e54582016-11-28 10:06:27 -050059 typedef GrTextureProducer INHERITED;
60};
61
62#endif