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 Salomon | aff329b | 2017-08-11 09:40:37 -0400 | [diff] [blame] | 21 | std::unique_ptr<GrFragmentProcessor> createFragmentProcessor( |
| 22 | const SkMatrix& textureMatrix, |
| 23 | const SkRect& constraintRect, |
| 24 | FilterConstraint filterConstraint, |
| 25 | bool coordsLimitedToConstraintRect, |
Brian Salomon | 2bbdcc4 | 2017-09-07 12:36:34 -0400 | [diff] [blame] | 26 | const GrSamplerState::Filter* filterOrNullForBicubic, |
Brian Salomon | aff329b | 2017-08-11 09:40:37 -0400 | [diff] [blame] | 27 | SkColorSpace* dstColorSpace) override; |
Brian Osman | e8e5458 | 2016-11-28 10:06:27 -0500 | [diff] [blame] | 28 | |
| 29 | protected: |
| 30 | GrTextureMaker(GrContext* context, int width, int height, bool isAlphaOnly) |
Greg Daniel | 8e9b4c4 | 2018-07-20 10:30:48 -0400 | [diff] [blame] | 31 | : INHERITED(context, width, height, isAlphaOnly) {} |
Brian Osman | e8e5458 | 2016-11-28 10:06:27 -0500 | [diff] [blame] | 32 | |
| 33 | /** |
| 34 | * Return the maker's "original" texture. It is the responsibility of the maker to handle any |
| 35 | * caching of the original if desired. |
Stan Iliev | ba81af2 | 2017-06-08 15:16:53 -0400 | [diff] [blame] | 36 | * If "genType" argument equals AllowedTexGenType::kCheap and the texture is not trivial to |
| 37 | * construct then refOriginalTextureProxy should return nullptr (for example if texture is made |
| 38 | * by drawing into a render target). |
Brian Osman | e8e5458 | 2016-11-28 10:06:27 -0500 | [diff] [blame] | 39 | */ |
Robert Phillips | 0c984a0 | 2017-03-16 07:51:56 -0400 | [diff] [blame] | 40 | virtual sk_sp<GrTextureProxy> refOriginalTextureProxy(bool willBeMipped, |
Stan Iliev | ba81af2 | 2017-06-08 15:16:53 -0400 | [diff] [blame] | 41 | SkColorSpace* dstColorSpace, |
| 42 | AllowedTexGenType genType) = 0; |
Robert Phillips | 0c984a0 | 2017-03-16 07:51:56 -0400 | [diff] [blame] | 43 | |
Brian Osman | e8e5458 | 2016-11-28 10:06:27 -0500 | [diff] [blame] | 44 | /** |
| 45 | * 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] | 46 | * the same destination color space. |
Brian Osman | e8e5458 | 2016-11-28 10:06:27 -0500 | [diff] [blame] | 47 | */ |
Brian Osman | 61624f0 | 2016-12-09 14:51:59 -0500 | [diff] [blame] | 48 | virtual sk_sp<SkColorSpace> getColorSpace(SkColorSpace* dstColorSpace) = 0; |
Brian Osman | e8e5458 | 2016-11-28 10:06:27 -0500 | [diff] [blame] | 49 | |
Brian Osman | e8e5458 | 2016-11-28 10:06:27 -0500 | [diff] [blame] | 50 | GrContext* context() const { return fContext; } |
| 51 | |
| 52 | private: |
Brian Salomon | 2a943df | 2018-05-04 13:43:19 -0400 | [diff] [blame] | 53 | sk_sp<GrTextureProxy> onRefTextureProxyForParams(const GrSamplerState&, |
| 54 | SkColorSpace* dstColorSpace, |
| 55 | sk_sp<SkColorSpace>* proxyColorSpace, |
Greg Daniel | 8e9b4c4 | 2018-07-20 10:30:48 -0400 | [diff] [blame] | 56 | bool willBeMipped, |
Brian Salomon | 2a943df | 2018-05-04 13:43:19 -0400 | [diff] [blame] | 57 | SkScalar scaleAdjust[2]) override; |
| 58 | |
Brian Osman | e8e5458 | 2016-11-28 10:06:27 -0500 | [diff] [blame] | 59 | typedef GrTextureProducer INHERITED; |
| 60 | }; |
| 61 | |
| 62 | #endif |