Brian Osman | 3b66ab6 | 2016-11-28 09:26:31 -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 GrImageTextureMaker_DEFINED |
| 9 | #define GrImageTextureMaker_DEFINED |
| 10 | |
Brian Osman | e8e5458 | 2016-11-28 10:06:27 -0500 | [diff] [blame] | 11 | #include "GrTextureMaker.h" |
Brian Osman | 3b66ab6 | 2016-11-28 09:26:31 -0500 | [diff] [blame] | 12 | #include "SkImage.h" |
| 13 | |
Brian Osman | bd65955 | 2018-09-11 10:03:19 -0400 | [diff] [blame] | 14 | class SkImage_Lazy; |
Jim Van Verth | 30e0d7f | 2018-11-02 13:36:42 -0400 | [diff] [blame] | 15 | class SkImage_GpuYUVA; |
Brian Osman | 3b66ab6 | 2016-11-28 09:26:31 -0500 | [diff] [blame] | 16 | |
| 17 | /** This class manages the conversion of generator-backed images to GrTextures. If the caching hint |
| 18 | is kAllow the image's ID is used for the cache key. */ |
| 19 | class GrImageTextureMaker : public GrTextureMaker { |
| 20 | public: |
Brian Osman | df7e075 | 2017-04-26 16:20:28 -0400 | [diff] [blame] | 21 | GrImageTextureMaker(GrContext* context, const SkImage* client, SkImage::CachingHint chint); |
Brian Osman | 3b66ab6 | 2016-11-28 09:26:31 -0500 | [diff] [blame] | 22 | |
| 23 | protected: |
| 24 | // TODO: consider overriding this, for the case where the underlying generator might be |
| 25 | // able to efficiently produce a "stretched" texture natively (e.g. picture-backed) |
| 26 | // GrTexture* generateTextureForParams(const CopyParams&) override; |
Robert Phillips | 0c984a0 | 2017-03-16 07:51:56 -0400 | [diff] [blame] | 27 | sk_sp<GrTextureProxy> refOriginalTextureProxy(bool willBeMipped, |
Stan Iliev | ba81af2 | 2017-06-08 15:16:53 -0400 | [diff] [blame] | 28 | AllowedTexGenType onlyIfFast) override; |
Robert Phillips | 0c984a0 | 2017-03-16 07:51:56 -0400 | [diff] [blame] | 29 | |
Brian Osman | b3f3830 | 2018-09-07 15:24:44 -0400 | [diff] [blame] | 30 | void makeCopyKey(const CopyParams& stretch, GrUniqueKey* paramsCopyKey) override; |
Mike Reed | 30301c4 | 2018-07-19 09:39:21 -0400 | [diff] [blame] | 31 | void didCacheCopy(const GrUniqueKey& copyKey, uint32_t contextUniqueID) override {} |
Brian Osman | 3b66ab6 | 2016-11-28 09:26:31 -0500 | [diff] [blame] | 32 | |
| 33 | SkAlphaType alphaType() const override; |
Brian Osman | 6064e1c | 2018-10-19 14:27:54 -0400 | [diff] [blame] | 34 | SkColorSpace* colorSpace() const override; |
Brian Osman | 3b66ab6 | 2016-11-28 09:26:31 -0500 | [diff] [blame] | 35 | |
| 36 | private: |
Brian Osman | bd65955 | 2018-09-11 10:03:19 -0400 | [diff] [blame] | 37 | const SkImage_Lazy* fImage; |
Brian Osman | 3b66ab6 | 2016-11-28 09:26:31 -0500 | [diff] [blame] | 38 | GrUniqueKey fOriginalKey; |
| 39 | SkImage::CachingHint fCachingHint; |
| 40 | |
| 41 | typedef GrTextureMaker INHERITED; |
| 42 | }; |
| 43 | |
Jim Van Verth | 30e0d7f | 2018-11-02 13:36:42 -0400 | [diff] [blame] | 44 | /** This class manages the conversion of generator-backed YUVA images to GrTextures. */ |
| 45 | class GrYUVAImageTextureMaker : public GrTextureMaker { |
| 46 | public: |
| 47 | GrYUVAImageTextureMaker(GrContext* context, const SkImage* client); |
| 48 | |
| 49 | protected: |
| 50 | // TODO: consider overriding this, for the case where the underlying generator might be |
| 51 | // able to efficiently produce a "stretched" texture natively (e.g. picture-backed) |
| 52 | // GrTexture* generateTextureForParams(const CopyParams&) override; |
| 53 | sk_sp<GrTextureProxy> refOriginalTextureProxy(bool willBeMipped, |
| 54 | AllowedTexGenType onlyIfFast) override; |
| 55 | |
| 56 | void makeCopyKey(const CopyParams& stretch, GrUniqueKey* paramsCopyKey) override; |
| 57 | void didCacheCopy(const GrUniqueKey& copyKey, uint32_t contextUniqueID) override {} |
| 58 | |
| 59 | std::unique_ptr<GrFragmentProcessor> createFragmentProcessor( |
| 60 | const SkMatrix& textureMatrix, |
| 61 | const SkRect& constraintRect, |
| 62 | FilterConstraint filterConstraint, |
| 63 | bool coordsLimitedToConstraintRect, |
| 64 | const GrSamplerState::Filter* filterOrNullForBicubic) override; |
| 65 | |
| 66 | SkAlphaType alphaType() const override; |
| 67 | SkColorSpace* colorSpace() const override; |
Jim Van Verth | 3e4c2f3 | 2019-01-11 13:32:45 -0500 | [diff] [blame] | 68 | SkColorSpace* targetColorSpace() const override; |
Jim Van Verth | 30e0d7f | 2018-11-02 13:36:42 -0400 | [diff] [blame] | 69 | |
| 70 | private: |
| 71 | const SkImage_GpuYUVA* fImage; |
| 72 | GrUniqueKey fOriginalKey; |
| 73 | |
| 74 | typedef GrTextureMaker INHERITED; |
| 75 | }; |
| 76 | |
| 77 | |
Brian Osman | 3b66ab6 | 2016-11-28 09:26:31 -0500 | [diff] [blame] | 78 | #endif |