• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 "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 
ycbcrConversion()22     VkSamplerYcbcrConversion ycbcrConversion() const { return fYcbcrConversion; }
23 
24     struct Key {
KeyKey25         Key() : fExternalFormat(0), fConversionKey(0) {}
KeyKey26         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 
GetKey(const GrVkSamplerYcbcrConversion & ycbcrConversion)44     static const Key& GetKey(const GrVkSamplerYcbcrConversion& ycbcrConversion) {
45         return ycbcrConversion.fKey;
46     }
Hash(const Key & key)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
dumpInfo()52     void dumpInfo() const override {
53         SkDebugf("GrVkSamplerYcbcrConversion: %d (%d refs)\n", fYcbcrConversion, this->getRefCnt());
54     }
55 #endif
56 
57 private:
GrVkSamplerYcbcrConversion(VkSamplerYcbcrConversion ycbcrConversion,Key key)58     GrVkSamplerYcbcrConversion(VkSamplerYcbcrConversion ycbcrConversion, Key key)
59             : INHERITED()
60             , fYcbcrConversion(ycbcrConversion)
61             , fKey(key) {}
62 
63     void freeGPUData(GrVkGpu* gpu) const override;
64 
65     VkSamplerYcbcrConversion fYcbcrConversion;
66     Key                      fKey;
67 
68     typedef GrVkResource INHERITED;
69 };
70 
71 #endif
72 
73