Coverage Report

Created: 2024-05-20 07:14

/src/skia/include/gpu/graphite/TextureInfo.h
Line
Count
Source (jump to first uncovered line)
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_graphite_TextureInfo_DEFINED
9
#define skgpu_graphite_TextureInfo_DEFINED
10
11
#include "include/core/SkString.h"
12
#include "include/core/SkTextureCompressionType.h"
13
#include "include/gpu/graphite/GraphiteTypes.h"
14
15
#ifdef SK_DAWN
16
#include "include/private/gpu/graphite/DawnTypesPriv.h"
17
#endif
18
19
#ifdef SK_METAL
20
#include "include/private/gpu/graphite/MtlGraphiteTypesPriv.h"
21
#endif
22
23
#ifdef SK_VULKAN
24
#include "include/private/gpu/graphite/VulkanGraphiteTypesPriv.h"
25
#endif
26
27
struct SkISize;
28
29
namespace skgpu::graphite {
30
31
class SK_API TextureInfo {
32
public:
33
0
    TextureInfo() {}
34
#ifdef SK_DAWN
35
    TextureInfo(const DawnTextureInfo& dawnInfo)
36
            : fBackend(BackendApi::kDawn)
37
            , fValid(true)
38
            , fSampleCount(dawnInfo.fSampleCount)
39
            , fMipmapped(dawnInfo.fMipmapped)
40
            , fProtected(Protected::kNo)
41
            , fDawnSpec(dawnInfo) {}
42
#endif
43
44
#ifdef SK_METAL
45
    TextureInfo(const MtlTextureInfo& mtlInfo)
46
            : fBackend(BackendApi::kMetal)
47
            , fValid(true)
48
            , fSampleCount(mtlInfo.fSampleCount)
49
            , fMipmapped(mtlInfo.fMipmapped)
50
            , fProtected(Protected::kNo)
51
            , fMtlSpec(mtlInfo) {}
52
#endif
53
54
#ifdef SK_VULKAN
55
    TextureInfo(const VulkanTextureInfo& vkInfo)
56
            : fBackend(BackendApi::kVulkan)
57
            , fValid(true)
58
            , fSampleCount(vkInfo.fSampleCount)
59
            , fMipmapped(vkInfo.fMipmapped)
60
            , fProtected(Protected::kNo)
61
0
            , fVkSpec(vkInfo) {
62
0
        if (vkInfo.fFlags & VK_IMAGE_CREATE_PROTECTED_BIT) {
63
0
            fProtected = Protected::kYes;
64
0
        }
65
0
    }
66
#endif
67
68
0
    ~TextureInfo() {}
69
    TextureInfo(const TextureInfo&) = default;
70
    TextureInfo& operator=(const TextureInfo&);
71
72
    bool operator==(const TextureInfo&) const;
73
0
    bool operator!=(const TextureInfo& that) const { return !(*this == that); }
74
75
0
    bool isValid() const { return fValid; }
76
0
    BackendApi backend() const { return fBackend; }
77
78
0
    uint32_t numSamples() const { return fSampleCount; }
79
0
    Mipmapped mipmapped() const { return fMipmapped; }
80
0
    Protected isProtected() const { return fProtected; }
81
    SkTextureCompressionType compressionType() const;
82
83
#ifdef SK_DAWN
84
    bool getDawnTextureInfo(DawnTextureInfo* info) const;
85
#endif
86
87
#ifdef SK_METAL
88
    bool getMtlTextureInfo(MtlTextureInfo* info) const {
89
        if (!this->isValid() || fBackend != BackendApi::kMetal) {
90
            return false;
91
        }
92
        *info = MtlTextureSpecToTextureInfo(fMtlSpec, fSampleCount, fMipmapped);
93
        return true;
94
    }
95
#endif
96
97
#ifdef SK_VULKAN
98
0
    bool getVulkanTextureInfo(VulkanTextureInfo* info) const {
99
0
        if (!this->isValid() || fBackend != BackendApi::kVulkan) {
100
0
            return false;
101
0
        }
102
0
        *info = VulkanTextureSpecToTextureInfo(fVkSpec, fSampleCount, fMipmapped);
103
0
        return true;
104
0
    }
105
#endif
106
107
    bool isCompatible(const TextureInfo& that) const;
108
    // Return a string containing the full description of this TextureInfo.
109
    SkString toString() const;
110
    // Return a string containing only the info relevant for its use as a RenderPass attachment.
111
    SkString toRPAttachmentString() const;
112
113
private:
114
    friend size_t ComputeSize(SkISize dimensions, const TextureInfo&);  // for bytesPerPixel
115
116
    size_t bytesPerPixel() const;
117
118
#ifdef SK_DAWN
119
    friend class DawnCaps;
120
    friend class DawnCommandBuffer;
121
    friend class DawnComputePipeline;
122
    friend class DawnGraphicsPipeline;
123
    friend class DawnResourceProvider;
124
    friend class DawnTexture;
125
    const DawnTextureSpec& dawnTextureSpec() const {
126
        SkASSERT(fValid && fBackend == BackendApi::kDawn);
127
        return fDawnSpec;
128
    }
129
#endif
130
131
#ifdef SK_METAL
132
    friend class MtlCaps;
133
    friend class MtlGraphicsPipeline;
134
    friend class MtlTexture;
135
    const MtlTextureSpec& mtlTextureSpec() const {
136
        SkASSERT(fValid && fBackend == BackendApi::kMetal);
137
        return fMtlSpec;
138
    }
139
#endif
140
141
#ifdef SK_VULKAN
142
    friend class VulkanCaps;
143
    friend class VulkanTexture;
144
0
    const VulkanTextureSpec& vulkanTextureSpec() const {
145
0
        SkASSERT(fValid && fBackend == BackendApi::kVulkan);
146
0
        return fVkSpec;
147
0
    }
Unexecuted instantiation: skgpu::graphite::TextureInfo::vulkanTextureSpec() const
Unexecuted instantiation: skgpu::graphite::TextureInfo::vulkanTextureSpec() const
148
#endif
149
150
    BackendApi fBackend = BackendApi::kMock;
151
    bool fValid = false;
152
153
    uint32_t fSampleCount = 1;
154
    Mipmapped fMipmapped = Mipmapped::kNo;
155
    Protected fProtected = Protected::kNo;
156
157
    union {
158
#ifdef SK_DAWN
159
        DawnTextureSpec fDawnSpec;
160
#endif
161
#ifdef SK_METAL
162
        MtlTextureSpec fMtlSpec;
163
#endif
164
#ifdef SK_VULKAN
165
        VulkanTextureSpec fVkSpec;
166
#endif
167
        void* fEnsureUnionNonEmpty;
168
    };
169
};
170
171
}  // namespace skgpu::graphite
172
173
#endif  //skgpu_graphite_TextureInfo_DEFINED