/src/skia/src/gpu/ganesh/GrSurfaceCharacterization.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/private/chromium/GrSurfaceCharacterization.h" |
9 | | |
10 | | #include "include/core/SkColorSpace.h" |
11 | | #include "include/private/gpu/ganesh/GrTypesPriv.h" |
12 | | #include "src/gpu/ganesh/GrCaps.h" |
13 | | #include "src/gpu/ganesh/GrContextThreadSafeProxyPriv.h" |
14 | | |
15 | | #ifdef SK_DEBUG |
16 | 0 | void GrSurfaceCharacterization::validate() const { |
17 | 0 | const GrCaps* caps = fContextInfo->priv().caps(); |
18 | |
|
19 | 0 | GrColorType grCT = SkColorTypeToGrColorType(this->colorType()); |
20 | 0 | SkASSERT(fSampleCnt && caps->isFormatAsColorTypeRenderable(grCT, fBackendFormat, fSampleCnt)); |
21 | |
|
22 | 0 | SkASSERT(caps->areColorTypeAndFormatCompatible(grCT, fBackendFormat)); |
23 | |
|
24 | 0 | SkASSERT(skgpu::Mipmapped::kNo == fIsMipmapped || Textureable::kYes == fIsTextureable); |
25 | 0 | SkASSERT(Textureable::kNo == fIsTextureable || UsesGLFBO0::kNo == fUsesGLFBO0); |
26 | 0 | auto backend = fBackendFormat.backend(); |
27 | 0 | SkASSERT(UsesGLFBO0::kNo == fUsesGLFBO0 || backend == GrBackendApi::kOpenGL); |
28 | 0 | SkASSERT((VulkanSecondaryCBCompatible::kNo == fVulkanSecondaryCBCompatible && |
29 | 0 | VkRTSupportsInputAttachment::kNo == fVkRTSupportsInputAttachment) || |
30 | 0 | backend == GrBackendApi::kVulkan); |
31 | 0 | SkASSERT(VulkanSecondaryCBCompatible::kNo == fVulkanSecondaryCBCompatible || |
32 | 0 | VkRTSupportsInputAttachment::kNo == fVkRTSupportsInputAttachment); |
33 | 0 | SkASSERT(Textureable::kNo == fIsTextureable || |
34 | 0 | VulkanSecondaryCBCompatible::kNo == fVulkanSecondaryCBCompatible); |
35 | 0 | } |
36 | | #endif |
37 | | |
38 | | |
39 | 0 | bool GrSurfaceCharacterization::operator==(const GrSurfaceCharacterization& other) const { |
40 | 0 | if (!this->isValid() || !other.isValid()) { |
41 | 0 | return false; |
42 | 0 | } |
43 | | |
44 | 0 | if (fContextInfo != other.fContextInfo) { |
45 | 0 | return false; |
46 | 0 | } |
47 | | |
48 | 0 | return fCacheMaxResourceBytes == other.fCacheMaxResourceBytes && |
49 | 0 | fOrigin == other.fOrigin && |
50 | 0 | fImageInfo == other.fImageInfo && |
51 | 0 | fBackendFormat == other.fBackendFormat && |
52 | 0 | fSampleCnt == other.fSampleCnt && |
53 | 0 | fIsTextureable == other.fIsTextureable && |
54 | 0 | fIsMipmapped == other.fIsMipmapped && |
55 | 0 | fUsesGLFBO0 == other.fUsesGLFBO0 && |
56 | 0 | fVulkanSecondaryCBCompatible == other.fVulkanSecondaryCBCompatible && |
57 | 0 | fIsProtected == other.fIsProtected && |
58 | 0 | fSurfaceProps == other.fSurfaceProps; |
59 | 0 | } |
60 | | |
61 | 0 | GrSurfaceCharacterization GrSurfaceCharacterization::createResized(int width, int height) const { |
62 | 0 | const GrCaps* caps = fContextInfo->priv().caps(); |
63 | 0 | if (!caps) { |
64 | 0 | return GrSurfaceCharacterization(); |
65 | 0 | } |
66 | | |
67 | 0 | if (width <= 0 || height <= 0 || width > caps->maxRenderTargetSize() || |
68 | 0 | height > caps->maxRenderTargetSize()) { |
69 | 0 | return GrSurfaceCharacterization(); |
70 | 0 | } |
71 | | |
72 | 0 | return GrSurfaceCharacterization(fContextInfo, |
73 | 0 | fCacheMaxResourceBytes, |
74 | 0 | fImageInfo.makeWH(width, height), |
75 | 0 | fBackendFormat, |
76 | 0 | fOrigin, |
77 | 0 | fSampleCnt, |
78 | 0 | fIsTextureable, |
79 | 0 | fIsMipmapped, |
80 | 0 | fUsesGLFBO0, |
81 | 0 | fVkRTSupportsInputAttachment, |
82 | 0 | fVulkanSecondaryCBCompatible, |
83 | 0 | fIsProtected, |
84 | 0 | fSurfaceProps); |
85 | 0 | } |
86 | | |
87 | | GrSurfaceCharacterization GrSurfaceCharacterization::createColorSpace( |
88 | 0 | sk_sp<SkColorSpace> cs) const { |
89 | 0 | if (!this->isValid()) { |
90 | 0 | return GrSurfaceCharacterization(); |
91 | 0 | } |
92 | | |
93 | 0 | return GrSurfaceCharacterization(fContextInfo, |
94 | 0 | fCacheMaxResourceBytes, |
95 | 0 | fImageInfo.makeColorSpace(std::move(cs)), |
96 | 0 | fBackendFormat, |
97 | 0 | fOrigin, |
98 | 0 | fSampleCnt, |
99 | 0 | fIsTextureable, |
100 | 0 | fIsMipmapped, |
101 | 0 | fUsesGLFBO0, |
102 | 0 | fVkRTSupportsInputAttachment, |
103 | 0 | fVulkanSecondaryCBCompatible, |
104 | 0 | fIsProtected, |
105 | 0 | fSurfaceProps); |
106 | 0 | } |
107 | | |
108 | | GrSurfaceCharacterization GrSurfaceCharacterization::createBackendFormat( |
109 | | SkColorType colorType, |
110 | 0 | const GrBackendFormat& backendFormat) const { |
111 | 0 | if (!this->isValid()) { |
112 | 0 | return GrSurfaceCharacterization(); |
113 | 0 | } |
114 | | |
115 | 0 | SkImageInfo newII = fImageInfo.makeColorType(colorType); |
116 | |
|
117 | 0 | return GrSurfaceCharacterization(fContextInfo, |
118 | 0 | fCacheMaxResourceBytes, |
119 | 0 | newII, |
120 | 0 | backendFormat, |
121 | 0 | fOrigin, |
122 | 0 | fSampleCnt, |
123 | 0 | fIsTextureable, |
124 | 0 | fIsMipmapped, |
125 | 0 | fUsesGLFBO0, |
126 | 0 | fVkRTSupportsInputAttachment, |
127 | 0 | fVulkanSecondaryCBCompatible, |
128 | 0 | fIsProtected, |
129 | 0 | fSurfaceProps); |
130 | 0 | } |
131 | | |
132 | 0 | GrSurfaceCharacterization GrSurfaceCharacterization::createFBO0(bool usesGLFBO0) const { |
133 | 0 | if (!this->isValid()) { |
134 | 0 | return GrSurfaceCharacterization(); |
135 | 0 | } |
136 | | |
137 | | // We can't create an FBO0 characterization that is textureable or has any non-gl specific flags |
138 | 0 | if (fIsTextureable == Textureable::kYes || |
139 | 0 | fVkRTSupportsInputAttachment == VkRTSupportsInputAttachment::kYes || |
140 | 0 | fVulkanSecondaryCBCompatible == VulkanSecondaryCBCompatible::kYes) { |
141 | 0 | return GrSurfaceCharacterization(); |
142 | 0 | } |
143 | | |
144 | 0 | return GrSurfaceCharacterization(fContextInfo, |
145 | 0 | fCacheMaxResourceBytes, |
146 | 0 | fImageInfo, |
147 | 0 | fBackendFormat, |
148 | 0 | fOrigin, |
149 | 0 | fSampleCnt, |
150 | 0 | fIsTextureable, |
151 | 0 | fIsMipmapped, |
152 | 0 | usesGLFBO0 ? UsesGLFBO0::kYes : UsesGLFBO0::kNo, |
153 | 0 | fVkRTSupportsInputAttachment, |
154 | 0 | fVulkanSecondaryCBCompatible, |
155 | 0 | fIsProtected, |
156 | 0 | fSurfaceProps); |
157 | 0 | } |