Merge pull request #5276 from ligfx/macosheadless
Add headless support on macOS
This commit is contained in:
commit
192fec50b9
|
@ -396,9 +396,13 @@ elseif(CMAKE_SYSTEM_NAME STREQUAL "Linux")
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
if(ENABLE_HEADLESS)
|
if(ENABLE_HEADLESS)
|
||||||
|
if(APPLE)
|
||||||
|
message(STATUS "Enabling Headless! Disabling GUI.")
|
||||||
|
else()
|
||||||
message(STATUS "Enabling Headless! Disabling GUI, force enabling EGL!")
|
message(STATUS "Enabling Headless! Disabling GUI, force enabling EGL!")
|
||||||
set(USE_X11 0)
|
|
||||||
set(USE_EGL 1)
|
set(USE_EGL 1)
|
||||||
|
endif()
|
||||||
|
set(USE_X11 0)
|
||||||
set(DISABLE_WX 1)
|
set(DISABLE_WX 1)
|
||||||
set(ENABLE_QT2 0)
|
set(ENABLE_QT2 0)
|
||||||
add_definitions(-DUSE_HEADLESS)
|
add_definitions(-DUSE_HEADLESS)
|
||||||
|
|
|
@ -15,10 +15,6 @@ struct NSView;
|
||||||
|
|
||||||
class cInterfaceAGL : public cInterfaceBase
|
class cInterfaceAGL : public cInterfaceBase
|
||||||
{
|
{
|
||||||
private:
|
|
||||||
NSView* cocoaWin;
|
|
||||||
NSOpenGLContext* cocoaCtx;
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
void Swap() override;
|
void Swap() override;
|
||||||
bool Create(void* window_handle, bool core) override;
|
bool Create(void* window_handle, bool core) override;
|
||||||
|
@ -27,4 +23,8 @@ public:
|
||||||
void Shutdown() override;
|
void Shutdown() override;
|
||||||
void Update() override;
|
void Update() override;
|
||||||
void SwapInterval(int interval) override;
|
void SwapInterval(int interval) override;
|
||||||
|
|
||||||
|
private:
|
||||||
|
NSView* m_view;
|
||||||
|
NSOpenGLContext* m_context;
|
||||||
};
|
};
|
||||||
|
|
|
@ -5,31 +5,54 @@
|
||||||
#include "Common/GL/GLInterface/AGL.h"
|
#include "Common/GL/GLInterface/AGL.h"
|
||||||
#include "Common/Logging/Log.h"
|
#include "Common/Logging/Log.h"
|
||||||
|
|
||||||
|
static bool UpdateCachedDimensions(NSView* view, u32* width, u32* height)
|
||||||
|
{
|
||||||
|
NSWindow* window = [view window];
|
||||||
|
NSSize size = [view frame].size;
|
||||||
|
|
||||||
|
float scale = [window backingScaleFactor];
|
||||||
|
size.width *= scale;
|
||||||
|
size.height *= scale;
|
||||||
|
|
||||||
|
if (*width == size.width && *height == size.height)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
*width = size.width;
|
||||||
|
*height = size.height;
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
static bool AttachContextToView(NSOpenGLContext* context, NSView* view, u32* width, u32* height)
|
||||||
|
{
|
||||||
|
// Enable high-resolution display support.
|
||||||
|
[view setWantsBestResolutionOpenGLSurface:YES];
|
||||||
|
|
||||||
|
NSWindow* window = [view window];
|
||||||
|
if (window == nil)
|
||||||
|
{
|
||||||
|
ERROR_LOG(VIDEO, "failed to get NSWindow");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
(void)UpdateCachedDimensions(view, width, height);
|
||||||
|
|
||||||
|
[window makeFirstResponder:view];
|
||||||
|
[context setView:view];
|
||||||
|
[window makeKeyAndOrderFront:nil];
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
void cInterfaceAGL::Swap()
|
void cInterfaceAGL::Swap()
|
||||||
{
|
{
|
||||||
[cocoaCtx flushBuffer];
|
[m_context flushBuffer];
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create rendering window.
|
// Create rendering window.
|
||||||
// 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,
|
||||||
|
@ -41,30 +64,24 @@ bool cInterfaceAGL::Create(void* window_handle, bool core)
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
cocoaCtx = [[NSOpenGLContext alloc] initWithFormat:fmt shareContext:nil];
|
m_context = [[NSOpenGLContext alloc] initWithFormat:fmt shareContext:nil];
|
||||||
[fmt release];
|
[fmt release];
|
||||||
if (cocoaCtx == nil)
|
if (m_context == nil)
|
||||||
{
|
{
|
||||||
ERROR_LOG(VIDEO, "failed to create context");
|
ERROR_LOG(VIDEO, "failed to create context");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (cocoaWin == nil)
|
if (!window_handle)
|
||||||
{
|
|
||||||
ERROR_LOG(VIDEO, "failed to create window");
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
[window makeFirstResponder:cocoaWin];
|
|
||||||
[cocoaCtx setView:cocoaWin];
|
|
||||||
[window makeKeyAndOrderFront:nil];
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
|
m_view = static_cast<NSView*>(window_handle);
|
||||||
|
return AttachContextToView(m_context, m_view, &s_backbuffer_width, &s_backbuffer_height);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool cInterfaceAGL::MakeCurrent()
|
bool cInterfaceAGL::MakeCurrent()
|
||||||
{
|
{
|
||||||
[cocoaCtx makeCurrentContext];
|
[m_context makeCurrentContext];
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -77,30 +94,21 @@ bool cInterfaceAGL::ClearCurrent()
|
||||||
// Close backend
|
// Close backend
|
||||||
void cInterfaceAGL::Shutdown()
|
void cInterfaceAGL::Shutdown()
|
||||||
{
|
{
|
||||||
[cocoaCtx clearDrawable];
|
[m_context clearDrawable];
|
||||||
[cocoaCtx release];
|
[m_context release];
|
||||||
cocoaCtx = nil;
|
m_context = nil;
|
||||||
}
|
}
|
||||||
|
|
||||||
void cInterfaceAGL::Update()
|
void cInterfaceAGL::Update()
|
||||||
{
|
{
|
||||||
NSWindow* window = [cocoaWin window];
|
if (!m_view)
|
||||||
NSSize size = [cocoaWin frame].size;
|
|
||||||
|
|
||||||
float scale = [window backingScaleFactor];
|
|
||||||
size.width *= scale;
|
|
||||||
size.height *= scale;
|
|
||||||
|
|
||||||
if (s_backbuffer_width == size.width && s_backbuffer_height == size.height)
|
|
||||||
return;
|
return;
|
||||||
|
|
||||||
s_backbuffer_width = size.width;
|
if (UpdateCachedDimensions(m_view, &s_backbuffer_width, &s_backbuffer_height))
|
||||||
s_backbuffer_height = size.height;
|
[m_context update];
|
||||||
|
|
||||||
[cocoaCtx update];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void cInterfaceAGL::SwapInterval(int interval)
|
void cInterfaceAGL::SwapInterval(int interval)
|
||||||
{
|
{
|
||||||
[cocoaCtx setValues:(GLint*)&interval forParameter:NSOpenGLCPSwapInterval];
|
[m_context setValues:static_cast<GLint*>(&interval) forParameter:NSOpenGLCPSwapInterval];
|
||||||
}
|
}
|
||||||
|
|
|
@ -363,7 +363,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();
|
||||||
|
|
|
@ -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");
|
||||||
|
|
|
@ -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));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue