2010-04-25 00:31:27 +00:00
|
|
|
/*
|
2009-02-09 21:15:56 +00:00
|
|
|
* Copyright (C) 2007-2009 Gabest
|
|
|
|
* http://www.gabest.org
|
|
|
|
*
|
|
|
|
* 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, or (at your option)
|
|
|
|
* any later version.
|
2010-04-25 00:31:27 +00:00
|
|
|
*
|
2009-02-09 21:15:56 +00:00
|
|
|
* 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.
|
2010-04-25 00:31:27 +00:00
|
|
|
*
|
2009-02-09 21:15:56 +00:00
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with GNU Make; see the file COPYING. If not, write to
|
2010-04-25 00:31:27 +00:00
|
|
|
* the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
|
2009-02-09 21:15:56 +00:00
|
|
|
* http://www.gnu.org/copyleft/gpl.html
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2011-02-19 03:36:30 +00:00
|
|
|
#include "stdafx.h"
|
2009-05-18 11:08:04 +00:00
|
|
|
#include "GSdx.h"
|
2009-02-09 21:15:56 +00:00
|
|
|
#include "GSWnd.h"
|
|
|
|
|
2011-02-23 09:16:00 +00:00
|
|
|
#ifdef _WINDOWS
|
|
|
|
|
2009-02-09 21:15:56 +00:00
|
|
|
GSWnd::GSWnd()
|
2009-06-03 12:09:04 +00:00
|
|
|
: m_hWnd(NULL)
|
2011-02-24 04:55:35 +00:00
|
|
|
, m_managed(true)
|
2011-02-23 09:16:00 +00:00
|
|
|
, m_frame(true)
|
2009-02-09 21:15:56 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
GSWnd::~GSWnd()
|
|
|
|
{
|
2009-06-03 12:09:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
LRESULT CALLBACK GSWnd::WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
|
|
|
|
{
|
|
|
|
GSWnd* wnd = NULL;
|
|
|
|
|
|
|
|
if(message == WM_NCCREATE)
|
|
|
|
{
|
|
|
|
wnd = (GSWnd*)((LPCREATESTRUCT)lParam)->lpCreateParams;
|
|
|
|
|
2011-02-12 21:45:16 +00:00
|
|
|
SetWindowLongPtr(hWnd, GWLP_USERDATA, (LONG_PTR)wnd);
|
2009-06-03 12:09:04 +00:00
|
|
|
|
|
|
|
wnd->m_hWnd = hWnd;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2011-02-12 21:45:16 +00:00
|
|
|
wnd = (GSWnd*)GetWindowLongPtr(hWnd, GWLP_USERDATA);
|
2009-06-03 12:09:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if(wnd == NULL)
|
|
|
|
{
|
|
|
|
return DefWindowProc(hWnd, message, wParam, lParam);
|
|
|
|
}
|
|
|
|
|
|
|
|
return wnd->OnMessage(message, wParam, lParam);
|
|
|
|
}
|
|
|
|
|
|
|
|
LRESULT GSWnd::OnMessage(UINT message, WPARAM wParam, LPARAM lParam)
|
|
|
|
{
|
|
|
|
switch(message)
|
|
|
|
{
|
|
|
|
case WM_CLOSE:
|
|
|
|
Hide();
|
|
|
|
// DestroyWindow(m_hWnd);
|
|
|
|
return 0;
|
|
|
|
case WM_DESTROY:
|
2009-09-18 23:48:12 +00:00
|
|
|
// This kills the emulator when GS is closed, which *really* isn't desired behavior,
|
|
|
|
// especially in STGS mode (worked in MTGS mode since it only quit the thread, but even
|
|
|
|
// that wasn't needed).
|
2009-09-18 22:13:40 +00:00
|
|
|
//PostQuitMessage(0);
|
2009-06-03 12:09:04 +00:00
|
|
|
return 0;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2011-02-19 03:36:30 +00:00
|
|
|
return DefWindowProc((HWND)m_hWnd, message, wParam, lParam);
|
2009-02-09 21:15:56 +00:00
|
|
|
}
|
|
|
|
|
2009-07-17 23:45:32 +00:00
|
|
|
bool GSWnd::Create(const string& title, int w, int h)
|
2009-02-09 21:15:56 +00:00
|
|
|
{
|
2011-02-23 09:16:00 +00:00
|
|
|
if(m_hWnd) return false;
|
2010-04-25 00:31:27 +00:00
|
|
|
|
2009-06-03 12:09:04 +00:00
|
|
|
WNDCLASS wc;
|
|
|
|
|
|
|
|
memset(&wc, 0, sizeof(wc));
|
2009-02-09 21:15:56 +00:00
|
|
|
|
2009-06-03 12:09:04 +00:00
|
|
|
wc.style = CS_HREDRAW | CS_VREDRAW | CS_DBLCLKS;
|
|
|
|
wc.lpfnWndProc = WndProc;
|
|
|
|
wc.hInstance = theApp.GetModuleHandle();
|
|
|
|
// TODO: wc.hIcon = ;
|
|
|
|
wc.hCursor = LoadCursor(NULL, IDC_ARROW);
|
|
|
|
wc.hbrBackground = (HBRUSH)GetStockObject(BLACK_BRUSH);
|
|
|
|
wc.lpszClassName = "GSWnd";
|
2009-02-09 21:15:56 +00:00
|
|
|
|
2009-06-04 00:15:05 +00:00
|
|
|
if(!GetClassInfo(wc.hInstance, wc.lpszClassName, &wc))
|
2009-06-03 12:09:04 +00:00
|
|
|
{
|
2009-06-04 00:15:05 +00:00
|
|
|
if(!RegisterClass(&wc))
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
2009-06-03 12:09:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
DWORD style = WS_CLIPCHILDREN | WS_CLIPSIBLINGS | WS_OVERLAPPEDWINDOW | WS_BORDER;
|
|
|
|
|
2009-07-17 23:45:32 +00:00
|
|
|
GSVector4i r;
|
|
|
|
|
|
|
|
GetWindowRect(GetDesktopWindow(), r);
|
|
|
|
|
|
|
|
bool remote = !!GetSystemMetrics(SM_REMOTESESSION);
|
|
|
|
|
2010-04-25 00:31:27 +00:00
|
|
|
if(w <= 0 || h <= 0 || remote)
|
2009-07-17 23:45:32 +00:00
|
|
|
{
|
|
|
|
w = r.width() / 3;
|
|
|
|
h = r.width() / 4;
|
|
|
|
|
|
|
|
if(!remote)
|
|
|
|
{
|
|
|
|
w *= 2;
|
|
|
|
h *= 2;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
r.left = (r.left + r.right - w) / 2;
|
|
|
|
r.top = (r.top + r.bottom - h) / 2;
|
|
|
|
r.right = r.left + w;
|
|
|
|
r.bottom = r.top + h;
|
|
|
|
|
|
|
|
AdjustWindowRect(r, style, FALSE);
|
|
|
|
|
|
|
|
m_hWnd = CreateWindow(wc.lpszClassName, title.c_str(), style, r.left, r.top, r.width(), r.height(), NULL, NULL, wc.hInstance, (LPVOID)this);
|
2009-06-03 12:09:04 +00:00
|
|
|
|
2011-02-23 09:16:00 +00:00
|
|
|
return m_hWnd != NULL;
|
2009-06-03 12:09:04 +00:00
|
|
|
}
|
|
|
|
|
2011-02-23 09:16:00 +00:00
|
|
|
bool GSWnd::Attach(void* handle, bool managed)
|
2009-06-03 12:09:04 +00:00
|
|
|
{
|
|
|
|
// TODO: subclass
|
|
|
|
|
2011-02-23 09:25:13 +00:00
|
|
|
m_hWnd = (HWND)handle;
|
2011-02-23 09:16:00 +00:00
|
|
|
m_managed = managed;
|
2009-06-03 12:09:04 +00:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2009-09-17 07:40:38 +00:00
|
|
|
void GSWnd::Detach()
|
|
|
|
{
|
2011-02-23 09:16:00 +00:00
|
|
|
if(m_hWnd && m_managed)
|
2009-09-18 22:13:40 +00:00
|
|
|
{
|
|
|
|
// close the window, since it's under GSdx care. It's not taking messages anyway, and
|
|
|
|
// that means its big, ugly, and in the way.
|
2011-02-19 03:36:30 +00:00
|
|
|
|
2011-02-23 09:16:00 +00:00
|
|
|
DestroyWindow(m_hWnd);
|
2009-09-18 22:13:40 +00:00
|
|
|
}
|
2011-02-18 01:56:05 +00:00
|
|
|
|
2009-09-17 07:40:38 +00:00
|
|
|
m_hWnd = NULL;
|
2011-02-24 04:55:35 +00:00
|
|
|
m_managed = true;
|
2009-09-17 07:40:38 +00:00
|
|
|
}
|
|
|
|
|
2009-06-03 12:09:04 +00:00
|
|
|
GSVector4i GSWnd::GetClientRect()
|
|
|
|
{
|
|
|
|
GSVector4i r;
|
|
|
|
|
2011-02-23 09:16:00 +00:00
|
|
|
::GetClientRect(m_hWnd, r);
|
2010-04-25 00:31:27 +00:00
|
|
|
|
2009-06-03 12:09:04 +00:00
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
2009-09-17 07:40:38 +00:00
|
|
|
// Returns FALSE if the window has no title, or if th window title is under the strict
|
|
|
|
// management of the emulator.
|
2011-02-07 01:59:05 +00:00
|
|
|
|
2009-09-17 07:40:38 +00:00
|
|
|
bool GSWnd::SetWindowText(const char* title)
|
2009-06-03 12:09:04 +00:00
|
|
|
{
|
2011-02-23 09:16:00 +00:00
|
|
|
if(!m_managed) return false;
|
2011-02-19 03:36:30 +00:00
|
|
|
|
2011-02-23 09:16:00 +00:00
|
|
|
::SetWindowText(m_hWnd, title);
|
2009-09-17 07:40:38 +00:00
|
|
|
|
2011-02-23 09:16:00 +00:00
|
|
|
return m_frame;
|
2009-02-09 21:15:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void GSWnd::Show()
|
|
|
|
{
|
2011-02-23 09:16:00 +00:00
|
|
|
if(!m_managed) return;
|
2009-09-17 07:40:38 +00:00
|
|
|
|
2011-02-23 09:16:00 +00:00
|
|
|
SetForegroundWindow(m_hWnd);
|
|
|
|
ShowWindow(m_hWnd, SW_SHOWNORMAL);
|
|
|
|
UpdateWindow(m_hWnd);
|
|
|
|
}
|
2011-02-19 03:36:30 +00:00
|
|
|
|
2011-02-23 09:16:00 +00:00
|
|
|
void GSWnd::Hide()
|
|
|
|
{
|
|
|
|
if(!m_managed) return;
|
|
|
|
|
|
|
|
ShowWindow(m_hWnd, SW_HIDE);
|
|
|
|
}
|
2010-04-25 00:31:27 +00:00
|
|
|
|
2011-02-23 09:16:00 +00:00
|
|
|
void GSWnd::HideFrame()
|
|
|
|
{
|
|
|
|
if(!m_managed) return;
|
2011-02-19 03:36:30 +00:00
|
|
|
|
2011-02-23 09:16:00 +00:00
|
|
|
SetWindowLong(m_hWnd, GWL_STYLE, GetWindowLong(m_hWnd, GWL_STYLE) & ~(WS_CAPTION|WS_THICKFRAME));
|
|
|
|
SetWindowPos(m_hWnd, NULL, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE | SWP_NOZORDER | SWP_NOACTIVATE);
|
|
|
|
SetMenu(m_hWnd, NULL);
|
2011-02-19 03:36:30 +00:00
|
|
|
|
2011-02-23 09:16:00 +00:00
|
|
|
m_frame = false;
|
|
|
|
}
|
2011-02-19 03:36:30 +00:00
|
|
|
|
|
|
|
#else
|
2010-04-25 00:31:27 +00:00
|
|
|
|
2011-02-24 23:46:26 +00:00
|
|
|
GSWnd::GSWnd()
|
2011-06-12 14:48:36 +00:00
|
|
|
: m_window(NULL), m_Xwindow(0), m_XDisplay(NULL)
|
2011-02-24 23:46:26 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
GSWnd::~GSWnd()
|
|
|
|
{
|
2012-01-04 23:19:17 +00:00
|
|
|
#ifdef ENABLE_SDL_DEV
|
2011-06-12 14:48:36 +00:00
|
|
|
if(m_window != NULL && m_managed)
|
2011-02-24 23:46:26 +00:00
|
|
|
{
|
|
|
|
SDL_DestroyWindow(m_window);
|
2011-03-12 22:38:07 +00:00
|
|
|
m_window = NULL;
|
|
|
|
}
|
2012-01-04 23:19:17 +00:00
|
|
|
#endif
|
2011-06-12 14:48:36 +00:00
|
|
|
if (m_XDisplay) {
|
|
|
|
XCloseDisplay(m_XDisplay);
|
|
|
|
m_XDisplay = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-01-06 21:43:39 +00:00
|
|
|
bool GSWnd::CreateContext(int major, int minor)
|
|
|
|
{
|
|
|
|
if ( !m_XDisplay || !m_Xwindow )
|
|
|
|
{
|
|
|
|
fprintf( stderr, "Wrong X11 display/window\n" );
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Get visual information
|
|
|
|
static int attrListDbl[] =
|
|
|
|
{
|
|
|
|
GLX_X_RENDERABLE , True,
|
|
|
|
GLX_DRAWABLE_TYPE , GLX_WINDOW_BIT,
|
|
|
|
GLX_RENDER_TYPE , GLX_RGBA_BIT,
|
|
|
|
GLX_RED_SIZE , 8,
|
|
|
|
GLX_GREEN_SIZE , 8,
|
|
|
|
GLX_BLUE_SIZE , 8,
|
|
|
|
GLX_DEPTH_SIZE , 24,
|
|
|
|
GLX_DOUBLEBUFFER , True,
|
|
|
|
None
|
|
|
|
};
|
|
|
|
|
|
|
|
PFNGLXCHOOSEFBCONFIGPROC glXChooseFBConfig = (PFNGLXCHOOSEFBCONFIGPROC) glXGetProcAddress((GLubyte *) "glXChooseFBConfig");
|
|
|
|
int fbcount = 0;
|
|
|
|
GLXFBConfig *fbc = glXChooseFBConfig(m_XDisplay, DefaultScreen(m_XDisplay), attrListDbl, &fbcount);
|
|
|
|
if (!fbc || fbcount < 1) return false;
|
|
|
|
|
|
|
|
PFNGLXCREATECONTEXTATTRIBSARBPROC glXCreateContextAttribsARB = (PFNGLXCREATECONTEXTATTRIBSARBPROC)glXGetProcAddress((const GLubyte*) "glXCreateContextAttribsARB");
|
|
|
|
if (!glXCreateContextAttribsARB) return false;
|
|
|
|
|
|
|
|
// Create a context
|
|
|
|
int context_attribs[] =
|
|
|
|
{
|
|
|
|
GLX_CONTEXT_MAJOR_VERSION_ARB, major,
|
|
|
|
GLX_CONTEXT_MINOR_VERSION_ARB, minor,
|
|
|
|
// FIXME : Request a debug context to ease opengl development
|
|
|
|
// Note: don't support deprecated feature (pre openg 3.1)
|
|
|
|
//GLX_CONTEXT_FLAGS_ARB, GLX_CONTEXT_DEBUG_BIT_ARB | GLX_CONTEXT_FORWARD_COMPATIBLE_BIT_ARB,
|
|
|
|
GLX_CONTEXT_FLAGS_ARB, GLX_CONTEXT_DEBUG_BIT_ARB,
|
|
|
|
None
|
|
|
|
};
|
|
|
|
|
|
|
|
m_context = glXCreateContextAttribsARB(m_XDisplay, fbc[0], 0, true, context_attribs);
|
|
|
|
if (!m_context) return false;
|
|
|
|
|
|
|
|
XSync( m_XDisplay, false);
|
|
|
|
}
|
|
|
|
|
|
|
|
void GSWnd::AttachContext()
|
|
|
|
{
|
|
|
|
glXMakeCurrent(m_XDisplay, m_Xwindow, m_context);
|
|
|
|
}
|
|
|
|
|
|
|
|
void GSWnd::DetachContext()
|
|
|
|
{
|
|
|
|
glXMakeCurrent(m_XDisplay, None, NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
void GSWnd::CheckContext()
|
|
|
|
{
|
|
|
|
int glxMajorVersion, glxMinorVersion;
|
|
|
|
glXQueryVersion(m_XDisplay, &glxMajorVersion, &glxMinorVersion);
|
|
|
|
if (glXIsDirect(m_XDisplay, m_context))
|
|
|
|
fprintf(stderr, "glX-Version %d.%d with Direct Rendering\n", glxMajorVersion, glxMinorVersion);
|
|
|
|
else
|
|
|
|
fprintf(stderr, "glX-Version %d.%d with Indirect Rendering !!! It will be slow\n", glxMajorVersion, glxMinorVersion);
|
|
|
|
}
|
|
|
|
|
2011-06-12 14:48:36 +00:00
|
|
|
bool GSWnd::Attach(void* handle, bool managed)
|
|
|
|
{
|
|
|
|
m_Xwindow = *(Window*)handle;
|
|
|
|
m_managed = managed;
|
|
|
|
|
2011-12-08 11:17:59 +00:00
|
|
|
m_renderer = theApp.GetConfig("renderer", 0) / 3;
|
2011-12-07 22:05:46 +00:00
|
|
|
if (m_renderer != 2) {
|
|
|
|
m_XDisplay = XOpenDisplay(NULL);
|
|
|
|
|
2012-01-06 21:43:39 +00:00
|
|
|
// Note: 4.2 crash on latest nvidia drivers!
|
|
|
|
if (!CreateContext(3, 3)) return false;
|
2011-12-07 22:05:46 +00:00
|
|
|
|
2012-01-06 21:43:39 +00:00
|
|
|
AttachContext();
|
|
|
|
|
|
|
|
CheckContext();
|
2011-12-07 22:05:46 +00:00
|
|
|
}
|
|
|
|
|
2011-06-12 14:48:36 +00:00
|
|
|
return true;
|
2011-03-12 22:38:07 +00:00
|
|
|
}
|
|
|
|
|
2011-04-09 06:28:28 +00:00
|
|
|
void GSWnd::Detach()
|
2011-03-12 22:38:07 +00:00
|
|
|
{
|
2011-06-12 14:48:36 +00:00
|
|
|
// Actually the destructor is not called when there is only a GSclose/GSshutdown
|
|
|
|
// The window still need to be closed
|
2011-12-07 22:05:46 +00:00
|
|
|
if (m_renderer == 2) {
|
2012-01-04 23:19:17 +00:00
|
|
|
#ifdef ENABLE_SDL_DEV
|
2011-12-07 22:05:46 +00:00
|
|
|
if(m_window != NULL && m_managed)
|
|
|
|
{
|
|
|
|
SDL_DestroyWindow(m_window);
|
|
|
|
m_window = NULL;
|
|
|
|
}
|
2012-01-04 23:19:17 +00:00
|
|
|
#endif
|
2011-12-07 22:05:46 +00:00
|
|
|
} else {
|
2012-01-06 21:43:39 +00:00
|
|
|
DetachContext();
|
2011-12-07 22:05:46 +00:00
|
|
|
if (m_context) glXDestroyContext(m_XDisplay, m_context);
|
2011-02-24 23:46:26 +00:00
|
|
|
}
|
2011-06-12 14:48:36 +00:00
|
|
|
if (m_XDisplay) {
|
|
|
|
XCloseDisplay(m_XDisplay);
|
|
|
|
m_XDisplay = NULL;
|
|
|
|
}
|
2011-02-24 23:46:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool GSWnd::Create(const string& title, int w, int h)
|
|
|
|
{
|
|
|
|
if(m_window != NULL) return false;
|
|
|
|
|
2011-04-07 09:41:20 +00:00
|
|
|
if(w <= 0 || h <= 0) {
|
2011-04-08 17:41:04 +00:00
|
|
|
w = theApp.GetConfig("ModeWidth", 640);
|
|
|
|
h = theApp.GetConfig("ModeHeight", 480);
|
2011-04-07 09:41:20 +00:00
|
|
|
}
|
2011-02-24 23:46:26 +00:00
|
|
|
|
2011-06-12 14:48:36 +00:00
|
|
|
m_managed = true;
|
2011-11-16 22:17:37 +00:00
|
|
|
|
2012-01-12 07:29:31 +00:00
|
|
|
if (m_renderer == 2) {
|
|
|
|
#ifdef ENABLE_SDL_DEV
|
2011-06-12 14:48:36 +00:00
|
|
|
|
2012-01-12 07:29:31 +00:00
|
|
|
#ifdef _LINUX
|
|
|
|
// When you reconfigure the plugins during the play, SDL is shutdown so SDL_GetNumVideoDisplays return 0
|
|
|
|
// and the plugins is badly closed. NOTE: SDL is initialized in SDL_CreateWindow.
|
|
|
|
//
|
|
|
|
// I'm not sure this sanity check is still useful, normally (I hope) SDL_CreateWindow will return a null
|
|
|
|
// hence a false for this current function.
|
|
|
|
// For the moment do an init -- Gregory
|
|
|
|
if(!SDL_WasInit(SDL_INIT_VIDEO))
|
|
|
|
if(SDL_Init(SDL_INIT_VIDEO) < 0) return false;
|
|
|
|
|
|
|
|
// Sanity check; if there aren't any video displays available, we can't create a window.
|
|
|
|
if (SDL_GetNumVideoDisplays() <= 0) return false;
|
|
|
|
#endif
|
2011-06-12 14:48:36 +00:00
|
|
|
|
2012-01-12 07:29:31 +00:00
|
|
|
m_window = SDL_CreateWindow(title.c_str(), 100, 100, w, h, SDL_WINDOW_OPENGL | SDL_WINDOW_SHOWN | SDL_WINDOW_RESIZABLE);
|
2011-06-12 14:48:36 +00:00
|
|
|
|
2012-01-12 07:29:31 +00:00
|
|
|
// Get the X window from the newly created window
|
|
|
|
// It would be needed to get the current size
|
|
|
|
SDL_SysWMinfo wminfo;
|
|
|
|
memset(&wminfo, 0, sizeof(wminfo));
|
2012-01-06 21:43:39 +00:00
|
|
|
|
2012-01-12 07:29:31 +00:00
|
|
|
wminfo.version.major = SDL_MAJOR_VERSION;
|
|
|
|
wminfo.version.minor = SDL_MINOR_VERSION;
|
2012-01-06 21:43:39 +00:00
|
|
|
|
2012-01-12 07:29:31 +00:00
|
|
|
SDL_GetWindowWMInfo(m_window, &wminfo);
|
|
|
|
m_Xwindow = wminfo.info.x11.window;
|
2012-01-06 21:43:39 +00:00
|
|
|
|
2012-01-12 07:29:31 +00:00
|
|
|
#endif
|
|
|
|
return (m_window != NULL);
|
2012-01-06 21:43:39 +00:00
|
|
|
|
2012-01-12 07:29:31 +00:00
|
|
|
} else {
|
2012-01-06 21:43:39 +00:00
|
|
|
|
2012-01-12 07:29:31 +00:00
|
|
|
// note this part must be only executed when replaying .gs debug file
|
|
|
|
m_XDisplay = XOpenDisplay(NULL);
|
2012-01-06 21:43:39 +00:00
|
|
|
|
2012-01-12 07:29:31 +00:00
|
|
|
int attrListDbl[] = { GLX_RGBA, GLX_DOUBLEBUFFER,
|
|
|
|
GLX_RED_SIZE, 8,
|
|
|
|
GLX_GREEN_SIZE, 8,
|
|
|
|
GLX_BLUE_SIZE, 8,
|
|
|
|
GLX_DEPTH_SIZE, 24,
|
|
|
|
None
|
|
|
|
};
|
|
|
|
XVisualInfo* vi = glXChooseVisual(m_XDisplay, DefaultScreen(m_XDisplay), attrListDbl);
|
|
|
|
|
|
|
|
/* create a color map */
|
|
|
|
XSetWindowAttributes attr;
|
|
|
|
attr.colormap = XCreateColormap(m_XDisplay, RootWindow(m_XDisplay, vi->screen),
|
|
|
|
vi->visual, AllocNone);
|
|
|
|
attr.border_pixel = 0;
|
|
|
|
attr.event_mask = ExposureMask | KeyPressMask | KeyReleaseMask | ButtonPressMask |
|
|
|
|
StructureNotifyMask | SubstructureRedirectMask | SubstructureNotifyMask |
|
|
|
|
EnterWindowMask | LeaveWindowMask | FocusChangeMask ;
|
|
|
|
|
|
|
|
// Create a window at the last position/size
|
|
|
|
m_Xwindow = XCreateWindow(m_XDisplay, RootWindow(m_XDisplay, vi->screen),
|
|
|
|
0 , 0 , w, h, 0, vi->depth, InputOutput, vi->visual,
|
|
|
|
CWBorderPixel | CWColormap | CWEventMask, &attr);
|
|
|
|
|
|
|
|
XMapWindow (m_XDisplay, m_Xwindow);
|
|
|
|
XFree(vi);
|
2012-01-06 21:43:39 +00:00
|
|
|
|
2012-01-12 07:29:31 +00:00
|
|
|
if (!CreateContext(3, 3)) return false;
|
2012-01-06 21:43:39 +00:00
|
|
|
|
2012-01-12 07:29:31 +00:00
|
|
|
AttachContext();
|
2012-01-06 21:43:39 +00:00
|
|
|
|
2012-01-12 07:29:31 +00:00
|
|
|
return (m_Xwindow != 0);
|
|
|
|
}
|
2011-02-24 23:46:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Display* GSWnd::GetDisplay()
|
|
|
|
{
|
2012-01-04 23:19:17 +00:00
|
|
|
#ifdef ENABLE_SDL_DEV
|
2011-02-24 23:46:26 +00:00
|
|
|
SDL_SysWMinfo wminfo;
|
|
|
|
|
|
|
|
memset(&wminfo, 0, sizeof(wminfo));
|
|
|
|
|
|
|
|
wminfo.version.major = SDL_MAJOR_VERSION;
|
|
|
|
wminfo.version.minor = SDL_MINOR_VERSION;
|
|
|
|
|
|
|
|
SDL_GetWindowWMInfo(m_window, &wminfo);
|
|
|
|
|
|
|
|
return wminfo.subsystem == SDL_SYSWM_X11 ? wminfo.info.x11.display : NULL;
|
2012-01-04 23:19:17 +00:00
|
|
|
#else
|
2012-01-06 21:43:39 +00:00
|
|
|
// note this part must be only executed when replaying .gs debug file
|
|
|
|
return m_XDisplay;
|
2012-01-04 23:19:17 +00:00
|
|
|
#endif
|
2011-02-24 23:46:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
GSVector4i GSWnd::GetClientRect()
|
|
|
|
{
|
2011-06-12 14:48:36 +00:00
|
|
|
unsigned int h = 480;
|
|
|
|
unsigned int w = 640;
|
|
|
|
|
|
|
|
unsigned int borderDummy;
|
|
|
|
unsigned int depthDummy;
|
|
|
|
Window winDummy;
|
|
|
|
int xDummy;
|
|
|
|
int yDummy;
|
|
|
|
|
|
|
|
// In gsopen2, pcsx2 stoles all event (including resize event). SDL is not able to update its structure
|
|
|
|
// so you must do it yourself
|
|
|
|
// In perfect world:
|
|
|
|
// if (m_window) SDL_GetWindowSize(m_window, &w, &h);
|
|
|
|
// In real world...:
|
|
|
|
if (!m_XDisplay) m_XDisplay = XOpenDisplay(NULL);
|
|
|
|
XGetGeometry(m_XDisplay, m_Xwindow, &winDummy, &xDummy, &yDummy, &w, &h, &borderDummy, &depthDummy);
|
2012-01-04 23:19:17 +00:00
|
|
|
#ifdef ENABLE_SDL_DEV
|
2011-12-07 22:05:46 +00:00
|
|
|
if (m_renderer == 2)
|
|
|
|
SDL_SetWindowSize(m_window, w, h);
|
2012-01-04 23:19:17 +00:00
|
|
|
#endif
|
2011-06-12 14:48:36 +00:00
|
|
|
|
|
|
|
return GSVector4i(0, 0, (int)w, (int)h);
|
2011-02-24 23:46:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Returns FALSE if the window has no title, or if th window title is under the strict
|
|
|
|
// management of the emulator.
|
|
|
|
|
|
|
|
bool GSWnd::SetWindowText(const char* title)
|
|
|
|
{
|
2011-06-12 14:48:36 +00:00
|
|
|
if (!m_managed) return true;
|
|
|
|
|
2012-01-12 07:29:31 +00:00
|
|
|
if (m_renderer == 2) {
|
|
|
|
#ifdef ENABLE_SDL_DEV
|
|
|
|
|
2011-04-24 16:00:36 +00:00
|
|
|
// Do not find anyway to check the current fullscreen status
|
|
|
|
// Better than nothing heuristic, check the window position. Fullscreen = (0,0)
|
|
|
|
// if(!(m_window->flags & SDL_WINDOW_FULLSCREEN) ) // Do not compile
|
|
|
|
//
|
2011-06-12 14:48:36 +00:00
|
|
|
// We call SDL_PumpEvents to refresh x and y value.
|
|
|
|
// but we not use this function anyway.
|
2011-04-24 16:00:36 +00:00
|
|
|
// FIXME: it does not feel a good solution -- Gregory
|
2011-06-12 14:48:36 +00:00
|
|
|
// NOte: it might be more thread safe to use a call to XGetGeometry
|
2012-01-12 07:29:31 +00:00
|
|
|
int x,y = 0;
|
2011-12-07 22:05:46 +00:00
|
|
|
SDL_PumpEvents();
|
|
|
|
SDL_GetWindowPosition(m_window, &x, &y);
|
|
|
|
if ( x && y )
|
|
|
|
SDL_SetWindowTitle(m_window, title);
|
2011-02-24 23:46:26 +00:00
|
|
|
|
2012-01-04 23:19:17 +00:00
|
|
|
#endif
|
2012-01-12 07:29:31 +00:00
|
|
|
} else {
|
|
|
|
XTextProperty prop;
|
|
|
|
|
|
|
|
memset(&prop, 0, sizeof(prop));
|
|
|
|
|
|
|
|
char* ptitle = (char*)title;
|
|
|
|
if (XStringListToTextProperty(&ptitle, 1, &prop)) {
|
|
|
|
XSetWMName(m_XDisplay, m_Xwindow, &prop);
|
|
|
|
}
|
|
|
|
|
|
|
|
XFree(prop.value);
|
|
|
|
XFlush(m_XDisplay);
|
|
|
|
}
|
|
|
|
|
2011-02-24 23:46:26 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2011-12-07 22:05:46 +00:00
|
|
|
void GSWnd::Flip()
|
|
|
|
{
|
|
|
|
if (m_renderer == 2) {
|
2012-01-04 23:19:17 +00:00
|
|
|
#ifdef ENABLE_SDL_DEV
|
2011-12-07 22:05:46 +00:00
|
|
|
#if SDL_VERSION_ATLEAST(1,3,0)
|
|
|
|
SDL_GL_SwapWindow(m_window);
|
|
|
|
#else
|
|
|
|
SDL_GL_SwapBuffers();
|
2012-01-04 23:19:17 +00:00
|
|
|
#endif
|
2011-12-07 22:05:46 +00:00
|
|
|
#endif
|
|
|
|
} else {
|
|
|
|
glXSwapBuffers(m_XDisplay, m_Xwindow);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-02-24 23:46:26 +00:00
|
|
|
void GSWnd::Show()
|
|
|
|
{
|
2011-12-07 22:05:46 +00:00
|
|
|
if (m_renderer == 2) {
|
2012-01-04 23:19:17 +00:00
|
|
|
#ifdef ENABLE_SDL_DEV
|
2011-12-07 22:05:46 +00:00
|
|
|
SDL_ShowWindow(m_window);
|
2012-01-04 23:19:17 +00:00
|
|
|
#endif
|
2011-12-07 22:05:46 +00:00
|
|
|
} else {
|
|
|
|
XMapRaised(m_XDisplay, m_Xwindow);
|
|
|
|
XFlush(m_XDisplay);
|
|
|
|
}
|
2011-02-24 23:46:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void GSWnd::Hide()
|
|
|
|
{
|
2011-12-07 22:05:46 +00:00
|
|
|
if (m_renderer == 2) {
|
2012-01-04 23:19:17 +00:00
|
|
|
#ifdef ENABLE_SDL_DEV
|
2011-12-07 22:05:46 +00:00
|
|
|
SDL_HideWindow(m_window);
|
2012-01-04 23:19:17 +00:00
|
|
|
#endif
|
2011-12-07 22:05:46 +00:00
|
|
|
} else {
|
|
|
|
XUnmapWindow(m_XDisplay, m_Xwindow);
|
|
|
|
XFlush(m_XDisplay);
|
|
|
|
}
|
2011-02-24 23:46:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void GSWnd::HideFrame()
|
|
|
|
{
|
|
|
|
// TODO
|
|
|
|
}
|
2011-02-23 09:16:00 +00:00
|
|
|
|
|
|
|
#endif
|