blob: aa26f45f59d9acfc77be68586ecc22fdf489d0b7 [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
Mike Kleinc0bd9f92019-04-23 12:05:21 -050011#include "src/core/SkTLazy.h"
12#include "src/gpu/GrTextureProducer.h"
Greg Danielf91aeb22019-06-18 09:58:02 -040013#include "src/gpu/GrTextureProxy.h"
Brian Osmane8e54582016-11-28 10:06:27 -050014
Robert Phillips9338c602019-02-19 12:52:29 -050015class GrRecordingContext;
16
Brian Osmane8e54582016-11-28 10:06:27 -050017/**
18 * Base class for sources that start out as textures. Optionally allows for a content area subrect.
19 * The intent is not to use content area for subrect rendering. Rather, the pixels outside the
20 * content area have undefined values and shouldn't be read *regardless* of filtering mode or
21 * the SkCanvas::SrcRectConstraint used for subrect draws.
22 */
23class GrTextureAdjuster : public GrTextureProducer {
24public:
Brian Salomonaff329b2017-08-11 09:40:37 -040025 std::unique_ptr<GrFragmentProcessor> createFragmentProcessor(
26 const SkMatrix& textureMatrix,
27 const SkRect& constraintRect,
28 FilterConstraint,
29 bool coordsLimitedToConstraintRect,
Brian Osman05c8f462018-10-22 17:13:36 -040030 const GrSamplerState::Filter* filterOrNullForBicubic) override;
Brian Osmane8e54582016-11-28 10:06:27 -050031
32 // We do not ref the texture nor the colorspace, so the caller must keep them in scope while
33 // this Adjuster is alive.
Michael Ludwigddeed372019-02-20 16:50:10 -050034 GrTextureAdjuster(GrRecordingContext*, sk_sp<GrTextureProxy>, SkAlphaType,
35 uint32_t uniqueID, SkColorSpace*, bool useDecal = false);
Brian Osmane8e54582016-11-28 10:06:27 -050036
37protected:
38 SkAlphaType alphaType() const override { return fAlphaType; }
Brian Osman6064e1c2018-10-19 14:27:54 -040039 SkColorSpace* colorSpace() const override { return fColorSpace; }
Brian Osmanb3f38302018-09-07 15:24:44 -040040 void makeCopyKey(const CopyParams& params, GrUniqueKey* copyKey) override;
Brian Salomon238069b2018-07-11 15:58:57 -040041 void didCacheCopy(const GrUniqueKey& copyKey, uint32_t contextUniqueID) override;
Brian Osmane8e54582016-11-28 10:06:27 -050042
Robert Phillips3798c862017-03-27 11:08:16 -040043 GrTextureProxy* originalProxy() const { return fOriginal.get(); }
44 sk_sp<GrTextureProxy> originalProxyRef() const { return fOriginal; }
Brian Osmane8e54582016-11-28 10:06:27 -050045
Brian Osmane8e54582016-11-28 10:06:27 -050046private:
Brian Salomon2a943df2018-05-04 13:43:19 -040047 sk_sp<GrTextureProxy> onRefTextureProxyForParams(const GrSamplerState&,
Greg Daniel8e9b4c42018-07-20 10:30:48 -040048 bool willBeMipped,
Brian Salomon2a943df2018-05-04 13:43:19 -040049 SkScalar scaleAdjust[2]) override;
50
51 sk_sp<GrTextureProxy> refTextureProxyCopy(const CopyParams& copyParams, bool willBeMipped);
52
Robert Phillips3798c862017-03-27 11:08:16 -040053 sk_sp<GrTextureProxy> fOriginal;
54 SkAlphaType fAlphaType;
55 SkColorSpace* fColorSpace;
56 uint32_t fUniqueID;
Brian Osmane8e54582016-11-28 10:06:27 -050057
Brian Osmane8e54582016-11-28 10:06:27 -050058 typedef GrTextureProducer INHERITED;
59};
60
61#endif