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"
|
2010-05-18 04:04:22 +00:00
|
|
|
#include "GLContext.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-05-18 04:04:22 +00:00
|
|
|
#include "WGLLibrary.h"
|
2010-06-23 09:24:31 +00:00
|
|
|
#include "gfxASurface.h"
|
2010-07-01 16:30:38 +00:00
|
|
|
#include "gfxImageSurface.h"
|
|
|
|
#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"
|
|
|
|
|
2013-02-13 23:26:24 +00:00
|
|
|
using namespace mozilla::gfx;
|
|
|
|
|
2010-04-27 02:09:44 +00:00
|
|
|
namespace mozilla {
|
|
|
|
namespace gl {
|
|
|
|
|
2012-06-02 16:05:45 +00:00
|
|
|
typedef WGLLibrary::LibraryType LibType;
|
2010-04-27 02:09:44 +00:00
|
|
|
|
2012-06-02 16:05:45 +00:00
|
|
|
WGLLibrary sWGLLib[WGLLibrary::LIBS_MAX];
|
2010-07-19 05:01:14 +00:00
|
|
|
|
2012-06-02 16:05:45 +00:00
|
|
|
LibType
|
2013-09-04 12:14:52 +00:00
|
|
|
WGLLibrary::SelectLibrary(const ContextFlags& aFlags)
|
2012-06-02 16:05:45 +00:00
|
|
|
{
|
2013-09-04 12:14:52 +00:00
|
|
|
return (aFlags & ContextFlagsMesaLLVMPipe)
|
2012-06-02 16:05:45 +00:00
|
|
|
? WGLLibrary::MESA_LLVMPIPE_LIB
|
|
|
|
: WGLLibrary::OPENGL_LIB;
|
|
|
|
}
|
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
|
2012-06-02 16:05:45 +00:00
|
|
|
WGLLibrary::EnsureInitialized(bool aUseMesaLlvmPipe)
|
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;
|
2012-06-02 16:05:45 +00:00
|
|
|
|
|
|
|
mozilla::ScopedGfxFeatureReporter reporter("WGL", aUseMesaLlvmPipe);
|
2010-05-18 04:04:22 +00:00
|
|
|
|
2012-06-02 16:05:45 +00:00
|
|
|
const char* libGLFilename = aUseMesaLlvmPipe
|
|
|
|
? "mesallvmpipe.dll"
|
|
|
|
: "Opengl32.dll";
|
2010-05-18 04:04:22 +00:00
|
|
|
if (!mOGLLibrary) {
|
2012-06-02 16:05:45 +00:00
|
|
|
mOGLLibrary = PR_LoadLibrary(libGLFilename);
|
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
|
|
|
}
|
|
|
|
|
|
|
|
// 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
|
|
|
};
|
|
|
|
|
2012-03-16 22:24:12 +00:00
|
|
|
if (!GLLibraryLoader::LoadSymbols(mOGLLibrary, &pbufferSymbols[0],
|
|
|
|
(GLLibraryLoader::PlatformLookupFunction)fGetProcAddress))
|
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
|
|
|
}
|
|
|
|
|
2012-03-16 22:24:12 +00:00
|
|
|
if (!GLLibraryLoader::LoadSymbols(mOGLLibrary, &pixFmtSymbols[0],
|
|
|
|
(GLLibraryLoader::PlatformLookupFunction)fGetProcAddress))
|
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
|
|
|
};
|
|
|
|
|
2012-03-16 22:24:12 +00:00
|
|
|
if (GLLibraryLoader::LoadSymbols(mOGLLibrary, &extensionsSymbols[0],
|
|
|
|
(GLLibraryLoader::PlatformLookupFunction)fGetProcAddress)) {
|
2012-06-02 16:05:45 +00:00
|
|
|
const char *wglExts = fGetExtensionsString(mWindowDC);
|
2011-12-03 07:50:11 +00:00
|
|
|
if (wglExts && HasExtension(wglExts, "WGL_ARB_create_context")) {
|
2012-03-16 22:24:12 +00:00
|
|
|
GLLibraryLoader::LoadSymbols(mOGLLibrary, &robustnessSymbols[0],
|
|
|
|
(GLLibraryLoader::PlatformLookupFunction)fGetProcAddress);
|
2011-12-03 07:50:11 +00:00
|
|
|
if (HasExtension(wglExts, "WGL_ARB_create_context_robustness")) {
|
|
|
|
mHasRobustness = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
2013-09-04 12:14:52 +00:00
|
|
|
ContextFlags flag = ContextFlagsNone;
|
2012-06-02 16:05:45 +00:00
|
|
|
if (aUseMesaLlvmPipe) {
|
|
|
|
mLibType = WGLLibrary::MESA_LLVMPIPE_LIB;
|
2013-09-04 12:14:52 +00:00
|
|
|
flag = ContextFlagsMesaLLVMPipe;
|
2012-06-02 16:05:45 +00:00
|
|
|
}
|
|
|
|
|
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.
|
2012-07-30 14:20:58 +00:00
|
|
|
if (GLContextProviderWGL::GetGlobalContext(flag) == 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
|
|
|
|
|
|
|
class GLContextWGL : public GLContext
|
|
|
|
{
|
|
|
|
public:
|
2013-02-13 23:26:24 +00:00
|
|
|
// From Window: (possibly for offscreen!)
|
|
|
|
GLContextWGL(const SurfaceCaps& caps,
|
|
|
|
GLContext* sharedContext,
|
|
|
|
bool isOffscreen,
|
2010-07-19 05:01:14 +00:00
|
|
|
HDC aDC,
|
|
|
|
HGLRC aContext,
|
2012-06-02 16:05:45 +00:00
|
|
|
LibType aLibUsed,
|
2013-02-13 23:26:24 +00:00
|
|
|
HWND aWindow = nullptr)
|
|
|
|
: GLContext(caps, sharedContext, isOffscreen),
|
2010-07-19 05:01:14 +00:00
|
|
|
mDC(aDC),
|
|
|
|
mContext(aContext),
|
|
|
|
mWnd(aWindow),
|
2013-07-20 08:48:55 +00:00
|
|
|
mPBuffer(nullptr),
|
2010-09-09 20:40:29 +00:00
|
|
|
mPixelFormat(0),
|
2012-06-02 16:05:45 +00:00
|
|
|
mLibType(aLibUsed),
|
2011-10-17 14:59:28 +00:00
|
|
|
mIsDoubleBuffered(false)
|
2010-07-19 05:01:14 +00:00
|
|
|
{
|
2013-08-01 23:43:27 +00:00
|
|
|
// See 899855
|
|
|
|
SetProfileVersion(ContextProfile::OpenGLCompatibility, 200);
|
2010-07-19 05:01:14 +00:00
|
|
|
}
|
2010-05-18 04:04:22 +00:00
|
|
|
|
2013-02-13 23:26:24 +00:00
|
|
|
// From PBuffer
|
|
|
|
GLContextWGL(const SurfaceCaps& caps,
|
|
|
|
GLContext* sharedContext,
|
|
|
|
bool isOffscreen,
|
2010-07-19 05:01:14 +00:00
|
|
|
HANDLE aPbuffer,
|
|
|
|
HDC aDC,
|
|
|
|
HGLRC aContext,
|
2012-06-02 16:05:45 +00:00
|
|
|
int aPixelFormat,
|
|
|
|
LibType aLibUsed)
|
2013-02-13 23:26:24 +00:00
|
|
|
: GLContext(caps, sharedContext, isOffscreen),
|
2010-07-19 05:01:14 +00:00
|
|
|
mDC(aDC),
|
|
|
|
mContext(aContext),
|
2013-07-20 08:48:55 +00:00
|
|
|
mWnd(nullptr),
|
2010-07-19 05:01:14 +00:00
|
|
|
mPBuffer(aPbuffer),
|
2010-09-09 20:40:29 +00:00
|
|
|
mPixelFormat(aPixelFormat),
|
2012-06-02 16:05:45 +00:00
|
|
|
mLibType(aLibUsed),
|
2011-10-17 14:59:28 +00:00
|
|
|
mIsDoubleBuffered(false)
|
2010-07-19 05:01:14 +00:00
|
|
|
{
|
2013-08-01 23:43:27 +00:00
|
|
|
// See 899855
|
|
|
|
SetProfileVersion(ContextProfile::OpenGLCompatibility, 200);
|
2010-05-18 04:04:22 +00:00
|
|
|
}
|
2010-04-27 02:09:44 +00:00
|
|
|
|
|
|
|
~GLContextWGL()
|
|
|
|
{
|
2010-09-21 19:41:24 +00:00
|
|
|
MarkDestroyed();
|
2010-07-19 05:01:14 +00:00
|
|
|
|
2012-06-02 16:05:45 +00:00
|
|
|
sWGLLib[mLibType].fDeleteContext(mContext);
|
2010-05-18 04:04:22 +00:00
|
|
|
|
|
|
|
if (mPBuffer)
|
2012-06-02 16:05:45 +00:00
|
|
|
sWGLLib[mLibType].fDestroyPbuffer(mPBuffer);
|
2010-07-19 05:01:14 +00:00
|
|
|
if (mWnd)
|
|
|
|
DestroyWindow(mWnd);
|
|
|
|
}
|
|
|
|
|
|
|
|
GLContextType GetContextType() {
|
|
|
|
return ContextTypeWGL;
|
2010-04-27 02:09:44 +00:00
|
|
|
}
|
|
|
|
|
2011-09-29 06:19:26 +00:00
|
|
|
bool Init()
|
2010-04-27 02:09:44 +00:00
|
|
|
{
|
2010-07-19 05:01:14 +00:00
|
|
|
if (!mDC || !mContext)
|
2011-10-17 14:59:28 +00:00
|
|
|
return false;
|
2010-07-19 05:01:14 +00:00
|
|
|
|
2010-04-27 02:09:44 +00:00
|
|
|
SetupLookupFunction();
|
2012-03-12 22:10:38 +00:00
|
|
|
if (!InitWithPrefix("gl", true))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
return true;
|
2010-04-27 02:09:44 +00:00
|
|
|
}
|
|
|
|
|
2012-05-12 23:23:56 +00:00
|
|
|
bool MakeCurrentImpl(bool aForce = false)
|
2010-04-27 02:09:44 +00:00
|
|
|
{
|
2012-05-12 23:23:56 +00:00
|
|
|
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..
|
2012-06-02 16:05:45 +00:00
|
|
|
if (aForce || sWGLLib[mLibType].fGetCurrentContext() != mContext) {
|
|
|
|
succeeded = sWGLLib[mLibType].fMakeCurrent(mDC, mContext);
|
2012-05-12 23:23:56 +00:00
|
|
|
NS_ASSERTION(succeeded, "Failed to make GL context current!");
|
|
|
|
}
|
2010-05-21 00:20:39 +00:00
|
|
|
|
2010-04-27 02:09:44 +00:00
|
|
|
return succeeded;
|
|
|
|
}
|
|
|
|
|
2012-08-22 03:30:20 +00:00
|
|
|
virtual bool IsCurrent() {
|
|
|
|
return sWGLLib[mLibType].fGetCurrentContext() == mContext;
|
|
|
|
}
|
|
|
|
|
2011-09-29 06:19:26 +00:00
|
|
|
void SetIsDoubleBuffered(bool aIsDB) {
|
2010-09-09 20:40:29 +00:00
|
|
|
mIsDoubleBuffered = aIsDB;
|
|
|
|
}
|
|
|
|
|
2011-09-29 06:19:26 +00:00
|
|
|
virtual bool IsDoubleBuffered() {
|
2010-09-09 20:40:29 +00:00
|
|
|
return mIsDoubleBuffered;
|
|
|
|
}
|
|
|
|
|
2011-11-19 03:57:29 +00:00
|
|
|
bool SupportsRobustness()
|
|
|
|
{
|
2012-06-02 16:05:45 +00:00
|
|
|
return sWGLLib[mLibType].HasRobustness();
|
2011-11-19 03:57:29 +00:00
|
|
|
}
|
|
|
|
|
2011-09-29 06:19:26 +00:00
|
|
|
virtual bool SwapBuffers() {
|
2010-09-09 20:40:29 +00:00
|
|
|
if (!mIsDoubleBuffered)
|
2011-10-17 14:59:28 +00:00
|
|
|
return false;
|
2010-09-09 20:40:29 +00:00
|
|
|
return ::SwapBuffers(mDC);
|
|
|
|
}
|
|
|
|
|
2011-09-29 06:19:26 +00:00
|
|
|
bool SetupLookupFunction()
|
2010-04-27 02:09:44 +00:00
|
|
|
{
|
2012-06-02 16:05:45 +00:00
|
|
|
mLookupFunc = (PlatformLookupFunction)sWGLLib[mLibType].fGetProcAddress;
|
2011-10-17 14:59:28 +00:00
|
|
|
return true;
|
2010-04-27 02:09:44 +00:00
|
|
|
}
|
|
|
|
|
2010-05-18 04:04:22 +00:00
|
|
|
void *GetNativeData(NativeDataType aType)
|
|
|
|
{
|
|
|
|
switch (aType) {
|
|
|
|
case NativeGLContext:
|
|
|
|
return mContext;
|
|
|
|
|
|
|
|
default:
|
2012-07-30 14:20:58 +00:00
|
|
|
return nullptr;
|
2010-05-18 04:04:22 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-12-17 00:33:07 +00:00
|
|
|
bool ResizeOffscreen(const gfxIntSize& aNewSize);
|
2010-07-19 05:01:14 +00:00
|
|
|
|
|
|
|
HGLRC Context() { return mContext; }
|
|
|
|
|
|
|
|
protected:
|
|
|
|
friend class GLContextProviderWGL;
|
|
|
|
|
|
|
|
HDC mDC;
|
|
|
|
HGLRC mContext;
|
|
|
|
HWND mWnd;
|
|
|
|
HANDLE mPBuffer;
|
|
|
|
int mPixelFormat;
|
2012-06-02 16:05:45 +00:00
|
|
|
LibType mLibType;
|
2011-09-29 06:19:26 +00:00
|
|
|
bool mIsDoubleBuffered;
|
2010-07-19 05:01:14 +00:00
|
|
|
};
|
|
|
|
|
2011-10-19 19:09:57 +00:00
|
|
|
|
|
|
|
static bool
|
2012-06-02 16:05:45 +00:00
|
|
|
GetMaxSize(HDC hDC, int format, gfxIntSize& size, LibType aLibToUse)
|
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)
|
2012-06-02 16:05:45 +00:00
|
|
|
if (!sWGLLib[aLibToUse].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
|
2012-06-02 16:05:45 +00:00
|
|
|
IsValidSizeForFormat(HDC hDC, int format,
|
|
|
|
const gfxIntSize& requested,
|
|
|
|
LibType aLibUsed)
|
2011-10-19 19:09:57 +00:00
|
|
|
{
|
|
|
|
gfxIntSize max;
|
2012-06-02 16:05:45 +00:00
|
|
|
if (!GetMaxSize(hDC, format, max, aLibUsed))
|
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;
|
|
|
|
}
|
|
|
|
|
2011-09-29 06:19:26 +00:00
|
|
|
bool
|
2013-12-17 00:33:07 +00:00
|
|
|
GLContextWGL::ResizeOffscreen(const gfxIntSize& aNewSize)
|
2010-07-19 05:01:14 +00:00
|
|
|
{
|
2013-12-17 00:33:07 +00:00
|
|
|
return ResizeScreenBuffer(aNewSize);
|
2010-07-19 05:01:14 +00:00
|
|
|
}
|
2010-07-01 16:30:38 +00:00
|
|
|
|
2010-07-19 05:01:14 +00:00
|
|
|
static GLContextWGL *
|
2013-09-04 12:14:52 +00:00
|
|
|
GetGlobalContextWGL(const ContextFlags aFlags = ContextFlagsNone)
|
2010-07-19 05:01:14 +00:00
|
|
|
{
|
2012-06-02 16:05:45 +00:00
|
|
|
return static_cast<GLContextWGL*>(GLContextProviderWGL::GetGlobalContext(aFlags));
|
2010-07-19 05:01:14 +00:00
|
|
|
}
|
2010-04-27 02:09:44 +00:00
|
|
|
|
|
|
|
already_AddRefed<GLContext>
|
2010-07-19 05:01:14 +00:00
|
|
|
GLContextProviderWGL::CreateForWindow(nsIWidget *aWidget)
|
2010-04-27 02:09:44 +00:00
|
|
|
{
|
2012-06-02 16:05:45 +00:00
|
|
|
LibType libToUse = WGLLibrary::OPENGL_LIB;
|
|
|
|
|
|
|
|
if (!sWGLLib[libToUse].EnsureInitialized(false)) {
|
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
|
|
|
/**
|
|
|
|
* We need to make sure we call SetPixelFormat -after- calling
|
|
|
|
* EnsureInitialized, otherwise it can load/unload the dll and
|
|
|
|
* wglCreateContext will fail.
|
|
|
|
*/
|
|
|
|
|
|
|
|
HDC dc = (HDC)aWidget->GetNativeData(NS_NATIVE_GRAPHIC);
|
|
|
|
|
2013-07-20 08:48:55 +00:00
|
|
|
SetPixelFormat(dc, sWGLLib[libToUse].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
|
|
|
|
2012-06-02 16:05:45 +00:00
|
|
|
if (sWGLLib[libToUse].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
|
|
|
};
|
|
|
|
|
2012-06-02 16:05:45 +00:00
|
|
|
context = sWGLLib[libToUse].fCreateContextAttribs(dc,
|
2012-07-30 14:20:58 +00:00
|
|
|
shareContext ? shareContext->Context() : nullptr,
|
2011-12-03 07:50:11 +00:00
|
|
|
attribs);
|
|
|
|
if (!context && shareContext) {
|
2012-07-30 14:20:58 +00:00
|
|
|
context = sWGLLib[libToUse].fCreateContextAttribs(dc, nullptr, attribs);
|
2011-12-03 07:50:11 +00:00
|
|
|
if (context) {
|
2012-07-30 14:20:58 +00:00
|
|
|
shareContext = nullptr;
|
2011-12-03 07:50:11 +00:00
|
|
|
}
|
|
|
|
} else {
|
2012-06-02 16:05:45 +00:00
|
|
|
context = sWGLLib[libToUse].fCreateContext(dc);
|
|
|
|
if (context && shareContext && !sWGLLib[libToUse].fShareLists(shareContext->Context(), context)) {
|
2012-07-30 14:20:58 +00:00
|
|
|
shareContext = nullptr;
|
2011-12-03 07:50:11 +00:00
|
|
|
}
|
|
|
|
}
|
2011-12-16 21:12:02 +00:00
|
|
|
} else {
|
2012-06-02 16:05:45 +00:00
|
|
|
context = sWGLLib[libToUse].fCreateContext(dc);
|
2011-12-16 21:12:02 +00:00
|
|
|
if (context &&
|
|
|
|
shareContext &&
|
2012-06-02 16:05:45 +00:00
|
|
|
!sWGLLib[libToUse].fShareLists(shareContext->Context(), context))
|
2011-12-16 21:12:02 +00:00
|
|
|
{
|
2012-07-30 14:20:58 +00:00
|
|
|
shareContext = 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();
|
|
|
|
nsRefPtr<GLContextWGL> glContext = new GLContextWGL(caps,
|
|
|
|
shareContext,
|
|
|
|
false,
|
|
|
|
dc,
|
|
|
|
context,
|
|
|
|
libToUse);
|
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>
|
|
|
|
CreatePBufferOffscreenContext(const gfxIntSize& aSize,
|
2012-06-02 16:05:45 +00:00
|
|
|
LibType aLibToUse)
|
2010-04-27 02:09:44 +00:00
|
|
|
{
|
2013-02-13 23:26:24 +00:00
|
|
|
WGLLibrary& wgl = sWGLLib[aLibToUse];
|
|
|
|
|
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];
|
2013-02-13 23:26:24 +00:00
|
|
|
if (!IsValidSizeForFormat(windowDC, chosenFormat, aSize, aLibToUse))
|
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-02-13 23:26:24 +00:00
|
|
|
context = wgl.fCreateContextAttribs(pbdc, nullptr, attribs);
|
2011-12-03 07:50:11 +00:00
|
|
|
} else {
|
2013-02-13 23:26:24 +00:00
|
|
|
context = wgl.fCreateContext(pbdc);
|
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();
|
2013-02-13 23:26:24 +00:00
|
|
|
nsRefPtr<GLContextWGL> glContext = new GLContextWGL(dummyCaps,
|
|
|
|
nullptr, true,
|
2010-07-19 05:01:14 +00:00
|
|
|
pbuffer,
|
|
|
|
pbdc,
|
|
|
|
context,
|
2012-06-02 16:05:45 +00:00
|
|
|
chosenFormat,
|
|
|
|
aLibToUse);
|
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>
|
2013-09-04 12:14:52 +00:00
|
|
|
CreateWindowOffscreenContext(ContextFlags aFlags)
|
2010-07-19 05:01:14 +00:00
|
|
|
{
|
|
|
|
// CreateWindowOffscreenContext must return a global-shared context
|
2012-06-02 16:05:45 +00:00
|
|
|
GLContextWGL *shareContext = GetGlobalContextWGL(aFlags);
|
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
|
|
|
}
|
|
|
|
|
2012-06-02 16:05:45 +00:00
|
|
|
LibType libToUse = WGLLibrary::SelectLibrary(aFlags);
|
2010-07-19 05:01:14 +00:00
|
|
|
HDC dc;
|
2012-06-02 16:05:45 +00:00
|
|
|
HWND win = sWGLLib[libToUse].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
|
|
|
}
|
|
|
|
|
2012-06-02 16:05:45 +00:00
|
|
|
HGLRC context = sWGLLib[libToUse].fCreateContext(dc);
|
|
|
|
if (sWGLLib[libToUse].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
|
|
|
};
|
|
|
|
|
2012-06-02 16:05:45 +00:00
|
|
|
context = sWGLLib[libToUse].fCreateContextAttribs(dc, shareContext->Context(), attribs);
|
2011-12-03 07:50:11 +00:00
|
|
|
} else {
|
2012-06-02 16:05:45 +00:00
|
|
|
context = sWGLLib[libToUse].fCreateContext(dc);
|
2011-12-03 07:50:11 +00:00
|
|
|
if (context && shareContext &&
|
2012-06-02 16:05:45 +00:00
|
|
|
!sWGLLib[libToUse].fShareLists(shareContext->Context(), context))
|
2011-12-03 07:50:11 +00:00
|
|
|
{
|
|
|
|
NS_WARNING("wglShareLists failed!");
|
2010-07-19 05:01:14 +00:00
|
|
|
|
2012-06-02 16:05:45 +00:00
|
|
|
sWGLLib[libToUse].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();
|
|
|
|
nsRefPtr<GLContextWGL> glContext = new GLContextWGL(caps,
|
|
|
|
shareContext, true,
|
|
|
|
dc, context,
|
|
|
|
libToUse, win);
|
2010-07-19 05:01:14 +00:00
|
|
|
|
|
|
|
return glContext.forget();
|
|
|
|
}
|
|
|
|
|
|
|
|
already_AddRefed<GLContext>
|
2013-02-13 23:26:24 +00:00
|
|
|
GLContextProviderWGL::CreateOffscreen(const gfxIntSize& size,
|
|
|
|
const SurfaceCaps& caps,
|
|
|
|
ContextFlags flags)
|
2010-07-19 05:01:14 +00:00
|
|
|
{
|
2013-02-13 23:26:24 +00:00
|
|
|
LibType libToUse = WGLLibrary::SelectLibrary(flags);
|
2012-06-02 16:05:45 +00:00
|
|
|
|
|
|
|
if (!sWGLLib[libToUse].EnsureInitialized(libToUse == WGLLibrary::MESA_LLVMPIPE_LIB)) {
|
2012-07-30 14:20:58 +00:00
|
|
|
return nullptr;
|
2010-07-19 05:01:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
nsRefPtr<GLContextWGL> glContext;
|
|
|
|
|
|
|
|
// Always try to create a pbuffer context first, because we
|
|
|
|
// want the context isolation.
|
2013-02-13 23:26:24 +00:00
|
|
|
if (sWGLLib[libToUse].fCreatePbuffer &&
|
2012-06-02 16:05:45 +00:00
|
|
|
sWGLLib[libToUse].fChoosePixelFormat)
|
2010-07-19 05:01:14 +00:00
|
|
|
{
|
2013-02-13 23:26:24 +00:00
|
|
|
gfxIntSize dummySize = gfxIntSize(16, 16);
|
|
|
|
glContext = CreatePBufferOffscreenContext(dummySize, libToUse);
|
2010-07-19 05:01:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// If it failed, then create a window context and use a FBO.
|
|
|
|
if (!glContext) {
|
2013-02-13 23:26:24 +00:00
|
|
|
glContext = CreateWindowOffscreenContext(flags);
|
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
|
|
|
}
|
|
|
|
|
2013-02-13 23:26:24 +00:00
|
|
|
if (!glContext->InitOffscreen(size, caps))
|
2012-07-30 14:20:58 +00:00
|
|
|
return nullptr;
|
2011-10-19 19:09:57 +00:00
|
|
|
|
2010-07-19 05:01:14 +00:00
|
|
|
return glContext.forget();
|
2010-04-27 02:09:44 +00:00
|
|
|
}
|
|
|
|
|
2012-06-02 16:05:45 +00:00
|
|
|
static nsRefPtr<GLContextWGL> gGlobalContext[WGLLibrary::LIBS_MAX];
|
2010-07-19 05:01:14 +00:00
|
|
|
|
|
|
|
GLContext *
|
2013-02-13 23:26:24 +00:00
|
|
|
GLContextProviderWGL::GetGlobalContext(const ContextFlags flags)
|
2010-07-19 05:01:14 +00:00
|
|
|
{
|
2013-02-13 23:26:24 +00:00
|
|
|
LibType libToUse = WGLLibrary::SelectLibrary(flags);
|
2012-06-02 16:05:45 +00:00
|
|
|
|
|
|
|
if (!sWGLLib[libToUse].EnsureInitialized(libToUse == WGLLibrary::MESA_LLVMPIPE_LIB)) {
|
2012-07-30 14:20:58 +00:00
|
|
|
return nullptr;
|
2010-07-19 05:01:14 +00:00
|
|
|
}
|
|
|
|
|
2012-06-02 16:05:45 +00:00
|
|
|
static bool triedToCreateContext[WGLLibrary::LIBS_MAX] = {false, false};
|
2010-07-19 05:01:14 +00:00
|
|
|
|
2012-06-02 16:05:45 +00:00
|
|
|
if (!triedToCreateContext[libToUse] && !gGlobalContext[libToUse]) {
|
|
|
|
triedToCreateContext[libToUse] = 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();
|
|
|
|
gGlobalContext[libToUse] = new GLContextWGL(dummyCaps,
|
|
|
|
nullptr, true,
|
|
|
|
sWGLLib[libToUse].GetWindowDC(),
|
|
|
|
sWGLLib[libToUse].GetWindowGLContext(),
|
|
|
|
libToUse);
|
2012-06-02 16:05:45 +00:00
|
|
|
if (!gGlobalContext[libToUse]->Init()) {
|
2010-07-19 05:01:14 +00:00
|
|
|
NS_WARNING("Global context GLContext initialization failed?");
|
2012-07-30 14:20:58 +00:00
|
|
|
gGlobalContext[libToUse] = nullptr;
|
2012-10-04 08:31:56 +00:00
|
|
|
return nullptr;
|
2010-07-19 05:01:14 +00:00
|
|
|
}
|
2010-08-07 05:09:18 +00:00
|
|
|
|
2012-06-02 16:05:45 +00:00
|
|
|
gGlobalContext[libToUse]->SetIsGlobalSharedContext(true);
|
2010-07-19 05:01:14 +00:00
|
|
|
}
|
|
|
|
|
2012-06-02 16:05:45 +00:00
|
|
|
return static_cast<GLContext*>(gGlobalContext[libToUse]);
|
2010-07-19 05:01:14 +00:00
|
|
|
}
|
|
|
|
|
2010-07-20 04:05:42 +00:00
|
|
|
void
|
|
|
|
GLContextProviderWGL::Shutdown()
|
|
|
|
{
|
2012-06-02 16:05:45 +00:00
|
|
|
for (int i = 0; i < WGLLibrary::LIBS_MAX; ++i)
|
2012-07-30 14:20:58 +00:00
|
|
|
gGlobalContext[i] = nullptr;
|
2010-07-20 04:05:42 +00:00
|
|
|
}
|
|
|
|
|
2010-04-27 02:09:44 +00:00
|
|
|
} /* namespace gl */
|
|
|
|
} /* namespace mozilla */
|