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