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 8 #ifndef GrVkSamplerYcbcrConverison_DEFINED 9 #define GrVkSamplerYcbcrConverison_DEFINED 10 11 #include "include/private/base/SkDebug.h" 12 #include "include/private/base/SkMacros.h" 13 #include "include/private/gpu/vk/SkiaVulkan.h" 14 #include "src/core/SkChecksum.h" 15 #include "src/gpu/ganesh/GrManagedResource.h" 16 #include "src/gpu/ganesh/vk/GrVkManagedResource.h" 17 18 #include <cinttypes> 19 #include <cstdint> 20 class GrVkGpu; 21 namespace skgpu { 22 struct VulkanYcbcrConversionInfo; 23 } 24 25 class GrVkSamplerYcbcrConversion : public GrVkManagedResource { 26 public: 27 static GrVkSamplerYcbcrConversion* Create(GrVkGpu* gpu, 28 const skgpu::VulkanYcbcrConversionInfo&); 29 ycbcrConversion()30 VkSamplerYcbcrConversion ycbcrConversion() const { return fYcbcrConversion; } 31 32 SK_BEGIN_REQUIRE_DENSE 33 struct Key { 34 Key() = default; KeyKey35 Key(VkFormat vkFormat, uint64_t externalFormat, uint32_t conversionKey) { 36 fVkFormat = vkFormat; 37 fExternalFormat = externalFormat; 38 fConversionKey = conversionKey; 39 } 40 41 VkFormat fVkFormat = VK_FORMAT_UNDEFINED; 42 uint32_t fConversionKey = 0; 43 uint64_t fExternalFormat = 0; 44 45 bool operator==(const Key& that) const { 46 return this->fVkFormat == that.fVkFormat && 47 this->fExternalFormat == that.fExternalFormat && 48 this->fConversionKey == that.fConversionKey; 49 } 50 }; 51 SK_END_REQUIRE_DENSE 52 53 // Helpers for hashing GrVkSamplerYcbcrConversion 54 static Key GenerateKey(const skgpu::VulkanYcbcrConversionInfo& ycbcrInfo); 55 GetKey(const GrVkSamplerYcbcrConversion & ycbcrConversion)56 static const Key& GetKey(const GrVkSamplerYcbcrConversion& ycbcrConversion) { 57 return ycbcrConversion.fKey; 58 } Hash(const Key & key)59 static uint32_t Hash(const Key& key) { 60 return SkChecksum::Hash32(&key, sizeof(Key)); 61 } 62 63 #ifdef SK_TRACE_MANAGED_RESOURCES dumpInfo()64 void dumpInfo() const override { 65 SkDebugf("GrVkSamplerYcbcrConversion: %" PRIdPTR " (%d refs)\n", (intptr_t)fYcbcrConversion, 66 this->getRefCnt()); 67 } 68 #endif 69 70 private: GrVkSamplerYcbcrConversion(const GrVkGpu * gpu,VkSamplerYcbcrConversion ycbcrConversion,Key key)71 GrVkSamplerYcbcrConversion(const GrVkGpu* gpu, VkSamplerYcbcrConversion ycbcrConversion, 72 Key key) 73 : INHERITED(gpu) 74 , fYcbcrConversion(ycbcrConversion) 75 , fKey(key) {} 76 77 void freeGPUData() const override; 78 79 VkSamplerYcbcrConversion fYcbcrConversion; 80 Key fKey; 81 82 using INHERITED = GrVkManagedResource; 83 }; 84 85 #endif 86 87