blob: eb500f7929eb36ec63b0aa5e9cf89be15843cedf [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:
23 /** Makes the subset of the texture safe to use with the given texture parameters.
24 outOffset will be the top-left corner of the subset if a copy is not made. Otherwise,
25 the copy will be tight to the contents and outOffset will be (0, 0). If the copy's size
26 does not match subset's dimensions then the contents are scaled to fit the copy.*/
Robert Phillips3798c862017-03-27 11:08:16 -040027 sk_sp<GrTextureProxy> refTextureProxySafeForParams(const GrSamplerParams&, SkIPoint* outOffset,
28 SkScalar scaleAdjust[2]);
Brian Osmane8e54582016-11-28 10:06:27 -050029
30 sk_sp<GrFragmentProcessor> createFragmentProcessor(
31 const SkMatrix& textureMatrix,
32 const SkRect& constraintRect,
33 FilterConstraint,
34 bool coordsLimitedToConstraintRect,
35 const GrSamplerParams::FilterMode* filterOrNullForBicubic,
Brian Osman61624f02016-12-09 14:51:59 -050036 SkColorSpace* dstColorSpace) override;
Brian Osmane8e54582016-11-28 10:06:27 -050037
38 // We do not ref the texture nor the colorspace, so the caller must keep them in scope while
39 // this Adjuster is alive.
Robert Phillips3798c862017-03-27 11:08:16 -040040 GrTextureAdjuster(GrContext*, sk_sp<GrTextureProxy>, SkAlphaType, const SkIRect& area,
Robert Phillips0c984a02017-03-16 07:51:56 -040041 uint32_t uniqueID, SkColorSpace*);
Brian Osmane8e54582016-11-28 10:06:27 -050042
43protected:
44 SkAlphaType alphaType() const override { return fAlphaType; }
45 void makeCopyKey(const CopyParams& params, GrUniqueKey* copyKey,
Brian Osman61624f02016-12-09 14:51:59 -050046 SkColorSpace* dstColorSpace) override;
Brian Osmane8e54582016-11-28 10:06:27 -050047 void didCacheCopy(const GrUniqueKey& copyKey) override;
48
Robert Phillips3798c862017-03-27 11:08:16 -040049 GrTextureProxy* originalProxy() const { return fOriginal.get(); }
50 sk_sp<GrTextureProxy> originalProxyRef() const { return fOriginal; }
Brian Osmane8e54582016-11-28 10:06:27 -050051
52 /** Returns the content area or null for the whole original texture */
53 const SkIRect* contentAreaOrNull() { return fContentArea.getMaybeNull(); }
54
55private:
Robert Phillips3798c862017-03-27 11:08:16 -040056 SkTLazy<SkIRect> fContentArea;
57 GrContext* fContext;
58 sk_sp<GrTextureProxy> fOriginal;
59 SkAlphaType fAlphaType;
60 SkColorSpace* fColorSpace;
61 uint32_t fUniqueID;
Brian Osmane8e54582016-11-28 10:06:27 -050062
Robert Phillips0c984a02017-03-16 07:51:56 -040063 sk_sp<GrTextureProxy> refTextureProxyCopy(const CopyParams &copyParams);
Brian Osmane8e54582016-11-28 10:06:27 -050064
65 typedef GrTextureProducer INHERITED;
66};
67
68#endif