Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add headless support on macOS #5276

Merged
merged 3 commits into from Jun 6, 2017
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 6 additions & 2 deletions CMakeLists.txt
Expand Up @@ -414,9 +414,13 @@ elseif(CMAKE_SYSTEM_NAME STREQUAL "Linux")
endif()

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_EGL 1)
set(DISABLE_WX 1)
set(ENABLE_QT2 0)
add_definitions(-DUSE_HEADLESS)
Expand Down
70 changes: 38 additions & 32 deletions Source/Core/Common/GL/GLInterface/AGL.mm
Expand Up @@ -14,22 +14,6 @@
// Call browser: Core.cpp:EmuThread() > main.cpp:Video_Initialize()
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,
core ? NSOpenGLProfileVersion3_2Core :
NSOpenGLProfileVersionLegacy,
Expand All @@ -49,15 +33,34 @@
return false;
}

if (cocoaWin == nil)
if (window_handle)

This comment was marked as off-topic.

This comment was marked as off-topic.

This comment was marked as off-topic.

This comment was marked as off-topic.

This comment was marked as off-topic.

{
ERROR_LOG(VIDEO, "failed to create window");
return false;
}
cocoaWin = reinterpret_cast<NSView*>(window_handle);
NSSize size = [cocoaWin frame].size;

// Enable high-resolution display support.
[cocoaWin setWantsBestResolutionOpenGLSurface:YES];

[window makeFirstResponder:cocoaWin];
[cocoaCtx setView:cocoaWin];
[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;
}
Expand All @@ -84,18 +87,21 @@

void cInterfaceAGL::Update()
{
NSWindow* window = [cocoaWin window];
NSSize size = [cocoaWin frame].size;
if (cocoaWin)
{
NSWindow* window = [cocoaWin window];
NSSize size = [cocoaWin frame].size;

float scale = [window backingScaleFactor];
size.width *= scale;
size.height *= scale;
float scale = [window backingScaleFactor];
size.width *= scale;
size.height *= scale;

if (s_backbuffer_width == size.width && s_backbuffer_height == size.height)
return;
if (s_backbuffer_width == size.width && s_backbuffer_height == size.height)
return;

s_backbuffer_width = size.width;
s_backbuffer_height = size.height;
s_backbuffer_width = size.width;
s_backbuffer_height = size.height;
}

[cocoaCtx update];
}
Expand Down
2 changes: 1 addition & 1 deletion Source/Core/DolphinNoGUI/MainNoGUI.cpp
Expand Up @@ -370,7 +370,7 @@ class PlatformX11 : public Platform

static Platform* GetPlatform()
{
#if defined(USE_EGL) && defined(USE_HEADLESS)
#if defined(USE_HEADLESS)
return new Platform();
#elif HAVE_X11
return new PlatformX11();
Expand Down
14 changes: 11 additions & 3 deletions Source/Core/InputCommon/ControllerInterface/OSX/OSX.mm
Expand Up @@ -173,26 +173,34 @@ static void DeviceMatchingCallback(void* inContext, IOReturn inResult, void* inS

// Add a device if it's of a type we want
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
else if (IOHIDDeviceConformsTo(inIOHIDDeviceRef, kHIDPage_GenericDesktop, kHIDUsage_GD_Mouse))
{
g_controller_interface.AddDevice(new Mouse(inIOHIDDeviceRef, name));
}
#endif
else
{
g_controller_interface.AddDevice(std::make_shared<Joystick>(inIOHIDDeviceRef, name));
}

NOTICE_LOG(SERIALINTERFACE, "Added device: %s", name.c_str());
g_controller_interface.InvokeHotplugCallbacks();
}

void Init(void* window)
{
g_window = window;

HIDManager = IOHIDManagerCreate(kCFAllocatorDefault, kIOHIDOptionsTypeNone);
if (!HIDManager)
ERROR_LOG(SERIALINTERFACE, "Failed to create HID Manager reference");

g_window = window;

IOHIDManagerSetDeviceMatching(HIDManager, nullptr);
if (IOHIDManagerOpen(HIDManager, kIOHIDOptionsTypeNone) != kIOReturnSuccess)
ERROR_LOG(SERIALINTERFACE, "Failed to open HID Manager");
Expand Down
3 changes: 3 additions & 0 deletions Source/Core/InputCommon/ControllerInterface/Quartz/Quartz.mm
Expand Up @@ -12,6 +12,9 @@
{
void PopulateDevices(void* window)
{
if (!window)
return;

g_controller_interface.AddDevice(std::make_shared<KeyboardAndMouse>(window));
}

Expand Down