1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/gfx/skia/trunk/src/gpu/gl/GrGLCaps.cpp Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,665 @@ 1.4 +/* 1.5 + * Copyright 2012 Google Inc. 1.6 + * 1.7 + * Use of this source code is governed by a BSD-style license that can be 1.8 + * found in the LICENSE file. 1.9 + */ 1.10 + 1.11 + 1.12 +#include "GrGLCaps.h" 1.13 +#include "GrGLContext.h" 1.14 +#include "SkTSearch.h" 1.15 +#include "SkTSort.h" 1.16 + 1.17 +GrGLCaps::GrGLCaps() { 1.18 + this->reset(); 1.19 +} 1.20 + 1.21 +void GrGLCaps::reset() { 1.22 + INHERITED::reset(); 1.23 + 1.24 + fVerifiedColorConfigs.reset(); 1.25 + fStencilFormats.reset(); 1.26 + fStencilVerifiedColorConfigs.reset(); 1.27 + fMSFBOType = kNone_MSFBOType; 1.28 + fFBFetchType = kNone_FBFetchType; 1.29 + fMaxFragmentUniformVectors = 0; 1.30 + fMaxVertexAttributes = 0; 1.31 + fMaxFragmentTextureUnits = 0; 1.32 + fMaxFixedFunctionTextureCoords = 0; 1.33 + fRGBA8RenderbufferSupport = false; 1.34 + fBGRAFormatSupport = false; 1.35 + fBGRAIsInternalFormat = false; 1.36 + fTextureSwizzleSupport = false; 1.37 + fUnpackRowLengthSupport = false; 1.38 + fUnpackFlipYSupport = false; 1.39 + fPackRowLengthSupport = false; 1.40 + fPackFlipYSupport = false; 1.41 + fTextureUsageSupport = false; 1.42 + fTexStorageSupport = false; 1.43 + fTextureRedSupport = false; 1.44 + fImagingSupport = false; 1.45 + fTwoFormatLimit = false; 1.46 + fFragCoordsConventionSupport = false; 1.47 + fVertexArrayObjectSupport = false; 1.48 + fUseNonVBOVertexAndIndexDynamicData = false; 1.49 + fIsCoreProfile = false; 1.50 + fFixedFunctionSupport = false; 1.51 + fDiscardFBSupport = false; 1.52 + fFullClearIsFree = false; 1.53 +} 1.54 + 1.55 +GrGLCaps::GrGLCaps(const GrGLCaps& caps) : GrDrawTargetCaps() { 1.56 + *this = caps; 1.57 +} 1.58 + 1.59 +GrGLCaps& GrGLCaps::operator = (const GrGLCaps& caps) { 1.60 + INHERITED::operator=(caps); 1.61 + fVerifiedColorConfigs = caps.fVerifiedColorConfigs; 1.62 + fStencilFormats = caps.fStencilFormats; 1.63 + fStencilVerifiedColorConfigs = caps.fStencilVerifiedColorConfigs; 1.64 + fMaxFragmentUniformVectors = caps.fMaxFragmentUniformVectors; 1.65 + fMaxVertexAttributes = caps.fMaxVertexAttributes; 1.66 + fMaxFragmentTextureUnits = caps.fMaxFragmentTextureUnits; 1.67 + fMaxFixedFunctionTextureCoords = caps.fMaxFixedFunctionTextureCoords; 1.68 + fMSFBOType = caps.fMSFBOType; 1.69 + fFBFetchType = caps.fFBFetchType; 1.70 + fRGBA8RenderbufferSupport = caps.fRGBA8RenderbufferSupport; 1.71 + fBGRAFormatSupport = caps.fBGRAFormatSupport; 1.72 + fBGRAIsInternalFormat = caps.fBGRAIsInternalFormat; 1.73 + fTextureSwizzleSupport = caps.fTextureSwizzleSupport; 1.74 + fUnpackRowLengthSupport = caps.fUnpackRowLengthSupport; 1.75 + fUnpackFlipYSupport = caps.fUnpackFlipYSupport; 1.76 + fPackRowLengthSupport = caps.fPackRowLengthSupport; 1.77 + fPackFlipYSupport = caps.fPackFlipYSupport; 1.78 + fTextureUsageSupport = caps.fTextureUsageSupport; 1.79 + fTexStorageSupport = caps.fTexStorageSupport; 1.80 + fTextureRedSupport = caps.fTextureRedSupport; 1.81 + fImagingSupport = caps.fImagingSupport; 1.82 + fTwoFormatLimit = caps.fTwoFormatLimit; 1.83 + fFragCoordsConventionSupport = caps.fFragCoordsConventionSupport; 1.84 + fVertexArrayObjectSupport = caps.fVertexArrayObjectSupport; 1.85 + fUseNonVBOVertexAndIndexDynamicData = caps.fUseNonVBOVertexAndIndexDynamicData; 1.86 + fIsCoreProfile = caps.fIsCoreProfile; 1.87 + fFixedFunctionSupport = caps.fFixedFunctionSupport; 1.88 + fDiscardFBSupport = caps.fDiscardFBSupport; 1.89 + fFullClearIsFree = caps.fFullClearIsFree; 1.90 + 1.91 + return *this; 1.92 +} 1.93 + 1.94 +void GrGLCaps::init(const GrGLContextInfo& ctxInfo, const GrGLInterface* gli) { 1.95 + 1.96 + this->reset(); 1.97 + if (!ctxInfo.isInitialized()) { 1.98 + return; 1.99 + } 1.100 + 1.101 + GrGLStandard standard = ctxInfo.standard(); 1.102 + GrGLVersion version = ctxInfo.version(); 1.103 + 1.104 + /************************************************************************** 1.105 + * Caps specific to GrGLCaps 1.106 + **************************************************************************/ 1.107 + 1.108 + if (kGLES_GrGLStandard == standard) { 1.109 + GR_GL_GetIntegerv(gli, GR_GL_MAX_FRAGMENT_UNIFORM_VECTORS, 1.110 + &fMaxFragmentUniformVectors); 1.111 + } else { 1.112 + SkASSERT(kGL_GrGLStandard == standard); 1.113 + GrGLint max; 1.114 + GR_GL_GetIntegerv(gli, GR_GL_MAX_FRAGMENT_UNIFORM_COMPONENTS, &max); 1.115 + fMaxFragmentUniformVectors = max / 4; 1.116 + if (version >= GR_GL_VER(3, 2)) { 1.117 + GrGLint profileMask; 1.118 + GR_GL_GetIntegerv(gli, GR_GL_CONTEXT_PROFILE_MASK, &profileMask); 1.119 + fIsCoreProfile = SkToBool(profileMask & GR_GL_CONTEXT_CORE_PROFILE_BIT); 1.120 + } 1.121 + if (!fIsCoreProfile) { 1.122 + fFixedFunctionSupport = true; 1.123 + GR_GL_GetIntegerv(gli, GR_GL_MAX_TEXTURE_COORDS, &fMaxFixedFunctionTextureCoords); 1.124 + // Sanity check 1.125 + SkASSERT(fMaxFixedFunctionTextureCoords > 0 && fMaxFixedFunctionTextureCoords < 128); 1.126 + } 1.127 + } 1.128 + GR_GL_GetIntegerv(gli, GR_GL_MAX_VERTEX_ATTRIBS, &fMaxVertexAttributes); 1.129 + GR_GL_GetIntegerv(gli, GR_GL_MAX_TEXTURE_IMAGE_UNITS, &fMaxFragmentTextureUnits); 1.130 + 1.131 + if (kGL_GrGLStandard == standard) { 1.132 + fRGBA8RenderbufferSupport = true; 1.133 + } else { 1.134 + fRGBA8RenderbufferSupport = version >= GR_GL_VER(3,0) || 1.135 + ctxInfo.hasExtension("GL_OES_rgb8_rgba8") || 1.136 + ctxInfo.hasExtension("GL_ARM_rgba8"); 1.137 + } 1.138 + 1.139 + if (kGL_GrGLStandard == standard) { 1.140 + fBGRAFormatSupport = version >= GR_GL_VER(1,2) || 1.141 + ctxInfo.hasExtension("GL_EXT_bgra"); 1.142 + } else { 1.143 + if (ctxInfo.hasExtension("GL_APPLE_texture_format_BGRA8888")) { 1.144 + fBGRAFormatSupport = true; 1.145 + } else if (ctxInfo.hasExtension("GL_EXT_texture_format_BGRA8888")) { 1.146 + fBGRAFormatSupport = true; 1.147 + fBGRAIsInternalFormat = true; 1.148 + } 1.149 + SkASSERT(fBGRAFormatSupport || 1.150 + kSkia8888_GrPixelConfig != kBGRA_8888_GrPixelConfig); 1.151 + } 1.152 + 1.153 + if (kGL_GrGLStandard == standard) { 1.154 + fTextureSwizzleSupport = version >= GR_GL_VER(3,3) || 1.155 + ctxInfo.hasExtension("GL_ARB_texture_swizzle"); 1.156 + } else { 1.157 + fTextureSwizzleSupport = version >= GR_GL_VER(3,0); 1.158 + } 1.159 + 1.160 + if (kGL_GrGLStandard == standard) { 1.161 + fUnpackRowLengthSupport = true; 1.162 + fUnpackFlipYSupport = false; 1.163 + fPackRowLengthSupport = true; 1.164 + fPackFlipYSupport = false; 1.165 + } else { 1.166 + fUnpackRowLengthSupport = version >= GR_GL_VER(3,0) || 1.167 + ctxInfo.hasExtension("GL_EXT_unpack_subimage"); 1.168 + fUnpackFlipYSupport = ctxInfo.hasExtension("GL_CHROMIUM_flipy"); 1.169 + fPackRowLengthSupport = version >= GR_GL_VER(3,0) || 1.170 + ctxInfo.hasExtension("GL_NV_pack_subimage"); 1.171 + fPackFlipYSupport = 1.172 + ctxInfo.hasExtension("GL_ANGLE_pack_reverse_row_order"); 1.173 + } 1.174 + 1.175 + fTextureUsageSupport = (kGLES_GrGLStandard == standard) && 1.176 + ctxInfo.hasExtension("GL_ANGLE_texture_usage"); 1.177 + 1.178 + if (kGL_GrGLStandard == standard) { 1.179 + // The EXT version can apply to either GL or GLES. 1.180 + fTexStorageSupport = version >= GR_GL_VER(4,2) || 1.181 + ctxInfo.hasExtension("GL_ARB_texture_storage") || 1.182 + ctxInfo.hasExtension("GL_EXT_texture_storage"); 1.183 + } else { 1.184 + // Qualcomm Adreno drivers appear to have issues with texture storage. 1.185 + fTexStorageSupport = (version >= GR_GL_VER(3,0) && 1.186 + kQualcomm_GrGLVendor != ctxInfo.vendor()) || 1.187 + ctxInfo.hasExtension("GL_EXT_texture_storage"); 1.188 + } 1.189 + 1.190 + // ARB_texture_rg is part of OpenGL 3.0, but mesa doesn't support it if 1.191 + // it doesn't have ARB_texture_rg extension. 1.192 + if (kGL_GrGLStandard == standard) { 1.193 + if (ctxInfo.isMesa()) { 1.194 + fTextureRedSupport = ctxInfo.hasExtension("GL_ARB_texture_rg"); 1.195 + } else { 1.196 + fTextureRedSupport = version >= GR_GL_VER(3,0) || 1.197 + ctxInfo.hasExtension("GL_ARB_texture_rg"); 1.198 + } 1.199 + } else { 1.200 + fTextureRedSupport = version >= GR_GL_VER(3,0) || 1.201 + ctxInfo.hasExtension("GL_EXT_texture_rg"); 1.202 + } 1.203 + 1.204 + fImagingSupport = kGL_GrGLStandard == standard && 1.205 + ctxInfo.hasExtension("GL_ARB_imaging"); 1.206 + 1.207 + // ES 2 only guarantees RGBA/uchar + one other format/type combo for 1.208 + // ReadPixels. The other format has to checked at run-time since it 1.209 + // can change based on which render target is bound 1.210 + fTwoFormatLimit = kGLES_GrGLStandard == standard; 1.211 + 1.212 + // Known issue on at least some Intel platforms: 1.213 + // http://code.google.com/p/skia/issues/detail?id=946 1.214 + if (kIntel_GrGLVendor != ctxInfo.vendor()) { 1.215 + fFragCoordsConventionSupport = ctxInfo.glslGeneration() >= k150_GrGLSLGeneration || 1.216 + ctxInfo.hasExtension("GL_ARB_fragment_coord_conventions"); 1.217 + } 1.218 + 1.219 + // SGX and Mali GPUs that are based on a tiled-deferred architecture that have trouble with 1.220 + // frequently changing VBOs. We've measured a performance increase using non-VBO vertex 1.221 + // data for dynamic content on these GPUs. Perhaps we should read the renderer string and 1.222 + // limit this decision to specific GPU families rather than basing it on the vendor alone. 1.223 + if (!GR_GL_MUST_USE_VBO && 1.224 + (kARM_GrGLVendor == ctxInfo.vendor() || kImagination_GrGLVendor == ctxInfo.vendor())) { 1.225 + fUseNonVBOVertexAndIndexDynamicData = true; 1.226 + } 1.227 + 1.228 + fDiscardFBSupport = ctxInfo.hasExtension("GL_EXT_discard_framebuffer"); 1.229 + 1.230 + if (kARM_GrGLVendor == ctxInfo.vendor() || kImagination_GrGLVendor == ctxInfo.vendor()) { 1.231 + fFullClearIsFree = true; 1.232 + } 1.233 + 1.234 + if (kGL_GrGLStandard == standard) { 1.235 + fVertexArrayObjectSupport = version >= GR_GL_VER(3, 0) || 1.236 + ctxInfo.hasExtension("GL_ARB_vertex_array_object"); 1.237 + } else { 1.238 + fVertexArrayObjectSupport = version >= GR_GL_VER(3, 0) || 1.239 + ctxInfo.hasExtension("GL_OES_vertex_array_object"); 1.240 + } 1.241 + 1.242 + if (kGLES_GrGLStandard == standard) { 1.243 + if (ctxInfo.hasExtension("GL_EXT_shader_framebuffer_fetch")) { 1.244 + fFBFetchType = kEXT_FBFetchType; 1.245 + } else if (ctxInfo.hasExtension("GL_NV_shader_framebuffer_fetch")) { 1.246 + fFBFetchType = kNV_FBFetchType; 1.247 + } 1.248 + } 1.249 + 1.250 + this->initFSAASupport(ctxInfo, gli); 1.251 + this->initStencilFormats(ctxInfo); 1.252 + 1.253 + /************************************************************************** 1.254 + * GrDrawTargetCaps fields 1.255 + **************************************************************************/ 1.256 + GrGLint numFormats; 1.257 + GR_GL_GetIntegerv(gli, GR_GL_NUM_COMPRESSED_TEXTURE_FORMATS, &numFormats); 1.258 + if (numFormats) { 1.259 + SkAutoSTMalloc<10, GrGLint> formats(numFormats); 1.260 + GR_GL_GetIntegerv(gli, GR_GL_COMPRESSED_TEXTURE_FORMATS, formats); 1.261 + for (int i = 0; i < numFormats; ++i) { 1.262 + if (formats[i] == GR_GL_PALETTE8_RGBA8) { 1.263 + f8BitPaletteSupport = true; 1.264 + break; 1.265 + } 1.266 + } 1.267 + } 1.268 + 1.269 + if (kGL_GrGLStandard == standard) { 1.270 + // we could also look for GL_ATI_separate_stencil extension or 1.271 + // GL_EXT_stencil_two_side but they use different function signatures 1.272 + // than GL2.0+ (and than each other). 1.273 + fTwoSidedStencilSupport = (ctxInfo.version() >= GR_GL_VER(2,0)); 1.274 + // supported on GL 1.4 and higher or by extension 1.275 + fStencilWrapOpsSupport = (ctxInfo.version() >= GR_GL_VER(1,4)) || 1.276 + ctxInfo.hasExtension("GL_EXT_stencil_wrap"); 1.277 + } else { 1.278 + // ES 2 has two sided stencil and stencil wrap 1.279 + fTwoSidedStencilSupport = true; 1.280 + fStencilWrapOpsSupport = true; 1.281 + } 1.282 + 1.283 + if (kGL_GrGLStandard == standard) { 1.284 + fBufferLockSupport = true; // we require VBO support and the desktop VBO extension includes 1.285 + // glMapBuffer. 1.286 + } else { 1.287 + fBufferLockSupport = ctxInfo.hasExtension("GL_OES_mapbuffer"); 1.288 + } 1.289 + 1.290 + if (kGL_GrGLStandard == standard) { 1.291 + SkASSERT(ctxInfo.version() >= GR_GL_VER(2,0) || 1.292 + ctxInfo.hasExtension("GL_ARB_texture_non_power_of_two")); 1.293 + fNPOTTextureTileSupport = true; 1.294 + fMipMapSupport = true; 1.295 + } else { 1.296 + // Unextended ES2 supports NPOT textures with clamp_to_edge and non-mip filters only 1.297 + // ES3 has no limitations. 1.298 + fNPOTTextureTileSupport = ctxInfo.version() >= GR_GL_VER(3,0) || 1.299 + ctxInfo.hasExtension("GL_OES_texture_npot"); 1.300 + // ES2 supports MIP mapping for POT textures but our caps don't allow for limited MIP 1.301 + // support. The OES extension or ES 3.0 allow for MIPS on NPOT textures. So, apparently, 1.302 + // does the undocumented GL_IMG_texture_npot extension. This extension does not seem to 1.303 + // to alllow arbitrary wrap modes, however. 1.304 + fMipMapSupport = fNPOTTextureTileSupport || ctxInfo.hasExtension("GL_IMG_texture_npot"); 1.305 + } 1.306 + 1.307 + fHWAALineSupport = (kGL_GrGLStandard == standard); 1.308 + 1.309 + GR_GL_GetIntegerv(gli, GR_GL_MAX_TEXTURE_SIZE, &fMaxTextureSize); 1.310 + GR_GL_GetIntegerv(gli, GR_GL_MAX_RENDERBUFFER_SIZE, &fMaxRenderTargetSize); 1.311 + // Our render targets are always created with textures as the color 1.312 + // attachment, hence this min: 1.313 + fMaxRenderTargetSize = GrMin(fMaxTextureSize, fMaxRenderTargetSize); 1.314 + 1.315 + fPathRenderingSupport = ctxInfo.hasExtension("GL_NV_path_rendering"); 1.316 + SkASSERT(!fPathRenderingSupport || fFixedFunctionSupport); 1.317 + 1.318 + fGpuTracingSupport = ctxInfo.hasExtension("GL_EXT_debug_marker"); 1.319 + 1.320 + fDstReadInShaderSupport = kNone_FBFetchType != fFBFetchType; 1.321 + 1.322 + // Disable scratch texture reuse on Mali and Adreno devices 1.323 + fReuseScratchTextures = kARM_GrGLVendor != ctxInfo.vendor() && 1.324 + kQualcomm_GrGLVendor != ctxInfo.vendor(); 1.325 + 1.326 + // Enable supported shader-related caps 1.327 + if (kGL_GrGLStandard == standard) { 1.328 + fDualSourceBlendingSupport = ctxInfo.version() >= GR_GL_VER(3,3) || 1.329 + ctxInfo.hasExtension("GL_ARB_blend_func_extended"); 1.330 + fShaderDerivativeSupport = true; 1.331 + // we don't support GL_ARB_geometry_shader4, just GL 3.2+ GS 1.332 + fGeometryShaderSupport = ctxInfo.version() >= GR_GL_VER(3,2) && 1.333 + ctxInfo.glslGeneration() >= k150_GrGLSLGeneration; 1.334 + } else { 1.335 + fShaderDerivativeSupport = ctxInfo.hasExtension("GL_OES_standard_derivatives"); 1.336 + } 1.337 + 1.338 + if (GrGLCaps::kES_IMG_MsToTexture_MSFBOType == fMSFBOType) { 1.339 + GR_GL_GetIntegerv(gli, GR_GL_MAX_SAMPLES_IMG, &fMaxSampleCount); 1.340 + } else if (GrGLCaps::kNone_MSFBOType != fMSFBOType) { 1.341 + GR_GL_GetIntegerv(gli, GR_GL_MAX_SAMPLES, &fMaxSampleCount); 1.342 + } 1.343 + 1.344 + this->initConfigRenderableTable(ctxInfo); 1.345 +} 1.346 + 1.347 +void GrGLCaps::initConfigRenderableTable(const GrGLContextInfo& ctxInfo) { 1.348 + 1.349 + // OpenGL < 3.0 1.350 + // no support for render targets unless the GL_ARB_framebuffer_object 1.351 + // extension is supported (in which case we get ALPHA, RED, RG, RGB, 1.352 + // RGBA (ALPHA8, RGBA4, RGBA8) for OpenGL > 1.1). Note that we 1.353 + // probably don't get R8 in this case. 1.354 + 1.355 + // OpenGL 3.0 1.356 + // base color renderable: ALPHA, RED, RG, RGB, and RGBA 1.357 + // sized derivatives: ALPHA8, R8, RGBA4, RGBA8 1.358 + 1.359 + // >= OpenGL 3.1 1.360 + // base color renderable: RED, RG, RGB, and RGBA 1.361 + // sized derivatives: R8, RGBA4, RGBA8 1.362 + // if the GL_ARB_compatibility extension is supported then we get back 1.363 + // support for GL_ALPHA and ALPHA8 1.364 + 1.365 + // GL_EXT_bgra adds BGRA render targets to any version 1.366 + 1.367 + // ES 2.0 1.368 + // color renderable: RGBA4, RGB5_A1, RGB565 1.369 + // GL_EXT_texture_rg adds support for R8 as a color render target 1.370 + // GL_OES_rgb8_rgba8 and/or GL_ARM_rgba8 adds support for RGBA8 1.371 + // GL_EXT_texture_format_BGRA8888 and/or GL_APPLE_texture_format_BGRA8888 added BGRA support 1.372 + 1.373 + // ES 3.0 1.374 + // Same as ES 2.0 except R8 and RGBA8 are supported without extensions (the functions called 1.375 + // below already account for this). 1.376 + 1.377 + enum { 1.378 + kNo_MSAA = 0, 1.379 + kYes_MSAA = 1, 1.380 + }; 1.381 + 1.382 + if (kGL_GrGLStandard == ctxInfo.standard()) { 1.383 + // Post 3.0 we will get R8 1.384 + // Prior to 3.0 we will get ALPHA8 (with GL_ARB_framebuffer_object) 1.385 + if (ctxInfo.version() >= GR_GL_VER(3,0) || 1.386 + ctxInfo.hasExtension("GL_ARB_framebuffer_object")) { 1.387 + fConfigRenderSupport[kAlpha_8_GrPixelConfig][kNo_MSAA] = true; 1.388 + fConfigRenderSupport[kAlpha_8_GrPixelConfig][kYes_MSAA] = true; 1.389 + } 1.390 + } else { 1.391 + // On ES we can only hope for R8 1.392 + fConfigRenderSupport[kAlpha_8_GrPixelConfig][kNo_MSAA] = fTextureRedSupport; 1.393 + fConfigRenderSupport[kAlpha_8_GrPixelConfig][kYes_MSAA] = fTextureRedSupport; 1.394 + } 1.395 + 1.396 + if (kGL_GrGLStandard != ctxInfo.standard()) { 1.397 + // only available in ES 1.398 + fConfigRenderSupport[kRGB_565_GrPixelConfig][kNo_MSAA] = true; 1.399 + fConfigRenderSupport[kRGB_565_GrPixelConfig][kYes_MSAA] = true; 1.400 + } 1.401 + 1.402 + // we no longer support 444 as a render target 1.403 + fConfigRenderSupport[kRGBA_4444_GrPixelConfig][kNo_MSAA] = false; 1.404 + fConfigRenderSupport[kRGBA_4444_GrPixelConfig][kYes_MSAA] = false; 1.405 + 1.406 + if (this->fRGBA8RenderbufferSupport) { 1.407 + fConfigRenderSupport[kRGBA_8888_GrPixelConfig][kNo_MSAA] = true; 1.408 + fConfigRenderSupport[kRGBA_8888_GrPixelConfig][kYes_MSAA] = true; 1.409 + } 1.410 + 1.411 + if (this->fBGRAFormatSupport) { 1.412 + fConfigRenderSupport[kBGRA_8888_GrPixelConfig][kNo_MSAA] = true; 1.413 + // The GL_EXT_texture_format_BGRA8888 extension does not add BGRA to the list of 1.414 + // configs that are color-renderable and can be passed to glRenderBufferStorageMultisample. 1.415 + // Chromium may have an extension to allow BGRA renderbuffers to work on desktop platforms. 1.416 + if (ctxInfo.hasExtension("GL_CHROMIUM_renderbuffer_format_BGRA8888")) { 1.417 + fConfigRenderSupport[kBGRA_8888_GrPixelConfig][kYes_MSAA] = true; 1.418 + } else { 1.419 + fConfigRenderSupport[kBGRA_8888_GrPixelConfig][kYes_MSAA] = 1.420 + !fBGRAIsInternalFormat || !this->usesMSAARenderBuffers(); 1.421 + } 1.422 + } 1.423 + 1.424 + // If we don't support MSAA then undo any places above where we set a config as renderable with 1.425 + // msaa. 1.426 + if (kNone_MSFBOType == fMSFBOType) { 1.427 + for (int i = 0; i < kGrPixelConfigCnt; ++i) { 1.428 + fConfigRenderSupport[i][kYes_MSAA] = false; 1.429 + } 1.430 + } 1.431 +} 1.432 + 1.433 +bool GrGLCaps::readPixelsSupported(const GrGLInterface* intf, 1.434 + GrGLenum format, 1.435 + GrGLenum type) const { 1.436 + if (GR_GL_RGBA == format && GR_GL_UNSIGNED_BYTE == type) { 1.437 + // ES 2 guarantees this format is supported 1.438 + return true; 1.439 + } 1.440 + 1.441 + if (!fTwoFormatLimit) { 1.442 + // not limited by ES 2's constraints 1.443 + return true; 1.444 + } 1.445 + 1.446 + GrGLint otherFormat = GR_GL_RGBA; 1.447 + GrGLint otherType = GR_GL_UNSIGNED_BYTE; 1.448 + 1.449 + // The other supported format/type combo supported for ReadPixels 1.450 + // can change based on which render target is bound 1.451 + GR_GL_GetIntegerv(intf, 1.452 + GR_GL_IMPLEMENTATION_COLOR_READ_FORMAT, 1.453 + &otherFormat); 1.454 + 1.455 + GR_GL_GetIntegerv(intf, 1.456 + GR_GL_IMPLEMENTATION_COLOR_READ_TYPE, 1.457 + &otherType); 1.458 + 1.459 + return (GrGLenum)otherFormat == format && (GrGLenum)otherType == type; 1.460 +} 1.461 + 1.462 +void GrGLCaps::initFSAASupport(const GrGLContextInfo& ctxInfo, const GrGLInterface* gli) { 1.463 + 1.464 + fMSFBOType = kNone_MSFBOType; 1.465 + if (kGL_GrGLStandard != ctxInfo.standard()) { 1.466 + // We prefer the EXT/IMG extension over ES3 MSAA because we've observed 1.467 + // ES3 driver bugs on at least one device with a tiled GPU (N10). 1.468 + if (ctxInfo.hasExtension("GL_EXT_multisampled_render_to_texture")) { 1.469 + fMSFBOType = kES_EXT_MsToTexture_MSFBOType; 1.470 + } else if (ctxInfo.hasExtension("GL_IMG_multisampled_render_to_texture")) { 1.471 + fMSFBOType = kES_IMG_MsToTexture_MSFBOType; 1.472 + } else if (ctxInfo.version() >= GR_GL_VER(3,0)) { 1.473 + fMSFBOType = GrGLCaps::kES_3_0_MSFBOType; 1.474 + } else if (ctxInfo.hasExtension("GL_CHROMIUM_framebuffer_multisample")) { 1.475 + // chrome's extension is equivalent to the EXT msaa 1.476 + // and fbo_blit extensions. 1.477 + fMSFBOType = kDesktop_EXT_MSFBOType; 1.478 + } else if (ctxInfo.hasExtension("GL_APPLE_framebuffer_multisample")) { 1.479 + fMSFBOType = kES_Apple_MSFBOType; 1.480 + } 1.481 + } else { 1.482 + if ((ctxInfo.version() >= GR_GL_VER(3,0)) || 1.483 + ctxInfo.hasExtension("GL_ARB_framebuffer_object")) { 1.484 + fMSFBOType = GrGLCaps::kDesktop_ARB_MSFBOType; 1.485 + } else if (ctxInfo.hasExtension("GL_EXT_framebuffer_multisample") && 1.486 + ctxInfo.hasExtension("GL_EXT_framebuffer_blit")) { 1.487 + fMSFBOType = GrGLCaps::kDesktop_EXT_MSFBOType; 1.488 + } 1.489 + } 1.490 +} 1.491 + 1.492 +namespace { 1.493 +const GrGLuint kUnknownBitCount = GrGLStencilBuffer::kUnknownBitCount; 1.494 +} 1.495 + 1.496 +void GrGLCaps::initStencilFormats(const GrGLContextInfo& ctxInfo) { 1.497 + 1.498 + // Build up list of legal stencil formats (though perhaps not supported on 1.499 + // the particular gpu/driver) from most preferred to least. 1.500 + 1.501 + // these consts are in order of most preferred to least preferred 1.502 + // we don't bother with GL_STENCIL_INDEX1 or GL_DEPTH32F_STENCIL8 1.503 + 1.504 + static const StencilFormat 1.505 + // internal Format stencil bits total bits packed? 1.506 + gS8 = {GR_GL_STENCIL_INDEX8, 8, 8, false}, 1.507 + gS16 = {GR_GL_STENCIL_INDEX16, 16, 16, false}, 1.508 + gD24S8 = {GR_GL_DEPTH24_STENCIL8, 8, 32, true }, 1.509 + gS4 = {GR_GL_STENCIL_INDEX4, 4, 4, false}, 1.510 + // gS = {GR_GL_STENCIL_INDEX, kUnknownBitCount, kUnknownBitCount, false}, 1.511 + gDS = {GR_GL_DEPTH_STENCIL, kUnknownBitCount, kUnknownBitCount, true }; 1.512 + 1.513 + if (kGL_GrGLStandard == ctxInfo.standard()) { 1.514 + bool supportsPackedDS = 1.515 + ctxInfo.version() >= GR_GL_VER(3,0) || 1.516 + ctxInfo.hasExtension("GL_EXT_packed_depth_stencil") || 1.517 + ctxInfo.hasExtension("GL_ARB_framebuffer_object"); 1.518 + 1.519 + // S1 thru S16 formats are in GL 3.0+, EXT_FBO, and ARB_FBO since we 1.520 + // require FBO support we can expect these are legal formats and don't 1.521 + // check. These also all support the unsized GL_STENCIL_INDEX. 1.522 + fStencilFormats.push_back() = gS8; 1.523 + fStencilFormats.push_back() = gS16; 1.524 + if (supportsPackedDS) { 1.525 + fStencilFormats.push_back() = gD24S8; 1.526 + } 1.527 + fStencilFormats.push_back() = gS4; 1.528 + if (supportsPackedDS) { 1.529 + fStencilFormats.push_back() = gDS; 1.530 + } 1.531 + } else { 1.532 + // ES2 has STENCIL_INDEX8 without extensions but requires extensions 1.533 + // for other formats. 1.534 + // ES doesn't support using the unsized format. 1.535 + 1.536 + fStencilFormats.push_back() = gS8; 1.537 + //fStencilFormats.push_back() = gS16; 1.538 + if (ctxInfo.version() >= GR_GL_VER(3,0) || 1.539 + ctxInfo.hasExtension("GL_OES_packed_depth_stencil")) { 1.540 + fStencilFormats.push_back() = gD24S8; 1.541 + } 1.542 + if (ctxInfo.hasExtension("GL_OES_stencil4")) { 1.543 + fStencilFormats.push_back() = gS4; 1.544 + } 1.545 + } 1.546 + SkASSERT(0 == fStencilVerifiedColorConfigs.count()); 1.547 + fStencilVerifiedColorConfigs.push_back_n(fStencilFormats.count()); 1.548 +} 1.549 + 1.550 +void GrGLCaps::markColorConfigAndStencilFormatAsVerified( 1.551 + GrPixelConfig config, 1.552 + const GrGLStencilBuffer::Format& format) { 1.553 +#if !GR_GL_CHECK_FBO_STATUS_ONCE_PER_FORMAT 1.554 + return; 1.555 +#endif 1.556 + SkASSERT((unsigned)config < (unsigned)kGrPixelConfigCnt); 1.557 + SkASSERT(fStencilFormats.count() == fStencilVerifiedColorConfigs.count()); 1.558 + int count = fStencilFormats.count(); 1.559 + // we expect a really small number of possible formats so linear search 1.560 + // should be OK 1.561 + SkASSERT(count < 16); 1.562 + for (int i = 0; i < count; ++i) { 1.563 + if (format.fInternalFormat == 1.564 + fStencilFormats[i].fInternalFormat) { 1.565 + fStencilVerifiedColorConfigs[i].markVerified(config); 1.566 + return; 1.567 + } 1.568 + } 1.569 + GrCrash("Why are we seeing a stencil format that " 1.570 + "GrGLCaps doesn't know about."); 1.571 +} 1.572 + 1.573 +bool GrGLCaps::isColorConfigAndStencilFormatVerified( 1.574 + GrPixelConfig config, 1.575 + const GrGLStencilBuffer::Format& format) const { 1.576 +#if !GR_GL_CHECK_FBO_STATUS_ONCE_PER_FORMAT 1.577 + return false; 1.578 +#endif 1.579 + SkASSERT((unsigned)config < (unsigned)kGrPixelConfigCnt); 1.580 + int count = fStencilFormats.count(); 1.581 + // we expect a really small number of possible formats so linear search 1.582 + // should be OK 1.583 + SkASSERT(count < 16); 1.584 + for (int i = 0; i < count; ++i) { 1.585 + if (format.fInternalFormat == 1.586 + fStencilFormats[i].fInternalFormat) { 1.587 + return fStencilVerifiedColorConfigs[i].isVerified(config); 1.588 + } 1.589 + } 1.590 + GrCrash("Why are we seeing a stencil format that " 1.591 + "GLCaps doesn't know about."); 1.592 + return false; 1.593 +} 1.594 + 1.595 +SkString GrGLCaps::dump() const { 1.596 + 1.597 + SkString r = INHERITED::dump(); 1.598 + 1.599 + r.appendf("--- GL-Specific ---\n"); 1.600 + for (int i = 0; i < fStencilFormats.count(); ++i) { 1.601 + r.appendf("Stencil Format %d, stencil bits: %02d, total bits: %02d\n", 1.602 + i, 1.603 + fStencilFormats[i].fStencilBits, 1.604 + fStencilFormats[i].fTotalBits); 1.605 + } 1.606 + 1.607 + static const char* kMSFBOExtStr[] = { 1.608 + "None", 1.609 + "ARB", 1.610 + "EXT", 1.611 + "ES 3.0", 1.612 + "Apple", 1.613 + "IMG MS To Texture", 1.614 + "EXT MS To Texture", 1.615 + }; 1.616 + GR_STATIC_ASSERT(0 == kNone_MSFBOType); 1.617 + GR_STATIC_ASSERT(1 == kDesktop_ARB_MSFBOType); 1.618 + GR_STATIC_ASSERT(2 == kDesktop_EXT_MSFBOType); 1.619 + GR_STATIC_ASSERT(3 == kES_3_0_MSFBOType); 1.620 + GR_STATIC_ASSERT(4 == kES_Apple_MSFBOType); 1.621 + GR_STATIC_ASSERT(5 == kES_IMG_MsToTexture_MSFBOType); 1.622 + GR_STATIC_ASSERT(6 == kES_EXT_MsToTexture_MSFBOType); 1.623 + GR_STATIC_ASSERT(GR_ARRAY_COUNT(kMSFBOExtStr) == kLast_MSFBOType + 1); 1.624 + 1.625 + static const char* kFBFetchTypeStr[] = { 1.626 + "None", 1.627 + "EXT", 1.628 + "NV", 1.629 + }; 1.630 + GR_STATIC_ASSERT(0 == kNone_FBFetchType); 1.631 + GR_STATIC_ASSERT(1 == kEXT_FBFetchType); 1.632 + GR_STATIC_ASSERT(2 == kNV_FBFetchType); 1.633 + GR_STATIC_ASSERT(GR_ARRAY_COUNT(kFBFetchTypeStr) == kLast_FBFetchType + 1); 1.634 + 1.635 + 1.636 + r.appendf("Core Profile: %s\n", (fIsCoreProfile ? "YES" : "NO")); 1.637 + r.appendf("Fixed Function Support: %s\n", (fFixedFunctionSupport ? "YES" : "NO")); 1.638 + r.appendf("MSAA Type: %s\n", kMSFBOExtStr[fMSFBOType]); 1.639 + r.appendf("FB Fetch Type: %s\n", kFBFetchTypeStr[fFBFetchType]); 1.640 + r.appendf("Max FS Uniform Vectors: %d\n", fMaxFragmentUniformVectors); 1.641 + r.appendf("Max FS Texture Units: %d\n", fMaxFragmentTextureUnits); 1.642 + if (fFixedFunctionSupport) { 1.643 + r.appendf("Max Fixed Function Texture Coords: %d\n", fMaxFixedFunctionTextureCoords); 1.644 + } 1.645 + r.appendf("Max Vertex Attributes: %d\n", fMaxVertexAttributes); 1.646 + r.appendf("Support RGBA8 Render Buffer: %s\n", (fRGBA8RenderbufferSupport ? "YES": "NO")); 1.647 + r.appendf("BGRA support: %s\n", (fBGRAFormatSupport ? "YES": "NO")); 1.648 + r.appendf("BGRA is an internal format: %s\n", (fBGRAIsInternalFormat ? "YES": "NO")); 1.649 + r.appendf("Support texture swizzle: %s\n", (fTextureSwizzleSupport ? "YES": "NO")); 1.650 + r.appendf("Unpack Row length support: %s\n", (fUnpackRowLengthSupport ? "YES": "NO")); 1.651 + r.appendf("Unpack Flip Y support: %s\n", (fUnpackFlipYSupport ? "YES": "NO")); 1.652 + r.appendf("Pack Row length support: %s\n", (fPackRowLengthSupport ? "YES": "NO")); 1.653 + r.appendf("Pack Flip Y support: %s\n", (fPackFlipYSupport ? "YES": "NO")); 1.654 + 1.655 + r.appendf("Texture Usage support: %s\n", (fTextureUsageSupport ? "YES": "NO")); 1.656 + r.appendf("Texture Storage support: %s\n", (fTexStorageSupport ? "YES": "NO")); 1.657 + r.appendf("GL_R support: %s\n", (fTextureRedSupport ? "YES": "NO")); 1.658 + r.appendf("GL_ARB_imaging support: %s\n", (fImagingSupport ? "YES": "NO")); 1.659 + r.appendf("Two Format Limit: %s\n", (fTwoFormatLimit ? "YES": "NO")); 1.660 + r.appendf("Fragment coord conventions support: %s\n", 1.661 + (fFragCoordsConventionSupport ? "YES": "NO")); 1.662 + r.appendf("Vertex array object support: %s\n", (fVertexArrayObjectSupport ? "YES": "NO")); 1.663 + r.appendf("Use non-VBO for dynamic data: %s\n", 1.664 + (fUseNonVBOVertexAndIndexDynamicData ? "YES" : "NO")); 1.665 + r.appendf("Discard FrameBuffer support: %s\n", (fDiscardFBSupport ? "YES" : "NO")); 1.666 + r.appendf("Full screen clear is free: %s\n", (fFullClearIsFree ? "YES" : "NO")); 1.667 + return r; 1.668 +}