Plumb dst color space in many places, rather than "mode"
[platform/upstream/libSkiaSharp.git] / src / gpu / GrTextureMaker.h
1 /*
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  */
17 class GrTextureMaker : public GrTextureProducer {
18 public:
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
22      *  the texture. Places the color space of the texture in (*texColorSpace).
23      */
24     GrTexture* refTextureForParams(const GrSamplerParams&, SkColorSpace* dstColorSpace,
25                                    sk_sp<SkColorSpace>* texColorSpace);
26
27     sk_sp<GrFragmentProcessor> createFragmentProcessor(
28                                 const SkMatrix& textureMatrix,
29                                 const SkRect& constraintRect,
30                                 FilterConstraint filterConstraint,
31                                 bool coordsLimitedToConstraintRect,
32                                 const GrSamplerParams::FilterMode* filterOrNullForBicubic,
33                                 SkColorSpace* dstColorSpace) override;
34
35 protected:
36     GrTextureMaker(GrContext* context, int width, int height, bool isAlphaOnly)
37         : INHERITED(width, height, isAlphaOnly)
38         , fContext(context) {}
39
40     /**
41      *  Return the maker's "original" texture. It is the responsibility of the maker to handle any
42      *  caching of the original if desired.
43      */
44     virtual GrTexture* refOriginalTexture(bool willBeMipped, SkColorSpace* dstColorSpace) = 0;
45
46     /**
47      *  Returns the color space of the maker's "original" texture, assuming it was retrieved with
48      *  the same destination color space.
49      */
50     virtual sk_sp<SkColorSpace> getColorSpace(SkColorSpace* dstColorSpace) = 0;
51
52     /**
53      *  Return a new (uncached) texture that is the stretch of the maker's original.
54      *
55      *  The base-class handles general logic for this, and only needs access to the following
56      *  method:
57      *  - refOriginalTexture()
58      *
59      *  Subclass may override this if they can handle creating the texture more directly than
60      *  by copying.
61      */
62     virtual GrTexture* generateTextureForParams(const CopyParams&, bool willBeMipped,
63                                                 SkColorSpace* dstColorSpace);
64
65     GrContext* context() const { return fContext; }
66
67 private:
68     GrContext*  fContext;
69
70     typedef GrTextureProducer INHERITED;
71 };
72
73 #endif