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: |
Stan Iliev | ba81af2 | 2017-06-08 15:16:53 -0400 | [diff] [blame] | 19 | enum class AllowedTexGenType : bool { kCheap, kAny }; |
| 20 | |
Brian Osman | e8e5458 | 2016-11-28 10:06:27 -0500 | [diff] [blame] | 21 | /** |
| 22 | * Returns a texture that is safe for use with the params. If the size of the returned texture |
| 23 | * 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] | 24 | * the texture. Additionally, the 'scaleAdjust' must be applied to the texture matrix |
| 25 | * in order to correct the absolute texture coordinates. |
| 26 | * Places the color space of the texture in (*texColorSpace). |
Brian Osman | e8e5458 | 2016-11-28 10:06:27 -0500 | [diff] [blame] | 27 | */ |
Brian Salomon | 2bbdcc4 | 2017-09-07 12:36:34 -0400 | [diff] [blame] | 28 | sk_sp<GrTextureProxy> refTextureProxyForParams(const GrSamplerState&, |
Robert Phillips | 3798c86 | 2017-03-27 11:08:16 -0400 | [diff] [blame] | 29 | SkColorSpace* dstColorSpace, |
| 30 | sk_sp<SkColorSpace>* texColorSpace, |
| 31 | SkScalar scaleAdjust[2]); |
Brian Osman | e8e5458 | 2016-11-28 10:06:27 -0500 | [diff] [blame] | 32 | |
Brian Salomon | aff329b | 2017-08-11 09:40:37 -0400 | [diff] [blame] | 33 | std::unique_ptr<GrFragmentProcessor> createFragmentProcessor( |
| 34 | const SkMatrix& textureMatrix, |
| 35 | const SkRect& constraintRect, |
| 36 | FilterConstraint filterConstraint, |
| 37 | bool coordsLimitedToConstraintRect, |
Brian Salomon | 2bbdcc4 | 2017-09-07 12:36:34 -0400 | [diff] [blame] | 38 | const GrSamplerState::Filter* filterOrNullForBicubic, |
Brian Salomon | aff329b | 2017-08-11 09:40:37 -0400 | [diff] [blame] | 39 | SkColorSpace* dstColorSpace) override; |
Brian Osman | e8e5458 | 2016-11-28 10:06:27 -0500 | [diff] [blame] | 40 | |
| 41 | protected: |
| 42 | GrTextureMaker(GrContext* context, int width, int height, bool isAlphaOnly) |
| 43 | : INHERITED(width, height, isAlphaOnly) |
| 44 | , fContext(context) {} |
| 45 | |
| 46 | /** |
| 47 | * Return the maker's "original" texture. It is the responsibility of the maker to handle any |
| 48 | * caching of the original if desired. |
Stan Iliev | ba81af2 | 2017-06-08 15:16:53 -0400 | [diff] [blame] | 49 | * If "genType" argument equals AllowedTexGenType::kCheap and the texture is not trivial to |
| 50 | * construct then refOriginalTextureProxy should return nullptr (for example if texture is made |
| 51 | * by drawing into a render target). |
Brian Osman | e8e5458 | 2016-11-28 10:06:27 -0500 | [diff] [blame] | 52 | */ |
Robert Phillips | 0c984a0 | 2017-03-16 07:51:56 -0400 | [diff] [blame] | 53 | virtual sk_sp<GrTextureProxy> refOriginalTextureProxy(bool willBeMipped, |
Stan Iliev | ba81af2 | 2017-06-08 15:16:53 -0400 | [diff] [blame] | 54 | SkColorSpace* dstColorSpace, |
| 55 | AllowedTexGenType genType) = 0; |
Robert Phillips | 0c984a0 | 2017-03-16 07:51:56 -0400 | [diff] [blame] | 56 | |
Brian Osman | e8e5458 | 2016-11-28 10:06:27 -0500 | [diff] [blame] | 57 | /** |
| 58 | * 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] | 59 | * the same destination color space. |
Brian Osman | e8e5458 | 2016-11-28 10:06:27 -0500 | [diff] [blame] | 60 | */ |
Brian Osman | 61624f0 | 2016-12-09 14:51:59 -0500 | [diff] [blame] | 61 | virtual sk_sp<SkColorSpace> getColorSpace(SkColorSpace* dstColorSpace) = 0; |
Brian Osman | e8e5458 | 2016-11-28 10:06:27 -0500 | [diff] [blame] | 62 | |
| 63 | /** |
| 64 | * Return a new (uncached) texture that is the stretch of the maker's original. |
| 65 | * |
| 66 | * The base-class handles general logic for this, and only needs access to the following |
| 67 | * method: |
Robert Phillips | 7807580 | 2017-03-23 11:11:59 -0400 | [diff] [blame] | 68 | * - refOriginalTextureProxy() |
Brian Osman | e8e5458 | 2016-11-28 10:06:27 -0500 | [diff] [blame] | 69 | * |
| 70 | * Subclass may override this if they can handle creating the texture more directly than |
| 71 | * by copying. |
| 72 | */ |
Robert Phillips | 3798c86 | 2017-03-27 11:08:16 -0400 | [diff] [blame] | 73 | virtual sk_sp<GrTextureProxy> generateTextureProxyForParams(const CopyParams&, |
| 74 | bool willBeMipped, |
| 75 | SkColorSpace* dstColorSpace); |
Brian Osman | e8e5458 | 2016-11-28 10:06:27 -0500 | [diff] [blame] | 76 | |
| 77 | GrContext* context() const { return fContext; } |
| 78 | |
| 79 | private: |
| 80 | GrContext* fContext; |
| 81 | |
| 82 | typedef GrTextureProducer INHERITED; |
| 83 | }; |
| 84 | |
| 85 | #endif |