michael@0: /* michael@0: * Copyright 2012 Google Inc. michael@0: * michael@0: * Use of this source code is governed by a BSD-style license that can be michael@0: * found in the LICENSE file. michael@0: */ michael@0: michael@0: michael@0: #include "GrGLCaps.h" michael@0: #include "GrGLContext.h" michael@0: #include "SkTSearch.h" michael@0: #include "SkTSort.h" michael@0: michael@0: GrGLCaps::GrGLCaps() { michael@0: this->reset(); michael@0: } michael@0: michael@0: void GrGLCaps::reset() { michael@0: INHERITED::reset(); michael@0: michael@0: fVerifiedColorConfigs.reset(); michael@0: fStencilFormats.reset(); michael@0: fStencilVerifiedColorConfigs.reset(); michael@0: fMSFBOType = kNone_MSFBOType; michael@0: fFBFetchType = kNone_FBFetchType; michael@0: fMaxFragmentUniformVectors = 0; michael@0: fMaxVertexAttributes = 0; michael@0: fMaxFragmentTextureUnits = 0; michael@0: fMaxFixedFunctionTextureCoords = 0; michael@0: fRGBA8RenderbufferSupport = false; michael@0: fBGRAFormatSupport = false; michael@0: fBGRAIsInternalFormat = false; michael@0: fTextureSwizzleSupport = false; michael@0: fUnpackRowLengthSupport = false; michael@0: fUnpackFlipYSupport = false; michael@0: fPackRowLengthSupport = false; michael@0: fPackFlipYSupport = false; michael@0: fTextureUsageSupport = false; michael@0: fTexStorageSupport = false; michael@0: fTextureRedSupport = false; michael@0: fImagingSupport = false; michael@0: fTwoFormatLimit = false; michael@0: fFragCoordsConventionSupport = false; michael@0: fVertexArrayObjectSupport = false; michael@0: fUseNonVBOVertexAndIndexDynamicData = false; michael@0: fIsCoreProfile = false; michael@0: fFixedFunctionSupport = false; michael@0: fDiscardFBSupport = false; michael@0: fFullClearIsFree = false; michael@0: } michael@0: michael@0: GrGLCaps::GrGLCaps(const GrGLCaps& caps) : GrDrawTargetCaps() { michael@0: *this = caps; michael@0: } michael@0: michael@0: GrGLCaps& GrGLCaps::operator = (const GrGLCaps& caps) { michael@0: INHERITED::operator=(caps); michael@0: fVerifiedColorConfigs = caps.fVerifiedColorConfigs; michael@0: fStencilFormats = caps.fStencilFormats; michael@0: fStencilVerifiedColorConfigs = caps.fStencilVerifiedColorConfigs; michael@0: fMaxFragmentUniformVectors = caps.fMaxFragmentUniformVectors; michael@0: fMaxVertexAttributes = caps.fMaxVertexAttributes; michael@0: fMaxFragmentTextureUnits = caps.fMaxFragmentTextureUnits; michael@0: fMaxFixedFunctionTextureCoords = caps.fMaxFixedFunctionTextureCoords; michael@0: fMSFBOType = caps.fMSFBOType; michael@0: fFBFetchType = caps.fFBFetchType; michael@0: fRGBA8RenderbufferSupport = caps.fRGBA8RenderbufferSupport; michael@0: fBGRAFormatSupport = caps.fBGRAFormatSupport; michael@0: fBGRAIsInternalFormat = caps.fBGRAIsInternalFormat; michael@0: fTextureSwizzleSupport = caps.fTextureSwizzleSupport; michael@0: fUnpackRowLengthSupport = caps.fUnpackRowLengthSupport; michael@0: fUnpackFlipYSupport = caps.fUnpackFlipYSupport; michael@0: fPackRowLengthSupport = caps.fPackRowLengthSupport; michael@0: fPackFlipYSupport = caps.fPackFlipYSupport; michael@0: fTextureUsageSupport = caps.fTextureUsageSupport; michael@0: fTexStorageSupport = caps.fTexStorageSupport; michael@0: fTextureRedSupport = caps.fTextureRedSupport; michael@0: fImagingSupport = caps.fImagingSupport; michael@0: fTwoFormatLimit = caps.fTwoFormatLimit; michael@0: fFragCoordsConventionSupport = caps.fFragCoordsConventionSupport; michael@0: fVertexArrayObjectSupport = caps.fVertexArrayObjectSupport; michael@0: fUseNonVBOVertexAndIndexDynamicData = caps.fUseNonVBOVertexAndIndexDynamicData; michael@0: fIsCoreProfile = caps.fIsCoreProfile; michael@0: fFixedFunctionSupport = caps.fFixedFunctionSupport; michael@0: fDiscardFBSupport = caps.fDiscardFBSupport; michael@0: fFullClearIsFree = caps.fFullClearIsFree; michael@0: michael@0: return *this; michael@0: } michael@0: michael@0: void GrGLCaps::init(const GrGLContextInfo& ctxInfo, const GrGLInterface* gli) { michael@0: michael@0: this->reset(); michael@0: if (!ctxInfo.isInitialized()) { michael@0: return; michael@0: } michael@0: michael@0: GrGLStandard standard = ctxInfo.standard(); michael@0: GrGLVersion version = ctxInfo.version(); michael@0: michael@0: /************************************************************************** michael@0: * Caps specific to GrGLCaps michael@0: **************************************************************************/ michael@0: michael@0: if (kGLES_GrGLStandard == standard) { michael@0: GR_GL_GetIntegerv(gli, GR_GL_MAX_FRAGMENT_UNIFORM_VECTORS, michael@0: &fMaxFragmentUniformVectors); michael@0: } else { michael@0: SkASSERT(kGL_GrGLStandard == standard); michael@0: GrGLint max; michael@0: GR_GL_GetIntegerv(gli, GR_GL_MAX_FRAGMENT_UNIFORM_COMPONENTS, &max); michael@0: fMaxFragmentUniformVectors = max / 4; michael@0: if (version >= GR_GL_VER(3, 2)) { michael@0: GrGLint profileMask; michael@0: GR_GL_GetIntegerv(gli, GR_GL_CONTEXT_PROFILE_MASK, &profileMask); michael@0: fIsCoreProfile = SkToBool(profileMask & GR_GL_CONTEXT_CORE_PROFILE_BIT); michael@0: } michael@0: if (!fIsCoreProfile) { michael@0: fFixedFunctionSupport = true; michael@0: GR_GL_GetIntegerv(gli, GR_GL_MAX_TEXTURE_COORDS, &fMaxFixedFunctionTextureCoords); michael@0: // Sanity check michael@0: SkASSERT(fMaxFixedFunctionTextureCoords > 0 && fMaxFixedFunctionTextureCoords < 128); michael@0: } michael@0: } michael@0: GR_GL_GetIntegerv(gli, GR_GL_MAX_VERTEX_ATTRIBS, &fMaxVertexAttributes); michael@0: GR_GL_GetIntegerv(gli, GR_GL_MAX_TEXTURE_IMAGE_UNITS, &fMaxFragmentTextureUnits); michael@0: michael@0: if (kGL_GrGLStandard == standard) { michael@0: fRGBA8RenderbufferSupport = true; michael@0: } else { michael@0: fRGBA8RenderbufferSupport = version >= GR_GL_VER(3,0) || michael@0: ctxInfo.hasExtension("GL_OES_rgb8_rgba8") || michael@0: ctxInfo.hasExtension("GL_ARM_rgba8"); michael@0: } michael@0: michael@0: if (kGL_GrGLStandard == standard) { michael@0: fBGRAFormatSupport = version >= GR_GL_VER(1,2) || michael@0: ctxInfo.hasExtension("GL_EXT_bgra"); michael@0: } else { michael@0: if (ctxInfo.hasExtension("GL_APPLE_texture_format_BGRA8888")) { michael@0: fBGRAFormatSupport = true; michael@0: } else if (ctxInfo.hasExtension("GL_EXT_texture_format_BGRA8888")) { michael@0: fBGRAFormatSupport = true; michael@0: fBGRAIsInternalFormat = true; michael@0: } michael@0: SkASSERT(fBGRAFormatSupport || michael@0: kSkia8888_GrPixelConfig != kBGRA_8888_GrPixelConfig); michael@0: } michael@0: michael@0: if (kGL_GrGLStandard == standard) { michael@0: fTextureSwizzleSupport = version >= GR_GL_VER(3,3) || michael@0: ctxInfo.hasExtension("GL_ARB_texture_swizzle"); michael@0: } else { michael@0: fTextureSwizzleSupport = version >= GR_GL_VER(3,0); michael@0: } michael@0: michael@0: if (kGL_GrGLStandard == standard) { michael@0: fUnpackRowLengthSupport = true; michael@0: fUnpackFlipYSupport = false; michael@0: fPackRowLengthSupport = true; michael@0: fPackFlipYSupport = false; michael@0: } else { michael@0: fUnpackRowLengthSupport = version >= GR_GL_VER(3,0) || michael@0: ctxInfo.hasExtension("GL_EXT_unpack_subimage"); michael@0: fUnpackFlipYSupport = ctxInfo.hasExtension("GL_CHROMIUM_flipy"); michael@0: fPackRowLengthSupport = version >= GR_GL_VER(3,0) || michael@0: ctxInfo.hasExtension("GL_NV_pack_subimage"); michael@0: fPackFlipYSupport = michael@0: ctxInfo.hasExtension("GL_ANGLE_pack_reverse_row_order"); michael@0: } michael@0: michael@0: fTextureUsageSupport = (kGLES_GrGLStandard == standard) && michael@0: ctxInfo.hasExtension("GL_ANGLE_texture_usage"); michael@0: michael@0: if (kGL_GrGLStandard == standard) { michael@0: // The EXT version can apply to either GL or GLES. michael@0: fTexStorageSupport = version >= GR_GL_VER(4,2) || michael@0: ctxInfo.hasExtension("GL_ARB_texture_storage") || michael@0: ctxInfo.hasExtension("GL_EXT_texture_storage"); michael@0: } else { michael@0: // Qualcomm Adreno drivers appear to have issues with texture storage. michael@0: fTexStorageSupport = (version >= GR_GL_VER(3,0) && michael@0: kQualcomm_GrGLVendor != ctxInfo.vendor()) || michael@0: ctxInfo.hasExtension("GL_EXT_texture_storage"); michael@0: } michael@0: michael@0: // ARB_texture_rg is part of OpenGL 3.0, but mesa doesn't support it if michael@0: // it doesn't have ARB_texture_rg extension. michael@0: if (kGL_GrGLStandard == standard) { michael@0: if (ctxInfo.isMesa()) { michael@0: fTextureRedSupport = ctxInfo.hasExtension("GL_ARB_texture_rg"); michael@0: } else { michael@0: fTextureRedSupport = version >= GR_GL_VER(3,0) || michael@0: ctxInfo.hasExtension("GL_ARB_texture_rg"); michael@0: } michael@0: } else { michael@0: fTextureRedSupport = version >= GR_GL_VER(3,0) || michael@0: ctxInfo.hasExtension("GL_EXT_texture_rg"); michael@0: } michael@0: michael@0: fImagingSupport = kGL_GrGLStandard == standard && michael@0: ctxInfo.hasExtension("GL_ARB_imaging"); michael@0: michael@0: // ES 2 only guarantees RGBA/uchar + one other format/type combo for michael@0: // ReadPixels. The other format has to checked at run-time since it michael@0: // can change based on which render target is bound michael@0: fTwoFormatLimit = kGLES_GrGLStandard == standard; michael@0: michael@0: // Known issue on at least some Intel platforms: michael@0: // http://code.google.com/p/skia/issues/detail?id=946 michael@0: if (kIntel_GrGLVendor != ctxInfo.vendor()) { michael@0: fFragCoordsConventionSupport = ctxInfo.glslGeneration() >= k150_GrGLSLGeneration || michael@0: ctxInfo.hasExtension("GL_ARB_fragment_coord_conventions"); michael@0: } michael@0: michael@0: // SGX and Mali GPUs that are based on a tiled-deferred architecture that have trouble with michael@0: // frequently changing VBOs. We've measured a performance increase using non-VBO vertex michael@0: // data for dynamic content on these GPUs. Perhaps we should read the renderer string and michael@0: // limit this decision to specific GPU families rather than basing it on the vendor alone. michael@0: if (!GR_GL_MUST_USE_VBO && michael@0: (kARM_GrGLVendor == ctxInfo.vendor() || kImagination_GrGLVendor == ctxInfo.vendor())) { michael@0: fUseNonVBOVertexAndIndexDynamicData = true; michael@0: } michael@0: michael@0: fDiscardFBSupport = ctxInfo.hasExtension("GL_EXT_discard_framebuffer"); michael@0: michael@0: if (kARM_GrGLVendor == ctxInfo.vendor() || kImagination_GrGLVendor == ctxInfo.vendor()) { michael@0: fFullClearIsFree = true; michael@0: } michael@0: michael@0: if (kGL_GrGLStandard == standard) { michael@0: fVertexArrayObjectSupport = version >= GR_GL_VER(3, 0) || michael@0: ctxInfo.hasExtension("GL_ARB_vertex_array_object"); michael@0: } else { michael@0: fVertexArrayObjectSupport = version >= GR_GL_VER(3, 0) || michael@0: ctxInfo.hasExtension("GL_OES_vertex_array_object"); michael@0: } michael@0: michael@0: if (kGLES_GrGLStandard == standard) { michael@0: if (ctxInfo.hasExtension("GL_EXT_shader_framebuffer_fetch")) { michael@0: fFBFetchType = kEXT_FBFetchType; michael@0: } else if (ctxInfo.hasExtension("GL_NV_shader_framebuffer_fetch")) { michael@0: fFBFetchType = kNV_FBFetchType; michael@0: } michael@0: } michael@0: michael@0: this->initFSAASupport(ctxInfo, gli); michael@0: this->initStencilFormats(ctxInfo); michael@0: michael@0: /************************************************************************** michael@0: * GrDrawTargetCaps fields michael@0: **************************************************************************/ michael@0: GrGLint numFormats; michael@0: GR_GL_GetIntegerv(gli, GR_GL_NUM_COMPRESSED_TEXTURE_FORMATS, &numFormats); michael@0: if (numFormats) { michael@0: SkAutoSTMalloc<10, GrGLint> formats(numFormats); michael@0: GR_GL_GetIntegerv(gli, GR_GL_COMPRESSED_TEXTURE_FORMATS, formats); michael@0: for (int i = 0; i < numFormats; ++i) { michael@0: if (formats[i] == GR_GL_PALETTE8_RGBA8) { michael@0: f8BitPaletteSupport = true; michael@0: break; michael@0: } michael@0: } michael@0: } michael@0: michael@0: if (kGL_GrGLStandard == standard) { michael@0: // we could also look for GL_ATI_separate_stencil extension or michael@0: // GL_EXT_stencil_two_side but they use different function signatures michael@0: // than GL2.0+ (and than each other). michael@0: fTwoSidedStencilSupport = (ctxInfo.version() >= GR_GL_VER(2,0)); michael@0: // supported on GL 1.4 and higher or by extension michael@0: fStencilWrapOpsSupport = (ctxInfo.version() >= GR_GL_VER(1,4)) || michael@0: ctxInfo.hasExtension("GL_EXT_stencil_wrap"); michael@0: } else { michael@0: // ES 2 has two sided stencil and stencil wrap michael@0: fTwoSidedStencilSupport = true; michael@0: fStencilWrapOpsSupport = true; michael@0: } michael@0: michael@0: if (kGL_GrGLStandard == standard) { michael@0: fBufferLockSupport = true; // we require VBO support and the desktop VBO extension includes michael@0: // glMapBuffer. michael@0: } else { michael@0: fBufferLockSupport = ctxInfo.hasExtension("GL_OES_mapbuffer"); michael@0: } michael@0: michael@0: if (kGL_GrGLStandard == standard) { michael@0: SkASSERT(ctxInfo.version() >= GR_GL_VER(2,0) || michael@0: ctxInfo.hasExtension("GL_ARB_texture_non_power_of_two")); michael@0: fNPOTTextureTileSupport = true; michael@0: fMipMapSupport = true; michael@0: } else { michael@0: // Unextended ES2 supports NPOT textures with clamp_to_edge and non-mip filters only michael@0: // ES3 has no limitations. michael@0: fNPOTTextureTileSupport = ctxInfo.version() >= GR_GL_VER(3,0) || michael@0: ctxInfo.hasExtension("GL_OES_texture_npot"); michael@0: // ES2 supports MIP mapping for POT textures but our caps don't allow for limited MIP michael@0: // support. The OES extension or ES 3.0 allow for MIPS on NPOT textures. So, apparently, michael@0: // does the undocumented GL_IMG_texture_npot extension. This extension does not seem to michael@0: // to alllow arbitrary wrap modes, however. michael@0: fMipMapSupport = fNPOTTextureTileSupport || ctxInfo.hasExtension("GL_IMG_texture_npot"); michael@0: } michael@0: michael@0: fHWAALineSupport = (kGL_GrGLStandard == standard); michael@0: michael@0: GR_GL_GetIntegerv(gli, GR_GL_MAX_TEXTURE_SIZE, &fMaxTextureSize); michael@0: GR_GL_GetIntegerv(gli, GR_GL_MAX_RENDERBUFFER_SIZE, &fMaxRenderTargetSize); michael@0: // Our render targets are always created with textures as the color michael@0: // attachment, hence this min: michael@0: fMaxRenderTargetSize = GrMin(fMaxTextureSize, fMaxRenderTargetSize); michael@0: michael@0: fPathRenderingSupport = ctxInfo.hasExtension("GL_NV_path_rendering"); michael@0: SkASSERT(!fPathRenderingSupport || fFixedFunctionSupport); michael@0: michael@0: fGpuTracingSupport = ctxInfo.hasExtension("GL_EXT_debug_marker"); michael@0: michael@0: fDstReadInShaderSupport = kNone_FBFetchType != fFBFetchType; michael@0: michael@0: // Disable scratch texture reuse on Mali and Adreno devices michael@0: fReuseScratchTextures = kARM_GrGLVendor != ctxInfo.vendor() && michael@0: kQualcomm_GrGLVendor != ctxInfo.vendor(); michael@0: michael@0: // Enable supported shader-related caps michael@0: if (kGL_GrGLStandard == standard) { michael@0: fDualSourceBlendingSupport = ctxInfo.version() >= GR_GL_VER(3,3) || michael@0: ctxInfo.hasExtension("GL_ARB_blend_func_extended"); michael@0: fShaderDerivativeSupport = true; michael@0: // we don't support GL_ARB_geometry_shader4, just GL 3.2+ GS michael@0: fGeometryShaderSupport = ctxInfo.version() >= GR_GL_VER(3,2) && michael@0: ctxInfo.glslGeneration() >= k150_GrGLSLGeneration; michael@0: } else { michael@0: fShaderDerivativeSupport = ctxInfo.hasExtension("GL_OES_standard_derivatives"); michael@0: } michael@0: michael@0: if (GrGLCaps::kES_IMG_MsToTexture_MSFBOType == fMSFBOType) { michael@0: GR_GL_GetIntegerv(gli, GR_GL_MAX_SAMPLES_IMG, &fMaxSampleCount); michael@0: } else if (GrGLCaps::kNone_MSFBOType != fMSFBOType) { michael@0: GR_GL_GetIntegerv(gli, GR_GL_MAX_SAMPLES, &fMaxSampleCount); michael@0: } michael@0: michael@0: this->initConfigRenderableTable(ctxInfo); michael@0: } michael@0: michael@0: void GrGLCaps::initConfigRenderableTable(const GrGLContextInfo& ctxInfo) { michael@0: michael@0: // OpenGL < 3.0 michael@0: // no support for render targets unless the GL_ARB_framebuffer_object michael@0: // extension is supported (in which case we get ALPHA, RED, RG, RGB, michael@0: // RGBA (ALPHA8, RGBA4, RGBA8) for OpenGL > 1.1). Note that we michael@0: // probably don't get R8 in this case. michael@0: michael@0: // OpenGL 3.0 michael@0: // base color renderable: ALPHA, RED, RG, RGB, and RGBA michael@0: // sized derivatives: ALPHA8, R8, RGBA4, RGBA8 michael@0: michael@0: // >= OpenGL 3.1 michael@0: // base color renderable: RED, RG, RGB, and RGBA michael@0: // sized derivatives: R8, RGBA4, RGBA8 michael@0: // if the GL_ARB_compatibility extension is supported then we get back michael@0: // support for GL_ALPHA and ALPHA8 michael@0: michael@0: // GL_EXT_bgra adds BGRA render targets to any version michael@0: michael@0: // ES 2.0 michael@0: // color renderable: RGBA4, RGB5_A1, RGB565 michael@0: // GL_EXT_texture_rg adds support for R8 as a color render target michael@0: // GL_OES_rgb8_rgba8 and/or GL_ARM_rgba8 adds support for RGBA8 michael@0: // GL_EXT_texture_format_BGRA8888 and/or GL_APPLE_texture_format_BGRA8888 added BGRA support michael@0: michael@0: // ES 3.0 michael@0: // Same as ES 2.0 except R8 and RGBA8 are supported without extensions (the functions called michael@0: // below already account for this). michael@0: michael@0: enum { michael@0: kNo_MSAA = 0, michael@0: kYes_MSAA = 1, michael@0: }; michael@0: michael@0: if (kGL_GrGLStandard == ctxInfo.standard()) { michael@0: // Post 3.0 we will get R8 michael@0: // Prior to 3.0 we will get ALPHA8 (with GL_ARB_framebuffer_object) michael@0: if (ctxInfo.version() >= GR_GL_VER(3,0) || michael@0: ctxInfo.hasExtension("GL_ARB_framebuffer_object")) { michael@0: fConfigRenderSupport[kAlpha_8_GrPixelConfig][kNo_MSAA] = true; michael@0: fConfigRenderSupport[kAlpha_8_GrPixelConfig][kYes_MSAA] = true; michael@0: } michael@0: } else { michael@0: // On ES we can only hope for R8 michael@0: fConfigRenderSupport[kAlpha_8_GrPixelConfig][kNo_MSAA] = fTextureRedSupport; michael@0: fConfigRenderSupport[kAlpha_8_GrPixelConfig][kYes_MSAA] = fTextureRedSupport; michael@0: } michael@0: michael@0: if (kGL_GrGLStandard != ctxInfo.standard()) { michael@0: // only available in ES michael@0: fConfigRenderSupport[kRGB_565_GrPixelConfig][kNo_MSAA] = true; michael@0: fConfigRenderSupport[kRGB_565_GrPixelConfig][kYes_MSAA] = true; michael@0: } michael@0: michael@0: // we no longer support 444 as a render target michael@0: fConfigRenderSupport[kRGBA_4444_GrPixelConfig][kNo_MSAA] = false; michael@0: fConfigRenderSupport[kRGBA_4444_GrPixelConfig][kYes_MSAA] = false; michael@0: michael@0: if (this->fRGBA8RenderbufferSupport) { michael@0: fConfigRenderSupport[kRGBA_8888_GrPixelConfig][kNo_MSAA] = true; michael@0: fConfigRenderSupport[kRGBA_8888_GrPixelConfig][kYes_MSAA] = true; michael@0: } michael@0: michael@0: if (this->fBGRAFormatSupport) { michael@0: fConfigRenderSupport[kBGRA_8888_GrPixelConfig][kNo_MSAA] = true; michael@0: // The GL_EXT_texture_format_BGRA8888 extension does not add BGRA to the list of michael@0: // configs that are color-renderable and can be passed to glRenderBufferStorageMultisample. michael@0: // Chromium may have an extension to allow BGRA renderbuffers to work on desktop platforms. michael@0: if (ctxInfo.hasExtension("GL_CHROMIUM_renderbuffer_format_BGRA8888")) { michael@0: fConfigRenderSupport[kBGRA_8888_GrPixelConfig][kYes_MSAA] = true; michael@0: } else { michael@0: fConfigRenderSupport[kBGRA_8888_GrPixelConfig][kYes_MSAA] = michael@0: !fBGRAIsInternalFormat || !this->usesMSAARenderBuffers(); michael@0: } michael@0: } michael@0: michael@0: // If we don't support MSAA then undo any places above where we set a config as renderable with michael@0: // msaa. michael@0: if (kNone_MSFBOType == fMSFBOType) { michael@0: for (int i = 0; i < kGrPixelConfigCnt; ++i) { michael@0: fConfigRenderSupport[i][kYes_MSAA] = false; michael@0: } michael@0: } michael@0: } michael@0: michael@0: bool GrGLCaps::readPixelsSupported(const GrGLInterface* intf, michael@0: GrGLenum format, michael@0: GrGLenum type) const { michael@0: if (GR_GL_RGBA == format && GR_GL_UNSIGNED_BYTE == type) { michael@0: // ES 2 guarantees this format is supported michael@0: return true; michael@0: } michael@0: michael@0: if (!fTwoFormatLimit) { michael@0: // not limited by ES 2's constraints michael@0: return true; michael@0: } michael@0: michael@0: GrGLint otherFormat = GR_GL_RGBA; michael@0: GrGLint otherType = GR_GL_UNSIGNED_BYTE; michael@0: michael@0: // The other supported format/type combo supported for ReadPixels michael@0: // can change based on which render target is bound michael@0: GR_GL_GetIntegerv(intf, michael@0: GR_GL_IMPLEMENTATION_COLOR_READ_FORMAT, michael@0: &otherFormat); michael@0: michael@0: GR_GL_GetIntegerv(intf, michael@0: GR_GL_IMPLEMENTATION_COLOR_READ_TYPE, michael@0: &otherType); michael@0: michael@0: return (GrGLenum)otherFormat == format && (GrGLenum)otherType == type; michael@0: } michael@0: michael@0: void GrGLCaps::initFSAASupport(const GrGLContextInfo& ctxInfo, const GrGLInterface* gli) { michael@0: michael@0: fMSFBOType = kNone_MSFBOType; michael@0: if (kGL_GrGLStandard != ctxInfo.standard()) { michael@0: // We prefer the EXT/IMG extension over ES3 MSAA because we've observed michael@0: // ES3 driver bugs on at least one device with a tiled GPU (N10). michael@0: if (ctxInfo.hasExtension("GL_EXT_multisampled_render_to_texture")) { michael@0: fMSFBOType = kES_EXT_MsToTexture_MSFBOType; michael@0: } else if (ctxInfo.hasExtension("GL_IMG_multisampled_render_to_texture")) { michael@0: fMSFBOType = kES_IMG_MsToTexture_MSFBOType; michael@0: } else if (ctxInfo.version() >= GR_GL_VER(3,0)) { michael@0: fMSFBOType = GrGLCaps::kES_3_0_MSFBOType; michael@0: } else if (ctxInfo.hasExtension("GL_CHROMIUM_framebuffer_multisample")) { michael@0: // chrome's extension is equivalent to the EXT msaa michael@0: // and fbo_blit extensions. michael@0: fMSFBOType = kDesktop_EXT_MSFBOType; michael@0: } else if (ctxInfo.hasExtension("GL_APPLE_framebuffer_multisample")) { michael@0: fMSFBOType = kES_Apple_MSFBOType; michael@0: } michael@0: } else { michael@0: if ((ctxInfo.version() >= GR_GL_VER(3,0)) || michael@0: ctxInfo.hasExtension("GL_ARB_framebuffer_object")) { michael@0: fMSFBOType = GrGLCaps::kDesktop_ARB_MSFBOType; michael@0: } else if (ctxInfo.hasExtension("GL_EXT_framebuffer_multisample") && michael@0: ctxInfo.hasExtension("GL_EXT_framebuffer_blit")) { michael@0: fMSFBOType = GrGLCaps::kDesktop_EXT_MSFBOType; michael@0: } michael@0: } michael@0: } michael@0: michael@0: namespace { michael@0: const GrGLuint kUnknownBitCount = GrGLStencilBuffer::kUnknownBitCount; michael@0: } michael@0: michael@0: void GrGLCaps::initStencilFormats(const GrGLContextInfo& ctxInfo) { michael@0: michael@0: // Build up list of legal stencil formats (though perhaps not supported on michael@0: // the particular gpu/driver) from most preferred to least. michael@0: michael@0: // these consts are in order of most preferred to least preferred michael@0: // we don't bother with GL_STENCIL_INDEX1 or GL_DEPTH32F_STENCIL8 michael@0: michael@0: static const StencilFormat michael@0: // internal Format stencil bits total bits packed? michael@0: gS8 = {GR_GL_STENCIL_INDEX8, 8, 8, false}, michael@0: gS16 = {GR_GL_STENCIL_INDEX16, 16, 16, false}, michael@0: gD24S8 = {GR_GL_DEPTH24_STENCIL8, 8, 32, true }, michael@0: gS4 = {GR_GL_STENCIL_INDEX4, 4, 4, false}, michael@0: // gS = {GR_GL_STENCIL_INDEX, kUnknownBitCount, kUnknownBitCount, false}, michael@0: gDS = {GR_GL_DEPTH_STENCIL, kUnknownBitCount, kUnknownBitCount, true }; michael@0: michael@0: if (kGL_GrGLStandard == ctxInfo.standard()) { michael@0: bool supportsPackedDS = michael@0: ctxInfo.version() >= GR_GL_VER(3,0) || michael@0: ctxInfo.hasExtension("GL_EXT_packed_depth_stencil") || michael@0: ctxInfo.hasExtension("GL_ARB_framebuffer_object"); michael@0: michael@0: // S1 thru S16 formats are in GL 3.0+, EXT_FBO, and ARB_FBO since we michael@0: // require FBO support we can expect these are legal formats and don't michael@0: // check. These also all support the unsized GL_STENCIL_INDEX. michael@0: fStencilFormats.push_back() = gS8; michael@0: fStencilFormats.push_back() = gS16; michael@0: if (supportsPackedDS) { michael@0: fStencilFormats.push_back() = gD24S8; michael@0: } michael@0: fStencilFormats.push_back() = gS4; michael@0: if (supportsPackedDS) { michael@0: fStencilFormats.push_back() = gDS; michael@0: } michael@0: } else { michael@0: // ES2 has STENCIL_INDEX8 without extensions but requires extensions michael@0: // for other formats. michael@0: // ES doesn't support using the unsized format. michael@0: michael@0: fStencilFormats.push_back() = gS8; michael@0: //fStencilFormats.push_back() = gS16; michael@0: if (ctxInfo.version() >= GR_GL_VER(3,0) || michael@0: ctxInfo.hasExtension("GL_OES_packed_depth_stencil")) { michael@0: fStencilFormats.push_back() = gD24S8; michael@0: } michael@0: if (ctxInfo.hasExtension("GL_OES_stencil4")) { michael@0: fStencilFormats.push_back() = gS4; michael@0: } michael@0: } michael@0: SkASSERT(0 == fStencilVerifiedColorConfigs.count()); michael@0: fStencilVerifiedColorConfigs.push_back_n(fStencilFormats.count()); michael@0: } michael@0: michael@0: void GrGLCaps::markColorConfigAndStencilFormatAsVerified( michael@0: GrPixelConfig config, michael@0: const GrGLStencilBuffer::Format& format) { michael@0: #if !GR_GL_CHECK_FBO_STATUS_ONCE_PER_FORMAT michael@0: return; michael@0: #endif michael@0: SkASSERT((unsigned)config < (unsigned)kGrPixelConfigCnt); michael@0: SkASSERT(fStencilFormats.count() == fStencilVerifiedColorConfigs.count()); michael@0: int count = fStencilFormats.count(); michael@0: // we expect a really small number of possible formats so linear search michael@0: // should be OK michael@0: SkASSERT(count < 16); michael@0: for (int i = 0; i < count; ++i) { michael@0: if (format.fInternalFormat == michael@0: fStencilFormats[i].fInternalFormat) { michael@0: fStencilVerifiedColorConfigs[i].markVerified(config); michael@0: return; michael@0: } michael@0: } michael@0: GrCrash("Why are we seeing a stencil format that " michael@0: "GrGLCaps doesn't know about."); michael@0: } michael@0: michael@0: bool GrGLCaps::isColorConfigAndStencilFormatVerified( michael@0: GrPixelConfig config, michael@0: const GrGLStencilBuffer::Format& format) const { michael@0: #if !GR_GL_CHECK_FBO_STATUS_ONCE_PER_FORMAT michael@0: return false; michael@0: #endif michael@0: SkASSERT((unsigned)config < (unsigned)kGrPixelConfigCnt); michael@0: int count = fStencilFormats.count(); michael@0: // we expect a really small number of possible formats so linear search michael@0: // should be OK michael@0: SkASSERT(count < 16); michael@0: for (int i = 0; i < count; ++i) { michael@0: if (format.fInternalFormat == michael@0: fStencilFormats[i].fInternalFormat) { michael@0: return fStencilVerifiedColorConfigs[i].isVerified(config); michael@0: } michael@0: } michael@0: GrCrash("Why are we seeing a stencil format that " michael@0: "GLCaps doesn't know about."); michael@0: return false; michael@0: } michael@0: michael@0: SkString GrGLCaps::dump() const { michael@0: michael@0: SkString r = INHERITED::dump(); michael@0: michael@0: r.appendf("--- GL-Specific ---\n"); michael@0: for (int i = 0; i < fStencilFormats.count(); ++i) { michael@0: r.appendf("Stencil Format %d, stencil bits: %02d, total bits: %02d\n", michael@0: i, michael@0: fStencilFormats[i].fStencilBits, michael@0: fStencilFormats[i].fTotalBits); michael@0: } michael@0: michael@0: static const char* kMSFBOExtStr[] = { michael@0: "None", michael@0: "ARB", michael@0: "EXT", michael@0: "ES 3.0", michael@0: "Apple", michael@0: "IMG MS To Texture", michael@0: "EXT MS To Texture", michael@0: }; michael@0: GR_STATIC_ASSERT(0 == kNone_MSFBOType); michael@0: GR_STATIC_ASSERT(1 == kDesktop_ARB_MSFBOType); michael@0: GR_STATIC_ASSERT(2 == kDesktop_EXT_MSFBOType); michael@0: GR_STATIC_ASSERT(3 == kES_3_0_MSFBOType); michael@0: GR_STATIC_ASSERT(4 == kES_Apple_MSFBOType); michael@0: GR_STATIC_ASSERT(5 == kES_IMG_MsToTexture_MSFBOType); michael@0: GR_STATIC_ASSERT(6 == kES_EXT_MsToTexture_MSFBOType); michael@0: GR_STATIC_ASSERT(GR_ARRAY_COUNT(kMSFBOExtStr) == kLast_MSFBOType + 1); michael@0: michael@0: static const char* kFBFetchTypeStr[] = { michael@0: "None", michael@0: "EXT", michael@0: "NV", michael@0: }; michael@0: GR_STATIC_ASSERT(0 == kNone_FBFetchType); michael@0: GR_STATIC_ASSERT(1 == kEXT_FBFetchType); michael@0: GR_STATIC_ASSERT(2 == kNV_FBFetchType); michael@0: GR_STATIC_ASSERT(GR_ARRAY_COUNT(kFBFetchTypeStr) == kLast_FBFetchType + 1); michael@0: michael@0: michael@0: r.appendf("Core Profile: %s\n", (fIsCoreProfile ? "YES" : "NO")); michael@0: r.appendf("Fixed Function Support: %s\n", (fFixedFunctionSupport ? "YES" : "NO")); michael@0: r.appendf("MSAA Type: %s\n", kMSFBOExtStr[fMSFBOType]); michael@0: r.appendf("FB Fetch Type: %s\n", kFBFetchTypeStr[fFBFetchType]); michael@0: r.appendf("Max FS Uniform Vectors: %d\n", fMaxFragmentUniformVectors); michael@0: r.appendf("Max FS Texture Units: %d\n", fMaxFragmentTextureUnits); michael@0: if (fFixedFunctionSupport) { michael@0: r.appendf("Max Fixed Function Texture Coords: %d\n", fMaxFixedFunctionTextureCoords); michael@0: } michael@0: r.appendf("Max Vertex Attributes: %d\n", fMaxVertexAttributes); michael@0: r.appendf("Support RGBA8 Render Buffer: %s\n", (fRGBA8RenderbufferSupport ? "YES": "NO")); michael@0: r.appendf("BGRA support: %s\n", (fBGRAFormatSupport ? "YES": "NO")); michael@0: r.appendf("BGRA is an internal format: %s\n", (fBGRAIsInternalFormat ? "YES": "NO")); michael@0: r.appendf("Support texture swizzle: %s\n", (fTextureSwizzleSupport ? "YES": "NO")); michael@0: r.appendf("Unpack Row length support: %s\n", (fUnpackRowLengthSupport ? "YES": "NO")); michael@0: r.appendf("Unpack Flip Y support: %s\n", (fUnpackFlipYSupport ? "YES": "NO")); michael@0: r.appendf("Pack Row length support: %s\n", (fPackRowLengthSupport ? "YES": "NO")); michael@0: r.appendf("Pack Flip Y support: %s\n", (fPackFlipYSupport ? "YES": "NO")); michael@0: michael@0: r.appendf("Texture Usage support: %s\n", (fTextureUsageSupport ? "YES": "NO")); michael@0: r.appendf("Texture Storage support: %s\n", (fTexStorageSupport ? "YES": "NO")); michael@0: r.appendf("GL_R support: %s\n", (fTextureRedSupport ? "YES": "NO")); michael@0: r.appendf("GL_ARB_imaging support: %s\n", (fImagingSupport ? "YES": "NO")); michael@0: r.appendf("Two Format Limit: %s\n", (fTwoFormatLimit ? "YES": "NO")); michael@0: r.appendf("Fragment coord conventions support: %s\n", michael@0: (fFragCoordsConventionSupport ? "YES": "NO")); michael@0: r.appendf("Vertex array object support: %s\n", (fVertexArrayObjectSupport ? "YES": "NO")); michael@0: r.appendf("Use non-VBO for dynamic data: %s\n", michael@0: (fUseNonVBOVertexAndIndexDynamicData ? "YES" : "NO")); michael@0: r.appendf("Discard FrameBuffer support: %s\n", (fDiscardFBSupport ? "YES" : "NO")); michael@0: r.appendf("Full screen clear is free: %s\n", (fFullClearIsFree ? "YES" : "NO")); michael@0: return r; michael@0: }