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 | |
bsalomon | b1b0199 | 2015-11-18 10:56:08 -0800 | [diff] [blame] | 18 | /** This class manages the conversion of SW-backed bitmaps to GrTextures. If the input bitmap is |
| 19 | non-volatile the texture is cached using a key created from the pixels' image id and the |
| 20 | subset of the pixelref specified by the bitmap. */ |
| 21 | class GrBitmapTextureMaker : public GrTextureMaker { |
| 22 | public: |
| 23 | GrBitmapTextureMaker(GrContext* context, const SkBitmap& bitmap); |
| 24 | |
| 25 | protected: |
brianosman | 982eb7f | 2016-06-06 13:10:58 -0700 | [diff] [blame] | 26 | GrTexture* refOriginalTexture(bool willBeMipped, SkSourceGammaTreatment) override; |
bsalomon | b1b0199 | 2015-11-18 10:56:08 -0800 | [diff] [blame] | 27 | |
| 28 | void makeCopyKey(const CopyParams& copyParams, GrUniqueKey* copyKey) override; |
| 29 | |
| 30 | void didCacheCopy(const GrUniqueKey& copyKey) override; |
| 31 | |
brianosman | 5814b8a | 2016-08-18 06:43:03 -0700 | [diff] [blame] | 32 | SkAlphaType alphaType() const override; |
brianosman | 4280366 | 2016-07-15 06:59:48 -0700 | [diff] [blame] | 33 | SkColorSpace* getColorSpace() override; |
| 34 | |
bsalomon | b1b0199 | 2015-11-18 10:56:08 -0800 | [diff] [blame] | 35 | private: |
| 36 | const SkBitmap fBitmap; |
| 37 | GrUniqueKey fOriginalKey; |
| 38 | |
| 39 | typedef GrTextureMaker INHERITED; |
| 40 | }; |
| 41 | |
bsalomon | 1cf6f9b | 2015-12-08 10:53:43 -0800 | [diff] [blame] | 42 | /** This class manages the conversion of generator-backed images to GrTextures. If the caching hint |
| 43 | is kAllow the image's ID is used for the cache key. */ |
| 44 | class GrImageTextureMaker : public GrTextureMaker { |
| 45 | public: |
| 46 | GrImageTextureMaker(GrContext* context, SkImageCacherator* cacher, const SkImage* client, |
| 47 | SkImage::CachingHint chint); |
| 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 | |
brianosman | 982eb7f | 2016-06-06 13:10:58 -0700 | [diff] [blame] | 54 | GrTexture* refOriginalTexture(bool willBeMipped, SkSourceGammaTreatment) override; |
bsalomon | 1cf6f9b | 2015-12-08 10:53:43 -0800 | [diff] [blame] | 55 | void makeCopyKey(const CopyParams& stretch, GrUniqueKey* paramsCopyKey) override; |
| 56 | void didCacheCopy(const GrUniqueKey& copyKey) override; |
| 57 | |
brianosman | 5814b8a | 2016-08-18 06:43:03 -0700 | [diff] [blame] | 58 | SkAlphaType alphaType() const override; |
brianosman | 4280366 | 2016-07-15 06:59:48 -0700 | [diff] [blame] | 59 | SkColorSpace* getColorSpace() override; |
| 60 | |
bsalomon | 1cf6f9b | 2015-12-08 10:53:43 -0800 | [diff] [blame] | 61 | private: |
| 62 | SkImageCacherator* fCacher; |
| 63 | const SkImage* fClient; |
| 64 | GrUniqueKey fOriginalKey; |
| 65 | SkImage::CachingHint fCachingHint; |
| 66 | |
| 67 | typedef GrTextureMaker INHERITED; |
| 68 | }; |
| 69 | |
bsalomon | c55271f | 2015-11-09 11:55:57 -0800 | [diff] [blame] | 70 | #endif |