blob: a365b504447d969f99ed37a7d378a64f3a6ee794 [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 GrTextureMaker_DEFINED
9#define GrTextureMaker_DEFINED
10
11#include "GrTextureProducer.h"
12
13/**
14 * Base class for sources that start out as something other than a texture (encoded image,
15 * picture, ...).
16 */
17class GrTextureMaker : public GrTextureProducer {
18public:
Stan Ilievba81af22017-06-08 15:16:53 -040019 enum class AllowedTexGenType : bool { kCheap, kAny };
20
Brian Salomonaff329b2017-08-11 09:40:37 -040021 std::unique_ptr<GrFragmentProcessor> createFragmentProcessor(
22 const SkMatrix& textureMatrix,
23 const SkRect& constraintRect,
24 FilterConstraint filterConstraint,
25 bool coordsLimitedToConstraintRect,
Brian Salomon2bbdcc42017-09-07 12:36:34 -040026 const GrSamplerState::Filter* filterOrNullForBicubic,
Brian Salomonaff329b2017-08-11 09:40:37 -040027 SkColorSpace* dstColorSpace) override;
Brian Osmane8e54582016-11-28 10:06:27 -050028
29protected:
30 GrTextureMaker(GrContext* context, int width, int height, bool isAlphaOnly)
31 : INHERITED(width, height, isAlphaOnly)
32 , fContext(context) {}
33
34 /**
35 * Return the maker's "original" texture. It is the responsibility of the maker to handle any
36 * caching of the original if desired.
Stan Ilievba81af22017-06-08 15:16:53 -040037 * If "genType" argument equals AllowedTexGenType::kCheap and the texture is not trivial to
38 * construct then refOriginalTextureProxy should return nullptr (for example if texture is made
39 * by drawing into a render target).
Brian Osmane8e54582016-11-28 10:06:27 -050040 */
Robert Phillips0c984a02017-03-16 07:51:56 -040041 virtual sk_sp<GrTextureProxy> refOriginalTextureProxy(bool willBeMipped,
Stan Ilievba81af22017-06-08 15:16:53 -040042 SkColorSpace* dstColorSpace,
43 AllowedTexGenType genType) = 0;
Robert Phillips0c984a02017-03-16 07:51:56 -040044
Brian Osmane8e54582016-11-28 10:06:27 -050045 /**
46 * Returns the color space of the maker's "original" texture, assuming it was retrieved with
Brian Osman61624f02016-12-09 14:51:59 -050047 * the same destination color space.
Brian Osmane8e54582016-11-28 10:06:27 -050048 */
Brian Osman61624f02016-12-09 14:51:59 -050049 virtual sk_sp<SkColorSpace> getColorSpace(SkColorSpace* dstColorSpace) = 0;
Brian Osmane8e54582016-11-28 10:06:27 -050050
Brian Osmane8e54582016-11-28 10:06:27 -050051 GrContext* context() const { return fContext; }
52
53private:
Brian Salomon2a943df2018-05-04 13:43:19 -040054 sk_sp<GrTextureProxy> onRefTextureProxyForParams(const GrSamplerState&,
55 SkColorSpace* dstColorSpace,
56 sk_sp<SkColorSpace>* proxyColorSpace,
57 SkScalar scaleAdjust[2]) override;
58
Brian Osmane8e54582016-11-28 10:06:27 -050059 GrContext* fContext;
60
61 typedef GrTextureProducer INHERITED;
62};
63
64#endif