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 
11 #include "GrTextureMaker.h"
12 #include "SkImage.h"
13 
14 class SkImage_Lazy;
15 class SkImage_GpuYUVA;
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:
21     GrImageTextureMaker(GrRecordingContext* context, const SkImage* client,
22                         SkImage::CachingHint chint, bool useDecal = false);
23 
24 protected:
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;
28     sk_sp<GrTextureProxy> refOriginalTextureProxy(bool willBeMipped,
29                                                   AllowedTexGenType onlyIfFast) override;
30 
31     void makeCopyKey(const CopyParams& stretch, GrUniqueKey* paramsCopyKey) override;
didCacheCopy(const GrUniqueKey & copyKey,uint32_t contextUniqueID)32     void didCacheCopy(const GrUniqueKey& copyKey, uint32_t contextUniqueID) override {}
33 
34     SkAlphaType alphaType() const override;
35     SkColorSpace* colorSpace() const override;
36 
37 private:
38     const SkImage_Lazy*     fImage;
39     GrUniqueKey             fOriginalKey;
40     SkImage::CachingHint    fCachingHint;
41 
42     typedef GrTextureMaker INHERITED;
43 };
44 
45 /** This class manages the conversion of generator-backed YUVA images to GrTextures. */
46 class GrYUVAImageTextureMaker : public GrTextureMaker {
47 public:
48     GrYUVAImageTextureMaker(GrContext* context, const SkImage* client, bool useDecal = false);
49 
50 protected:
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;
didCacheCopy(const GrUniqueKey & copyKey,uint32_t contextUniqueID)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 
67     SkAlphaType alphaType() const override;
68     SkColorSpace* colorSpace() const override;
69 
70 private:
71     const SkImage_GpuYUVA*  fImage;
72     GrUniqueKey             fOriginalKey;
73 
74     typedef GrTextureMaker INHERITED;
75 };
76 
77 
78 #endif
79