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 SkImageCacherator;
15 
16 /** This class manages the conversion of generator-backed images to GrTextures. If the caching hint
17     is kAllow the image's ID is used for the cache key. */
18 class GrImageTextureMaker : public GrTextureMaker {
19 public:
20     GrImageTextureMaker(GrContext* context, const SkImage* client, SkImage::CachingHint chint);
21 
22 protected:
23     // TODO: consider overriding this, for the case where the underlying generator might be
24     //       able to efficiently produce a "stretched" texture natively (e.g. picture-backed)
25     //          GrTexture* generateTextureForParams(const CopyParams&) override;
26     sk_sp<GrTextureProxy> refOriginalTextureProxy(bool willBeMipped,
27                                                   SkColorSpace* dstColorSpace,
28                                                   AllowedTexGenType onlyIfFast) override;
29 
30     void makeCopyKey(const CopyParams& stretch, GrUniqueKey* paramsCopyKey,
31                      SkColorSpace* dstColorSpace) override;
32     void didCacheCopy(const GrUniqueKey& copyKey) override;
33 
34     SkAlphaType alphaType() const override;
35     sk_sp<SkColorSpace> getColorSpace(SkColorSpace* dstColorSpace) override;
36 
37 private:
38     SkImageCacherator*      fCacher;
39     const SkImage*          fClient;
40     GrUniqueKey             fOriginalKey;
41     SkImage::CachingHint    fCachingHint;
42 
43     typedef GrTextureMaker INHERITED;
44 };
45 
46 #endif
47