GregMiscellaneous: zzogl:

* add more locking to X11. Never too safe.
* Free the visual (memory leak)
* Only search event of the current window
* force 4:3 in fullscreen mode (will need a toggle box to enable/disable it)
* do not grab cursor on debug (this one will need more test)


git-svn-id: http://pcsx2.googlecode.com/svn/branches/GregMiscellaneous@3739 96395faa-99c1-11dd-bbfe-3dabce05a288
This commit is contained in:
gregory.hainaut@gmail.com 2010-09-06 22:21:07 +00:00
parent ddb33652ab
commit 873cb9656f
1 changed files with 38 additions and 7 deletions

View File

@ -43,19 +43,28 @@ bool GLWindow::CreateWindow(void *pDisplay)
bool GLWindow::ReleaseContext() bool GLWindow::ReleaseContext()
{ {
if (context && (glDisplay != NULL)) bool status = true;
if (!glDisplay) return status;
// free the context
if (context)
{ {
if (!glXMakeCurrent(glDisplay, None, NULL)) if (!glXMakeCurrent(glDisplay, None, NULL)) {
{
ZZLog::Error_Log("Could not release drawing context."); ZZLog::Error_Log("Could not release drawing context.");
} status = false;
}
glXDestroyContext(glDisplay, context); glXDestroyContext(glDisplay, context);
context = NULL; context = NULL;
} }
return true; // free the visual
if (vi) {
XFree(vi);
vi = NULL;
}
return status;
} }
void GLWindow::CloseWindow() void GLWindow::CloseWindow()
@ -125,9 +134,12 @@ void GLWindow::GetWindowSize()
s32 xDummy; s32 xDummy;
s32 yDummy; s32 yDummy;
XLockDisplay(glDisplay);
XGetGeometry(glDisplay, glWindow, &winDummy, &xDummy, &yDummy, &width, &height, &borderDummy, &depth); XGetGeometry(glDisplay, glWindow, &winDummy, &xDummy, &yDummy, &width, &height, &borderDummy, &depth);
XUnlockDisplay(glDisplay);
nBackbufferWidth = width; nBackbufferWidth = width;
nBackbufferHeight = height; nBackbufferHeight = height;
nBackbufferHeight = height;
ZZLog::Error_Log("Resolution %dx%d. Depth %d bpp. Position (%d,%d)", width, height, depth, conf.x, conf.y); ZZLog::Error_Log("Resolution %dx%d. Depth %d bpp. Position (%d,%d)", width, height, depth, conf.x, conf.y);
} }
@ -141,6 +153,8 @@ void GLWindow::GetGLXVersion()
} }
void GLWindow::UpdateGrabKey() { void GLWindow::UpdateGrabKey() {
// Do not stole the key in debug mode. It is not breakpoint friendly...
#ifndef _DEBUG
XLockDisplay(glDisplay); XLockDisplay(glDisplay);
if (fullScreen) { if (fullScreen) {
XGrabPointer(glDisplay, glWindow, True, ButtonPressMask, GrabModeAsync, GrabModeAsync, glWindow, None, CurrentTime); XGrabPointer(glDisplay, glWindow, True, ButtonPressMask, GrabModeAsync, GrabModeAsync, glWindow, None, CurrentTime);
@ -150,6 +164,7 @@ void GLWindow::UpdateGrabKey() {
XUngrabKeyboard(glDisplay, CurrentTime); XUngrabKeyboard(glDisplay, CurrentTime);
} }
XUnlockDisplay(glDisplay); XUnlockDisplay(glDisplay);
#endif
} }
#define _NET_WM_STATE_REMOVE 0 #define _NET_WM_STATE_REMOVE 0
@ -160,6 +175,19 @@ void GLWindow::ToggleFullscreen()
{ {
if (!glDisplay or !glWindow) return; if (!glDisplay or !glWindow) return;
// Force 4:3 ratio of the screen when going fullscreen
// FIXME add a nice configuration option
if(!fullScreen) {
XLockDisplay(glDisplay);
// Compute the width based on height
width = (4*height)/3;
conf.width = width;
// resize the window
XResizeWindow(glDisplay, glWindow, width, height);
XSync(glDisplay, False);
XUnlockDisplay(glDisplay);
}
u32 mask = SubstructureRedirectMask | SubstructureNotifyMask; u32 mask = SubstructureRedirectMask | SubstructureNotifyMask;
// Setup a new event structure // Setup a new event structure
XClientMessageEvent cme; XClientMessageEvent cme;
@ -278,8 +306,10 @@ void GLWindow::SetTitle(char *strtitle)
void GLWindow::ResizeCheck() void GLWindow::ResizeCheck()
{ {
XEvent event; XEvent event;
if (!glDisplay or !glWindow) return;
while (XCheckTypedEvent(glDisplay, ConfigureNotify, &event)) XLockDisplay(glDisplay);
while (XCheckTypedWindowEvent(glDisplay, glWindow, ConfigureNotify, &event))
{ {
if ((event.xconfigure.width != width) || (event.xconfigure.height != height)) if ((event.xconfigure.width != width) || (event.xconfigure.height != height))
{ {
@ -299,6 +329,7 @@ void GLWindow::ResizeCheck()
} }
} }
XUnlockDisplay(glDisplay);
} }
#endif #endif