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 /** Implementation for texture-backed SkBitmaps. The bitmap must stay in scope and unmodified 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 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: 58 GrTexture* refOriginalTexture() override; 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 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 83 GrTexture* refOriginalTexture() override; 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 96 #endif 97