blob: 8024579505c1f2805438950319eec0b4f053c98d [file] [log] [blame]
Brian Osman3b66ab62016-11-28 09:26:31 -05001/*
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 Osmane8e54582016-11-28 10:06:27 -050011#include "GrTextureMaker.h"
Brian Osman3b66ab62016-11-28 09:26:31 -050012#include "SkImage.h"
13
Brian Osmanbd659552018-09-11 10:03:19 -040014class SkImage_Lazy;
Jim Van Verth30e0d7f2018-11-02 13:36:42 -040015class SkImage_GpuYUVA;
Brian Osman3b66ab62016-11-28 09:26:31 -050016
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. */
19class GrImageTextureMaker : public GrTextureMaker {
20public:
Brian Osmandf7e0752017-04-26 16:20:28 -040021 GrImageTextureMaker(GrContext* context, const SkImage* client, SkImage::CachingHint chint);
Brian Osman3b66ab62016-11-28 09:26:31 -050022
23protected:
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 Phillips0c984a02017-03-16 07:51:56 -040027 sk_sp<GrTextureProxy> refOriginalTextureProxy(bool willBeMipped,
Stan Ilievba81af22017-06-08 15:16:53 -040028 AllowedTexGenType onlyIfFast) override;
Robert Phillips0c984a02017-03-16 07:51:56 -040029
Brian Osmanb3f38302018-09-07 15:24:44 -040030 void makeCopyKey(const CopyParams& stretch, GrUniqueKey* paramsCopyKey) override;
Mike Reed30301c42018-07-19 09:39:21 -040031 void didCacheCopy(const GrUniqueKey& copyKey, uint32_t contextUniqueID) override {}
Brian Osman3b66ab62016-11-28 09:26:31 -050032
33 SkAlphaType alphaType() const override;
Brian Osman6064e1c2018-10-19 14:27:54 -040034 SkColorSpace* colorSpace() const override;
Brian Osman3b66ab62016-11-28 09:26:31 -050035
36private:
Brian Osmanbd659552018-09-11 10:03:19 -040037 const SkImage_Lazy* fImage;
Brian Osman3b66ab62016-11-28 09:26:31 -050038 GrUniqueKey fOriginalKey;
39 SkImage::CachingHint fCachingHint;
40
41 typedef GrTextureMaker INHERITED;
42};
43
Jim Van Verth30e0d7f2018-11-02 13:36:42 -040044/** This class manages the conversion of generator-backed YUVA images to GrTextures. */
45class GrYUVAImageTextureMaker : public GrTextureMaker {
46public:
47 GrYUVAImageTextureMaker(GrContext* context, const SkImage* client);
48
49protected:
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 Verth3e4c2f32019-01-11 13:32:45 -050068 SkColorSpace* targetColorSpace() const override;
Jim Van Verth30e0d7f2018-11-02 13:36:42 -040069
70private:
71 const SkImage_GpuYUVA* fImage;
72 GrUniqueKey fOriginalKey;
73
74 typedef GrTextureMaker INHERITED;
75};
76
77
Brian Osman3b66ab62016-11-28 09:26:31 -050078#endif