blob: 87e505d4d4080dd7ef2538febd87077aded1b492 [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
Greg Daniel82c6b102020-01-21 10:33:22 -050024private:
Greg Danielcc104db2020-02-03 14:17:08 -050025 GrSurfaceProxyView refOriginalTextureProxyView(bool willBeMipped,
26 AllowedTexGenType onlyIfFast) override;
Robert Phillips0c984a02017-03-16 07:51:56 -040027
Brian Salomonc8d092a2020-02-24 10:14:21 -050028 void makeMipMappedKey(GrUniqueKey* mipMappedKey) override;
29 void didCacheMipMappedCopy(const GrUniqueKey& mipMappedKey, uint32_t contextUniqueID) override {
30 }
Brian Osman3b66ab62016-11-28 09:26:31 -050031
Brian Osmanbd659552018-09-11 10:03:19 -040032 const SkImage_Lazy* fImage;
Brian Osman3b66ab62016-11-28 09:26:31 -050033 GrUniqueKey fOriginalKey;
34 SkImage::CachingHint fCachingHint;
35
36 typedef GrTextureMaker INHERITED;
37};
38
Jim Van Verth30e0d7f2018-11-02 13:36:42 -040039/** This class manages the conversion of generator-backed YUVA images to GrTextures. */
40class GrYUVAImageTextureMaker : public GrTextureMaker {
41public:
Michael Ludwigddeed372019-02-20 16:50:10 -050042 GrYUVAImageTextureMaker(GrContext* context, const SkImage* client, bool useDecal = false);
Jim Van Verth30e0d7f2018-11-02 13:36:42 -040043
Michael Ludwiga6a84002019-04-12 15:03:02 -040044 // This could be made more nuanced and compare all of the texture proxy resolutions, but
45 // it's probably not worth the effort.
46 bool hasMixedResolutions() const override { return true; }
Jim Van Verth30e0d7f2018-11-02 13:36:42 -040047protected:
48 // TODO: consider overriding this, for the case where the underlying generator might be
49 // able to efficiently produce a "stretched" texture natively (e.g. picture-backed)
50 // GrTexture* generateTextureForParams(const CopyParams&) override;
Greg Danielcc104db2020-02-03 14:17:08 -050051 GrSurfaceProxyView refOriginalTextureProxyView(bool willBeMipped,
52 AllowedTexGenType onlyIfFast) override;
Jim Van Verth30e0d7f2018-11-02 13:36:42 -040053
Brian Salomonc8d092a2020-02-24 10:14:21 -050054 void makeMipMappedKey(GrUniqueKey* mipMappedKey) override;
55 void didCacheMipMappedCopy(const GrUniqueKey& mipMappedKey, uint32_t contextUniqueID) override {
56 }
Jim Van Verth30e0d7f2018-11-02 13:36:42 -040057
58 std::unique_ptr<GrFragmentProcessor> createFragmentProcessor(
59 const SkMatrix& textureMatrix,
60 const SkRect& constraintRect,
61 FilterConstraint filterConstraint,
62 bool coordsLimitedToConstraintRect,
63 const GrSamplerState::Filter* filterOrNullForBicubic) override;
64
Jim Van Verth30e0d7f2018-11-02 13:36:42 -040065private:
66 const SkImage_GpuYUVA* fImage;
67 GrUniqueKey fOriginalKey;
68
69 typedef GrTextureMaker INHERITED;
70};
71
Brian Osman3b66ab62016-11-28 09:26:31 -050072#endif