GrVkSamplerYcbcrConversion.h 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. /*
  2. * Copyright 2018 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 GrVkSamplerYcbcrConverison_DEFINED
  8. #define GrVkSamplerYcbcrConverison_DEFINED
  9. #include "src/gpu/vk/GrVkResource.h"
  10. #include "include/gpu/vk/GrVkTypes.h"
  11. #include "src/core/SkOpts.h"
  12. class GrVkGpu;
  13. class GrVkSamplerYcbcrConversion : public GrVkResource {
  14. public:
  15. static GrVkSamplerYcbcrConversion* Create(const GrVkGpu* gpu, const GrVkYcbcrConversionInfo&);
  16. VkSamplerYcbcrConversion ycbcrConversion() const { return fYcbcrConversion; }
  17. struct Key {
  18. Key() : fExternalFormat(0), fConversionKey(0) {}
  19. Key(uint64_t externalFormat, uint8_t conversionKey) {
  20. memset(this, 0, sizeof(Key));
  21. fExternalFormat = externalFormat;
  22. fConversionKey = conversionKey;
  23. }
  24. uint64_t fExternalFormat;
  25. uint8_t fConversionKey;
  26. bool operator==(const Key& that) const {
  27. return this->fExternalFormat == that.fExternalFormat &&
  28. this->fConversionKey == that.fConversionKey;
  29. }
  30. };
  31. // Helpers for hashing GrVkSamplerYcbcrConversion
  32. static Key GenerateKey(const GrVkYcbcrConversionInfo& ycbcrInfo);
  33. static const Key& GetKey(const GrVkSamplerYcbcrConversion& ycbcrConversion) {
  34. return ycbcrConversion.fKey;
  35. }
  36. static uint32_t Hash(const Key& key) {
  37. return SkOpts::hash(reinterpret_cast<const uint32_t*>(&key), sizeof(Key));
  38. }
  39. #ifdef SK_TRACE_VK_RESOURCES
  40. void dumpInfo() const override {
  41. SkDebugf("GrVkSamplerYcbcrConversion: %d (%d refs)\n", fYcbcrConversion, this->getRefCnt());
  42. }
  43. #endif
  44. private:
  45. GrVkSamplerYcbcrConversion(VkSamplerYcbcrConversion ycbcrConversion, Key key)
  46. : INHERITED()
  47. , fYcbcrConversion(ycbcrConversion)
  48. , fKey(key) {}
  49. void freeGPUData(GrVkGpu* gpu) const override;
  50. VkSamplerYcbcrConversion fYcbcrConversion;
  51. Key fKey;
  52. typedef GrVkResource INHERITED;
  53. };
  54. #endif