2012-12-26 18:12:26 +00:00
|
|
|
// Copyright (C) 2003 Dolphin Project.
|
|
|
|
|
|
|
|
// 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, version 2.0.
|
|
|
|
|
|
|
|
// 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 2.0 for more details.
|
|
|
|
|
|
|
|
// A copy of the GPL 2.0 should have been included with the program.
|
|
|
|
// If not, see http://www.gnu.org/licenses/
|
|
|
|
|
|
|
|
// Official SVN repository and contact information can be found at
|
|
|
|
// http://code.google.com/p/dolphin-emu/
|
|
|
|
|
|
|
|
#include "Host.h"
|
|
|
|
#include "VideoConfig.h"
|
2014-01-20 07:46:21 +00:00
|
|
|
#include "GLInterface.h"
|
2012-12-26 18:12:26 +00:00
|
|
|
|
2013-04-20 17:19:03 +00:00
|
|
|
#if USE_EGL
|
|
|
|
bool cXInterface::ServerConnect(void)
|
|
|
|
{
|
2013-04-26 15:53:46 +00:00
|
|
|
GLWin.dpy = XOpenDisplay(NULL);
|
2013-04-20 17:19:03 +00:00
|
|
|
|
2013-04-26 15:53:46 +00:00
|
|
|
if (!GLWin.dpy)
|
2013-04-20 17:19:03 +00:00
|
|
|
return false;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2014-01-24 02:41:07 +00:00
|
|
|
bool cXInterface::Initialize(void *config, void *window_handle)
|
2013-04-20 17:19:03 +00:00
|
|
|
{
|
|
|
|
int _tx, _ty, _twidth, _theight;
|
|
|
|
XVisualInfo visTemplate;
|
|
|
|
int num_visuals;
|
|
|
|
EGLint vid;
|
|
|
|
|
2013-04-26 15:53:46 +00:00
|
|
|
if (!GLWin.dpy) {
|
2013-04-20 17:19:03 +00:00
|
|
|
printf("Error: couldn't open X display\n");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!eglGetConfigAttrib(GLWin.egl_dpy, config, EGL_NATIVE_VISUAL_ID, &vid)) {
|
|
|
|
printf("Error: eglGetConfigAttrib() failed\n");
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* The X window visual must match the EGL config */
|
|
|
|
visTemplate.visualid = vid;
|
2013-04-26 15:53:46 +00:00
|
|
|
GLWin.vi = XGetVisualInfo(GLWin.dpy, VisualIDMask, &visTemplate, &num_visuals);
|
2013-04-20 17:19:03 +00:00
|
|
|
if (!GLWin.vi) {
|
|
|
|
printf("Error: couldn't get X visual\n");
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
Host_GetRenderWindowSize(_tx, _ty, _twidth, _theight);
|
|
|
|
|
|
|
|
GLWin.x = _tx;
|
|
|
|
GLWin.y = _ty;
|
|
|
|
GLWin.width = _twidth;
|
|
|
|
GLWin.height = _theight;
|
|
|
|
|
2013-04-26 15:53:46 +00:00
|
|
|
GLWin.evdpy = XOpenDisplay(NULL);
|
2014-01-24 02:41:07 +00:00
|
|
|
GLWin.parent = (Window) window_handle;
|
2013-04-26 15:53:46 +00:00
|
|
|
GLWin.screen = DefaultScreen(GLWin.dpy);
|
2013-04-20 17:19:03 +00:00
|
|
|
|
|
|
|
if (GLWin.parent == 0)
|
2013-04-26 15:53:46 +00:00
|
|
|
GLWin.parent = RootWindow(GLWin.dpy, GLWin.screen);
|
2013-04-20 17:19:03 +00:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void *cXInterface::EGLGetDisplay(void)
|
|
|
|
{
|
2014-01-20 02:06:55 +00:00
|
|
|
#if HAVE_WAYLAND
|
|
|
|
return eglGetDisplay((wl_display *) GLWin.dpy);
|
|
|
|
#else
|
2013-04-26 15:53:46 +00:00
|
|
|
return eglGetDisplay(GLWin.dpy);
|
2014-01-20 02:06:55 +00:00
|
|
|
#endif
|
2013-04-20 17:19:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void *cXInterface::CreateWindow(void)
|
|
|
|
{
|
|
|
|
Atom wmProtocols[1];
|
|
|
|
|
|
|
|
// Setup window attributes
|
2013-04-26 15:53:46 +00:00
|
|
|
GLWin.attr.colormap = XCreateColormap(GLWin.evdpy,
|
2013-04-20 17:19:03 +00:00
|
|
|
GLWin.parent, GLWin.vi->visual, AllocNone);
|
|
|
|
GLWin.attr.event_mask = KeyPressMask | StructureNotifyMask | FocusChangeMask;
|
2013-04-26 15:53:46 +00:00
|
|
|
GLWin.attr.background_pixel = BlackPixel(GLWin.evdpy, GLWin.screen);
|
2013-04-20 17:19:03 +00:00
|
|
|
GLWin.attr.border_pixel = 0;
|
|
|
|
|
|
|
|
// Create the window
|
2013-04-26 15:53:46 +00:00
|
|
|
GLWin.win = XCreateWindow(GLWin.evdpy, GLWin.parent,
|
2013-04-20 17:19:03 +00:00
|
|
|
GLWin.x, GLWin.y, GLWin.width, GLWin.height, 0,
|
|
|
|
GLWin.vi->depth, InputOutput, GLWin.vi->visual,
|
|
|
|
CWBorderPixel | CWBackPixel | CWColormap | CWEventMask, &GLWin.attr);
|
2013-04-26 15:53:46 +00:00
|
|
|
wmProtocols[0] = XInternAtom(GLWin.evdpy, "WM_DELETE_WINDOW", True);
|
|
|
|
XSetWMProtocols(GLWin.evdpy, GLWin.win, wmProtocols, 1);
|
|
|
|
XSetStandardProperties(GLWin.evdpy, GLWin.win, "GPU", "GPU", None, NULL, 0, NULL);
|
|
|
|
XMapRaised(GLWin.evdpy, GLWin.win);
|
|
|
|
XSync(GLWin.evdpy, True);
|
2013-04-20 17:19:03 +00:00
|
|
|
|
|
|
|
GLWin.xEventThread = std::thread(&cXInterface::XEventThread, this);
|
|
|
|
// Control window size and picture scaling
|
|
|
|
GLInterface->SetBackBufferDimensions(GLWin.width, GLWin.height);
|
|
|
|
|
|
|
|
return (void *) GLWin.win;
|
|
|
|
}
|
|
|
|
|
|
|
|
void cXInterface::DestroyWindow(void)
|
|
|
|
{
|
2013-04-26 15:53:46 +00:00
|
|
|
XDestroyWindow(GLWin.evdpy, GLWin.win);
|
2013-04-20 17:19:03 +00:00
|
|
|
GLWin.win = 0;
|
|
|
|
if (GLWin.xEventThread.joinable())
|
|
|
|
GLWin.xEventThread.join();
|
2013-04-26 15:53:46 +00:00
|
|
|
XFreeColormap(GLWin.evdpy, GLWin.attr.colormap);
|
2013-04-20 17:19:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void cXInterface::UpdateFPSDisplay(const char *text)
|
|
|
|
{
|
2013-04-26 15:53:46 +00:00
|
|
|
XStoreName(GLWin.evdpy, GLWin.win, text);
|
2013-04-20 17:19:03 +00:00
|
|
|
}
|
|
|
|
|
2014-01-19 16:11:07 +00:00
|
|
|
void cXInterface::SwapBuffers()
|
|
|
|
{
|
|
|
|
eglSwapBuffers(GLWin.egl_dpy, GLWin.egl_surf);
|
|
|
|
}
|
|
|
|
|
2013-04-20 17:19:03 +00:00
|
|
|
void cXInterface::XEventThread()
|
|
|
|
#else
|
2012-12-26 18:12:26 +00:00
|
|
|
void cX11Window::CreateXWindow(void)
|
|
|
|
{
|
|
|
|
Atom wmProtocols[1];
|
|
|
|
|
|
|
|
// Setup window attributes
|
|
|
|
GLWin.attr.colormap = XCreateColormap(GLWin.evdpy,
|
|
|
|
GLWin.parent, GLWin.vi->visual, AllocNone);
|
|
|
|
GLWin.attr.event_mask = KeyPressMask | StructureNotifyMask | FocusChangeMask;
|
|
|
|
GLWin.attr.background_pixel = BlackPixel(GLWin.evdpy, GLWin.screen);
|
|
|
|
GLWin.attr.border_pixel = 0;
|
|
|
|
|
|
|
|
// Create the window
|
|
|
|
GLWin.win = XCreateWindow(GLWin.evdpy, GLWin.parent,
|
|
|
|
GLWin.x, GLWin.y, GLWin.width, GLWin.height, 0,
|
|
|
|
GLWin.vi->depth, InputOutput, GLWin.vi->visual,
|
|
|
|
CWBorderPixel | CWBackPixel | CWColormap | CWEventMask, &GLWin.attr);
|
|
|
|
wmProtocols[0] = XInternAtom(GLWin.evdpy, "WM_DELETE_WINDOW", True);
|
|
|
|
XSetWMProtocols(GLWin.evdpy, GLWin.win, wmProtocols, 1);
|
|
|
|
XSetStandardProperties(GLWin.evdpy, GLWin.win, "GPU", "GPU", None, NULL, 0, NULL);
|
|
|
|
XMapRaised(GLWin.evdpy, GLWin.win);
|
|
|
|
XSync(GLWin.evdpy, True);
|
|
|
|
|
|
|
|
GLWin.xEventThread = std::thread(&cX11Window::XEventThread, this);
|
|
|
|
}
|
|
|
|
|
|
|
|
void cX11Window::DestroyXWindow(void)
|
|
|
|
{
|
2013-04-26 04:41:45 +00:00
|
|
|
XUnmapWindow(GLWin.evdpy, GLWin.win);
|
2012-12-26 18:12:26 +00:00
|
|
|
GLWin.win = 0;
|
|
|
|
if (GLWin.xEventThread.joinable())
|
|
|
|
GLWin.xEventThread.join();
|
|
|
|
XFreeColormap(GLWin.evdpy, GLWin.attr.colormap);
|
|
|
|
}
|
|
|
|
|
|
|
|
void cX11Window::XEventThread()
|
2013-04-20 17:19:03 +00:00
|
|
|
#endif
|
2012-12-26 18:12:26 +00:00
|
|
|
{
|
|
|
|
while (GLWin.win)
|
|
|
|
{
|
|
|
|
XEvent event;
|
2013-04-26 04:41:45 +00:00
|
|
|
for (int num_events = XPending(GLWin.evdpy); num_events > 0; num_events--)
|
2012-12-26 18:12:26 +00:00
|
|
|
{
|
2013-04-26 04:41:45 +00:00
|
|
|
XNextEvent(GLWin.evdpy, &event);
|
2012-12-26 18:12:26 +00:00
|
|
|
switch(event.type) {
|
|
|
|
case ConfigureNotify:
|
2013-07-21 05:02:10 +00:00
|
|
|
GLInterface->SetBackBufferDimensions(event.xconfigure.width, event.xconfigure.height);
|
2012-12-26 18:12:26 +00:00
|
|
|
break;
|
|
|
|
case ClientMessage:
|
|
|
|
if ((unsigned long) event.xclient.data.l[0] ==
|
2013-04-26 04:41:45 +00:00
|
|
|
XInternAtom(GLWin.evdpy, "WM_DELETE_WINDOW", False))
|
2012-12-26 18:12:26 +00:00
|
|
|
Host_Message(WM_USER_STOP);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
Common::SleepCurrentThread(20);
|
|
|
|
}
|
|
|
|
}
|