GrImageTextureMaker.h 2.9 KB

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