blob: d516fc592c212a7f21786f080181c25ea7110825 [file] [log] [blame]
bsalomonc55271f2015-11-09 11:55:57 -08001/*
2 * Copyright 2015 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 GrImageIDTextureAdjuster_DEFINED
9#define GrImageIDTextureAdjuster_DEFINED
10
11#include "GrTextureParamsAdjuster.h"
bsalomon1cf6f9b2015-12-08 10:53:43 -080012#include "SkImage.h"
bsalomonc55271f2015-11-09 11:55:57 -080013
14class SkBitmap;
15class SkImage_Base;
bsalomon1cf6f9b2015-12-08 10:53:43 -080016class SkImageCacherator;
bsalomonc55271f2015-11-09 11:55:57 -080017
halcanary9d524f22016-03-29 09:03:52 -070018/** Implementation for texture-backed SkBitmaps. The bitmap must stay in scope and unmodified
bsalomonc55271f2015-11-09 11:55:57 -080019 while this object exists. */
20class GrBitmapTextureAdjuster : public GrTextureAdjuster {
21public:
22 explicit GrBitmapTextureAdjuster(const SkBitmap* bmp);
23
24private:
25 void makeCopyKey(const CopyParams& params, GrUniqueKey* copyKey) override;
26
27 void didCacheCopy(const GrUniqueKey& copyKey) override;
28
29 const SkBitmap* fBmp;
30
31 typedef GrTextureAdjuster INHERITED;
32};
33
34/** Implementation for texture-backed SkImages. The image must stay in scope and unmodified while
35 this object exists. */
36class GrImageTextureAdjuster : public GrTextureAdjuster {
37public:
38 explicit GrImageTextureAdjuster(const SkImage_Base* img);
39
40private:
41 void makeCopyKey(const CopyParams& params, GrUniqueKey* copyKey) override;
42
43 void didCacheCopy(const GrUniqueKey& copyKey) override;
44
45 const SkImage_Base* fImageBase;
46
47 typedef GrTextureAdjuster INHERITED;
48};
49
bsalomonb1b01992015-11-18 10:56:08 -080050/** This class manages the conversion of SW-backed bitmaps to GrTextures. If the input bitmap is
51 non-volatile the texture is cached using a key created from the pixels' image id and the
52 subset of the pixelref specified by the bitmap. */
53class GrBitmapTextureMaker : public GrTextureMaker {
54public:
55 GrBitmapTextureMaker(GrContext* context, const SkBitmap& bitmap);
56
57protected:
brianosman982eb7f2016-06-06 13:10:58 -070058 GrTexture* refOriginalTexture(bool willBeMipped, SkSourceGammaTreatment) override;
bsalomonb1b01992015-11-18 10:56:08 -080059
60 void makeCopyKey(const CopyParams& copyParams, GrUniqueKey* copyKey) override;
61
62 void didCacheCopy(const GrUniqueKey& copyKey) override;
63
64private:
65 const SkBitmap fBitmap;
66 GrUniqueKey fOriginalKey;
67
68 typedef GrTextureMaker INHERITED;
69};
70
bsalomon1cf6f9b2015-12-08 10:53:43 -080071/** This class manages the conversion of generator-backed images to GrTextures. If the caching hint
72 is kAllow the image's ID is used for the cache key. */
73class GrImageTextureMaker : public GrTextureMaker {
74public:
75 GrImageTextureMaker(GrContext* context, SkImageCacherator* cacher, const SkImage* client,
76 SkImage::CachingHint chint);
77
78protected:
79 // TODO: consider overriding this, for the case where the underlying generator might be
80 // able to efficiently produce a "stretched" texture natively (e.g. picture-backed)
81 // GrTexture* generateTextureForParams(const CopyParams&) override;
82
brianosman982eb7f2016-06-06 13:10:58 -070083 GrTexture* refOriginalTexture(bool willBeMipped, SkSourceGammaTreatment) override;
bsalomon1cf6f9b2015-12-08 10:53:43 -080084 void makeCopyKey(const CopyParams& stretch, GrUniqueKey* paramsCopyKey) override;
85 void didCacheCopy(const GrUniqueKey& copyKey) override;
86
87private:
88 SkImageCacherator* fCacher;
89 const SkImage* fClient;
90 GrUniqueKey fOriginalKey;
91 SkImage::CachingHint fCachingHint;
92
93 typedef GrTextureMaker INHERITED;
94};
95
bsalomonc55271f2015-11-09 11:55:57 -080096#endif