OLD | NEW |
(Empty) | |
| 1 |
| 2 /* |
| 3 * Copyright 2015 Google Inc. |
| 4 * |
| 5 * Use of this source code is governed by a BSD-style license that can be |
| 6 * found in the LICENSE file. |
| 7 */ |
| 8 |
| 9 #include "GrCaps.h" |
| 10 #include "GrContextOptions.h" |
| 11 |
| 12 GrShaderCaps::GrShaderCaps() { |
| 13 fShaderDerivativeSupport = false; |
| 14 fGeometryShaderSupport = false; |
| 15 fPathRenderingSupport = false; |
| 16 fDstReadInShaderSupport = false; |
| 17 fDualSourceBlendingSupport = false; |
| 18 fMixedSamplesSupport = false; |
| 19 fShaderPrecisionVaries = false; |
| 20 } |
| 21 |
| 22 static const char* shader_type_to_string(GrShaderType type) { |
| 23 switch (type) { |
| 24 case kVertex_GrShaderType: |
| 25 return "vertex"; |
| 26 case kGeometry_GrShaderType: |
| 27 return "geometry"; |
| 28 case kFragment_GrShaderType: |
| 29 return "fragment"; |
| 30 } |
| 31 return ""; |
| 32 } |
| 33 |
| 34 static const char* precision_to_string(GrSLPrecision p) { |
| 35 switch (p) { |
| 36 case kLow_GrSLPrecision: |
| 37 return "low"; |
| 38 case kMedium_GrSLPrecision: |
| 39 return "medium"; |
| 40 case kHigh_GrSLPrecision: |
| 41 return "high"; |
| 42 } |
| 43 return ""; |
| 44 } |
| 45 |
| 46 SkString GrShaderCaps::dump() const { |
| 47 SkString r; |
| 48 static const char* gNY[] = { "NO", "YES" }; |
| 49 r.appendf("Shader Derivative Support : %s\n", gNY[fShaderDerivative
Support]); |
| 50 r.appendf("Geometry Shader Support : %s\n", gNY[fGeometryShaderSu
pport]); |
| 51 r.appendf("Path Rendering Support : %s\n", gNY[fPathRenderingSup
port]); |
| 52 r.appendf("Dst Read In Shader Support : %s\n", gNY[fDstReadInShaderS
upport]); |
| 53 r.appendf("Dual Source Blending Support : %s\n", gNY[fDualSourceBlendi
ngSupport]); |
| 54 r.appendf("Mixed Samples Support : %s\n", gNY[fMixedSamplesSupp
ort]); |
| 55 |
| 56 r.appendf("Shader Float Precisions (varies: %s):\n", gNY[fShaderPrecisionVar
ies]); |
| 57 |
| 58 for (int s = 0; s < kGrShaderTypeCount; ++s) { |
| 59 GrShaderType shaderType = static_cast<GrShaderType>(s); |
| 60 r.appendf("\t%s:\n", shader_type_to_string(shaderType)); |
| 61 for (int p = 0; p < kGrSLPrecisionCount; ++p) { |
| 62 if (fFloatPrecisions[s][p].supported()) { |
| 63 GrSLPrecision precision = static_cast<GrSLPrecision>(p); |
| 64 r.appendf("\t\t%s: log_low: %d log_high: %d bits: %d\n", |
| 65 precision_to_string(precision), |
| 66 fFloatPrecisions[s][p].fLogRangeLow, |
| 67 fFloatPrecisions[s][p].fLogRangeHigh, |
| 68 fFloatPrecisions[s][p].fBits); |
| 69 } |
| 70 } |
| 71 } |
| 72 |
| 73 return r; |
| 74 } |
| 75 |
| 76 /////////////////////////////////////////////////////////////////////////////// |
| 77 |
| 78 GrCaps::GrCaps(const GrContextOptions& options) { |
| 79 fMipMapSupport = false; |
| 80 fNPOTTextureTileSupport = false; |
| 81 fTwoSidedStencilSupport = false; |
| 82 fStencilWrapOpsSupport = false; |
| 83 fDiscardRenderTargetSupport = false; |
| 84 fReuseScratchTextures = true; |
| 85 fGpuTracingSupport = false; |
| 86 fCompressedTexSubImageSupport = false; |
| 87 fOversizedStencilSupport = false; |
| 88 fTextureBarrierSupport = false; |
| 89 |
| 90 fUseDrawInsteadOfClear = false; |
| 91 |
| 92 fBlendEquationSupport = kBasic_BlendEquationSupport; |
| 93 fMapBufferFlags = kNone_MapFlags; |
| 94 |
| 95 fMaxRenderTargetSize = 0; |
| 96 fMaxTextureSize = 0; |
| 97 fMaxSampleCount = 0; |
| 98 |
| 99 memset(fConfigRenderSupport, 0, sizeof(fConfigRenderSupport)); |
| 100 memset(fConfigTextureSupport, 0, sizeof(fConfigTextureSupport)); |
| 101 |
| 102 fSupressPrints = options.fSuppressPrints; |
| 103 fDrawPathMasksToCompressedTextureSupport = options.fDrawPathToCompressedText
ure; |
| 104 } |
| 105 |
| 106 static SkString map_flags_to_string(uint32_t flags) { |
| 107 SkString str; |
| 108 if (GrCaps::kNone_MapFlags == flags) { |
| 109 str = "none"; |
| 110 } else { |
| 111 SkASSERT(GrCaps::kCanMap_MapFlag & flags); |
| 112 SkDEBUGCODE(flags &= ~GrCaps::kCanMap_MapFlag); |
| 113 str = "can_map"; |
| 114 |
| 115 if (GrCaps::kSubset_MapFlag & flags) { |
| 116 str.append(" partial"); |
| 117 } else { |
| 118 str.append(" full"); |
| 119 } |
| 120 SkDEBUGCODE(flags &= ~GrCaps::kSubset_MapFlag); |
| 121 } |
| 122 SkASSERT(0 == flags); // Make sure we handled all the flags. |
| 123 return str; |
| 124 } |
| 125 |
| 126 SkString GrCaps::dump() const { |
| 127 SkString r; |
| 128 static const char* gNY[] = {"NO", "YES"}; |
| 129 r.appendf("MIP Map Support : %s\n", gNY[fMipMapSupport]); |
| 130 r.appendf("NPOT Texture Tile Support : %s\n", gNY[fNPOTTextureTileS
upport]); |
| 131 r.appendf("Two Sided Stencil Support : %s\n", gNY[fTwoSidedStencilS
upport]); |
| 132 r.appendf("Stencil Wrap Ops Support : %s\n", gNY[fStencilWrapOpsSu
pport]); |
| 133 r.appendf("Discard Render Target Support : %s\n", gNY[fDiscardRenderTar
getSupport]); |
| 134 r.appendf("Reuse Scratch Textures : %s\n", gNY[fReuseScratchText
ures]); |
| 135 r.appendf("Gpu Tracing Support : %s\n", gNY[fGpuTracingSuppor
t]); |
| 136 r.appendf("Compressed Update Support : %s\n", gNY[fCompressedTexSub
ImageSupport]); |
| 137 r.appendf("Oversized Stencil Support : %s\n", gNY[fOversizedStencil
Support]); |
| 138 r.appendf("Texture Barrier Support : %s\n", gNY[fTextureBarrierSu
pport]); |
| 139 r.appendf("Draw Instead of Clear [workaround] : %s\n", gNY[fUseDrawInsteadOf
Clear]); |
| 140 |
| 141 r.appendf("Max Texture Size : %d\n", fMaxTextureSize); |
| 142 r.appendf("Max Render Target Size : %d\n", fMaxRenderTargetSize)
; |
| 143 r.appendf("Max Sample Count : %d\n", fMaxSampleCount); |
| 144 |
| 145 static const char* kBlendEquationSupportNames[] = { |
| 146 "Basic", |
| 147 "Advanced", |
| 148 "Advanced Coherent", |
| 149 }; |
| 150 GR_STATIC_ASSERT(0 == kBasic_BlendEquationSupport); |
| 151 GR_STATIC_ASSERT(1 == kAdvanced_BlendEquationSupport); |
| 152 GR_STATIC_ASSERT(2 == kAdvancedCoherent_BlendEquationSupport); |
| 153 GR_STATIC_ASSERT(SK_ARRAY_COUNT(kBlendEquationSupportNames) == kLast_BlendEq
uationSupport + 1); |
| 154 |
| 155 r.appendf("Blend Equation Support : %s\n", |
| 156 kBlendEquationSupportNames[fBlendEquationSupport]); |
| 157 r.appendf("Map Buffer Support : %s\n", |
| 158 map_flags_to_string(fMapBufferFlags).c_str()); |
| 159 |
| 160 static const char* kConfigNames[] = { |
| 161 "Unknown", // kUnknown_GrPixelConfig |
| 162 "Alpha8", // kAlpha_8_GrPixelConfig, |
| 163 "Index8", // kIndex_8_GrPixelConfig, |
| 164 "RGB565", // kRGB_565_GrPixelConfig, |
| 165 "RGBA444", // kRGBA_4444_GrPixelConfig, |
| 166 "RGBA8888", // kRGBA_8888_GrPixelConfig, |
| 167 "BGRA8888", // kBGRA_8888_GrPixelConfig, |
| 168 "SRGBA8888",// kSRGBA_8888_GrPixelConfig, |
| 169 "ETC1", // kETC1_GrPixelConfig, |
| 170 "LATC", // kLATC_GrPixelConfig, |
| 171 "R11EAC", // kR11_EAC_GrPixelConfig, |
| 172 "ASTC12x12",// kASTC_12x12_GrPixelConfig, |
| 173 "RGBAFloat",// kRGBA_float_GrPixelConfig |
| 174 "AlphaHalf",// kAlpha_half_GrPixelConfig |
| 175 "RGBAHalf", // kRGBA_half_GrPixelConfig |
| 176 }; |
| 177 GR_STATIC_ASSERT(0 == kUnknown_GrPixelConfig); |
| 178 GR_STATIC_ASSERT(1 == kAlpha_8_GrPixelConfig); |
| 179 GR_STATIC_ASSERT(2 == kIndex_8_GrPixelConfig); |
| 180 GR_STATIC_ASSERT(3 == kRGB_565_GrPixelConfig); |
| 181 GR_STATIC_ASSERT(4 == kRGBA_4444_GrPixelConfig); |
| 182 GR_STATIC_ASSERT(5 == kRGBA_8888_GrPixelConfig); |
| 183 GR_STATIC_ASSERT(6 == kBGRA_8888_GrPixelConfig); |
| 184 GR_STATIC_ASSERT(7 == kSRGBA_8888_GrPixelConfig); |
| 185 GR_STATIC_ASSERT(8 == kETC1_GrPixelConfig); |
| 186 GR_STATIC_ASSERT(9 == kLATC_GrPixelConfig); |
| 187 GR_STATIC_ASSERT(10 == kR11_EAC_GrPixelConfig); |
| 188 GR_STATIC_ASSERT(11 == kASTC_12x12_GrPixelConfig); |
| 189 GR_STATIC_ASSERT(12 == kRGBA_float_GrPixelConfig); |
| 190 GR_STATIC_ASSERT(13 == kAlpha_half_GrPixelConfig); |
| 191 GR_STATIC_ASSERT(14 == kRGBA_half_GrPixelConfig); |
| 192 GR_STATIC_ASSERT(SK_ARRAY_COUNT(kConfigNames) == kGrPixelConfigCnt); |
| 193 |
| 194 SkASSERT(!fConfigRenderSupport[kUnknown_GrPixelConfig][0]); |
| 195 SkASSERT(!fConfigRenderSupport[kUnknown_GrPixelConfig][1]); |
| 196 |
| 197 for (size_t i = 1; i < SK_ARRAY_COUNT(kConfigNames); ++i) { |
| 198 r.appendf("%s is renderable: %s, with MSAA: %s\n", |
| 199 kConfigNames[i], |
| 200 gNY[fConfigRenderSupport[i][0]], |
| 201 gNY[fConfigRenderSupport[i][1]]); |
| 202 } |
| 203 |
| 204 SkASSERT(!fConfigTextureSupport[kUnknown_GrPixelConfig]); |
| 205 |
| 206 for (size_t i = 1; i < SK_ARRAY_COUNT(kConfigNames); ++i) { |
| 207 r.appendf("%s is uploadable to a texture: %s\n", |
| 208 kConfigNames[i], |
| 209 gNY[fConfigTextureSupport[i]]); |
| 210 } |
| 211 |
| 212 return r; |
| 213 } |
OLD | NEW |