michael@0: /* michael@0: * Copyright 2011 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 "gl/GrGLInterface.h" michael@0: #include "gl/GrGLExtensions.h" michael@0: #include "gl/GrGLUtil.h" michael@0: michael@0: #include michael@0: michael@0: #if GR_GL_PER_GL_FUNC_CALLBACK michael@0: namespace { michael@0: void GrGLDefaultInterfaceCallback(const GrGLInterface*) {} michael@0: } michael@0: #endif michael@0: michael@0: const GrGLInterface* GrGLInterfaceAddTestDebugMarker(const GrGLInterface* interface, michael@0: GrGLInsertEventMarkerProc insertEventMarkerFn, michael@0: GrGLPushGroupMarkerProc pushGroupMarkerFn, michael@0: GrGLPopGroupMarkerProc popGroupMarkerFn) { michael@0: GrGLInterface* newInterface = GrGLInterface::NewClone(interface); michael@0: michael@0: if (!newInterface->fExtensions.has("GL_EXT_debug_marker")) { michael@0: newInterface->fExtensions.add("GL_EXT_debug_marker"); michael@0: } michael@0: michael@0: newInterface->fFunctions.fInsertEventMarker = insertEventMarkerFn; michael@0: newInterface->fFunctions.fPushGroupMarker = pushGroupMarkerFn; michael@0: newInterface->fFunctions.fPopGroupMarker = popGroupMarkerFn; michael@0: michael@0: return newInterface; michael@0: } michael@0: michael@0: const GrGLInterface* GrGLInterfaceRemoveNVPR(const GrGLInterface* interface) { michael@0: GrGLInterface* newInterface = GrGLInterface::NewClone(interface); michael@0: michael@0: newInterface->fExtensions.remove("GL_NV_path_rendering"); michael@0: michael@0: newInterface->fFunctions.fPathCommands = NULL; michael@0: newInterface->fFunctions.fPathCoords = NULL; michael@0: newInterface->fFunctions.fPathSubCommands = NULL; michael@0: newInterface->fFunctions.fPathSubCoords = NULL; michael@0: newInterface->fFunctions.fPathString = NULL; michael@0: newInterface->fFunctions.fPathGlyphs = NULL; michael@0: newInterface->fFunctions.fPathGlyphRange = NULL; michael@0: newInterface->fFunctions.fWeightPaths = NULL; michael@0: newInterface->fFunctions.fCopyPath = NULL; michael@0: newInterface->fFunctions.fInterpolatePaths = NULL; michael@0: newInterface->fFunctions.fTransformPath = NULL; michael@0: newInterface->fFunctions.fPathParameteriv = NULL; michael@0: newInterface->fFunctions.fPathParameteri = NULL; michael@0: newInterface->fFunctions.fPathParameterfv = NULL; michael@0: newInterface->fFunctions.fPathParameterf = NULL; michael@0: newInterface->fFunctions.fPathDashArray = NULL; michael@0: newInterface->fFunctions.fGenPaths = NULL; michael@0: newInterface->fFunctions.fDeletePaths = NULL; michael@0: newInterface->fFunctions.fIsPath = NULL; michael@0: newInterface->fFunctions.fPathStencilFunc = NULL; michael@0: newInterface->fFunctions.fPathStencilDepthOffset = NULL; michael@0: newInterface->fFunctions.fStencilFillPath = NULL; michael@0: newInterface->fFunctions.fStencilStrokePath = NULL; michael@0: newInterface->fFunctions.fStencilFillPathInstanced = NULL; michael@0: newInterface->fFunctions.fStencilStrokePathInstanced = NULL; michael@0: newInterface->fFunctions.fPathCoverDepthFunc = NULL; michael@0: newInterface->fFunctions.fPathColorGen = NULL; michael@0: newInterface->fFunctions.fPathTexGen = NULL; michael@0: newInterface->fFunctions.fPathFogGen = NULL; michael@0: newInterface->fFunctions.fCoverFillPath = NULL; michael@0: newInterface->fFunctions.fCoverStrokePath = NULL; michael@0: newInterface->fFunctions.fCoverFillPathInstanced = NULL; michael@0: newInterface->fFunctions.fCoverStrokePathInstanced = NULL; michael@0: newInterface->fFunctions.fGetPathParameteriv = NULL; michael@0: newInterface->fFunctions.fGetPathParameterfv = NULL; michael@0: newInterface->fFunctions.fGetPathCommands = NULL; michael@0: newInterface->fFunctions.fGetPathCoords = NULL; michael@0: newInterface->fFunctions.fGetPathDashArray = NULL; michael@0: newInterface->fFunctions.fGetPathMetrics = NULL; michael@0: newInterface->fFunctions.fGetPathMetricRange = NULL; michael@0: newInterface->fFunctions.fGetPathSpacing = NULL; michael@0: newInterface->fFunctions.fGetPathColorGeniv = NULL; michael@0: newInterface->fFunctions.fGetPathColorGenfv = NULL; michael@0: newInterface->fFunctions.fGetPathTexGeniv = NULL; michael@0: newInterface->fFunctions.fGetPathTexGenfv = NULL; michael@0: newInterface->fFunctions.fIsPointInFillPath = NULL; michael@0: newInterface->fFunctions.fIsPointInStrokePath = NULL; michael@0: newInterface->fFunctions.fGetPathLength = NULL; michael@0: newInterface->fFunctions.fPointAlongPath = NULL; michael@0: michael@0: return newInterface; michael@0: } michael@0: michael@0: GrGLInterface::GrGLInterface() { michael@0: fStandard = kNone_GrGLStandard; michael@0: michael@0: #if GR_GL_PER_GL_FUNC_CALLBACK michael@0: fCallback = GrGLDefaultInterfaceCallback; michael@0: fCallbackData = 0; michael@0: #endif michael@0: } michael@0: michael@0: GrGLInterface* GrGLInterface::NewClone(const GrGLInterface* interface) { michael@0: SkASSERT(NULL != interface); michael@0: michael@0: GrGLInterface* clone = SkNEW(GrGLInterface); michael@0: clone->fStandard = interface->fStandard; michael@0: clone->fExtensions = interface->fExtensions; michael@0: clone->fFunctions = interface->fFunctions; michael@0: #if GR_GL_PER_GL_FUNC_CALLBACK michael@0: clone->fCallback = interface->fCallback; michael@0: clone->fCallbackData = interface->fCallbackData; michael@0: #endif michael@0: return clone; michael@0: } michael@0: michael@0: bool GrGLInterface::validate() const { michael@0: michael@0: if (kNone_GrGLStandard == fStandard) { michael@0: return false; michael@0: } michael@0: michael@0: if (!fExtensions.isInitialized()) { michael@0: return false; michael@0: } michael@0: michael@0: // functions that are always required michael@0: if (NULL == fFunctions.fActiveTexture || michael@0: NULL == fFunctions.fAttachShader || michael@0: NULL == fFunctions.fBindAttribLocation || michael@0: NULL == fFunctions.fBindBuffer || michael@0: NULL == fFunctions.fBindTexture || michael@0: NULL == fFunctions.fBlendFunc || michael@0: NULL == fFunctions.fBlendColor || // -> GL >= 1.4, ES >= 2.0 or extension michael@0: NULL == fFunctions.fBufferData || michael@0: NULL == fFunctions.fBufferSubData || michael@0: NULL == fFunctions.fClear || michael@0: NULL == fFunctions.fClearColor || michael@0: NULL == fFunctions.fClearStencil || michael@0: NULL == fFunctions.fColorMask || michael@0: NULL == fFunctions.fCompileShader || michael@0: NULL == fFunctions.fCopyTexSubImage2D || michael@0: NULL == fFunctions.fCreateProgram || michael@0: NULL == fFunctions.fCreateShader || michael@0: NULL == fFunctions.fCullFace || michael@0: NULL == fFunctions.fDeleteBuffers || michael@0: NULL == fFunctions.fDeleteProgram || michael@0: NULL == fFunctions.fDeleteShader || michael@0: NULL == fFunctions.fDeleteTextures || michael@0: NULL == fFunctions.fDepthMask || michael@0: NULL == fFunctions.fDisable || michael@0: NULL == fFunctions.fDisableVertexAttribArray || michael@0: NULL == fFunctions.fDrawArrays || michael@0: NULL == fFunctions.fDrawElements || michael@0: NULL == fFunctions.fEnable || michael@0: NULL == fFunctions.fEnableVertexAttribArray || michael@0: NULL == fFunctions.fFrontFace || michael@0: NULL == fFunctions.fGenBuffers || michael@0: NULL == fFunctions.fGenTextures || michael@0: NULL == fFunctions.fGetBufferParameteriv || michael@0: NULL == fFunctions.fGenerateMipmap || michael@0: NULL == fFunctions.fGetError || michael@0: NULL == fFunctions.fGetIntegerv || michael@0: NULL == fFunctions.fGetProgramInfoLog || michael@0: NULL == fFunctions.fGetProgramiv || michael@0: NULL == fFunctions.fGetShaderInfoLog || michael@0: NULL == fFunctions.fGetShaderiv || michael@0: NULL == fFunctions.fGetString || michael@0: NULL == fFunctions.fGetUniformLocation || michael@0: NULL == fFunctions.fLinkProgram || michael@0: NULL == fFunctions.fLineWidth || michael@0: NULL == fFunctions.fPixelStorei || michael@0: NULL == fFunctions.fReadPixels || michael@0: NULL == fFunctions.fScissor || michael@0: NULL == fFunctions.fShaderSource || michael@0: NULL == fFunctions.fStencilFunc || michael@0: NULL == fFunctions.fStencilMask || michael@0: NULL == fFunctions.fStencilOp || michael@0: NULL == fFunctions.fTexImage2D || michael@0: NULL == fFunctions.fTexParameteri || michael@0: NULL == fFunctions.fTexParameteriv || michael@0: NULL == fFunctions.fTexSubImage2D || michael@0: NULL == fFunctions.fUniform1f || michael@0: NULL == fFunctions.fUniform1i || michael@0: NULL == fFunctions.fUniform1fv || michael@0: NULL == fFunctions.fUniform1iv || michael@0: NULL == fFunctions.fUniform2f || michael@0: NULL == fFunctions.fUniform2i || michael@0: NULL == fFunctions.fUniform2fv || michael@0: NULL == fFunctions.fUniform2iv || michael@0: NULL == fFunctions.fUniform3f || michael@0: NULL == fFunctions.fUniform3i || michael@0: NULL == fFunctions.fUniform3fv || michael@0: NULL == fFunctions.fUniform3iv || michael@0: NULL == fFunctions.fUniform4f || michael@0: NULL == fFunctions.fUniform4i || michael@0: NULL == fFunctions.fUniform4fv || michael@0: NULL == fFunctions.fUniform4iv || michael@0: NULL == fFunctions.fUniformMatrix2fv || michael@0: NULL == fFunctions.fUniformMatrix3fv || michael@0: NULL == fFunctions.fUniformMatrix4fv || michael@0: NULL == fFunctions.fUseProgram || michael@0: NULL == fFunctions.fVertexAttrib4fv || michael@0: NULL == fFunctions.fVertexAttribPointer || michael@0: NULL == fFunctions.fViewport || michael@0: NULL == fFunctions.fBindFramebuffer || michael@0: NULL == fFunctions.fBindRenderbuffer || michael@0: NULL == fFunctions.fCheckFramebufferStatus || michael@0: NULL == fFunctions.fDeleteFramebuffers || michael@0: NULL == fFunctions.fDeleteRenderbuffers || michael@0: NULL == fFunctions.fFinish || michael@0: NULL == fFunctions.fFlush || michael@0: NULL == fFunctions.fFramebufferRenderbuffer || michael@0: NULL == fFunctions.fFramebufferTexture2D || michael@0: NULL == fFunctions.fGetFramebufferAttachmentParameteriv || michael@0: NULL == fFunctions.fGetRenderbufferParameteriv || michael@0: NULL == fFunctions.fGenFramebuffers || michael@0: NULL == fFunctions.fGenRenderbuffers || michael@0: NULL == fFunctions.fRenderbufferStorage) { michael@0: return false; michael@0: } michael@0: michael@0: GrGLVersion glVer = GrGLGetVersion(this); michael@0: michael@0: bool isCoreProfile = false; michael@0: if (kGL_GrGLStandard == fStandard && glVer >= GR_GL_VER(3,2)) { michael@0: GrGLint profileMask; michael@0: GR_GL_GetIntegerv(this, GR_GL_CONTEXT_PROFILE_MASK, &profileMask); michael@0: isCoreProfile = SkToBool(profileMask & GR_GL_CONTEXT_CORE_PROFILE_BIT); michael@0: } michael@0: michael@0: // Now check that baseline ES/Desktop fns not covered above are present michael@0: // and that we have fn pointers for any advertised fExtensions that we will michael@0: // try to use. michael@0: michael@0: // these functions are part of ES2, we assume they are available michael@0: // On the desktop we assume they are available if the extension michael@0: // is present or GL version is high enough. michael@0: if (kGLES_GrGLStandard == fStandard) { michael@0: if (NULL == fFunctions.fStencilFuncSeparate || michael@0: NULL == fFunctions.fStencilMaskSeparate || michael@0: NULL == fFunctions.fStencilOpSeparate) { michael@0: return false; michael@0: } michael@0: } else if (kGL_GrGLStandard == fStandard) { michael@0: michael@0: if (glVer >= GR_GL_VER(2,0)) { michael@0: if (NULL == fFunctions.fStencilFuncSeparate || michael@0: NULL == fFunctions.fStencilMaskSeparate || michael@0: NULL == fFunctions.fStencilOpSeparate) { michael@0: return false; michael@0: } michael@0: } michael@0: if (glVer >= GR_GL_VER(3,0) && NULL == fFunctions.fBindFragDataLocation) { michael@0: return false; michael@0: } michael@0: if (glVer >= GR_GL_VER(2,0) || fExtensions.has("GL_ARB_draw_buffers")) { michael@0: if (NULL == fFunctions.fDrawBuffers) { michael@0: return false; michael@0: } michael@0: } michael@0: michael@0: if (glVer >= GR_GL_VER(1,5) || fExtensions.has("GL_ARB_occlusion_query")) { michael@0: if (NULL == fFunctions.fGenQueries || michael@0: NULL == fFunctions.fDeleteQueries || michael@0: NULL == fFunctions.fBeginQuery || michael@0: NULL == fFunctions.fEndQuery || michael@0: NULL == fFunctions.fGetQueryiv || michael@0: NULL == fFunctions.fGetQueryObjectiv || michael@0: NULL == fFunctions.fGetQueryObjectuiv) { michael@0: return false; michael@0: } michael@0: } michael@0: if (glVer >= GR_GL_VER(3,3) || michael@0: fExtensions.has("GL_ARB_timer_query") || michael@0: fExtensions.has("GL_EXT_timer_query")) { michael@0: if (NULL == fFunctions.fGetQueryObjecti64v || michael@0: NULL == fFunctions.fGetQueryObjectui64v) { michael@0: return false; michael@0: } michael@0: } michael@0: if (glVer >= GR_GL_VER(3,3) || fExtensions.has("GL_ARB_timer_query")) { michael@0: if (NULL == fFunctions.fQueryCounter) { michael@0: return false; michael@0: } michael@0: } michael@0: if (!isCoreProfile) { michael@0: if (NULL == fFunctions.fLoadIdentity || michael@0: NULL == fFunctions.fLoadMatrixf || michael@0: NULL == fFunctions.fMatrixMode || michael@0: NULL == fFunctions.fTexGenfv || michael@0: NULL == fFunctions.fTexGeni) { michael@0: return false; michael@0: } michael@0: } michael@0: if (fExtensions.has("GL_NV_path_rendering")) { michael@0: if (NULL == fFunctions.fPathCommands || michael@0: NULL == fFunctions.fPathCoords || michael@0: NULL == fFunctions.fPathSubCommands || michael@0: NULL == fFunctions.fPathSubCoords || michael@0: NULL == fFunctions.fPathString || michael@0: NULL == fFunctions.fPathGlyphs || michael@0: NULL == fFunctions.fPathGlyphRange || michael@0: NULL == fFunctions.fWeightPaths || michael@0: NULL == fFunctions.fCopyPath || michael@0: NULL == fFunctions.fInterpolatePaths || michael@0: NULL == fFunctions.fTransformPath || michael@0: NULL == fFunctions.fPathParameteriv || michael@0: NULL == fFunctions.fPathParameteri || michael@0: NULL == fFunctions.fPathParameterfv || michael@0: NULL == fFunctions.fPathParameterf || michael@0: NULL == fFunctions.fPathDashArray || michael@0: NULL == fFunctions.fGenPaths || michael@0: NULL == fFunctions.fDeletePaths || michael@0: NULL == fFunctions.fIsPath || michael@0: NULL == fFunctions.fPathStencilFunc || michael@0: NULL == fFunctions.fPathStencilDepthOffset || michael@0: NULL == fFunctions.fStencilFillPath || michael@0: NULL == fFunctions.fStencilStrokePath || michael@0: NULL == fFunctions.fStencilFillPathInstanced || michael@0: NULL == fFunctions.fStencilStrokePathInstanced || michael@0: NULL == fFunctions.fPathCoverDepthFunc || michael@0: NULL == fFunctions.fPathColorGen || michael@0: NULL == fFunctions.fPathTexGen || michael@0: NULL == fFunctions.fPathFogGen || michael@0: NULL == fFunctions.fCoverFillPath || michael@0: NULL == fFunctions.fCoverStrokePath || michael@0: NULL == fFunctions.fCoverFillPathInstanced || michael@0: NULL == fFunctions.fCoverStrokePathInstanced || michael@0: NULL == fFunctions.fGetPathParameteriv || michael@0: NULL == fFunctions.fGetPathParameterfv || michael@0: NULL == fFunctions.fGetPathCommands || michael@0: NULL == fFunctions.fGetPathCoords || michael@0: NULL == fFunctions.fGetPathDashArray || michael@0: NULL == fFunctions.fGetPathMetrics || michael@0: NULL == fFunctions.fGetPathMetricRange || michael@0: NULL == fFunctions.fGetPathSpacing || michael@0: NULL == fFunctions.fGetPathColorGeniv || michael@0: NULL == fFunctions.fGetPathColorGenfv || michael@0: NULL == fFunctions.fGetPathTexGeniv || michael@0: NULL == fFunctions.fGetPathTexGenfv || michael@0: NULL == fFunctions.fIsPointInFillPath || michael@0: NULL == fFunctions.fIsPointInStrokePath || michael@0: NULL == fFunctions.fGetPathLength || michael@0: NULL == fFunctions.fPointAlongPath) { michael@0: return false; michael@0: } michael@0: } michael@0: } michael@0: michael@0: // optional function on desktop before 1.3 michael@0: if (kGL_GrGLStandard != fStandard || michael@0: (glVer >= GR_GL_VER(1,3)) || michael@0: fExtensions.has("GL_ARB_texture_compression")) { michael@0: if (NULL == fFunctions.fCompressedTexImage2D) { michael@0: return false; michael@0: } michael@0: } michael@0: michael@0: // part of desktop GL, but not ES michael@0: if (kGL_GrGLStandard == fStandard && michael@0: (NULL == fFunctions.fGetTexLevelParameteriv || michael@0: NULL == fFunctions.fDrawBuffer || michael@0: NULL == fFunctions.fReadBuffer)) { michael@0: return false; michael@0: } michael@0: michael@0: // GL_EXT_texture_storage is part of desktop 4.2 michael@0: // There is a desktop ARB extension and an ES+desktop EXT extension michael@0: if (kGL_GrGLStandard == fStandard) { michael@0: if (glVer >= GR_GL_VER(4,2) || michael@0: fExtensions.has("GL_ARB_texture_storage") || michael@0: fExtensions.has("GL_EXT_texture_storage")) { michael@0: if (NULL == fFunctions.fTexStorage2D) { michael@0: return false; michael@0: } michael@0: } michael@0: } else if (glVer >= GR_GL_VER(3,0) || fExtensions.has("GL_EXT_texture_storage")) { michael@0: if (NULL == fFunctions.fTexStorage2D) { michael@0: return false; michael@0: } michael@0: } michael@0: michael@0: if (fExtensions.has("GL_EXT_discard_framebuffer")) { michael@0: // FIXME: Remove this once Chromium is updated to provide this function michael@0: #if 0 michael@0: if (NULL == fFunctions.fDiscardFramebuffer) { michael@0: return false; michael@0: } michael@0: #endif michael@0: } michael@0: michael@0: // FBO MSAA michael@0: if (kGL_GrGLStandard == fStandard) { michael@0: // GL 3.0 and the ARB extension have multisample + blit michael@0: if (glVer >= GR_GL_VER(3,0) || fExtensions.has("GL_ARB_framebuffer_object")) { michael@0: if (NULL == fFunctions.fRenderbufferStorageMultisample || michael@0: NULL == fFunctions.fBlitFramebuffer) { michael@0: return false; michael@0: } michael@0: } else { michael@0: if (fExtensions.has("GL_EXT_framebuffer_blit") && michael@0: NULL == fFunctions.fBlitFramebuffer) { michael@0: return false; michael@0: } michael@0: if (fExtensions.has("GL_EXT_framebuffer_multisample") && michael@0: NULL == fFunctions.fRenderbufferStorageMultisample) { michael@0: return false; michael@0: } michael@0: } michael@0: } else { michael@0: if (glVer >= GR_GL_VER(3,0) || fExtensions.has("GL_CHROMIUM_framebuffer_multisample")) { michael@0: if (NULL == fFunctions.fRenderbufferStorageMultisample || michael@0: NULL == fFunctions.fBlitFramebuffer) { michael@0: return false; michael@0: } michael@0: } michael@0: if (fExtensions.has("GL_APPLE_framebuffer_multisample")) { michael@0: if (NULL == fFunctions.fRenderbufferStorageMultisampleES2APPLE || michael@0: NULL == fFunctions.fResolveMultisampleFramebuffer) { michael@0: return false; michael@0: } michael@0: } michael@0: if (fExtensions.has("GL_IMG_multisampled_render_to_texture") || michael@0: fExtensions.has("GL_EXT_multisampled_render_to_texture")) { michael@0: if (NULL == fFunctions.fRenderbufferStorageMultisampleES2EXT || michael@0: NULL == fFunctions.fFramebufferTexture2DMultisample) { michael@0: return false; michael@0: } michael@0: } michael@0: } michael@0: michael@0: // On ES buffer mapping is an extension. On Desktop michael@0: // buffer mapping was part of original VBO extension michael@0: // which we require. michael@0: if (kGL_GrGLStandard == fStandard || fExtensions.has("GL_OES_mapbuffer")) { michael@0: if (NULL == fFunctions.fMapBuffer || michael@0: NULL == fFunctions.fUnmapBuffer) { michael@0: return false; michael@0: } michael@0: } michael@0: michael@0: // Dual source blending michael@0: if (kGL_GrGLStandard == fStandard && michael@0: (glVer >= GR_GL_VER(3,3) || fExtensions.has("GL_ARB_blend_func_extended"))) { michael@0: if (NULL == fFunctions.fBindFragDataLocationIndexed) { michael@0: return false; michael@0: } michael@0: } michael@0: michael@0: // glGetStringi was added in version 3.0 of both desktop and ES. michael@0: if (glVer >= GR_GL_VER(3, 0)) { michael@0: if (NULL == fFunctions.fGetStringi) { michael@0: return false; michael@0: } michael@0: } michael@0: michael@0: if (kGL_GrGLStandard == fStandard) { michael@0: if (glVer >= GR_GL_VER(3, 0) || fExtensions.has("GL_ARB_vertex_array_object")) { michael@0: if (NULL == fFunctions.fBindVertexArray || michael@0: NULL == fFunctions.fDeleteVertexArrays || michael@0: NULL == fFunctions.fGenVertexArrays) { michael@0: return false; michael@0: } michael@0: } michael@0: } else { michael@0: if (glVer >= GR_GL_VER(3,0) || fExtensions.has("GL_OES_vertex_array_object")) { michael@0: if (NULL == fFunctions.fBindVertexArray || michael@0: NULL == fFunctions.fDeleteVertexArrays || michael@0: NULL == fFunctions.fGenVertexArrays) { michael@0: return false; michael@0: } michael@0: } michael@0: } michael@0: michael@0: #if 0 michael@0: if (fExtensions.has("GL_EXT_debug_marker")) { michael@0: if (NULL == fFunctions.fInsertEventMarker || michael@0: NULL == fFunctions.fPushGroupMarker || michael@0: NULL == fFunctions.fPopGroupMarker) { michael@0: return false; michael@0: } michael@0: } michael@0: #endif michael@0: return true; michael@0: }