2018-11-30 22:52:05 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
2012-05-21 15:12:37 +04: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 06:09:44 +04:00
|
|
|
|
|
|
|
#include "GLContextProvider.h"
|
2014-01-08 00:02:18 +04:00
|
|
|
#include "GLContextWGL.h"
|
2012-03-17 02:24:12 +04:00
|
|
|
#include "GLLibraryLoader.h"
|
2010-04-27 06:09:44 +04:00
|
|
|
#include "nsDebug.h"
|
|
|
|
#include "nsIWidget.h"
|
2010-07-01 20:30:38 +04:00
|
|
|
#include "gfxPlatform.h"
|
|
|
|
#include "gfxWindowsSurface.h"
|
2010-04-27 06:09:44 +04:00
|
|
|
|
2011-03-02 23:50:36 +03:00
|
|
|
#include "gfxCrashReporterUtils.h"
|
|
|
|
|
2010-09-21 23:41:24 +04:00
|
|
|
#include "prenv.h"
|
|
|
|
|
2016-11-15 01:13:40 +03:00
|
|
|
#include "mozilla/gfx/gfxVars.h"
|
2011-10-19 23:09:57 +04:00
|
|
|
#include "mozilla/Preferences.h"
|
2020-12-07 17:25:59 +03:00
|
|
|
#include "mozilla/ScopeExit.h"
|
2016-04-01 11:17:36 +03:00
|
|
|
#include "mozilla/StaticPtr.h"
|
2017-01-13 23:16:52 +03:00
|
|
|
#include "mozilla/layers/CompositorOptions.h"
|
2018-03-26 04:35:27 +03:00
|
|
|
#include "mozilla/webrender/RenderThread.h"
|
2016-07-25 21:41:00 +03:00
|
|
|
#include "mozilla/widget/CompositorWidget.h"
|
2017-01-17 01:14:45 +03:00
|
|
|
#include "mozilla/widget/WinCompositorWidget.h"
|
2011-10-19 23:09:57 +04:00
|
|
|
|
2010-04-27 06:09:44 +04:00
|
|
|
namespace mozilla {
|
|
|
|
namespace gl {
|
|
|
|
|
2014-05-22 14:11:45 +04:00
|
|
|
using namespace mozilla::gfx;
|
2016-07-25 21:41:00 +03:00
|
|
|
using namespace mozilla::widget;
|
2014-05-22 14:11:45 +04:00
|
|
|
|
2014-01-10 22:55:23 +04:00
|
|
|
WGLLibrary sWGLLib;
|
2010-09-21 23:41:24 +04:00
|
|
|
|
2018-01-03 05:30:15 +03:00
|
|
|
/*
|
|
|
|
ScopedWindow::~ScopedWindow()
|
|
|
|
{
|
|
|
|
if (mDC) {
|
|
|
|
MOZ_ALWAYS_TRUE( ReleaseDC(mDC) );
|
|
|
|
}
|
|
|
|
if (mWindow) {
|
|
|
|
MOZ_ALWAYS_TRUE( DestroyWindow(mWindow) );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
*/
|
|
|
|
static HWND CreateDummyWindow() {
|
|
|
|
WNDCLASSW wc{};
|
2013-07-20 12:48:55 +04:00
|
|
|
if (!GetClassInfoW(GetModuleHandle(nullptr), L"GLContextWGLClass", &wc)) {
|
2018-01-03 05:30:15 +03:00
|
|
|
wc = {};
|
2010-07-19 09:01:14 +04:00
|
|
|
wc.style = CS_OWNDC;
|
2013-07-20 12:48:55 +04:00
|
|
|
wc.hInstance = GetModuleHandle(nullptr);
|
2010-07-19 09:01:14 +04: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 12:48:55 +04:00
|
|
|
return nullptr;
|
2010-07-19 09:01:14 +04:00
|
|
|
}
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
2010-07-19 09:01:14 +04:00
|
|
|
|
2018-01-03 05:30:15 +03:00
|
|
|
return CreateWindowW(L"GLContextWGLClass", L"GLContextWGL", 0, 0, 0, 1, 1,
|
|
|
|
nullptr, nullptr, GetModuleHandle(nullptr), nullptr);
|
2010-07-19 09:01:14 +04:00
|
|
|
}
|
2010-05-18 08:04:22 +04:00
|
|
|
|
2011-12-03 11:50:11 +04:00
|
|
|
static inline bool HasExtension(const char* aExtensions,
|
|
|
|
const char* aRequiredExtension) {
|
|
|
|
return GLContext::ListHasExtension(
|
|
|
|
reinterpret_cast<const GLubyte*>(aExtensions), aRequiredExtension);
|
|
|
|
}
|
|
|
|
|
2019-02-23 00:17:28 +03:00
|
|
|
SymbolLoader WGLLibrary::GetSymbolLoader() const {
|
|
|
|
auto ret = SymbolLoader(*mOGLLibrary);
|
|
|
|
ret.mPfn = SymbolLoader::GetProcAddressT(mSymbols.fGetProcAddress);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2014-01-10 22:55:23 +04:00
|
|
|
bool WGLLibrary::EnsureInitialized() {
|
2010-05-18 08:04:22 +04:00
|
|
|
if (mInitialized) return true;
|
2014-03-04 06:47:43 +04:00
|
|
|
|
2014-01-10 22:55:23 +04:00
|
|
|
mozilla::ScopedGfxFeatureReporter reporter("WGL");
|
2010-05-18 08:04:22 +04:00
|
|
|
|
2018-02-24 19:33:57 +03:00
|
|
|
std::wstring libGLFilename = L"Opengl32.dll";
|
2013-12-18 22:09:10 +04:00
|
|
|
// SU_SPIES_DIRECTORY is for AMD CodeXL/gDEBugger
|
2018-02-24 19:33:57 +03:00
|
|
|
if (_wgetenv(L"SU_SPIES_DIRECTORY")) {
|
|
|
|
libGLFilename =
|
|
|
|
std::wstring(_wgetenv(L"SU_SPIES_DIRECTORY")) + L"\\opengl32.dll";
|
2013-12-18 22:09:10 +04:00
|
|
|
}
|
|
|
|
|
2010-05-18 08:04:22 +04:00
|
|
|
if (!mOGLLibrary) {
|
2018-02-24 19:33:57 +03:00
|
|
|
mOGLLibrary = LoadLibraryWithFlags(libGLFilename.c_str());
|
2010-05-18 08:04:22 +04:00
|
|
|
if (!mOGLLibrary) {
|
2012-06-02 20:05:45 +04:00
|
|
|
NS_WARNING("Couldn't load OpenGL library.");
|
2011-10-17 18:59:28 +04:00
|
|
|
return false;
|
2010-05-18 08:04:22 +04:00
|
|
|
}
|
2017-03-04 03:49:49 +03:00
|
|
|
}
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2019-02-23 00:17:28 +03:00
|
|
|
#define SYMBOL(X) \
|
|
|
|
{ \
|
|
|
|
(PRFuncPtr*)&mSymbols.f##X, { \
|
|
|
|
{ "wgl" #X } \
|
|
|
|
} \
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
2019-02-23 00:17:28 +03:00
|
|
|
#define END_OF_SYMBOLS {nullptr, {}}
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2019-02-23 00:17:28 +03:00
|
|
|
{
|
|
|
|
const auto loader = SymbolLoader(*mOGLLibrary);
|
|
|
|
const SymLoadStruct earlySymbols[] = {SYMBOL(CreateContext),
|
|
|
|
SYMBOL(MakeCurrent),
|
|
|
|
SYMBOL(GetProcAddress),
|
|
|
|
SYMBOL(DeleteContext),
|
|
|
|
SYMBOL(GetCurrentContext),
|
|
|
|
SYMBOL(GetCurrentDC),
|
|
|
|
END_OF_SYMBOLS};
|
|
|
|
|
|
|
|
if (!loader.LoadSymbols(earlySymbols)) {
|
|
|
|
NS_WARNING(
|
|
|
|
"Couldn't find required entry points in OpenGL DLL (early init)");
|
|
|
|
return false;
|
|
|
|
}
|
2010-05-18 08:04:22 +04:00
|
|
|
}
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2018-01-03 05:30:15 +03:00
|
|
|
mDummyWindow = CreateDummyWindow();
|
|
|
|
MOZ_ASSERT(mDummyWindow);
|
|
|
|
if (!mDummyWindow) return false;
|
|
|
|
auto cleanup = MakeScopeExit([&]() { Reset(); });
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2018-01-03 05:30:15 +03:00
|
|
|
mRootDc = GetDC(mDummyWindow);
|
|
|
|
MOZ_ASSERT(mRootDc);
|
|
|
|
if (!mRootDc) return false;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2018-01-03 05:30:15 +03:00
|
|
|
// --
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2018-01-03 05:30:15 +03:00
|
|
|
{
|
|
|
|
PIXELFORMATDESCRIPTOR pfd{};
|
|
|
|
pfd.nSize = sizeof(PIXELFORMATDESCRIPTOR);
|
|
|
|
pfd.nVersion = 1;
|
|
|
|
pfd.dwFlags = PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL;
|
|
|
|
// pfd.iPixelType = PFD_TYPE_RGBA;
|
|
|
|
// pfd.cColorBits = 24;
|
|
|
|
// pfd.cRedBits = 8;
|
|
|
|
// pfd.cGreenBits = 8;
|
|
|
|
// pfd.cBlueBits = 8;
|
|
|
|
// pfd.cAlphaBits = 8;
|
|
|
|
pfd.iLayerType = PFD_MAIN_PLANE;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2018-01-03 05:30:15 +03:00
|
|
|
const auto pixelFormat = ChoosePixelFormat(mRootDc, &pfd);
|
|
|
|
MOZ_ASSERT(pixelFormat);
|
|
|
|
if (!pixelFormat) return false;
|
|
|
|
const bool setPixelFormatOk = SetPixelFormat(mRootDc, pixelFormat, nullptr);
|
|
|
|
MOZ_ASSERT(setPixelFormatOk);
|
|
|
|
if (!setPixelFormatOk) return false;
|
|
|
|
}
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2018-01-03 05:30:15 +03:00
|
|
|
// --
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2010-05-18 08:04:22 +04:00
|
|
|
// create rendering context
|
2018-01-03 05:30:15 +03:00
|
|
|
mDummyGlrc = mSymbols.fCreateContext(mRootDc);
|
|
|
|
if (!mDummyGlrc) return false;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2018-01-03 05:30:15 +03:00
|
|
|
const auto curCtx = mSymbols.fGetCurrentContext();
|
|
|
|
const auto curDC = mSymbols.fGetCurrentDC();
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2018-01-03 05:30:15 +03:00
|
|
|
if (!mSymbols.fMakeCurrent(mRootDc, mDummyGlrc)) {
|
2010-05-18 08:04:22 +04:00
|
|
|
NS_WARNING("wglMakeCurrent failed");
|
2011-10-17 18:59:28 +04:00
|
|
|
return false;
|
2010-05-18 08:04:22 +04:00
|
|
|
}
|
2018-01-03 05:30:15 +03:00
|
|
|
const auto resetContext =
|
|
|
|
MakeScopeExit([&]() { mSymbols.fMakeCurrent(curDC, curCtx); });
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2019-02-23 00:17:28 +03:00
|
|
|
const auto loader = GetSymbolLoader();
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2010-05-18 08:04:22 +04:00
|
|
|
// Now we can grab all the other symbols that we couldn't without having
|
|
|
|
// a context current.
|
2018-01-03 05:30:15 +03:00
|
|
|
// clang-format off
|
2019-02-23 00:17:28 +03:00
|
|
|
const SymLoadStruct reqExtSymbols[] = {
|
|
|
|
{ (PRFuncPtr*)&mSymbols.fCreatePbuffer, {{ "wglCreatePbufferARB", "wglCreatePbufferEXT" }} },
|
|
|
|
{ (PRFuncPtr*)&mSymbols.fDestroyPbuffer, {{ "wglDestroyPbufferARB", "wglDestroyPbufferEXT" }} },
|
|
|
|
{ (PRFuncPtr*)&mSymbols.fGetPbufferDC, {{ "wglGetPbufferDCARB", "wglGetPbufferDCEXT" }} },
|
|
|
|
{ (PRFuncPtr*)&mSymbols.fReleasePbufferDC, {{ "wglReleasePbufferDCARB", "wglReleasePbufferDCEXT" }} },
|
|
|
|
// { (PRFuncPtr*)&mSymbols.fBindTexImage, {{ "wglBindTexImageARB", "wglBindTexImageEXT" }} },
|
|
|
|
// { (PRFuncPtr*)&mSymbols.fReleaseTexImage, {{ "wglReleaseTexImageARB", "wglReleaseTexImageEXT" }} },
|
|
|
|
{ (PRFuncPtr*)&mSymbols.fChoosePixelFormat, {{ "wglChoosePixelFormatARB", "wglChoosePixelFormatEXT" }} },
|
|
|
|
// { (PRFuncPtr*)&mSymbols.fGetPixelFormatAttribiv, {{ "wglGetPixelFormatAttribivARB", "wglGetPixelFormatAttribivEXT" }} },
|
2017-03-04 03:49:49 +03:00
|
|
|
SYMBOL(GetExtensionsStringARB),
|
|
|
|
END_OF_SYMBOLS
|
2011-12-03 11:50:11 +04:00
|
|
|
};
|
2012-05-21 15:12:37 +04:00
|
|
|
// clang-format on
|
2019-02-23 00:17:28 +03:00
|
|
|
if (!loader.LoadSymbols(reqExtSymbols)) {
|
2018-01-03 05:30:15 +03:00
|
|
|
NS_WARNING("reqExtSymbols missing");
|
|
|
|
return false;
|
|
|
|
}
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2018-01-03 05:30:15 +03:00
|
|
|
// --
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2018-01-03 05:30:15 +03:00
|
|
|
const auto extString = mSymbols.fGetExtensionsStringARB(mRootDc);
|
|
|
|
MOZ_ASSERT(extString);
|
|
|
|
MOZ_ASSERT(HasExtension(extString, "WGL_ARB_extensions_string"));
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2018-01-03 05:30:15 +03:00
|
|
|
// --
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2018-01-03 05:30:15 +03:00
|
|
|
if (HasExtension(extString, "WGL_ARB_create_context")) {
|
2019-02-23 00:17:28 +03:00
|
|
|
const SymLoadStruct createContextSymbols[] = {
|
2018-01-03 05:30:15 +03:00
|
|
|
SYMBOL(CreateContextAttribsARB), END_OF_SYMBOLS};
|
2019-02-23 00:17:28 +03:00
|
|
|
if (loader.LoadSymbols(createContextSymbols)) {
|
2018-01-03 05:30:15 +03:00
|
|
|
if (HasExtension(extString, "WGL_ARB_create_context_robustness")) {
|
|
|
|
mHasRobustness = true;
|
2015-11-06 03:19:24 +03:00
|
|
|
}
|
2018-01-03 05:30:15 +03:00
|
|
|
} else {
|
|
|
|
NS_ERROR(
|
|
|
|
"WGL_ARB_create_context announced without supplying its functions.");
|
|
|
|
ClearSymbols(createContextSymbols);
|
|
|
|
}
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// --
|
|
|
|
|
2018-01-03 05:30:15 +03:00
|
|
|
bool hasDXInterop2 = HasExtension(extString, "WGL_NV_DX_interop2");
|
2019-05-26 17:29:42 +03:00
|
|
|
if (gfxVars::DXInterop2Blocked() &&
|
2019-06-26 06:05:06 +03:00
|
|
|
!StaticPrefs::gl_ignore_dx_interop2_blacklist()) {
|
2018-01-03 05:30:15 +03:00
|
|
|
hasDXInterop2 = false;
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
|
|
|
|
2018-01-03 05:30:15 +03:00
|
|
|
if (hasDXInterop2) {
|
2019-02-23 00:17:28 +03:00
|
|
|
const SymLoadStruct dxInteropSymbols[] = {
|
2018-01-03 05:30:15 +03:00
|
|
|
SYMBOL(DXSetResourceShareHandleNV),
|
|
|
|
SYMBOL(DXOpenDeviceNV),
|
|
|
|
SYMBOL(DXCloseDeviceNV),
|
|
|
|
SYMBOL(DXRegisterObjectNV),
|
|
|
|
SYMBOL(DXUnregisterObjectNV),
|
|
|
|
SYMBOL(DXObjectAccessNV),
|
|
|
|
SYMBOL(DXLockObjectsNV),
|
|
|
|
SYMBOL(DXUnlockObjectsNV),
|
|
|
|
END_OF_SYMBOLS};
|
2019-02-23 00:17:28 +03:00
|
|
|
if (!loader.LoadSymbols(dxInteropSymbols)) {
|
2018-01-03 05:30:15 +03:00
|
|
|
NS_ERROR(
|
|
|
|
"WGL_NV_DX_interop2 announceed without supplying its functions.");
|
|
|
|
ClearSymbols(dxInteropSymbols);
|
2011-12-03 11:50:11 +04:00
|
|
|
}
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
2011-12-03 11:50:11 +04:00
|
|
|
|
2018-01-03 05:30:15 +03:00
|
|
|
// --
|
|
|
|
|
|
|
|
cleanup.release();
|
|
|
|
|
2011-10-17 18:59:28 +04:00
|
|
|
mInitialized = true;
|
2010-07-19 09:01:14 +04:00
|
|
|
|
2011-03-02 23:50:36 +03:00
|
|
|
reporter.SetSuccessful();
|
2011-10-17 18:59:28 +04:00
|
|
|
return true;
|
2010-05-18 08:04:22 +04:00
|
|
|
}
|
2010-04-27 06:09:44 +04:00
|
|
|
|
2017-03-04 03:49:49 +03:00
|
|
|
#undef SYMBOL
|
|
|
|
#undef END_OF_SYMBOLS
|
|
|
|
|
2018-01-03 05:30:15 +03:00
|
|
|
void WGLLibrary::Reset() {
|
|
|
|
if (mDummyGlrc) {
|
|
|
|
(void)mSymbols.fDeleteContext(mDummyGlrc);
|
|
|
|
mDummyGlrc = nullptr;
|
|
|
|
}
|
|
|
|
if (mRootDc) {
|
|
|
|
(void)ReleaseDC(mDummyWindow, mRootDc);
|
|
|
|
mRootDc = nullptr;
|
|
|
|
}
|
|
|
|
if (mDummyWindow) {
|
|
|
|
(void)DestroyWindow(mDummyWindow);
|
|
|
|
mDummyWindow = nullptr;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-06-15 21:25:55 +03:00
|
|
|
GLContextWGL::GLContextWGL(const GLContextDesc& desc, HDC aDC, HGLRC aContext,
|
2016-07-18 00:49:55 +03:00
|
|
|
HWND aWindow)
|
2020-06-15 21:25:55 +03:00
|
|
|
: GLContext(desc, nullptr, false),
|
2014-01-08 00:02:18 +04:00
|
|
|
mDC(aDC),
|
|
|
|
mContext(aContext),
|
|
|
|
mWnd(aWindow),
|
|
|
|
mPBuffer(nullptr),
|
2018-08-18 01:21:26 +03:00
|
|
|
mPixelFormat(0) {}
|
2010-05-18 08:04:22 +04:00
|
|
|
|
2020-06-15 21:25:55 +03:00
|
|
|
GLContextWGL::GLContextWGL(const GLContextDesc& desc, HANDLE aPbuffer, HDC aDC,
|
2016-07-18 00:49:55 +03:00
|
|
|
HGLRC aContext, int aPixelFormat)
|
2020-06-15 21:25:55 +03:00
|
|
|
: GLContext(desc, nullptr, false),
|
2014-01-08 00:02:18 +04:00
|
|
|
mDC(aDC),
|
|
|
|
mContext(aContext),
|
|
|
|
mWnd(nullptr),
|
|
|
|
mPBuffer(aPbuffer),
|
2018-08-18 01:21:26 +03:00
|
|
|
mPixelFormat(aPixelFormat) {}
|
2010-07-19 09:01:14 +04:00
|
|
|
|
2014-01-08 00:02:18 +04:00
|
|
|
GLContextWGL::~GLContextWGL() {
|
|
|
|
MarkDestroyed();
|
2018-10-26 19:30:48 +03:00
|
|
|
|
2018-01-03 05:30:15 +03:00
|
|
|
(void)sWGLLib.mSymbols.fDeleteContext(mContext);
|
2010-07-19 09:01:14 +04:00
|
|
|
|
2018-01-03 05:30:15 +03:00
|
|
|
if (mPBuffer) {
|
|
|
|
(void)sWGLLib.mSymbols.fReleasePbufferDC(mPBuffer, mDC);
|
|
|
|
(void)sWGLLib.mSymbols.fDestroyPbuffer(mPBuffer);
|
|
|
|
}
|
|
|
|
if (mWnd) {
|
|
|
|
(void)ReleaseDC(mWnd, mDC);
|
2014-01-08 00:02:18 +04:00
|
|
|
DestroyWindow(mWnd);
|
2018-01-03 05:30:15 +03:00
|
|
|
}
|
2014-01-08 00:02:18 +04:00
|
|
|
}
|
2013-12-18 22:09:11 +04:00
|
|
|
|
2017-08-15 23:21:37 +03:00
|
|
|
bool GLContextWGL::MakeCurrentImpl() const {
|
|
|
|
const bool succeeded = sWGLLib.mSymbols.fMakeCurrent(mDC, mContext);
|
|
|
|
NS_ASSERTION(succeeded, "Failed to make GL context current!");
|
2014-01-08 00:02:18 +04:00
|
|
|
return succeeded;
|
|
|
|
}
|
2010-09-10 00:40:29 +04:00
|
|
|
|
2017-08-11 23:54:40 +03:00
|
|
|
bool GLContextWGL::IsCurrentImpl() const {
|
2017-03-04 03:49:49 +03:00
|
|
|
return sWGLLib.mSymbols.fGetCurrentContext() == mContext;
|
2014-01-08 00:02:18 +04:00
|
|
|
}
|
2011-11-19 07:57:29 +04:00
|
|
|
|
2018-01-03 05:30:15 +03:00
|
|
|
bool GLContextWGL::SwapBuffers() {
|
2014-01-08 00:02:18 +04:00
|
|
|
if (!mIsDoubleBuffered) return false;
|
|
|
|
return ::SwapBuffers(mDC);
|
|
|
|
}
|
2010-05-18 08:04:22 +04:00
|
|
|
|
2017-01-31 05:58:52 +03:00
|
|
|
void GLContextWGL::GetWSIInfo(nsCString* const out) const {
|
|
|
|
out->AppendLiteral("wglGetExtensionsString: ");
|
2017-03-04 03:49:49 +03:00
|
|
|
out->Append(sWGLLib.mSymbols.fGetExtensionsStringARB(mDC));
|
2017-01-31 05:58:52 +03:00
|
|
|
}
|
|
|
|
|
2018-01-03 05:30:15 +03:00
|
|
|
HGLRC
|
|
|
|
WGLLibrary::CreateContextWithFallback(const HDC dc,
|
|
|
|
const bool tryRobustBuffers) const {
|
|
|
|
if (mHasRobustness) {
|
|
|
|
if (tryRobustBuffers) {
|
|
|
|
const int attribs[] = {LOCAL_WGL_CONTEXT_FLAGS_ARB,
|
|
|
|
LOCAL_WGL_CONTEXT_ROBUST_ACCESS_BIT_ARB,
|
|
|
|
LOCAL_WGL_CONTEXT_RESET_NOTIFICATION_STRATEGY_ARB,
|
|
|
|
LOCAL_WGL_LOSE_CONTEXT_ON_RESET_ARB, 0};
|
|
|
|
const auto context =
|
|
|
|
mSymbols.fCreateContextAttribsARB(dc, nullptr, attribs);
|
|
|
|
if (context) return context;
|
|
|
|
}
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2018-01-03 05:30:15 +03:00
|
|
|
const int attribs[] = {LOCAL_WGL_CONTEXT_RESET_NOTIFICATION_STRATEGY_ARB,
|
|
|
|
LOCAL_WGL_LOSE_CONTEXT_ON_RESET_ARB, 0};
|
|
|
|
const auto context =
|
|
|
|
mSymbols.fCreateContextAttribsARB(dc, nullptr, attribs);
|
|
|
|
if (context) return context;
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
2018-01-03 05:30:15 +03:00
|
|
|
if (mSymbols.fCreateContextAttribsARB) {
|
|
|
|
const auto context =
|
|
|
|
mSymbols.fCreateContextAttribsARB(dc, nullptr, nullptr);
|
|
|
|
if (context) return context;
|
|
|
|
}
|
|
|
|
return mSymbols.fCreateContext(dc);
|
2011-10-19 23:09:57 +04:00
|
|
|
}
|
|
|
|
|
2018-01-03 05:30:15 +03:00
|
|
|
static RefPtr<GLContext> CreateForWidget(const HWND window,
|
|
|
|
const bool isWebRender,
|
|
|
|
const bool requireAccelerated) {
|
|
|
|
auto& wgl = sWGLLib;
|
|
|
|
if (!wgl.EnsureInitialized()) return nullptr;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2018-01-03 05:30:15 +03:00
|
|
|
const auto dc = GetDC(window);
|
2012-07-30 18:20:58 +04:00
|
|
|
if (!dc) return nullptr;
|
2018-01-03 05:30:15 +03:00
|
|
|
auto cleanupDc = MakeScopeExit([&]() { (void)ReleaseDC(window, dc); });
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2018-01-03 05:30:15 +03:00
|
|
|
int chosenFormat;
|
|
|
|
UINT foundFormats = 0;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2018-01-03 05:30:15 +03:00
|
|
|
if (!foundFormats) {
|
|
|
|
const int kAttribs[] = {LOCAL_WGL_DRAW_TO_WINDOW_ARB,
|
|
|
|
true,
|
|
|
|
LOCAL_WGL_SUPPORT_OPENGL_ARB,
|
|
|
|
true,
|
|
|
|
LOCAL_WGL_DOUBLE_BUFFER_ARB,
|
|
|
|
true,
|
|
|
|
LOCAL_WGL_ACCELERATION_ARB,
|
|
|
|
LOCAL_WGL_FULL_ACCELERATION_ARB,
|
|
|
|
0};
|
2018-03-26 04:35:27 +03:00
|
|
|
const int kAttribsForWebRender[] = {LOCAL_WGL_DRAW_TO_WINDOW_ARB,
|
|
|
|
true,
|
|
|
|
LOCAL_WGL_SUPPORT_OPENGL_ARB,
|
|
|
|
true,
|
|
|
|
LOCAL_WGL_DOUBLE_BUFFER_ARB,
|
|
|
|
true,
|
|
|
|
LOCAL_WGL_DEPTH_BITS_ARB,
|
|
|
|
24,
|
|
|
|
LOCAL_WGL_ACCELERATION_ARB,
|
|
|
|
LOCAL_WGL_FULL_ACCELERATION_ARB,
|
2018-11-30 13:46:48 +03:00
|
|
|
0};
|
2018-03-26 04:35:27 +03:00
|
|
|
const int* attribs;
|
|
|
|
if (wr::RenderThread::IsInRenderThread()) {
|
|
|
|
attribs = kAttribsForWebRender;
|
2018-11-30 13:46:48 +03:00
|
|
|
} else {
|
2018-03-26 04:35:27 +03:00
|
|
|
attribs = kAttribs;
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
|
|
|
|
2018-03-26 04:35:27 +03:00
|
|
|
if (!wgl.mSymbols.fChoosePixelFormat(wgl.RootDc(), attribs, nullptr, 1,
|
2018-01-03 05:30:15 +03:00
|
|
|
&chosenFormat, &foundFormats)) {
|
|
|
|
foundFormats = 0;
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
|
|
|
}
|
2018-01-03 05:30:15 +03:00
|
|
|
if (!foundFormats) {
|
2018-03-26 04:35:27 +03:00
|
|
|
if (requireAccelerated) return nullptr;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2018-01-03 05:30:15 +03:00
|
|
|
const int kAttribs[] = {LOCAL_WGL_DRAW_TO_WINDOW_ARB,
|
2018-11-30 13:46:48 +03:00
|
|
|
true,
|
2018-03-26 04:35:27 +03:00
|
|
|
LOCAL_WGL_SUPPORT_OPENGL_ARB,
|
2018-11-30 13:46:48 +03:00
|
|
|
true,
|
2018-01-03 05:30:15 +03:00
|
|
|
LOCAL_WGL_DOUBLE_BUFFER_ARB,
|
2018-11-30 13:46:48 +03:00
|
|
|
true,
|
|
|
|
0};
|
2018-03-26 04:35:27 +03:00
|
|
|
const int kAttribsForWebRender[] = {LOCAL_WGL_DRAW_TO_WINDOW_ARB,
|
2018-11-30 13:46:48 +03:00
|
|
|
true,
|
2018-01-03 05:30:15 +03:00
|
|
|
LOCAL_WGL_SUPPORT_OPENGL_ARB,
|
2018-11-30 13:46:48 +03:00
|
|
|
true,
|
2018-01-03 05:30:15 +03:00
|
|
|
LOCAL_WGL_DOUBLE_BUFFER_ARB,
|
2018-11-30 13:46:48 +03:00
|
|
|
true,
|
2018-03-26 04:35:27 +03:00
|
|
|
LOCAL_WGL_DEPTH_BITS_ARB,
|
2018-11-30 13:46:48 +03:00
|
|
|
24,
|
2018-03-26 04:35:27 +03:00
|
|
|
0};
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2018-03-26 04:35:27 +03:00
|
|
|
const int* attribs;
|
|
|
|
if (wr::RenderThread::IsInRenderThread()) {
|
|
|
|
attribs = kAttribsForWebRender;
|
|
|
|
} else {
|
|
|
|
attribs = kAttribs;
|
2010-04-27 06:09:44 +04:00
|
|
|
}
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2018-03-26 04:35:27 +03:00
|
|
|
if (!wgl.mSymbols.fChoosePixelFormat(wgl.RootDc(), attribs, nullptr, 1,
|
2018-01-03 05:30:15 +03:00
|
|
|
&chosenFormat, &foundFormats)) {
|
|
|
|
foundFormats = 0;
|
2011-12-03 11:50:11 +04:00
|
|
|
}
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
2018-01-03 05:30:15 +03:00
|
|
|
if (!foundFormats) return nullptr;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2018-01-03 05:30:15 +03:00
|
|
|
// We need to make sure we call SetPixelFormat -after- calling
|
|
|
|
// EnsureInitialized, otherwise it can load/unload the dll and
|
|
|
|
// wglCreateContext will fail.
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2018-01-03 05:30:15 +03:00
|
|
|
SetPixelFormat(dc, chosenFormat, nullptr);
|
|
|
|
const auto context = sWGLLib.CreateContextWithFallback(dc, false);
|
2012-07-30 18:20:58 +04:00
|
|
|
if (!context) return nullptr;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2020-06-15 21:25:55 +03:00
|
|
|
const RefPtr<GLContextWGL> gl = new GLContextWGL({}, dc, context);
|
2018-01-03 05:30:15 +03:00
|
|
|
cleanupDc.release();
|
|
|
|
gl->mIsDoubleBuffered = true;
|
|
|
|
if (!gl->Init()) return nullptr;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2018-01-03 05:30:15 +03:00
|
|
|
return gl;
|
2010-04-27 06:09:44 +04:00
|
|
|
}
|
|
|
|
|
2017-01-17 01:14:45 +03:00
|
|
|
already_AddRefed<GLContext> GLContextProviderWGL::CreateForCompositorWidget(
|
2021-04-07 10:04:43 +03:00
|
|
|
CompositorWidget* aCompositorWidget, bool aHardwareWebRender,
|
2019-03-13 03:17:01 +03:00
|
|
|
bool aForceAccelerated) {
|
|
|
|
if (!aCompositorWidget) {
|
|
|
|
MOZ_ASSERT(false);
|
|
|
|
return nullptr;
|
|
|
|
}
|
2021-04-07 10:04:43 +03:00
|
|
|
return CreateForWidget(aCompositorWidget->AsWindows()->GetHwnd(),
|
|
|
|
aHardwareWebRender, aForceAccelerated)
|
2018-01-03 05:30:15 +03:00
|
|
|
.forget();
|
2017-01-17 01:14:45 +03:00
|
|
|
}
|
|
|
|
|
2019-02-26 01:07:19 +03:00
|
|
|
/*static*/
|
|
|
|
already_AddRefed<GLContext> GLContextProviderWGL::CreateHeadless(
|
2020-06-15 21:25:55 +03:00
|
|
|
const GLContextCreateDesc& desc, nsACString* const out_failureId) {
|
2018-01-03 05:30:15 +03:00
|
|
|
auto& wgl = sWGLLib;
|
|
|
|
if (!wgl.EnsureInitialized()) return nullptr;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2018-01-03 05:30:15 +03:00
|
|
|
int chosenFormat;
|
|
|
|
UINT foundFormats = 0;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2018-01-03 05:30:15 +03:00
|
|
|
if (!foundFormats) {
|
|
|
|
const int kAttribs[] = {LOCAL_WGL_DRAW_TO_PBUFFER_ARB,
|
|
|
|
true,
|
|
|
|
LOCAL_WGL_SUPPORT_OPENGL_ARB,
|
2018-11-30 13:46:48 +03:00
|
|
|
true,
|
2018-01-03 05:30:15 +03:00
|
|
|
LOCAL_WGL_ACCELERATION_ARB,
|
|
|
|
LOCAL_WGL_FULL_ACCELERATION_ARB,
|
2011-12-03 11:50:11 +04:00
|
|
|
0};
|
2018-01-03 05:30:15 +03:00
|
|
|
if (!wgl.mSymbols.fChoosePixelFormat(wgl.RootDc(), kAttribs, nullptr, 1,
|
|
|
|
&chosenFormat, &foundFormats)) {
|
|
|
|
foundFormats = 0;
|
2010-07-19 09:01:14 +04:00
|
|
|
}
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
2018-01-03 05:30:15 +03:00
|
|
|
if (!foundFormats) {
|
|
|
|
const int kAttribs[] = {LOCAL_WGL_DRAW_TO_PBUFFER_ARB, true,
|
|
|
|
LOCAL_WGL_SUPPORT_OPENGL_ARB, true, 0};
|
|
|
|
if (!wgl.mSymbols.fChoosePixelFormat(wgl.RootDc(), kAttribs, nullptr, 1,
|
|
|
|
&chosenFormat, &foundFormats)) {
|
|
|
|
foundFormats = 0;
|
2011-12-03 11:50:11 +04:00
|
|
|
}
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
2018-01-03 05:30:15 +03:00
|
|
|
if (!foundFormats) return nullptr;
|
|
|
|
const int kPbufferAttribs[] = {0};
|
|
|
|
const auto pbuffer = wgl.mSymbols.fCreatePbuffer(wgl.RootDc(), chosenFormat,
|
|
|
|
1, 1, kPbufferAttribs);
|
2012-07-30 18:20:58 +04:00
|
|
|
if (!pbuffer) return nullptr;
|
2018-01-03 05:30:15 +03:00
|
|
|
auto cleanupPbuffer =
|
|
|
|
MakeScopeExit([&]() { (void)wgl.mSymbols.fDestroyPbuffer(pbuffer); });
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2018-01-03 05:30:15 +03:00
|
|
|
const auto dc = wgl.mSymbols.fGetPbufferDC(pbuffer);
|
|
|
|
if (!dc) return nullptr;
|
|
|
|
auto cleanupDc = MakeScopeExit(
|
|
|
|
[&]() { (void)wgl.mSymbols.fReleasePbufferDC(pbuffer, dc); });
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2018-01-03 05:30:15 +03:00
|
|
|
const auto context = wgl.CreateContextWithFallback(dc, true);
|
|
|
|
if (!context) return nullptr;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2020-06-15 21:25:55 +03:00
|
|
|
const auto fullDesc = GLContextDesc{desc, true};
|
2018-01-03 05:30:15 +03:00
|
|
|
const RefPtr<GLContextWGL> gl =
|
2020-06-15 21:25:55 +03:00
|
|
|
new GLContextWGL(fullDesc, pbuffer, dc, context, chosenFormat);
|
2018-01-03 05:30:15 +03:00
|
|
|
cleanupPbuffer.release();
|
|
|
|
cleanupDc.release();
|
|
|
|
if (!gl->Init()) return nullptr;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2018-01-03 05:30:15 +03:00
|
|
|
return RefPtr<GLContext>(gl.get()).forget();
|
2014-08-28 03:16:22 +04:00
|
|
|
}
|
|
|
|
|
2019-02-26 01:07:19 +03:00
|
|
|
/*static*/
|
|
|
|
GLContext* GLContextProviderWGL::GetGlobalContext() { return nullptr; }
|
2010-07-19 09:01:14 +04:00
|
|
|
|
2019-02-26 01:07:19 +03:00
|
|
|
/*static*/
|
|
|
|
void GLContextProviderWGL::Shutdown() {}
|
2010-07-20 08:05:42 +04:00
|
|
|
|
2010-04-27 06:09:44 +04:00
|
|
|
} /* namespace gl */
|
|
|
|
} /* namespace mozilla */
|