MainNoGUI: Remove old OS X backend that doesn't work, rearchitect

This commit is contained in:
Jasper St. Pierre
2014-08-06 00:34:31 -04:00
parent e3a9ba30e3
commit 09eb30ea3b

View File

@ -18,24 +18,26 @@
#include "Core/Core.h"
#include "Core/CoreParameter.h"
#include "Core/Host.h"
#include "Core/State.h"
#include "Core/HW/Wiimote.h"
#include "Core/PowerPC/PowerPC.h"
#include "VideoCommon/VideoBackendBase.h"
#if HAVE_X11
#include <X11/keysym.h>
#include "Core/State.h"
#include "DolphinWX/X11Utils.h"
#endif
#ifdef __APPLE__
#import <Cocoa/Cocoa.h>
#endif
static bool rendererHasFocus = true;
static bool running = true;
class Platform
{
public:
virtual void Init() = 0;
virtual void MainLoop() = 0;
virtual void Shutdown() = 0;
virtual ~Platform() {};
};
static Platform* platform;
void Host_NotifyMapLoaded() {}
void Host_RefreshDSPDebuggerWindow() {}
@ -121,13 +123,25 @@ void Host_SetWiiMoteConnectionState(int _State) {}
void Host_ShowVideoConfig(void*, const std::string&, const std::string&) {}
#if HAVE_X11
static void X11_MainLoop()
{
bool fullscreen = SConfig::GetInstance().m_LocalCoreStartupParameter.bFullscreen;
while (!Core::IsRunning())
updateMainFrameEvent.Wait();
#include <X11/keysym.h>
#include "DolphinWX/X11Utils.h"
Display *dpy = XOpenDisplay(0);
class PlatformX11 : public Platform
{
Display *dpy;
Cursor blankCursor = None;
#if defined(HAVE_XRANDR) && HAVE_XRANDR
X11Utils::XRRConfiguration *XRRConfig;
#endif
void Init() override
{
XInitThreads();
dpy = XOpenDisplay(NULL);
}
void MainLoop() override
{
Window win = (Window)Core::GetWindowHandle();
XSelectInput(dpy, win, KeyPressMask | FocusChangeMask);
@ -135,10 +149,9 @@ static void X11_MainLoop()
X11Utils::InhibitScreensaver(dpy, win, true);
#if defined(HAVE_XRANDR) && HAVE_XRANDR
X11Utils::XRRConfiguration *XRRConfig = new X11Utils::XRRConfiguration(dpy, win);
XRRConfig = new X11Utils::XRRConfiguration(dpy, win);
#endif
Cursor blankCursor = None;
if (SConfig::GetInstance().m_LocalCoreStartupParameter.bHideCursor)
{
// make a blank cursor
@ -151,6 +164,8 @@ static void X11_MainLoop()
XDefineCursor(dpy, win, blankCursor);
}
bool fullscreen = SConfig::GetInstance().m_LocalCoreStartupParameter.bFullscreen;
if (fullscreen)
{
X11Utils::EWMH_Fullscreen(dpy, _NET_WM_STATE_TOGGLE);
@ -240,29 +255,32 @@ static void X11_MainLoop()
}
usleep(100000);
}
}
void Shutdown() override
{
#if defined(HAVE_XRANDR) && HAVE_XRANDR
delete XRRConfig;
#endif
if (SConfig::GetInstance().m_LocalCoreStartupParameter.bDisableScreenSaver)
X11Utils::InhibitScreensaver(dpy, win, false);
if (SConfig::GetInstance().m_LocalCoreStartupParameter.bHideCursor)
XFreeCursor(dpy, blankCursor);
XCloseDisplay(dpy);
Core::Stop();
}
}
};
#endif
static Platform* GetPlatform()
{
#if HAVE_X11
return new PlatformX11();
#endif
return nullptr;
}
int main(int argc, char* argv[])
{
#ifdef __APPLE__
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
NSEvent *event = [[NSEvent alloc] init];
[NSApplication sharedApplication];
[NSApp activateIgnoringOtherApps: YES];
[NSApp finishLaunching];
#endif
int ch, help = 0;
struct option longopts[] = {
{ "exec", no_argument, nullptr, 'e' },
@ -298,6 +316,13 @@ int main(int argc, char* argv[])
return 1;
}
platform = GetPlatform();
if (!platform)
{
fprintf(stderr, "No platform found\n");
return 1;
}
LogManager::Init();
SConfig::Init();
VideoBackend::PopulateList();
@ -305,45 +330,30 @@ int main(int argc, char* argv[])
m_LocalCoreStartupParameter.m_strVideoBackend);
WiimoteReal::LoadSettings();
// No use running the loop when booting fails
if (BootManager::BootCore(argv[optind]))
{
#if HAVE_X11
XInitThreads();
X11_MainLoop();
#endif
#ifdef __APPLE__
while (running)
{
event = [NSApp nextEventMatchingMask: NSAnyEventMask
untilDate: [NSDate distantFuture]
inMode: NSDefaultRunLoopMode dequeue: YES];
platform->Init();
if ([event type] == NSKeyDown &&
[event modifierFlags] & NSCommandKeyMask &&
[[event characters] UTF8String][0] == 'q')
if (!BootManager::BootCore(argv[optind]))
{
fprintf(stderr, "Could not boot %s\n", argv[optind]);
return 1;
}
while (!Core::IsRunning())
updateMainFrameEvent.Wait();
platform->MainLoop();
Core::Stop();
break;
}
if ([event type] != NSKeyDown)
[NSApp sendEvent: event];
}
[event release];
[pool release];
#else
while (PowerPC::GetState() != PowerPC::CPU_POWERDOWN)
updateMainFrameEvent.Wait();
#endif
}
platform->Shutdown();
Core::Shutdown();
WiimoteReal::Shutdown();
VideoBackend::ClearList();
SConfig::Shutdown();
LogManager::Shutdown();
delete platform;
return 0;
}