Greg Daniel | 7e00022 | 2018-12-03 10:08:21 -0500 | [diff] [blame] | 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 | |
Greg Daniel | 7e00022 | 2018-12-03 10:08:21 -0500 | [diff] [blame] | 11 | #include "GrVkResource.h" |
| 12 | |
| 13 | #include "SkOpts.h" |
| 14 | #include "vk/GrVkTypes.h" |
| 15 | |
| 16 | class GrVkGpu; |
| 17 | |
| 18 | class GrVkSamplerYcbcrConversion : public GrVkResource { |
| 19 | public: |
| 20 | static GrVkSamplerYcbcrConversion* Create(const GrVkGpu* gpu, const GrVkYcbcrConversionInfo&); |
| 21 | |
| 22 | VkSamplerYcbcrConversion ycbcrConversion() const { return fYcbcrConversion; } |
| 23 | |
| 24 | struct Key { |
| 25 | Key() : fExternalFormat(0), fConversionKey(0) {} |
| 26 | Key(uint64_t externalFormat, uint8_t conversionKey) { |
| 27 | memset(this, 0, sizeof(Key)); |
| 28 | fExternalFormat = externalFormat; |
| 29 | fConversionKey = conversionKey; |
| 30 | } |
| 31 | |
| 32 | uint64_t fExternalFormat; |
| 33 | uint8_t fConversionKey; |
| 34 | |
| 35 | bool operator==(const Key& that) const { |
| 36 | return this->fExternalFormat == that.fExternalFormat && |
| 37 | this->fConversionKey == that.fConversionKey; |
| 38 | } |
| 39 | }; |
| 40 | |
| 41 | // Helpers for hashing GrVkSamplerYcbcrConversion |
| 42 | static Key GenerateKey(const GrVkYcbcrConversionInfo& ycbcrInfo); |
| 43 | |
| 44 | static const Key& GetKey(const GrVkSamplerYcbcrConversion& ycbcrConversion) { |
| 45 | return ycbcrConversion.fKey; |
| 46 | } |
| 47 | static uint32_t Hash(const Key& key) { |
| 48 | return SkOpts::hash(reinterpret_cast<const uint32_t*>(&key), sizeof(Key)); |
| 49 | } |
| 50 | |
| 51 | #ifdef SK_TRACE_VK_RESOURCES |
| 52 | void dumpInfo() const override { |
| 53 | SkDebugf("GrVkSamplerYcbcrConversion: %d (%d refs)\n", fYcbcrConversion, this->getRefCnt()); |
| 54 | } |
| 55 | #endif |
| 56 | |
| 57 | private: |
| 58 | GrVkSamplerYcbcrConversion(VkSamplerYcbcrConversion ycbcrConversion, Key key) |
| 59 | : INHERITED() |
| 60 | , fYcbcrConversion(ycbcrConversion) |
| 61 | , fKey(key) {} |
| 62 | |
Ethan Nicholas | 8e265a7 | 2018-12-12 16:22:40 -0500 | [diff] [blame] | 63 | void freeGPUData(GrVkGpu* gpu) const override; |
Greg Daniel | 7e00022 | 2018-12-03 10:08:21 -0500 | [diff] [blame] | 64 | |
| 65 | VkSamplerYcbcrConversion fYcbcrConversion; |
| 66 | Key fKey; |
| 67 | |
| 68 | typedef GrVkResource INHERITED; |
| 69 | }; |
| 70 | |
| 71 | #endif |
| 72 | |