зеркало из https://github.com/mozilla/gecko-dev.git
Bug 950903 - 4/8 - Expose GLContextWGL publicly - r=jgilbert
This commit is contained in:
Родитель
46c30d835d
Коммит
98ca33fe7f
|
@ -4,11 +4,10 @@
|
|||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
#include "GLContextProvider.h"
|
||||
#include "GLContext.h"
|
||||
#include "GLContextWGL.h"
|
||||
#include "GLLibraryLoader.h"
|
||||
#include "nsDebug.h"
|
||||
#include "nsIWidget.h"
|
||||
#include "WGLLibrary.h"
|
||||
#include "gfxASurface.h"
|
||||
#include "gfxImageSurface.h"
|
||||
#include "gfxPlatform.h"
|
||||
|
@ -25,8 +24,6 @@ using namespace mozilla::gfx;
|
|||
namespace mozilla {
|
||||
namespace gl {
|
||||
|
||||
typedef WGLLibrary::LibraryType LibType;
|
||||
|
||||
WGLLibrary sWGLLib[WGLLibrary::LIBS_MAX];
|
||||
|
||||
LibType
|
||||
|
@ -253,161 +250,153 @@ WGLLibrary::EnsureInitialized(bool aUseMesaLlvmPipe)
|
|||
return true;
|
||||
}
|
||||
|
||||
class GLContextWGL : public GLContext
|
||||
GLContextWGL::GLContextWGL(
|
||||
const SurfaceCaps& caps,
|
||||
GLContext* sharedContext,
|
||||
bool isOffscreen,
|
||||
HDC aDC,
|
||||
HGLRC aContext,
|
||||
LibType aLibUsed,
|
||||
HWND aWindow)
|
||||
: GLContext(caps, sharedContext, isOffscreen),
|
||||
mDC(aDC),
|
||||
mContext(aContext),
|
||||
mWnd(aWindow),
|
||||
mPBuffer(nullptr),
|
||||
mPixelFormat(0),
|
||||
mLibType(aLibUsed),
|
||||
mIsDoubleBuffered(false)
|
||||
{
|
||||
public:
|
||||
// From Window: (possibly for offscreen!)
|
||||
GLContextWGL(const SurfaceCaps& caps,
|
||||
GLContext* sharedContext,
|
||||
bool isOffscreen,
|
||||
HDC aDC,
|
||||
HGLRC aContext,
|
||||
LibType aLibUsed,
|
||||
HWND aWindow = nullptr)
|
||||
: GLContext(caps, sharedContext, isOffscreen),
|
||||
mDC(aDC),
|
||||
mContext(aContext),
|
||||
mWnd(aWindow),
|
||||
mPBuffer(nullptr),
|
||||
mPixelFormat(0),
|
||||
mLibType(aLibUsed),
|
||||
mIsDoubleBuffered(false)
|
||||
{
|
||||
// See 899855
|
||||
SetProfileVersion(ContextProfile::OpenGLCompatibility, 200);
|
||||
// See 899855
|
||||
SetProfileVersion(ContextProfile::OpenGLCompatibility, 200);
|
||||
}
|
||||
|
||||
GLContextWGL::GLContextWGL(
|
||||
const SurfaceCaps& caps,
|
||||
GLContext* sharedContext,
|
||||
bool isOffscreen,
|
||||
HANDLE aPbuffer,
|
||||
HDC aDC,
|
||||
HGLRC aContext,
|
||||
int aPixelFormat,
|
||||
LibType aLibUsed)
|
||||
: GLContext(caps, sharedContext, isOffscreen),
|
||||
mDC(aDC),
|
||||
mContext(aContext),
|
||||
mWnd(nullptr),
|
||||
mPBuffer(aPbuffer),
|
||||
mPixelFormat(aPixelFormat),
|
||||
mLibType(aLibUsed),
|
||||
mIsDoubleBuffered(false)
|
||||
{
|
||||
// See 899855
|
||||
SetProfileVersion(ContextProfile::OpenGLCompatibility, 200);
|
||||
}
|
||||
|
||||
GLContextWGL::~GLContextWGL()
|
||||
{
|
||||
MarkDestroyed();
|
||||
|
||||
sWGLLib[mLibType].fDeleteContext(mContext);
|
||||
|
||||
if (mPBuffer)
|
||||
sWGLLib[mLibType].fDestroyPbuffer(mPBuffer);
|
||||
if (mWnd)
|
||||
DestroyWindow(mWnd);
|
||||
}
|
||||
|
||||
GLContextType
|
||||
GLContextWGL::GetContextType() {
|
||||
return ContextTypeWGL;
|
||||
}
|
||||
|
||||
bool
|
||||
GLContextWGL::Init()
|
||||
{
|
||||
if (!mDC || !mContext)
|
||||
return false;
|
||||
|
||||
// see bug 929506 comment 29. wglGetProcAddress requires a current context.
|
||||
if (!sWGLLib[mLibType].fMakeCurrent(mDC, mContext))
|
||||
return false;
|
||||
|
||||
SetupLookupFunction();
|
||||
if (!InitWithPrefix("gl", true))
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
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..
|
||||
if (aForce || sWGLLib[mLibType].fGetCurrentContext() != mContext) {
|
||||
succeeded = sWGLLib[mLibType].fMakeCurrent(mDC, mContext);
|
||||
NS_ASSERTION(succeeded, "Failed to make GL context current!");
|
||||
}
|
||||
|
||||
// From PBuffer
|
||||
GLContextWGL(const SurfaceCaps& caps,
|
||||
GLContext* sharedContext,
|
||||
bool isOffscreen,
|
||||
HANDLE aPbuffer,
|
||||
HDC aDC,
|
||||
HGLRC aContext,
|
||||
int aPixelFormat,
|
||||
LibType aLibUsed)
|
||||
: GLContext(caps, sharedContext, isOffscreen),
|
||||
mDC(aDC),
|
||||
mContext(aContext),
|
||||
mWnd(nullptr),
|
||||
mPBuffer(aPbuffer),
|
||||
mPixelFormat(aPixelFormat),
|
||||
mLibType(aLibUsed),
|
||||
mIsDoubleBuffered(false)
|
||||
{
|
||||
// See 899855
|
||||
SetProfileVersion(ContextProfile::OpenGLCompatibility, 200);
|
||||
return succeeded;
|
||||
}
|
||||
|
||||
bool
|
||||
GLContextWGL::IsCurrent() {
|
||||
return sWGLLib[mLibType].fGetCurrentContext() == mContext;
|
||||
}
|
||||
|
||||
void
|
||||
GLContextWGL::SetIsDoubleBuffered(bool aIsDB) {
|
||||
mIsDoubleBuffered = aIsDB;
|
||||
}
|
||||
|
||||
bool
|
||||
GLContextWGL::IsDoubleBuffered() {
|
||||
return mIsDoubleBuffered;
|
||||
}
|
||||
|
||||
bool
|
||||
GLContextWGL::SupportsRobustness()
|
||||
{
|
||||
return sWGLLib[mLibType].HasRobustness();
|
||||
}
|
||||
|
||||
bool
|
||||
GLContextWGL::SwapBuffers() {
|
||||
if (!mIsDoubleBuffered)
|
||||
return false;
|
||||
return ::SwapBuffers(mDC);
|
||||
}
|
||||
|
||||
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);
|
||||
|
||||
mLibrary = sWGLLib[mLibType].GetOGLLibrary();
|
||||
mLookupFunc = (PlatformLookupFunction)sWGLLib[mLibType].fGetProcAddress;
|
||||
return true;
|
||||
}
|
||||
|
||||
void*
|
||||
GLContextWGL::GetNativeData(NativeDataType aType)
|
||||
{
|
||||
switch (aType) {
|
||||
case NativeGLContext:
|
||||
return mContext;
|
||||
|
||||
default:
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
~GLContextWGL()
|
||||
{
|
||||
MarkDestroyed();
|
||||
|
||||
sWGLLib[mLibType].fDeleteContext(mContext);
|
||||
|
||||
if (mPBuffer)
|
||||
sWGLLib[mLibType].fDestroyPbuffer(mPBuffer);
|
||||
if (mWnd)
|
||||
DestroyWindow(mWnd);
|
||||
}
|
||||
|
||||
GLContextType GetContextType() {
|
||||
return ContextTypeWGL;
|
||||
}
|
||||
|
||||
bool Init()
|
||||
{
|
||||
if (!mDC || !mContext)
|
||||
return false;
|
||||
|
||||
// see bug 929506 comment 29. wglGetProcAddress requires a current context.
|
||||
if (!sWGLLib[mLibType].fMakeCurrent(mDC, mContext))
|
||||
return false;
|
||||
|
||||
SetupLookupFunction();
|
||||
if (!InitWithPrefix("gl", true))
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool MakeCurrentImpl(bool aForce = false)
|
||||
{
|
||||
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..
|
||||
if (aForce || sWGLLib[mLibType].fGetCurrentContext() != mContext) {
|
||||
succeeded = sWGLLib[mLibType].fMakeCurrent(mDC, mContext);
|
||||
NS_ASSERTION(succeeded, "Failed to make GL context current!");
|
||||
}
|
||||
|
||||
return succeeded;
|
||||
}
|
||||
|
||||
virtual bool IsCurrent() {
|
||||
return sWGLLib[mLibType].fGetCurrentContext() == mContext;
|
||||
}
|
||||
|
||||
void SetIsDoubleBuffered(bool aIsDB) {
|
||||
mIsDoubleBuffered = aIsDB;
|
||||
}
|
||||
|
||||
virtual bool IsDoubleBuffered() {
|
||||
return mIsDoubleBuffered;
|
||||
}
|
||||
|
||||
bool SupportsRobustness()
|
||||
{
|
||||
return sWGLLib[mLibType].HasRobustness();
|
||||
}
|
||||
|
||||
virtual bool SwapBuffers() {
|
||||
if (!mIsDoubleBuffered)
|
||||
return false;
|
||||
return ::SwapBuffers(mDC);
|
||||
}
|
||||
|
||||
bool 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);
|
||||
|
||||
mLibrary = sWGLLib[mLibType].GetOGLLibrary();
|
||||
mLookupFunc = (PlatformLookupFunction)sWGLLib[mLibType].fGetProcAddress;
|
||||
return true;
|
||||
}
|
||||
|
||||
void *GetNativeData(NativeDataType aType)
|
||||
{
|
||||
switch (aType) {
|
||||
case NativeGLContext:
|
||||
return mContext;
|
||||
|
||||
default:
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
bool ResizeOffscreen(const gfx::IntSize& aNewSize);
|
||||
|
||||
HGLRC Context() { return mContext; }
|
||||
|
||||
protected:
|
||||
friend class GLContextProviderWGL;
|
||||
|
||||
HDC mDC;
|
||||
HGLRC mContext;
|
||||
HWND mWnd;
|
||||
HANDLE mPBuffer;
|
||||
int mPixelFormat;
|
||||
LibType mLibType;
|
||||
bool mIsDoubleBuffered;
|
||||
};
|
||||
|
||||
|
||||
static bool
|
||||
|
|
|
@ -0,0 +1,81 @@
|
|||
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
||||
/* vim: set ts=8 sts=4 et sw=4 tw=80: */
|
||||
/* 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/. */
|
||||
|
||||
#ifndef GLCONTEXTWGL_H_
|
||||
#define GLCONTEXTWGL_H_
|
||||
|
||||
#include "GLContext.h"
|
||||
#include "WGLLibrary.h"
|
||||
|
||||
namespace mozilla {
|
||||
namespace gl {
|
||||
|
||||
typedef WGLLibrary::LibraryType LibType;
|
||||
|
||||
class GLContextWGL : public GLContext
|
||||
{
|
||||
public:
|
||||
// From Window: (possibly for offscreen!)
|
||||
GLContextWGL(const SurfaceCaps& caps,
|
||||
GLContext* sharedContext,
|
||||
bool isOffscreen,
|
||||
HDC aDC,
|
||||
HGLRC aContext,
|
||||
LibType aLibUsed,
|
||||
HWND aWindow = nullptr);
|
||||
|
||||
// From PBuffer
|
||||
GLContextWGL(const SurfaceCaps& caps,
|
||||
GLContext* sharedContext,
|
||||
bool isOffscreen,
|
||||
HANDLE aPbuffer,
|
||||
HDC aDC,
|
||||
HGLRC aContext,
|
||||
int aPixelFormat,
|
||||
LibType aLibUsed);
|
||||
|
||||
~GLContextWGL();
|
||||
|
||||
GLContextType GetContextType();
|
||||
|
||||
bool Init();
|
||||
|
||||
bool MakeCurrentImpl(bool aForce = false);
|
||||
|
||||
virtual bool IsCurrent();
|
||||
|
||||
void SetIsDoubleBuffered(bool aIsDB);
|
||||
|
||||
virtual bool IsDoubleBuffered();
|
||||
|
||||
bool SupportsRobustness();
|
||||
|
||||
virtual bool SwapBuffers();
|
||||
|
||||
bool SetupLookupFunction();
|
||||
|
||||
void *GetNativeData(NativeDataType aType);
|
||||
|
||||
bool ResizeOffscreen(const gfx::IntSize& aNewSize);
|
||||
|
||||
HGLRC Context() { return mContext; }
|
||||
|
||||
protected:
|
||||
friend class GLContextProviderWGL;
|
||||
|
||||
HDC mDC;
|
||||
HGLRC mContext;
|
||||
HWND mWnd;
|
||||
HANDLE mPBuffer;
|
||||
int mPixelFormat;
|
||||
LibType mLibType;
|
||||
bool mIsDoubleBuffered;
|
||||
};
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
#endif // GLCONTEXTWGL_H_
|
|
@ -4,6 +4,8 @@
|
|||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
#include "GLContextTypes.h"
|
||||
#include <windows.h>
|
||||
|
||||
struct PRLibrary;
|
||||
|
||||
namespace mozilla {
|
||||
|
|
|
@ -66,6 +66,7 @@ if CONFIG['MOZ_X11']:
|
|||
# Win32 is a special snowflake, for ANGLE
|
||||
if CONFIG['MOZ_WIDGET_TOOLKIT'] == 'windows':
|
||||
EXPORTS += [
|
||||
'GLContextWGL.h',
|
||||
'SharedSurfaceANGLE.h',
|
||||
'WGLLibrary.h',
|
||||
]
|
||||
|
|
Загрузка…
Ссылка в новой задаче