blob: ca5b0e90c779d288d490bfbbf1b862c3ec5fc88c [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:
Greg Daniel4faa0402017-09-29 15:21:28 -040023 /** Makes the subset of the texture safe to use with the given texture parameters. If the copy's
24 size does not match subset's dimensions then the contents are scaled to fit the copy.*/
25 sk_sp<GrTextureProxy> refTextureProxySafeForParams(const GrSamplerState&,
Robert Phillips3798c862017-03-27 11:08:16 -040026 SkScalar scaleAdjust[2]);
Brian Osmane8e54582016-11-28 10:06:27 -050027
Brian Salomonaff329b2017-08-11 09:40:37 -040028 std::unique_ptr<GrFragmentProcessor> createFragmentProcessor(
29 const SkMatrix& textureMatrix,
30 const SkRect& constraintRect,
31 FilterConstraint,
32 bool coordsLimitedToConstraintRect,
Brian Salomon2bbdcc42017-09-07 12:36:34 -040033 const GrSamplerState::Filter* filterOrNullForBicubic,
Brian Salomonaff329b2017-08-11 09:40:37 -040034 SkColorSpace* dstColorSpace) override;
Brian Osmane8e54582016-11-28 10:06:27 -050035
36 // We do not ref the texture nor the colorspace, so the caller must keep them in scope while
37 // this Adjuster is alive.
Brian Salomon4df00922017-09-07 16:34:11 +000038 GrTextureAdjuster(GrContext*, sk_sp<GrTextureProxy>, SkAlphaType, const SkIRect& area,
39 uint32_t uniqueID, SkColorSpace*);
Brian Osmane8e54582016-11-28 10:06:27 -050040
41protected:
42 SkAlphaType alphaType() const override { return fAlphaType; }
43 void makeCopyKey(const CopyParams& params, GrUniqueKey* copyKey,
Brian Osman61624f02016-12-09 14:51:59 -050044 SkColorSpace* dstColorSpace) override;
Brian Osmane8e54582016-11-28 10:06:27 -050045 void didCacheCopy(const GrUniqueKey& copyKey) override;
46
Robert Phillips3798c862017-03-27 11:08:16 -040047 GrTextureProxy* originalProxy() const { return fOriginal.get(); }
48 sk_sp<GrTextureProxy> originalProxyRef() const { return fOriginal; }
Brian Osmane8e54582016-11-28 10:06:27 -050049
Brian Salomon4df00922017-09-07 16:34:11 +000050 /** Returns the content area or null for the whole original texture */
51 const SkIRect* contentAreaOrNull() { return fContentArea.getMaybeNull(); }
52
Brian Osmane8e54582016-11-28 10:06:27 -050053private:
Brian Salomon4df00922017-09-07 16:34:11 +000054 SkTLazy<SkIRect> fContentArea;
Robert Phillips3798c862017-03-27 11:08:16 -040055 GrContext* fContext;
56 sk_sp<GrTextureProxy> fOriginal;
57 SkAlphaType fAlphaType;
58 SkColorSpace* fColorSpace;
59 uint32_t fUniqueID;
Brian Osmane8e54582016-11-28 10:06:27 -050060
Greg Daniele1da1d92017-10-06 15:59:27 -040061 sk_sp<GrTextureProxy> refTextureProxyCopy(const CopyParams &copyParams, bool willBeMipped);
Brian Osmane8e54582016-11-28 10:06:27 -050062
63 typedef GrTextureProducer INHERITED;
64};
65
66#endif