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. 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).
25      */
26     sk_sp<GrTextureProxy> refTextureProxyForParams(const GrSamplerParams&,
27                                                    SkColorSpace* dstColorSpace,
28                                                    sk_sp<SkColorSpace>* texColorSpace,
29                                                    SkScalar scaleAdjust[2]);
30 
31     sk_sp<GrFragmentProcessor> createFragmentProcessor(
32                                 const SkMatrix& textureMatrix,
33                                 const SkRect& constraintRect,
34                                 FilterConstraint filterConstraint,
35                                 bool coordsLimitedToConstraintRect,
36                                 const GrSamplerParams::FilterMode* filterOrNullForBicubic,
37                                 SkColorSpace* dstColorSpace) override;
38 
39 protected:
GrTextureMaker(GrContext * context,int width,int height,bool isAlphaOnly)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      */
48     virtual sk_sp<GrTextureProxy> refOriginalTextureProxy(bool willBeMipped,
49                                                           SkColorSpace* dstColorSpace) = 0;
50 
51     /**
52      *  Returns the color space of the maker's "original" texture, assuming it was retrieved with
53      *  the same destination color space.
54      */
55     virtual sk_sp<SkColorSpace> getColorSpace(SkColorSpace* dstColorSpace) = 0;
56 
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:
62      *  - refOriginalTextureProxy()
63      *
64      *  Subclass may override this if they can handle creating the texture more directly than
65      *  by copying.
66      */
67     virtual sk_sp<GrTextureProxy> generateTextureProxyForParams(const CopyParams&,
68                                                                 bool willBeMipped,
69                                                                 SkColorSpace* dstColorSpace);
70 
context()71     GrContext* context() const { return fContext; }
72 
73 private:
74     GrContext*  fContext;
75 
76     typedef GrTextureProducer INHERITED;
77 };
78 
79 #endif
80