michael@0: /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ michael@0: /* vim: set ts=8 sts=4 et sw=4 tw=80: */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #include michael@0: #include michael@0: #include michael@0: #include michael@0: michael@0: #include "GLContext.h" michael@0: #include "GLBlitHelper.h" michael@0: #include "GLBlitTextureImageHelper.h" michael@0: #include "GLReadTexImageHelper.h" michael@0: michael@0: #include "gfxCrashReporterUtils.h" michael@0: #include "gfxUtils.h" michael@0: #include "GLContextProvider.h" michael@0: #include "GLTextureImage.h" michael@0: #include "nsPrintfCString.h" michael@0: #include "nsThreadUtils.h" michael@0: #include "prenv.h" michael@0: #include "prlink.h" michael@0: #include "ScopedGLHelpers.h" michael@0: #include "SharedSurfaceGL.h" michael@0: #include "SurfaceStream.h" michael@0: #include "GfxTexturesReporter.h" michael@0: #include "TextureGarbageBin.h" michael@0: #include "gfx2DGlue.h" michael@0: #include "gfxPrefs.h" michael@0: michael@0: #include "OGLShaderProgram.h" // for ShaderProgramType michael@0: michael@0: #include "mozilla/DebugOnly.h" michael@0: michael@0: #ifdef XP_MACOSX michael@0: #include michael@0: #include "gfxColor.h" michael@0: #endif michael@0: michael@0: #if defined(MOZ_WIDGET_COCOA) michael@0: #include "nsCocoaFeatures.h" michael@0: #endif michael@0: michael@0: using namespace mozilla::gfx; michael@0: using namespace mozilla::layers; michael@0: michael@0: namespace mozilla { michael@0: namespace gl { michael@0: michael@0: #ifdef DEBUG michael@0: unsigned GLContext::sCurrentGLContextTLS = -1; michael@0: #endif michael@0: michael@0: uint32_t GLContext::sDebugMode = 0; michael@0: michael@0: michael@0: #define MAX_SYMBOL_LENGTH 128 michael@0: #define MAX_SYMBOL_NAMES 5 michael@0: michael@0: // should match the order of GLExtensions, and be null-terminated. michael@0: static const char *sExtensionNames[] = { michael@0: "GL_EXT_framebuffer_object", michael@0: "GL_ARB_framebuffer_object", michael@0: "GL_ARB_texture_rectangle", michael@0: "GL_EXT_bgra", michael@0: "GL_EXT_texture_format_BGRA8888", michael@0: "GL_OES_depth24", michael@0: "GL_OES_depth32", michael@0: "GL_OES_stencil8", michael@0: "GL_OES_texture_npot", michael@0: "GL_ARB_depth_texture", michael@0: "GL_OES_depth_texture", michael@0: "GL_OES_packed_depth_stencil", michael@0: "GL_IMG_read_format", michael@0: "GL_EXT_read_format_bgra", michael@0: "GL_APPLE_client_storage", michael@0: "GL_APPLE_texture_range", michael@0: "GL_ARB_texture_non_power_of_two", michael@0: "GL_ARB_pixel_buffer_object", michael@0: "GL_ARB_ES2_compatibility", michael@0: "GL_ARB_ES3_compatibility", michael@0: "GL_OES_texture_float", michael@0: "GL_OES_texture_float_linear", michael@0: "GL_ARB_texture_float", michael@0: "GL_OES_texture_half_float", michael@0: "GL_OES_texture_half_float_linear", michael@0: "GL_NV_half_float", michael@0: "GL_EXT_color_buffer_float", michael@0: "GL_EXT_color_buffer_half_float", michael@0: "GL_ARB_color_buffer_float", michael@0: "GL_EXT_unpack_subimage", michael@0: "GL_OES_standard_derivatives", michael@0: "GL_EXT_texture_filter_anisotropic", michael@0: "GL_EXT_texture_compression_s3tc", michael@0: "GL_EXT_texture_compression_dxt1", michael@0: "GL_ANGLE_texture_compression_dxt3", michael@0: "GL_ANGLE_texture_compression_dxt5", michael@0: "GL_AMD_compressed_ATC_texture", michael@0: "GL_IMG_texture_compression_pvrtc", michael@0: "GL_EXT_framebuffer_blit", michael@0: "GL_ANGLE_framebuffer_blit", michael@0: "GL_EXT_framebuffer_multisample", michael@0: "GL_ANGLE_framebuffer_multisample", michael@0: "GL_OES_rgb8_rgba8", michael@0: "GL_ARB_robustness", michael@0: "GL_EXT_robustness", michael@0: "GL_ARB_sync", michael@0: "GL_OES_EGL_image", michael@0: "GL_OES_EGL_sync", michael@0: "GL_OES_EGL_image_external", michael@0: "GL_EXT_packed_depth_stencil", michael@0: "GL_OES_element_index_uint", michael@0: "GL_OES_vertex_array_object", michael@0: "GL_ARB_vertex_array_object", michael@0: "GL_APPLE_vertex_array_object", michael@0: "GL_ARB_draw_buffers", michael@0: "GL_EXT_draw_buffers", michael@0: "GL_EXT_gpu_shader4", michael@0: "GL_EXT_blend_minmax", michael@0: "GL_ARB_draw_instanced", michael@0: "GL_EXT_draw_instanced", michael@0: "GL_NV_draw_instanced", michael@0: "GL_ARB_instanced_arrays", michael@0: "GL_NV_instanced_arrays", michael@0: "GL_ANGLE_instanced_arrays", michael@0: "GL_EXT_occlusion_query_boolean", michael@0: "GL_ARB_occlusion_query2", michael@0: "GL_EXT_transform_feedback", michael@0: "GL_NV_transform_feedback", michael@0: "GL_ANGLE_depth_texture", michael@0: "GL_EXT_sRGB", michael@0: "GL_EXT_texture_sRGB", michael@0: "GL_ARB_framebuffer_sRGB", michael@0: "GL_EXT_framebuffer_sRGB", michael@0: "GL_KHR_debug", michael@0: "GL_ARB_half_float_pixel", michael@0: "GL_EXT_frag_depth", michael@0: "GL_OES_compressed_ETC1_RGB8_texture", michael@0: "GL_EXT_draw_range_elements", michael@0: nullptr michael@0: }; michael@0: michael@0: static bool michael@0: ParseGLVersion(GLContext* gl, unsigned int* version) michael@0: { michael@0: GLenum error = gl->fGetError(); michael@0: if (error != LOCAL_GL_NO_ERROR) { michael@0: MOZ_ASSERT(false, "An OpenGL error has been triggered before."); michael@0: return false; michael@0: } michael@0: michael@0: /** michael@0: * B2G emulator bug work around: The emulator implements OpenGL ES 2.0 on michael@0: * OpenGL 3.2. The bug is that GetIntegerv(LOCAL_GL_{MAJOR,MINOR}_VERSION) michael@0: * returns OpenGL 3.2 instead of generating an error. michael@0: */ michael@0: if (!gl->IsGLES()) michael@0: { michael@0: /** michael@0: * OpenGL 3.1 and OpenGL ES 3.0 both introduce GL_{MAJOR,MINOR}_VERSION michael@0: * with GetIntegerv. So we first try those constants even though we michael@0: * might not have an OpenGL context supporting them, has this is a michael@0: * better way than parsing GL_VERSION. michael@0: */ michael@0: GLint majorVersion = 0; michael@0: GLint minorVersion = 0; michael@0: michael@0: gl->fGetIntegerv(LOCAL_GL_MAJOR_VERSION, &majorVersion); michael@0: gl->fGetIntegerv(LOCAL_GL_MINOR_VERSION, &minorVersion); michael@0: michael@0: // If it's not an OpenGL (ES) 3.0 context, we will have an error michael@0: error = gl->fGetError(); michael@0: if (error == LOCAL_GL_NO_ERROR && michael@0: majorVersion > 0 && michael@0: minorVersion >= 0) michael@0: { michael@0: *version = majorVersion * 100 + minorVersion * 10; michael@0: return true; michael@0: } michael@0: } michael@0: michael@0: /** michael@0: * We were not able to use GL_{MAJOR,MINOR}_VERSION, so we parse michael@0: * GL_VERSION. michael@0: * michael@0: * michael@0: * OpenGL 2.x, 3.x, 4.x specifications: michael@0: * The VERSION and SHADING_LANGUAGE_VERSION strings are laid out as follows: michael@0: * michael@0: * michael@0: * michael@0: * The version number is either of the form major_number.minor_number or michael@0: * major_number.minor_number.release_number, where the numbers all have michael@0: * one or more digits. michael@0: * michael@0: * michael@0: * OpenGL ES 2.0, 3.0 specifications: michael@0: * The VERSION string is laid out as follows: michael@0: * michael@0: * "OpenGL ES N.M vendor-specific information" michael@0: * michael@0: * The version number is either of the form major_number.minor_number or michael@0: * major_number.minor_number.release_number, where the numbers all have michael@0: * one or more digits. michael@0: * michael@0: * michael@0: * Note: michael@0: * We don't care about release_number. michael@0: */ michael@0: const char* versionString = (const char*)gl->fGetString(LOCAL_GL_VERSION); michael@0: michael@0: error = gl->fGetError(); michael@0: if (error != LOCAL_GL_NO_ERROR) { michael@0: MOZ_ASSERT(false, "glGetString(GL_VERSION) has generated an error"); michael@0: return false; michael@0: } else if (!versionString) { michael@0: MOZ_ASSERT(false, "glGetString(GL_VERSION) has returned 0"); michael@0: return false; michael@0: } michael@0: michael@0: const char kGLESVersionPrefix[] = "OpenGL ES "; michael@0: if (strncmp(versionString, kGLESVersionPrefix, strlen(kGLESVersionPrefix)) == 0) { michael@0: versionString += strlen(kGLESVersionPrefix); michael@0: } michael@0: michael@0: const char* itr = versionString; michael@0: char* end = nullptr; michael@0: int majorVersion = (int)strtol(itr, &end, 10); michael@0: michael@0: if (!end) { michael@0: MOZ_ASSERT(false, "Failed to parse the GL major version number."); michael@0: return false; michael@0: } else if (*end != '.') { michael@0: MOZ_ASSERT(false, "Failed to parse GL's major-minor version number separator."); michael@0: return false; michael@0: } michael@0: michael@0: // we skip the '.' between the major and the minor version michael@0: itr = end + 1; michael@0: michael@0: end = nullptr; michael@0: michael@0: int minorVersion = (int)strtol(itr, &end, 10); michael@0: if (!end) { michael@0: MOZ_ASSERT(false, "Failed to parse GL's minor version number."); michael@0: return false; michael@0: } michael@0: michael@0: if (majorVersion <= 0 || majorVersion >= 100) { michael@0: MOZ_ASSERT(false, "Invalid major version."); michael@0: return false; michael@0: } else if (minorVersion < 0 || minorVersion >= 10) { michael@0: MOZ_ASSERT(false, "Invalid minor version."); michael@0: return false; michael@0: } michael@0: michael@0: *version = (unsigned int)(majorVersion * 100 + minorVersion * 10); michael@0: return true; michael@0: } michael@0: michael@0: GLContext::GLContext(const SurfaceCaps& caps, michael@0: GLContext* sharedContext, michael@0: bool isOffscreen) michael@0: : mInitialized(false), michael@0: mIsOffscreen(isOffscreen), michael@0: mContextLost(false), michael@0: mVersion(0), michael@0: mProfile(ContextProfile::Unknown), michael@0: mVendor(GLVendor::Other), michael@0: mRenderer(GLRenderer::Other), michael@0: mHasRobustness(false), michael@0: #ifdef DEBUG michael@0: mGLError(LOCAL_GL_NO_ERROR), michael@0: #endif michael@0: mSharedContext(sharedContext), michael@0: mCaps(caps), michael@0: mScreen(nullptr), michael@0: mLockedSurface(nullptr), michael@0: mMaxTextureSize(0), michael@0: mMaxCubeMapTextureSize(0), michael@0: mMaxTextureImageSize(0), michael@0: mMaxRenderbufferSize(0), michael@0: mNeedsTextureSizeChecks(false), michael@0: mWorkAroundDriverBugs(true) michael@0: { michael@0: mOwningThread = NS_GetCurrentThread(); michael@0: } michael@0: michael@0: GLContext::~GLContext() { michael@0: NS_ASSERTION(IsDestroyed(), "GLContext implementation must call MarkDestroyed in destructor!"); michael@0: #ifdef DEBUG michael@0: if (mSharedContext) { michael@0: GLContext *tip = mSharedContext; michael@0: while (tip->mSharedContext) michael@0: tip = tip->mSharedContext; michael@0: tip->SharedContextDestroyed(this); michael@0: tip->ReportOutstandingNames(); michael@0: } else { michael@0: ReportOutstandingNames(); michael@0: } michael@0: #endif michael@0: } michael@0: michael@0: bool michael@0: GLContext::InitWithPrefix(const char *prefix, bool trygl) michael@0: { michael@0: ScopedGfxFeatureReporter reporter("GL Context"); michael@0: michael@0: if (mInitialized) { michael@0: reporter.SetSuccessful(); michael@0: return true; michael@0: } michael@0: michael@0: mWorkAroundDriverBugs = gfxPrefs::WorkAroundDriverBugs(); michael@0: michael@0: SymLoadStruct symbols[] = { michael@0: { (PRFuncPtr*) &mSymbols.fActiveTexture, { "ActiveTexture", "ActiveTextureARB", nullptr } }, michael@0: { (PRFuncPtr*) &mSymbols.fAttachShader, { "AttachShader", "AttachShaderARB", nullptr } }, michael@0: { (PRFuncPtr*) &mSymbols.fBindAttribLocation, { "BindAttribLocation", "BindAttribLocationARB", nullptr } }, michael@0: { (PRFuncPtr*) &mSymbols.fBindBuffer, { "BindBuffer", "BindBufferARB", nullptr } }, michael@0: { (PRFuncPtr*) &mSymbols.fBindTexture, { "BindTexture", "BindTextureARB", nullptr } }, michael@0: { (PRFuncPtr*) &mSymbols.fBlendColor, { "BlendColor", nullptr } }, michael@0: { (PRFuncPtr*) &mSymbols.fBlendEquation, { "BlendEquation", nullptr } }, michael@0: { (PRFuncPtr*) &mSymbols.fBlendEquationSeparate, { "BlendEquationSeparate", "BlendEquationSeparateEXT", nullptr } }, michael@0: { (PRFuncPtr*) &mSymbols.fBlendFunc, { "BlendFunc", nullptr } }, michael@0: { (PRFuncPtr*) &mSymbols.fBlendFuncSeparate, { "BlendFuncSeparate", "BlendFuncSeparateEXT", nullptr } }, michael@0: { (PRFuncPtr*) &mSymbols.fBufferData, { "BufferData", nullptr } }, michael@0: { (PRFuncPtr*) &mSymbols.fBufferSubData, { "BufferSubData", nullptr } }, michael@0: { (PRFuncPtr*) &mSymbols.fClear, { "Clear", nullptr } }, michael@0: { (PRFuncPtr*) &mSymbols.fClearColor, { "ClearColor", nullptr } }, michael@0: { (PRFuncPtr*) &mSymbols.fClearStencil, { "ClearStencil", nullptr } }, michael@0: { (PRFuncPtr*) &mSymbols.fColorMask, { "ColorMask", nullptr } }, michael@0: { (PRFuncPtr*) &mSymbols.fCompressedTexImage2D, {"CompressedTexImage2D", nullptr} }, michael@0: { (PRFuncPtr*) &mSymbols.fCompressedTexSubImage2D, {"CompressedTexSubImage2D", nullptr} }, michael@0: { (PRFuncPtr*) &mSymbols.fCullFace, { "CullFace", nullptr } }, michael@0: { (PRFuncPtr*) &mSymbols.fDetachShader, { "DetachShader", "DetachShaderARB", nullptr } }, michael@0: { (PRFuncPtr*) &mSymbols.fDepthFunc, { "DepthFunc", nullptr } }, michael@0: { (PRFuncPtr*) &mSymbols.fDepthMask, { "DepthMask", nullptr } }, michael@0: { (PRFuncPtr*) &mSymbols.fDisable, { "Disable", nullptr } }, michael@0: { (PRFuncPtr*) &mSymbols.fDisableVertexAttribArray, { "DisableVertexAttribArray", "DisableVertexAttribArrayARB", nullptr } }, michael@0: { (PRFuncPtr*) &mSymbols.fDrawArrays, { "DrawArrays", nullptr } }, michael@0: { (PRFuncPtr*) &mSymbols.fDrawElements, { "DrawElements", nullptr } }, michael@0: { (PRFuncPtr*) &mSymbols.fEnable, { "Enable", nullptr } }, michael@0: { (PRFuncPtr*) &mSymbols.fEnableVertexAttribArray, { "EnableVertexAttribArray", "EnableVertexAttribArrayARB", nullptr } }, michael@0: { (PRFuncPtr*) &mSymbols.fFinish, { "Finish", nullptr } }, michael@0: { (PRFuncPtr*) &mSymbols.fFlush, { "Flush", nullptr } }, michael@0: { (PRFuncPtr*) &mSymbols.fFrontFace, { "FrontFace", nullptr } }, michael@0: { (PRFuncPtr*) &mSymbols.fGetActiveAttrib, { "GetActiveAttrib", "GetActiveAttribARB", nullptr } }, michael@0: { (PRFuncPtr*) &mSymbols.fGetActiveUniform, { "GetActiveUniform", "GetActiveUniformARB", nullptr } }, michael@0: { (PRFuncPtr*) &mSymbols.fGetAttachedShaders, { "GetAttachedShaders", "GetAttachedShadersARB", nullptr } }, michael@0: { (PRFuncPtr*) &mSymbols.fGetAttribLocation, { "GetAttribLocation", "GetAttribLocationARB", nullptr } }, michael@0: { (PRFuncPtr*) &mSymbols.fGetIntegerv, { "GetIntegerv", nullptr } }, michael@0: { (PRFuncPtr*) &mSymbols.fGetFloatv, { "GetFloatv", nullptr } }, michael@0: { (PRFuncPtr*) &mSymbols.fGetBooleanv, { "GetBooleanv", nullptr } }, michael@0: { (PRFuncPtr*) &mSymbols.fGetBufferParameteriv, { "GetBufferParameteriv", "GetBufferParameterivARB", nullptr } }, michael@0: { (PRFuncPtr*) &mSymbols.fGetError, { "GetError", nullptr } }, michael@0: { (PRFuncPtr*) &mSymbols.fGetProgramiv, { "GetProgramiv", "GetProgramivARB", nullptr } }, michael@0: { (PRFuncPtr*) &mSymbols.fGetProgramInfoLog, { "GetProgramInfoLog", "GetProgramInfoLogARB", nullptr } }, michael@0: { (PRFuncPtr*) &mSymbols.fTexParameteri, { "TexParameteri", nullptr } }, michael@0: { (PRFuncPtr*) &mSymbols.fTexParameteriv, { "TexParameteriv", nullptr } }, michael@0: { (PRFuncPtr*) &mSymbols.fTexParameterf, { "TexParameterf", nullptr } }, michael@0: { (PRFuncPtr*) &mSymbols.fGetString, { "GetString", nullptr } }, michael@0: { (PRFuncPtr*) &mSymbols.fGetTexParameterfv, { "GetTexParameterfv", nullptr } }, michael@0: { (PRFuncPtr*) &mSymbols.fGetTexParameteriv, { "GetTexParameteriv", nullptr } }, michael@0: { (PRFuncPtr*) &mSymbols.fGetUniformfv, { "GetUniformfv", "GetUniformfvARB", nullptr } }, michael@0: { (PRFuncPtr*) &mSymbols.fGetUniformiv, { "GetUniformiv", "GetUniformivARB", nullptr } }, michael@0: { (PRFuncPtr*) &mSymbols.fGetUniformLocation, { "GetUniformLocation", "GetUniformLocationARB", nullptr } }, michael@0: { (PRFuncPtr*) &mSymbols.fGetVertexAttribfv, { "GetVertexAttribfv", "GetVertexAttribfvARB", nullptr } }, michael@0: { (PRFuncPtr*) &mSymbols.fGetVertexAttribiv, { "GetVertexAttribiv", "GetVertexAttribivARB", nullptr } }, michael@0: { (PRFuncPtr*) &mSymbols.fGetVertexAttribPointerv, { "GetVertexAttribPointerv", nullptr } }, michael@0: { (PRFuncPtr*) &mSymbols.fHint, { "Hint", nullptr } }, michael@0: { (PRFuncPtr*) &mSymbols.fIsBuffer, { "IsBuffer", "IsBufferARB", nullptr } }, michael@0: { (PRFuncPtr*) &mSymbols.fIsEnabled, { "IsEnabled", nullptr } }, michael@0: { (PRFuncPtr*) &mSymbols.fIsProgram, { "IsProgram", "IsProgramARB", nullptr } }, michael@0: { (PRFuncPtr*) &mSymbols.fIsShader, { "IsShader", "IsShaderARB", nullptr } }, michael@0: { (PRFuncPtr*) &mSymbols.fIsTexture, { "IsTexture", "IsTextureARB", nullptr } }, michael@0: { (PRFuncPtr*) &mSymbols.fLineWidth, { "LineWidth", nullptr } }, michael@0: { (PRFuncPtr*) &mSymbols.fLinkProgram, { "LinkProgram", "LinkProgramARB", nullptr } }, michael@0: { (PRFuncPtr*) &mSymbols.fPixelStorei, { "PixelStorei", nullptr } }, michael@0: { (PRFuncPtr*) &mSymbols.fPolygonOffset, { "PolygonOffset", nullptr } }, michael@0: { (PRFuncPtr*) &mSymbols.fReadPixels, { "ReadPixels", nullptr } }, michael@0: { (PRFuncPtr*) &mSymbols.fSampleCoverage, { "SampleCoverage", nullptr } }, michael@0: { (PRFuncPtr*) &mSymbols.fScissor, { "Scissor", nullptr } }, michael@0: { (PRFuncPtr*) &mSymbols.fStencilFunc, { "StencilFunc", nullptr } }, michael@0: { (PRFuncPtr*) &mSymbols.fStencilFuncSeparate, { "StencilFuncSeparate", "StencilFuncSeparateEXT", nullptr } }, michael@0: { (PRFuncPtr*) &mSymbols.fStencilMask, { "StencilMask", nullptr } }, michael@0: { (PRFuncPtr*) &mSymbols.fStencilMaskSeparate, { "StencilMaskSeparate", "StencilMaskSeparateEXT", nullptr } }, michael@0: { (PRFuncPtr*) &mSymbols.fStencilOp, { "StencilOp", nullptr } }, michael@0: { (PRFuncPtr*) &mSymbols.fStencilOpSeparate, { "StencilOpSeparate", "StencilOpSeparateEXT", nullptr } }, michael@0: { (PRFuncPtr*) &mSymbols.fTexImage2D, { "TexImage2D", nullptr } }, michael@0: { (PRFuncPtr*) &mSymbols.fTexSubImage2D, { "TexSubImage2D", nullptr } }, michael@0: { (PRFuncPtr*) &mSymbols.fUniform1f, { "Uniform1f", nullptr } }, michael@0: { (PRFuncPtr*) &mSymbols.fUniform1fv, { "Uniform1fv", nullptr } }, michael@0: { (PRFuncPtr*) &mSymbols.fUniform1i, { "Uniform1i", nullptr } }, michael@0: { (PRFuncPtr*) &mSymbols.fUniform1iv, { "Uniform1iv", nullptr } }, michael@0: { (PRFuncPtr*) &mSymbols.fUniform2f, { "Uniform2f", nullptr } }, michael@0: { (PRFuncPtr*) &mSymbols.fUniform2fv, { "Uniform2fv", nullptr } }, michael@0: { (PRFuncPtr*) &mSymbols.fUniform2i, { "Uniform2i", nullptr } }, michael@0: { (PRFuncPtr*) &mSymbols.fUniform2iv, { "Uniform2iv", nullptr } }, michael@0: { (PRFuncPtr*) &mSymbols.fUniform3f, { "Uniform3f", nullptr } }, michael@0: { (PRFuncPtr*) &mSymbols.fUniform3fv, { "Uniform3fv", nullptr } }, michael@0: { (PRFuncPtr*) &mSymbols.fUniform3i, { "Uniform3i", nullptr } }, michael@0: { (PRFuncPtr*) &mSymbols.fUniform3iv, { "Uniform3iv", nullptr } }, michael@0: { (PRFuncPtr*) &mSymbols.fUniform4f, { "Uniform4f", nullptr } }, michael@0: { (PRFuncPtr*) &mSymbols.fUniform4fv, { "Uniform4fv", nullptr } }, michael@0: { (PRFuncPtr*) &mSymbols.fUniform4i, { "Uniform4i", nullptr } }, michael@0: { (PRFuncPtr*) &mSymbols.fUniform4iv, { "Uniform4iv", nullptr } }, michael@0: { (PRFuncPtr*) &mSymbols.fUniformMatrix2fv, { "UniformMatrix2fv", nullptr } }, michael@0: { (PRFuncPtr*) &mSymbols.fUniformMatrix3fv, { "UniformMatrix3fv", nullptr } }, michael@0: { (PRFuncPtr*) &mSymbols.fUniformMatrix4fv, { "UniformMatrix4fv", nullptr } }, michael@0: { (PRFuncPtr*) &mSymbols.fUseProgram, { "UseProgram", nullptr } }, michael@0: { (PRFuncPtr*) &mSymbols.fValidateProgram, { "ValidateProgram", nullptr } }, michael@0: { (PRFuncPtr*) &mSymbols.fVertexAttribPointer, { "VertexAttribPointer", nullptr } }, michael@0: { (PRFuncPtr*) &mSymbols.fVertexAttrib1f, { "VertexAttrib1f", nullptr } }, michael@0: { (PRFuncPtr*) &mSymbols.fVertexAttrib2f, { "VertexAttrib2f", nullptr } }, michael@0: { (PRFuncPtr*) &mSymbols.fVertexAttrib3f, { "VertexAttrib3f", nullptr } }, michael@0: { (PRFuncPtr*) &mSymbols.fVertexAttrib4f, { "VertexAttrib4f", nullptr } }, michael@0: { (PRFuncPtr*) &mSymbols.fVertexAttrib1fv, { "VertexAttrib1fv", nullptr } }, michael@0: { (PRFuncPtr*) &mSymbols.fVertexAttrib2fv, { "VertexAttrib2fv", nullptr } }, michael@0: { (PRFuncPtr*) &mSymbols.fVertexAttrib3fv, { "VertexAttrib3fv", nullptr } }, michael@0: { (PRFuncPtr*) &mSymbols.fVertexAttrib4fv, { "VertexAttrib4fv", nullptr } }, michael@0: { (PRFuncPtr*) &mSymbols.fViewport, { "Viewport", nullptr } }, michael@0: { (PRFuncPtr*) &mSymbols.fCompileShader, { "CompileShader", nullptr } }, michael@0: { (PRFuncPtr*) &mSymbols.fCopyTexImage2D, { "CopyTexImage2D", nullptr } }, michael@0: { (PRFuncPtr*) &mSymbols.fCopyTexSubImage2D, { "CopyTexSubImage2D", nullptr } }, michael@0: { (PRFuncPtr*) &mSymbols.fGetShaderiv, { "GetShaderiv", nullptr } }, michael@0: { (PRFuncPtr*) &mSymbols.fGetShaderInfoLog, { "GetShaderInfoLog", nullptr } }, michael@0: { (PRFuncPtr*) &mSymbols.fGetShaderSource, { "GetShaderSource", nullptr } }, michael@0: { (PRFuncPtr*) &mSymbols.fShaderSource, { "ShaderSource", nullptr } }, michael@0: { (PRFuncPtr*) &mSymbols.fVertexAttribPointer, { "VertexAttribPointer", nullptr } }, michael@0: { (PRFuncPtr*) &mSymbols.fBindFramebuffer, { "BindFramebuffer", "BindFramebufferEXT", nullptr } }, michael@0: { (PRFuncPtr*) &mSymbols.fBindRenderbuffer, { "BindRenderbuffer", "BindRenderbufferEXT", nullptr } }, michael@0: { (PRFuncPtr*) &mSymbols.fCheckFramebufferStatus, { "CheckFramebufferStatus", "CheckFramebufferStatusEXT", nullptr } }, michael@0: { (PRFuncPtr*) &mSymbols.fFramebufferRenderbuffer, { "FramebufferRenderbuffer", "FramebufferRenderbufferEXT", nullptr } }, michael@0: { (PRFuncPtr*) &mSymbols.fFramebufferTexture2D, { "FramebufferTexture2D", "FramebufferTexture2DEXT", nullptr } }, michael@0: { (PRFuncPtr*) &mSymbols.fGenerateMipmap, { "GenerateMipmap", "GenerateMipmapEXT", nullptr } }, michael@0: { (PRFuncPtr*) &mSymbols.fGetFramebufferAttachmentParameteriv, { "GetFramebufferAttachmentParameteriv", "GetFramebufferAttachmentParameterivEXT", nullptr } }, michael@0: { (PRFuncPtr*) &mSymbols.fGetRenderbufferParameteriv, { "GetRenderbufferParameteriv", "GetRenderbufferParameterivEXT", nullptr } }, michael@0: { (PRFuncPtr*) &mSymbols.fIsFramebuffer, { "IsFramebuffer", "IsFramebufferEXT", nullptr } }, michael@0: { (PRFuncPtr*) &mSymbols.fIsRenderbuffer, { "IsRenderbuffer", "IsRenderbufferEXT", nullptr } }, michael@0: { (PRFuncPtr*) &mSymbols.fRenderbufferStorage, { "RenderbufferStorage", "RenderbufferStorageEXT", nullptr } }, michael@0: michael@0: { (PRFuncPtr*) &mSymbols.fGenBuffers, { "GenBuffers", "GenBuffersARB", nullptr } }, michael@0: { (PRFuncPtr*) &mSymbols.fGenTextures, { "GenTextures", nullptr } }, michael@0: { (PRFuncPtr*) &mSymbols.fCreateProgram, { "CreateProgram", "CreateProgramARB", nullptr } }, michael@0: { (PRFuncPtr*) &mSymbols.fCreateShader, { "CreateShader", "CreateShaderARB", nullptr } }, michael@0: { (PRFuncPtr*) &mSymbols.fGenFramebuffers, { "GenFramebuffers", "GenFramebuffersEXT", nullptr } }, michael@0: { (PRFuncPtr*) &mSymbols.fGenRenderbuffers, { "GenRenderbuffers", "GenRenderbuffersEXT", nullptr } }, michael@0: michael@0: { (PRFuncPtr*) &mSymbols.fDeleteBuffers, { "DeleteBuffers", "DeleteBuffersARB", nullptr } }, michael@0: { (PRFuncPtr*) &mSymbols.fDeleteTextures, { "DeleteTextures", "DeleteTexturesARB", nullptr } }, michael@0: { (PRFuncPtr*) &mSymbols.fDeleteProgram, { "DeleteProgram", "DeleteProgramARB", nullptr } }, michael@0: { (PRFuncPtr*) &mSymbols.fDeleteShader, { "DeleteShader", "DeleteShaderARB", nullptr } }, michael@0: { (PRFuncPtr*) &mSymbols.fDeleteFramebuffers, { "DeleteFramebuffers", "DeleteFramebuffersEXT", nullptr } }, michael@0: { (PRFuncPtr*) &mSymbols.fDeleteRenderbuffers, { "DeleteRenderbuffers", "DeleteRenderbuffersEXT", nullptr } }, michael@0: michael@0: { nullptr, { nullptr } }, michael@0: michael@0: }; michael@0: michael@0: mInitialized = LoadSymbols(&symbols[0], trygl, prefix); michael@0: MakeCurrent(); michael@0: if (mInitialized) { michael@0: unsigned int version = 0; michael@0: michael@0: ParseGLVersion(this, &version); michael@0: michael@0: #ifdef DEBUG michael@0: printf_stderr("OpenGL version detected: %u\n", version); michael@0: printf_stderr("OpenGL vendor: %s\n", fGetString(LOCAL_GL_VENDOR)); michael@0: printf_stderr("OpenGL renderer: %s\n", fGetString(LOCAL_GL_RENDERER)); michael@0: #endif michael@0: michael@0: if (version >= mVersion) { michael@0: mVersion = version; michael@0: } michael@0: // Don't fail if version < mVersion, see bug 999445, michael@0: // Mac OSX 10.6/10.7 machines with Intel GPUs claim only OpenGL 1.4 but michael@0: // have all the GL2+ extensions that we need. michael@0: } michael@0: michael@0: // Load OpenGL ES 2.0 symbols, or desktop if we aren't using ES 2. michael@0: if (mInitialized) { michael@0: if (IsGLES()) { michael@0: SymLoadStruct symbols_ES2[] = { michael@0: { (PRFuncPtr*) &mSymbols.fGetShaderPrecisionFormat, { "GetShaderPrecisionFormat", nullptr } }, michael@0: { (PRFuncPtr*) &mSymbols.fClearDepthf, { "ClearDepthf", nullptr } }, michael@0: { (PRFuncPtr*) &mSymbols.fDepthRangef, { "DepthRangef", nullptr } }, michael@0: { nullptr, { nullptr } }, michael@0: }; michael@0: michael@0: if (!LoadSymbols(&symbols_ES2[0], trygl, prefix)) { michael@0: NS_ERROR("OpenGL ES 2.0 supported, but symbols could not be loaded."); michael@0: mInitialized = false; michael@0: } michael@0: } else { michael@0: SymLoadStruct symbols_desktop[] = { michael@0: { (PRFuncPtr*) &mSymbols.fClearDepth, { "ClearDepth", nullptr } }, michael@0: { (PRFuncPtr*) &mSymbols.fDepthRange, { "DepthRange", nullptr } }, michael@0: { (PRFuncPtr*) &mSymbols.fReadBuffer, { "ReadBuffer", nullptr } }, michael@0: { (PRFuncPtr*) &mSymbols.fMapBuffer, { "MapBuffer", nullptr } }, michael@0: { (PRFuncPtr*) &mSymbols.fUnmapBuffer, { "UnmapBuffer", nullptr } }, michael@0: { (PRFuncPtr*) &mSymbols.fPointParameterf, { "PointParameterf", nullptr } }, michael@0: { (PRFuncPtr*) &mSymbols.fDrawBuffer, { "DrawBuffer", nullptr } }, michael@0: // These functions are only used by Skia/GL in desktop mode. michael@0: // Other parts of Gecko should avoid using these michael@0: { (PRFuncPtr*) &mSymbols.fDrawBuffers, { "DrawBuffers", nullptr } }, michael@0: { (PRFuncPtr*) &mSymbols.fClientActiveTexture, { "ClientActiveTexture", nullptr } }, michael@0: { (PRFuncPtr*) &mSymbols.fDisableClientState, { "DisableClientState", nullptr } }, michael@0: { (PRFuncPtr*) &mSymbols.fEnableClientState, { "EnableClientState", nullptr } }, michael@0: { (PRFuncPtr*) &mSymbols.fLoadIdentity, { "LoadIdentity", nullptr } }, michael@0: { (PRFuncPtr*) &mSymbols.fLoadMatrixf, { "LoadMatrixf", nullptr } }, michael@0: { (PRFuncPtr*) &mSymbols.fMatrixMode, { "MatrixMode", nullptr } }, michael@0: { (PRFuncPtr*) &mSymbols.fTexGeni, { "TexGeni", nullptr } }, michael@0: { (PRFuncPtr*) &mSymbols.fTexGenf, { "TexGenf", nullptr } }, michael@0: { (PRFuncPtr*) &mSymbols.fTexGenfv, { "TexGenfv", nullptr } }, michael@0: { (PRFuncPtr*) &mSymbols.fVertexPointer, { "VertexPointer", nullptr } }, michael@0: { nullptr, { nullptr } }, michael@0: }; michael@0: michael@0: if (!LoadSymbols(&symbols_desktop[0], trygl, prefix)) { michael@0: NS_ERROR("Desktop symbols failed to load."); michael@0: mInitialized = false; michael@0: } michael@0: } michael@0: } michael@0: michael@0: const char *glVendorString = nullptr; michael@0: const char *glRendererString = nullptr; michael@0: michael@0: if (mInitialized) { michael@0: // The order of these strings must match up with the order of the enum michael@0: // defined in GLContext.h for vendor IDs michael@0: glVendorString = (const char *)fGetString(LOCAL_GL_VENDOR); michael@0: if (!glVendorString) michael@0: mInitialized = false; michael@0: michael@0: const char *vendorMatchStrings[size_t(GLVendor::Other)] = { michael@0: "Intel", michael@0: "NVIDIA", michael@0: "ATI", michael@0: "Qualcomm", michael@0: "Imagination", michael@0: "nouveau", michael@0: "Vivante", michael@0: "VMware, Inc." michael@0: }; michael@0: michael@0: mVendor = GLVendor::Other; michael@0: for (size_t i = 0; i < size_t(GLVendor::Other); ++i) { michael@0: if (DoesStringMatch(glVendorString, vendorMatchStrings[i])) { michael@0: mVendor = GLVendor(i); michael@0: break; michael@0: } michael@0: } michael@0: michael@0: // The order of these strings must match up with the order of the enum michael@0: // defined in GLContext.h for renderer IDs michael@0: glRendererString = (const char *)fGetString(LOCAL_GL_RENDERER); michael@0: if (!glRendererString) michael@0: mInitialized = false; michael@0: michael@0: const char *rendererMatchStrings[size_t(GLRenderer::Other)] = { michael@0: "Adreno 200", michael@0: "Adreno 205", michael@0: "Adreno (TM) 205", michael@0: "Adreno (TM) 320", michael@0: "PowerVR SGX 530", michael@0: "PowerVR SGX 540", michael@0: "NVIDIA Tegra", michael@0: "Android Emulator", michael@0: "Gallium 0.4 on llvmpipe" michael@0: }; michael@0: michael@0: mRenderer = GLRenderer::Other; michael@0: for (size_t i = 0; i < size_t(GLRenderer::Other); ++i) { michael@0: if (DoesStringMatch(glRendererString, rendererMatchStrings[i])) { michael@0: mRenderer = GLRenderer(i); michael@0: break; michael@0: } michael@0: } michael@0: } michael@0: michael@0: michael@0: #ifdef DEBUG michael@0: if (PR_GetEnv("MOZ_GL_DEBUG")) michael@0: sDebugMode |= DebugEnabled; michael@0: michael@0: // enables extra verbose output, informing of the start and finish of every GL call. michael@0: // useful e.g. to record information to investigate graphics system crashes/lockups michael@0: if (PR_GetEnv("MOZ_GL_DEBUG_VERBOSE")) michael@0: sDebugMode |= DebugTrace; michael@0: michael@0: // aborts on GL error. Can be useful to debug quicker code that is known not to generate any GL error in principle. michael@0: if (PR_GetEnv("MOZ_GL_DEBUG_ABORT_ON_ERROR")) michael@0: sDebugMode |= DebugAbortOnError; michael@0: #endif michael@0: michael@0: if (mInitialized) { michael@0: #ifdef DEBUG michael@0: static bool firstRun = true; michael@0: if (firstRun && DebugMode()) { michael@0: const char *vendors[size_t(GLVendor::Other)] = { michael@0: "Intel", michael@0: "NVIDIA", michael@0: "ATI", michael@0: "Qualcomm" michael@0: }; michael@0: michael@0: MOZ_ASSERT(glVendorString); michael@0: if (mVendor < GLVendor::Other) { michael@0: printf_stderr("OpenGL vendor ('%s') recognized as: %s\n", michael@0: glVendorString, vendors[size_t(mVendor)]); michael@0: } else { michael@0: printf_stderr("OpenGL vendor ('%s') unrecognized\n", glVendorString); michael@0: } michael@0: } michael@0: firstRun = false; michael@0: #endif michael@0: michael@0: InitExtensions(); michael@0: InitFeatures(); michael@0: michael@0: // Disable extensions with partial or incorrect support. michael@0: if (WorkAroundDriverBugs()) { michael@0: if (Renderer() == GLRenderer::AdrenoTM320) { michael@0: MarkUnsupported(GLFeature::standard_derivatives); michael@0: } michael@0: michael@0: if (Vendor() == GLVendor::Vivante) { michael@0: // bug 958256 michael@0: MarkUnsupported(GLFeature::standard_derivatives); michael@0: } michael@0: michael@0: if (Vendor() == GLVendor::Imagination && michael@0: Renderer() == GLRenderer::SGX540) { michael@0: // Bug 980048 michael@0: MarkExtensionUnsupported(OES_EGL_sync); michael@0: } michael@0: michael@0: #ifdef XP_MACOSX michael@0: // The Mac Nvidia driver, for versions up to and including 10.8, don't seem michael@0: // to properly support this. See 814839 michael@0: // this has been fixed in Mac OS X 10.9. See 907946 michael@0: if (Vendor() == gl::GLVendor::NVIDIA && michael@0: !nsCocoaFeatures::OnMavericksOrLater()) michael@0: { michael@0: MarkUnsupported(GLFeature::depth_texture); michael@0: } michael@0: #endif michael@0: // ANGLE's divisor support is busted. (see bug 916816) michael@0: if (IsANGLE()) { michael@0: MarkUnsupported(GLFeature::instanced_arrays); michael@0: } michael@0: } michael@0: michael@0: NS_ASSERTION(!IsExtensionSupported(GLContext::ARB_pixel_buffer_object) || michael@0: (mSymbols.fMapBuffer && mSymbols.fUnmapBuffer), michael@0: "ARB_pixel_buffer_object supported without glMapBuffer/UnmapBuffer being available!"); michael@0: michael@0: if (SupportsRobustness()) { michael@0: mHasRobustness = false; michael@0: michael@0: if (IsExtensionSupported(ARB_robustness)) { michael@0: SymLoadStruct robustnessSymbols[] = { michael@0: { (PRFuncPtr*) &mSymbols.fGetGraphicsResetStatus, { "GetGraphicsResetStatusARB", nullptr } }, michael@0: { nullptr, { nullptr } }, michael@0: }; michael@0: michael@0: if (!LoadSymbols(&robustnessSymbols[0], trygl, prefix)) { michael@0: NS_ERROR("GL supports ARB_robustness without supplying GetGraphicsResetStatusARB."); michael@0: michael@0: mSymbols.fGetGraphicsResetStatus = nullptr; michael@0: } else { michael@0: mHasRobustness = true; michael@0: } michael@0: } michael@0: if (!IsExtensionSupported(ARB_robustness) && michael@0: IsExtensionSupported(EXT_robustness)) { michael@0: SymLoadStruct robustnessSymbols[] = { michael@0: { (PRFuncPtr*) &mSymbols.fGetGraphicsResetStatus, { "GetGraphicsResetStatusEXT", nullptr } }, michael@0: { nullptr, { nullptr } }, michael@0: }; michael@0: michael@0: if (!LoadSymbols(&robustnessSymbols[0], trygl, prefix)) { michael@0: NS_ERROR("GL supports EXT_robustness without supplying GetGraphicsResetStatusEXT."); michael@0: michael@0: mSymbols.fGetGraphicsResetStatus = nullptr; michael@0: } else { michael@0: mHasRobustness = true; michael@0: } michael@0: } michael@0: michael@0: if (!mHasRobustness) { michael@0: MarkUnsupported(GLFeature::robustness); michael@0: } michael@0: } michael@0: michael@0: // Check for aux symbols based on extensions michael@0: if (IsSupported(GLFeature::framebuffer_blit)) michael@0: { michael@0: SymLoadStruct auxSymbols[] = { michael@0: { michael@0: (PRFuncPtr*) &mSymbols.fBlitFramebuffer, michael@0: { michael@0: "BlitFramebuffer", michael@0: "BlitFramebufferEXT", michael@0: "BlitFramebufferANGLE", michael@0: nullptr michael@0: } michael@0: }, michael@0: { nullptr, { nullptr } }, michael@0: }; michael@0: if (!LoadSymbols(&auxSymbols[0], trygl, prefix)) { michael@0: NS_ERROR("GL supports framebuffer_blit without supplying glBlitFramebuffer"); michael@0: michael@0: MarkUnsupported(GLFeature::framebuffer_blit); michael@0: mSymbols.fBlitFramebuffer = nullptr; michael@0: } michael@0: } michael@0: michael@0: if (IsSupported(GLFeature::framebuffer_multisample)) michael@0: { michael@0: SymLoadStruct auxSymbols[] = { michael@0: { michael@0: (PRFuncPtr*) &mSymbols.fRenderbufferStorageMultisample, michael@0: { michael@0: "RenderbufferStorageMultisample", michael@0: "RenderbufferStorageMultisampleEXT", michael@0: "RenderbufferStorageMultisampleANGLE", michael@0: nullptr michael@0: } michael@0: }, michael@0: { nullptr, { nullptr } }, michael@0: }; michael@0: if (!LoadSymbols(&auxSymbols[0], trygl, prefix)) { michael@0: NS_ERROR("GL supports framebuffer_multisample without supplying glRenderbufferStorageMultisample"); michael@0: michael@0: MarkUnsupported(GLFeature::framebuffer_multisample); michael@0: mSymbols.fRenderbufferStorageMultisample = nullptr; michael@0: } michael@0: } michael@0: michael@0: if (IsExtensionSupported(ARB_sync)) { michael@0: SymLoadStruct syncSymbols[] = { michael@0: { (PRFuncPtr*) &mSymbols.fFenceSync, { "FenceSync", nullptr } }, michael@0: { (PRFuncPtr*) &mSymbols.fIsSync, { "IsSync", nullptr } }, michael@0: { (PRFuncPtr*) &mSymbols.fDeleteSync, { "DeleteSync", nullptr } }, michael@0: { (PRFuncPtr*) &mSymbols.fClientWaitSync, { "ClientWaitSync", nullptr } }, michael@0: { (PRFuncPtr*) &mSymbols.fWaitSync, { "WaitSync", nullptr } }, michael@0: { (PRFuncPtr*) &mSymbols.fGetInteger64v, { "GetInteger64v", nullptr } }, michael@0: { (PRFuncPtr*) &mSymbols.fGetSynciv, { "GetSynciv", nullptr } }, michael@0: { nullptr, { nullptr } }, michael@0: }; michael@0: michael@0: if (!LoadSymbols(&syncSymbols[0], trygl, prefix)) { michael@0: NS_ERROR("GL supports ARB_sync without supplying its functions."); michael@0: michael@0: MarkExtensionUnsupported(ARB_sync); michael@0: mSymbols.fFenceSync = nullptr; michael@0: mSymbols.fIsSync = nullptr; michael@0: mSymbols.fDeleteSync = nullptr; michael@0: mSymbols.fClientWaitSync = nullptr; michael@0: mSymbols.fWaitSync = nullptr; michael@0: mSymbols.fGetInteger64v = nullptr; michael@0: mSymbols.fGetSynciv = nullptr; michael@0: } michael@0: } michael@0: michael@0: if (IsExtensionSupported(OES_EGL_image)) { michael@0: SymLoadStruct imageSymbols[] = { michael@0: { (PRFuncPtr*) &mSymbols.fEGLImageTargetTexture2D, { "EGLImageTargetTexture2DOES", nullptr } }, michael@0: { (PRFuncPtr*) &mSymbols.fEGLImageTargetRenderbufferStorage, { "EGLImageTargetRenderbufferStorageOES", nullptr } }, michael@0: { nullptr, { nullptr } }, michael@0: }; michael@0: michael@0: if (!LoadSymbols(&imageSymbols[0], trygl, prefix)) { michael@0: NS_ERROR("GL supports OES_EGL_image without supplying its functions."); michael@0: michael@0: MarkExtensionUnsupported(OES_EGL_image); michael@0: mSymbols.fEGLImageTargetTexture2D = nullptr; michael@0: mSymbols.fEGLImageTargetRenderbufferStorage = nullptr; michael@0: } michael@0: } michael@0: michael@0: if (IsExtensionSupported(APPLE_texture_range)) { michael@0: SymLoadStruct vaoSymbols[] = { michael@0: { (PRFuncPtr*) &mSymbols.fTextureRangeAPPLE, { "TextureRangeAPPLE", nullptr } }, michael@0: { nullptr, { nullptr } }, michael@0: }; michael@0: michael@0: if (!LoadSymbols(&vaoSymbols[0], trygl, prefix)) { michael@0: mSymbols.fTextureRangeAPPLE = nullptr; michael@0: } michael@0: } michael@0: michael@0: if (IsExtensionSupported(ARB_vertex_array_object) || michael@0: IsExtensionSupported(OES_vertex_array_object)) { michael@0: SymLoadStruct vaoSymbols[] = { michael@0: { (PRFuncPtr*) &mSymbols.fIsVertexArray, { "IsVertexArray", "IsVertexArrayOES", nullptr } }, michael@0: { (PRFuncPtr*) &mSymbols.fGenVertexArrays, { "GenVertexArrays", "GenVertexArraysOES", nullptr } }, michael@0: { (PRFuncPtr*) &mSymbols.fBindVertexArray, { "BindVertexArray", "BindVertexArrayOES", nullptr } }, michael@0: { (PRFuncPtr*) &mSymbols.fDeleteVertexArrays, { "DeleteVertexArrays", "DeleteVertexArraysOES", nullptr } }, michael@0: { nullptr, { nullptr } }, michael@0: }; michael@0: michael@0: if (!LoadSymbols(&vaoSymbols[0], trygl, prefix)) { michael@0: NS_ERROR("GL supports Vertex Array Object without supplying its functions."); michael@0: michael@0: MarkUnsupported(GLFeature::vertex_array_object); michael@0: mSymbols.fIsVertexArray = nullptr; michael@0: mSymbols.fGenVertexArrays = nullptr; michael@0: mSymbols.fBindVertexArray = nullptr; michael@0: mSymbols.fDeleteVertexArrays = nullptr; michael@0: } michael@0: } michael@0: else if (IsExtensionSupported(APPLE_vertex_array_object)) { michael@0: /* michael@0: * separate call to LoadSymbols with APPLE_vertex_array_object to work around michael@0: * a driver bug : the IsVertexArray symbol (without suffix) can be present but unusable. michael@0: */ michael@0: SymLoadStruct vaoSymbols[] = { michael@0: { (PRFuncPtr*) &mSymbols.fIsVertexArray, { "IsVertexArrayAPPLE", nullptr } }, michael@0: { (PRFuncPtr*) &mSymbols.fGenVertexArrays, { "GenVertexArraysAPPLE", nullptr } }, michael@0: { (PRFuncPtr*) &mSymbols.fBindVertexArray, { "BindVertexArrayAPPLE", nullptr } }, michael@0: { (PRFuncPtr*) &mSymbols.fDeleteVertexArrays, { "DeleteVertexArraysAPPLE", nullptr } }, michael@0: { nullptr, { nullptr } }, michael@0: }; michael@0: michael@0: if (!LoadSymbols(&vaoSymbols[0], trygl, prefix)) { michael@0: NS_ERROR("GL supports Vertex Array Object without supplying its functions."); michael@0: michael@0: MarkUnsupported(GLFeature::vertex_array_object); michael@0: mSymbols.fIsVertexArray = nullptr; michael@0: mSymbols.fGenVertexArrays = nullptr; michael@0: mSymbols.fBindVertexArray = nullptr; michael@0: mSymbols.fDeleteVertexArrays = nullptr; michael@0: } michael@0: } michael@0: michael@0: if (IsSupported(GLFeature::draw_instanced)) { michael@0: SymLoadStruct drawInstancedSymbols[] = { michael@0: { (PRFuncPtr*) &mSymbols.fDrawArraysInstanced, michael@0: { "DrawArraysInstanced", michael@0: "DrawArraysInstancedARB", michael@0: "DrawArraysInstancedEXT", michael@0: "DrawArraysInstancedNV", michael@0: "DrawArraysInstancedANGLE", michael@0: nullptr michael@0: } michael@0: }, michael@0: { (PRFuncPtr*) &mSymbols.fDrawElementsInstanced, michael@0: { "DrawElementsInstanced", michael@0: "DrawElementsInstancedARB", michael@0: "DrawElementsInstancedEXT", michael@0: "DrawElementsInstancedNV", michael@0: "DrawElementsInstancedANGLE", michael@0: nullptr michael@0: } michael@0: }, michael@0: { nullptr, { nullptr } }, michael@0: }; michael@0: michael@0: if (!LoadSymbols(drawInstancedSymbols, trygl, prefix)) { michael@0: NS_ERROR("GL supports instanced draws without supplying its functions."); michael@0: michael@0: MarkUnsupported(GLFeature::draw_instanced); michael@0: mSymbols.fDrawArraysInstanced = nullptr; michael@0: mSymbols.fDrawElementsInstanced = nullptr; michael@0: } michael@0: } michael@0: michael@0: if (IsSupported(GLFeature::instanced_arrays)) { michael@0: SymLoadStruct instancedArraySymbols[] = { michael@0: { (PRFuncPtr*) &mSymbols.fVertexAttribDivisor, michael@0: { "VertexAttribDivisor", michael@0: "VertexAttribDivisorARB", michael@0: "VertexAttribDivisorNV", michael@0: "VertexAttribDivisorANGLE", michael@0: nullptr michael@0: } michael@0: }, michael@0: { nullptr, { nullptr } }, michael@0: }; michael@0: michael@0: if (!LoadSymbols(instancedArraySymbols, trygl, prefix)) { michael@0: NS_ERROR("GL supports array instanced without supplying it function."); michael@0: michael@0: MarkUnsupported(GLFeature::instanced_arrays); michael@0: mSymbols.fVertexAttribDivisor = nullptr; michael@0: } michael@0: } michael@0: michael@0: if (IsSupported(GLFeature::transform_feedback)) { michael@0: SymLoadStruct transformFeedbackSymbols[] = { michael@0: { (PRFuncPtr*) &mSymbols.fBindBufferBase, michael@0: { "BindBufferBase", michael@0: "BindBufferBaseEXT", michael@0: "BindBufferBaseNV", michael@0: nullptr michael@0: } michael@0: }, michael@0: { (PRFuncPtr*) &mSymbols.fBindBufferRange, michael@0: { "BindBufferRange", michael@0: "BindBufferRangeEXT", michael@0: "BindBufferRangeNV", michael@0: nullptr michael@0: } michael@0: }, michael@0: { (PRFuncPtr*) &mSymbols.fBeginTransformFeedback, michael@0: { "BeginTransformFeedback", michael@0: "BeginTransformFeedbackEXT", michael@0: "BeginTransformFeedbackNV", michael@0: nullptr michael@0: } michael@0: }, michael@0: { (PRFuncPtr*) &mSymbols.fEndTransformFeedback, michael@0: { "EndTransformFeedback", michael@0: "EndTransformFeedbackEXT", michael@0: "EndTransformFeedbackNV", michael@0: nullptr michael@0: } michael@0: }, michael@0: { (PRFuncPtr*) &mSymbols.fTransformFeedbackVaryings, michael@0: { "TransformFeedbackVaryings", michael@0: "TransformFeedbackVaryingsEXT", michael@0: "TransformFeedbackVaryingsNV", michael@0: nullptr michael@0: } michael@0: }, michael@0: { (PRFuncPtr*) &mSymbols.fGetTransformFeedbackVarying, michael@0: { "GetTransformFeedbackVarying", michael@0: "GetTransformFeedbackVaryingEXT", michael@0: "GetTransformFeedbackVaryingNV", michael@0: nullptr michael@0: } michael@0: }, michael@0: { (PRFuncPtr*) &mSymbols.fGetIntegeri_v, michael@0: { "GetIntegeri_v", michael@0: "GetIntegerIndexedvEXT", michael@0: "GetIntegerIndexedvNV", michael@0: nullptr michael@0: } michael@0: }, michael@0: { nullptr, { nullptr } }, michael@0: }; michael@0: michael@0: if (!LoadSymbols(transformFeedbackSymbols, trygl, prefix)) { michael@0: NS_ERROR("GL supports transform feedback without supplying its functions."); michael@0: michael@0: MarkUnsupported(GLFeature::transform_feedback); michael@0: MarkUnsupported(GLFeature::bind_buffer_offset); michael@0: mSymbols.fBindBufferBase = nullptr; michael@0: mSymbols.fBindBufferRange = nullptr; michael@0: mSymbols.fBeginTransformFeedback = nullptr; michael@0: mSymbols.fEndTransformFeedback = nullptr; michael@0: mSymbols.fTransformFeedbackVaryings = nullptr; michael@0: mSymbols.fGetTransformFeedbackVarying = nullptr; michael@0: mSymbols.fGetIntegeri_v = nullptr; michael@0: } michael@0: } michael@0: michael@0: if (IsSupported(GLFeature::bind_buffer_offset)) { michael@0: SymLoadStruct bindBufferOffsetSymbols[] = { michael@0: { (PRFuncPtr*) &mSymbols.fBindBufferOffset, michael@0: { "BindBufferOffset", michael@0: "BindBufferOffsetEXT", michael@0: "BindBufferOffsetNV", michael@0: nullptr michael@0: } michael@0: }, michael@0: { nullptr, { nullptr } }, michael@0: }; michael@0: michael@0: if (!LoadSymbols(bindBufferOffsetSymbols, trygl, prefix)) { michael@0: NS_ERROR("GL supports BindBufferOffset without supplying its function."); michael@0: michael@0: MarkUnsupported(GLFeature::bind_buffer_offset); michael@0: mSymbols.fBindBufferOffset = nullptr; michael@0: } michael@0: } michael@0: michael@0: if (IsSupported(GLFeature::query_objects)) { michael@0: SymLoadStruct queryObjectsSymbols[] = { michael@0: { (PRFuncPtr*) &mSymbols.fBeginQuery, { "BeginQuery", "BeginQueryEXT", nullptr } }, michael@0: { (PRFuncPtr*) &mSymbols.fGenQueries, { "GenQueries", "GenQueriesEXT", nullptr } }, michael@0: { (PRFuncPtr*) &mSymbols.fDeleteQueries, { "DeleteQueries", "DeleteQueriesEXT", nullptr } }, michael@0: { (PRFuncPtr*) &mSymbols.fEndQuery, { "EndQuery", "EndQueryEXT", nullptr } }, michael@0: { (PRFuncPtr*) &mSymbols.fGetQueryiv, { "GetQueryiv", "GetQueryivEXT", nullptr } }, michael@0: { (PRFuncPtr*) &mSymbols.fGetQueryObjectuiv, { "GetQueryObjectuiv", "GetQueryObjectuivEXT", nullptr } }, michael@0: { (PRFuncPtr*) &mSymbols.fIsQuery, { "IsQuery", "IsQueryEXT", nullptr } }, michael@0: { nullptr, { nullptr } }, michael@0: }; michael@0: michael@0: if (!LoadSymbols(queryObjectsSymbols, trygl, prefix)) { michael@0: NS_ERROR("GL supports query objects without supplying its functions."); michael@0: michael@0: MarkUnsupported(GLFeature::query_objects); michael@0: MarkUnsupported(GLFeature::get_query_object_iv); michael@0: MarkUnsupported(GLFeature::occlusion_query); michael@0: MarkUnsupported(GLFeature::occlusion_query_boolean); michael@0: MarkUnsupported(GLFeature::occlusion_query2); michael@0: mSymbols.fBeginQuery = nullptr; michael@0: mSymbols.fGenQueries = nullptr; michael@0: mSymbols.fDeleteQueries = nullptr; michael@0: mSymbols.fEndQuery = nullptr; michael@0: mSymbols.fGetQueryiv = nullptr; michael@0: mSymbols.fGetQueryObjectuiv = nullptr; michael@0: mSymbols.fIsQuery = nullptr; michael@0: } michael@0: } michael@0: michael@0: if (IsSupported(GLFeature::get_query_object_iv)) { michael@0: SymLoadStruct queryObjectsSymbols[] = { michael@0: { (PRFuncPtr*) &mSymbols.fGetQueryObjectiv, { "GetQueryObjectiv", "GetQueryObjectivEXT", nullptr } }, michael@0: { nullptr, { nullptr } }, michael@0: }; michael@0: michael@0: if (!LoadSymbols(queryObjectsSymbols, trygl, prefix)) { michael@0: NS_ERROR("GL supports query objects iv getter without supplying its function."); michael@0: michael@0: MarkUnsupported(GLFeature::get_query_object_iv); michael@0: mSymbols.fGetQueryObjectiv = nullptr; michael@0: } michael@0: } michael@0: michael@0: if (IsSupported(GLFeature::draw_buffers)) { michael@0: SymLoadStruct drawBuffersSymbols[] = { michael@0: { (PRFuncPtr*) &mSymbols.fDrawBuffers, { "DrawBuffers", nullptr } }, michael@0: { nullptr, { nullptr } }, michael@0: }; michael@0: michael@0: if (!LoadSymbols(drawBuffersSymbols, trygl, prefix)) { michael@0: NS_ERROR("GL supports draw_buffers without supplying its functions."); michael@0: michael@0: MarkUnsupported(GLFeature::draw_buffers); michael@0: mSymbols.fDrawBuffers = nullptr; michael@0: } michael@0: } michael@0: michael@0: if (IsExtensionSupported(KHR_debug)) { michael@0: SymLoadStruct extSymbols[] = { michael@0: { (PRFuncPtr*) &mSymbols.fDebugMessageControl, { "DebugMessageControl", "DebugMessageControlKHR", nullptr } }, michael@0: { (PRFuncPtr*) &mSymbols.fDebugMessageInsert, { "DebugMessageInsert", "DebugMessageInsertKHR", nullptr } }, michael@0: { (PRFuncPtr*) &mSymbols.fDebugMessageCallback, { "DebugMessageCallback", "DebugMessageCallbackKHR", nullptr } }, michael@0: { (PRFuncPtr*) &mSymbols.fGetDebugMessageLog, { "GetDebugMessageLog", "GetDebugMessageLogKHR", nullptr } }, michael@0: { (PRFuncPtr*) &mSymbols.fGetPointerv, { "GetPointerv", "GetPointervKHR", nullptr } }, michael@0: { (PRFuncPtr*) &mSymbols.fPushDebugGroup, { "PushDebugGroup", "PushDebugGroupKHR", nullptr } }, michael@0: { (PRFuncPtr*) &mSymbols.fPopDebugGroup, { "PopDebugGroup", "PopDebugGroupKHR", nullptr } }, michael@0: { (PRFuncPtr*) &mSymbols.fObjectLabel, { "ObjectLabel", "ObjectLabelKHR", nullptr } }, michael@0: { (PRFuncPtr*) &mSymbols.fGetObjectLabel, { "GetObjectLabel", "GetObjectLabelKHR", nullptr } }, michael@0: { (PRFuncPtr*) &mSymbols.fObjectPtrLabel, { "ObjectPtrLabel", "ObjectPtrLabelKHR", nullptr } }, michael@0: { (PRFuncPtr*) &mSymbols.fGetObjectPtrLabel, { "GetObjectPtrLabel", "GetObjectPtrLabelKHR", nullptr } }, michael@0: { nullptr, { nullptr } }, michael@0: }; michael@0: michael@0: if (!LoadSymbols(&extSymbols[0], trygl, prefix)) { michael@0: NS_ERROR("GL supports KHR_debug without supplying its functions."); michael@0: michael@0: MarkExtensionUnsupported(KHR_debug); michael@0: mSymbols.fDebugMessageControl = nullptr; michael@0: mSymbols.fDebugMessageInsert = nullptr; michael@0: mSymbols.fDebugMessageCallback = nullptr; michael@0: mSymbols.fGetDebugMessageLog = nullptr; michael@0: mSymbols.fGetPointerv = nullptr; michael@0: mSymbols.fPushDebugGroup = nullptr; michael@0: mSymbols.fPopDebugGroup = nullptr; michael@0: mSymbols.fObjectLabel = nullptr; michael@0: mSymbols.fGetObjectLabel = nullptr; michael@0: mSymbols.fObjectPtrLabel = nullptr; michael@0: mSymbols.fGetObjectPtrLabel = nullptr; michael@0: } michael@0: } michael@0: michael@0: if (IsSupported(GLFeature::draw_range_elements)) { michael@0: SymLoadStruct imageSymbols[] = { michael@0: { (PRFuncPtr*) &mSymbols.fDrawRangeElements, { "DrawRangeElementsEXT", "DrawRangeElements", nullptr } }, michael@0: { nullptr, { nullptr } }, michael@0: }; michael@0: michael@0: if (!LoadSymbols(&imageSymbols[0], trygl, prefix)) { michael@0: NS_ERROR("GL supports draw_range_elements without supplying its functions."); michael@0: michael@0: MarkUnsupported(GLFeature::draw_range_elements); michael@0: mSymbols.fDrawRangeElements = nullptr; michael@0: } michael@0: } michael@0: michael@0: // Load developer symbols, don't fail if we can't find them. michael@0: SymLoadStruct auxSymbols[] = { michael@0: { (PRFuncPtr*) &mSymbols.fGetTexImage, { "GetTexImage", nullptr } }, michael@0: { (PRFuncPtr*) &mSymbols.fGetTexLevelParameteriv, { "GetTexLevelParameteriv", nullptr } }, michael@0: { nullptr, { nullptr } }, michael@0: }; michael@0: bool warnOnFailures = DebugMode(); michael@0: LoadSymbols(&auxSymbols[0], trygl, prefix, warnOnFailures); michael@0: } michael@0: michael@0: if (mInitialized) { michael@0: raw_fGetIntegerv(LOCAL_GL_VIEWPORT, mViewportRect); michael@0: raw_fGetIntegerv(LOCAL_GL_SCISSOR_BOX, mScissorRect); michael@0: raw_fGetIntegerv(LOCAL_GL_MAX_TEXTURE_SIZE, &mMaxTextureSize); michael@0: raw_fGetIntegerv(LOCAL_GL_MAX_CUBE_MAP_TEXTURE_SIZE, &mMaxCubeMapTextureSize); michael@0: raw_fGetIntegerv(LOCAL_GL_MAX_RENDERBUFFER_SIZE, &mMaxRenderbufferSize); michael@0: michael@0: #ifdef XP_MACOSX michael@0: if (mWorkAroundDriverBugs) { michael@0: if (mVendor == GLVendor::Intel) { michael@0: // see bug 737182 for 2D textures, bug 684882 for cube map textures. michael@0: mMaxTextureSize = std::min(mMaxTextureSize, 4096); michael@0: mMaxCubeMapTextureSize = std::min(mMaxCubeMapTextureSize, 512); michael@0: // for good measure, we align renderbuffers on what we do for 2D textures michael@0: mMaxRenderbufferSize = std::min(mMaxRenderbufferSize, 4096); michael@0: mNeedsTextureSizeChecks = true; michael@0: } else if (mVendor == GLVendor::NVIDIA) { michael@0: if (nsCocoaFeatures::OnMountainLionOrLater()) { michael@0: // See bug 879656. 8192 fails, 8191 works. michael@0: mMaxTextureSize = std::min(mMaxTextureSize, 8191); michael@0: mMaxRenderbufferSize = std::min(mMaxRenderbufferSize, 8191); michael@0: } michael@0: else { michael@0: // See bug 877949. michael@0: mMaxTextureSize = std::min(mMaxTextureSize, 4096); michael@0: mMaxRenderbufferSize = std::min(mMaxRenderbufferSize, 4096); michael@0: } michael@0: michael@0: // Part of the bug 879656, but it also doesn't hurt the 877949 michael@0: mNeedsTextureSizeChecks = true; michael@0: } michael@0: } michael@0: #endif michael@0: #ifdef MOZ_X11 michael@0: if (mWorkAroundDriverBugs && michael@0: mVendor == GLVendor::Nouveau) { michael@0: // see bug 814716. Clamp MaxCubeMapTextureSize at 2K for Nouveau. michael@0: mMaxCubeMapTextureSize = std::min(mMaxCubeMapTextureSize, 2048); michael@0: mNeedsTextureSizeChecks = true; michael@0: } michael@0: #endif michael@0: michael@0: mMaxTextureImageSize = mMaxTextureSize; michael@0: michael@0: mMaxSamples = 0; michael@0: if (IsSupported(GLFeature::framebuffer_multisample)) { michael@0: fGetIntegerv(LOCAL_GL_MAX_SAMPLES, (GLint*)&mMaxSamples); michael@0: } michael@0: michael@0: // We're ready for final setup. michael@0: fBindFramebuffer(LOCAL_GL_FRAMEBUFFER, 0); michael@0: michael@0: if (mCaps.any) michael@0: DetermineCaps(); michael@0: michael@0: UpdatePixelFormat(); michael@0: UpdateGLFormats(mCaps); michael@0: michael@0: mTexGarbageBin = new TextureGarbageBin(this); michael@0: michael@0: MOZ_ASSERT(IsCurrent()); michael@0: } michael@0: michael@0: if (mInitialized) michael@0: reporter.SetSuccessful(); michael@0: else { michael@0: // if initialization fails, ensure all symbols are zero, to avoid hard-to-understand bugs michael@0: mSymbols.Zero(); michael@0: NS_WARNING("InitWithPrefix failed!"); michael@0: } michael@0: michael@0: mVersionString = nsPrintfCString("%u.%u.%u", mVersion / 100, (mVersion / 10) % 10, mVersion % 10); michael@0: michael@0: return mInitialized; michael@0: } michael@0: michael@0: void michael@0: GLContext::InitExtensions() michael@0: { michael@0: MakeCurrent(); michael@0: const char* extensions = (const char*)fGetString(LOCAL_GL_EXTENSIONS); michael@0: if (!extensions) michael@0: return; michael@0: michael@0: #ifdef DEBUG michael@0: static bool firstRun = true; michael@0: #else michael@0: // Non-DEBUG, so never spew. michael@0: const bool firstRun = false; michael@0: #endif michael@0: michael@0: InitializeExtensionsBitSet(mAvailableExtensions, extensions, sExtensionNames, firstRun && DebugMode()); michael@0: michael@0: if (WorkAroundDriverBugs() && michael@0: Vendor() == GLVendor::Qualcomm) { michael@0: michael@0: // Some Adreno drivers do not report GL_OES_EGL_sync, but they really do support it. michael@0: MarkExtensionSupported(OES_EGL_sync); michael@0: } michael@0: michael@0: if (WorkAroundDriverBugs() && michael@0: Renderer() == GLRenderer::AndroidEmulator) { michael@0: // the Android emulator, which we use to run B2G reftests on, michael@0: // doesn't expose the OES_rgb8_rgba8 extension, but it seems to michael@0: // support it (tautologically, as it only runs on desktop GL). michael@0: MarkExtensionSupported(OES_rgb8_rgba8); michael@0: } michael@0: michael@0: if (WorkAroundDriverBugs() && michael@0: Vendor() == GLVendor::VMware && michael@0: Renderer() == GLRenderer::GalliumLlvmpipe) michael@0: { michael@0: // The llvmpipe driver that is used on linux try servers appears to have michael@0: // buggy support for s3tc/dxt1 compressed textures. michael@0: // See Bug 975824. michael@0: MarkExtensionUnsupported(EXT_texture_compression_s3tc); michael@0: MarkExtensionUnsupported(EXT_texture_compression_dxt1); michael@0: MarkExtensionUnsupported(ANGLE_texture_compression_dxt3); michael@0: MarkExtensionUnsupported(ANGLE_texture_compression_dxt5); michael@0: } michael@0: michael@0: #ifdef DEBUG michael@0: firstRun = false; michael@0: #endif michael@0: } michael@0: michael@0: void michael@0: GLContext::PlatformStartup() michael@0: { michael@0: RegisterStrongMemoryReporter(new GfxTexturesReporter()); michael@0: } michael@0: michael@0: // Common code for checking for both GL extensions and GLX extensions. michael@0: bool michael@0: GLContext::ListHasExtension(const GLubyte *extensions, const char *extension) michael@0: { michael@0: // fix bug 612572 - we were crashing as we were calling this function with extensions==null michael@0: if (extensions == nullptr || extension == nullptr) michael@0: return false; michael@0: michael@0: const GLubyte *start; michael@0: GLubyte *where, *terminator; michael@0: michael@0: /* Extension names should not have spaces. */ michael@0: where = (GLubyte *) strchr(extension, ' '); michael@0: if (where || *extension == '\0') michael@0: return false; michael@0: michael@0: /* michael@0: * It takes a bit of care to be fool-proof about parsing the michael@0: * OpenGL extensions string. Don't be fooled by sub-strings, michael@0: * etc. michael@0: */ michael@0: start = extensions; michael@0: for (;;) { michael@0: where = (GLubyte *) strstr((const char *) start, extension); michael@0: if (!where) { michael@0: break; michael@0: } michael@0: terminator = where + strlen(extension); michael@0: if (where == start || *(where - 1) == ' ') { michael@0: if (*terminator == ' ' || *terminator == '\0') { michael@0: return true; michael@0: } michael@0: } michael@0: start = terminator; michael@0: } michael@0: return false; michael@0: } michael@0: michael@0: void michael@0: GLContext::DetermineCaps() michael@0: { michael@0: PixelBufferFormat format = QueryPixelFormat(); michael@0: michael@0: SurfaceCaps caps; michael@0: caps.color = !!format.red && !!format.green && !!format.blue; michael@0: caps.bpp16 = caps.color && format.ColorBits() == 16; michael@0: caps.alpha = !!format.alpha; michael@0: caps.depth = !!format.depth; michael@0: caps.stencil = !!format.stencil; michael@0: caps.antialias = format.samples > 1; michael@0: caps.preserve = true; michael@0: michael@0: mCaps = caps; michael@0: } michael@0: michael@0: PixelBufferFormat michael@0: GLContext::QueryPixelFormat() michael@0: { michael@0: PixelBufferFormat format; michael@0: michael@0: ScopedBindFramebuffer autoFB(this, 0); michael@0: michael@0: fGetIntegerv(LOCAL_GL_RED_BITS , &format.red ); michael@0: fGetIntegerv(LOCAL_GL_GREEN_BITS, &format.green); michael@0: fGetIntegerv(LOCAL_GL_BLUE_BITS , &format.blue ); michael@0: fGetIntegerv(LOCAL_GL_ALPHA_BITS, &format.alpha); michael@0: michael@0: fGetIntegerv(LOCAL_GL_DEPTH_BITS, &format.depth); michael@0: fGetIntegerv(LOCAL_GL_STENCIL_BITS, &format.stencil); michael@0: michael@0: fGetIntegerv(LOCAL_GL_SAMPLES, &format.samples); michael@0: michael@0: return format; michael@0: } michael@0: michael@0: void michael@0: GLContext::UpdatePixelFormat() michael@0: { michael@0: PixelBufferFormat format = QueryPixelFormat(); michael@0: #ifdef DEBUG michael@0: const SurfaceCaps& caps = Caps(); michael@0: MOZ_ASSERT(!caps.any, "Did you forget to DetermineCaps()?"); michael@0: michael@0: MOZ_ASSERT(caps.color == !!format.red); michael@0: MOZ_ASSERT(caps.color == !!format.green); michael@0: MOZ_ASSERT(caps.color == !!format.blue); michael@0: michael@0: MOZ_ASSERT(caps.alpha == !!format.alpha); michael@0: michael@0: // These we either must have if they're requested, or michael@0: // we can have if they're not. michael@0: MOZ_ASSERT(caps.depth == !!format.depth || !caps.depth); michael@0: MOZ_ASSERT(caps.stencil == !!format.stencil || !caps.stencil); michael@0: michael@0: MOZ_ASSERT(caps.antialias == (format.samples > 1)); michael@0: #endif michael@0: mPixelFormat = new PixelBufferFormat(format); michael@0: } michael@0: michael@0: GLFormats michael@0: GLContext::ChooseGLFormats(const SurfaceCaps& caps) const michael@0: { michael@0: GLFormats formats; michael@0: michael@0: // If we're on ES2 hardware and we have an explicit request for 16 bits of color or less michael@0: // OR we don't support full 8-bit color, return a 4444 or 565 format. michael@0: bool bpp16 = caps.bpp16; michael@0: if (IsGLES()) { michael@0: if (!IsExtensionSupported(OES_rgb8_rgba8)) michael@0: bpp16 = true; michael@0: } else { michael@0: // RGB565 is uncommon on desktop, requiring ARB_ES2_compatibility. michael@0: // Since it's also vanishingly useless there, let's not support it. michael@0: bpp16 = false; michael@0: } michael@0: michael@0: if (bpp16) { michael@0: MOZ_ASSERT(IsGLES()); michael@0: if (caps.alpha) { michael@0: formats.color_texInternalFormat = LOCAL_GL_RGBA; michael@0: formats.color_texFormat = LOCAL_GL_RGBA; michael@0: formats.color_texType = LOCAL_GL_UNSIGNED_SHORT_4_4_4_4; michael@0: formats.color_rbFormat = LOCAL_GL_RGBA4; michael@0: } else { michael@0: formats.color_texInternalFormat = LOCAL_GL_RGB; michael@0: formats.color_texFormat = LOCAL_GL_RGB; michael@0: formats.color_texType = LOCAL_GL_UNSIGNED_SHORT_5_6_5; michael@0: formats.color_rbFormat = LOCAL_GL_RGB565; michael@0: } michael@0: } else { michael@0: formats.color_texType = LOCAL_GL_UNSIGNED_BYTE; michael@0: michael@0: if (caps.alpha) { michael@0: formats.color_texInternalFormat = IsGLES() ? LOCAL_GL_RGBA : LOCAL_GL_RGBA8; michael@0: formats.color_texFormat = LOCAL_GL_RGBA; michael@0: formats.color_rbFormat = LOCAL_GL_RGBA8; michael@0: } else { michael@0: formats.color_texInternalFormat = IsGLES() ? LOCAL_GL_RGB : LOCAL_GL_RGB8; michael@0: formats.color_texFormat = LOCAL_GL_RGB; michael@0: formats.color_rbFormat = LOCAL_GL_RGB8; michael@0: } michael@0: } michael@0: michael@0: uint32_t msaaLevel = gfxPrefs::MSAALevel(); michael@0: GLsizei samples = msaaLevel * msaaLevel; michael@0: samples = std::min(samples, mMaxSamples); michael@0: michael@0: // Bug 778765. michael@0: if (WorkAroundDriverBugs() && samples == 1) { michael@0: samples = 0; michael@0: } michael@0: formats.samples = samples; michael@0: michael@0: michael@0: // Be clear that these are 0 if unavailable. michael@0: formats.depthStencil = 0; michael@0: if (!IsGLES() || IsExtensionSupported(OES_packed_depth_stencil)) { michael@0: formats.depthStencil = LOCAL_GL_DEPTH24_STENCIL8; michael@0: } michael@0: michael@0: formats.depth = 0; michael@0: if (IsGLES()) { michael@0: if (IsExtensionSupported(OES_depth24)) { michael@0: formats.depth = LOCAL_GL_DEPTH_COMPONENT24; michael@0: } else { michael@0: formats.depth = LOCAL_GL_DEPTH_COMPONENT16; michael@0: } michael@0: } else { michael@0: formats.depth = LOCAL_GL_DEPTH_COMPONENT24; michael@0: } michael@0: michael@0: formats.stencil = LOCAL_GL_STENCIL_INDEX8; michael@0: michael@0: return formats; michael@0: } michael@0: michael@0: bool michael@0: GLContext::IsFramebufferComplete(GLuint fb, GLenum* pStatus) michael@0: { michael@0: MOZ_ASSERT(fb); michael@0: michael@0: ScopedBindFramebuffer autoFB(this, fb); michael@0: MOZ_ASSERT(fIsFramebuffer(fb)); michael@0: michael@0: GLenum status = fCheckFramebufferStatus(LOCAL_GL_FRAMEBUFFER); michael@0: if (pStatus) michael@0: *pStatus = status; michael@0: michael@0: return status == LOCAL_GL_FRAMEBUFFER_COMPLETE; michael@0: } michael@0: michael@0: void michael@0: GLContext::AttachBuffersToFB(GLuint colorTex, GLuint colorRB, michael@0: GLuint depthRB, GLuint stencilRB, michael@0: GLuint fb, GLenum target) michael@0: { michael@0: MOZ_ASSERT(fb); michael@0: MOZ_ASSERT( !(colorTex && colorRB) ); michael@0: michael@0: ScopedBindFramebuffer autoFB(this, fb); michael@0: MOZ_ASSERT(fIsFramebuffer(fb)); // It only counts after being bound. michael@0: michael@0: if (colorTex) { michael@0: MOZ_ASSERT(fIsTexture(colorTex)); michael@0: MOZ_ASSERT(target == LOCAL_GL_TEXTURE_2D || michael@0: target == LOCAL_GL_TEXTURE_RECTANGLE_ARB); michael@0: fFramebufferTexture2D(LOCAL_GL_FRAMEBUFFER, michael@0: LOCAL_GL_COLOR_ATTACHMENT0, michael@0: target, michael@0: colorTex, michael@0: 0); michael@0: } else if (colorRB) { michael@0: MOZ_ASSERT(fIsRenderbuffer(colorRB)); michael@0: fFramebufferRenderbuffer(LOCAL_GL_FRAMEBUFFER, michael@0: LOCAL_GL_COLOR_ATTACHMENT0, michael@0: LOCAL_GL_RENDERBUFFER, michael@0: colorRB); michael@0: } michael@0: michael@0: if (depthRB) { michael@0: MOZ_ASSERT(fIsRenderbuffer(depthRB)); michael@0: fFramebufferRenderbuffer(LOCAL_GL_FRAMEBUFFER, michael@0: LOCAL_GL_DEPTH_ATTACHMENT, michael@0: LOCAL_GL_RENDERBUFFER, michael@0: depthRB); michael@0: } michael@0: michael@0: if (stencilRB) { michael@0: MOZ_ASSERT(fIsRenderbuffer(stencilRB)); michael@0: fFramebufferRenderbuffer(LOCAL_GL_FRAMEBUFFER, michael@0: LOCAL_GL_STENCIL_ATTACHMENT, michael@0: LOCAL_GL_RENDERBUFFER, michael@0: stencilRB); michael@0: } michael@0: } michael@0: michael@0: bool michael@0: GLContext::AssembleOffscreenFBs(const GLuint colorMSRB, michael@0: const GLuint depthRB, michael@0: const GLuint stencilRB, michael@0: const GLuint texture, michael@0: GLuint* drawFB_out, michael@0: GLuint* readFB_out) michael@0: { michael@0: if (!colorMSRB && !texture) { michael@0: MOZ_ASSERT(!depthRB && !stencilRB); michael@0: michael@0: if (drawFB_out) michael@0: *drawFB_out = 0; michael@0: if (readFB_out) michael@0: *readFB_out = 0; michael@0: michael@0: return true; michael@0: } michael@0: michael@0: ScopedBindFramebuffer autoFB(this); michael@0: michael@0: GLuint drawFB = 0; michael@0: GLuint readFB = 0; michael@0: michael@0: if (texture) { michael@0: readFB = 0; michael@0: fGenFramebuffers(1, &readFB); michael@0: BindFB(readFB); michael@0: fFramebufferTexture2D(LOCAL_GL_FRAMEBUFFER, michael@0: LOCAL_GL_COLOR_ATTACHMENT0, michael@0: LOCAL_GL_TEXTURE_2D, michael@0: texture, michael@0: 0); michael@0: } michael@0: michael@0: if (colorMSRB) { michael@0: drawFB = 0; michael@0: fGenFramebuffers(1, &drawFB); michael@0: BindFB(drawFB); michael@0: fFramebufferRenderbuffer(LOCAL_GL_FRAMEBUFFER, michael@0: LOCAL_GL_COLOR_ATTACHMENT0, michael@0: LOCAL_GL_RENDERBUFFER, michael@0: colorMSRB); michael@0: } else { michael@0: drawFB = readFB; michael@0: } michael@0: MOZ_ASSERT(GetFB() == drawFB); michael@0: michael@0: if (depthRB) { michael@0: fFramebufferRenderbuffer(LOCAL_GL_FRAMEBUFFER, michael@0: LOCAL_GL_DEPTH_ATTACHMENT, michael@0: LOCAL_GL_RENDERBUFFER, michael@0: depthRB); michael@0: } michael@0: michael@0: if (stencilRB) { michael@0: fFramebufferRenderbuffer(LOCAL_GL_FRAMEBUFFER, michael@0: LOCAL_GL_STENCIL_ATTACHMENT, michael@0: LOCAL_GL_RENDERBUFFER, michael@0: stencilRB); michael@0: } michael@0: michael@0: // We should be all resized. Check for framebuffer completeness. michael@0: GLenum status; michael@0: bool isComplete = true; michael@0: michael@0: if (!IsFramebufferComplete(drawFB, &status)) { michael@0: NS_WARNING("DrawFBO: Incomplete"); michael@0: #ifdef DEBUG michael@0: if (DebugMode()) { michael@0: printf_stderr("Framebuffer status: %X\n", status); michael@0: } michael@0: #endif michael@0: isComplete = false; michael@0: } michael@0: michael@0: if (!IsFramebufferComplete(readFB, &status)) { michael@0: NS_WARNING("ReadFBO: Incomplete"); michael@0: #ifdef DEBUG michael@0: if (DebugMode()) { michael@0: printf_stderr("Framebuffer status: %X\n", status); michael@0: } michael@0: #endif michael@0: isComplete = false; michael@0: } michael@0: michael@0: if (drawFB_out) { michael@0: *drawFB_out = drawFB; michael@0: } else if (drawFB) { michael@0: NS_RUNTIMEABORT("drawFB created when not requested!"); michael@0: } michael@0: michael@0: if (readFB_out) { michael@0: *readFB_out = readFB; michael@0: } else if (readFB) { michael@0: NS_RUNTIMEABORT("readFB created when not requested!"); michael@0: } michael@0: michael@0: return isComplete; michael@0: } michael@0: michael@0: michael@0: michael@0: bool michael@0: GLContext::PublishFrame() michael@0: { michael@0: MOZ_ASSERT(mScreen); michael@0: michael@0: if (!mScreen->PublishFrame(OffscreenSize())) michael@0: return false; michael@0: michael@0: return true; michael@0: } michael@0: michael@0: SharedSurface_GL* michael@0: GLContext::RequestFrame() michael@0: { michael@0: MOZ_ASSERT(mScreen); michael@0: michael@0: SharedSurface* ret = mScreen->Stream()->SwapConsumer(); michael@0: if (!ret) michael@0: return nullptr; michael@0: michael@0: return SharedSurface_GL::Cast(ret); michael@0: } michael@0: michael@0: michael@0: michael@0: void michael@0: GLContext::ClearSafely() michael@0: { michael@0: // bug 659349 --- we must be very careful here: clearing a GL framebuffer is nontrivial, relies on a lot of state, michael@0: // and in the case of the backbuffer of a WebGL context, state is exposed to scripts. michael@0: // michael@0: // The code here is taken from WebGLContext::ForceClearFramebufferWithDefaultValues, but I didn't find a good way of michael@0: // sharing code with it. WebGL's code is somewhat performance-critical as it is typically called on every frame, so michael@0: // WebGL keeps track of GL state to avoid having to query it everytime, and also tries to only do work for actually michael@0: // present buffers (e.g. stencil buffer). Doing that here seems like premature optimization, michael@0: // as ClearSafely() is called only when e.g. a canvas is resized, not on every animation frame. michael@0: michael@0: realGLboolean scissorTestEnabled; michael@0: realGLboolean ditherEnabled; michael@0: realGLboolean colorWriteMask[4]; michael@0: realGLboolean depthWriteMask; michael@0: GLint stencilWriteMaskFront, stencilWriteMaskBack; michael@0: GLfloat colorClearValue[4]; michael@0: GLfloat depthClearValue; michael@0: GLint stencilClearValue; michael@0: michael@0: // save current GL state michael@0: fGetBooleanv(LOCAL_GL_SCISSOR_TEST, &scissorTestEnabled); michael@0: fGetBooleanv(LOCAL_GL_DITHER, &ditherEnabled); michael@0: fGetBooleanv(LOCAL_GL_COLOR_WRITEMASK, colorWriteMask); michael@0: fGetBooleanv(LOCAL_GL_DEPTH_WRITEMASK, &depthWriteMask); michael@0: fGetIntegerv(LOCAL_GL_STENCIL_WRITEMASK, &stencilWriteMaskFront); michael@0: fGetIntegerv(LOCAL_GL_STENCIL_BACK_WRITEMASK, &stencilWriteMaskBack); michael@0: fGetFloatv(LOCAL_GL_COLOR_CLEAR_VALUE, colorClearValue); michael@0: fGetFloatv(LOCAL_GL_DEPTH_CLEAR_VALUE, &depthClearValue); michael@0: fGetIntegerv(LOCAL_GL_STENCIL_CLEAR_VALUE, &stencilClearValue); michael@0: michael@0: // prepare GL state for clearing michael@0: fDisable(LOCAL_GL_SCISSOR_TEST); michael@0: fDisable(LOCAL_GL_DITHER); michael@0: michael@0: fColorMask(1, 1, 1, 1); michael@0: fClearColor(0.f, 0.f, 0.f, 0.f); michael@0: michael@0: fDepthMask(1); michael@0: fClearDepth(1.0f); michael@0: michael@0: fStencilMask(0xffffffff); michael@0: fClearStencil(0); michael@0: michael@0: // do clear michael@0: fClear(LOCAL_GL_COLOR_BUFFER_BIT | michael@0: LOCAL_GL_DEPTH_BUFFER_BIT | michael@0: LOCAL_GL_STENCIL_BUFFER_BIT); michael@0: michael@0: // restore GL state after clearing michael@0: fColorMask(colorWriteMask[0], michael@0: colorWriteMask[1], michael@0: colorWriteMask[2], michael@0: colorWriteMask[3]); michael@0: fClearColor(colorClearValue[0], michael@0: colorClearValue[1], michael@0: colorClearValue[2], michael@0: colorClearValue[3]); michael@0: michael@0: fDepthMask(depthWriteMask); michael@0: fClearDepth(depthClearValue); michael@0: michael@0: fStencilMaskSeparate(LOCAL_GL_FRONT, stencilWriteMaskFront); michael@0: fStencilMaskSeparate(LOCAL_GL_BACK, stencilWriteMaskBack); michael@0: fClearStencil(stencilClearValue); michael@0: michael@0: if (ditherEnabled) michael@0: fEnable(LOCAL_GL_DITHER); michael@0: else michael@0: fDisable(LOCAL_GL_DITHER); michael@0: michael@0: if (scissorTestEnabled) michael@0: fEnable(LOCAL_GL_SCISSOR_TEST); michael@0: else michael@0: fDisable(LOCAL_GL_SCISSOR_TEST); michael@0: michael@0: } michael@0: michael@0: void michael@0: GLContext::MarkDestroyed() michael@0: { michael@0: if (IsDestroyed()) michael@0: return; michael@0: michael@0: if (MakeCurrent()) { michael@0: DestroyScreenBuffer(); michael@0: michael@0: mBlitHelper = nullptr; michael@0: mBlitTextureImageHelper = nullptr; michael@0: mReadTexImageHelper = nullptr; michael@0: michael@0: mTexGarbageBin->GLContextTeardown(); michael@0: } else { michael@0: NS_WARNING("MakeCurrent() failed during MarkDestroyed! Skipping GL object teardown."); michael@0: } michael@0: michael@0: mSymbols.Zero(); michael@0: } michael@0: michael@0: #ifdef MOZ_ENABLE_GL_TRACKING michael@0: void michael@0: GLContext::CreatedProgram(GLContext *aOrigin, GLuint aName) michael@0: { michael@0: mTrackedPrograms.AppendElement(NamedResource(aOrigin, aName)); michael@0: } michael@0: michael@0: void michael@0: GLContext::CreatedShader(GLContext *aOrigin, GLuint aName) michael@0: { michael@0: mTrackedShaders.AppendElement(NamedResource(aOrigin, aName)); michael@0: } michael@0: michael@0: void michael@0: GLContext::CreatedBuffers(GLContext *aOrigin, GLsizei aCount, GLuint *aNames) michael@0: { michael@0: for (GLsizei i = 0; i < aCount; ++i) { michael@0: mTrackedBuffers.AppendElement(NamedResource(aOrigin, aNames[i])); michael@0: } michael@0: } michael@0: michael@0: void michael@0: GLContext::CreatedQueries(GLContext *aOrigin, GLsizei aCount, GLuint *aNames) michael@0: { michael@0: for (GLsizei i = 0; i < aCount; ++i) { michael@0: mTrackedQueries.AppendElement(NamedResource(aOrigin, aNames[i])); michael@0: } michael@0: } michael@0: michael@0: void michael@0: GLContext::CreatedTextures(GLContext *aOrigin, GLsizei aCount, GLuint *aNames) michael@0: { michael@0: for (GLsizei i = 0; i < aCount; ++i) { michael@0: mTrackedTextures.AppendElement(NamedResource(aOrigin, aNames[i])); michael@0: } michael@0: } michael@0: michael@0: void michael@0: GLContext::CreatedFramebuffers(GLContext *aOrigin, GLsizei aCount, GLuint *aNames) michael@0: { michael@0: for (GLsizei i = 0; i < aCount; ++i) { michael@0: mTrackedFramebuffers.AppendElement(NamedResource(aOrigin, aNames[i])); michael@0: } michael@0: } michael@0: michael@0: void michael@0: GLContext::CreatedRenderbuffers(GLContext *aOrigin, GLsizei aCount, GLuint *aNames) michael@0: { michael@0: for (GLsizei i = 0; i < aCount; ++i) { michael@0: mTrackedRenderbuffers.AppendElement(NamedResource(aOrigin, aNames[i])); michael@0: } michael@0: } michael@0: michael@0: static void michael@0: RemoveNamesFromArray(GLContext *aOrigin, GLsizei aCount, const GLuint *aNames, nsTArray& aArray) michael@0: { michael@0: for (GLsizei j = 0; j < aCount; ++j) { michael@0: GLuint name = aNames[j]; michael@0: // name 0 can be ignored michael@0: if (name == 0) michael@0: continue; michael@0: michael@0: for (uint32_t i = 0; i < aArray.Length(); ++i) { michael@0: if (aArray[i].name == name) { michael@0: aArray.RemoveElementAt(i); michael@0: break; michael@0: } michael@0: } michael@0: } michael@0: } michael@0: michael@0: void michael@0: GLContext::DeletedProgram(GLContext *aOrigin, GLuint aName) michael@0: { michael@0: RemoveNamesFromArray(aOrigin, 1, &aName, mTrackedPrograms); michael@0: } michael@0: michael@0: void michael@0: GLContext::DeletedShader(GLContext *aOrigin, GLuint aName) michael@0: { michael@0: RemoveNamesFromArray(aOrigin, 1, &aName, mTrackedShaders); michael@0: } michael@0: michael@0: void michael@0: GLContext::DeletedBuffers(GLContext *aOrigin, GLsizei aCount, const GLuint *aNames) michael@0: { michael@0: RemoveNamesFromArray(aOrigin, aCount, aNames, mTrackedBuffers); michael@0: } michael@0: michael@0: void michael@0: GLContext::DeletedQueries(GLContext *aOrigin, GLsizei aCount, const GLuint *aNames) michael@0: { michael@0: RemoveNamesFromArray(aOrigin, aCount, aNames, mTrackedQueries); michael@0: } michael@0: michael@0: void michael@0: GLContext::DeletedTextures(GLContext *aOrigin, GLsizei aCount, const GLuint *aNames) michael@0: { michael@0: RemoveNamesFromArray(aOrigin, aCount, aNames, mTrackedTextures); michael@0: } michael@0: michael@0: void michael@0: GLContext::DeletedFramebuffers(GLContext *aOrigin, GLsizei aCount, const GLuint *aNames) michael@0: { michael@0: RemoveNamesFromArray(aOrigin, aCount, aNames, mTrackedFramebuffers); michael@0: } michael@0: michael@0: void michael@0: GLContext::DeletedRenderbuffers(GLContext *aOrigin, GLsizei aCount, const GLuint *aNames) michael@0: { michael@0: RemoveNamesFromArray(aOrigin, aCount, aNames, mTrackedRenderbuffers); michael@0: } michael@0: michael@0: static void michael@0: MarkContextDestroyedInArray(GLContext *aContext, nsTArray& aArray) michael@0: { michael@0: for (uint32_t i = 0; i < aArray.Length(); ++i) { michael@0: if (aArray[i].origin == aContext) michael@0: aArray[i].originDeleted = true; michael@0: } michael@0: } michael@0: michael@0: void michael@0: GLContext::SharedContextDestroyed(GLContext *aChild) michael@0: { michael@0: MarkContextDestroyedInArray(aChild, mTrackedPrograms); michael@0: MarkContextDestroyedInArray(aChild, mTrackedShaders); michael@0: MarkContextDestroyedInArray(aChild, mTrackedTextures); michael@0: MarkContextDestroyedInArray(aChild, mTrackedFramebuffers); michael@0: MarkContextDestroyedInArray(aChild, mTrackedRenderbuffers); michael@0: MarkContextDestroyedInArray(aChild, mTrackedBuffers); michael@0: MarkContextDestroyedInArray(aChild, mTrackedQueries); michael@0: } michael@0: michael@0: static void michael@0: ReportArrayContents(const char *title, const nsTArray& aArray) michael@0: { michael@0: if (aArray.Length() == 0) michael@0: return; michael@0: michael@0: printf_stderr("%s:\n", title); michael@0: michael@0: nsTArray copy(aArray); michael@0: copy.Sort(); michael@0: michael@0: GLContext *lastContext = nullptr; michael@0: for (uint32_t i = 0; i < copy.Length(); ++i) { michael@0: if (lastContext != copy[i].origin) { michael@0: if (lastContext) michael@0: printf_stderr("\n"); michael@0: printf_stderr(" [%p - %s] ", copy[i].origin, copy[i].originDeleted ? "deleted" : "live"); michael@0: lastContext = copy[i].origin; michael@0: } michael@0: printf_stderr("%d ", copy[i].name); michael@0: } michael@0: printf_stderr("\n"); michael@0: } michael@0: michael@0: void michael@0: GLContext::ReportOutstandingNames() michael@0: { michael@0: if (!DebugMode()) michael@0: return; michael@0: michael@0: printf_stderr("== GLContext %p Outstanding ==\n", this); michael@0: michael@0: ReportArrayContents("Outstanding Textures", mTrackedTextures); michael@0: ReportArrayContents("Outstanding Buffers", mTrackedBuffers); michael@0: ReportArrayContents("Outstanding Queries", mTrackedQueries); michael@0: ReportArrayContents("Outstanding Programs", mTrackedPrograms); michael@0: ReportArrayContents("Outstanding Shaders", mTrackedShaders); michael@0: ReportArrayContents("Outstanding Framebuffers", mTrackedFramebuffers); michael@0: ReportArrayContents("Outstanding Renderbuffers", mTrackedRenderbuffers); michael@0: } michael@0: michael@0: #endif /* DEBUG */ michael@0: michael@0: michael@0: void michael@0: GLContext::GuaranteeResolve() michael@0: { michael@0: if (mScreen) { michael@0: mScreen->AssureBlitted(); michael@0: } michael@0: fFinish(); michael@0: } michael@0: michael@0: const gfx::IntSize& michael@0: GLContext::OffscreenSize() const michael@0: { michael@0: MOZ_ASSERT(IsOffscreen()); michael@0: return mScreen->Size(); michael@0: } michael@0: michael@0: bool michael@0: GLContext::CreateScreenBufferImpl(const IntSize& size, const SurfaceCaps& caps) michael@0: { michael@0: GLScreenBuffer* newScreen = GLScreenBuffer::Create(this, size, caps); michael@0: if (!newScreen) michael@0: return false; michael@0: michael@0: if (!newScreen->Resize(size)) { michael@0: delete newScreen; michael@0: return false; michael@0: } michael@0: michael@0: DestroyScreenBuffer(); michael@0: michael@0: // This will rebind to 0 (Screen) if needed when michael@0: // it falls out of scope. michael@0: ScopedBindFramebuffer autoFB(this); michael@0: michael@0: mScreen = newScreen; michael@0: michael@0: return true; michael@0: } michael@0: michael@0: bool michael@0: GLContext::ResizeScreenBuffer(const IntSize& size) michael@0: { michael@0: if (!IsOffscreenSizeAllowed(size)) michael@0: return false; michael@0: michael@0: return mScreen->Resize(size); michael@0: } michael@0: michael@0: michael@0: void michael@0: GLContext::DestroyScreenBuffer() michael@0: { michael@0: delete mScreen; michael@0: mScreen = nullptr; michael@0: } michael@0: michael@0: void michael@0: GLContext::ForceDirtyScreen() michael@0: { michael@0: ScopedBindFramebuffer autoFB(0); michael@0: michael@0: BeforeGLDrawCall(); michael@0: // no-op; just pretend we did something michael@0: AfterGLDrawCall(); michael@0: } michael@0: michael@0: void michael@0: GLContext::CleanDirtyScreen() michael@0: { michael@0: ScopedBindFramebuffer autoFB(0); michael@0: michael@0: BeforeGLReadCall(); michael@0: // no-op; we just want to make sure the Read FBO is updated if it needs to be michael@0: AfterGLReadCall(); michael@0: } michael@0: michael@0: void michael@0: GLContext::EmptyTexGarbageBin() michael@0: { michael@0: TexGarbageBin()->EmptyGarbage(); michael@0: } michael@0: michael@0: bool michael@0: GLContext::IsOffscreenSizeAllowed(const IntSize& aSize) const { michael@0: int32_t biggerDimension = std::max(aSize.width, aSize.height); michael@0: int32_t maxAllowed = std::min(mMaxRenderbufferSize, mMaxTextureSize); michael@0: return biggerDimension <= maxAllowed; michael@0: } michael@0: michael@0: bool michael@0: GLContext::IsOwningThreadCurrent() michael@0: { michael@0: return NS_GetCurrentThread() == mOwningThread; michael@0: } michael@0: michael@0: void michael@0: GLContext::DispatchToOwningThread(nsIRunnable *event) michael@0: { michael@0: // Before dispatching, we need to ensure we're not in the middle of michael@0: // shutting down. Dispatching runnables in the middle of shutdown michael@0: // (that is, when the main thread is no longer get-able) can cause them michael@0: // to leak. See Bug 741319, and Bug 744115. michael@0: nsCOMPtr mainThread; michael@0: if (NS_SUCCEEDED(NS_GetMainThread(getter_AddRefs(mainThread)))) { michael@0: mOwningThread->Dispatch(event, NS_DISPATCH_NORMAL); michael@0: } michael@0: } michael@0: michael@0: GLBlitHelper* michael@0: GLContext::BlitHelper() michael@0: { michael@0: if (!mBlitHelper) { michael@0: mBlitHelper = new GLBlitHelper(this); michael@0: } michael@0: michael@0: return mBlitHelper; michael@0: } michael@0: michael@0: GLBlitTextureImageHelper* michael@0: GLContext::BlitTextureImageHelper() michael@0: { michael@0: if (!mBlitTextureImageHelper) { michael@0: mBlitTextureImageHelper = new GLBlitTextureImageHelper(this); michael@0: } michael@0: michael@0: return mBlitTextureImageHelper; michael@0: } michael@0: michael@0: GLReadTexImageHelper* michael@0: GLContext::ReadTexImageHelper() michael@0: { michael@0: if (!mReadTexImageHelper) { michael@0: mReadTexImageHelper = new GLReadTexImageHelper(this); michael@0: } michael@0: michael@0: return mReadTexImageHelper; michael@0: } michael@0: michael@0: bool michael@0: DoesStringMatch(const char* aString, const char *aWantedString) michael@0: { michael@0: if (!aString || !aWantedString) michael@0: return false; michael@0: michael@0: const char *occurrence = strstr(aString, aWantedString); michael@0: michael@0: // aWanted not found michael@0: if (!occurrence) michael@0: return false; michael@0: michael@0: // aWantedString preceded by alpha character michael@0: if (occurrence != aString && isalpha(*(occurrence-1))) michael@0: return false; michael@0: michael@0: // aWantedVendor followed by alpha character michael@0: const char *afterOccurrence = occurrence + strlen(aWantedString); michael@0: if (isalpha(*afterOccurrence)) michael@0: return false; michael@0: michael@0: return true; michael@0: } michael@0: michael@0: } /* namespace gl */ michael@0: } /* namespace mozilla */