bool WGLLibrary::EnsureInitialized(bool aUseMesaLlvmPipe) { if (mInitialized) return true; mozilla::ScopedGfxFeatureReporter reporter("WGL", aUseMesaLlvmPipe); const char* libGLFilename = aUseMesaLlvmPipe ? "mesallvmpipe.dll" : "Opengl32.dll"; if (!mOGLLibrary) { mOGLLibrary = PR_LoadLibrary(libGLFilename); if (!mOGLLibrary) { NS_WARNING("Couldn't load OpenGL library."); return false; } } mUseDoubleBufferedWindows = PR_GetEnv("MOZ_WGL_DB") != nullptr; GLLibraryLoader::SymLoadStruct earlySymbols[] = { { (PRFuncPtr*) &fCreateContext, { "wglCreateContext", NULL } }, { (PRFuncPtr*) &fMakeCurrent, { "wglMakeCurrent", NULL } }, { (PRFuncPtr*) &fGetProcAddress, { "wglGetProcAddress", NULL } }, { (PRFuncPtr*) &fDeleteContext, { "wglDeleteContext", NULL } }, { (PRFuncPtr*) &fGetCurrentContext, { "wglGetCurrentContext", NULL } }, { (PRFuncPtr*) &fGetCurrentDC, { "wglGetCurrentDC", NULL } }, { (PRFuncPtr*) &fShareLists, { "wglShareLists", NULL } }, { NULL, { NULL } } }; if (!GLLibraryLoader::LoadSymbols(mOGLLibrary, &earlySymbols[0])) { NS_WARNING("Couldn't find required entry points in OpenGL DLL (early init)"); return false; } // This is ridiculous -- we have to actually create a context to // get the OpenGL ICD to load. mWindow = CreateDummyWindow(&mWindowDC); NS_ENSURE_TRUE(mWindow, false); // create rendering context mWindowGLContext = fCreateContext(mWindowDC); NS_ENSURE_TRUE(mWindowGLContext, false); HGLRC curCtx = fGetCurrentContext(); HDC curDC = fGetCurrentDC(); if (!fMakeCurrent((HDC)mWindowDC, (HGLRC)mWindowGLContext)) { NS_WARNING("wglMakeCurrent failed"); return false; } // Now we can grab all the other symbols that we couldn't without having // a context current. GLLibraryLoader::SymLoadStruct pbufferSymbols[] = { { (PRFuncPtr*) &fCreatePbuffer, { "wglCreatePbufferARB", "wglCreatePbufferEXT", NULL } }, { (PRFuncPtr*) &fDestroyPbuffer, { "wglDestroyPbufferARB", "wglDestroyPbufferEXT", NULL } }, { (PRFuncPtr*) &fGetPbufferDC, { "wglGetPbufferDCARB", "wglGetPbufferDCEXT", NULL } }, { (PRFuncPtr*) &fBindTexImage, { "wglBindTexImageARB", "wglBindTexImageEXT", NULL } }, { (PRFuncPtr*) &fReleaseTexImage, { "wglReleaseTexImageARB", "wglReleaseTexImageEXT", NULL } }, { NULL, { NULL } } }; GLLibraryLoader::SymLoadStruct pixFmtSymbols[] = { { (PRFuncPtr*) &fChoosePixelFormat, { "wglChoosePixelFormatARB", "wglChoosePixelFormatEXT", NULL } }, { (PRFuncPtr*) &fGetPixelFormatAttribiv, { "wglGetPixelFormatAttribivARB", "wglGetPixelFormatAttribivEXT", NULL } }, { NULL, { NULL } } }; if (!GLLibraryLoader::LoadSymbols(mOGLLibrary, &pbufferSymbols[0], (GLLibraryLoader::PlatformLookupFunction)fGetProcAddress)) { // this isn't an error, just means that pbuffers aren't supported fCreatePbuffer = nullptr; } if (!GLLibraryLoader::LoadSymbols(mOGLLibrary, &pixFmtSymbols[0], (GLLibraryLoader::PlatformLookupFunction)fGetProcAddress)) { // this isn't an error, just means that we don't have the pixel format extension fChoosePixelFormat = nullptr; } GLLibraryLoader::SymLoadStruct extensionsSymbols[] = { { (PRFuncPtr *) &fGetExtensionsString, { "wglGetExtensionsStringARB", NULL} }, { NULL, { NULL } } }; GLLibraryLoader::SymLoadStruct robustnessSymbols[] = { { (PRFuncPtr *) &fCreateContextAttribs, { "wglCreateContextAttribsARB", NULL} }, { NULL, { NULL } } }; if (GLLibraryLoader::LoadSymbols(mOGLLibrary, &extensionsSymbols[0], (GLLibraryLoader::PlatformLookupFunction)fGetProcAddress)) { const char *wglExts = fGetExtensionsString(mWindowDC); if (wglExts && HasExtension(wglExts, "WGL_ARB_create_context")) { GLLibraryLoader::LoadSymbols(mOGLLibrary, &robustnessSymbols[0], (GLLibraryLoader::PlatformLookupFunction)fGetProcAddress); if (HasExtension(wglExts, "WGL_ARB_create_context_robustness")) { mHasRobustness = true; } } } // reset back to the previous context, just in case fMakeCurrent(curDC, curCtx); if (mHasRobustness) { fDeleteContext(mWindowGLContext); int attribs[] = { LOCAL_WGL_CONTEXT_FLAGS_ARB, LOCAL_WGL_CONTEXT_ROBUST_ACCESS_BIT_ARB, LOCAL_WGL_CONTEXT_RESET_NOTIFICATION_STRATEGY_ARB, LOCAL_WGL_LOSE_CONTEXT_ON_RESET_ARB, 0 }; mWindowGLContext = fCreateContextAttribs(mWindowDC, NULL, attribs); if (!mWindowGLContext) { mHasRobustness = false; mWindowGLContext = fCreateContext(mWindowDC); } } mInitialized = true; GLContext::ContextFlags flag = GLContext::ContextFlagsNone; if (aUseMesaLlvmPipe) { mLibType = WGLLibrary::MESA_LLVMPIPE_LIB; flag = GLContext::ContextFlagsMesaLLVMPipe; } // Call this to create the global GLContext instance, // and to check for errors. Note that this must happen /after/ // setting mInitialized to TRUE, or an infinite loop results. if (GLContextProviderWGL::GetGlobalContext(flag) == nullptr) { mInitialized = false; return false; } reporter.SetSuccessful(); return true; }
const char* SkWGLExtensions::getExtensionsString(HDC hdc) const { return fGetExtensionsString(hdc); }