bsalomon | c55271f | 2015-11-09 11:55:57 -0800 | [diff] [blame] | 1 | /* |
| 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" |
bsalomon | 1cf6f9b | 2015-12-08 10:53:43 -0800 | [diff] [blame] | 12 | #include "SkImage.h" |
bsalomon | c55271f | 2015-11-09 11:55:57 -0800 | [diff] [blame] | 13 | |
| 14 | class SkBitmap; |
| 15 | class SkImage_Base; |
bsalomon | 1cf6f9b | 2015-12-08 10:53:43 -0800 | [diff] [blame] | 16 | class SkImageCacherator; |
bsalomon | c55271f | 2015-11-09 11:55:57 -0800 | [diff] [blame] | 17 | |
halcanary | 9d524f2 | 2016-03-29 09:03:52 -0700 | [diff] [blame] | 18 | /** Implementation for texture-backed SkBitmaps. The bitmap must stay in scope and unmodified |
bsalomon | c55271f | 2015-11-09 11:55:57 -0800 | [diff] [blame] | 19 | while this object exists. */ |
| 20 | class GrBitmapTextureAdjuster : public GrTextureAdjuster { |
| 21 | public: |
| 22 | explicit GrBitmapTextureAdjuster(const SkBitmap* bmp); |
| 23 | |
| 24 | private: |
| 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. */ |
| 36 | class GrImageTextureAdjuster : public GrTextureAdjuster { |
| 37 | public: |
| 38 | explicit GrImageTextureAdjuster(const SkImage_Base* img); |
| 39 | |
| 40 | private: |
| 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 | |
bsalomon | b1b0199 | 2015-11-18 10:56:08 -0800 | [diff] [blame] | 50 | /** 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. */ |
| 53 | class GrBitmapTextureMaker : public GrTextureMaker { |
| 54 | public: |
| 55 | GrBitmapTextureMaker(GrContext* context, const SkBitmap& bitmap); |
| 56 | |
| 57 | protected: |
brianosman | 982eb7f | 2016-06-06 13:10:58 -0700 | [diff] [blame] | 58 | GrTexture* refOriginalTexture(bool willBeMipped, SkSourceGammaTreatment) override; |
bsalomon | b1b0199 | 2015-11-18 10:56:08 -0800 | [diff] [blame] | 59 | |
| 60 | void makeCopyKey(const CopyParams& copyParams, GrUniqueKey* copyKey) override; |
| 61 | |
| 62 | void didCacheCopy(const GrUniqueKey& copyKey) override; |
| 63 | |
| 64 | private: |
| 65 | const SkBitmap fBitmap; |
| 66 | GrUniqueKey fOriginalKey; |
| 67 | |
| 68 | typedef GrTextureMaker INHERITED; |
| 69 | }; |
| 70 | |
bsalomon | 1cf6f9b | 2015-12-08 10:53:43 -0800 | [diff] [blame] | 71 | /** 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. */ |
| 73 | class GrImageTextureMaker : public GrTextureMaker { |
| 74 | public: |
| 75 | GrImageTextureMaker(GrContext* context, SkImageCacherator* cacher, const SkImage* client, |
| 76 | SkImage::CachingHint chint); |
| 77 | |
| 78 | protected: |
| 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 | |
brianosman | 982eb7f | 2016-06-06 13:10:58 -0700 | [diff] [blame] | 83 | GrTexture* refOriginalTexture(bool willBeMipped, SkSourceGammaTreatment) override; |
bsalomon | 1cf6f9b | 2015-12-08 10:53:43 -0800 | [diff] [blame] | 84 | void makeCopyKey(const CopyParams& stretch, GrUniqueKey* paramsCopyKey) override; |
| 85 | void didCacheCopy(const GrUniqueKey& copyKey) override; |
| 86 | |
| 87 | private: |
| 88 | SkImageCacherator* fCacher; |
| 89 | const SkImage* fClient; |
| 90 | GrUniqueKey fOriginalKey; |
| 91 | SkImage::CachingHint fCachingHint; |
| 92 | |
| 93 | typedef GrTextureMaker INHERITED; |
| 94 | }; |
| 95 | |
bsalomon | c55271f | 2015-11-09 11:55:57 -0800 | [diff] [blame] | 96 | #endif |