• 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/ganesh/vk/GrVkManagedResource.h"
12 
13 #include "include/gpu/vk/GrVkTypes.h"
14 #include "src/core/SkChecksum.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     SK_BEGIN_REQUIRE_DENSE
27     struct Key {
28         Key() = default;
KeyKey29         Key(VkFormat vkFormat, uint64_t externalFormat, uint32_t conversionKey) {
30             fVkFormat = vkFormat;
31             fExternalFormat = externalFormat;
32             fConversionKey = conversionKey;
33         }
34 
35         VkFormat fVkFormat = VK_FORMAT_UNDEFINED;
36         uint32_t fConversionKey = 0;
37         uint64_t fExternalFormat = 0;
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     SK_END_REQUIRE_DENSE
46 
47     // Helpers for hashing GrVkSamplerYcbcrConversion
48     static Key GenerateKey(const GrVkYcbcrConversionInfo& ycbcrInfo);
49 
GetKey(const GrVkSamplerYcbcrConversion & ycbcrConversion)50     static const Key& GetKey(const GrVkSamplerYcbcrConversion& ycbcrConversion) {
51         return ycbcrConversion.fKey;
52     }
Hash(const Key & key)53     static uint32_t Hash(const Key& key) {
54         return SkChecksum::Hash32(&key, sizeof(Key));
55     }
56 
57 #ifdef SK_TRACE_MANAGED_RESOURCES
dumpInfo()58     void dumpInfo() const override {
59         SkDebugf("GrVkSamplerYcbcrConversion: %" PRIdPTR " (%d refs)\n", (intptr_t)fYcbcrConversion,
60                  this->getRefCnt());
61     }
62 #endif
63 
64 private:
GrVkSamplerYcbcrConversion(const GrVkGpu * gpu,VkSamplerYcbcrConversion ycbcrConversion,Key key)65     GrVkSamplerYcbcrConversion(const GrVkGpu* gpu, VkSamplerYcbcrConversion ycbcrConversion,
66                                Key key)
67             : INHERITED(gpu)
68             , fYcbcrConversion(ycbcrConversion)
69             , fKey(key) {}
70 
71     void freeGPUData() const override;
72 
73     VkSamplerYcbcrConversion fYcbcrConversion;
74     Key                      fKey;
75 
76     using INHERITED = GrVkManagedResource;
77 };
78 
79 #endif
80 
81