1/*
2 * Copyright 2021 Google LLC
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 skgpu_TextureInfo_DEFINED
9#define skgpu_TextureInfo_DEFINED
10
11#include "experimental/graphite/include/GraphiteTypes.h"
12
13#ifdef SK_METAL
14#include "experimental/graphite/include/private/MtlTypesPriv.h"
15#endif
16
17namespace skgpu {
18
19// Forward declares so we can friend classes in other namespaces
20#ifdef SK_METAL
21namespace mtl {
22    class Caps;
23    class Texture;
24}
25#endif
26
27class TextureInfo {
28public:
29    TextureInfo() {}
30#ifdef SK_METAL
31    TextureInfo(const mtl::TextureInfo& mtlInfo)
32            : fBackend(BackendApi::kMetal)
33            , fValid(true)
34            , fSampleCount(mtlInfo.fSampleCount)
35            , fLevelCount(mtlInfo.fLevelCount)
36            , fProtected(Protected::kNo)
37            , fMtlSpec(mtlInfo) {}
38#endif
39
40    ~TextureInfo() {}
41    TextureInfo(const TextureInfo&) = default;
42    TextureInfo& operator=(const TextureInfo&) = delete;
43
44    bool operator==(const TextureInfo&) const;
45
46    bool isValid() const { return fValid; }
47    BackendApi backend() const { return fBackend; }
48
49    uint32_t numSamples() const { return fSampleCount; }
50    uint32_t numMipLevels() const { return fLevelCount; }
51    Protected isProtected() const { return fProtected; }
52
53#ifdef SK_METAL
54    bool getMtlTextureInfo(mtl::TextureInfo* info) const {
55        if (!this->isValid() || fBackend != BackendApi::kMetal) {
56            return false;
57        }
58        *info = mtl::TextureSpecToTextureInfo(fMtlSpec, fSampleCount, fLevelCount);
59        return true;
60    }
61#endif
62
63private:
64#ifdef SK_METAL
65    friend class mtl::Caps;
66    friend class mtl::Texture;
67    const mtl::TextureSpec& mtlTextureSpec() const {
68        SkASSERT(fValid && fBackend == BackendApi::kMetal);
69        return fMtlSpec;
70    }
71#endif
72
73    BackendApi fBackend = BackendApi::kMock;
74    bool fValid = false;
75
76    uint32_t fSampleCount = 1;
77    uint32_t fLevelCount = 0;
78    Protected fProtected = Protected::kNo;
79
80    union {
81#ifdef SK_METAL
82        mtl::TextureSpec fMtlSpec;
83#endif
84    };
85};
86
87}  // namespace skgpu
88
89#endif  //skgpu_TextureInfo_DEFINED
90