blob: 4b7b63b1a078f107d53e4cd1c77840f60bacbb83 [file] [log] [blame]
Greg Daniel7e000222018-12-03 10:08:21 -05001/*
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 Daniel7e000222018-12-03 10:08:21 -050011#include "GrVkResource.h"
12
13#include "SkOpts.h"
14#include "vk/GrVkTypes.h"
15
16class GrVkGpu;
17
18class GrVkSamplerYcbcrConversion : public GrVkResource {
19public:
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
57private:
58 GrVkSamplerYcbcrConversion(VkSamplerYcbcrConversion ycbcrConversion, Key key)
59 : INHERITED()
60 , fYcbcrConversion(ycbcrConversion)
61 , fKey(key) {}
62
Ethan Nicholas8e265a72018-12-12 16:22:40 -050063 void freeGPUData(GrVkGpu* gpu) const override;
Greg Daniel7e000222018-12-03 10:08:21 -050064
65 VkSamplerYcbcrConversion fYcbcrConversion;
66 Key fKey;
67
68 typedef GrVkResource INHERITED;
69};
70
71#endif
72