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 #include "GrContextOptions.h"
10 #include "GrWindowRectangles.h"
11
pixel_config_name(GrPixelConfig config)12 static const char* pixel_config_name(GrPixelConfig config) {
13 switch (config) {
14 case kUnknown_GrPixelConfig: return "Unknown";
15 case kAlpha_8_GrPixelConfig: return "Alpha8";
16 case kGray_8_GrPixelConfig: return "Gray8";
17 case kRGB_565_GrPixelConfig: return "RGB565";
18 case kRGBA_4444_GrPixelConfig: return "RGBA444";
19 case kRGBA_8888_GrPixelConfig: return "RGBA8888";
20 case kBGRA_8888_GrPixelConfig: return "BGRA8888";
21 case kSRGBA_8888_GrPixelConfig: return "SRGBA8888";
22 case kSBGRA_8888_GrPixelConfig: return "SBGRA8888";
23 case kRGBA_8888_sint_GrPixelConfig: return "RGBA8888_sint";
24 case kRGBA_float_GrPixelConfig: return "RGBAFloat";
25 case kRG_float_GrPixelConfig: return "RGFloat";
26 case kAlpha_half_GrPixelConfig: return "AlphaHalf";
27 case kRGBA_half_GrPixelConfig: return "RGBAHalf";
28 }
29 SkFAIL("Invalid pixel config");
30 return "<invalid>";
31 }
32
GrCaps(const GrContextOptions & options)33 GrCaps::GrCaps(const GrContextOptions& options) {
34 fMipMapSupport = false;
35 fNPOTTextureTileSupport = false;
36 fSRGBSupport = false;
37 fSRGBWriteControl = false;
38 fDiscardRenderTargetSupport = false;
39 fReuseScratchTextures = true;
40 fReuseScratchBuffers = true;
41 fGpuTracingSupport = false;
42 fOversizedStencilSupport = false;
43 fTextureBarrierSupport = false;
44 fSampleLocationsSupport = false;
45 fMultisampleDisableSupport = false;
46 fInstanceAttribSupport = false;
47 fUsesMixedSamples = false;
48 fPreferClientSideDynamicBuffers = false;
49 fFullClearIsFree = false;
50 fMustClearUploadedBufferData = false;
51 fSampleShadingSupport = false;
52 fFenceSyncSupport = false;
53 fCrossContextTextureSupport = false;
54
55 fUseDrawInsteadOfClear = false;
56
57 fInstancedSupport = InstancedSupport::kNone;
58
59 fBlendEquationSupport = kBasic_BlendEquationSupport;
60 fAdvBlendEqBlacklist = 0;
61
62 fMapBufferFlags = kNone_MapFlags;
63
64 fMaxVertexAttributes = 0;
65 fMaxRenderTargetSize = 1;
66 fMaxTextureSize = 1;
67 fMaxColorSampleCount = 0;
68 fMaxStencilSampleCount = 0;
69 fMaxRasterSamples = 0;
70 fMaxWindowRectangles = 0;
71
72 fSuppressPrints = options.fSuppressPrints;
73 fWireframeMode = options.fWireframeMode;
74 fBufferMapThreshold = options.fBufferMapThreshold;
75 fAvoidInstancedDrawsToFPTargets = false;
76 fAvoidStencilBuffers = false;
77
78 fPreferVRAMUseOverFlushes = true;
79 }
80
applyOptionsOverrides(const GrContextOptions & options)81 void GrCaps::applyOptionsOverrides(const GrContextOptions& options) {
82 this->onApplyOptionsOverrides(options);
83 fMaxTextureSize = SkTMin(fMaxTextureSize, options.fMaxTextureSizeOverride);
84 // If the max tile override is zero, it means we should use the max texture size.
85 if (!options.fMaxTileSizeOverride || options.fMaxTileSizeOverride > fMaxTextureSize) {
86 fMaxTileSize = fMaxTextureSize;
87 } else {
88 fMaxTileSize = options.fMaxTileSizeOverride;
89 }
90 if (fMaxWindowRectangles > GrWindowRectangles::kMaxWindows) {
91 SkDebugf("WARNING: capping window rectangles at %i. HW advertises support for %i.\n",
92 GrWindowRectangles::kMaxWindows, fMaxWindowRectangles);
93 fMaxWindowRectangles = GrWindowRectangles::kMaxWindows;
94 }
95 fAvoidStencilBuffers = options.fAvoidStencilBuffers;
96 }
97
map_flags_to_string(uint32_t flags)98 static SkString map_flags_to_string(uint32_t flags) {
99 SkString str;
100 if (GrCaps::kNone_MapFlags == flags) {
101 str = "none";
102 } else {
103 SkASSERT(GrCaps::kCanMap_MapFlag & flags);
104 SkDEBUGCODE(flags &= ~GrCaps::kCanMap_MapFlag);
105 str = "can_map";
106
107 if (GrCaps::kSubset_MapFlag & flags) {
108 str.append(" partial");
109 } else {
110 str.append(" full");
111 }
112 SkDEBUGCODE(flags &= ~GrCaps::kSubset_MapFlag);
113 }
114 SkASSERT(0 == flags); // Make sure we handled all the flags.
115 return str;
116 }
117
dump() const118 SkString GrCaps::dump() const {
119 SkString r;
120 static const char* gNY[] = {"NO", "YES"};
121 r.appendf("MIP Map Support : %s\n", gNY[fMipMapSupport]);
122 r.appendf("NPOT Texture Tile Support : %s\n", gNY[fNPOTTextureTileSupport]);
123 r.appendf("sRGB Support : %s\n", gNY[fSRGBSupport]);
124 r.appendf("sRGB Write Control : %s\n", gNY[fSRGBWriteControl]);
125 r.appendf("Discard Render Target Support : %s\n", gNY[fDiscardRenderTargetSupport]);
126 r.appendf("Reuse Scratch Textures : %s\n", gNY[fReuseScratchTextures]);
127 r.appendf("Reuse Scratch Buffers : %s\n", gNY[fReuseScratchBuffers]);
128 r.appendf("Gpu Tracing Support : %s\n", gNY[fGpuTracingSupport]);
129 r.appendf("Oversized Stencil Support : %s\n", gNY[fOversizedStencilSupport]);
130 r.appendf("Texture Barrier Support : %s\n", gNY[fTextureBarrierSupport]);
131 r.appendf("Sample Locations Support : %s\n", gNY[fSampleLocationsSupport]);
132 r.appendf("Multisample disable support : %s\n", gNY[fMultisampleDisableSupport]);
133 r.appendf("Instance Attrib Support : %s\n", gNY[fInstanceAttribSupport]);
134 r.appendf("Uses Mixed Samples : %s\n", gNY[fUsesMixedSamples]);
135 r.appendf("Prefer client-side dynamic buffers : %s\n", gNY[fPreferClientSideDynamicBuffers]);
136 r.appendf("Full screen clear is free : %s\n", gNY[fFullClearIsFree]);
137 r.appendf("Must clear buffer memory : %s\n", gNY[fMustClearUploadedBufferData]);
138 r.appendf("Sample shading support : %s\n", gNY[fSampleShadingSupport]);
139 r.appendf("Fence sync support : %s\n", gNY[fFenceSyncSupport]);
140 r.appendf("Cross context texture support : %s\n", gNY[fCrossContextTextureSupport]);
141
142 r.appendf("Draw Instead of Clear [workaround] : %s\n", gNY[fUseDrawInsteadOfClear]);
143 r.appendf("Prefer VRAM Use over flushes [workaround] : %s\n", gNY[fPreferVRAMUseOverFlushes]);
144
145 if (this->advancedBlendEquationSupport()) {
146 r.appendf("Advanced Blend Equation Blacklist : 0x%x\n", fAdvBlendEqBlacklist);
147 }
148
149 r.appendf("Max Vertex Attributes : %d\n", fMaxVertexAttributes);
150 r.appendf("Max Texture Size : %d\n", fMaxTextureSize);
151 r.appendf("Max Render Target Size : %d\n", fMaxRenderTargetSize);
152 r.appendf("Max Color Sample Count : %d\n", fMaxColorSampleCount);
153 r.appendf("Max Stencil Sample Count : %d\n", fMaxStencilSampleCount);
154 r.appendf("Max Raster Samples : %d\n", fMaxRasterSamples);
155 r.appendf("Max Window Rectangles : %d\n", fMaxWindowRectangles);
156
157 static const char* kInstancedSupportNames[] = {
158 "None",
159 "Basic",
160 "Multisampled",
161 "Mixed Sampled",
162 };
163 GR_STATIC_ASSERT(0 == (int)InstancedSupport::kNone);
164 GR_STATIC_ASSERT(1 == (int)InstancedSupport::kBasic);
165 GR_STATIC_ASSERT(2 == (int)InstancedSupport::kMultisampled);
166 GR_STATIC_ASSERT(3 == (int)InstancedSupport::kMixedSampled);
167 GR_STATIC_ASSERT(4 == SK_ARRAY_COUNT(kInstancedSupportNames));
168
169 r.appendf("Instanced Support : %s\n",
170 kInstancedSupportNames[(int)fInstancedSupport]);
171
172 static const char* kBlendEquationSupportNames[] = {
173 "Basic",
174 "Advanced",
175 "Advanced Coherent",
176 };
177 GR_STATIC_ASSERT(0 == kBasic_BlendEquationSupport);
178 GR_STATIC_ASSERT(1 == kAdvanced_BlendEquationSupport);
179 GR_STATIC_ASSERT(2 == kAdvancedCoherent_BlendEquationSupport);
180 GR_STATIC_ASSERT(SK_ARRAY_COUNT(kBlendEquationSupportNames) == kLast_BlendEquationSupport + 1);
181
182 r.appendf("Blend Equation Support : %s\n",
183 kBlendEquationSupportNames[fBlendEquationSupport]);
184 r.appendf("Map Buffer Support : %s\n",
185 map_flags_to_string(fMapBufferFlags).c_str());
186
187 SkASSERT(!this->isConfigRenderable(kUnknown_GrPixelConfig, false));
188 SkASSERT(!this->isConfigRenderable(kUnknown_GrPixelConfig, true));
189
190 for (size_t i = 1; i < kGrPixelConfigCnt; ++i) {
191 GrPixelConfig config = static_cast<GrPixelConfig>(i);
192 r.appendf("%s is renderable: %s, with MSAA: %s\n",
193 pixel_config_name(config),
194 gNY[this->isConfigRenderable(config, false)],
195 gNY[this->isConfigRenderable(config, true)]);
196 }
197
198 SkASSERT(!this->isConfigTexturable(kUnknown_GrPixelConfig));
199
200 for (size_t i = 1; i < kGrPixelConfigCnt; ++i) {
201 GrPixelConfig config = static_cast<GrPixelConfig>(i);
202 r.appendf("%s is uploadable to a texture: %s\n",
203 pixel_config_name(config),
204 gNY[this->isConfigTexturable(config)]);
205 }
206
207 return r;
208 }
209