2010-04-27 02:09:44 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
2012-05-21 11:12:37 +00:00
|
|
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2010-04-27 02:09:44 +00:00
|
|
|
|
|
|
|
#include "GLContextProvider.h"
|
2014-01-07 20:02:18 +00:00
|
|
|
#include "GLContextWGL.h"
|
2012-03-16 22:24:12 +00:00
|
|
|
#include "GLLibraryLoader.h"
|
2010-04-27 02:09:44 +00:00
|
|
|
#include "nsDebug.h"
|
|
|
|
#include "nsIWidget.h"
|
2010-07-01 16:30:38 +00:00
|
|
|
#include "gfxPlatform.h"
|
|
|
|
#include "gfxWindowsSurface.h"
|
2010-04-27 02:09:44 +00:00
|
|
|
|
2011-03-02 20:50:36 +00:00
|
|
|
#include "gfxCrashReporterUtils.h"
|
|
|
|
|
2010-09-21 19:41:24 +00:00
|
|
|
#include "prenv.h"
|
|
|
|
|
2011-10-19 19:09:57 +00:00
|
|
|
#include "mozilla/Preferences.h"
|
|
|
|
|
2010-04-27 02:09:44 +00:00
|
|
|
namespace mozilla {
|
|
|
|
namespace gl {
|
|
|
|
|
2014-05-22 10:11:45 +00:00
|
|
|
using namespace mozilla::gfx;
|
|
|
|
|
2014-01-10 18:55:23 +00:00
|
|
|
WGLLibrary sWGLLib;
|
2010-09-21 19:41:24 +00:00
|
|
|
|
2012-06-02 16:05:45 +00:00
|
|
|
HWND
|
|
|
|
WGLLibrary::CreateDummyWindow(HDC *aWindowDC)
|
2010-07-19 05:01:14 +00:00
|
|
|
{
|
|
|
|
WNDCLASSW wc;
|
2013-07-20 08:48:55 +00:00
|
|
|
if (!GetClassInfoW(GetModuleHandle(nullptr), L"GLContextWGLClass", &wc)) {
|
2010-07-19 05:01:14 +00:00
|
|
|
ZeroMemory(&wc, sizeof(WNDCLASSW));
|
|
|
|
wc.style = CS_OWNDC;
|
2013-07-20 08:48:55 +00:00
|
|
|
wc.hInstance = GetModuleHandle(nullptr);
|
2010-07-19 05:01:14 +00:00
|
|
|
wc.lpfnWndProc = DefWindowProc;
|
|
|
|
wc.lpszClassName = L"GLContextWGLClass";
|
|
|
|
if (!RegisterClassW(&wc)) {
|
|
|
|
NS_WARNING("Failed to register GLContextWGLClass?!");
|
|
|
|
// er. failed to register our class?
|
2013-07-20 08:48:55 +00:00
|
|
|
return nullptr;
|
2010-07-19 05:01:14 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
HWND win = CreateWindowW(L"GLContextWGLClass", L"GLContextWGL", 0,
|
|
|
|
0, 0, 16, 16,
|
2013-07-20 08:48:55 +00:00
|
|
|
nullptr, nullptr, GetModuleHandle(nullptr),
|
|
|
|
nullptr);
|
|
|
|
NS_ENSURE_TRUE(win, nullptr);
|
2010-07-19 05:01:14 +00:00
|
|
|
|
|
|
|
HDC dc = GetDC(win);
|
2013-07-20 08:48:55 +00:00
|
|
|
NS_ENSURE_TRUE(dc, nullptr);
|
2010-07-19 05:01:14 +00:00
|
|
|
|
2012-06-02 16:05:45 +00:00
|
|
|
if (mWindowPixelFormat == 0) {
|
2010-07-19 05:01:14 +00:00
|
|
|
PIXELFORMATDESCRIPTOR pfd;
|
|
|
|
ZeroMemory(&pfd, sizeof(PIXELFORMATDESCRIPTOR));
|
|
|
|
pfd.nSize = sizeof(PIXELFORMATDESCRIPTOR);
|
|
|
|
pfd.nVersion = 1;
|
2013-10-17 04:16:40 +00:00
|
|
|
pfd.dwFlags = PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER;
|
2010-07-19 05:01:14 +00:00
|
|
|
pfd.iPixelType = PFD_TYPE_RGBA;
|
|
|
|
pfd.cColorBits = 24;
|
2010-08-07 05:09:18 +00:00
|
|
|
pfd.cRedBits = 8;
|
|
|
|
pfd.cGreenBits = 8;
|
|
|
|
pfd.cBlueBits = 8;
|
|
|
|
pfd.cAlphaBits = 8;
|
2010-07-19 05:01:14 +00:00
|
|
|
pfd.cDepthBits = 0;
|
|
|
|
pfd.iLayerType = PFD_MAIN_PLANE;
|
|
|
|
|
2012-06-02 16:05:45 +00:00
|
|
|
mWindowPixelFormat = ChoosePixelFormat(dc, &pfd);
|
2010-07-19 05:01:14 +00:00
|
|
|
}
|
|
|
|
|
2012-06-02 16:05:45 +00:00
|
|
|
if (!mWindowPixelFormat ||
|
2013-07-20 08:48:55 +00:00
|
|
|
!SetPixelFormat(dc, mWindowPixelFormat, nullptr))
|
2011-02-01 23:08:55 +00:00
|
|
|
{
|
2010-07-19 05:01:14 +00:00
|
|
|
NS_WARNING("SetPixelFormat failed!");
|
|
|
|
DestroyWindow(win);
|
2013-07-20 08:48:55 +00:00
|
|
|
return nullptr;
|
2010-07-19 05:01:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (aWindowDC) {
|
|
|
|
*aWindowDC = dc;
|
|
|
|
}
|
|
|
|
|
|
|
|
return win;
|
|
|
|
}
|
2010-05-18 04:04:22 +00:00
|
|
|
|
2011-12-03 07:50:11 +00:00
|
|
|
static inline bool
|
|
|
|
HasExtension(const char* aExtensions, const char* aRequiredExtension)
|
|
|
|
{
|
|
|
|
return GLContext::ListHasExtension(
|
|
|
|
reinterpret_cast<const GLubyte*>(aExtensions), aRequiredExtension);
|
|
|
|
}
|
|
|
|
|
2011-09-29 06:19:26 +00:00
|
|
|
bool
|
2014-01-10 18:55:23 +00:00
|
|
|
WGLLibrary::EnsureInitialized()
|
2010-04-27 02:09:44 +00:00
|
|
|
{
|
2010-05-18 04:04:22 +00:00
|
|
|
if (mInitialized)
|
2011-10-17 14:59:28 +00:00
|
|
|
return true;
|
2014-03-04 02:47:43 +00:00
|
|
|
|
2014-01-10 18:55:23 +00:00
|
|
|
mozilla::ScopedGfxFeatureReporter reporter("WGL");
|
2010-05-18 04:04:22 +00:00
|
|
|
|
2014-01-10 18:55:23 +00:00
|
|
|
std::string libGLFilename = "Opengl32.dll";
|
2013-12-18 18:09:10 +00:00
|
|
|
// SU_SPIES_DIRECTORY is for AMD CodeXL/gDEBugger
|
2014-01-10 18:55:23 +00:00
|
|
|
if (PR_GetEnv("SU_SPIES_DIRECTORY")) {
|
2013-12-18 18:09:10 +00:00
|
|
|
libGLFilename = std::string(PR_GetEnv("SU_SPIES_DIRECTORY")) + "\\opengl32.dll";
|
|
|
|
}
|
|
|
|
|
2010-05-18 04:04:22 +00:00
|
|
|
if (!mOGLLibrary) {
|
2013-12-18 18:09:10 +00:00
|
|
|
mOGLLibrary = PR_LoadLibrary(&libGLFilename[0]);
|
2010-04-27 02:09:44 +00:00
|
|
|
if (!mOGLLibrary) {
|
2012-06-02 16:05:45 +00:00
|
|
|
NS_WARNING("Couldn't load OpenGL library.");
|
2011-10-17 14:59:28 +00:00
|
|
|
return false;
|
2010-04-27 02:09:44 +00:00
|
|
|
}
|
2010-05-18 04:04:22 +00:00
|
|
|
}
|
|
|
|
|
2012-03-16 22:24:12 +00:00
|
|
|
GLLibraryLoader::SymLoadStruct earlySymbols[] = {
|
2013-07-20 08:48:55 +00:00
|
|
|
{ (PRFuncPtr*) &fCreateContext, { "wglCreateContext", nullptr } },
|
|
|
|
{ (PRFuncPtr*) &fMakeCurrent, { "wglMakeCurrent", nullptr } },
|
|
|
|
{ (PRFuncPtr*) &fGetProcAddress, { "wglGetProcAddress", nullptr } },
|
|
|
|
{ (PRFuncPtr*) &fDeleteContext, { "wglDeleteContext", nullptr } },
|
|
|
|
{ (PRFuncPtr*) &fGetCurrentContext, { "wglGetCurrentContext", nullptr } },
|
|
|
|
{ (PRFuncPtr*) &fGetCurrentDC, { "wglGetCurrentDC", nullptr } },
|
|
|
|
{ (PRFuncPtr*) &fShareLists, { "wglShareLists", nullptr } },
|
|
|
|
{ nullptr, { nullptr } }
|
2010-05-18 04:04:22 +00:00
|
|
|
};
|
|
|
|
|
2012-03-16 22:24:12 +00:00
|
|
|
if (!GLLibraryLoader::LoadSymbols(mOGLLibrary, &earlySymbols[0])) {
|
2010-05-18 04:04:22 +00:00
|
|
|
NS_WARNING("Couldn't find required entry points in OpenGL DLL (early init)");
|
2011-10-17 14:59:28 +00:00
|
|
|
return false;
|
2010-05-18 04:04:22 +00:00
|
|
|
}
|
|
|
|
|
2010-07-19 05:01:14 +00:00
|
|
|
// This is ridiculous -- we have to actually create a context to
|
|
|
|
// get the OpenGL ICD to load.
|
2012-06-02 16:05:45 +00:00
|
|
|
mWindow = CreateDummyWindow(&mWindowDC);
|
|
|
|
NS_ENSURE_TRUE(mWindow, false);
|
2010-05-18 04:04:22 +00:00
|
|
|
|
|
|
|
// create rendering context
|
2012-06-02 16:05:45 +00:00
|
|
|
mWindowGLContext = fCreateContext(mWindowDC);
|
|
|
|
NS_ENSURE_TRUE(mWindowGLContext, false);
|
2010-05-18 04:04:22 +00:00
|
|
|
|
|
|
|
HGLRC curCtx = fGetCurrentContext();
|
|
|
|
HDC curDC = fGetCurrentDC();
|
|
|
|
|
2012-06-02 16:05:45 +00:00
|
|
|
if (!fMakeCurrent((HDC)mWindowDC, (HGLRC)mWindowGLContext)) {
|
2010-05-18 04:04:22 +00:00
|
|
|
NS_WARNING("wglMakeCurrent failed");
|
2011-10-17 14:59:28 +00:00
|
|
|
return false;
|
2010-05-18 04:04:22 +00:00
|
|
|
}
|
|
|
|
|
2015-10-08 20:36:58 +00:00
|
|
|
const GLLibraryLoader::PlatformLookupFunction lookupFunc =
|
|
|
|
(GLLibraryLoader::PlatformLookupFunction) fGetProcAddress;
|
|
|
|
|
2010-05-18 04:04:22 +00:00
|
|
|
// Now we can grab all the other symbols that we couldn't without having
|
|
|
|
// a context current.
|
2012-03-16 22:24:12 +00:00
|
|
|
GLLibraryLoader::SymLoadStruct pbufferSymbols[] = {
|
2013-07-20 08:48:55 +00:00
|
|
|
{ (PRFuncPtr*) &fCreatePbuffer, { "wglCreatePbufferARB", "wglCreatePbufferEXT", nullptr } },
|
|
|
|
{ (PRFuncPtr*) &fDestroyPbuffer, { "wglDestroyPbufferARB", "wglDestroyPbufferEXT", nullptr } },
|
|
|
|
{ (PRFuncPtr*) &fGetPbufferDC, { "wglGetPbufferDCARB", "wglGetPbufferDCEXT", nullptr } },
|
|
|
|
{ (PRFuncPtr*) &fBindTexImage, { "wglBindTexImageARB", "wglBindTexImageEXT", nullptr } },
|
|
|
|
{ (PRFuncPtr*) &fReleaseTexImage, { "wglReleaseTexImageARB", "wglReleaseTexImageEXT", nullptr } },
|
|
|
|
{ nullptr, { nullptr } }
|
2010-05-18 04:04:22 +00:00
|
|
|
};
|
|
|
|
|
2012-03-16 22:24:12 +00:00
|
|
|
GLLibraryLoader::SymLoadStruct pixFmtSymbols[] = {
|
2013-07-20 08:48:55 +00:00
|
|
|
{ (PRFuncPtr*) &fChoosePixelFormat, { "wglChoosePixelFormatARB", "wglChoosePixelFormatEXT", nullptr } },
|
|
|
|
{ (PRFuncPtr*) &fGetPixelFormatAttribiv, { "wglGetPixelFormatAttribivARB", "wglGetPixelFormatAttribivEXT", nullptr } },
|
|
|
|
{ nullptr, { nullptr } }
|
2010-05-18 04:04:22 +00:00
|
|
|
};
|
|
|
|
|
2015-10-08 20:36:58 +00:00
|
|
|
if (!GLLibraryLoader::LoadSymbols(mOGLLibrary, &pbufferSymbols[0], lookupFunc)) {
|
2010-05-18 04:04:22 +00:00
|
|
|
// this isn't an error, just means that pbuffers aren't supported
|
2012-07-30 14:20:58 +00:00
|
|
|
fCreatePbuffer = nullptr;
|
2010-05-18 04:04:22 +00:00
|
|
|
}
|
|
|
|
|
2015-10-08 20:36:58 +00:00
|
|
|
if (!GLLibraryLoader::LoadSymbols(mOGLLibrary, &pixFmtSymbols[0], lookupFunc)) {
|
2010-05-18 04:04:22 +00:00
|
|
|
// this isn't an error, just means that we don't have the pixel format extension
|
2012-07-30 14:20:58 +00:00
|
|
|
fChoosePixelFormat = nullptr;
|
2010-05-18 04:04:22 +00:00
|
|
|
}
|
|
|
|
|
2012-03-16 22:24:12 +00:00
|
|
|
GLLibraryLoader::SymLoadStruct extensionsSymbols[] = {
|
2013-07-20 08:48:55 +00:00
|
|
|
{ (PRFuncPtr *) &fGetExtensionsString, { "wglGetExtensionsStringARB", nullptr} },
|
|
|
|
{ nullptr, { nullptr } }
|
2011-12-03 07:50:11 +00:00
|
|
|
};
|
|
|
|
|
2012-03-16 22:24:12 +00:00
|
|
|
GLLibraryLoader::SymLoadStruct robustnessSymbols[] = {
|
2013-07-20 08:48:55 +00:00
|
|
|
{ (PRFuncPtr *) &fCreateContextAttribs, { "wglCreateContextAttribsARB", nullptr} },
|
|
|
|
{ nullptr, { nullptr } }
|
2011-12-03 07:50:11 +00:00
|
|
|
};
|
|
|
|
|
2015-10-08 20:36:58 +00:00
|
|
|
GLLibraryLoader::SymLoadStruct dxInteropSymbols[] = {
|
2015-11-06 00:19:24 +00:00
|
|
|
{ (PRFuncPtr *)&fDXSetResourceShareHandle,{ "wglDXSetResourceShareHandleNV", nullptr } },
|
|
|
|
{ (PRFuncPtr *)&fDXOpenDevice, { "wglDXOpenDeviceNV", nullptr } },
|
|
|
|
{ (PRFuncPtr *)&fDXCloseDevice, { "wglDXCloseDeviceNV", nullptr } },
|
|
|
|
{ (PRFuncPtr *)&fDXRegisterObject, { "wglDXRegisterObjectNV", nullptr } },
|
|
|
|
{ (PRFuncPtr *)&fDXUnregisterObject, { "wglDXUnregisterObjectNV", nullptr } },
|
|
|
|
{ (PRFuncPtr *)&fDXObjectAccess, { "wglDXObjectAccessNV", nullptr } },
|
|
|
|
{ (PRFuncPtr *)&fDXLockObjects, { "wglDXLockObjectsNV", nullptr } },
|
|
|
|
{ (PRFuncPtr *)&fDXUnlockObjects, { "wglDXUnlockObjectsNV", nullptr } },
|
2015-10-08 20:36:58 +00:00
|
|
|
{ nullptr, { nullptr } }
|
|
|
|
};
|
|
|
|
|
2015-11-06 00:19:24 +00:00
|
|
|
if (GLLibraryLoader::LoadSymbols(mOGLLibrary, &extensionsSymbols[0], lookupFunc))
|
|
|
|
{
|
|
|
|
const char* extString = fGetExtensionsString(mWindowDC);
|
|
|
|
MOZ_ASSERT(extString);
|
|
|
|
MOZ_ASSERT(HasExtension(extString, "WGL_ARB_extensions_string"));
|
|
|
|
|
|
|
|
if (HasExtension(extString, "WGL_ARB_context_create")) {
|
|
|
|
if (GLLibraryLoader::LoadSymbols(mOGLLibrary, &robustnessSymbols[0], lookupFunc)) {
|
|
|
|
if (HasExtension(extString, "WGL_ARB_create_context_robustness")) {
|
|
|
|
mHasRobustness = true;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
NS_ERROR("WGL supports ARB_create_context without supplying its functions.");
|
|
|
|
fCreateContextAttribs = nullptr;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (HasExtension(extString, "WGL_NV_DX_interop")) {
|
|
|
|
if (GLLibraryLoader::LoadSymbols(mOGLLibrary, &dxInteropSymbols[0], lookupFunc)) {
|
|
|
|
mHasDXInterop = true;
|
|
|
|
mHasDXInterop2 = HasExtension(extString, "WGL_NV_DX_interop2");
|
|
|
|
} else {
|
|
|
|
NS_ERROR("WGL supports NV_DX_interop without supplying its functions.");
|
|
|
|
fDXSetResourceShareHandle = nullptr;
|
|
|
|
fDXOpenDevice = nullptr;
|
|
|
|
fDXCloseDevice = nullptr;
|
|
|
|
fDXRegisterObject = nullptr;
|
|
|
|
fDXUnregisterObject = nullptr;
|
|
|
|
fDXObjectAccess = nullptr;
|
|
|
|
fDXLockObjects = nullptr;
|
|
|
|
fDXUnlockObjects = nullptr;
|
|
|
|
}
|
|
|
|
}
|
2015-10-08 20:36:58 +00:00
|
|
|
}
|
|
|
|
|
2010-05-18 04:04:22 +00:00
|
|
|
// reset back to the previous context, just in case
|
|
|
|
fMakeCurrent(curDC, curCtx);
|
|
|
|
|
2011-12-03 07:50:11 +00:00
|
|
|
if (mHasRobustness) {
|
2012-06-02 16:05:45 +00:00
|
|
|
fDeleteContext(mWindowGLContext);
|
2011-12-03 07:50:11 +00:00
|
|
|
|
|
|
|
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,
|
2012-10-04 08:31:56 +00:00
|
|
|
0
|
2011-12-03 07:50:11 +00:00
|
|
|
};
|
|
|
|
|
2013-07-20 08:48:55 +00:00
|
|
|
mWindowGLContext = fCreateContextAttribs(mWindowDC, nullptr, attribs);
|
2012-06-02 16:05:45 +00:00
|
|
|
if (!mWindowGLContext) {
|
2011-12-03 07:50:11 +00:00
|
|
|
mHasRobustness = false;
|
2012-06-02 16:05:45 +00:00
|
|
|
mWindowGLContext = fCreateContext(mWindowDC);
|
2011-12-03 07:50:11 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-10-17 14:59:28 +00:00
|
|
|
mInitialized = true;
|
2010-07-19 05:01:14 +00:00
|
|
|
|
|
|
|
// 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.
|
2014-01-10 18:55:23 +00:00
|
|
|
if (GLContextProviderWGL::GetGlobalContext() == nullptr) {
|
2011-10-17 14:59:28 +00:00
|
|
|
mInitialized = false;
|
|
|
|
return false;
|
2010-07-19 05:01:14 +00:00
|
|
|
}
|
|
|
|
|
2011-03-02 20:50:36 +00:00
|
|
|
reporter.SetSuccessful();
|
2011-10-17 14:59:28 +00:00
|
|
|
return true;
|
2010-05-18 04:04:22 +00:00
|
|
|
}
|
2010-04-27 02:09:44 +00:00
|
|
|
|
2014-01-07 20:02:18 +00:00
|
|
|
GLContextWGL::GLContextWGL(
|
|
|
|
const SurfaceCaps& caps,
|
|
|
|
GLContext* sharedContext,
|
|
|
|
bool isOffscreen,
|
|
|
|
HDC aDC,
|
|
|
|
HGLRC aContext,
|
|
|
|
HWND aWindow)
|
|
|
|
: GLContext(caps, sharedContext, isOffscreen),
|
|
|
|
mDC(aDC),
|
|
|
|
mContext(aContext),
|
|
|
|
mWnd(aWindow),
|
|
|
|
mPBuffer(nullptr),
|
|
|
|
mPixelFormat(0),
|
|
|
|
mIsDoubleBuffered(false)
|
2010-04-27 02:09:44 +00:00
|
|
|
{
|
2014-01-07 20:02:18 +00:00
|
|
|
// See 899855
|
|
|
|
SetProfileVersion(ContextProfile::OpenGLCompatibility, 200);
|
|
|
|
}
|
2010-05-18 04:04:22 +00:00
|
|
|
|
2014-01-07 20:02:18 +00:00
|
|
|
GLContextWGL::GLContextWGL(
|
|
|
|
const SurfaceCaps& caps,
|
|
|
|
GLContext* sharedContext,
|
|
|
|
bool isOffscreen,
|
|
|
|
HANDLE aPbuffer,
|
|
|
|
HDC aDC,
|
|
|
|
HGLRC aContext,
|
2014-01-10 18:55:23 +00:00
|
|
|
int aPixelFormat)
|
2014-01-07 20:02:18 +00:00
|
|
|
: GLContext(caps, sharedContext, isOffscreen),
|
|
|
|
mDC(aDC),
|
|
|
|
mContext(aContext),
|
|
|
|
mWnd(nullptr),
|
|
|
|
mPBuffer(aPbuffer),
|
|
|
|
mPixelFormat(aPixelFormat),
|
|
|
|
mIsDoubleBuffered(false)
|
|
|
|
{
|
|
|
|
// See 899855
|
|
|
|
SetProfileVersion(ContextProfile::OpenGLCompatibility, 200);
|
|
|
|
}
|
2010-07-19 05:01:14 +00:00
|
|
|
|
2014-01-07 20:02:18 +00:00
|
|
|
GLContextWGL::~GLContextWGL()
|
|
|
|
{
|
|
|
|
MarkDestroyed();
|
2010-04-27 02:09:44 +00:00
|
|
|
|
2014-01-10 18:55:23 +00:00
|
|
|
sWGLLib.fDeleteContext(mContext);
|
2010-07-19 05:01:14 +00:00
|
|
|
|
2014-01-07 20:02:18 +00:00
|
|
|
if (mPBuffer)
|
2014-01-10 18:55:23 +00:00
|
|
|
sWGLLib.fDestroyPbuffer(mPBuffer);
|
2014-01-07 20:02:18 +00:00
|
|
|
if (mWnd)
|
|
|
|
DestroyWindow(mWnd);
|
|
|
|
}
|
2013-12-18 18:09:11 +00:00
|
|
|
|
2014-01-07 20:02:18 +00:00
|
|
|
bool
|
|
|
|
GLContextWGL::Init()
|
|
|
|
{
|
|
|
|
if (!mDC || !mContext)
|
|
|
|
return false;
|
2010-04-27 02:09:44 +00:00
|
|
|
|
2014-01-07 20:02:18 +00:00
|
|
|
// see bug 929506 comment 29. wglGetProcAddress requires a current context.
|
2014-01-10 18:55:23 +00:00
|
|
|
if (!sWGLLib.fMakeCurrent(mDC, mContext))
|
2014-01-07 20:02:18 +00:00
|
|
|
return false;
|
2010-05-21 00:20:39 +00:00
|
|
|
|
2014-01-07 20:02:18 +00:00
|
|
|
SetupLookupFunction();
|
|
|
|
if (!InitWithPrefix("gl", true))
|
|
|
|
return false;
|
2010-04-27 02:09:44 +00:00
|
|
|
|
2014-01-07 20:02:18 +00:00
|
|
|
return true;
|
|
|
|
}
|
2012-08-22 03:30:20 +00:00
|
|
|
|
2014-01-07 20:02:18 +00:00
|
|
|
bool
|
|
|
|
GLContextWGL::MakeCurrentImpl(bool aForce)
|
|
|
|
{
|
|
|
|
BOOL succeeded = true;
|
|
|
|
|
|
|
|
// wglGetCurrentContext seems to just pull the HGLRC out
|
|
|
|
// of its TLS slot, so no need to do our own tls slot.
|
|
|
|
// You would think that wglMakeCurrent would avoid doing
|
|
|
|
// work if mContext was already current, but not so much..
|
2014-01-10 18:55:23 +00:00
|
|
|
if (aForce || sWGLLib.fGetCurrentContext() != mContext) {
|
|
|
|
succeeded = sWGLLib.fMakeCurrent(mDC, mContext);
|
2014-01-07 20:02:18 +00:00
|
|
|
NS_ASSERTION(succeeded, "Failed to make GL context current!");
|
2010-09-09 20:40:29 +00:00
|
|
|
}
|
|
|
|
|
2014-01-07 20:02:18 +00:00
|
|
|
return succeeded;
|
|
|
|
}
|
2010-09-09 20:40:29 +00:00
|
|
|
|
2014-01-07 20:02:18 +00:00
|
|
|
bool
|
2014-03-04 02:47:43 +00:00
|
|
|
GLContextWGL::IsCurrent()
|
|
|
|
{
|
2014-01-10 18:55:23 +00:00
|
|
|
return sWGLLib.fGetCurrentContext() == mContext;
|
2014-01-07 20:02:18 +00:00
|
|
|
}
|
2011-11-19 03:57:29 +00:00
|
|
|
|
2014-01-07 20:02:18 +00:00
|
|
|
void
|
2014-03-04 02:47:43 +00:00
|
|
|
GLContextWGL::SetIsDoubleBuffered(bool aIsDB)
|
|
|
|
{
|
2014-01-07 20:02:18 +00:00
|
|
|
mIsDoubleBuffered = aIsDB;
|
|
|
|
}
|
2010-09-09 20:40:29 +00:00
|
|
|
|
2014-01-07 20:02:18 +00:00
|
|
|
bool
|
2014-03-04 02:47:43 +00:00
|
|
|
GLContextWGL::IsDoubleBuffered() const
|
|
|
|
{
|
2014-01-07 20:02:18 +00:00
|
|
|
return mIsDoubleBuffered;
|
|
|
|
}
|
2013-12-18 18:09:11 +00:00
|
|
|
|
2014-01-07 20:02:18 +00:00
|
|
|
bool
|
2014-03-04 02:47:43 +00:00
|
|
|
GLContextWGL::SupportsRobustness() const
|
2014-01-07 20:02:18 +00:00
|
|
|
{
|
2014-01-10 18:55:23 +00:00
|
|
|
return sWGLLib.HasRobustness();
|
2014-01-07 20:02:18 +00:00
|
|
|
}
|
2010-04-27 02:09:44 +00:00
|
|
|
|
2014-01-07 20:02:18 +00:00
|
|
|
bool
|
|
|
|
GLContextWGL::SwapBuffers() {
|
|
|
|
if (!mIsDoubleBuffered)
|
|
|
|
return false;
|
|
|
|
return ::SwapBuffers(mDC);
|
|
|
|
}
|
2010-05-18 04:04:22 +00:00
|
|
|
|
2014-01-07 20:02:18 +00:00
|
|
|
bool
|
|
|
|
GLContextWGL::SetupLookupFunction()
|
|
|
|
{
|
|
|
|
// Make sure that we have a ref to the OGL library;
|
|
|
|
// when run under CodeXL, wglGetProcAddress won't return
|
|
|
|
// the right thing for some core functions.
|
|
|
|
MOZ_ASSERT(mLibrary == nullptr);
|
2010-05-18 04:04:22 +00:00
|
|
|
|
2014-01-10 18:55:23 +00:00
|
|
|
mLibrary = sWGLLib.GetOGLLibrary();
|
|
|
|
mLookupFunc = (PlatformLookupFunction)sWGLLib.fGetProcAddress;
|
2014-01-07 20:02:18 +00:00
|
|
|
return true;
|
|
|
|
}
|
2010-07-19 05:01:14 +00:00
|
|
|
|
2011-10-19 19:09:57 +00:00
|
|
|
static bool
|
2015-05-28 09:45:33 +00:00
|
|
|
GetMaxSize(HDC hDC, int format, IntSize& size)
|
2011-10-19 19:09:57 +00:00
|
|
|
{
|
|
|
|
int query[] = {LOCAL_WGL_MAX_PBUFFER_WIDTH_ARB, LOCAL_WGL_MAX_PBUFFER_HEIGHT_ARB};
|
|
|
|
int result[2];
|
|
|
|
|
|
|
|
// (HDC hdc, int iPixelFormat, int iLayerPlane, UINT nAttributes, int* piAttributes, int *piValues)
|
2014-01-10 18:55:23 +00:00
|
|
|
if (!sWGLLib.fGetPixelFormatAttribiv(hDC, format, 0, 2, query, result))
|
2011-10-19 19:09:57 +00:00
|
|
|
return false;
|
|
|
|
|
|
|
|
size.width = result[0];
|
|
|
|
size.height = result[1];
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool
|
2014-03-04 02:47:43 +00:00
|
|
|
IsValidSizeForFormat(HDC hDC, int format,
|
2015-05-28 09:45:33 +00:00
|
|
|
const IntSize& requested)
|
2011-10-19 19:09:57 +00:00
|
|
|
{
|
2015-05-28 09:45:33 +00:00
|
|
|
IntSize max;
|
2014-01-10 18:55:23 +00:00
|
|
|
if (!GetMaxSize(hDC, format, max))
|
2011-10-19 19:09:57 +00:00
|
|
|
return true;
|
|
|
|
|
|
|
|
if (requested.width > max.width)
|
|
|
|
return false;
|
|
|
|
if (requested.height > max.height)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2010-07-19 05:01:14 +00:00
|
|
|
static GLContextWGL *
|
2014-01-10 18:55:23 +00:00
|
|
|
GetGlobalContextWGL()
|
2010-07-19 05:01:14 +00:00
|
|
|
{
|
2014-01-10 18:55:23 +00:00
|
|
|
return static_cast<GLContextWGL*>(GLContextProviderWGL::GetGlobalContext());
|
2010-07-19 05:01:14 +00:00
|
|
|
}
|
2010-04-27 02:09:44 +00:00
|
|
|
|
2014-04-15 14:57:26 +00:00
|
|
|
already_AddRefed<GLContext>
|
|
|
|
GLContextProviderWGL::CreateWrappingExisting(void*, void*)
|
|
|
|
{
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2010-04-27 02:09:44 +00:00
|
|
|
already_AddRefed<GLContext>
|
2015-12-23 15:22:55 +00:00
|
|
|
GLContextProviderWGL::CreateForWindow(nsIWidget *aWidget, bool aForceAccelerated)
|
2010-04-27 02:09:44 +00:00
|
|
|
{
|
2014-01-10 18:55:23 +00:00
|
|
|
if (!sWGLLib.EnsureInitialized()) {
|
2012-07-30 14:20:58 +00:00
|
|
|
return nullptr;
|
2010-04-27 02:09:44 +00:00
|
|
|
}
|
2010-07-19 05:01:14 +00:00
|
|
|
|
2010-04-27 02:09:44 +00:00
|
|
|
/**
|
2014-03-04 02:47:43 +00:00
|
|
|
* We need to make sure we call SetPixelFormat -after- calling
|
|
|
|
* EnsureInitialized, otherwise it can load/unload the dll and
|
2010-04-27 02:09:44 +00:00
|
|
|
* wglCreateContext will fail.
|
|
|
|
*/
|
|
|
|
|
|
|
|
HDC dc = (HDC)aWidget->GetNativeData(NS_NATIVE_GRAPHIC);
|
|
|
|
|
2014-01-10 18:55:23 +00:00
|
|
|
SetPixelFormat(dc, sWGLLib.GetWindowPixelFormat(), nullptr);
|
2011-12-03 07:50:11 +00:00
|
|
|
HGLRC context;
|
2010-04-27 02:09:44 +00:00
|
|
|
|
2010-07-19 05:01:14 +00:00
|
|
|
GLContextWGL *shareContext = GetGlobalContextWGL();
|
2011-12-03 07:50:11 +00:00
|
|
|
|
2014-01-10 18:55:23 +00:00
|
|
|
if (sWGLLib.HasRobustness()) {
|
2011-12-03 07:50:11 +00:00
|
|
|
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,
|
2012-10-04 08:31:56 +00:00
|
|
|
0
|
2011-12-03 07:50:11 +00:00
|
|
|
};
|
|
|
|
|
2014-01-10 18:55:23 +00:00
|
|
|
context = sWGLLib.fCreateContextAttribs(dc,
|
2013-12-18 18:09:10 +00:00
|
|
|
shareContext ? shareContext->Context() : nullptr,
|
|
|
|
attribs);
|
2011-12-16 21:12:02 +00:00
|
|
|
} else {
|
2014-01-10 18:55:23 +00:00
|
|
|
context = sWGLLib.fCreateContext(dc);
|
2011-12-16 21:12:02 +00:00
|
|
|
if (context &&
|
|
|
|
shareContext &&
|
2014-01-10 18:55:23 +00:00
|
|
|
!sWGLLib.fShareLists(shareContext->Context(), context))
|
2011-12-16 21:12:02 +00:00
|
|
|
{
|
2013-12-18 18:09:10 +00:00
|
|
|
printf_stderr("WGL context creation failed for window: wglShareLists returned false!");
|
2014-01-10 18:55:23 +00:00
|
|
|
sWGLLib.fDeleteContext(context);
|
2013-12-18 18:09:10 +00:00
|
|
|
context = nullptr;
|
2011-12-16 21:12:02 +00:00
|
|
|
}
|
2011-12-03 07:50:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!context) {
|
2012-07-30 14:20:58 +00:00
|
|
|
return nullptr;
|
2010-07-19 05:01:14 +00:00
|
|
|
}
|
|
|
|
|
2013-02-13 23:26:24 +00:00
|
|
|
SurfaceCaps caps = SurfaceCaps::ForRGBA();
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<GLContextWGL> glContext = new GLContextWGL(caps,
|
2013-02-13 23:26:24 +00:00
|
|
|
shareContext,
|
|
|
|
false,
|
|
|
|
dc,
|
2014-01-10 18:55:23 +00:00
|
|
|
context);
|
2010-07-19 05:01:14 +00:00
|
|
|
if (!glContext->Init()) {
|
2012-07-30 14:20:58 +00:00
|
|
|
return nullptr;
|
2010-07-19 05:01:14 +00:00
|
|
|
}
|
2010-04-27 02:09:44 +00:00
|
|
|
|
2013-10-17 04:16:40 +00:00
|
|
|
glContext->SetIsDoubleBuffered(true);
|
2010-09-21 19:41:24 +00:00
|
|
|
|
2010-07-19 05:01:14 +00:00
|
|
|
return glContext.forget();
|
2010-04-27 02:09:44 +00:00
|
|
|
}
|
|
|
|
|
2010-07-19 05:01:14 +00:00
|
|
|
static already_AddRefed<GLContextWGL>
|
2015-05-28 09:45:33 +00:00
|
|
|
CreatePBufferOffscreenContext(const IntSize& aSize,
|
2013-12-18 18:09:10 +00:00
|
|
|
GLContextWGL *aShareContext)
|
2010-04-27 02:09:44 +00:00
|
|
|
{
|
2014-01-10 18:55:23 +00:00
|
|
|
WGLLibrary& wgl = sWGLLib;
|
2013-02-13 23:26:24 +00:00
|
|
|
|
2010-07-19 05:01:14 +00:00
|
|
|
#define A1(_a,_x) do { _a.AppendElement(_x); } while(0)
|
|
|
|
#define A2(_a,_x,_y) do { _a.AppendElement(_x); _a.AppendElement(_y); } while(0)
|
|
|
|
|
|
|
|
nsTArray<int> attrs;
|
2010-05-18 04:04:22 +00:00
|
|
|
|
2010-07-19 05:01:14 +00:00
|
|
|
A2(attrs, LOCAL_WGL_SUPPORT_OPENGL_ARB, LOCAL_GL_TRUE);
|
|
|
|
A2(attrs, LOCAL_WGL_DRAW_TO_PBUFFER_ARB, LOCAL_GL_TRUE);
|
|
|
|
A2(attrs, LOCAL_WGL_DOUBLE_BUFFER_ARB, LOCAL_GL_FALSE);
|
2010-05-18 04:04:22 +00:00
|
|
|
|
2010-07-19 05:01:14 +00:00
|
|
|
A2(attrs, LOCAL_WGL_ACCELERATION_ARB, LOCAL_WGL_FULL_ACCELERATION_ARB);
|
2010-05-18 04:04:22 +00:00
|
|
|
|
2010-07-19 05:01:14 +00:00
|
|
|
A2(attrs, LOCAL_WGL_DOUBLE_BUFFER_ARB, LOCAL_GL_FALSE);
|
|
|
|
A2(attrs, LOCAL_WGL_STEREO_ARB, LOCAL_GL_FALSE);
|
2010-05-18 04:04:22 +00:00
|
|
|
|
2010-07-19 05:01:14 +00:00
|
|
|
A1(attrs, 0);
|
2010-05-18 04:04:22 +00:00
|
|
|
|
2010-07-19 05:01:14 +00:00
|
|
|
nsTArray<int> pbattrs;
|
|
|
|
A1(pbattrs, 0);
|
2010-05-18 04:04:22 +00:00
|
|
|
|
2013-02-13 23:26:24 +00:00
|
|
|
#undef A1
|
|
|
|
#undef A2
|
2010-05-18 04:04:22 +00:00
|
|
|
|
2013-02-13 23:26:24 +00:00
|
|
|
// We only need one!
|
|
|
|
UINT numFormats = 1;
|
|
|
|
int formats[1];
|
|
|
|
HDC windowDC = wgl.GetWindowDC();
|
|
|
|
if (!wgl.fChoosePixelFormat(windowDC,
|
2013-07-20 08:48:55 +00:00
|
|
|
attrs.Elements(), nullptr,
|
2013-02-13 23:26:24 +00:00
|
|
|
numFormats, formats, &numFormats)
|
2010-05-18 04:04:22 +00:00
|
|
|
|| numFormats == 0)
|
|
|
|
{
|
2012-07-30 14:20:58 +00:00
|
|
|
return nullptr;
|
2010-05-18 04:04:22 +00:00
|
|
|
}
|
|
|
|
|
2013-02-13 23:26:24 +00:00
|
|
|
// We don't care; just pick the first one.
|
2010-05-18 04:04:22 +00:00
|
|
|
int chosenFormat = formats[0];
|
2014-01-10 18:55:23 +00:00
|
|
|
if (!IsValidSizeForFormat(windowDC, chosenFormat, aSize))
|
2012-07-30 14:20:58 +00:00
|
|
|
return nullptr;
|
2011-10-19 19:09:57 +00:00
|
|
|
|
2013-02-13 23:26:24 +00:00
|
|
|
HANDLE pbuffer = wgl.fCreatePbuffer(windowDC, chosenFormat,
|
|
|
|
aSize.width, aSize.height,
|
|
|
|
pbattrs.Elements());
|
2010-07-19 05:01:14 +00:00
|
|
|
if (!pbuffer) {
|
2012-07-30 14:20:58 +00:00
|
|
|
return nullptr;
|
2010-07-19 05:01:14 +00:00
|
|
|
}
|
|
|
|
|
2013-02-13 23:26:24 +00:00
|
|
|
HDC pbdc = wgl.fGetPbufferDC(pbuffer);
|
2010-07-19 05:01:14 +00:00
|
|
|
NS_ASSERTION(pbdc, "expected a dc");
|
|
|
|
|
2011-12-03 07:50:11 +00:00
|
|
|
HGLRC context;
|
2013-02-13 23:26:24 +00:00
|
|
|
if (wgl.HasRobustness()) {
|
2011-12-03 07:50:11 +00:00
|
|
|
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,
|
2012-10-04 08:31:56 +00:00
|
|
|
0
|
2011-12-03 07:50:11 +00:00
|
|
|
};
|
|
|
|
|
2013-12-18 18:09:10 +00:00
|
|
|
context = wgl.fCreateContextAttribs(pbdc, aShareContext->Context(), attribs);
|
2011-12-03 07:50:11 +00:00
|
|
|
} else {
|
2013-02-13 23:26:24 +00:00
|
|
|
context = wgl.fCreateContext(pbdc);
|
2013-12-18 18:09:10 +00:00
|
|
|
if (context && aShareContext) {
|
|
|
|
if (!wgl.fShareLists(aShareContext->Context(), context)) {
|
|
|
|
wgl.fDeleteContext(context);
|
|
|
|
context = nullptr;
|
|
|
|
printf_stderr("ERROR - creating pbuffer context failed because wglShareLists returned FALSE");
|
|
|
|
}
|
|
|
|
}
|
2011-12-03 07:50:11 +00:00
|
|
|
}
|
|
|
|
|
2010-07-19 05:01:14 +00:00
|
|
|
if (!context) {
|
2013-02-13 23:26:24 +00:00
|
|
|
wgl.fDestroyPbuffer(pbuffer);
|
2012-10-04 08:31:56 +00:00
|
|
|
return nullptr;
|
2010-05-18 04:04:22 +00:00
|
|
|
}
|
|
|
|
|
2013-06-21 18:22:18 +00:00
|
|
|
SurfaceCaps dummyCaps = SurfaceCaps::Any();
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<GLContextWGL> glContext = new GLContextWGL(dummyCaps,
|
2013-12-18 18:09:10 +00:00
|
|
|
aShareContext,
|
|
|
|
true,
|
2010-07-19 05:01:14 +00:00
|
|
|
pbuffer,
|
|
|
|
pbdc,
|
|
|
|
context,
|
2014-01-10 18:55:23 +00:00
|
|
|
chosenFormat);
|
2010-05-18 04:04:22 +00:00
|
|
|
|
2010-07-19 05:01:14 +00:00
|
|
|
return glContext.forget();
|
|
|
|
}
|
2010-05-18 04:04:22 +00:00
|
|
|
|
2010-07-19 05:01:14 +00:00
|
|
|
static already_AddRefed<GLContextWGL>
|
2014-01-10 18:55:23 +00:00
|
|
|
CreateWindowOffscreenContext()
|
2010-07-19 05:01:14 +00:00
|
|
|
{
|
|
|
|
// CreateWindowOffscreenContext must return a global-shared context
|
2014-01-10 18:55:23 +00:00
|
|
|
GLContextWGL *shareContext = GetGlobalContextWGL();
|
2010-07-19 05:01:14 +00:00
|
|
|
if (!shareContext) {
|
2012-07-30 14:20:58 +00:00
|
|
|
return nullptr;
|
2010-07-19 05:01:14 +00:00
|
|
|
}
|
2014-03-04 02:47:43 +00:00
|
|
|
|
2010-07-19 05:01:14 +00:00
|
|
|
HDC dc;
|
2014-01-10 18:55:23 +00:00
|
|
|
HWND win = sWGLLib.CreateDummyWindow(&dc);
|
2010-07-19 05:01:14 +00:00
|
|
|
if (!win) {
|
2012-07-30 14:20:58 +00:00
|
|
|
return nullptr;
|
2010-07-19 05:01:14 +00:00
|
|
|
}
|
2014-03-04 02:47:43 +00:00
|
|
|
|
2014-01-10 18:55:23 +00:00
|
|
|
HGLRC context = sWGLLib.fCreateContext(dc);
|
|
|
|
if (sWGLLib.HasRobustness()) {
|
2011-12-03 07:50:11 +00:00
|
|
|
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,
|
2012-10-04 08:31:56 +00:00
|
|
|
0
|
2011-12-03 07:50:11 +00:00
|
|
|
};
|
|
|
|
|
2014-01-10 18:55:23 +00:00
|
|
|
context = sWGLLib.fCreateContextAttribs(dc, shareContext->Context(), attribs);
|
2011-12-03 07:50:11 +00:00
|
|
|
} else {
|
2014-01-10 18:55:23 +00:00
|
|
|
context = sWGLLib.fCreateContext(dc);
|
2011-12-03 07:50:11 +00:00
|
|
|
if (context && shareContext &&
|
2014-01-10 18:55:23 +00:00
|
|
|
!sWGLLib.fShareLists(shareContext->Context(), context))
|
2011-12-03 07:50:11 +00:00
|
|
|
{
|
|
|
|
NS_WARNING("wglShareLists failed!");
|
2010-07-19 05:01:14 +00:00
|
|
|
|
2014-01-10 18:55:23 +00:00
|
|
|
sWGLLib.fDeleteContext(context);
|
2011-12-03 07:50:11 +00:00
|
|
|
DestroyWindow(win);
|
2012-07-30 14:20:58 +00:00
|
|
|
return nullptr;
|
2011-12-03 07:50:11 +00:00
|
|
|
}
|
|
|
|
}
|
2010-07-19 05:01:14 +00:00
|
|
|
|
2011-12-03 07:50:11 +00:00
|
|
|
if (!context) {
|
2012-07-30 14:20:58 +00:00
|
|
|
return nullptr;
|
2010-07-19 05:01:14 +00:00
|
|
|
}
|
|
|
|
|
2013-02-13 23:26:24 +00:00
|
|
|
SurfaceCaps caps = SurfaceCaps::ForRGBA();
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<GLContextWGL> glContext = new GLContextWGL(caps,
|
2013-02-13 23:26:24 +00:00
|
|
|
shareContext, true,
|
2014-01-10 18:55:23 +00:00
|
|
|
dc, context, win);
|
2010-07-19 05:01:14 +00:00
|
|
|
|
|
|
|
return glContext.forget();
|
|
|
|
}
|
|
|
|
|
2015-09-24 19:21:05 +00:00
|
|
|
/*static*/ already_AddRefed<GLContext>
|
2015-07-29 20:35:55 +00:00
|
|
|
GLContextProviderWGL::CreateHeadless(CreateContextFlags)
|
2010-07-19 05:01:14 +00:00
|
|
|
{
|
2014-01-10 18:55:23 +00:00
|
|
|
if (!sWGLLib.EnsureInitialized()) {
|
2012-07-30 14:20:58 +00:00
|
|
|
return nullptr;
|
2010-07-19 05:01:14 +00:00
|
|
|
}
|
|
|
|
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<GLContextWGL> glContext;
|
2010-07-19 05:01:14 +00:00
|
|
|
|
|
|
|
// Always try to create a pbuffer context first, because we
|
|
|
|
// want the context isolation.
|
2014-01-10 18:55:23 +00:00
|
|
|
if (sWGLLib.fCreatePbuffer &&
|
|
|
|
sWGLLib.fChoosePixelFormat)
|
2010-07-19 05:01:14 +00:00
|
|
|
{
|
2015-05-28 09:45:33 +00:00
|
|
|
IntSize dummySize = IntSize(16, 16);
|
2014-01-10 18:55:23 +00:00
|
|
|
glContext = CreatePBufferOffscreenContext(dummySize, GetGlobalContextWGL());
|
2010-07-19 05:01:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// If it failed, then create a window context and use a FBO.
|
|
|
|
if (!glContext) {
|
2014-01-10 18:55:23 +00:00
|
|
|
glContext = CreateWindowOffscreenContext();
|
2010-07-19 05:01:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!glContext ||
|
|
|
|
!glContext->Init())
|
|
|
|
{
|
2012-07-30 14:20:58 +00:00
|
|
|
return nullptr;
|
2010-05-18 04:04:22 +00:00
|
|
|
}
|
|
|
|
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<GLContext> retGL = glContext.get();
|
2014-08-27 23:16:22 +00:00
|
|
|
return retGL.forget();
|
|
|
|
}
|
|
|
|
|
2015-09-24 19:21:05 +00:00
|
|
|
/*static*/ already_AddRefed<GLContext>
|
2015-04-07 14:08:57 +00:00
|
|
|
GLContextProviderWGL::CreateOffscreen(const IntSize& size,
|
2015-09-24 19:21:05 +00:00
|
|
|
const SurfaceCaps& minCaps,
|
2015-07-29 20:35:55 +00:00
|
|
|
CreateContextFlags flags)
|
2014-08-27 23:16:22 +00:00
|
|
|
{
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<GLContext> gl = CreateHeadless(flags);
|
2015-09-24 19:21:05 +00:00
|
|
|
if (!gl)
|
2014-08-27 23:16:22 +00:00
|
|
|
return nullptr;
|
|
|
|
|
2015-09-24 19:21:05 +00:00
|
|
|
if (!gl->InitOffscreen(size, minCaps))
|
2012-07-30 14:20:58 +00:00
|
|
|
return nullptr;
|
2011-10-19 19:09:57 +00:00
|
|
|
|
2015-09-24 19:21:05 +00:00
|
|
|
return gl.forget();
|
2010-04-27 02:09:44 +00:00
|
|
|
}
|
|
|
|
|
2015-10-18 05:24:48 +00:00
|
|
|
static RefPtr<GLContextWGL> gGlobalContext;
|
2010-07-19 05:01:14 +00:00
|
|
|
|
2015-09-24 19:21:05 +00:00
|
|
|
/*static*/ GLContext*
|
2014-01-10 18:55:23 +00:00
|
|
|
GLContextProviderWGL::GetGlobalContext()
|
2010-07-19 05:01:14 +00:00
|
|
|
{
|
2014-01-10 18:55:23 +00:00
|
|
|
if (!sWGLLib.EnsureInitialized()) {
|
2012-07-30 14:20:58 +00:00
|
|
|
return nullptr;
|
2010-07-19 05:01:14 +00:00
|
|
|
}
|
|
|
|
|
2014-01-10 18:55:23 +00:00
|
|
|
static bool triedToCreateContext = false;
|
2010-07-19 05:01:14 +00:00
|
|
|
|
2014-01-10 18:55:23 +00:00
|
|
|
if (!triedToCreateContext && !gGlobalContext) {
|
|
|
|
triedToCreateContext = true;
|
2010-07-19 05:01:14 +00:00
|
|
|
|
|
|
|
// conveniently, we already have what we need...
|
2013-02-13 23:26:24 +00:00
|
|
|
SurfaceCaps dummyCaps = SurfaceCaps::Any();
|
2014-01-10 18:55:23 +00:00
|
|
|
gGlobalContext = new GLContextWGL(dummyCaps,
|
|
|
|
nullptr, true,
|
|
|
|
sWGLLib.GetWindowDC(),
|
|
|
|
sWGLLib.GetWindowGLContext());
|
|
|
|
if (!gGlobalContext->Init()) {
|
2010-07-19 05:01:14 +00:00
|
|
|
NS_WARNING("Global context GLContext initialization failed?");
|
2014-01-10 18:55:23 +00:00
|
|
|
gGlobalContext = nullptr;
|
2012-10-04 08:31:56 +00:00
|
|
|
return nullptr;
|
2010-07-19 05:01:14 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-01-10 18:55:23 +00:00
|
|
|
return static_cast<GLContext*>(gGlobalContext);
|
2010-07-19 05:01:14 +00:00
|
|
|
}
|
|
|
|
|
2015-09-24 19:21:05 +00:00
|
|
|
/*static*/ void
|
2010-07-20 04:05:42 +00:00
|
|
|
GLContextProviderWGL::Shutdown()
|
|
|
|
{
|
2014-01-10 18:55:23 +00:00
|
|
|
gGlobalContext = nullptr;
|
2010-07-20 04:05:42 +00:00
|
|
|
}
|
|
|
|
|
2010-04-27 02:09:44 +00:00
|
|
|
} /* namespace gl */
|
|
|
|
} /* namespace mozilla */
|