blob: 44e74243e531339735212f5f61267de7c6a5c3da [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
Mike Kleinc0bd9f92019-04-23 12:05:21 -050011#include "include/core/SkImage.h"
12#include "src/gpu/GrTextureMaker.h"
Brian Osman3b66ab62016-11-28 09:26:31 -050013
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:
Robert Phillips9338c602019-02-19 12:52:29 -050021 GrImageTextureMaker(GrRecordingContext* context, const SkImage* client,
Michael Ludwigddeed372019-02-20 16:50:10 -050022 SkImage::CachingHint chint, bool useDecal = false);
Brian Osman3b66ab62016-11-28 09:26:31 -050023
24protected:
25 // TODO: consider overriding this, for the case where the underlying generator might be
26 // able to efficiently produce a "stretched" texture natively (e.g. picture-backed)
27 // GrTexture* generateTextureForParams(const CopyParams&) override;
Robert Phillips0c984a02017-03-16 07:51:56 -040028 sk_sp<GrTextureProxy> refOriginalTextureProxy(bool willBeMipped,
Stan Ilievba81af22017-06-08 15:16:53 -040029 AllowedTexGenType onlyIfFast) override;
Robert Phillips0c984a02017-03-16 07:51:56 -040030
Brian Osmanb3f38302018-09-07 15:24:44 -040031 void makeCopyKey(const CopyParams& stretch, GrUniqueKey* paramsCopyKey) override;
Mike Reed30301c42018-07-19 09:39:21 -040032 void didCacheCopy(const GrUniqueKey& copyKey, uint32_t contextUniqueID) override {}
Brian Osman3b66ab62016-11-28 09:26:31 -050033
Brian Osman3b66ab62016-11-28 09:26:31 -050034private:
Brian Osmanbd659552018-09-11 10:03:19 -040035 const SkImage_Lazy* fImage;
Brian Osman3b66ab62016-11-28 09:26:31 -050036 GrUniqueKey fOriginalKey;
37 SkImage::CachingHint fCachingHint;
38
39 typedef GrTextureMaker INHERITED;
40};
41
Jim Van Verth30e0d7f2018-11-02 13:36:42 -040042/** This class manages the conversion of generator-backed YUVA images to GrTextures. */
43class GrYUVAImageTextureMaker : public GrTextureMaker {
44public:
Michael Ludwigddeed372019-02-20 16:50:10 -050045 GrYUVAImageTextureMaker(GrContext* context, const SkImage* client, bool useDecal = false);
Jim Van Verth30e0d7f2018-11-02 13:36:42 -040046
Michael Ludwiga6a84002019-04-12 15:03:02 -040047 // This could be made more nuanced and compare all of the texture proxy resolutions, but
48 // it's probably not worth the effort.
49 bool hasMixedResolutions() const override { return true; }
Jim Van Verth30e0d7f2018-11-02 13:36:42 -040050protected:
51 // TODO: consider overriding this, for the case where the underlying generator might be
52 // able to efficiently produce a "stretched" texture natively (e.g. picture-backed)
53 // GrTexture* generateTextureForParams(const CopyParams&) override;
54 sk_sp<GrTextureProxy> refOriginalTextureProxy(bool willBeMipped,
55 AllowedTexGenType onlyIfFast) override;
56
57 void makeCopyKey(const CopyParams& stretch, GrUniqueKey* paramsCopyKey) override;
58 void didCacheCopy(const GrUniqueKey& copyKey, uint32_t contextUniqueID) override {}
59
60 std::unique_ptr<GrFragmentProcessor> createFragmentProcessor(
61 const SkMatrix& textureMatrix,
62 const SkRect& constraintRect,
63 FilterConstraint filterConstraint,
64 bool coordsLimitedToConstraintRect,
65 const GrSamplerState::Filter* filterOrNullForBicubic) override;
66
Jim Van Verth30e0d7f2018-11-02 13:36:42 -040067private:
68 const SkImage_GpuYUVA* fImage;
69 GrUniqueKey fOriginalKey;
70
71 typedef GrTextureMaker INHERITED;
72};
73
74
Brian Osman3b66ab62016-11-28 09:26:31 -050075#endif