Add headless support on macOS

This commit is contained in:
Michael Maltese 2017-04-15 19:23:19 -07:00
parent a389ae0711
commit 5298328cb1
5 changed files with 59 additions and 38 deletions

View File

@ -414,9 +414,13 @@ elseif(CMAKE_SYSTEM_NAME STREQUAL "Linux")
endif() endif()
if(ENABLE_HEADLESS) if(ENABLE_HEADLESS)
message(STATUS "Enabling Headless! Disabling GUI, force enabling EGL!") if(APPLE)
message(STATUS "Enabling Headless! Disabling GUI.")
else()
message(STATUS "Enabling Headless! Disabling GUI, force enabling EGL!")
set(USE_EGL 1)
endif()
set(USE_X11 0) set(USE_X11 0)
set(USE_EGL 1)
set(DISABLE_WX 1) set(DISABLE_WX 1)
set(ENABLE_QT2 0) set(ENABLE_QT2 0)
add_definitions(-DUSE_HEADLESS) add_definitions(-DUSE_HEADLESS)

View File

@ -14,22 +14,6 @@ void cInterfaceAGL::Swap()
// Call browser: Core.cpp:EmuThread() > main.cpp:Video_Initialize() // Call browser: Core.cpp:EmuThread() > main.cpp:Video_Initialize()
bool cInterfaceAGL::Create(void* window_handle, bool core) bool cInterfaceAGL::Create(void* window_handle, bool core)
{ {
cocoaWin = reinterpret_cast<NSView*>(window_handle);
NSSize size = [cocoaWin frame].size;
// Enable high-resolution display support.
[cocoaWin setWantsBestResolutionOpenGLSurface:YES];
NSWindow* window = [cocoaWin window];
float scale = [window backingScaleFactor];
size.width *= scale;
size.height *= scale;
// Control window size and picture scaling
s_backbuffer_width = size.width;
s_backbuffer_height = size.height;
NSOpenGLPixelFormatAttribute attr[] = {NSOpenGLPFADoubleBuffer, NSOpenGLPFAOpenGLProfile, NSOpenGLPixelFormatAttribute attr[] = {NSOpenGLPFADoubleBuffer, NSOpenGLPFAOpenGLProfile,
core ? NSOpenGLProfileVersion3_2Core : core ? NSOpenGLProfileVersion3_2Core :
NSOpenGLProfileVersionLegacy, NSOpenGLProfileVersionLegacy,
@ -49,15 +33,34 @@ bool cInterfaceAGL::Create(void* window_handle, bool core)
return false; return false;
} }
if (cocoaWin == nil) if (window_handle)
{ {
ERROR_LOG(VIDEO, "failed to create window"); cocoaWin = reinterpret_cast<NSView*>(window_handle);
return false; NSSize size = [cocoaWin frame].size;
}
[window makeFirstResponder:cocoaWin]; // Enable high-resolution display support.
[cocoaCtx setView:cocoaWin]; [cocoaWin setWantsBestResolutionOpenGLSurface:YES];
[window makeKeyAndOrderFront:nil];
NSWindow* window = [cocoaWin window];
float scale = [window backingScaleFactor];
size.width *= scale;
size.height *= scale;
// Control window size and picture scaling
s_backbuffer_width = size.width;
s_backbuffer_height = size.height;
if (cocoaWin == nil)
{
ERROR_LOG(VIDEO, "failed to create window");
return false;
}
[window makeFirstResponder:cocoaWin];
[cocoaCtx setView:cocoaWin];
[window makeKeyAndOrderFront:nil];
}
return true; return true;
} }
@ -84,18 +87,21 @@ void cInterfaceAGL::Shutdown()
void cInterfaceAGL::Update() void cInterfaceAGL::Update()
{ {
NSWindow* window = [cocoaWin window]; if (cocoaWin)
NSSize size = [cocoaWin frame].size; {
NSWindow* window = [cocoaWin window];
NSSize size = [cocoaWin frame].size;
float scale = [window backingScaleFactor]; float scale = [window backingScaleFactor];
size.width *= scale; size.width *= scale;
size.height *= scale; size.height *= scale;
if (s_backbuffer_width == size.width && s_backbuffer_height == size.height) if (s_backbuffer_width == size.width && s_backbuffer_height == size.height)
return; return;
s_backbuffer_width = size.width; s_backbuffer_width = size.width;
s_backbuffer_height = size.height; s_backbuffer_height = size.height;
}
[cocoaCtx update]; [cocoaCtx update];
} }

View File

@ -370,7 +370,7 @@ class PlatformX11 : public Platform
static Platform* GetPlatform() static Platform* GetPlatform()
{ {
#if defined(USE_EGL) && defined(USE_HEADLESS) #if defined(USE_HEADLESS)
return new Platform(); return new Platform();
#elif HAVE_X11 #elif HAVE_X11
return new PlatformX11(); return new PlatformX11();

View File

@ -173,13 +173,21 @@ static void DeviceMatchingCallback(void* inContext, IOReturn inResult, void* inS
// Add a device if it's of a type we want // Add a device if it's of a type we want
if (IOHIDDeviceConformsTo(inIOHIDDeviceRef, kHIDPage_GenericDesktop, kHIDUsage_GD_Keyboard)) if (IOHIDDeviceConformsTo(inIOHIDDeviceRef, kHIDPage_GenericDesktop, kHIDUsage_GD_Keyboard))
g_controller_interface.AddDevice(std::make_shared<Keyboard>(inIOHIDDeviceRef, name, g_window)); {
if (g_window)
g_controller_interface.AddDevice(
std::make_shared<Keyboard>(inIOHIDDeviceRef, name, g_window));
}
#if 0 #if 0
else if (IOHIDDeviceConformsTo(inIOHIDDeviceRef, kHIDPage_GenericDesktop, kHIDUsage_GD_Mouse)) else if (IOHIDDeviceConformsTo(inIOHIDDeviceRef, kHIDPage_GenericDesktop, kHIDUsage_GD_Mouse))
{
g_controller_interface.AddDevice(new Mouse(inIOHIDDeviceRef, name)); g_controller_interface.AddDevice(new Mouse(inIOHIDDeviceRef, name));
}
#endif #endif
else else
{
g_controller_interface.AddDevice(std::make_shared<Joystick>(inIOHIDDeviceRef, name)); g_controller_interface.AddDevice(std::make_shared<Joystick>(inIOHIDDeviceRef, name));
}
NOTICE_LOG(SERIALINTERFACE, "Added device: %s", name.c_str()); NOTICE_LOG(SERIALINTERFACE, "Added device: %s", name.c_str());
g_controller_interface.InvokeHotplugCallbacks(); g_controller_interface.InvokeHotplugCallbacks();
@ -187,12 +195,12 @@ static void DeviceMatchingCallback(void* inContext, IOReturn inResult, void* inS
void Init(void* window) void Init(void* window)
{ {
g_window = window;
HIDManager = IOHIDManagerCreate(kCFAllocatorDefault, kIOHIDOptionsTypeNone); HIDManager = IOHIDManagerCreate(kCFAllocatorDefault, kIOHIDOptionsTypeNone);
if (!HIDManager) if (!HIDManager)
ERROR_LOG(SERIALINTERFACE, "Failed to create HID Manager reference"); ERROR_LOG(SERIALINTERFACE, "Failed to create HID Manager reference");
g_window = window;
IOHIDManagerSetDeviceMatching(HIDManager, nullptr); IOHIDManagerSetDeviceMatching(HIDManager, nullptr);
if (IOHIDManagerOpen(HIDManager, kIOHIDOptionsTypeNone) != kIOReturnSuccess) if (IOHIDManagerOpen(HIDManager, kIOHIDOptionsTypeNone) != kIOReturnSuccess)
ERROR_LOG(SERIALINTERFACE, "Failed to open HID Manager"); ERROR_LOG(SERIALINTERFACE, "Failed to open HID Manager");

View File

@ -12,6 +12,9 @@ namespace Quartz
{ {
void PopulateDevices(void* window) void PopulateDevices(void* window)
{ {
if (!window)
return;
g_controller_interface.AddDevice(std::make_shared<KeyboardAndMouse>(window)); g_controller_interface.AddDevice(std::make_shared<KeyboardAndMouse>(window));
} }