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