• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
17 namespace skgpu {
18 
19 // Forward declares so we can friend classes in other namespaces
20 #ifdef SK_METAL
21 namespace mtl {
22     class Caps;
23     class Texture;
24 }
25 #endif
26 
27 class TextureInfo {
28 public:
TextureInfo()29     TextureInfo() {}
30 #ifdef SK_METAL
TextureInfo(const mtl::TextureInfo & mtlInfo)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 
~TextureInfo()40     ~TextureInfo() {}
41     TextureInfo(const TextureInfo&) = default;
42     TextureInfo& operator=(const TextureInfo&);
43 
44     bool operator==(const TextureInfo&) const;
45     bool operator!=(const TextureInfo& that) const { return !(*this == that); }
46 
isValid()47     bool isValid() const { return fValid; }
backend()48     BackendApi backend() const { return fBackend; }
49 
numSamples()50     uint32_t numSamples() const { return fSampleCount; }
numMipLevels()51     uint32_t numMipLevels() const { return fLevelCount; }
isProtected()52     Protected isProtected() const { return fProtected; }
53 
54 #ifdef SK_METAL
getMtlTextureInfo(mtl::TextureInfo * info)55     bool getMtlTextureInfo(mtl::TextureInfo* info) const {
56         if (!this->isValid() || fBackend != BackendApi::kMetal) {
57             return false;
58         }
59         *info = mtl::TextureSpecToTextureInfo(fMtlSpec, fSampleCount, fLevelCount);
60         return true;
61     }
62 #endif
63 
64 private:
65 #ifdef SK_METAL
66     friend class mtl::Caps;
67     friend class mtl::Texture;
mtlTextureSpec()68     const mtl::TextureSpec& mtlTextureSpec() const {
69         SkASSERT(fValid && fBackend == BackendApi::kMetal);
70         return fMtlSpec;
71     }
72 #endif
73 
74     BackendApi fBackend = BackendApi::kMock;
75     bool fValid = false;
76 
77     uint32_t fSampleCount = 1;
78     uint32_t fLevelCount = 0;
79     Protected fProtected = Protected::kNo;
80 
81     union {
82 #ifdef SK_METAL
83         mtl::TextureSpec fMtlSpec;
84 #endif
85     };
86 };
87 
88 }  // namespace skgpu
89 
90 #endif  //skgpu_TextureInfo_DEFINED
91