Coverage Report

Created: 2021-08-22 09:07

/src/skia/src/core/SkSurfaceCharacterization.cpp
Line
Count
Source (jump to first uncovered line)
1
/*
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
#include "include/core/SkSurfaceCharacterization.h"
9
10
#if SK_SUPPORT_GPU
11
#include "src/gpu/GrCaps.h"
12
#include "src/gpu/GrContextThreadSafeProxyPriv.h"
13
14
#ifdef SK_VULKAN
15
#include "include/gpu/vk/GrVkTypes.h"
16
#endif
17
18
#ifdef SK_DEBUG
19
0
void SkSurfaceCharacterization::validate() const {
20
0
    const GrCaps* caps = fContextInfo->priv().caps();
21
22
0
    GrColorType grCT = SkColorTypeToGrColorType(this->colorType());
23
0
    SkASSERT(fSampleCnt && caps->isFormatAsColorTypeRenderable(grCT, fBackendFormat, fSampleCnt));
24
25
0
    SkASSERT(caps->areColorTypeAndFormatCompatible(grCT, fBackendFormat));
26
27
0
    SkASSERT(MipMapped::kNo == fIsMipMapped || Textureable::kYes == fIsTextureable);
28
0
    SkASSERT(Textureable::kNo == fIsTextureable || UsesGLFBO0::kNo == fUsesGLFBO0);
29
0
    auto backend = fBackendFormat.backend();
30
0
    SkASSERT(UsesGLFBO0::kNo == fUsesGLFBO0 || backend == GrBackendApi::kOpenGL);
31
0
    SkASSERT((VulkanSecondaryCBCompatible::kNo == fVulkanSecondaryCBCompatible &&
32
0
              VkRTSupportsInputAttachment::kNo == fVkRTSupportsInputAttachment) ||
33
0
             backend == GrBackendApi::kVulkan);
34
0
    SkASSERT(VulkanSecondaryCBCompatible::kNo == fVulkanSecondaryCBCompatible ||
35
0
             VkRTSupportsInputAttachment::kNo == fVkRTSupportsInputAttachment);
36
0
    SkASSERT(Textureable::kNo == fIsTextureable ||
37
0
             VulkanSecondaryCBCompatible::kNo == fVulkanSecondaryCBCompatible);
38
0
}
39
#endif
40
41
42
0
bool SkSurfaceCharacterization::operator==(const SkSurfaceCharacterization& other) const {
43
0
    if (!this->isValid() || !other.isValid()) {
44
0
        return false;
45
0
    }
46
47
0
    if (fContextInfo != other.fContextInfo) {
48
0
        return false;
49
0
    }
50
51
0
    return fCacheMaxResourceBytes == other.fCacheMaxResourceBytes &&
52
0
           fOrigin == other.fOrigin &&
53
0
           fImageInfo == other.fImageInfo &&
54
0
           fBackendFormat == other.fBackendFormat &&
55
0
           fSampleCnt == other.fSampleCnt &&
56
0
           fIsTextureable == other.fIsTextureable &&
57
0
           fIsMipMapped == other.fIsMipMapped &&
58
0
           fUsesGLFBO0 == other.fUsesGLFBO0 &&
59
0
           fVulkanSecondaryCBCompatible == other.fVulkanSecondaryCBCompatible &&
60
0
           fIsProtected == other.fIsProtected &&
61
0
           fSurfaceProps == other.fSurfaceProps;
62
0
}
63
64
0
SkSurfaceCharacterization SkSurfaceCharacterization::createResized(int width, int height) const {
65
0
    const GrCaps* caps = fContextInfo->priv().caps();
66
0
    if (!caps) {
67
0
        return SkSurfaceCharacterization();
68
0
    }
69
70
0
    if (width <= 0 || height <= 0 || width > caps->maxRenderTargetSize() ||
71
0
        height > caps->maxRenderTargetSize()) {
72
0
        return SkSurfaceCharacterization();
73
0
    }
74
75
0
    return SkSurfaceCharacterization(fContextInfo, fCacheMaxResourceBytes,
76
0
                                     fImageInfo.makeWH(width, height), fBackendFormat, fOrigin,
77
0
                                     fSampleCnt, fIsTextureable, fIsMipMapped, fUsesGLFBO0,
78
0
                                     fVkRTSupportsInputAttachment,
79
0
                                     fVulkanSecondaryCBCompatible,
80
0
                                     fIsProtected, fSurfaceProps);
81
0
}
82
83
SkSurfaceCharacterization SkSurfaceCharacterization::createColorSpace(
84
0
                                                                     sk_sp<SkColorSpace> cs) const {
85
0
    if (!this->isValid()) {
86
0
        return SkSurfaceCharacterization();
87
0
    }
88
89
0
    return SkSurfaceCharacterization(fContextInfo, fCacheMaxResourceBytes,
90
0
                                     fImageInfo.makeColorSpace(std::move(cs)), fBackendFormat,
91
0
                                     fOrigin, fSampleCnt, fIsTextureable, fIsMipMapped, fUsesGLFBO0,
92
0
                                     fVkRTSupportsInputAttachment,
93
0
                                     fVulkanSecondaryCBCompatible, fIsProtected, fSurfaceProps);
94
0
}
95
96
SkSurfaceCharacterization SkSurfaceCharacterization::createBackendFormat(
97
                                                    SkColorType colorType,
98
0
                                                    const GrBackendFormat& backendFormat) const {
99
0
    if (!this->isValid()) {
100
0
        return SkSurfaceCharacterization();
101
0
    }
102
103
0
    SkImageInfo newII = fImageInfo.makeColorType(colorType);
104
105
0
    return SkSurfaceCharacterization(fContextInfo, fCacheMaxResourceBytes, newII, backendFormat,
106
0
                                     fOrigin, fSampleCnt, fIsTextureable, fIsMipMapped, fUsesGLFBO0,
107
0
                                     fVkRTSupportsInputAttachment,
108
0
                                     fVulkanSecondaryCBCompatible, fIsProtected, fSurfaceProps);
109
0
}
110
111
0
SkSurfaceCharacterization SkSurfaceCharacterization::createFBO0(bool usesGLFBO0) const {
112
0
    if (!this->isValid()) {
113
0
        return SkSurfaceCharacterization();
114
0
    }
115
116
    // We can't create an FBO0 characterization that is textureable or has any non-gl specific flags
117
0
    if (fIsTextureable == Textureable::kYes ||
118
0
        fVkRTSupportsInputAttachment == VkRTSupportsInputAttachment::kYes ||
119
0
        fVulkanSecondaryCBCompatible == VulkanSecondaryCBCompatible::kYes) {
120
0
        return SkSurfaceCharacterization();
121
0
    }
122
123
0
    return SkSurfaceCharacterization(fContextInfo, fCacheMaxResourceBytes,
124
0
                                     fImageInfo, fBackendFormat,
125
0
                                     fOrigin, fSampleCnt, fIsTextureable, fIsMipMapped,
126
0
                                     usesGLFBO0 ? UsesGLFBO0::kYes : UsesGLFBO0::kNo,
127
0
                                     fVkRTSupportsInputAttachment,
128
0
                                     fVulkanSecondaryCBCompatible, fIsProtected, fSurfaceProps);
129
0
}
130
131
0
bool SkSurfaceCharacterization::isCompatible(const GrBackendTexture& backendTex) const {
132
0
    if (!this->isValid() || !backendTex.isValid()) {
133
0
        return false;
134
0
    }
135
136
0
    if (fBackendFormat != backendTex.getBackendFormat()) {
137
0
        return false;
138
0
    }
139
140
0
    if (this->usesGLFBO0()) {
141
        // It is a backend texture so can't be wrapping FBO0
142
0
        return false;
143
0
    }
144
145
0
    if (this->vulkanSecondaryCBCompatible()) {
146
0
        return false;
147
0
    }
148
149
0
    if (this->vkRTSupportsInputAttachment()) {
150
0
        if (backendTex.backend() != GrBackendApi::kVulkan) {
151
0
            return false;
152
0
        }
153
#ifdef SK_VULKAN
154
        GrVkImageInfo vkInfo;
155
        if (!backendTex.getVkImageInfo(&vkInfo)) {
156
            return false;
157
        }
158
        if (!SkToBool(vkInfo.fImageUsageFlags & VK_IMAGE_USAGE_INPUT_ATTACHMENT_BIT)) {
159
            return false;
160
        }
161
#endif  // SK_VULKAN
162
0
    }
163
164
0
    if (this->isMipMapped() && !backendTex.hasMipmaps()) {
165
        // backend texture is allowed to have mipmaps even if the characterization doesn't require
166
        // them.
167
0
        return false;
168
0
    }
169
170
0
    if (this->width() != backendTex.width() || this->height() != backendTex.height()) {
171
0
        return false;
172
0
    }
173
174
0
    if (this->isProtected() != GrProtected(backendTex.isProtected())) {
175
0
        return false;
176
0
    }
177
178
0
    return true;
179
0
}
180
181
182
#endif