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 SkImageCacherator_DEFINED 9 #define SkImageCacherator_DEFINED 10 11 #include "SkImage.h" 12 #include "SkImageInfo.h" 13 14 #if SK_SUPPORT_GPU 15 #include "GrTextureMaker.h" 16 #endif 17 18 class GrCaps; 19 class GrContext; 20 class GrTextureProxy; 21 class GrUniqueKey; 22 class SkColorSpace; 23 24 /* 25 * Interface used by GrImageTextureMaker to construct textures from instances of SkImage 26 * (specifically, SkImage_Lazy). 27 */ 28 class SkImageCacherator { 29 public: 30 virtual ~SkImageCacherator() {} 31 32 enum CachedFormat { 33 kLegacy_CachedFormat, // The format from the generator, with any color space stripped out 34 kLinearF16_CachedFormat, // Half float RGBA with linear gamma 35 kSRGB8888_CachedFormat, // sRGB bytes 36 kSBGR8888_CachedFormat, // sRGB bytes, in BGR order 37 38 kNumCachedFormats, 39 }; 40 41 virtual CachedFormat chooseCacheFormat(SkColorSpace* dstColorSpace, 42 const GrCaps* = nullptr) const = 0; 43 virtual SkImageInfo buildCacheInfo(CachedFormat) const = 0; 44 45 #if SK_SUPPORT_GPU 46 // Returns the texture proxy. If the cacherator is generating the texture and wants to cache it, 47 // it should use the passed in key (if the key is valid). 48 // If "genType" argument equals AllowedTexGenType::kCheap and the texture is not trivial to 49 // construct then refOriginalTextureProxy should return nullptr (for example if texture is made 50 // by drawing into a render target). 51 virtual sk_sp<GrTextureProxy> lockTextureProxy(GrContext*, const GrUniqueKey& key, 52 SkImage::CachingHint, bool willBeMipped, 53 SkColorSpace* dstColorSpace, 54 GrTextureMaker::AllowedTexGenType genType) = 0; 55 56 // Returns the color space of the texture that would be returned if you called lockTexture. 57 // Separate code path to allow querying of the color space for textures that cached (even 58 // externally). 59 virtual sk_sp<SkColorSpace> getColorSpace(GrContext*, SkColorSpace* dstColorSpace) = 0; 60 virtual void makeCacheKeyFromOrigKey(const GrUniqueKey& origKey, CachedFormat, 61 GrUniqueKey* cacheKey) = 0; 62 #endif 63 }; 64 65 #endif 66