Brian Osman | e8e5458 | 2016-11-28 10:06:27 -0500 | [diff] [blame] | 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 |
Robert Phillips | 67c18d6 | 2017-01-20 12:44:06 -0500 | [diff] [blame] | 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). |
Brian Osman | e8e5458 | 2016-11-28 10:06:27 -0500 | [diff] [blame] | 25 | */ |
Brian Osman | 61624f0 | 2016-12-09 14:51:59 -0500 | [diff] [blame] | 26 | GrTexture* refTextureForParams(const GrSamplerParams&, SkColorSpace* dstColorSpace, |
Robert Phillips | 67c18d6 | 2017-01-20 12:44:06 -0500 | [diff] [blame] | 27 | sk_sp<SkColorSpace>* texColorSpace, SkScalar scaleAdjust[2]); |
Brian Osman | e8e5458 | 2016-11-28 10:06:27 -0500 | [diff] [blame] | 28 | |
| 29 | sk_sp<GrFragmentProcessor> createFragmentProcessor( |
| 30 | const SkMatrix& textureMatrix, |
| 31 | const SkRect& constraintRect, |
| 32 | FilterConstraint filterConstraint, |
| 33 | bool coordsLimitedToConstraintRect, |
| 34 | const GrSamplerParams::FilterMode* filterOrNullForBicubic, |
Brian Osman | 61624f0 | 2016-12-09 14:51:59 -0500 | [diff] [blame] | 35 | SkColorSpace* dstColorSpace) override; |
Brian Osman | e8e5458 | 2016-11-28 10:06:27 -0500 | [diff] [blame] | 36 | |
| 37 | protected: |
| 38 | GrTextureMaker(GrContext* context, int width, int height, bool isAlphaOnly) |
| 39 | : INHERITED(width, height, isAlphaOnly) |
| 40 | , fContext(context) {} |
| 41 | |
| 42 | /** |
| 43 | * Return the maker's "original" texture. It is the responsibility of the maker to handle any |
| 44 | * caching of the original if desired. |
| 45 | */ |
Brian Osman | 61624f0 | 2016-12-09 14:51:59 -0500 | [diff] [blame] | 46 | virtual GrTexture* refOriginalTexture(bool willBeMipped, SkColorSpace* dstColorSpace) = 0; |
Brian Osman | e8e5458 | 2016-11-28 10:06:27 -0500 | [diff] [blame] | 47 | |
| 48 | /** |
| 49 | * Returns the color space of the maker's "original" texture, assuming it was retrieved with |
Brian Osman | 61624f0 | 2016-12-09 14:51:59 -0500 | [diff] [blame] | 50 | * the same destination color space. |
Brian Osman | e8e5458 | 2016-11-28 10:06:27 -0500 | [diff] [blame] | 51 | */ |
Brian Osman | 61624f0 | 2016-12-09 14:51:59 -0500 | [diff] [blame] | 52 | virtual sk_sp<SkColorSpace> getColorSpace(SkColorSpace* dstColorSpace) = 0; |
Brian Osman | e8e5458 | 2016-11-28 10:06:27 -0500 | [diff] [blame] | 53 | |
| 54 | /** |
| 55 | * Return a new (uncached) texture that is the stretch of the maker's original. |
| 56 | * |
| 57 | * The base-class handles general logic for this, and only needs access to the following |
| 58 | * method: |
| 59 | * - refOriginalTexture() |
| 60 | * |
| 61 | * Subclass may override this if they can handle creating the texture more directly than |
| 62 | * by copying. |
| 63 | */ |
| 64 | virtual GrTexture* generateTextureForParams(const CopyParams&, bool willBeMipped, |
Brian Osman | 61624f0 | 2016-12-09 14:51:59 -0500 | [diff] [blame] | 65 | SkColorSpace* dstColorSpace); |
Brian Osman | e8e5458 | 2016-11-28 10:06:27 -0500 | [diff] [blame] | 66 | |
| 67 | GrContext* context() const { return fContext; } |
| 68 | |
| 69 | private: |
| 70 | GrContext* fContext; |
| 71 | |
| 72 | typedef GrTextureProducer INHERITED; |
| 73 | }; |
| 74 | |
| 75 | #endif |