/src/mozilla-central/gfx/skia/skia/src/gpu/GrCaps.cpp
Line | Count | Source (jump to first uncovered line) |
1 | | /* |
2 | | * Copyright 2015 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 "GrCaps.h" |
9 | | |
10 | | #include "GrBackendSurface.h" |
11 | | #include "GrContextOptions.h" |
12 | | #include "GrWindowRectangles.h" |
13 | | #include "SkJSONWriter.h" |
14 | | |
15 | 0 | static const char* pixel_config_name(GrPixelConfig config) { |
16 | 0 | switch (config) { |
17 | 0 | case kUnknown_GrPixelConfig: return "Unknown"; |
18 | 0 | case kAlpha_8_GrPixelConfig: return "Alpha8"; |
19 | 0 | case kAlpha_8_as_Alpha_GrPixelConfig: return "Alpha8_asAlpha"; |
20 | 0 | case kAlpha_8_as_Red_GrPixelConfig: return "Alpha8_asRed"; |
21 | 0 | case kGray_8_GrPixelConfig: return "Gray8"; |
22 | 0 | case kGray_8_as_Lum_GrPixelConfig: return "Gray8_asLum"; |
23 | 0 | case kGray_8_as_Red_GrPixelConfig: return "Gray8_asRed"; |
24 | 0 | case kRGB_565_GrPixelConfig: return "RGB565"; |
25 | 0 | case kRGBA_4444_GrPixelConfig: return "RGBA444"; |
26 | 0 | case kRGBA_8888_GrPixelConfig: return "RGBA8888"; |
27 | 0 | case kBGRA_8888_GrPixelConfig: return "BGRA8888"; |
28 | 0 | case kSRGBA_8888_GrPixelConfig: return "SRGBA8888"; |
29 | 0 | case kSBGRA_8888_GrPixelConfig: return "SBGRA8888"; |
30 | 0 | case kRGBA_float_GrPixelConfig: return "RGBAFloat"; |
31 | 0 | case kRG_float_GrPixelConfig: return "RGFloat"; |
32 | 0 | case kAlpha_half_GrPixelConfig: return "AlphaHalf"; |
33 | 0 | case kAlpha_half_as_Red_GrPixelConfig: return "AlphaHalf_asRed"; |
34 | 0 | case kRGBA_half_GrPixelConfig: return "RGBAHalf"; |
35 | 0 | } |
36 | 0 | SK_ABORT("Invalid pixel config"); |
37 | 0 | return "<invalid>"; |
38 | 0 | } |
39 | | |
40 | 0 | GrCaps::GrCaps(const GrContextOptions& options) { |
41 | 0 | fMipMapSupport = false; |
42 | 0 | fNPOTTextureTileSupport = false; |
43 | 0 | fSRGBSupport = false; |
44 | 0 | fSRGBWriteControl = false; |
45 | 0 | fSRGBDecodeDisableSupport = false; |
46 | 0 | fDiscardRenderTargetSupport = false; |
47 | 0 | fReuseScratchTextures = true; |
48 | 0 | fReuseScratchBuffers = true; |
49 | 0 | fGpuTracingSupport = false; |
50 | 0 | fOversizedStencilSupport = false; |
51 | 0 | fTextureBarrierSupport = false; |
52 | 0 | fSampleLocationsSupport = false; |
53 | 0 | fMultisampleDisableSupport = false; |
54 | 0 | fInstanceAttribSupport = false; |
55 | 0 | fUsesMixedSamples = false; |
56 | 0 | fUsePrimitiveRestart = false; |
57 | 0 | fPreferClientSideDynamicBuffers = false; |
58 | 0 | fPreferFullscreenClears = false; |
59 | 0 | fMustClearUploadedBufferData = false; |
60 | 0 | fSampleShadingSupport = false; |
61 | 0 | fFenceSyncSupport = false; |
62 | 0 | fCrossContextTextureSupport = false; |
63 | 0 |
|
64 | 0 | fBlendEquationSupport = kBasic_BlendEquationSupport; |
65 | 0 | fAdvBlendEqBlacklist = 0; |
66 | 0 |
|
67 | 0 | fMapBufferFlags = kNone_MapFlags; |
68 | 0 |
|
69 | 0 | fMaxVertexAttributes = 0; |
70 | 0 | fMaxRenderTargetSize = 1; |
71 | 0 | fMaxPreferredRenderTargetSize = 1; |
72 | 0 | fMaxTextureSize = 1; |
73 | 0 | fMaxRasterSamples = 0; |
74 | 0 | fMaxWindowRectangles = 0; |
75 | 0 |
|
76 | 0 | // An default count of 4 was chosen because of the common pattern in Blink of: |
77 | 0 | // isect RR |
78 | 0 | // diff RR |
79 | 0 | // isect convex_poly |
80 | 0 | // isect convex_poly |
81 | 0 | // when drawing rounded div borders. |
82 | 0 | fMaxClipAnalyticFPs = 4; |
83 | 0 |
|
84 | 0 | fSuppressPrints = options.fSuppressPrints; |
85 | | #if GR_TEST_UTILS |
86 | | fWireframeMode = options.fWireframeMode; |
87 | | #else |
88 | | fWireframeMode = false; |
89 | 0 | #endif |
90 | 0 | fBufferMapThreshold = options.fBufferMapThreshold; |
91 | 0 | fBlacklistCoverageCounting = false; |
92 | 0 | fAvoidStencilBuffers = false; |
93 | 0 |
|
94 | 0 | fPreferVRAMUseOverFlushes = true; |
95 | 0 | } |
96 | | |
97 | 0 | void GrCaps::applyOptionsOverrides(const GrContextOptions& options) { |
98 | 0 | this->onApplyOptionsOverrides(options); |
99 | 0 | if (options.fDisableDriverCorrectnessWorkarounds) { |
100 | 0 | // We always blacklist coverage counting on Vulkan currently. TODO: Either stop doing that |
101 | 0 | // or disambiguate blacklisting from incomplete implementation. |
102 | 0 | // SkASSERT(!fBlacklistCoverageCounting); |
103 | 0 | SkASSERT(!fAvoidStencilBuffers); |
104 | 0 | SkASSERT(!fAdvBlendEqBlacklist); |
105 | 0 | } |
106 | 0 |
|
107 | 0 | fMaxTextureSize = SkTMin(fMaxTextureSize, options.fMaxTextureSizeOverride); |
108 | 0 | fMaxTileSize = fMaxTextureSize; |
109 | | #if GR_TEST_UTILS |
110 | | // If the max tile override is zero, it means we should use the max texture size. |
111 | | if (options.fMaxTileSizeOverride && options.fMaxTileSizeOverride < fMaxTextureSize) { |
112 | | fMaxTileSize = options.fMaxTileSizeOverride; |
113 | | } |
114 | | if (options.fSuppressGeometryShaders) { |
115 | | fShaderCaps->fGeometryShaderSupport = false; |
116 | | } |
117 | | #endif |
118 | 0 | if (fMaxWindowRectangles > GrWindowRectangles::kMaxWindows) { |
119 | 0 | SkDebugf("WARNING: capping window rectangles at %i. HW advertises support for %i.\n", |
120 | 0 | GrWindowRectangles::kMaxWindows, fMaxWindowRectangles); |
121 | 0 | fMaxWindowRectangles = GrWindowRectangles::kMaxWindows; |
122 | 0 | } |
123 | 0 | fAvoidStencilBuffers = options.fAvoidStencilBuffers; |
124 | 0 | } |
125 | | |
126 | 0 | static SkString map_flags_to_string(uint32_t flags) { |
127 | 0 | SkString str; |
128 | 0 | if (GrCaps::kNone_MapFlags == flags) { |
129 | 0 | str = "none"; |
130 | 0 | } else { |
131 | 0 | SkASSERT(GrCaps::kCanMap_MapFlag & flags); |
132 | 0 | SkDEBUGCODE(flags &= ~GrCaps::kCanMap_MapFlag); |
133 | 0 | str = "can_map"; |
134 | 0 |
|
135 | 0 | if (GrCaps::kSubset_MapFlag & flags) { |
136 | 0 | str.append(" partial"); |
137 | 0 | } else { |
138 | 0 | str.append(" full"); |
139 | 0 | } |
140 | 0 | SkDEBUGCODE(flags &= ~GrCaps::kSubset_MapFlag); |
141 | 0 | } |
142 | 0 | SkASSERT(0 == flags); // Make sure we handled all the flags. |
143 | 0 | return str; |
144 | 0 | } |
145 | | |
146 | 0 | void GrCaps::dumpJSON(SkJSONWriter* writer) const { |
147 | 0 | writer->beginObject(); |
148 | 0 |
|
149 | 0 | writer->appendBool("MIP Map Support", fMipMapSupport); |
150 | 0 | writer->appendBool("NPOT Texture Tile Support", fNPOTTextureTileSupport); |
151 | 0 | writer->appendBool("sRGB Support", fSRGBSupport); |
152 | 0 | writer->appendBool("sRGB Write Control", fSRGBWriteControl); |
153 | 0 | writer->appendBool("sRGB Decode Disable", fSRGBDecodeDisableSupport); |
154 | 0 | writer->appendBool("Discard Render Target Support", fDiscardRenderTargetSupport); |
155 | 0 | writer->appendBool("Reuse Scratch Textures", fReuseScratchTextures); |
156 | 0 | writer->appendBool("Reuse Scratch Buffers", fReuseScratchBuffers); |
157 | 0 | writer->appendBool("Gpu Tracing Support", fGpuTracingSupport); |
158 | 0 | writer->appendBool("Oversized Stencil Support", fOversizedStencilSupport); |
159 | 0 | writer->appendBool("Texture Barrier Support", fTextureBarrierSupport); |
160 | 0 | writer->appendBool("Sample Locations Support", fSampleLocationsSupport); |
161 | 0 | writer->appendBool("Multisample disable support", fMultisampleDisableSupport); |
162 | 0 | writer->appendBool("Instance Attrib Support", fInstanceAttribSupport); |
163 | 0 | writer->appendBool("Uses Mixed Samples", fUsesMixedSamples); |
164 | 0 | writer->appendBool("Use primitive restart", fUsePrimitiveRestart); |
165 | 0 | writer->appendBool("Prefer client-side dynamic buffers", fPreferClientSideDynamicBuffers); |
166 | 0 | writer->appendBool("Prefer fullscreen clears", fPreferFullscreenClears); |
167 | 0 | writer->appendBool("Must clear buffer memory", fMustClearUploadedBufferData); |
168 | 0 | writer->appendBool("Sample shading support", fSampleShadingSupport); |
169 | 0 | writer->appendBool("Fence sync support", fFenceSyncSupport); |
170 | 0 | writer->appendBool("Cross context texture support", fCrossContextTextureSupport); |
171 | 0 |
|
172 | 0 | writer->appendBool("Blacklist Coverage Counting Path Renderer [workaround]", |
173 | 0 | fBlacklistCoverageCounting); |
174 | 0 | writer->appendBool("Prefer VRAM Use over flushes [workaround]", fPreferVRAMUseOverFlushes); |
175 | 0 |
|
176 | 0 | if (this->advancedBlendEquationSupport()) { |
177 | 0 | writer->appendHexU32("Advanced Blend Equation Blacklist", fAdvBlendEqBlacklist); |
178 | 0 | } |
179 | 0 |
|
180 | 0 | writer->appendS32("Max Vertex Attributes", fMaxVertexAttributes); |
181 | 0 | writer->appendS32("Max Texture Size", fMaxTextureSize); |
182 | 0 | writer->appendS32("Max Render Target Size", fMaxRenderTargetSize); |
183 | 0 | writer->appendS32("Max Preferred Render Target Size", fMaxPreferredRenderTargetSize); |
184 | 0 | writer->appendS32("Max Raster Samples", fMaxRasterSamples); |
185 | 0 | writer->appendS32("Max Window Rectangles", fMaxWindowRectangles); |
186 | 0 | writer->appendS32("Max Clip Analytic Fragment Processors", fMaxClipAnalyticFPs); |
187 | 0 |
|
188 | 0 | static const char* kBlendEquationSupportNames[] = { |
189 | 0 | "Basic", |
190 | 0 | "Advanced", |
191 | 0 | "Advanced Coherent", |
192 | 0 | }; |
193 | 0 | GR_STATIC_ASSERT(0 == kBasic_BlendEquationSupport); |
194 | 0 | GR_STATIC_ASSERT(1 == kAdvanced_BlendEquationSupport); |
195 | 0 | GR_STATIC_ASSERT(2 == kAdvancedCoherent_BlendEquationSupport); |
196 | 0 | GR_STATIC_ASSERT(SK_ARRAY_COUNT(kBlendEquationSupportNames) == kLast_BlendEquationSupport + 1); |
197 | 0 |
|
198 | 0 | writer->appendString("Blend Equation Support", |
199 | 0 | kBlendEquationSupportNames[fBlendEquationSupport]); |
200 | 0 | writer->appendString("Map Buffer Support", map_flags_to_string(fMapBufferFlags).c_str()); |
201 | 0 |
|
202 | 0 | SkASSERT(!this->isConfigRenderable(kUnknown_GrPixelConfig)); |
203 | 0 | SkASSERT(!this->isConfigTexturable(kUnknown_GrPixelConfig)); |
204 | 0 |
|
205 | 0 | writer->beginArray("configs"); |
206 | 0 |
|
207 | 0 | for (size_t i = 1; i < kGrPixelConfigCnt; ++i) { |
208 | 0 | GrPixelConfig config = static_cast<GrPixelConfig>(i); |
209 | 0 | writer->beginObject(nullptr, false); |
210 | 0 | writer->appendString("name", pixel_config_name(config)); |
211 | 0 | writer->appendS32("max sample count", this->maxRenderTargetSampleCount(config)); |
212 | 0 | writer->appendBool("texturable", this->isConfigTexturable(config)); |
213 | 0 | writer->endObject(); |
214 | 0 | } |
215 | 0 |
|
216 | 0 | writer->endArray(); |
217 | 0 |
|
218 | 0 | this->onDumpJSON(writer); |
219 | 0 |
|
220 | 0 | writer->appendName("shaderCaps"); |
221 | 0 | this->shaderCaps()->dumpJSON(writer); |
222 | 0 |
|
223 | 0 | writer->endObject(); |
224 | 0 | } |
225 | | |
226 | 0 | bool GrCaps::validateSurfaceDesc(const GrSurfaceDesc& desc, GrMipMapped mipped) const { |
227 | 0 | if (!this->isConfigTexturable(desc.fConfig)) { |
228 | 0 | return false; |
229 | 0 | } |
230 | 0 | |
231 | 0 | if (GrMipMapped::kYes == mipped && !this->mipMapSupport()) { |
232 | 0 | return false; |
233 | 0 | } |
234 | 0 | |
235 | 0 | if (desc.fWidth < 1 || desc.fHeight < 1) { |
236 | 0 | return false; |
237 | 0 | } |
238 | 0 | |
239 | 0 | if (SkToBool(desc.fFlags & kRenderTarget_GrSurfaceFlag)) { |
240 | 0 | if (0 == this->getRenderTargetSampleCount(desc.fSampleCnt, desc.fConfig)) { |
241 | 0 | return false; |
242 | 0 | } |
243 | 0 | int maxRTSize = this->maxRenderTargetSize(); |
244 | 0 | if (desc.fWidth > maxRTSize || desc.fHeight > maxRTSize) { |
245 | 0 | return false; |
246 | 0 | } |
247 | 0 | } else { |
248 | 0 | // We currently do not support multisampled textures |
249 | 0 | if (desc.fSampleCnt > 1) { |
250 | 0 | return false; |
251 | 0 | } |
252 | 0 | int maxSize = this->maxTextureSize(); |
253 | 0 | if (desc.fWidth > maxSize || desc.fHeight > maxSize) { |
254 | 0 | return false; |
255 | 0 | } |
256 | 0 | } |
257 | 0 | |
258 | 0 | return true; |
259 | 0 | } |