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" 12 #include "SkImage.h" 13 14 class SkBitmap; 15 class SkImage_Base; 16 class SkImageCacherator; 17 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: 26 GrTexture* refOriginalTexture(bool willBeMipped, SkSourceGammaTreatment) override; 27 28 void makeCopyKey(const CopyParams& copyParams, GrUniqueKey* copyKey) override; 29 30 void didCacheCopy(const GrUniqueKey& copyKey) override; 31 32 SkAlphaType alphaType() const override; 33 SkColorSpace* getColorSpace() override; 34 35 private: 36 const SkBitmap fBitmap; 37 GrUniqueKey fOriginalKey; 38 39 typedef GrTextureMaker INHERITED; 40 }; 41 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 54 GrTexture* refOriginalTexture(bool willBeMipped, SkSourceGammaTreatment) override; 55 void makeCopyKey(const CopyParams& stretch, GrUniqueKey* paramsCopyKey) override; 56 void didCacheCopy(const GrUniqueKey& copyKey) override; 57 58 SkAlphaType alphaType() const override; 59 SkColorSpace* getColorSpace() override; 60 61 private: 62 SkImageCacherator* fCacher; 63 const SkImage* fClient; 64 GrUniqueKey fOriginalKey; 65 SkImage::CachingHint fCachingHint; 66 67 typedef GrTextureMaker INHERITED; 68 }; 69 70 #endif 71