gfx/skia/trunk/src/gpu/gl/GrGLCaps.cpp

Sat, 03 Jan 2015 20:18:00 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Sat, 03 Jan 2015 20:18:00 +0100
branch
TOR_BUG_3246
changeset 7
129ffea94266
permissions
-rw-r--r--

Conditionally enable double key logic according to:
private browsing mode or privacy.thirdparty.isolate preference and
implement in GetCookieStringCommon and FindCookie where it counts...
With some reservations of how to convince FindCookie users to test
condition and pass a nullptr when disabling double key logic.

michael@0 1 /*
michael@0 2 * Copyright 2012 Google Inc.
michael@0 3 *
michael@0 4 * Use of this source code is governed by a BSD-style license that can be
michael@0 5 * found in the LICENSE file.
michael@0 6 */
michael@0 7
michael@0 8
michael@0 9 #include "GrGLCaps.h"
michael@0 10 #include "GrGLContext.h"
michael@0 11 #include "SkTSearch.h"
michael@0 12 #include "SkTSort.h"
michael@0 13
michael@0 14 GrGLCaps::GrGLCaps() {
michael@0 15 this->reset();
michael@0 16 }
michael@0 17
michael@0 18 void GrGLCaps::reset() {
michael@0 19 INHERITED::reset();
michael@0 20
michael@0 21 fVerifiedColorConfigs.reset();
michael@0 22 fStencilFormats.reset();
michael@0 23 fStencilVerifiedColorConfigs.reset();
michael@0 24 fMSFBOType = kNone_MSFBOType;
michael@0 25 fFBFetchType = kNone_FBFetchType;
michael@0 26 fMaxFragmentUniformVectors = 0;
michael@0 27 fMaxVertexAttributes = 0;
michael@0 28 fMaxFragmentTextureUnits = 0;
michael@0 29 fMaxFixedFunctionTextureCoords = 0;
michael@0 30 fRGBA8RenderbufferSupport = false;
michael@0 31 fBGRAFormatSupport = false;
michael@0 32 fBGRAIsInternalFormat = false;
michael@0 33 fTextureSwizzleSupport = false;
michael@0 34 fUnpackRowLengthSupport = false;
michael@0 35 fUnpackFlipYSupport = false;
michael@0 36 fPackRowLengthSupport = false;
michael@0 37 fPackFlipYSupport = false;
michael@0 38 fTextureUsageSupport = false;
michael@0 39 fTexStorageSupport = false;
michael@0 40 fTextureRedSupport = false;
michael@0 41 fImagingSupport = false;
michael@0 42 fTwoFormatLimit = false;
michael@0 43 fFragCoordsConventionSupport = false;
michael@0 44 fVertexArrayObjectSupport = false;
michael@0 45 fUseNonVBOVertexAndIndexDynamicData = false;
michael@0 46 fIsCoreProfile = false;
michael@0 47 fFixedFunctionSupport = false;
michael@0 48 fDiscardFBSupport = false;
michael@0 49 fFullClearIsFree = false;
michael@0 50 }
michael@0 51
michael@0 52 GrGLCaps::GrGLCaps(const GrGLCaps& caps) : GrDrawTargetCaps() {
michael@0 53 *this = caps;
michael@0 54 }
michael@0 55
michael@0 56 GrGLCaps& GrGLCaps::operator = (const GrGLCaps& caps) {
michael@0 57 INHERITED::operator=(caps);
michael@0 58 fVerifiedColorConfigs = caps.fVerifiedColorConfigs;
michael@0 59 fStencilFormats = caps.fStencilFormats;
michael@0 60 fStencilVerifiedColorConfigs = caps.fStencilVerifiedColorConfigs;
michael@0 61 fMaxFragmentUniformVectors = caps.fMaxFragmentUniformVectors;
michael@0 62 fMaxVertexAttributes = caps.fMaxVertexAttributes;
michael@0 63 fMaxFragmentTextureUnits = caps.fMaxFragmentTextureUnits;
michael@0 64 fMaxFixedFunctionTextureCoords = caps.fMaxFixedFunctionTextureCoords;
michael@0 65 fMSFBOType = caps.fMSFBOType;
michael@0 66 fFBFetchType = caps.fFBFetchType;
michael@0 67 fRGBA8RenderbufferSupport = caps.fRGBA8RenderbufferSupport;
michael@0 68 fBGRAFormatSupport = caps.fBGRAFormatSupport;
michael@0 69 fBGRAIsInternalFormat = caps.fBGRAIsInternalFormat;
michael@0 70 fTextureSwizzleSupport = caps.fTextureSwizzleSupport;
michael@0 71 fUnpackRowLengthSupport = caps.fUnpackRowLengthSupport;
michael@0 72 fUnpackFlipYSupport = caps.fUnpackFlipYSupport;
michael@0 73 fPackRowLengthSupport = caps.fPackRowLengthSupport;
michael@0 74 fPackFlipYSupport = caps.fPackFlipYSupport;
michael@0 75 fTextureUsageSupport = caps.fTextureUsageSupport;
michael@0 76 fTexStorageSupport = caps.fTexStorageSupport;
michael@0 77 fTextureRedSupport = caps.fTextureRedSupport;
michael@0 78 fImagingSupport = caps.fImagingSupport;
michael@0 79 fTwoFormatLimit = caps.fTwoFormatLimit;
michael@0 80 fFragCoordsConventionSupport = caps.fFragCoordsConventionSupport;
michael@0 81 fVertexArrayObjectSupport = caps.fVertexArrayObjectSupport;
michael@0 82 fUseNonVBOVertexAndIndexDynamicData = caps.fUseNonVBOVertexAndIndexDynamicData;
michael@0 83 fIsCoreProfile = caps.fIsCoreProfile;
michael@0 84 fFixedFunctionSupport = caps.fFixedFunctionSupport;
michael@0 85 fDiscardFBSupport = caps.fDiscardFBSupport;
michael@0 86 fFullClearIsFree = caps.fFullClearIsFree;
michael@0 87
michael@0 88 return *this;
michael@0 89 }
michael@0 90
michael@0 91 void GrGLCaps::init(const GrGLContextInfo& ctxInfo, const GrGLInterface* gli) {
michael@0 92
michael@0 93 this->reset();
michael@0 94 if (!ctxInfo.isInitialized()) {
michael@0 95 return;
michael@0 96 }
michael@0 97
michael@0 98 GrGLStandard standard = ctxInfo.standard();
michael@0 99 GrGLVersion version = ctxInfo.version();
michael@0 100
michael@0 101 /**************************************************************************
michael@0 102 * Caps specific to GrGLCaps
michael@0 103 **************************************************************************/
michael@0 104
michael@0 105 if (kGLES_GrGLStandard == standard) {
michael@0 106 GR_GL_GetIntegerv(gli, GR_GL_MAX_FRAGMENT_UNIFORM_VECTORS,
michael@0 107 &fMaxFragmentUniformVectors);
michael@0 108 } else {
michael@0 109 SkASSERT(kGL_GrGLStandard == standard);
michael@0 110 GrGLint max;
michael@0 111 GR_GL_GetIntegerv(gli, GR_GL_MAX_FRAGMENT_UNIFORM_COMPONENTS, &max);
michael@0 112 fMaxFragmentUniformVectors = max / 4;
michael@0 113 if (version >= GR_GL_VER(3, 2)) {
michael@0 114 GrGLint profileMask;
michael@0 115 GR_GL_GetIntegerv(gli, GR_GL_CONTEXT_PROFILE_MASK, &profileMask);
michael@0 116 fIsCoreProfile = SkToBool(profileMask & GR_GL_CONTEXT_CORE_PROFILE_BIT);
michael@0 117 }
michael@0 118 if (!fIsCoreProfile) {
michael@0 119 fFixedFunctionSupport = true;
michael@0 120 GR_GL_GetIntegerv(gli, GR_GL_MAX_TEXTURE_COORDS, &fMaxFixedFunctionTextureCoords);
michael@0 121 // Sanity check
michael@0 122 SkASSERT(fMaxFixedFunctionTextureCoords > 0 && fMaxFixedFunctionTextureCoords < 128);
michael@0 123 }
michael@0 124 }
michael@0 125 GR_GL_GetIntegerv(gli, GR_GL_MAX_VERTEX_ATTRIBS, &fMaxVertexAttributes);
michael@0 126 GR_GL_GetIntegerv(gli, GR_GL_MAX_TEXTURE_IMAGE_UNITS, &fMaxFragmentTextureUnits);
michael@0 127
michael@0 128 if (kGL_GrGLStandard == standard) {
michael@0 129 fRGBA8RenderbufferSupport = true;
michael@0 130 } else {
michael@0 131 fRGBA8RenderbufferSupport = version >= GR_GL_VER(3,0) ||
michael@0 132 ctxInfo.hasExtension("GL_OES_rgb8_rgba8") ||
michael@0 133 ctxInfo.hasExtension("GL_ARM_rgba8");
michael@0 134 }
michael@0 135
michael@0 136 if (kGL_GrGLStandard == standard) {
michael@0 137 fBGRAFormatSupport = version >= GR_GL_VER(1,2) ||
michael@0 138 ctxInfo.hasExtension("GL_EXT_bgra");
michael@0 139 } else {
michael@0 140 if (ctxInfo.hasExtension("GL_APPLE_texture_format_BGRA8888")) {
michael@0 141 fBGRAFormatSupport = true;
michael@0 142 } else if (ctxInfo.hasExtension("GL_EXT_texture_format_BGRA8888")) {
michael@0 143 fBGRAFormatSupport = true;
michael@0 144 fBGRAIsInternalFormat = true;
michael@0 145 }
michael@0 146 SkASSERT(fBGRAFormatSupport ||
michael@0 147 kSkia8888_GrPixelConfig != kBGRA_8888_GrPixelConfig);
michael@0 148 }
michael@0 149
michael@0 150 if (kGL_GrGLStandard == standard) {
michael@0 151 fTextureSwizzleSupport = version >= GR_GL_VER(3,3) ||
michael@0 152 ctxInfo.hasExtension("GL_ARB_texture_swizzle");
michael@0 153 } else {
michael@0 154 fTextureSwizzleSupport = version >= GR_GL_VER(3,0);
michael@0 155 }
michael@0 156
michael@0 157 if (kGL_GrGLStandard == standard) {
michael@0 158 fUnpackRowLengthSupport = true;
michael@0 159 fUnpackFlipYSupport = false;
michael@0 160 fPackRowLengthSupport = true;
michael@0 161 fPackFlipYSupport = false;
michael@0 162 } else {
michael@0 163 fUnpackRowLengthSupport = version >= GR_GL_VER(3,0) ||
michael@0 164 ctxInfo.hasExtension("GL_EXT_unpack_subimage");
michael@0 165 fUnpackFlipYSupport = ctxInfo.hasExtension("GL_CHROMIUM_flipy");
michael@0 166 fPackRowLengthSupport = version >= GR_GL_VER(3,0) ||
michael@0 167 ctxInfo.hasExtension("GL_NV_pack_subimage");
michael@0 168 fPackFlipYSupport =
michael@0 169 ctxInfo.hasExtension("GL_ANGLE_pack_reverse_row_order");
michael@0 170 }
michael@0 171
michael@0 172 fTextureUsageSupport = (kGLES_GrGLStandard == standard) &&
michael@0 173 ctxInfo.hasExtension("GL_ANGLE_texture_usage");
michael@0 174
michael@0 175 if (kGL_GrGLStandard == standard) {
michael@0 176 // The EXT version can apply to either GL or GLES.
michael@0 177 fTexStorageSupport = version >= GR_GL_VER(4,2) ||
michael@0 178 ctxInfo.hasExtension("GL_ARB_texture_storage") ||
michael@0 179 ctxInfo.hasExtension("GL_EXT_texture_storage");
michael@0 180 } else {
michael@0 181 // Qualcomm Adreno drivers appear to have issues with texture storage.
michael@0 182 fTexStorageSupport = (version >= GR_GL_VER(3,0) &&
michael@0 183 kQualcomm_GrGLVendor != ctxInfo.vendor()) ||
michael@0 184 ctxInfo.hasExtension("GL_EXT_texture_storage");
michael@0 185 }
michael@0 186
michael@0 187 // ARB_texture_rg is part of OpenGL 3.0, but mesa doesn't support it if
michael@0 188 // it doesn't have ARB_texture_rg extension.
michael@0 189 if (kGL_GrGLStandard == standard) {
michael@0 190 if (ctxInfo.isMesa()) {
michael@0 191 fTextureRedSupport = ctxInfo.hasExtension("GL_ARB_texture_rg");
michael@0 192 } else {
michael@0 193 fTextureRedSupport = version >= GR_GL_VER(3,0) ||
michael@0 194 ctxInfo.hasExtension("GL_ARB_texture_rg");
michael@0 195 }
michael@0 196 } else {
michael@0 197 fTextureRedSupport = version >= GR_GL_VER(3,0) ||
michael@0 198 ctxInfo.hasExtension("GL_EXT_texture_rg");
michael@0 199 }
michael@0 200
michael@0 201 fImagingSupport = kGL_GrGLStandard == standard &&
michael@0 202 ctxInfo.hasExtension("GL_ARB_imaging");
michael@0 203
michael@0 204 // ES 2 only guarantees RGBA/uchar + one other format/type combo for
michael@0 205 // ReadPixels. The other format has to checked at run-time since it
michael@0 206 // can change based on which render target is bound
michael@0 207 fTwoFormatLimit = kGLES_GrGLStandard == standard;
michael@0 208
michael@0 209 // Known issue on at least some Intel platforms:
michael@0 210 // http://code.google.com/p/skia/issues/detail?id=946
michael@0 211 if (kIntel_GrGLVendor != ctxInfo.vendor()) {
michael@0 212 fFragCoordsConventionSupport = ctxInfo.glslGeneration() >= k150_GrGLSLGeneration ||
michael@0 213 ctxInfo.hasExtension("GL_ARB_fragment_coord_conventions");
michael@0 214 }
michael@0 215
michael@0 216 // SGX and Mali GPUs that are based on a tiled-deferred architecture that have trouble with
michael@0 217 // frequently changing VBOs. We've measured a performance increase using non-VBO vertex
michael@0 218 // data for dynamic content on these GPUs. Perhaps we should read the renderer string and
michael@0 219 // limit this decision to specific GPU families rather than basing it on the vendor alone.
michael@0 220 if (!GR_GL_MUST_USE_VBO &&
michael@0 221 (kARM_GrGLVendor == ctxInfo.vendor() || kImagination_GrGLVendor == ctxInfo.vendor())) {
michael@0 222 fUseNonVBOVertexAndIndexDynamicData = true;
michael@0 223 }
michael@0 224
michael@0 225 fDiscardFBSupport = ctxInfo.hasExtension("GL_EXT_discard_framebuffer");
michael@0 226
michael@0 227 if (kARM_GrGLVendor == ctxInfo.vendor() || kImagination_GrGLVendor == ctxInfo.vendor()) {
michael@0 228 fFullClearIsFree = true;
michael@0 229 }
michael@0 230
michael@0 231 if (kGL_GrGLStandard == standard) {
michael@0 232 fVertexArrayObjectSupport = version >= GR_GL_VER(3, 0) ||
michael@0 233 ctxInfo.hasExtension("GL_ARB_vertex_array_object");
michael@0 234 } else {
michael@0 235 fVertexArrayObjectSupport = version >= GR_GL_VER(3, 0) ||
michael@0 236 ctxInfo.hasExtension("GL_OES_vertex_array_object");
michael@0 237 }
michael@0 238
michael@0 239 if (kGLES_GrGLStandard == standard) {
michael@0 240 if (ctxInfo.hasExtension("GL_EXT_shader_framebuffer_fetch")) {
michael@0 241 fFBFetchType = kEXT_FBFetchType;
michael@0 242 } else if (ctxInfo.hasExtension("GL_NV_shader_framebuffer_fetch")) {
michael@0 243 fFBFetchType = kNV_FBFetchType;
michael@0 244 }
michael@0 245 }
michael@0 246
michael@0 247 this->initFSAASupport(ctxInfo, gli);
michael@0 248 this->initStencilFormats(ctxInfo);
michael@0 249
michael@0 250 /**************************************************************************
michael@0 251 * GrDrawTargetCaps fields
michael@0 252 **************************************************************************/
michael@0 253 GrGLint numFormats;
michael@0 254 GR_GL_GetIntegerv(gli, GR_GL_NUM_COMPRESSED_TEXTURE_FORMATS, &numFormats);
michael@0 255 if (numFormats) {
michael@0 256 SkAutoSTMalloc<10, GrGLint> formats(numFormats);
michael@0 257 GR_GL_GetIntegerv(gli, GR_GL_COMPRESSED_TEXTURE_FORMATS, formats);
michael@0 258 for (int i = 0; i < numFormats; ++i) {
michael@0 259 if (formats[i] == GR_GL_PALETTE8_RGBA8) {
michael@0 260 f8BitPaletteSupport = true;
michael@0 261 break;
michael@0 262 }
michael@0 263 }
michael@0 264 }
michael@0 265
michael@0 266 if (kGL_GrGLStandard == standard) {
michael@0 267 // we could also look for GL_ATI_separate_stencil extension or
michael@0 268 // GL_EXT_stencil_two_side but they use different function signatures
michael@0 269 // than GL2.0+ (and than each other).
michael@0 270 fTwoSidedStencilSupport = (ctxInfo.version() >= GR_GL_VER(2,0));
michael@0 271 // supported on GL 1.4 and higher or by extension
michael@0 272 fStencilWrapOpsSupport = (ctxInfo.version() >= GR_GL_VER(1,4)) ||
michael@0 273 ctxInfo.hasExtension("GL_EXT_stencil_wrap");
michael@0 274 } else {
michael@0 275 // ES 2 has two sided stencil and stencil wrap
michael@0 276 fTwoSidedStencilSupport = true;
michael@0 277 fStencilWrapOpsSupport = true;
michael@0 278 }
michael@0 279
michael@0 280 if (kGL_GrGLStandard == standard) {
michael@0 281 fBufferLockSupport = true; // we require VBO support and the desktop VBO extension includes
michael@0 282 // glMapBuffer.
michael@0 283 } else {
michael@0 284 fBufferLockSupport = ctxInfo.hasExtension("GL_OES_mapbuffer");
michael@0 285 }
michael@0 286
michael@0 287 if (kGL_GrGLStandard == standard) {
michael@0 288 SkASSERT(ctxInfo.version() >= GR_GL_VER(2,0) ||
michael@0 289 ctxInfo.hasExtension("GL_ARB_texture_non_power_of_two"));
michael@0 290 fNPOTTextureTileSupport = true;
michael@0 291 fMipMapSupport = true;
michael@0 292 } else {
michael@0 293 // Unextended ES2 supports NPOT textures with clamp_to_edge and non-mip filters only
michael@0 294 // ES3 has no limitations.
michael@0 295 fNPOTTextureTileSupport = ctxInfo.version() >= GR_GL_VER(3,0) ||
michael@0 296 ctxInfo.hasExtension("GL_OES_texture_npot");
michael@0 297 // ES2 supports MIP mapping for POT textures but our caps don't allow for limited MIP
michael@0 298 // support. The OES extension or ES 3.0 allow for MIPS on NPOT textures. So, apparently,
michael@0 299 // does the undocumented GL_IMG_texture_npot extension. This extension does not seem to
michael@0 300 // to alllow arbitrary wrap modes, however.
michael@0 301 fMipMapSupport = fNPOTTextureTileSupport || ctxInfo.hasExtension("GL_IMG_texture_npot");
michael@0 302 }
michael@0 303
michael@0 304 fHWAALineSupport = (kGL_GrGLStandard == standard);
michael@0 305
michael@0 306 GR_GL_GetIntegerv(gli, GR_GL_MAX_TEXTURE_SIZE, &fMaxTextureSize);
michael@0 307 GR_GL_GetIntegerv(gli, GR_GL_MAX_RENDERBUFFER_SIZE, &fMaxRenderTargetSize);
michael@0 308 // Our render targets are always created with textures as the color
michael@0 309 // attachment, hence this min:
michael@0 310 fMaxRenderTargetSize = GrMin(fMaxTextureSize, fMaxRenderTargetSize);
michael@0 311
michael@0 312 fPathRenderingSupport = ctxInfo.hasExtension("GL_NV_path_rendering");
michael@0 313 SkASSERT(!fPathRenderingSupport || fFixedFunctionSupport);
michael@0 314
michael@0 315 fGpuTracingSupport = ctxInfo.hasExtension("GL_EXT_debug_marker");
michael@0 316
michael@0 317 fDstReadInShaderSupport = kNone_FBFetchType != fFBFetchType;
michael@0 318
michael@0 319 // Disable scratch texture reuse on Mali and Adreno devices
michael@0 320 fReuseScratchTextures = kARM_GrGLVendor != ctxInfo.vendor() &&
michael@0 321 kQualcomm_GrGLVendor != ctxInfo.vendor();
michael@0 322
michael@0 323 // Enable supported shader-related caps
michael@0 324 if (kGL_GrGLStandard == standard) {
michael@0 325 fDualSourceBlendingSupport = ctxInfo.version() >= GR_GL_VER(3,3) ||
michael@0 326 ctxInfo.hasExtension("GL_ARB_blend_func_extended");
michael@0 327 fShaderDerivativeSupport = true;
michael@0 328 // we don't support GL_ARB_geometry_shader4, just GL 3.2+ GS
michael@0 329 fGeometryShaderSupport = ctxInfo.version() >= GR_GL_VER(3,2) &&
michael@0 330 ctxInfo.glslGeneration() >= k150_GrGLSLGeneration;
michael@0 331 } else {
michael@0 332 fShaderDerivativeSupport = ctxInfo.hasExtension("GL_OES_standard_derivatives");
michael@0 333 }
michael@0 334
michael@0 335 if (GrGLCaps::kES_IMG_MsToTexture_MSFBOType == fMSFBOType) {
michael@0 336 GR_GL_GetIntegerv(gli, GR_GL_MAX_SAMPLES_IMG, &fMaxSampleCount);
michael@0 337 } else if (GrGLCaps::kNone_MSFBOType != fMSFBOType) {
michael@0 338 GR_GL_GetIntegerv(gli, GR_GL_MAX_SAMPLES, &fMaxSampleCount);
michael@0 339 }
michael@0 340
michael@0 341 this->initConfigRenderableTable(ctxInfo);
michael@0 342 }
michael@0 343
michael@0 344 void GrGLCaps::initConfigRenderableTable(const GrGLContextInfo& ctxInfo) {
michael@0 345
michael@0 346 // OpenGL < 3.0
michael@0 347 // no support for render targets unless the GL_ARB_framebuffer_object
michael@0 348 // extension is supported (in which case we get ALPHA, RED, RG, RGB,
michael@0 349 // RGBA (ALPHA8, RGBA4, RGBA8) for OpenGL > 1.1). Note that we
michael@0 350 // probably don't get R8 in this case.
michael@0 351
michael@0 352 // OpenGL 3.0
michael@0 353 // base color renderable: ALPHA, RED, RG, RGB, and RGBA
michael@0 354 // sized derivatives: ALPHA8, R8, RGBA4, RGBA8
michael@0 355
michael@0 356 // >= OpenGL 3.1
michael@0 357 // base color renderable: RED, RG, RGB, and RGBA
michael@0 358 // sized derivatives: R8, RGBA4, RGBA8
michael@0 359 // if the GL_ARB_compatibility extension is supported then we get back
michael@0 360 // support for GL_ALPHA and ALPHA8
michael@0 361
michael@0 362 // GL_EXT_bgra adds BGRA render targets to any version
michael@0 363
michael@0 364 // ES 2.0
michael@0 365 // color renderable: RGBA4, RGB5_A1, RGB565
michael@0 366 // GL_EXT_texture_rg adds support for R8 as a color render target
michael@0 367 // GL_OES_rgb8_rgba8 and/or GL_ARM_rgba8 adds support for RGBA8
michael@0 368 // GL_EXT_texture_format_BGRA8888 and/or GL_APPLE_texture_format_BGRA8888 added BGRA support
michael@0 369
michael@0 370 // ES 3.0
michael@0 371 // Same as ES 2.0 except R8 and RGBA8 are supported without extensions (the functions called
michael@0 372 // below already account for this).
michael@0 373
michael@0 374 enum {
michael@0 375 kNo_MSAA = 0,
michael@0 376 kYes_MSAA = 1,
michael@0 377 };
michael@0 378
michael@0 379 if (kGL_GrGLStandard == ctxInfo.standard()) {
michael@0 380 // Post 3.0 we will get R8
michael@0 381 // Prior to 3.0 we will get ALPHA8 (with GL_ARB_framebuffer_object)
michael@0 382 if (ctxInfo.version() >= GR_GL_VER(3,0) ||
michael@0 383 ctxInfo.hasExtension("GL_ARB_framebuffer_object")) {
michael@0 384 fConfigRenderSupport[kAlpha_8_GrPixelConfig][kNo_MSAA] = true;
michael@0 385 fConfigRenderSupport[kAlpha_8_GrPixelConfig][kYes_MSAA] = true;
michael@0 386 }
michael@0 387 } else {
michael@0 388 // On ES we can only hope for R8
michael@0 389 fConfigRenderSupport[kAlpha_8_GrPixelConfig][kNo_MSAA] = fTextureRedSupport;
michael@0 390 fConfigRenderSupport[kAlpha_8_GrPixelConfig][kYes_MSAA] = fTextureRedSupport;
michael@0 391 }
michael@0 392
michael@0 393 if (kGL_GrGLStandard != ctxInfo.standard()) {
michael@0 394 // only available in ES
michael@0 395 fConfigRenderSupport[kRGB_565_GrPixelConfig][kNo_MSAA] = true;
michael@0 396 fConfigRenderSupport[kRGB_565_GrPixelConfig][kYes_MSAA] = true;
michael@0 397 }
michael@0 398
michael@0 399 // we no longer support 444 as a render target
michael@0 400 fConfigRenderSupport[kRGBA_4444_GrPixelConfig][kNo_MSAA] = false;
michael@0 401 fConfigRenderSupport[kRGBA_4444_GrPixelConfig][kYes_MSAA] = false;
michael@0 402
michael@0 403 if (this->fRGBA8RenderbufferSupport) {
michael@0 404 fConfigRenderSupport[kRGBA_8888_GrPixelConfig][kNo_MSAA] = true;
michael@0 405 fConfigRenderSupport[kRGBA_8888_GrPixelConfig][kYes_MSAA] = true;
michael@0 406 }
michael@0 407
michael@0 408 if (this->fBGRAFormatSupport) {
michael@0 409 fConfigRenderSupport[kBGRA_8888_GrPixelConfig][kNo_MSAA] = true;
michael@0 410 // The GL_EXT_texture_format_BGRA8888 extension does not add BGRA to the list of
michael@0 411 // configs that are color-renderable and can be passed to glRenderBufferStorageMultisample.
michael@0 412 // Chromium may have an extension to allow BGRA renderbuffers to work on desktop platforms.
michael@0 413 if (ctxInfo.hasExtension("GL_CHROMIUM_renderbuffer_format_BGRA8888")) {
michael@0 414 fConfigRenderSupport[kBGRA_8888_GrPixelConfig][kYes_MSAA] = true;
michael@0 415 } else {
michael@0 416 fConfigRenderSupport[kBGRA_8888_GrPixelConfig][kYes_MSAA] =
michael@0 417 !fBGRAIsInternalFormat || !this->usesMSAARenderBuffers();
michael@0 418 }
michael@0 419 }
michael@0 420
michael@0 421 // If we don't support MSAA then undo any places above where we set a config as renderable with
michael@0 422 // msaa.
michael@0 423 if (kNone_MSFBOType == fMSFBOType) {
michael@0 424 for (int i = 0; i < kGrPixelConfigCnt; ++i) {
michael@0 425 fConfigRenderSupport[i][kYes_MSAA] = false;
michael@0 426 }
michael@0 427 }
michael@0 428 }
michael@0 429
michael@0 430 bool GrGLCaps::readPixelsSupported(const GrGLInterface* intf,
michael@0 431 GrGLenum format,
michael@0 432 GrGLenum type) const {
michael@0 433 if (GR_GL_RGBA == format && GR_GL_UNSIGNED_BYTE == type) {
michael@0 434 // ES 2 guarantees this format is supported
michael@0 435 return true;
michael@0 436 }
michael@0 437
michael@0 438 if (!fTwoFormatLimit) {
michael@0 439 // not limited by ES 2's constraints
michael@0 440 return true;
michael@0 441 }
michael@0 442
michael@0 443 GrGLint otherFormat = GR_GL_RGBA;
michael@0 444 GrGLint otherType = GR_GL_UNSIGNED_BYTE;
michael@0 445
michael@0 446 // The other supported format/type combo supported for ReadPixels
michael@0 447 // can change based on which render target is bound
michael@0 448 GR_GL_GetIntegerv(intf,
michael@0 449 GR_GL_IMPLEMENTATION_COLOR_READ_FORMAT,
michael@0 450 &otherFormat);
michael@0 451
michael@0 452 GR_GL_GetIntegerv(intf,
michael@0 453 GR_GL_IMPLEMENTATION_COLOR_READ_TYPE,
michael@0 454 &otherType);
michael@0 455
michael@0 456 return (GrGLenum)otherFormat == format && (GrGLenum)otherType == type;
michael@0 457 }
michael@0 458
michael@0 459 void GrGLCaps::initFSAASupport(const GrGLContextInfo& ctxInfo, const GrGLInterface* gli) {
michael@0 460
michael@0 461 fMSFBOType = kNone_MSFBOType;
michael@0 462 if (kGL_GrGLStandard != ctxInfo.standard()) {
michael@0 463 // We prefer the EXT/IMG extension over ES3 MSAA because we've observed
michael@0 464 // ES3 driver bugs on at least one device with a tiled GPU (N10).
michael@0 465 if (ctxInfo.hasExtension("GL_EXT_multisampled_render_to_texture")) {
michael@0 466 fMSFBOType = kES_EXT_MsToTexture_MSFBOType;
michael@0 467 } else if (ctxInfo.hasExtension("GL_IMG_multisampled_render_to_texture")) {
michael@0 468 fMSFBOType = kES_IMG_MsToTexture_MSFBOType;
michael@0 469 } else if (ctxInfo.version() >= GR_GL_VER(3,0)) {
michael@0 470 fMSFBOType = GrGLCaps::kES_3_0_MSFBOType;
michael@0 471 } else if (ctxInfo.hasExtension("GL_CHROMIUM_framebuffer_multisample")) {
michael@0 472 // chrome's extension is equivalent to the EXT msaa
michael@0 473 // and fbo_blit extensions.
michael@0 474 fMSFBOType = kDesktop_EXT_MSFBOType;
michael@0 475 } else if (ctxInfo.hasExtension("GL_APPLE_framebuffer_multisample")) {
michael@0 476 fMSFBOType = kES_Apple_MSFBOType;
michael@0 477 }
michael@0 478 } else {
michael@0 479 if ((ctxInfo.version() >= GR_GL_VER(3,0)) ||
michael@0 480 ctxInfo.hasExtension("GL_ARB_framebuffer_object")) {
michael@0 481 fMSFBOType = GrGLCaps::kDesktop_ARB_MSFBOType;
michael@0 482 } else if (ctxInfo.hasExtension("GL_EXT_framebuffer_multisample") &&
michael@0 483 ctxInfo.hasExtension("GL_EXT_framebuffer_blit")) {
michael@0 484 fMSFBOType = GrGLCaps::kDesktop_EXT_MSFBOType;
michael@0 485 }
michael@0 486 }
michael@0 487 }
michael@0 488
michael@0 489 namespace {
michael@0 490 const GrGLuint kUnknownBitCount = GrGLStencilBuffer::kUnknownBitCount;
michael@0 491 }
michael@0 492
michael@0 493 void GrGLCaps::initStencilFormats(const GrGLContextInfo& ctxInfo) {
michael@0 494
michael@0 495 // Build up list of legal stencil formats (though perhaps not supported on
michael@0 496 // the particular gpu/driver) from most preferred to least.
michael@0 497
michael@0 498 // these consts are in order of most preferred to least preferred
michael@0 499 // we don't bother with GL_STENCIL_INDEX1 or GL_DEPTH32F_STENCIL8
michael@0 500
michael@0 501 static const StencilFormat
michael@0 502 // internal Format stencil bits total bits packed?
michael@0 503 gS8 = {GR_GL_STENCIL_INDEX8, 8, 8, false},
michael@0 504 gS16 = {GR_GL_STENCIL_INDEX16, 16, 16, false},
michael@0 505 gD24S8 = {GR_GL_DEPTH24_STENCIL8, 8, 32, true },
michael@0 506 gS4 = {GR_GL_STENCIL_INDEX4, 4, 4, false},
michael@0 507 // gS = {GR_GL_STENCIL_INDEX, kUnknownBitCount, kUnknownBitCount, false},
michael@0 508 gDS = {GR_GL_DEPTH_STENCIL, kUnknownBitCount, kUnknownBitCount, true };
michael@0 509
michael@0 510 if (kGL_GrGLStandard == ctxInfo.standard()) {
michael@0 511 bool supportsPackedDS =
michael@0 512 ctxInfo.version() >= GR_GL_VER(3,0) ||
michael@0 513 ctxInfo.hasExtension("GL_EXT_packed_depth_stencil") ||
michael@0 514 ctxInfo.hasExtension("GL_ARB_framebuffer_object");
michael@0 515
michael@0 516 // S1 thru S16 formats are in GL 3.0+, EXT_FBO, and ARB_FBO since we
michael@0 517 // require FBO support we can expect these are legal formats and don't
michael@0 518 // check. These also all support the unsized GL_STENCIL_INDEX.
michael@0 519 fStencilFormats.push_back() = gS8;
michael@0 520 fStencilFormats.push_back() = gS16;
michael@0 521 if (supportsPackedDS) {
michael@0 522 fStencilFormats.push_back() = gD24S8;
michael@0 523 }
michael@0 524 fStencilFormats.push_back() = gS4;
michael@0 525 if (supportsPackedDS) {
michael@0 526 fStencilFormats.push_back() = gDS;
michael@0 527 }
michael@0 528 } else {
michael@0 529 // ES2 has STENCIL_INDEX8 without extensions but requires extensions
michael@0 530 // for other formats.
michael@0 531 // ES doesn't support using the unsized format.
michael@0 532
michael@0 533 fStencilFormats.push_back() = gS8;
michael@0 534 //fStencilFormats.push_back() = gS16;
michael@0 535 if (ctxInfo.version() >= GR_GL_VER(3,0) ||
michael@0 536 ctxInfo.hasExtension("GL_OES_packed_depth_stencil")) {
michael@0 537 fStencilFormats.push_back() = gD24S8;
michael@0 538 }
michael@0 539 if (ctxInfo.hasExtension("GL_OES_stencil4")) {
michael@0 540 fStencilFormats.push_back() = gS4;
michael@0 541 }
michael@0 542 }
michael@0 543 SkASSERT(0 == fStencilVerifiedColorConfigs.count());
michael@0 544 fStencilVerifiedColorConfigs.push_back_n(fStencilFormats.count());
michael@0 545 }
michael@0 546
michael@0 547 void GrGLCaps::markColorConfigAndStencilFormatAsVerified(
michael@0 548 GrPixelConfig config,
michael@0 549 const GrGLStencilBuffer::Format& format) {
michael@0 550 #if !GR_GL_CHECK_FBO_STATUS_ONCE_PER_FORMAT
michael@0 551 return;
michael@0 552 #endif
michael@0 553 SkASSERT((unsigned)config < (unsigned)kGrPixelConfigCnt);
michael@0 554 SkASSERT(fStencilFormats.count() == fStencilVerifiedColorConfigs.count());
michael@0 555 int count = fStencilFormats.count();
michael@0 556 // we expect a really small number of possible formats so linear search
michael@0 557 // should be OK
michael@0 558 SkASSERT(count < 16);
michael@0 559 for (int i = 0; i < count; ++i) {
michael@0 560 if (format.fInternalFormat ==
michael@0 561 fStencilFormats[i].fInternalFormat) {
michael@0 562 fStencilVerifiedColorConfigs[i].markVerified(config);
michael@0 563 return;
michael@0 564 }
michael@0 565 }
michael@0 566 GrCrash("Why are we seeing a stencil format that "
michael@0 567 "GrGLCaps doesn't know about.");
michael@0 568 }
michael@0 569
michael@0 570 bool GrGLCaps::isColorConfigAndStencilFormatVerified(
michael@0 571 GrPixelConfig config,
michael@0 572 const GrGLStencilBuffer::Format& format) const {
michael@0 573 #if !GR_GL_CHECK_FBO_STATUS_ONCE_PER_FORMAT
michael@0 574 return false;
michael@0 575 #endif
michael@0 576 SkASSERT((unsigned)config < (unsigned)kGrPixelConfigCnt);
michael@0 577 int count = fStencilFormats.count();
michael@0 578 // we expect a really small number of possible formats so linear search
michael@0 579 // should be OK
michael@0 580 SkASSERT(count < 16);
michael@0 581 for (int i = 0; i < count; ++i) {
michael@0 582 if (format.fInternalFormat ==
michael@0 583 fStencilFormats[i].fInternalFormat) {
michael@0 584 return fStencilVerifiedColorConfigs[i].isVerified(config);
michael@0 585 }
michael@0 586 }
michael@0 587 GrCrash("Why are we seeing a stencil format that "
michael@0 588 "GLCaps doesn't know about.");
michael@0 589 return false;
michael@0 590 }
michael@0 591
michael@0 592 SkString GrGLCaps::dump() const {
michael@0 593
michael@0 594 SkString r = INHERITED::dump();
michael@0 595
michael@0 596 r.appendf("--- GL-Specific ---\n");
michael@0 597 for (int i = 0; i < fStencilFormats.count(); ++i) {
michael@0 598 r.appendf("Stencil Format %d, stencil bits: %02d, total bits: %02d\n",
michael@0 599 i,
michael@0 600 fStencilFormats[i].fStencilBits,
michael@0 601 fStencilFormats[i].fTotalBits);
michael@0 602 }
michael@0 603
michael@0 604 static const char* kMSFBOExtStr[] = {
michael@0 605 "None",
michael@0 606 "ARB",
michael@0 607 "EXT",
michael@0 608 "ES 3.0",
michael@0 609 "Apple",
michael@0 610 "IMG MS To Texture",
michael@0 611 "EXT MS To Texture",
michael@0 612 };
michael@0 613 GR_STATIC_ASSERT(0 == kNone_MSFBOType);
michael@0 614 GR_STATIC_ASSERT(1 == kDesktop_ARB_MSFBOType);
michael@0 615 GR_STATIC_ASSERT(2 == kDesktop_EXT_MSFBOType);
michael@0 616 GR_STATIC_ASSERT(3 == kES_3_0_MSFBOType);
michael@0 617 GR_STATIC_ASSERT(4 == kES_Apple_MSFBOType);
michael@0 618 GR_STATIC_ASSERT(5 == kES_IMG_MsToTexture_MSFBOType);
michael@0 619 GR_STATIC_ASSERT(6 == kES_EXT_MsToTexture_MSFBOType);
michael@0 620 GR_STATIC_ASSERT(GR_ARRAY_COUNT(kMSFBOExtStr) == kLast_MSFBOType + 1);
michael@0 621
michael@0 622 static const char* kFBFetchTypeStr[] = {
michael@0 623 "None",
michael@0 624 "EXT",
michael@0 625 "NV",
michael@0 626 };
michael@0 627 GR_STATIC_ASSERT(0 == kNone_FBFetchType);
michael@0 628 GR_STATIC_ASSERT(1 == kEXT_FBFetchType);
michael@0 629 GR_STATIC_ASSERT(2 == kNV_FBFetchType);
michael@0 630 GR_STATIC_ASSERT(GR_ARRAY_COUNT(kFBFetchTypeStr) == kLast_FBFetchType + 1);
michael@0 631
michael@0 632
michael@0 633 r.appendf("Core Profile: %s\n", (fIsCoreProfile ? "YES" : "NO"));
michael@0 634 r.appendf("Fixed Function Support: %s\n", (fFixedFunctionSupport ? "YES" : "NO"));
michael@0 635 r.appendf("MSAA Type: %s\n", kMSFBOExtStr[fMSFBOType]);
michael@0 636 r.appendf("FB Fetch Type: %s\n", kFBFetchTypeStr[fFBFetchType]);
michael@0 637 r.appendf("Max FS Uniform Vectors: %d\n", fMaxFragmentUniformVectors);
michael@0 638 r.appendf("Max FS Texture Units: %d\n", fMaxFragmentTextureUnits);
michael@0 639 if (fFixedFunctionSupport) {
michael@0 640 r.appendf("Max Fixed Function Texture Coords: %d\n", fMaxFixedFunctionTextureCoords);
michael@0 641 }
michael@0 642 r.appendf("Max Vertex Attributes: %d\n", fMaxVertexAttributes);
michael@0 643 r.appendf("Support RGBA8 Render Buffer: %s\n", (fRGBA8RenderbufferSupport ? "YES": "NO"));
michael@0 644 r.appendf("BGRA support: %s\n", (fBGRAFormatSupport ? "YES": "NO"));
michael@0 645 r.appendf("BGRA is an internal format: %s\n", (fBGRAIsInternalFormat ? "YES": "NO"));
michael@0 646 r.appendf("Support texture swizzle: %s\n", (fTextureSwizzleSupport ? "YES": "NO"));
michael@0 647 r.appendf("Unpack Row length support: %s\n", (fUnpackRowLengthSupport ? "YES": "NO"));
michael@0 648 r.appendf("Unpack Flip Y support: %s\n", (fUnpackFlipYSupport ? "YES": "NO"));
michael@0 649 r.appendf("Pack Row length support: %s\n", (fPackRowLengthSupport ? "YES": "NO"));
michael@0 650 r.appendf("Pack Flip Y support: %s\n", (fPackFlipYSupport ? "YES": "NO"));
michael@0 651
michael@0 652 r.appendf("Texture Usage support: %s\n", (fTextureUsageSupport ? "YES": "NO"));
michael@0 653 r.appendf("Texture Storage support: %s\n", (fTexStorageSupport ? "YES": "NO"));
michael@0 654 r.appendf("GL_R support: %s\n", (fTextureRedSupport ? "YES": "NO"));
michael@0 655 r.appendf("GL_ARB_imaging support: %s\n", (fImagingSupport ? "YES": "NO"));
michael@0 656 r.appendf("Two Format Limit: %s\n", (fTwoFormatLimit ? "YES": "NO"));
michael@0 657 r.appendf("Fragment coord conventions support: %s\n",
michael@0 658 (fFragCoordsConventionSupport ? "YES": "NO"));
michael@0 659 r.appendf("Vertex array object support: %s\n", (fVertexArrayObjectSupport ? "YES": "NO"));
michael@0 660 r.appendf("Use non-VBO for dynamic data: %s\n",
michael@0 661 (fUseNonVBOVertexAndIndexDynamicData ? "YES" : "NO"));
michael@0 662 r.appendf("Discard FrameBuffer support: %s\n", (fDiscardFBSupport ? "YES" : "NO"));
michael@0 663 r.appendf("Full screen clear is free: %s\n", (fFullClearIsFree ? "YES" : "NO"));
michael@0 664 return r;
michael@0 665 }

mercurial