1 /* 2 * Copyright 2016 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 GrImageTextureMaker_DEFINED 9 #define GrImageTextureMaker_DEFINED 10 11 #include "include/core/SkImage.h" 12 #include "src/gpu/GrTextureMaker.h" 13 14 class SkImage_Lazy; 15 class SkImage_GpuYUVA; 16 17 /** This class manages the conversion of generator-backed images to GrTextures. If the caching hint 18 is kAllow the image's ID is used for the cache key. */ 19 class GrImageTextureMaker : public GrTextureMaker { 20 public: 21 GrImageTextureMaker(GrRecordingContext* context, const SkImage* client, 22 SkImage::CachingHint chint, bool useDecal = false); 23 24 private: 25 // TODO: consider overriding this, for the case where the underlying generator might be 26 // able to efficiently produce a "stretched" texture natively (e.g. picture-backed) 27 // GrTexture* generateTextureForParams(const CopyParams&) override; 28 GrSurfaceProxyView refOriginalTextureProxyView(bool willBeMipped, 29 AllowedTexGenType onlyIfFast) override; 30 31 void makeCopyKey(const CopyParams& stretch, GrUniqueKey* paramsCopyKey) override; didCacheCopy(const GrUniqueKey & copyKey,uint32_t contextUniqueID)32 void didCacheCopy(const GrUniqueKey& copyKey, uint32_t contextUniqueID) override {} 33 34 const SkImage_Lazy* fImage; 35 GrUniqueKey fOriginalKey; 36 SkImage::CachingHint fCachingHint; 37 38 typedef GrTextureMaker INHERITED; 39 }; 40 41 /** This class manages the conversion of generator-backed YUVA images to GrTextures. */ 42 class GrYUVAImageTextureMaker : public GrTextureMaker { 43 public: 44 GrYUVAImageTextureMaker(GrContext* context, const SkImage* client, bool useDecal = false); 45 46 // This could be made more nuanced and compare all of the texture proxy resolutions, but 47 // it's probably not worth the effort. hasMixedResolutions()48 bool hasMixedResolutions() const override { return true; } 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 GrSurfaceProxyView refOriginalTextureProxyView(bool willBeMipped, 54 AllowedTexGenType onlyIfFast) override; 55 56 void makeCopyKey(const CopyParams& stretch, GrUniqueKey* paramsCopyKey) override; didCacheCopy(const GrUniqueKey & copyKey,uint32_t contextUniqueID)57 void didCacheCopy(const GrUniqueKey& copyKey, uint32_t contextUniqueID) override {} 58 59 std::unique_ptr<GrFragmentProcessor> createFragmentProcessor( 60 const SkMatrix& textureMatrix, 61 const SkRect& constraintRect, 62 FilterConstraint filterConstraint, 63 bool coordsLimitedToConstraintRect, 64 const GrSamplerState::Filter* filterOrNullForBicubic) override; 65 66 private: 67 const SkImage_GpuYUVA* fImage; 68 GrUniqueKey fOriginalKey; 69 70 typedef GrTextureMaker INHERITED; 71 }; 72 73 #endif 74