blob: 909d3480bf6b49930f3885c3db60f46534228312 [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:
19 /**
20 * Returns a texture that is safe for use with the params. If the size of the returned texture
21 * does not match width()/height() then the contents of the original must be scaled to fit
Robert Phillips67c18d62017-01-20 12:44:06 -050022 * the texture. Additionally, the 'scaleAdjust' must be applied to the texture matrix
23 * in order to correct the absolute texture coordinates.
24 * Places the color space of the texture in (*texColorSpace).
Brian Osmane8e54582016-11-28 10:06:27 -050025 */
Robert Phillips3798c862017-03-27 11:08:16 -040026 sk_sp<GrTextureProxy> refTextureProxyForParams(const GrSamplerParams&,
27 SkColorSpace* dstColorSpace,
28 sk_sp<SkColorSpace>* texColorSpace,
29 SkScalar scaleAdjust[2]);
Brian Osmane8e54582016-11-28 10:06:27 -050030
31 sk_sp<GrFragmentProcessor> createFragmentProcessor(
32 const SkMatrix& textureMatrix,
33 const SkRect& constraintRect,
34 FilterConstraint filterConstraint,
35 bool coordsLimitedToConstraintRect,
36 const GrSamplerParams::FilterMode* filterOrNullForBicubic,
Brian Osman61624f02016-12-09 14:51:59 -050037 SkColorSpace* dstColorSpace) override;
Brian Osmane8e54582016-11-28 10:06:27 -050038
39protected:
40 GrTextureMaker(GrContext* context, int width, int height, bool isAlphaOnly)
41 : INHERITED(width, height, isAlphaOnly)
42 , fContext(context) {}
43
44 /**
45 * Return the maker's "original" texture. It is the responsibility of the maker to handle any
46 * caching of the original if desired.
47 */
Robert Phillips0c984a02017-03-16 07:51:56 -040048 virtual sk_sp<GrTextureProxy> refOriginalTextureProxy(bool willBeMipped,
49 SkColorSpace* dstColorSpace) = 0;
50
Brian Osmane8e54582016-11-28 10:06:27 -050051 /**
52 * Returns the color space of the maker's "original" texture, assuming it was retrieved with
Brian Osman61624f02016-12-09 14:51:59 -050053 * the same destination color space.
Brian Osmane8e54582016-11-28 10:06:27 -050054 */
Brian Osman61624f02016-12-09 14:51:59 -050055 virtual sk_sp<SkColorSpace> getColorSpace(SkColorSpace* dstColorSpace) = 0;
Brian Osmane8e54582016-11-28 10:06:27 -050056
57 /**
58 * Return a new (uncached) texture that is the stretch of the maker's original.
59 *
60 * The base-class handles general logic for this, and only needs access to the following
61 * method:
Robert Phillips78075802017-03-23 11:11:59 -040062 * - refOriginalTextureProxy()
Brian Osmane8e54582016-11-28 10:06:27 -050063 *
64 * Subclass may override this if they can handle creating the texture more directly than
65 * by copying.
66 */
Robert Phillips3798c862017-03-27 11:08:16 -040067 virtual sk_sp<GrTextureProxy> generateTextureProxyForParams(const CopyParams&,
68 bool willBeMipped,
69 SkColorSpace* dstColorSpace);
Brian Osmane8e54582016-11-28 10:06:27 -050070
71 GrContext* context() const { return fContext; }
72
73private:
74 GrContext* fContext;
75
76 typedef GrTextureProducer INHERITED;
77};
78
79#endif