Commit 582173d9 by Corentin Wallez

FunctionsGLX: make most functions take the display implicitly

In later CLs FunctionsGLX will need to store the X display so we take advantage of it to reduce the verbosity of the other GLX files slightly. BUG=angleproject:892 Change-Id: I42ea00d0a37055e5e0752a860978b8ef5afb7a0b Reviewed-on: https://chromium-review.googlesource.com/271163Reviewed-by: 's avatarJamie Madill <jmadill@chromium.org> Tested-by: 's avatarCorentin Wallez <cwallez@chromium.org>
parent b8e3a568
...@@ -49,8 +49,7 @@ DisplayGLX::DisplayGLX() ...@@ -49,8 +49,7 @@ DisplayGLX::DisplayGLX()
mFunctionsGL(nullptr), mFunctionsGL(nullptr),
mContext(nullptr), mContext(nullptr),
mDummyPbuffer(0), mDummyPbuffer(0),
mEGLDisplay(nullptr), mEGLDisplay(nullptr)
mXDisplay(nullptr)
{ {
} }
...@@ -61,21 +60,21 @@ DisplayGLX::~DisplayGLX() ...@@ -61,21 +60,21 @@ DisplayGLX::~DisplayGLX()
egl::Error DisplayGLX::initialize(egl::Display *display) egl::Error DisplayGLX::initialize(egl::Display *display)
{ {
mEGLDisplay = display; mEGLDisplay = display;
mXDisplay = display->getNativeDisplayId(); Display *xDisplay = display->getNativeDisplayId();
// ANGLE_platform_angle allows the creation of a default display // ANGLE_platform_angle allows the creation of a default display
// using EGL_DEFAULT_DISPLAY (= nullptr). In this case just open // using EGL_DEFAULT_DISPLAY (= nullptr). In this case just open
// the display specified by the DISPLAY environment variable. // the display specified by the DISPLAY environment variable.
if (mXDisplay == EGL_DEFAULT_DISPLAY) if (xDisplay == EGL_DEFAULT_DISPLAY)
{ {
mXDisplay = XOpenDisplay(NULL); xDisplay = XOpenDisplay(NULL);
if (!mXDisplay) if (!xDisplay)
{ {
return egl::Error(EGL_NOT_INITIALIZED, "Could not open the default X display."); return egl::Error(EGL_NOT_INITIALIZED, "Could not open the default X display.");
} }
} }
egl::Error glxInitResult = mGLX.initialize(mXDisplay); egl::Error glxInitResult = mGLX.initialize(xDisplay, DefaultScreen(xDisplay));
if (glxInitResult.isError()) if (glxInitResult.isError())
{ {
return glxInitResult; return glxInitResult;
...@@ -124,7 +123,7 @@ egl::Error DisplayGLX::initialize(egl::Display *display) ...@@ -124,7 +123,7 @@ egl::Error DisplayGLX::initialize(egl::Display *display)
GLX_CONFIG_CAVEAT, GLX_NONE, GLX_CONFIG_CAVEAT, GLX_NONE,
None None
}; };
GLXFBConfig* candidates = mGLX.chooseFBConfig(mXDisplay, DefaultScreen(mXDisplay), attribList, &nConfigs); GLXFBConfig* candidates = mGLX.chooseFBConfig(attribList, &nConfigs);
if (nConfigs == 0) if (nConfigs == 0)
{ {
XFree(candidates); XFree(candidates);
...@@ -135,7 +134,7 @@ egl::Error DisplayGLX::initialize(egl::Display *display) ...@@ -135,7 +134,7 @@ egl::Error DisplayGLX::initialize(egl::Display *display)
} }
mContextVisualId = getGLXFBConfigAttrib(contextConfig, GLX_VISUAL_ID); mContextVisualId = getGLXFBConfigAttrib(contextConfig, GLX_VISUAL_ID);
mContext = mGLX.createContextAttribsARB(mXDisplay, contextConfig, nullptr, True, nullptr); mContext = mGLX.createContextAttribsARB(contextConfig, nullptr, True, nullptr);
if (!mContext) if (!mContext)
{ {
return egl::Error(EGL_NOT_INITIALIZED, "Could not create GL context."); return egl::Error(EGL_NOT_INITIALIZED, "Could not create GL context.");
...@@ -150,8 +149,8 @@ egl::Error DisplayGLX::initialize(egl::Display *display) ...@@ -150,8 +149,8 @@ egl::Error DisplayGLX::initialize(egl::Display *display)
// TODO(cwallez) during the initialization of ANGLE we need a gl context current // TODO(cwallez) during the initialization of ANGLE we need a gl context current
// to query things like limits. Ideally we would want to unset the current context // to query things like limits. Ideally we would want to unset the current context
// and destroy the pbuffer before going back to the application but this is TODO // and destroy the pbuffer before going back to the application but this is TODO
mDummyPbuffer = mGLX.createPbuffer(mXDisplay, contextConfig, nullptr); mDummyPbuffer = mGLX.createPbuffer(contextConfig, nullptr);
mGLX.makeCurrent(mXDisplay, mDummyPbuffer, mContext); mGLX.makeCurrent(mDummyPbuffer, mContext);
mFunctionsGL = new FunctionsGLGLX(mGLX.getProc); mFunctionsGL = new FunctionsGLGLX(mGLX.getProc);
mFunctionsGL->initialize(); mFunctionsGL->initialize();
...@@ -165,13 +164,13 @@ void DisplayGLX::terminate() ...@@ -165,13 +164,13 @@ void DisplayGLX::terminate()
if (mDummyPbuffer) if (mDummyPbuffer)
{ {
mGLX.destroyPbuffer(mXDisplay, mDummyPbuffer); mGLX.destroyPbuffer(mDummyPbuffer);
mDummyPbuffer = 0; mDummyPbuffer = 0;
} }
if (mContext) if (mContext)
{ {
mGLX.destroyContext(mXDisplay, mContext); mGLX.destroyContext(mContext);
mContext = nullptr; mContext = nullptr;
} }
...@@ -187,7 +186,7 @@ SurfaceImpl *DisplayGLX::createWindowSurface(const egl::Config *configuration, ...@@ -187,7 +186,7 @@ SurfaceImpl *DisplayGLX::createWindowSurface(const egl::Config *configuration,
ASSERT(configIdToGLXConfig.count(configuration->configID) > 0); ASSERT(configIdToGLXConfig.count(configuration->configID) > 0);
GLXFBConfig fbConfig = configIdToGLXConfig[configuration->configID]; GLXFBConfig fbConfig = configIdToGLXConfig[configuration->configID];
return new WindowSurfaceGLX(mGLX, window, mXDisplay, mContext, fbConfig); return new WindowSurfaceGLX(mGLX, window, mGLX.getDisplay(), mContext, fbConfig);
} }
SurfaceImpl *DisplayGLX::createPbufferSurface(const egl::Config *configuration, SurfaceImpl *DisplayGLX::createPbufferSurface(const egl::Config *configuration,
...@@ -200,7 +199,7 @@ SurfaceImpl *DisplayGLX::createPbufferSurface(const egl::Config *configuration, ...@@ -200,7 +199,7 @@ SurfaceImpl *DisplayGLX::createPbufferSurface(const egl::Config *configuration,
EGLint height = attribs.get(EGL_HEIGHT, 0); EGLint height = attribs.get(EGL_HEIGHT, 0);
bool largest = (attribs.get(EGL_LARGEST_PBUFFER, EGL_FALSE) == EGL_TRUE); bool largest = (attribs.get(EGL_LARGEST_PBUFFER, EGL_FALSE) == EGL_TRUE);
return new PbufferSurfaceGLX(width, height, largest, mGLX, mXDisplay, mContext, fbConfig); return new PbufferSurfaceGLX(width, height, largest, mGLX, mContext, fbConfig);
} }
SurfaceImpl* DisplayGLX::createPbufferFromClientBuffer(const egl::Config *configuration, SurfaceImpl* DisplayGLX::createPbufferFromClientBuffer(const egl::Config *configuration,
...@@ -234,7 +233,7 @@ egl::ConfigSet DisplayGLX::generateConfigs() const ...@@ -234,7 +233,7 @@ egl::ConfigSet DisplayGLX::generateConfigs() const
bool hasTextureFromPixmap = mGLX.hasExtension("GLX_EXT_texture_from_pixmap"); bool hasTextureFromPixmap = mGLX.hasExtension("GLX_EXT_texture_from_pixmap");
int glxConfigCount; int glxConfigCount;
GLXFBConfig *glxConfigs = mGLX.getFBConfigs(mXDisplay, DefaultScreen(mXDisplay), &glxConfigCount); GLXFBConfig *glxConfigs = mGLX.getFBConfigs(&glxConfigCount);
for (int i = 0; i < glxConfigCount; i++) for (int i = 0; i < glxConfigCount; i++)
{ {
...@@ -366,7 +365,7 @@ bool DisplayGLX::isValidNativeWindow(EGLNativeWindowType window) const ...@@ -366,7 +365,7 @@ bool DisplayGLX::isValidNativeWindow(EGLNativeWindowType window) const
Window parent; Window parent;
Window *children = nullptr; Window *children = nullptr;
unsigned nChildren; unsigned nChildren;
int status = XQueryTree(mXDisplay, window, &root, &parent, &children, &nChildren); int status = XQueryTree(mGLX.getDisplay(), window, &root, &parent, &children, &nChildren);
if (children) if (children)
{ {
XFree(children); XFree(children);
...@@ -399,7 +398,7 @@ void DisplayGLX::generateCaps(egl::Caps *outCaps) const ...@@ -399,7 +398,7 @@ void DisplayGLX::generateCaps(egl::Caps *outCaps) const
int DisplayGLX::getGLXFBConfigAttrib(GLXFBConfig config, int attrib) const int DisplayGLX::getGLXFBConfigAttrib(GLXFBConfig config, int attrib) const
{ {
int result; int result;
mGLX.getFBConfigAttrib(mXDisplay, config, attrib, &result); mGLX.getFBConfigAttrib(config, attrib, &result);
return result; return result;
} }
......
...@@ -74,7 +74,6 @@ class DisplayGLX : public DisplayGL ...@@ -74,7 +74,6 @@ class DisplayGLX : public DisplayGL
FunctionsGLX mGLX; FunctionsGLX mGLX;
egl::Display *mEGLDisplay; egl::Display *mEGLDisplay;
Display *mXDisplay;
}; };
} }
......
...@@ -27,24 +27,25 @@ static bool GetProc(PFNGLXGETPROCADDRESSPROC getProc, T *member, const char *nam ...@@ -27,24 +27,25 @@ static bool GetProc(PFNGLXGETPROCADDRESSPROC getProc, T *member, const char *nam
FunctionsGLX::FunctionsGLX() FunctionsGLX::FunctionsGLX()
: majorVersion(0), : majorVersion(0),
minorVersion(0), minorVersion(0),
getProc(nullptr), mLibHandle(nullptr),
destroyContext(nullptr), mXDisplay(nullptr),
makeCurrent(nullptr), mXScreen(-1),
swapBuffers(nullptr), mDestroyContextPtr(nullptr),
queryExtension(nullptr), mMakeCurrentPtr(nullptr),
queryVersion(nullptr), mSwapBuffersPtr(nullptr),
queryExtensionsString(nullptr), mQueryExtensionPtr(nullptr),
getFBConfigs(nullptr), mQueryVersionPtr(nullptr),
chooseFBConfig(nullptr), mQueryExtensionsStringPtr(nullptr),
getFBConfigAttrib(nullptr), mGetFBConfigsPtr(nullptr),
getVisualFromFBConfig(nullptr), mChooseFBConfigPtr(nullptr),
createWindow(nullptr), mGetFBConfigAttribPtr(nullptr),
destroyWindow(nullptr), mGetVisualFromFBConfigPtr(nullptr),
createPbuffer(nullptr), mCreateWindowPtr(nullptr),
destroyPbuffer(nullptr), mDestroyWindowPtr(nullptr),
queryDrawable(nullptr), mCreatePbufferPtr(nullptr),
createContextAttribsARB(nullptr), mDestroyPbufferPtr(nullptr),
mLibHandle(nullptr) mQueryDrawablePtr(nullptr),
mCreateContextAttribsARBPtr(nullptr)
{ {
} }
...@@ -53,9 +54,11 @@ FunctionsGLX::~FunctionsGLX() ...@@ -53,9 +54,11 @@ FunctionsGLX::~FunctionsGLX()
terminate(); terminate();
} }
egl::Error FunctionsGLX::initialize(Display *xDisplay) egl::Error FunctionsGLX::initialize(Display *xDisplay, int screen)
{ {
terminate(); terminate();
mXDisplay = xDisplay;
mXScreen = screen;
mLibHandle = dlopen("libGL.so.1", RTLD_NOW); mLibHandle = dlopen("libGL.so.1", RTLD_NOW);
if (!mLibHandle) if (!mLibHandle)
...@@ -80,27 +83,27 @@ egl::Error FunctionsGLX::initialize(Display *xDisplay) ...@@ -80,27 +83,27 @@ egl::Error FunctionsGLX::initialize(Display *xDisplay)
} }
// GLX 1.0 // GLX 1.0
GET_PROC_OR_ERROR(&destroyContext, "glXDestroyContext"); GET_PROC_OR_ERROR(&mDestroyContextPtr, "glXDestroyContext");
GET_PROC_OR_ERROR(&makeCurrent, "glXMakeCurrent"); GET_PROC_OR_ERROR(&mMakeCurrentPtr, "glXMakeCurrent");
GET_PROC_OR_ERROR(&swapBuffers, "glXSwapBuffers"); GET_PROC_OR_ERROR(&mSwapBuffersPtr, "glXSwapBuffers");
GET_PROC_OR_ERROR(&queryExtension, "glXQueryExtension"); GET_PROC_OR_ERROR(&mQueryExtensionPtr, "glXQueryExtension");
GET_PROC_OR_ERROR(&queryVersion, "glXQueryVersion"); GET_PROC_OR_ERROR(&mQueryVersionPtr, "glXQueryVersion");
// GLX 1.1 // GLX 1.1
GET_PROC_OR_ERROR(&queryExtensionsString, "glXQueryExtensionsString"); GET_PROC_OR_ERROR(&mQueryExtensionsStringPtr, "glXQueryExtensionsString");
// Check we have a working GLX // Check we have a working GLX
{ {
int errorBase; int errorBase;
int eventBase; int eventBase;
if (!queryExtension(xDisplay, &errorBase, &eventBase)) if (!queryExtension(&errorBase, &eventBase))
{ {
return egl::Error(EGL_NOT_INITIALIZED, "GLX is not present."); return egl::Error(EGL_NOT_INITIALIZED, "GLX is not present.");
} }
} }
// Check we have a supported version of GLX // Check we have a supported version of GLX
if (!queryVersion(xDisplay, &majorVersion, &minorVersion)) if (!queryVersion(&majorVersion, &minorVersion))
{ {
return egl::Error(EGL_NOT_INITIALIZED, "Could not query the GLX version."); return egl::Error(EGL_NOT_INITIALIZED, "Could not query the GLX version.");
} }
...@@ -109,7 +112,7 @@ egl::Error FunctionsGLX::initialize(Display *xDisplay) ...@@ -109,7 +112,7 @@ egl::Error FunctionsGLX::initialize(Display *xDisplay)
return egl::Error(EGL_NOT_INITIALIZED, "Unsupported GLX version (requires at least 1.3)."); return egl::Error(EGL_NOT_INITIALIZED, "Unsupported GLX version (requires at least 1.3).");
} }
const char *extensions = queryExtensionsString(xDisplay, DefaultScreen(xDisplay)); const char *extensions = queryExtensionsString();
if (!extensions) if (!extensions)
{ {
return egl::Error(EGL_NOT_INITIALIZED, "glXQueryExtensionsString returned NULL"); return egl::Error(EGL_NOT_INITIALIZED, "glXQueryExtensionsString returned NULL");
...@@ -117,24 +120,24 @@ egl::Error FunctionsGLX::initialize(Display *xDisplay) ...@@ -117,24 +120,24 @@ egl::Error FunctionsGLX::initialize(Display *xDisplay)
mExtensions = TokenizeExtensionsString(extensions); mExtensions = TokenizeExtensionsString(extensions);
// GLX 1.3 // GLX 1.3
GET_PROC_OR_ERROR(&getFBConfigs, "glXGetFBConfigs"); GET_PROC_OR_ERROR(&mGetFBConfigsPtr, "glXGetFBConfigs");
GET_PROC_OR_ERROR(&chooseFBConfig, "glXChooseFBConfig"); GET_PROC_OR_ERROR(&mChooseFBConfigPtr, "glXChooseFBConfig");
GET_PROC_OR_ERROR(&getFBConfigAttrib, "glXGetFBConfigAttrib"); GET_PROC_OR_ERROR(&mGetFBConfigAttribPtr, "glXGetFBConfigAttrib");
GET_PROC_OR_ERROR(&getVisualFromFBConfig, "glXGetVisualFromFBConfig"); GET_PROC_OR_ERROR(&mGetVisualFromFBConfigPtr, "glXGetVisualFromFBConfig");
GET_PROC_OR_ERROR(&createWindow, "glXCreateWindow"); GET_PROC_OR_ERROR(&mCreateWindowPtr, "glXCreateWindow");
GET_PROC_OR_ERROR(&destroyWindow, "glXDestroyWindow"); GET_PROC_OR_ERROR(&mDestroyWindowPtr, "glXDestroyWindow");
GET_PROC_OR_ERROR(&createPbuffer, "glXCreatePbuffer"); GET_PROC_OR_ERROR(&mCreatePbufferPtr, "glXCreatePbuffer");
GET_PROC_OR_ERROR(&destroyPbuffer, "glXDestroyPbuffer"); GET_PROC_OR_ERROR(&mDestroyPbufferPtr, "glXDestroyPbuffer");
GET_PROC_OR_ERROR(&queryDrawable, "glXQueryDrawable"); GET_PROC_OR_ERROR(&mQueryDrawablePtr, "glXQueryDrawable");
// Extensions // Extensions
if (hasExtension("GLX_ARB_create_context")) if (hasExtension("GLX_ARB_create_context"))
{ {
GET_PROC_OR_ERROR(&createContextAttribsARB, "glXCreateContextAttribsARB"); GET_PROC_OR_ERROR(&mCreateContextAttribsARBPtr, "glXCreateContextAttribsARB");
} }
else else
{ {
createContextAttribsARB = nullptr; mCreateContextAttribsARBPtr = nullptr;
} }
#undef GET_PROC_OR_ERROR #undef GET_PROC_OR_ERROR
...@@ -156,4 +159,88 @@ bool FunctionsGLX::hasExtension(const char *extension) const ...@@ -156,4 +159,88 @@ bool FunctionsGLX::hasExtension(const char *extension) const
return std::find(mExtensions.begin(), mExtensions.end(), extension) != mExtensions.end(); return std::find(mExtensions.begin(), mExtensions.end(), extension) != mExtensions.end();
} }
Display *FunctionsGLX::getDisplay() const
{
return mXDisplay;
}
int FunctionsGLX::getScreen() const
{
return mXScreen;
}
// GLX functions
// GLX 1.0
void FunctionsGLX::destroyContext(GLXContext context) const
{
mDestroyContextPtr(mXDisplay, context);
}
Bool FunctionsGLX::makeCurrent(GLXDrawable drawable, GLXContext context) const
{
return mMakeCurrentPtr(mXDisplay, drawable, context);
}
void FunctionsGLX::swapBuffers(GLXDrawable drawable) const
{
mSwapBuffersPtr(mXDisplay, drawable);
}
Bool FunctionsGLX::queryExtension(int *errorBase, int *event) const
{
return mQueryExtensionPtr(mXDisplay, errorBase, event);
}
Bool FunctionsGLX::queryVersion(int *major, int *minor) const
{
return mQueryVersionPtr(mXDisplay, major, minor);
}
// GLX 1.1
const char *FunctionsGLX::queryExtensionsString() const
{
return mQueryExtensionsStringPtr(mXDisplay, mXScreen);
}
// GLX 1.4
GLXFBConfig *FunctionsGLX::getFBConfigs(int *nElements) const
{
return mGetFBConfigsPtr(mXDisplay, mXScreen, nElements);
}
GLXFBConfig *FunctionsGLX::chooseFBConfig(const int *attribList, int *nElements) const
{
return mChooseFBConfigPtr(mXDisplay, mXScreen, attribList, nElements);
}
int FunctionsGLX::getFBConfigAttrib(GLXFBConfig config, int attribute, int *value) const
{
return mGetFBConfigAttribPtr(mXDisplay, config, attribute, value);
}
XVisualInfo *FunctionsGLX::getVisualFromFBConfig(GLXFBConfig config) const
{
return mGetVisualFromFBConfigPtr(mXDisplay, config);
}
GLXWindow FunctionsGLX::createWindow(GLXFBConfig config, Window window, const int *attribList) const
{
return mCreateWindowPtr(mXDisplay, config, window, attribList);
}
void FunctionsGLX::destroyWindow(GLXWindow window) const
{
mDestroyWindowPtr(mXDisplay, window);
}
GLXPbuffer FunctionsGLX::createPbuffer(GLXFBConfig config, const int *attribList) const
{
return mCreatePbufferPtr(mXDisplay, config, attribList);
}
void FunctionsGLX::destroyPbuffer(GLXPbuffer pbuffer) const
{
mDestroyPbufferPtr(mXDisplay, pbuffer);
}
void FunctionsGLX::queryDrawable(GLXDrawable drawable, int attribute, unsigned int *value) const
{
mQueryDrawablePtr(mXDisplay, drawable, attribute, value);
}
// GLX_ARB_create_context
GLXContext FunctionsGLX::createContextAttribsARB(GLXFBConfig config, GLXContext shareContext, Bool direct, const int *attribList) const
{
return mCreateContextAttribsARBPtr(mXDisplay, config, shareContext, direct, attribList);
}
} }
...@@ -26,7 +26,7 @@ class FunctionsGLX : angle::NonCopyable ...@@ -26,7 +26,7 @@ class FunctionsGLX : angle::NonCopyable
~FunctionsGLX(); ~FunctionsGLX();
// Load data from GLX, can be called multiple times // Load data from GLX, can be called multiple times
egl::Error initialize(Display *xDisplay); egl::Error initialize(Display *xDisplay, int screen);
void terminate(); void terminate();
bool hasExtension(const char *extension) const; bool hasExtension(const char *extension) const;
...@@ -34,35 +34,65 @@ class FunctionsGLX : angle::NonCopyable ...@@ -34,35 +34,65 @@ class FunctionsGLX : angle::NonCopyable
int majorVersion; int majorVersion;
int minorVersion; int minorVersion;
Display *getDisplay() const;
int getScreen() const;
PFNGLXGETPROCADDRESSPROC getProc; PFNGLXGETPROCADDRESSPROC getProc;
// GLX 1.0 // GLX 1.0
PFNGLXDESTROYCONTEXTPROC destroyContext; void destroyContext(GLXContext context) const;
PFNGLXMAKECURRENTPROC makeCurrent; Bool makeCurrent(GLXDrawable drawable, GLXContext context) const;
PFNGLXSWAPBUFFERSPROC swapBuffers; void swapBuffers(GLXDrawable drawable) const;
PFNGLXQUERYEXTENSIONPROC queryExtension; Bool queryExtension(int *errorBase, int *event) const;
PFNGLXQUERYVERSIONPROC queryVersion; Bool queryVersion(int *major, int *minor) const;
// GLX 1.1 // GLX 1.1
PFNGLXQUERYEXTENSIONSSTRINGPROC queryExtensionsString; const char *queryExtensionsString() const;
//GLX 1.3 // GLX 1.3
PFNGLXGETFBCONFIGSPROC getFBConfigs; GLXFBConfig *getFBConfigs(int *nElements) const;
PFNGLXCHOOSEFBCONFIGPROC chooseFBConfig; GLXFBConfig *chooseFBConfig(const int *attribList, int *nElements) const;
PFNGLXGETFBCONFIGATTRIBPROC getFBConfigAttrib; int getFBConfigAttrib(GLXFBConfig config, int attribute, int *value) const;
PFNGLXGETVISUALFROMFBCONFIGPROC getVisualFromFBConfig; XVisualInfo *getVisualFromFBConfig(GLXFBConfig config) const;
PFNGLXCREATEWINDOWPROC createWindow; GLXWindow createWindow(GLXFBConfig config, Window window, const int *attribList) const;
PFNGLXDESTROYWINDOWPROC destroyWindow; void destroyWindow(GLXWindow window) const;
PFNGLXCREATEPBUFFERPROC createPbuffer; GLXPbuffer createPbuffer(GLXFBConfig config, const int *attribList) const;
PFNGLXDESTROYPBUFFERPROC destroyPbuffer; void destroyPbuffer(GLXPbuffer pbuffer) const;
PFNGLXQUERYDRAWABLEPROC queryDrawable; void queryDrawable(GLXDrawable drawable, int attribute, unsigned int *value) const;
// GLX_ARB_create_context // GLX_ARB_create_context
PFNGLXCREATECONTEXTATTRIBSARBPROC createContextAttribsARB; GLXContext createContextAttribsARB(GLXFBConfig config, GLXContext shareContext, Bool direct, const int *attribList) const;
private: private:
void *mLibHandle; void *mLibHandle;
Display *mXDisplay;
int mXScreen;
std::vector<std::string> mExtensions; std::vector<std::string> mExtensions;
// GLX 1.0
PFNGLXDESTROYCONTEXTPROC mDestroyContextPtr;
PFNGLXMAKECURRENTPROC mMakeCurrentPtr;
PFNGLXSWAPBUFFERSPROC mSwapBuffersPtr;
PFNGLXQUERYEXTENSIONPROC mQueryExtensionPtr;
PFNGLXQUERYVERSIONPROC mQueryVersionPtr;
// GLX 1.1
PFNGLXQUERYEXTENSIONSSTRINGPROC mQueryExtensionsStringPtr;
//GLX 1.3
PFNGLXGETFBCONFIGSPROC mGetFBConfigsPtr;
PFNGLXCHOOSEFBCONFIGPROC mChooseFBConfigPtr;
PFNGLXGETFBCONFIGATTRIBPROC mGetFBConfigAttribPtr;
PFNGLXGETVISUALFROMFBCONFIGPROC mGetVisualFromFBConfigPtr;
PFNGLXCREATEWINDOWPROC mCreateWindowPtr;
PFNGLXDESTROYWINDOWPROC mDestroyWindowPtr;
PFNGLXCREATEPBUFFERPROC mCreatePbufferPtr;
PFNGLXDESTROYPBUFFERPROC mDestroyPbufferPtr;
PFNGLXQUERYDRAWABLEPROC mQueryDrawablePtr;
// GLX_ARB_create_context
PFNGLXCREATECONTEXTATTRIBSARBPROC mCreateContextAttribsARBPtr;
}; };
} }
......
...@@ -15,13 +15,12 @@ namespace rx ...@@ -15,13 +15,12 @@ namespace rx
{ {
PbufferSurfaceGLX::PbufferSurfaceGLX(EGLint width, EGLint height, bool largest, const FunctionsGLX &glx, PbufferSurfaceGLX::PbufferSurfaceGLX(EGLint width, EGLint height, bool largest, const FunctionsGLX &glx,
Display *display, GLXContext context, GLXFBConfig fbConfig) GLXContext context, GLXFBConfig fbConfig)
: SurfaceGL(), : SurfaceGL(),
mWidth(width), mWidth(width),
mHeight(height), mHeight(height),
mLargest(largest), mLargest(largest),
mGLX(glx), mGLX(glx),
mDisplay(display),
mContext(context), mContext(context),
mFBConfig(fbConfig), mFBConfig(fbConfig),
mPbuffer(0) mPbuffer(0)
...@@ -32,7 +31,7 @@ PbufferSurfaceGLX::~PbufferSurfaceGLX() ...@@ -32,7 +31,7 @@ PbufferSurfaceGLX::~PbufferSurfaceGLX()
{ {
if (mPbuffer) if (mPbuffer)
{ {
mGLX.destroyPbuffer(mDisplay, mPbuffer); mGLX.destroyPbuffer(mPbuffer);
} }
} }
...@@ -46,7 +45,7 @@ egl::Error PbufferSurfaceGLX::initialize() ...@@ -46,7 +45,7 @@ egl::Error PbufferSurfaceGLX::initialize()
None None
}; };
mPbuffer = mGLX.createPbuffer(mDisplay, mFBConfig, attribs); mPbuffer = mGLX.createPbuffer(mFBConfig, attribs);
if (!mPbuffer) if (!mPbuffer)
{ {
return egl::Error(EGL_BAD_ALLOC, "Failed to create a native GLX pbuffer."); return egl::Error(EGL_BAD_ALLOC, "Failed to create a native GLX pbuffer.");
...@@ -54,8 +53,8 @@ egl::Error PbufferSurfaceGLX::initialize() ...@@ -54,8 +53,8 @@ egl::Error PbufferSurfaceGLX::initialize()
if (mLargest) if (mLargest)
{ {
mGLX.queryDrawable(mDisplay, mPbuffer, GLX_WIDTH, &mWidth); mGLX.queryDrawable(mPbuffer, GLX_WIDTH, &mWidth);
mGLX.queryDrawable(mDisplay, mPbuffer, GLX_HEIGHT, &mHeight); mGLX.queryDrawable(mPbuffer, GLX_HEIGHT, &mHeight);
} }
return egl::Error(EGL_SUCCESS); return egl::Error(EGL_SUCCESS);
...@@ -63,7 +62,7 @@ egl::Error PbufferSurfaceGLX::initialize() ...@@ -63,7 +62,7 @@ egl::Error PbufferSurfaceGLX::initialize()
egl::Error PbufferSurfaceGLX::makeCurrent() egl::Error PbufferSurfaceGLX::makeCurrent()
{ {
if (mGLX.makeCurrent(mDisplay, mPbuffer, mContext) != True) if (mGLX.makeCurrent(mPbuffer, mContext) != True)
{ {
return egl::Error(EGL_BAD_DISPLAY); return egl::Error(EGL_BAD_DISPLAY);
} }
......
...@@ -23,7 +23,7 @@ class PbufferSurfaceGLX : public SurfaceGL ...@@ -23,7 +23,7 @@ class PbufferSurfaceGLX : public SurfaceGL
{ {
public: public:
PbufferSurfaceGLX(EGLint width, EGLint height, bool largest, const FunctionsGLX &glx, PbufferSurfaceGLX(EGLint width, EGLint height, bool largest, const FunctionsGLX &glx,
Display *display, GLXContext context, GLXFBConfig fbConfig); GLXContext context, GLXFBConfig fbConfig);
~PbufferSurfaceGLX() override; ~PbufferSurfaceGLX() override;
egl::Error initialize(); egl::Error initialize();
...@@ -47,7 +47,6 @@ class PbufferSurfaceGLX : public SurfaceGL ...@@ -47,7 +47,6 @@ class PbufferSurfaceGLX : public SurfaceGL
bool mLargest; bool mLargest;
const FunctionsGLX &mGLX; const FunctionsGLX &mGLX;
Display *mDisplay;
GLXContext mContext; GLXContext mContext;
GLXFBConfig mFBConfig; GLXFBConfig mFBConfig;
GLXPbuffer mPbuffer; GLXPbuffer mPbuffer;
......
...@@ -29,14 +29,14 @@ WindowSurfaceGLX::WindowSurfaceGLX(const FunctionsGLX &glx, EGLNativeWindowType ...@@ -29,14 +29,14 @@ WindowSurfaceGLX::WindowSurfaceGLX(const FunctionsGLX &glx, EGLNativeWindowType
WindowSurfaceGLX::~WindowSurfaceGLX() WindowSurfaceGLX::~WindowSurfaceGLX()
{ {
if (mWindow) if (mGLXWindow)
{ {
XDestroyWindow(mDisplay, mWindow); mGLX.destroyWindow(mGLXWindow);
} }
if (mGLXWindow) if (mWindow)
{ {
mGLX.destroyWindow(mDisplay, mGLXWindow); XDestroyWindow(mDisplay, mWindow);
} }
} }
...@@ -48,7 +48,7 @@ egl::Error WindowSurfaceGLX::initialize() ...@@ -48,7 +48,7 @@ egl::Error WindowSurfaceGLX::initialize()
// create a child window with the right visual that covers all of its // create a child window with the right visual that covers all of its
// parent. // parent.
XVisualInfo* visualInfo = mGLX.getVisualFromFBConfig(mDisplay, mFBConfig); XVisualInfo *visualInfo = mGLX.getVisualFromFBConfig(mFBConfig);
if (!visualInfo) if (!visualInfo)
{ {
return egl::Error(EGL_BAD_NATIVE_WINDOW, "Failed to get the XVisualInfo for the child window."); return egl::Error(EGL_BAD_NATIVE_WINDOW, "Failed to get the XVisualInfo for the child window.");
...@@ -76,7 +76,7 @@ egl::Error WindowSurfaceGLX::initialize() ...@@ -76,7 +76,7 @@ egl::Error WindowSurfaceGLX::initialize()
//TODO(cwallez) set up our own error handler to see if the call failed //TODO(cwallez) set up our own error handler to see if the call failed
mWindow = XCreateWindow(mDisplay, mParent, 0, 0, parentAttribs.width, parentAttribs.height, mWindow = XCreateWindow(mDisplay, mParent, 0, 0, parentAttribs.width, parentAttribs.height,
0, visualInfo->depth, InputOutput, visual, attributeMask, &attributes); 0, visualInfo->depth, InputOutput, visual, attributeMask, &attributes);
mGLXWindow = mGLX.createWindow(mDisplay, mFBConfig, mWindow, nullptr); mGLXWindow = mGLX.createWindow(mFBConfig, mWindow, nullptr);
XMapWindow(mDisplay, mWindow); XMapWindow(mDisplay, mWindow);
XFlush(mDisplay); XFlush(mDisplay);
...@@ -89,7 +89,7 @@ egl::Error WindowSurfaceGLX::initialize() ...@@ -89,7 +89,7 @@ egl::Error WindowSurfaceGLX::initialize()
egl::Error WindowSurfaceGLX::makeCurrent() egl::Error WindowSurfaceGLX::makeCurrent()
{ {
if (mGLX.makeCurrent(mDisplay, mGLXWindow, mContext) != True) if (mGLX.makeCurrent(mGLXWindow, mContext) != True)
{ {
return egl::Error(EGL_BAD_DISPLAY); return egl::Error(EGL_BAD_DISPLAY);
} }
...@@ -100,7 +100,7 @@ egl::Error WindowSurfaceGLX::swap() ...@@ -100,7 +100,7 @@ egl::Error WindowSurfaceGLX::swap()
{ {
//TODO(cwallez) resize support //TODO(cwallez) resize support
//TODO(cwallez) set up our own error handler to see if the call failed //TODO(cwallez) set up our own error handler to see if the call failed
mGLX.swapBuffers(mDisplay, mGLXWindow); mGLX.swapBuffers(mGLXWindow);
return egl::Error(EGL_SUCCESS); return egl::Error(EGL_SUCCESS);
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment