2010-04-26 19:09:44 -07:00
|
|
|
/* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
2012-05-21 04:12:37 -07: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-26 19:09:44 -07:00
|
|
|
|
|
|
|
#include "GLContextProvider.h"
|
2014-01-07 12:02:18 -08:00
|
|
|
#include "GLContextWGL.h"
|
2012-03-16 15:24:12 -07:00
|
|
|
#include "GLLibraryLoader.h"
|
2010-04-26 19:09:44 -07:00
|
|
|
#include "nsDebug.h"
|
|
|
|
#include "nsIWidget.h"
|
2010-07-01 09:30:38 -07:00
|
|
|
#include "gfxPlatform.h"
|
|
|
|
#include "gfxWindowsSurface.h"
|
2010-04-26 19:09:44 -07:00
|
|
|
|
2011-03-02 12:50:36 -08:00
|
|
|
#include "gfxCrashReporterUtils.h"
|
|
|
|
|
2010-09-21 12:41:24 -07:00
|
|
|
#include "prenv.h"
|
|
|
|
|
2011-10-19 12:09:57 -07:00
|
|
|
#include "mozilla/Preferences.h"
|
|
|
|
|
2010-04-26 19:09:44 -07:00
|
|
|
namespace mozilla {
|
|
|
|
namespace gl {
|
|
|
|
|
2014-05-22 03:11:45 -07:00
|
|
|
using namespace mozilla::gfx;
|
|
|
|
|
2014-01-10 10:55:23 -08:00
|
|
|
WGLLibrary sWGLLib;
|
2010-09-21 12:41:24 -07:00
|
|
|
|
2012-06-02 09:05:45 -07:00
|
|
|
HWND
|
|
|
|
WGLLibrary::CreateDummyWindow(HDC *aWindowDC)
|
2010-07-18 22:01:14 -07:00
|
|
|
{
|
|
|
|
WNDCLASSW wc;
|
2013-07-20 01:48:55 -07:00
|
|
|
if (!GetClassInfoW(GetModuleHandle(nullptr), L"GLContextWGLClass", &wc)) {
|
2010-07-18 22:01:14 -07:00
|
|
|
ZeroMemory(&wc, sizeof(WNDCLASSW));
|
|
|
|
wc.style = CS_OWNDC;
|
2013-07-20 01:48:55 -07:00
|
|
|
wc.hInstance = GetModuleHandle(nullptr);
|
2010-07-18 22:01:14 -07: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 01:48:55 -07:00
|
|
|
return nullptr;
|
2010-07-18 22:01:14 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
HWND win = CreateWindowW(L"GLContextWGLClass", L"GLContextWGL", 0,
|
|
|
|
0, 0, 16, 16,
|
2013-07-20 01:48:55 -07:00
|
|
|
nullptr, nullptr, GetModuleHandle(nullptr),
|
|
|
|
nullptr);
|
|
|
|
NS_ENSURE_TRUE(win, nullptr);
|
2010-07-18 22:01:14 -07:00
|
|
|
|
|
|
|
HDC dc = GetDC(win);
|
2013-07-20 01:48:55 -07:00
|
|
|
NS_ENSURE_TRUE(dc, nullptr);
|
2010-07-18 22:01:14 -07:00
|
|
|
|
2012-06-02 09:05:45 -07:00
|
|
|
if (mWindowPixelFormat == 0) {
|
2010-07-18 22:01:14 -07:00
|
|
|
PIXELFORMATDESCRIPTOR pfd;
|
|
|
|
ZeroMemory(&pfd, sizeof(PIXELFORMATDESCRIPTOR));
|
|
|
|
pfd.nSize = sizeof(PIXELFORMATDESCRIPTOR);
|
|
|
|
pfd.nVersion = 1;
|
2013-10-16 21:16:40 -07:00
|
|
|
pfd.dwFlags = PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER;
|
2010-07-18 22:01:14 -07:00
|
|
|
pfd.iPixelType = PFD_TYPE_RGBA;
|
|
|
|
pfd.cColorBits = 24;
|
2010-08-06 22:09:18 -07:00
|
|
|
pfd.cRedBits = 8;
|
|
|
|
pfd.cGreenBits = 8;
|
|
|
|
pfd.cBlueBits = 8;
|
|
|
|
pfd.cAlphaBits = 8;
|
2010-07-18 22:01:14 -07:00
|
|
|
pfd.cDepthBits = 0;
|
|
|
|
pfd.iLayerType = PFD_MAIN_PLANE;
|
|
|
|
|
2012-06-02 09:05:45 -07:00
|
|
|
mWindowPixelFormat = ChoosePixelFormat(dc, &pfd);
|
2010-07-18 22:01:14 -07:00
|
|
|
}
|
|
|
|
|
2012-06-02 09:05:45 -07:00
|
|
|
if (!mWindowPixelFormat ||
|
2013-07-20 01:48:55 -07:00
|
|
|
!SetPixelFormat(dc, mWindowPixelFormat, nullptr))
|
2011-02-01 15:08:55 -08:00
|
|
|
{
|
2010-07-18 22:01:14 -07:00
|
|
|
NS_WARNING("SetPixelFormat failed!");
|
|
|
|
DestroyWindow(win);
|
2013-07-20 01:48:55 -07:00
|
|
|
return nullptr;
|
2010-07-18 22:01:14 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
if (aWindowDC) {
|
|
|
|
*aWindowDC = dc;
|
|
|
|
}
|
|
|
|
|
|
|
|
return win;
|
|
|
|
}
|
2010-05-17 21:04:22 -07:00
|
|
|
|
2011-12-02 23:50:11 -08:00
|
|
|
static inline bool
|
|
|
|
HasExtension(const char* aExtensions, const char* aRequiredExtension)
|
|
|
|
{
|
|
|
|
return GLContext::ListHasExtension(
|
|
|
|
reinterpret_cast<const GLubyte*>(aExtensions), aRequiredExtension);
|
|
|
|
}
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool
|
2014-01-10 10:55:23 -08:00
|
|
|
WGLLibrary::EnsureInitialized()
|
2010-04-26 19:09:44 -07:00
|
|
|
{
|
2010-05-17 21:04:22 -07:00
|
|
|
if (mInitialized)
|
2011-10-17 07:59:28 -07:00
|
|
|
return true;
|
2014-03-03 18:47:43 -08:00
|
|
|
|
2014-01-10 10:55:23 -08:00
|
|
|
mozilla::ScopedGfxFeatureReporter reporter("WGL");
|
2010-05-17 21:04:22 -07:00
|
|
|
|
2014-01-10 10:55:23 -08:00
|
|
|
std::string libGLFilename = "Opengl32.dll";
|
2013-12-18 10:09:10 -08:00
|
|
|
// SU_SPIES_DIRECTORY is for AMD CodeXL/gDEBugger
|
2014-01-10 10:55:23 -08:00
|
|
|
if (PR_GetEnv("SU_SPIES_DIRECTORY")) {
|
2013-12-18 10:09:10 -08:00
|
|
|
libGLFilename = std::string(PR_GetEnv("SU_SPIES_DIRECTORY")) + "\\opengl32.dll";
|
|
|
|
}
|
|
|
|
|
2010-05-17 21:04:22 -07:00
|
|
|
if (!mOGLLibrary) {
|
2013-12-18 10:09:10 -08:00
|
|
|
mOGLLibrary = PR_LoadLibrary(&libGLFilename[0]);
|
2010-04-26 19:09:44 -07:00
|
|
|
if (!mOGLLibrary) {
|
2012-06-02 09:05:45 -07:00
|
|
|
NS_WARNING("Couldn't load OpenGL library.");
|
2011-10-17 07:59:28 -07:00
|
|
|
return false;
|
2010-04-26 19:09:44 -07:00
|
|
|
}
|
2010-05-17 21:04:22 -07:00
|
|
|
}
|
|
|
|
|
2012-03-16 15:24:12 -07:00
|
|
|
GLLibraryLoader::SymLoadStruct earlySymbols[] = {
|
2013-07-20 01:48:55 -07: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-17 21:04:22 -07:00
|
|
|
};
|
|
|
|
|
2012-03-16 15:24:12 -07:00
|
|
|
if (!GLLibraryLoader::LoadSymbols(mOGLLibrary, &earlySymbols[0])) {
|
2010-05-17 21:04:22 -07:00
|
|
|
NS_WARNING("Couldn't find required entry points in OpenGL DLL (early init)");
|
2011-10-17 07:59:28 -07:00
|
|
|
return false;
|
2010-05-17 21:04:22 -07:00
|
|
|
}
|
|
|
|
|
2010-07-18 22:01:14 -07:00
|
|
|
// This is ridiculous -- we have to actually create a context to
|
|
|
|
// get the OpenGL ICD to load.
|
2012-06-02 09:05:45 -07:00
|
|
|
mWindow = CreateDummyWindow(&mWindowDC);
|
|
|
|
NS_ENSURE_TRUE(mWindow, false);
|
2010-05-17 21:04:22 -07:00
|
|
|
|
|
|
|
// create rendering context
|
2012-06-02 09:05:45 -07:00
|
|
|
mWindowGLContext = fCreateContext(mWindowDC);
|
|
|
|
NS_ENSURE_TRUE(mWindowGLContext, false);
|
2010-05-17 21:04:22 -07:00
|
|
|
|
|
|
|
HGLRC curCtx = fGetCurrentContext();
|
|
|
|
HDC curDC = fGetCurrentDC();
|
|
|
|
|
2012-06-02 09:05:45 -07:00
|
|
|
if (!fMakeCurrent((HDC)mWindowDC, (HGLRC)mWindowGLContext)) {
|
2010-05-17 21:04:22 -07:00
|
|
|
NS_WARNING("wglMakeCurrent failed");
|
2011-10-17 07:59:28 -07:00
|
|
|
return false;
|
2010-05-17 21:04:22 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
// Now we can grab all the other symbols that we couldn't without having
|
|
|
|
// a context current.
|
|
|
|
|
2012-03-16 15:24:12 -07:00
|
|
|
GLLibraryLoader::SymLoadStruct pbufferSymbols[] = {
|
2013-07-20 01:48:55 -07: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-17 21:04:22 -07:00
|
|
|
};
|
|
|
|
|
2012-03-16 15:24:12 -07:00
|
|
|
GLLibraryLoader::SymLoadStruct pixFmtSymbols[] = {
|
2013-07-20 01:48:55 -07:00
|
|
|
{ (PRFuncPtr*) &fChoosePixelFormat, { "wglChoosePixelFormatARB", "wglChoosePixelFormatEXT", nullptr } },
|
|
|
|
{ (PRFuncPtr*) &fGetPixelFormatAttribiv, { "wglGetPixelFormatAttribivARB", "wglGetPixelFormatAttribivEXT", nullptr } },
|
|
|
|
{ nullptr, { nullptr } }
|
2010-05-17 21:04:22 -07:00
|
|
|
};
|
|
|
|
|
2012-03-16 15:24:12 -07:00
|
|
|
if (!GLLibraryLoader::LoadSymbols(mOGLLibrary, &pbufferSymbols[0],
|
|
|
|
(GLLibraryLoader::PlatformLookupFunction)fGetProcAddress))
|
2010-05-17 21:04:22 -07:00
|
|
|
{
|
|
|
|
// this isn't an error, just means that pbuffers aren't supported
|
2012-07-30 07:20:58 -07:00
|
|
|
fCreatePbuffer = nullptr;
|
2010-05-17 21:04:22 -07:00
|
|
|
}
|
|
|
|
|
2012-03-16 15:24:12 -07:00
|
|
|
if (!GLLibraryLoader::LoadSymbols(mOGLLibrary, &pixFmtSymbols[0],
|
|
|
|
(GLLibraryLoader::PlatformLookupFunction)fGetProcAddress))
|
2010-05-17 21:04:22 -07:00
|
|
|
{
|
|
|
|
// this isn't an error, just means that we don't have the pixel format extension
|
2012-07-30 07:20:58 -07:00
|
|
|
fChoosePixelFormat = nullptr;
|
2010-05-17 21:04:22 -07:00
|
|
|
}
|
|
|
|
|
2012-03-16 15:24:12 -07:00
|
|
|
GLLibraryLoader::SymLoadStruct extensionsSymbols[] = {
|
2013-07-20 01:48:55 -07:00
|
|
|
{ (PRFuncPtr *) &fGetExtensionsString, { "wglGetExtensionsStringARB", nullptr} },
|
|
|
|
{ nullptr, { nullptr } }
|
2011-12-02 23:50:11 -08:00
|
|
|
};
|
|
|
|
|
2012-03-16 15:24:12 -07:00
|
|
|
GLLibraryLoader::SymLoadStruct robustnessSymbols[] = {
|
2013-07-20 01:48:55 -07:00
|
|
|
{ (PRFuncPtr *) &fCreateContextAttribs, { "wglCreateContextAttribsARB", nullptr} },
|
|
|
|
{ nullptr, { nullptr } }
|
2011-12-02 23:50:11 -08:00
|
|
|
};
|
|
|
|
|
2012-03-16 15:24:12 -07:00
|
|
|
if (GLLibraryLoader::LoadSymbols(mOGLLibrary, &extensionsSymbols[0],
|
|
|
|
(GLLibraryLoader::PlatformLookupFunction)fGetProcAddress)) {
|
2012-06-02 09:05:45 -07:00
|
|
|
const char *wglExts = fGetExtensionsString(mWindowDC);
|
2011-12-02 23:50:11 -08:00
|
|
|
if (wglExts && HasExtension(wglExts, "WGL_ARB_create_context")) {
|
2012-03-16 15:24:12 -07:00
|
|
|
GLLibraryLoader::LoadSymbols(mOGLLibrary, &robustnessSymbols[0],
|
|
|
|
(GLLibraryLoader::PlatformLookupFunction)fGetProcAddress);
|
2011-12-02 23:50:11 -08:00
|
|
|
if (HasExtension(wglExts, "WGL_ARB_create_context_robustness")) {
|
|
|
|
mHasRobustness = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-05-17 21:04:22 -07:00
|
|
|
// reset back to the previous context, just in case
|
|
|
|
fMakeCurrent(curDC, curCtx);
|
|
|
|
|
2011-12-02 23:50:11 -08:00
|
|
|
if (mHasRobustness) {
|
2012-06-02 09:05:45 -07:00
|
|
|
fDeleteContext(mWindowGLContext);
|
2011-12-02 23:50:11 -08: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 01:31:56 -07:00
|
|
|
0
|
2011-12-02 23:50:11 -08:00
|
|
|
};
|
|
|
|
|
2013-07-20 01:48:55 -07:00
|
|
|
mWindowGLContext = fCreateContextAttribs(mWindowDC, nullptr, attribs);
|
2012-06-02 09:05:45 -07:00
|
|
|
if (!mWindowGLContext) {
|
2011-12-02 23:50:11 -08:00
|
|
|
mHasRobustness = false;
|
2012-06-02 09:05:45 -07:00
|
|
|
mWindowGLContext = fCreateContext(mWindowDC);
|
2011-12-02 23:50:11 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-10-17 07:59:28 -07:00
|
|
|
mInitialized = true;
|
2010-07-18 22:01:14 -07: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 10:55:23 -08:00
|
|
|
if (GLContextProviderWGL::GetGlobalContext() == nullptr) {
|
2011-10-17 07:59:28 -07:00
|
|
|
mInitialized = false;
|
|
|
|
return false;
|
2010-07-18 22:01:14 -07:00
|
|
|
}
|
|
|
|
|
2011-03-02 12:50:36 -08:00
|
|
|
reporter.SetSuccessful();
|
2011-10-17 07:59:28 -07:00
|
|
|
return true;
|
2010-05-17 21:04:22 -07:00
|
|
|
}
|
2010-04-26 19:09:44 -07:00
|
|
|
|
2014-01-07 12:02:18 -08: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-26 19:09:44 -07:00
|
|
|
{
|
2014-01-07 12:02:18 -08:00
|
|
|
// See 899855
|
|
|
|
SetProfileVersion(ContextProfile::OpenGLCompatibility, 200);
|
|
|
|
}
|
2010-05-17 21:04:22 -07:00
|
|
|
|
2014-01-07 12:02:18 -08:00
|
|
|
GLContextWGL::GLContextWGL(
|
|
|
|
const SurfaceCaps& caps,
|
|
|
|
GLContext* sharedContext,
|
|
|
|
bool isOffscreen,
|
|
|
|
HANDLE aPbuffer,
|
|
|
|
HDC aDC,
|
|
|
|
HGLRC aContext,
|
2014-01-10 10:55:23 -08:00
|
|
|
int aPixelFormat)
|
2014-01-07 12:02:18 -08: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-18 22:01:14 -07:00
|
|
|
|
2014-01-07 12:02:18 -08:00
|
|
|
GLContextWGL::~GLContextWGL()
|
|
|
|
{
|
|
|
|
MarkDestroyed();
|
2010-04-26 19:09:44 -07:00
|
|
|
|
2014-01-10 10:55:23 -08:00
|
|
|
sWGLLib.fDeleteContext(mContext);
|
2010-07-18 22:01:14 -07:00
|
|
|
|
2014-01-07 12:02:18 -08:00
|
|
|
if (mPBuffer)
|
2014-01-10 10:55:23 -08:00
|
|
|
sWGLLib.fDestroyPbuffer(mPBuffer);
|
2014-01-07 12:02:18 -08:00
|
|
|
if (mWnd)
|
|
|
|
DestroyWindow(mWnd);
|
|
|
|
}
|
2013-12-18 10:09:11 -08:00
|
|
|
|
2014-01-07 12:02:18 -08:00
|
|
|
bool
|
|
|
|
GLContextWGL::Init()
|
|
|
|
{
|
|
|
|
if (!mDC || !mContext)
|
|
|
|
return false;
|
2010-04-26 19:09:44 -07:00
|
|
|
|
2014-01-07 12:02:18 -08:00
|
|
|
// see bug 929506 comment 29. wglGetProcAddress requires a current context.
|
2014-01-10 10:55:23 -08:00
|
|
|
if (!sWGLLib.fMakeCurrent(mDC, mContext))
|
2014-01-07 12:02:18 -08:00
|
|
|
return false;
|
2010-05-20 17:20:39 -07:00
|
|
|
|
2014-01-07 12:02:18 -08:00
|
|
|
SetupLookupFunction();
|
|
|
|
if (!InitWithPrefix("gl", true))
|
|
|
|
return false;
|
2010-04-26 19:09:44 -07:00
|
|
|
|
2014-01-07 12:02:18 -08:00
|
|
|
return true;
|
|
|
|
}
|
2012-08-21 20:30:20 -07:00
|
|
|
|
2014-01-07 12:02:18 -08: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 10:55:23 -08:00
|
|
|
if (aForce || sWGLLib.fGetCurrentContext() != mContext) {
|
|
|
|
succeeded = sWGLLib.fMakeCurrent(mDC, mContext);
|
2014-01-07 12:02:18 -08:00
|
|
|
NS_ASSERTION(succeeded, "Failed to make GL context current!");
|
2010-09-09 13:40:29 -07:00
|
|
|
}
|
|
|
|
|
2014-01-07 12:02:18 -08:00
|
|
|
return succeeded;
|
|
|
|
}
|
2010-09-09 13:40:29 -07:00
|
|
|
|
2014-01-07 12:02:18 -08:00
|
|
|
bool
|
2014-03-03 18:47:43 -08:00
|
|
|
GLContextWGL::IsCurrent()
|
|
|
|
{
|
2014-01-10 10:55:23 -08:00
|
|
|
return sWGLLib.fGetCurrentContext() == mContext;
|
2014-01-07 12:02:18 -08:00
|
|
|
}
|
2011-11-18 19:57:29 -08:00
|
|
|
|
2014-01-07 12:02:18 -08:00
|
|
|
void
|
2014-03-03 18:47:43 -08:00
|
|
|
GLContextWGL::SetIsDoubleBuffered(bool aIsDB)
|
|
|
|
{
|
2014-01-07 12:02:18 -08:00
|
|
|
mIsDoubleBuffered = aIsDB;
|
|
|
|
}
|
2010-09-09 13:40:29 -07:00
|
|
|
|
2014-01-07 12:02:18 -08:00
|
|
|
bool
|
2014-03-03 18:47:43 -08:00
|
|
|
GLContextWGL::IsDoubleBuffered() const
|
|
|
|
{
|
2014-01-07 12:02:18 -08:00
|
|
|
return mIsDoubleBuffered;
|
|
|
|
}
|
2013-12-18 10:09:11 -08:00
|
|
|
|
2014-01-07 12:02:18 -08:00
|
|
|
bool
|
2014-03-03 18:47:43 -08:00
|
|
|
GLContextWGL::SupportsRobustness() const
|
2014-01-07 12:02:18 -08:00
|
|
|
{
|
2014-01-10 10:55:23 -08:00
|
|
|
return sWGLLib.HasRobustness();
|
2014-01-07 12:02:18 -08:00
|
|
|
}
|
2010-04-26 19:09:44 -07:00
|
|
|
|
2014-01-07 12:02:18 -08:00
|
|
|
bool
|
|
|
|
GLContextWGL::SwapBuffers() {
|
|
|
|
if (!mIsDoubleBuffered)
|
|
|
|
return false;
|
|
|
|
return ::SwapBuffers(mDC);
|
|
|
|
}
|
2010-05-17 21:04:22 -07:00
|
|
|
|
2014-01-07 12:02:18 -08: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-17 21:04:22 -07:00
|
|
|
|
2014-01-10 10:55:23 -08:00
|
|
|
mLibrary = sWGLLib.GetOGLLibrary();
|
|
|
|
mLookupFunc = (PlatformLookupFunction)sWGLLib.fGetProcAddress;
|
2014-01-07 12:02:18 -08:00
|
|
|
return true;
|
|
|
|
}
|
2010-07-18 22:01:14 -07:00
|
|
|
|
2011-10-19 12:09:57 -07:00
|
|
|
static bool
|
2014-01-10 10:55:23 -08:00
|
|
|
GetMaxSize(HDC hDC, int format, gfxIntSize& size)
|
2011-10-19 12:09:57 -07: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 10:55:23 -08:00
|
|
|
if (!sWGLLib.fGetPixelFormatAttribiv(hDC, format, 0, 2, query, result))
|
2011-10-19 12:09:57 -07:00
|
|
|
return false;
|
|
|
|
|
|
|
|
size.width = result[0];
|
|
|
|
size.height = result[1];
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool
|
2014-03-03 18:47:43 -08:00
|
|
|
IsValidSizeForFormat(HDC hDC, int format,
|
2014-01-10 10:55:23 -08:00
|
|
|
const gfxIntSize& requested)
|
2011-10-19 12:09:57 -07:00
|
|
|
{
|
|
|
|
gfxIntSize max;
|
2014-01-10 10:55:23 -08:00
|
|
|
if (!GetMaxSize(hDC, format, max))
|
2011-10-19 12:09:57 -07:00
|
|
|
return true;
|
|
|
|
|
|
|
|
if (requested.width > max.width)
|
|
|
|
return false;
|
|
|
|
if (requested.height > max.height)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2010-07-18 22:01:14 -07:00
|
|
|
static GLContextWGL *
|
2014-01-10 10:55:23 -08:00
|
|
|
GetGlobalContextWGL()
|
2010-07-18 22:01:14 -07:00
|
|
|
{
|
2014-01-10 10:55:23 -08:00
|
|
|
return static_cast<GLContextWGL*>(GLContextProviderWGL::GetGlobalContext());
|
2010-07-18 22:01:14 -07:00
|
|
|
}
|
2010-04-26 19:09:44 -07:00
|
|
|
|
2014-04-15 07:57:26 -07:00
|
|
|
already_AddRefed<GLContext>
|
|
|
|
GLContextProviderWGL::CreateWrappingExisting(void*, void*)
|
|
|
|
{
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2010-04-26 19:09:44 -07:00
|
|
|
already_AddRefed<GLContext>
|
2010-07-18 22:01:14 -07:00
|
|
|
GLContextProviderWGL::CreateForWindow(nsIWidget *aWidget)
|
2010-04-26 19:09:44 -07:00
|
|
|
{
|
2014-01-10 10:55:23 -08:00
|
|
|
if (!sWGLLib.EnsureInitialized()) {
|
2012-07-30 07:20:58 -07:00
|
|
|
return nullptr;
|
2010-04-26 19:09:44 -07:00
|
|
|
}
|
2010-07-18 22:01:14 -07:00
|
|
|
|
2010-04-26 19:09:44 -07:00
|
|
|
/**
|
2014-03-03 18:47:43 -08:00
|
|
|
* We need to make sure we call SetPixelFormat -after- calling
|
|
|
|
* EnsureInitialized, otherwise it can load/unload the dll and
|
2010-04-26 19:09:44 -07:00
|
|
|
* wglCreateContext will fail.
|
|
|
|
*/
|
|
|
|
|
|
|
|
HDC dc = (HDC)aWidget->GetNativeData(NS_NATIVE_GRAPHIC);
|
|
|
|
|
2014-01-10 10:55:23 -08:00
|
|
|
SetPixelFormat(dc, sWGLLib.GetWindowPixelFormat(), nullptr);
|
2011-12-02 23:50:11 -08:00
|
|
|
HGLRC context;
|
2010-04-26 19:09:44 -07:00
|
|
|
|
2010-07-18 22:01:14 -07:00
|
|
|
GLContextWGL *shareContext = GetGlobalContextWGL();
|
2011-12-02 23:50:11 -08:00
|
|
|
|
2014-01-10 10:55:23 -08:00
|
|
|
if (sWGLLib.HasRobustness()) {
|
2011-12-02 23:50:11 -08: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 01:31:56 -07:00
|
|
|
0
|
2011-12-02 23:50:11 -08:00
|
|
|
};
|
|
|
|
|
2014-01-10 10:55:23 -08:00
|
|
|
context = sWGLLib.fCreateContextAttribs(dc,
|
2013-12-18 10:09:10 -08:00
|
|
|
shareContext ? shareContext->Context() : nullptr,
|
|
|
|
attribs);
|
2011-12-16 13:12:02 -08:00
|
|
|
} else {
|
2014-01-10 10:55:23 -08:00
|
|
|
context = sWGLLib.fCreateContext(dc);
|
2011-12-16 13:12:02 -08:00
|
|
|
if (context &&
|
|
|
|
shareContext &&
|
2014-01-10 10:55:23 -08:00
|
|
|
!sWGLLib.fShareLists(shareContext->Context(), context))
|
2011-12-16 13:12:02 -08:00
|
|
|
{
|
2013-12-18 10:09:10 -08:00
|
|
|
printf_stderr("WGL context creation failed for window: wglShareLists returned false!");
|
2014-01-10 10:55:23 -08:00
|
|
|
sWGLLib.fDeleteContext(context);
|
2013-12-18 10:09:10 -08:00
|
|
|
context = nullptr;
|
2011-12-16 13:12:02 -08:00
|
|
|
}
|
2011-12-02 23:50:11 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!context) {
|
2012-07-30 07:20:58 -07:00
|
|
|
return nullptr;
|
2010-07-18 22:01:14 -07:00
|
|
|
}
|
|
|
|
|
2013-02-13 15:26:24 -08:00
|
|
|
SurfaceCaps caps = SurfaceCaps::ForRGBA();
|
|
|
|
nsRefPtr<GLContextWGL> glContext = new GLContextWGL(caps,
|
|
|
|
shareContext,
|
|
|
|
false,
|
|
|
|
dc,
|
2014-01-10 10:55:23 -08:00
|
|
|
context);
|
2010-07-18 22:01:14 -07:00
|
|
|
if (!glContext->Init()) {
|
2012-07-30 07:20:58 -07:00
|
|
|
return nullptr;
|
2010-07-18 22:01:14 -07:00
|
|
|
}
|
2010-04-26 19:09:44 -07:00
|
|
|
|
2013-10-16 21:16:40 -07:00
|
|
|
glContext->SetIsDoubleBuffered(true);
|
2010-09-21 12:41:24 -07:00
|
|
|
|
2010-07-18 22:01:14 -07:00
|
|
|
return glContext.forget();
|
2010-04-26 19:09:44 -07:00
|
|
|
}
|
|
|
|
|
2010-07-18 22:01:14 -07:00
|
|
|
static already_AddRefed<GLContextWGL>
|
|
|
|
CreatePBufferOffscreenContext(const gfxIntSize& aSize,
|
2013-12-18 10:09:10 -08:00
|
|
|
GLContextWGL *aShareContext)
|
2010-04-26 19:09:44 -07:00
|
|
|
{
|
2014-01-10 10:55:23 -08:00
|
|
|
WGLLibrary& wgl = sWGLLib;
|
2013-02-13 15:26:24 -08:00
|
|
|
|
2010-07-18 22:01:14 -07: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-17 21:04:22 -07:00
|
|
|
|
2010-07-18 22:01:14 -07: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-17 21:04:22 -07:00
|
|
|
|
2010-07-18 22:01:14 -07:00
|
|
|
A2(attrs, LOCAL_WGL_ACCELERATION_ARB, LOCAL_WGL_FULL_ACCELERATION_ARB);
|
2010-05-17 21:04:22 -07:00
|
|
|
|
2010-07-18 22:01:14 -07:00
|
|
|
A2(attrs, LOCAL_WGL_DOUBLE_BUFFER_ARB, LOCAL_GL_FALSE);
|
|
|
|
A2(attrs, LOCAL_WGL_STEREO_ARB, LOCAL_GL_FALSE);
|
2010-05-17 21:04:22 -07:00
|
|
|
|
2010-07-18 22:01:14 -07:00
|
|
|
A1(attrs, 0);
|
2010-05-17 21:04:22 -07:00
|
|
|
|
2010-07-18 22:01:14 -07:00
|
|
|
nsTArray<int> pbattrs;
|
|
|
|
A1(pbattrs, 0);
|
2010-05-17 21:04:22 -07:00
|
|
|
|
2013-02-13 15:26:24 -08:00
|
|
|
#undef A1
|
|
|
|
#undef A2
|
2010-05-17 21:04:22 -07:00
|
|
|
|
2013-02-13 15:26:24 -08:00
|
|
|
// We only need one!
|
|
|
|
UINT numFormats = 1;
|
|
|
|
int formats[1];
|
|
|
|
HDC windowDC = wgl.GetWindowDC();
|
|
|
|
if (!wgl.fChoosePixelFormat(windowDC,
|
2013-07-20 01:48:55 -07:00
|
|
|
attrs.Elements(), nullptr,
|
2013-02-13 15:26:24 -08:00
|
|
|
numFormats, formats, &numFormats)
|
2010-05-17 21:04:22 -07:00
|
|
|
|| numFormats == 0)
|
|
|
|
{
|
2012-07-30 07:20:58 -07:00
|
|
|
return nullptr;
|
2010-05-17 21:04:22 -07:00
|
|
|
}
|
|
|
|
|
2013-02-13 15:26:24 -08:00
|
|
|
// We don't care; just pick the first one.
|
2010-05-17 21:04:22 -07:00
|
|
|
int chosenFormat = formats[0];
|
2014-01-10 10:55:23 -08:00
|
|
|
if (!IsValidSizeForFormat(windowDC, chosenFormat, aSize))
|
2012-07-30 07:20:58 -07:00
|
|
|
return nullptr;
|
2011-10-19 12:09:57 -07:00
|
|
|
|
2013-02-13 15:26:24 -08:00
|
|
|
HANDLE pbuffer = wgl.fCreatePbuffer(windowDC, chosenFormat,
|
|
|
|
aSize.width, aSize.height,
|
|
|
|
pbattrs.Elements());
|
2010-07-18 22:01:14 -07:00
|
|
|
if (!pbuffer) {
|
2012-07-30 07:20:58 -07:00
|
|
|
return nullptr;
|
2010-07-18 22:01:14 -07:00
|
|
|
}
|
|
|
|
|
2013-02-13 15:26:24 -08:00
|
|
|
HDC pbdc = wgl.fGetPbufferDC(pbuffer);
|
2010-07-18 22:01:14 -07:00
|
|
|
NS_ASSERTION(pbdc, "expected a dc");
|
|
|
|
|
2011-12-02 23:50:11 -08:00
|
|
|
HGLRC context;
|
2013-02-13 15:26:24 -08:00
|
|
|
if (wgl.HasRobustness()) {
|
2011-12-02 23:50:11 -08: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 01:31:56 -07:00
|
|
|
0
|
2011-12-02 23:50:11 -08:00
|
|
|
};
|
|
|
|
|
2013-12-18 10:09:10 -08:00
|
|
|
context = wgl.fCreateContextAttribs(pbdc, aShareContext->Context(), attribs);
|
2011-12-02 23:50:11 -08:00
|
|
|
} else {
|
2013-02-13 15:26:24 -08:00
|
|
|
context = wgl.fCreateContext(pbdc);
|
2013-12-18 10:09:10 -08: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-02 23:50:11 -08:00
|
|
|
}
|
|
|
|
|
2010-07-18 22:01:14 -07:00
|
|
|
if (!context) {
|
2013-02-13 15:26:24 -08:00
|
|
|
wgl.fDestroyPbuffer(pbuffer);
|
2012-10-04 01:31:56 -07:00
|
|
|
return nullptr;
|
2010-05-17 21:04:22 -07:00
|
|
|
}
|
|
|
|
|
2013-06-21 11:22:18 -07:00
|
|
|
SurfaceCaps dummyCaps = SurfaceCaps::Any();
|
2013-02-13 15:26:24 -08:00
|
|
|
nsRefPtr<GLContextWGL> glContext = new GLContextWGL(dummyCaps,
|
2013-12-18 10:09:10 -08:00
|
|
|
aShareContext,
|
|
|
|
true,
|
2010-07-18 22:01:14 -07:00
|
|
|
pbuffer,
|
|
|
|
pbdc,
|
|
|
|
context,
|
2014-01-10 10:55:23 -08:00
|
|
|
chosenFormat);
|
2010-05-17 21:04:22 -07:00
|
|
|
|
2010-07-18 22:01:14 -07:00
|
|
|
return glContext.forget();
|
|
|
|
}
|
2010-05-17 21:04:22 -07:00
|
|
|
|
2010-07-18 22:01:14 -07:00
|
|
|
static already_AddRefed<GLContextWGL>
|
2014-01-10 10:55:23 -08:00
|
|
|
CreateWindowOffscreenContext()
|
2010-07-18 22:01:14 -07:00
|
|
|
{
|
|
|
|
// CreateWindowOffscreenContext must return a global-shared context
|
2014-01-10 10:55:23 -08:00
|
|
|
GLContextWGL *shareContext = GetGlobalContextWGL();
|
2010-07-18 22:01:14 -07:00
|
|
|
if (!shareContext) {
|
2012-07-30 07:20:58 -07:00
|
|
|
return nullptr;
|
2010-07-18 22:01:14 -07:00
|
|
|
}
|
2014-03-03 18:47:43 -08:00
|
|
|
|
2010-07-18 22:01:14 -07:00
|
|
|
HDC dc;
|
2014-01-10 10:55:23 -08:00
|
|
|
HWND win = sWGLLib.CreateDummyWindow(&dc);
|
2010-07-18 22:01:14 -07:00
|
|
|
if (!win) {
|
2012-07-30 07:20:58 -07:00
|
|
|
return nullptr;
|
2010-07-18 22:01:14 -07:00
|
|
|
}
|
2014-03-03 18:47:43 -08:00
|
|
|
|
2014-01-10 10:55:23 -08:00
|
|
|
HGLRC context = sWGLLib.fCreateContext(dc);
|
|
|
|
if (sWGLLib.HasRobustness()) {
|
2011-12-02 23:50:11 -08: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 01:31:56 -07:00
|
|
|
0
|
2011-12-02 23:50:11 -08:00
|
|
|
};
|
|
|
|
|
2014-01-10 10:55:23 -08:00
|
|
|
context = sWGLLib.fCreateContextAttribs(dc, shareContext->Context(), attribs);
|
2011-12-02 23:50:11 -08:00
|
|
|
} else {
|
2014-01-10 10:55:23 -08:00
|
|
|
context = sWGLLib.fCreateContext(dc);
|
2011-12-02 23:50:11 -08:00
|
|
|
if (context && shareContext &&
|
2014-01-10 10:55:23 -08:00
|
|
|
!sWGLLib.fShareLists(shareContext->Context(), context))
|
2011-12-02 23:50:11 -08:00
|
|
|
{
|
|
|
|
NS_WARNING("wglShareLists failed!");
|
2010-07-18 22:01:14 -07:00
|
|
|
|
2014-01-10 10:55:23 -08:00
|
|
|
sWGLLib.fDeleteContext(context);
|
2011-12-02 23:50:11 -08:00
|
|
|
DestroyWindow(win);
|
2012-07-30 07:20:58 -07:00
|
|
|
return nullptr;
|
2011-12-02 23:50:11 -08:00
|
|
|
}
|
|
|
|
}
|
2010-07-18 22:01:14 -07:00
|
|
|
|
2011-12-02 23:50:11 -08:00
|
|
|
if (!context) {
|
2012-07-30 07:20:58 -07:00
|
|
|
return nullptr;
|
2010-07-18 22:01:14 -07:00
|
|
|
}
|
|
|
|
|
2013-02-13 15:26:24 -08:00
|
|
|
SurfaceCaps caps = SurfaceCaps::ForRGBA();
|
|
|
|
nsRefPtr<GLContextWGL> glContext = new GLContextWGL(caps,
|
|
|
|
shareContext, true,
|
2014-01-10 10:55:23 -08:00
|
|
|
dc, context, win);
|
2010-07-18 22:01:14 -07:00
|
|
|
|
|
|
|
return glContext.forget();
|
|
|
|
}
|
|
|
|
|
|
|
|
already_AddRefed<GLContext>
|
2014-08-27 02:15:40 -07:00
|
|
|
GLContextProviderWGL::CreateOffscreen(const gfxIntSize& size,
|
|
|
|
const SurfaceCaps& caps)
|
2010-07-18 22:01:14 -07:00
|
|
|
{
|
2014-01-10 10:55:23 -08:00
|
|
|
if (!sWGLLib.EnsureInitialized()) {
|
2012-07-30 07:20:58 -07:00
|
|
|
return nullptr;
|
2010-07-18 22:01:14 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
nsRefPtr<GLContextWGL> glContext;
|
|
|
|
|
|
|
|
// Always try to create a pbuffer context first, because we
|
|
|
|
// want the context isolation.
|
2014-01-10 10:55:23 -08:00
|
|
|
if (sWGLLib.fCreatePbuffer &&
|
|
|
|
sWGLLib.fChoosePixelFormat)
|
2010-07-18 22:01:14 -07:00
|
|
|
{
|
2013-02-13 15:26:24 -08:00
|
|
|
gfxIntSize dummySize = gfxIntSize(16, 16);
|
2014-01-10 10:55:23 -08:00
|
|
|
glContext = CreatePBufferOffscreenContext(dummySize, GetGlobalContextWGL());
|
2010-07-18 22:01:14 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
// If it failed, then create a window context and use a FBO.
|
|
|
|
if (!glContext) {
|
2014-01-10 10:55:23 -08:00
|
|
|
glContext = CreateWindowOffscreenContext();
|
2010-07-18 22:01:14 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!glContext ||
|
|
|
|
!glContext->Init())
|
|
|
|
{
|
2012-07-30 07:20:58 -07:00
|
|
|
return nullptr;
|
2010-05-17 21:04:22 -07:00
|
|
|
}
|
|
|
|
|
2014-01-01 11:47:19 -08:00
|
|
|
if (!glContext->InitOffscreen(ToIntSize(size), caps))
|
2012-07-30 07:20:58 -07:00
|
|
|
return nullptr;
|
2011-10-19 12:09:57 -07:00
|
|
|
|
2010-07-18 22:01:14 -07:00
|
|
|
return glContext.forget();
|
2010-04-26 19:09:44 -07:00
|
|
|
}
|
|
|
|
|
2014-01-10 10:55:23 -08:00
|
|
|
static nsRefPtr<GLContextWGL> gGlobalContext;
|
2010-07-18 22:01:14 -07:00
|
|
|
|
|
|
|
GLContext *
|
2014-01-10 10:55:23 -08:00
|
|
|
GLContextProviderWGL::GetGlobalContext()
|
2010-07-18 22:01:14 -07:00
|
|
|
{
|
2014-01-10 10:55:23 -08:00
|
|
|
if (!sWGLLib.EnsureInitialized()) {
|
2012-07-30 07:20:58 -07:00
|
|
|
return nullptr;
|
2010-07-18 22:01:14 -07:00
|
|
|
}
|
|
|
|
|
2014-01-10 10:55:23 -08:00
|
|
|
static bool triedToCreateContext = false;
|
2010-07-18 22:01:14 -07:00
|
|
|
|
2014-01-10 10:55:23 -08:00
|
|
|
if (!triedToCreateContext && !gGlobalContext) {
|
|
|
|
triedToCreateContext = true;
|
2010-07-18 22:01:14 -07:00
|
|
|
|
|
|
|
// conveniently, we already have what we need...
|
2013-02-13 15:26:24 -08:00
|
|
|
SurfaceCaps dummyCaps = SurfaceCaps::Any();
|
2014-01-10 10:55:23 -08:00
|
|
|
gGlobalContext = new GLContextWGL(dummyCaps,
|
|
|
|
nullptr, true,
|
|
|
|
sWGLLib.GetWindowDC(),
|
|
|
|
sWGLLib.GetWindowGLContext());
|
|
|
|
if (!gGlobalContext->Init()) {
|
2010-07-18 22:01:14 -07:00
|
|
|
NS_WARNING("Global context GLContext initialization failed?");
|
2014-01-10 10:55:23 -08:00
|
|
|
gGlobalContext = nullptr;
|
2012-10-04 01:31:56 -07:00
|
|
|
return nullptr;
|
2010-07-18 22:01:14 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-01-10 10:55:23 -08:00
|
|
|
return static_cast<GLContext*>(gGlobalContext);
|
2010-07-18 22:01:14 -07:00
|
|
|
}
|
|
|
|
|
2010-07-19 21:05:42 -07:00
|
|
|
void
|
|
|
|
GLContextProviderWGL::Shutdown()
|
|
|
|
{
|
2014-01-10 10:55:23 -08:00
|
|
|
gGlobalContext = nullptr;
|
2010-07-19 21:05:42 -07:00
|
|
|
}
|
|
|
|
|
2010-04-26 19:09:44 -07:00
|
|
|
} /* namespace gl */
|
|
|
|
} /* namespace mozilla */
|