zzogl-pg: Move a bunch of X11 stuff to a separate file.

git-svn-id: http://pcsx2.googlecode.com/svn/trunk@2745 96395faa-99c1-11dd-bbfe-3dabce05a288
This commit is contained in:
arcum42 2010-03-19 02:04:55 +00:00
parent 0a8c267991
commit 28df00c2a3
8 changed files with 291 additions and 185 deletions

View File

@ -0,0 +1,242 @@
/* ZeroGS KOSMOS
* Copyright (C) 2005-2006 zerofrog@gmail.com
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include "GS.h"
#include "zerogs.h"
#ifdef GL_X11_WINDOW
bool GLWindow::CreateWindow(void *pDisplay)
{
glDisplay = XOpenDisplay(0);
glScreen = DefaultScreen(glDisplay);
if ( pDisplay == NULL ) return false;
*(Display**)pDisplay = glDisplay;
return true;
}
bool GLWindow::DestroyWindow()
{
if (context)
{
if (!glXMakeCurrent(glDisplay, None, NULL))
{
ERROR_LOG("Could not release drawing context.\n");
}
glXDestroyContext(glDisplay, context);
context = NULL;
}
/* switch back to original desktop resolution if we were in fullScreen */
if ( glDisplay != NULL )
{
if (fullScreen)
{
XF86VidModeSwitchToMode(glDisplay, glScreen, &deskMode);
XF86VidModeSetViewPort(glDisplay, glScreen, 0, 0);
}
}
}
void GLWindow::CloseWindow()
{
if ( glDisplay != NULL )
{
XCloseDisplay(glDisplay);
glDisplay = NULL;
}
}
void GLWindow::DisplayWindow(int _width, int _height)
{
int i;
XVisualInfo *vi;
Colormap cmap;
int dpyWidth, dpyHeight;
int glxMajorVersion, glxMinorVersion;
int vidModeMajorVersion, vidModeMinorVersion;
Atom wmDelete;
Window winDummy;
unsigned int borderDummy;
// attributes for a single buffered visual in RGBA format with at least
// 8 bits per color and a 24 bit depth buffer
int attrListSgl[] = {GLX_RGBA, GLX_RED_SIZE, 8,
GLX_GREEN_SIZE, 8,
GLX_BLUE_SIZE, 8,
GLX_DEPTH_SIZE, 24,
None};
// attributes for a double buffered visual in RGBA format with at least
// 8 bits per color and a 24 bit depth buffer
int attrListDbl[] = { GLX_RGBA, GLX_DOUBLEBUFFER,
GLX_RED_SIZE, 8,
GLX_GREEN_SIZE, 8,
GLX_BLUE_SIZE, 8,
GLX_DEPTH_SIZE, 24,
None };
GLWin.fullScreen = !!(conf.options & GSOPTION_FULLSCREEN);
/* get an appropriate visual */
vi = glXChooseVisual(GLWin.glDisplay, GLWin.glScreen, attrListDbl);
if (vi == NULL) {
vi = glXChooseVisual(GLWin.glDisplay, GLWin.glScreen, attrListSgl);
GLWin.doubleBuffered = False;
ERROR_LOG("Only Singlebuffered Visual!\n");
}
else {
GLWin.doubleBuffered = True;
ERROR_LOG("Got Doublebuffered Visual!\n");
}
glXQueryVersion(GLWin.glDisplay, &glxMajorVersion, &glxMinorVersion);
ERROR_LOG("glX-Version %d.%d\n", glxMajorVersion, glxMinorVersion);
/* create a GLX context */
GLWin.context = glXCreateContext(GLWin.glDisplay, vi, 0, GL_TRUE);
/* create a color map */
cmap = XCreateColormap(GLWin.glDisplay, RootWindow(GLWin.glDisplay, vi->screen),
vi->visual, AllocNone);
GLWin.attr.colormap = cmap;
GLWin.attr.border_pixel = 0;
// get a connection
XF86VidModeQueryVersion(GLWin.glDisplay, &vidModeMajorVersion, &vidModeMinorVersion);
if (GLWin.fullScreen) {
XF86VidModeModeInfo **modes = NULL;
int modeNum = 0;
int bestMode = 0;
// set best mode to current
bestMode = 0;
ERROR_LOG("XF86VidModeExtension-Version %d.%d\n", vidModeMajorVersion, vidModeMinorVersion);
XF86VidModeGetAllModeLines(GLWin.glDisplay, GLWin.glScreen, &modeNum, &modes);
if( modeNum > 0 && modes != NULL ) {
/* save desktop-resolution before switching modes */
GLWin.deskMode = *modes[0];
/* look for mode with requested resolution */
for (i = 0; i < modeNum; i++) {
if ((modes[i]->hdisplay == _width) && (modes[i]->vdisplay == _height)) {
bestMode = i;
}
}
XF86VidModeSwitchToMode(GLWin.glDisplay, GLWin.glScreen, modes[bestMode]);
XF86VidModeSetViewPort(GLWin.glDisplay, GLWin.glScreen, 0, 0);
dpyWidth = modes[bestMode]->hdisplay;
dpyHeight = modes[bestMode]->vdisplay;
ERROR_LOG("Resolution %dx%d\n", dpyWidth, dpyHeight);
XFree(modes);
/* create a fullscreen window */
GLWin.attr.override_redirect = True;
GLWin.attr.event_mask = ExposureMask | KeyPressMask | ButtonPressMask |
StructureNotifyMask;
GLWin.glWindow = XCreateWindow(GLWin.glDisplay, RootWindow(GLWin.glDisplay, vi->screen),
0, 0, dpyWidth, dpyHeight, 0, vi->depth, InputOutput, vi->visual,
CWBorderPixel | CWColormap | CWEventMask | CWOverrideRedirect,
&GLWin.attr);
XWarpPointer(GLWin.glDisplay, None, GLWin.glWindow, 0, 0, 0, 0, 0, 0);
XMapRaised(GLWin.glDisplay, GLWin.glWindow);
XGrabKeyboard(GLWin.glDisplay, GLWin.glWindow, True, GrabModeAsync,
GrabModeAsync, CurrentTime);
XGrabPointer(GLWin.glDisplay, GLWin.glWindow, True, ButtonPressMask,
GrabModeAsync, GrabModeAsync, GLWin.glWindow, None, CurrentTime);
}
else {
ERROR_LOG("Failed to start fullscreen. If you received the \n"
"\"XFree86-VidModeExtension\" extension is missing, add\n"
"Load \"extmod\"\n"
"to your X configuration file (under the Module Section)\n");
GLWin.fullScreen = false;
}
}
if( !GLWin.fullScreen ) {
//XRootWindow(dpy,screen)
//int X = (rcdesktop.right-rcdesktop.left)/2 - (rc.right-rc.left)/2;
//int Y = (rcdesktop.bottom-rcdesktop.top)/2 - (rc.bottom-rc.top)/2;
// create a window in window mode
GLWin.attr.event_mask = ExposureMask | KeyPressMask | ButtonPressMask |
StructureNotifyMask;
GLWin.glWindow = XCreateWindow(GLWin.glDisplay, RootWindow(GLWin.glDisplay, vi->screen),
0, 0, _width, _height, 0, vi->depth, InputOutput, vi->visual,
CWBorderPixel | CWColormap | CWEventMask, &GLWin.attr);
// only set window title and handle wm_delete_events if in windowed mode
wmDelete = XInternAtom(GLWin.glDisplay, "WM_DELETE_WINDOW", True);
XSetWMProtocols(GLWin.glDisplay, GLWin.glWindow, &wmDelete, 1);
XSetStandardProperties(GLWin.glDisplay, GLWin.glWindow, "ZZOgl-PG",
"ZZOgl-PG", None, NULL, 0, NULL);
XMapRaised(GLWin.glDisplay, GLWin.glWindow);
}
// connect the glx-context to the window
glXMakeCurrent(GLWin.glDisplay, GLWin.glWindow, GLWin.context);
XGetGeometry(GLWin.glDisplay, GLWin.glWindow, &winDummy, &GLWin.x, &GLWin.y,
&GLWin.width, &GLWin.height, &borderDummy, &GLWin.depth);
ERROR_LOG("Depth %d\n", GLWin.depth);
if (glXIsDirect(GLWin.glDisplay, GLWin.context))
ERROR_LOG("you have Direct Rendering!\n");
else
ERROR_LOG("no Direct Rendering possible!\n");
// better for pad plugin key input (thc)
XSelectInput(GLWin.glDisplay, GLWin.glWindow, ExposureMask | KeyPressMask | KeyReleaseMask |
ButtonPressMask | StructureNotifyMask | EnterWindowMask | LeaveWindowMask |
FocusChangeMask );
}
void GLWindow::SwapBuffers()
{
glXSwapBuffers(glDisplay, glWindow);
}
void GLWindow::SetTitle(char *strtitle)
{
XTextProperty prop;
memset(&prop, 0, sizeof(prop));
char* ptitle = strtitle;
if( XStringListToTextProperty(&ptitle, 1, &prop) )
XSetWMName(glDisplay, glWindow, &prop);
XFree(prop.value);
}
void GLWindow::ResizeCheck()
{
XEvent event;
while(XCheckTypedEvent(glDisplay, ConfigureNotify, &event))
{
if ((event.xconfigure.width != width) || (event.xconfigure.height != height)) {
ZeroGS::ChangeWindowSize(event.xconfigure.width, event.xconfigure.height);
width = event.xconfigure.width;
height = event.xconfigure.height;
}
}
}
#endif

View File

@ -122,7 +122,7 @@ struct RECT
int right, bottom;
};
typedef struct {
/*typedef struct {
Display *dpy;
int screen;
Window win;
@ -134,7 +134,34 @@ typedef struct {
int x, y;
unsigned int width, height;
unsigned int depth;
} GLWindow;
} GLWindow;*/
#define GL_X11_WINDOW
class GLWindow
{
private:
#ifdef GL_X11_WINDOW
Display *glDisplay;
Window glWindow;
int glScreen;
GLXContext context;
XSetWindowAttributes attr;
XF86VidModeModeInfo deskMode;
#endif
bool fullScreen, doubleBuffered;
s32 x, y;
u32 width, height, depth;
public:
void SwapBuffers();
void SetTitle(char *strtitle);
bool CreateWindow(void *pDisplay);
bool DestroyWindow();
void CloseWindow();
void DisplayWindow(int _width, int _height);
void ResizeCheck();
};
extern GLWindow GLWin;

View File

@ -767,11 +767,7 @@ s32 CALLBACK GSopen(void *pDsp, char *Title, int multithread)
strcpy(GStitle, Title);
GLWin.dpy = XOpenDisplay(0);
GLWin.screen = DefaultScreen(GLWin.dpy);
if( pDsp != NULL )
*(Display**)pDsp = GLWin.dpy;
GLWin.CreateWindow(pDsp);
ERROR_LOG("Using %s:%d.%d.%d\n", libraryName, zgsrevision, zgsbuild, zgsminor);
ERROR_LOG("creating zerogs\n");
@ -807,15 +803,8 @@ void ProcessMessages()
{
FUNCLOG
XEvent event;
// check resizing
while(XCheckTypedEvent(GLWin.dpy, ConfigureNotify, &event)) {
if ((event.xconfigure.width != GLWin.width) || (event.xconfigure.height != GLWin.height)) {
ZeroGS::ChangeWindowSize(event.xconfigure.width, event.xconfigure.height);
GLWin.width = event.xconfigure.width;
GLWin.height = event.xconfigure.height;
}
}
GLWin.ResizeCheck();
if ( THR_KeyEvent ) { // This values was passed from GSKeyEvents witch could be in another thread
int my_KeyEvent = THR_KeyEvent;
@ -851,11 +840,9 @@ void CALLBACK GSclose() {
GShwnd = NULL;
}
#else
if( GLWin.dpy != NULL ) {
XCloseDisplay(GLWin.dpy);
GLWin.dpy = NULL;
}
GLWin.CloseWindow();
#endif
SaveStateFile = NULL;
SaveStateExists = true; // default value
}
@ -990,12 +977,8 @@ void CALLBACK GSvsync(int interlace)
if( !(conf.options&GSOPTION_FULLSCREEN) )
SetWindowText(GShwnd, strtitle);
#else // linux
XTextProperty prop;
memset(&prop, 0, sizeof(prop));
char* ptitle = strtitle;
if( XStringListToTextProperty(&ptitle, 1, &prop) )
XSetWMName(GLWin.dpy, GLWin.win, &prop);
XFree(prop.value);
if (!(conf.options & GSOPTION_FULLSCREEN))
GLWin.SetTitle(strtitle);
#endif
if( fFPS < 16 ) UPDATE_FRAMES = 4;

View File

@ -57,6 +57,7 @@
<Add library="stdc++" />
<Add library="Cg" />
</Linker>
<Unit filename="../../GLWinX11.cpp" />
<Unit filename="../../GS.h" />
<Unit filename="../../GSmain.cpp" />
<Unit filename="../../GifTransfer.cpp" />

View File

@ -286,6 +286,10 @@
RelativePath="..\GSmain.cpp"
>
</File>
<File
RelativePath="..\GifTransfer.cpp"
>
</File>
<File
RelativePath=".\GSsoftdx.def"
>
@ -402,6 +406,10 @@
RelativePath="..\GS.h"
>
</File>
<File
RelativePath="..\GifTransfer.h"
>
</File>
<File
RelativePath="..\Mem.h"
>

View File

@ -628,7 +628,7 @@ inline void AfterRenderSwapBuffers() {
SwapBuffers(hDC);
lastswaptime = timeGetTime();
#else
glXSwapBuffers(GLWin.dpy, GLWin.win);
GLWin.SwapBuffers();
#endif
}

View File

@ -300,149 +300,9 @@ ZeroGS::Create_Window(int _width, int _height) {
UpdateWindow(GShwnd);
#else //NOT _WIN32
int i;
XVisualInfo *vi;
Colormap cmap;
int dpyWidth, dpyHeight;
int glxMajorVersion, glxMinorVersion;
int vidModeMajorVersion, vidModeMinorVersion;
Atom wmDelete;
Window winDummy;
unsigned int borderDummy;
// attributes for a single buffered visual in RGBA format with at least
// 8 bits per color and a 24 bit depth buffer
int attrListSgl[] = {GLX_RGBA, GLX_RED_SIZE, 8,
GLX_GREEN_SIZE, 8,
GLX_BLUE_SIZE, 8,
GLX_DEPTH_SIZE, 24,
None};
// attributes for a double buffered visual in RGBA format with at least
// 8 bits per color and a 24 bit depth buffer
int attrListDbl[] = { GLX_RGBA, GLX_DOUBLEBUFFER,
GLX_RED_SIZE, 8,
GLX_GREEN_SIZE, 8,
GLX_BLUE_SIZE, 8,
GLX_DEPTH_SIZE, 24,
None };
GLWin.fs = !!(conf.options & GSOPTION_FULLSCREEN);
/* get an appropriate visual */
vi = glXChooseVisual(GLWin.dpy, GLWin.screen, attrListDbl);
if (vi == NULL) {
vi = glXChooseVisual(GLWin.dpy, GLWin.screen, attrListSgl);
GLWin.doubleBuffered = False;
ERROR_LOG("Only Singlebuffered Visual!\n");
}
else {
GLWin.doubleBuffered = True;
ERROR_LOG("Got Doublebuffered Visual!\n");
}
glXQueryVersion(GLWin.dpy, &glxMajorVersion, &glxMinorVersion);
ERROR_LOG("glX-Version %d.%d\n", glxMajorVersion, glxMinorVersion);
/* create a GLX context */
GLWin.ctx = glXCreateContext(GLWin.dpy, vi, 0, GL_TRUE);
/* create a color map */
cmap = XCreateColormap(GLWin.dpy, RootWindow(GLWin.dpy, vi->screen),
vi->visual, AllocNone);
GLWin.attr.colormap = cmap;
GLWin.attr.border_pixel = 0;
// get a connection
XF86VidModeQueryVersion(GLWin.dpy, &vidModeMajorVersion, &vidModeMinorVersion);
if (GLWin.fs) {
XF86VidModeModeInfo **modes = NULL;
int modeNum = 0;
int bestMode = 0;
// set best mode to current
bestMode = 0;
ERROR_LOG("XF86VidModeExtension-Version %d.%d\n", vidModeMajorVersion, vidModeMinorVersion);
XF86VidModeGetAllModeLines(GLWin.dpy, GLWin.screen, &modeNum, &modes);
if( modeNum > 0 && modes != NULL ) {
/* save desktop-resolution before switching modes */
GLWin.deskMode = *modes[0];
/* look for mode with requested resolution */
for (i = 0; i < modeNum; i++) {
if ((modes[i]->hdisplay == _width) && (modes[i]->vdisplay == _height)) {
bestMode = i;
}
}
XF86VidModeSwitchToMode(GLWin.dpy, GLWin.screen, modes[bestMode]);
XF86VidModeSetViewPort(GLWin.dpy, GLWin.screen, 0, 0);
dpyWidth = modes[bestMode]->hdisplay;
dpyHeight = modes[bestMode]->vdisplay;
ERROR_LOG("Resolution %dx%d\n", dpyWidth, dpyHeight);
XFree(modes);
/* create a fullscreen window */
GLWin.attr.override_redirect = True;
GLWin.attr.event_mask = ExposureMask | KeyPressMask | ButtonPressMask |
StructureNotifyMask;
GLWin.win = XCreateWindow(GLWin.dpy, RootWindow(GLWin.dpy, vi->screen),
0, 0, dpyWidth, dpyHeight, 0, vi->depth, InputOutput, vi->visual,
CWBorderPixel | CWColormap | CWEventMask | CWOverrideRedirect,
&GLWin.attr);
XWarpPointer(GLWin.dpy, None, GLWin.win, 0, 0, 0, 0, 0, 0);
XMapRaised(GLWin.dpy, GLWin.win);
XGrabKeyboard(GLWin.dpy, GLWin.win, True, GrabModeAsync,
GrabModeAsync, CurrentTime);
XGrabPointer(GLWin.dpy, GLWin.win, True, ButtonPressMask,
GrabModeAsync, GrabModeAsync, GLWin.win, None, CurrentTime);
}
else {
ERROR_LOG("Failed to start fullscreen. If you received the \n"
"\"XFree86-VidModeExtension\" extension is missing, add\n"
"Load \"extmod\"\n"
"to your X configuration file (under the Module Section)\n");
GLWin.fs = 0;
}
}
if( !GLWin.fs ) {
//XRootWindow(dpy,screen)
//int X = (rcdesktop.right-rcdesktop.left)/2 - (rc.right-rc.left)/2;
//int Y = (rcdesktop.bottom-rcdesktop.top)/2 - (rc.bottom-rc.top)/2;
// create a window in window mode
GLWin.attr.event_mask = ExposureMask | KeyPressMask | ButtonPressMask |
StructureNotifyMask;
GLWin.win = XCreateWindow(GLWin.dpy, RootWindow(GLWin.dpy, vi->screen),
0, 0, _width, _height, 0, vi->depth, InputOutput, vi->visual,
CWBorderPixel | CWColormap | CWEventMask, &GLWin.attr);
// only set window title and handle wm_delete_events if in windowed mode
wmDelete = XInternAtom(GLWin.dpy, "WM_DELETE_WINDOW", True);
XSetWMProtocols(GLWin.dpy, GLWin.win, &wmDelete, 1);
XSetStandardProperties(GLWin.dpy, GLWin.win, "ZeroGS",
"ZeroGS", None, NULL, 0, NULL);
XMapRaised(GLWin.dpy, GLWin.win);
}
// connect the glx-context to the window
glXMakeCurrent(GLWin.dpy, GLWin.win, GLWin.ctx);
XGetGeometry(GLWin.dpy, GLWin.win, &winDummy, &GLWin.x, &GLWin.y,
&GLWin.width, &GLWin.height, &borderDummy, &GLWin.depth);
ERROR_LOG("Depth %d\n", GLWin.depth);
if (glXIsDirect(GLWin.dpy, GLWin.ctx))
ERROR_LOG("you have Direct Rendering!\n");
else
ERROR_LOG("no Direct Rendering possible!\n");
// better for pad plugin key input (thc)
XSelectInput(GLWin.dpy, GLWin.win, ExposureMask | KeyPressMask | KeyReleaseMask |
ButtonPressMask | StructureNotifyMask | EnterWindowMask | LeaveWindowMask |
FocusChangeMask );
GLWin.DisplayWindow(_width, _height);
#endif // WIN32
s_nFullscreen = (conf.options & GSOPTION_FULLSCREEN) ? 1 : 0;
conf.mrtdepth = 0; // for now
@ -1075,22 +935,7 @@ void ZeroGS::Destroy(BOOL bD3D)
hDC=NULL; // Set DC To NULL
}
#else // linux
if (GLWin.ctx)
{
if (!glXMakeCurrent(GLWin.dpy, None, NULL))
{
ERROR_LOG("Could not release drawing context.\n");
}
glXDestroyContext(GLWin.dpy, GLWin.ctx);
GLWin.ctx = NULL;
}
/* switch back to original desktop resolution if we were in fs */
if( GLWin.dpy != NULL ) {
if (GLWin.fs) {
XF86VidModeSwitchToMode(GLWin.dpy, GLWin.screen, &GLWin.deskMode);
XF86VidModeSetViewPort(GLWin.dpy, GLWin.screen, 0, 0);
}
}
GLWin.DestroyWindow();
#endif
mapGLExtensions.clear();

View File

@ -509,7 +509,7 @@ void ZeroGS::RenderCustom(float fAlpha)
#ifdef _WIN32
SwapBuffers(hDC);
#else
glXSwapBuffers(GLWin.dpy, GLWin.win);
GLWin.SwapBuffers();
#endif
glEnable(GL_SCISSOR_TEST);