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(GrContext* context, const SkImage* client, SkImage::CachingHint chint);
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;
27     sk_sp<GrTextureProxy> refOriginalTextureProxy(bool willBeMipped,
28                                                   AllowedTexGenType onlyIfFast) override;
29 
30     void makeCopyKey(const CopyParams& stretch, GrUniqueKey* paramsCopyKey) override;
didCacheCopy(const GrUniqueKey & copyKey,uint32_t contextUniqueID)31     void didCacheCopy(const GrUniqueKey& copyKey, uint32_t contextUniqueID) override {}
32 
33     SkAlphaType alphaType() const override;
34     SkColorSpace* colorSpace() const override;
35 
36 private:
37     const SkImage_Lazy*     fImage;
38     GrUniqueKey             fOriginalKey;
39     SkImage::CachingHint    fCachingHint;
40 
41     typedef GrTextureMaker INHERITED;
42 };
43 
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;
didCacheCopy(const GrUniqueKey & copyKey,uint32_t contextUniqueID)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;
68     SkColorSpace* targetColorSpace() const override;
69 
70 private:
71     const SkImage_GpuYUVA*  fImage;
72     GrUniqueKey             fOriginalKey;
73 
74     typedef GrTextureMaker INHERITED;
75 };
76 
77 
78 #endif
79