Coverage Report

Created: 2024-09-14 07:19

/src/skia/src/gpu/graphite/TextureInfo.cpp
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
#include "include/gpu/graphite/TextureInfo.h"
9
10
#include "src/gpu/graphite/TextureInfoPriv.h"
11
12
namespace skgpu::graphite {
13
14
0
TextureInfo::TextureInfo(){};
15
0
TextureInfo::~TextureInfo() = default;
16
17
0
static inline void assert_is_supported_backend(const BackendApi& backend) {
18
0
    SkASSERT(backend == BackendApi::kDawn ||
19
0
             backend == BackendApi::kMetal ||
20
0
             backend == BackendApi::kVulkan);
21
0
}
Unexecuted instantiation: TextureInfo.cpp:skgpu::graphite::assert_is_supported_backend(skgpu::BackendApi const&)
Unexecuted instantiation: TextureInfo.cpp:skgpu::graphite::assert_is_supported_backend(skgpu::BackendApi const&)
22
23
TextureInfo::TextureInfo(const TextureInfo& that)
24
        : fBackend(that.fBackend)
25
        , fValid(that.fValid)
26
        , fSampleCount(that.fSampleCount)
27
        , fMipmapped(that.fMipmapped)
28
0
        , fProtected(that.fProtected) {
29
0
    if (!fValid) {
30
0
        return;
31
0
    }
32
33
0
    assert_is_supported_backend(fBackend);
34
0
    fTextureInfoData.reset();
35
0
    that.fTextureInfoData->copyTo(fTextureInfoData);
36
0
}
37
38
0
TextureInfo& TextureInfo::operator=(const TextureInfo& that) {
39
0
    if (this != &that) {
40
0
        this->~TextureInfo();
41
0
        new (this) TextureInfo(that);
42
0
    }
43
0
    return *this;
44
0
}
45
46
0
bool TextureInfo::operator==(const TextureInfo& that) const {
47
0
    if (!this->isValid() && !that.isValid()) {
48
0
        return true;
49
0
    }
50
0
    if (!this->isValid() || !that.isValid()) {
51
0
        return false;
52
0
    }
53
54
0
    if (fBackend != that.fBackend) {
55
0
        return false;
56
0
    }
57
58
0
    if (fSampleCount != that.fSampleCount ||
59
0
        fMipmapped != that.fMipmapped ||
60
0
        fProtected != that.fProtected) {
61
0
        return false;
62
0
    }
63
0
    assert_is_supported_backend(fBackend);
64
0
    return fTextureInfoData->equal(that.fTextureInfoData.get());
65
0
}
66
67
0
bool TextureInfo::isCompatible(const TextureInfo& that) const {
68
0
    if (!this->isValid() || !that.isValid()) {
69
0
        return false;
70
0
    }
71
72
0
    if (fSampleCount != that.fSampleCount ||
73
0
        fMipmapped != that.fMipmapped ||
74
0
        fProtected != that.fProtected) {
75
0
        return false;
76
0
    }
77
78
0
    if (fBackend != that.fBackend) {
79
0
        return false;
80
0
    }
81
0
    assert_is_supported_backend(fBackend);
82
0
    return fTextureInfoData->isCompatible(that.fTextureInfoData.get());
83
0
}
84
85
0
SkString TextureInfo::toString() const {
86
0
    SkString ret;
87
0
    switch (fBackend) {
88
0
        case BackendApi::kDawn:
89
0
        case BackendApi::kMetal:
90
0
        case BackendApi::kVulkan:
91
0
            ret = fTextureInfoData->toString();
92
0
            break;
93
0
        case BackendApi::kMock:
94
0
            ret += "Mock(";
95
0
            break;
96
0
        default:
97
0
            ret += "Invalid(";
98
0
            break;
99
0
    }
100
0
    ret.appendf("bytesPerPixel=%zu,sampleCount=%u,mipmapped=%d,protected=%d)",
101
0
                this->bytesPerPixel(),
102
0
                fSampleCount,
103
0
                static_cast<int>(fMipmapped),
104
0
                static_cast<int>(fProtected));
105
0
    return ret;
106
0
}
107
108
0
SkString TextureInfo::toRPAttachmentString() const {
109
    // For renderpass attachments, the string will contain the view format and sample count only
110
0
    switch (fBackend) {
111
0
        case BackendApi::kDawn:
112
0
        case BackendApi::kMetal:
113
0
        case BackendApi::kVulkan:
114
0
            return fTextureInfoData->toRPAttachmentString(fSampleCount);
115
0
        case BackendApi::kMock:
116
0
            return SkStringPrintf("Mock(s=%u)", fSampleCount);
117
0
        default:
118
0
            return SkString("Invalid");
119
0
    }
120
0
}
121
122
0
size_t TextureInfo::bytesPerPixel() const {
123
0
    if (!this->isValid()) {
124
0
        return 0;
125
0
    }
126
127
0
    switch (fBackend) {
128
0
        case BackendApi::kDawn:
129
0
        case BackendApi::kMetal:
130
0
        case BackendApi::kVulkan:
131
0
            return fTextureInfoData->bytesPerPixel();
132
0
        default:
133
0
            return 0;
134
0
    }
135
0
}
136
137
0
SkTextureCompressionType TextureInfo::compressionType() const {
138
0
    if (!this->isValid()) {
139
0
        return SkTextureCompressionType::kNone;
140
0
    }
141
142
0
    switch (fBackend) {
143
0
        case BackendApi::kDawn:
144
0
        case BackendApi::kMetal:
145
0
        case BackendApi::kVulkan:
146
0
            return fTextureInfoData->compressionType();
147
0
        default:
148
0
            return SkTextureCompressionType::kNone;
149
0
    }
150
0
}
151
152
0
bool TextureInfo::isMemoryless() const {
153
0
    if (!this->isValid()) {
154
0
        return false;
155
0
    }
156
157
0
    switch (fBackend) {
158
0
        case BackendApi::kDawn:
159
0
        case BackendApi::kMetal:
160
0
        case BackendApi::kVulkan:
161
0
            return fTextureInfoData->isMemoryless();
162
0
        default:
163
0
            return false;
164
0
    }
165
0
}
166
167
0
TextureInfoData::~TextureInfoData(){};
168
169
} // namespace skgpu::graphite