GSdx: Fix issues on macOS

Note: Doesn't add the ability to make windows, so GSdx won't actually play games on macOS with this
This commit is contained in:
Tellow Krinkle 2020-04-09 04:32:07 -05:00 committed by tellowkrinkle
parent 99b8168ea8
commit 7fa6740710
10 changed files with 47 additions and 11 deletions

View File

@ -98,7 +98,7 @@ endif()
# -X11 # -X11
# -zlib # -zlib
#--------------------------------------- #---------------------------------------
if(OPENGL_FOUND AND X11_FOUND AND GTKn_FOUND AND ZLIB_FOUND AND PNG_FOUND AND FREETYPE_FOUND AND LIBLZMA_FOUND AND EGL_FOUND AND X11_XCB_FOUND) if(OPENGL_FOUND AND X11_FOUND AND GTKn_FOUND AND ZLIB_FOUND AND PNG_FOUND AND FREETYPE_FOUND AND LIBLZMA_FOUND AND ((EGL_FOUND AND X11_XCB_FOUND) OR APPLE))
set(GSdx TRUE) set(GSdx TRUE)
elseif(NOT EXISTS "${CMAKE_SOURCE_DIR}/plugins/GSdx") elseif(NOT EXISTS "${CMAKE_SOURCE_DIR}/plugins/GSdx")
set(GSdx FALSE) set(GSdx FALSE)

View File

@ -207,6 +207,10 @@ if(Windows)
resource.h resource.h
targetver.h targetver.h
) )
elseif(APPLE)
LIST(APPEND GSdxSources
Window/GSLinuxDialog.cpp
)
else() else()
LIST(APPEND GSdxSources LIST(APPEND GSdxSources
Window/GSLinuxDialog.cpp Window/GSLinuxDialog.cpp
@ -240,6 +244,12 @@ if(USE_VTUNE)
set(GSdxFinalLibs ${GSdxFinalLibs} ${VTUNE_LIBRARIES}) set(GSdxFinalLibs ${GSdxFinalLibs} ${VTUNE_LIBRARIES})
endif() endif()
if(APPLE)
find_library(APPKIT_LIBRARY AppKit)
set(GSdxFinalFlags ${GSdxFinalFlags} -fobjc-arc)
set(GSdxFinalLibs ${GSdxFinalLibs} ${APPKIT_LIBRARY} -fobjc-link-runtime)
endif()
set(RESOURCE_FILES set(RESOURCE_FILES
res/logo-ogl.bmp res/logo-ogl.bmp
res/fxaa.fx res/fxaa.fx

View File

@ -43,6 +43,11 @@ static HRESULT s_hr = E_FAIL;
#include "Window/GSWndEGL.h" #include "Window/GSWndEGL.h"
#ifdef __APPLE__
#include <gtk/gtk.h>
#include <CoreFoundation/CoreFoundation.h>
#endif
extern bool RunLinuxDialog(); extern bool RunLinuxDialog();
#endif #endif
@ -244,6 +249,8 @@ static int _GSopen(void** dsp, const char* title, GSRendererType renderer, int t
default: default:
break; break;
} }
#elif defined(__APPLE__)
// No windows available for macOS at the moment
#else #else
wnds.push_back(std::make_shared<GSWndWGL>()); wnds.push_back(std::make_shared<GSWndWGL>());
#endif #endif
@ -251,6 +258,8 @@ static int _GSopen(void** dsp, const char* title, GSRendererType renderer, int t
default: default:
#ifdef _WIN32 #ifdef _WIN32
wnds.push_back(std::make_shared<GSWndDX>()); wnds.push_back(std::make_shared<GSWndDX>());
#elif defined(__APPLE__)
// No windows available for macOS at the moment
#else #else
wnds.push_back(std::make_shared<GSWndEGL_X11>()); wnds.push_back(std::make_shared<GSWndEGL_X11>());
#endif #endif
@ -749,6 +758,20 @@ EXPORT_C GSconfigure()
theApp.SetCurrentRendererType(GSRendererType::Undefined); theApp.SetCurrentRendererType(GSRendererType::Undefined);
} }
#elif defined(__APPLE__)
// Rest of macOS UI doesn't use GTK so we need to init it now
gtk_init(nullptr, nullptr);
// GTK expects us to be using its event loop, rather than Cocoa's
// If we call its stuff right now, it'll attempt to drain a static autorelease pool that was already drained by Cocoa (see https://github.com/GNOME/gtk/blob/8c1072fad1cb6a2e292fce2441b4a571f173ce0f/gdk/quartz/gdkeventloop-quartz.c#L640-L646)
// We can convince it that touching that pool would be unsafe by running all GTK calls within a CFRunLoop
// (Blocks submitted to the main queue by dispatch_async are run by its CFRunLoop)
dispatch_async(dispatch_get_main_queue(), ^{
if (RunLinuxDialog()) {
theApp.ReloadConfig();
// Force a reload of the gs state
theApp.SetCurrentRendererType(GSRendererType::Undefined);
}
});
#else #else
if (RunLinuxDialog()) { if (RunLinuxDialog()) {
@ -802,7 +825,7 @@ EXPORT_C_(std::wstring*) GSsetupRecording(int start)
printf("GSdx: no s_gs for recording\n"); printf("GSdx: no s_gs for recording\n");
return nullptr; return nullptr;
} }
#if defined(__unix__) #if defined(__unix__) || defined(__APPLE__)
if (!theApp.GetConfigB("capture_enabled")) { if (!theApp.GetConfigB("capture_enabled")) {
printf("GSdx: Recording is disabled\n"); printf("GSdx: Recording is disabled\n");
return nullptr; return nullptr;
@ -1302,7 +1325,7 @@ EXPORT_C GSBenchmark(HWND hwnd, HINSTANCE hinst, LPSTR lpszCmdLine, int nCmdShow
#endif #endif
#if defined(__unix__) #if defined(__unix__) || defined(__APPLE__)
inline unsigned long timeGetTime() inline unsigned long timeGetTime()
{ {
@ -1316,7 +1339,9 @@ EXPORT_C GSReplay(char* lpszCmdLine, int renderer)
{ {
GLLoader::in_replayer = true; GLLoader::in_replayer = true;
// Required by multithread driver // Required by multithread driver
#ifndef __APPLE__
XInitThreads(); XInitThreads();
#endif
GSinit(); GSinit();

View File

@ -38,7 +38,7 @@ void GSPerfMon::Put(counter_t c, double val)
#ifndef DISABLE_PERF_MON #ifndef DISABLE_PERF_MON
if(c == Frame) if(c == Frame)
{ {
#if defined(__unix__) #if defined(__unix__) || defined(__APPLE__)
// clock on linux will return CLOCK_PROCESS_CPUTIME_ID. // clock on linux will return CLOCK_PROCESS_CPUTIME_ID.
// CLOCK_THREAD_CPUTIME_ID is much more useful to measure the fps // CLOCK_THREAD_CPUTIME_ID is much more useful to measure the fps
struct timespec ts; struct timespec ts;

View File

@ -21,7 +21,7 @@
#include "stdafx.h" #include "stdafx.h"
#include "GSRenderer.h" #include "GSRenderer.h"
#if defined(__unix__) #if defined(__unix__) || defined(__APPLE__)
#include <X11/keysym.h> #include <X11/keysym.h>
#endif #endif
@ -570,7 +570,7 @@ void GSRenderer::KeyEvent(GSKeyEventData* e)
int step = m_shift_key ? -1 : 1; int step = m_shift_key ? -1 : 1;
#if defined(__unix__) #if defined(__unix__) || defined(__APPLE__)
#define VK_F5 XK_F5 #define VK_F5 XK_F5
#define VK_F6 XK_F6 #define VK_F6 XK_F6
#define VK_DELETE XK_Delete #define VK_DELETE XK_Delete

View File

@ -23,7 +23,7 @@
#include "GSdx.h" #include "GSdx.h"
#include "GS.h" #include "GS.h"
#ifdef __unix__ #if defined(__unix__) || defined(__APPLE__)
PFNGLBLENDFUNCSEPARATEPROC glBlendFuncSeparate = NULL; PFNGLBLENDFUNCSEPARATEPROC glBlendFuncSeparate = NULL;
#endif #endif
PFNGLTEXTUREPAGECOMMITMENTEXTPROC glTexturePageCommitmentEXT = NULL; PFNGLTEXTUREPAGECOMMITMENTEXTPROC glTexturePageCommitmentEXT = NULL;

View File

@ -114,7 +114,7 @@ typedef void (APIENTRYP PFNGLTEXTUREPAGECOMMITMENTEXTPROC) (GLuint texture, GLin
// #define ENABLE_GL_VERSION_4_6 1 // #define ENABLE_GL_VERSION_4_6 1
// It should be done by ENABLE_GL_VERSION_1_4 but it conflicts with the old gl.h // It should be done by ENABLE_GL_VERSION_1_4 but it conflicts with the old gl.h
#ifdef __unix__ #if defined(__unix__) || defined(__APPLE__)
extern PFNGLBLENDFUNCSEPARATEPROC glBlendFuncSeparate; extern PFNGLBLENDFUNCSEPARATEPROC glBlendFuncSeparate;
#endif #endif
extern PFNGLTEXTUREPAGECOMMITMENTEXTPROC glTexturePageCommitmentEXT; extern PFNGLTEXTUREPAGECOMMITMENTEXTPROC glTexturePageCommitmentEXT;

View File

@ -33,7 +33,7 @@ void GSWndGL::PopulateGlFunction()
#include "PFN_WND.h" #include "PFN_WND.h"
// GL1.X mess // GL1.X mess
#ifdef __unix__ #if defined(__unix__) || defined(__APPLE__)
GL_EXT_LOAD(glBlendFuncSeparate); GL_EXT_LOAD(glBlendFuncSeparate);
#endif #endif
GL_EXT_LOAD_OPT(glTexturePageCommitmentEXT); GL_EXT_LOAD_OPT(glTexturePageCommitmentEXT);

View File

@ -43,6 +43,6 @@
//#define ENABLE_EXTRA_LOG // print extra log //#define ENABLE_EXTRA_LOG // print extra log
#endif #endif
#if defined(__unix__) && !(defined(_DEBUG) || defined(_DEVEL)) #if (defined(__unix__) || defined(__APPLE__)) && !(defined(_DEBUG) || defined(_DEVEL))
#define DISABLE_PERF_MON // Burn cycle for nothing in release mode #define DISABLE_PERF_MON // Burn cycle for nothing in release mode
#endif #endif

View File

@ -155,7 +155,8 @@ void* vmalloc(size_t size, bool code)
if(code) { if(code) {
prot |= PROT_EXEC; prot |= PROT_EXEC;
#ifdef _M_AMD64 #if defined(_M_AMD64) && !defined(__APPLE__)
// macOS doesn't allow any mappings in the first 4GB of address space
flags |= MAP_32BIT; flags |= MAP_32BIT;
#endif #endif
} }