Mac: graphics library changes to allow building project graphics apps compatible with MacOS 14 screensver

This commit is contained in:
Charlie Fenton 2024-05-03 01:15:24 -07:00
parent 55cb33ba44
commit d459b51f39
3 changed files with 78 additions and 31 deletions

View File

@ -1,6 +1,6 @@
// This file is part of BOINC.
// http://boinc.berkeley.edu
// Copyright (C) 2020 University of California
// Copyright (C) 2024 University of California
//
// BOINC is free software; you can redistribute it and/or modify it
// under the terms of the GNU Lesser General Public License
@ -237,15 +237,19 @@ void boinc_graphics_loop(int argc, char** argv, const char* title) {
boinc_init_graphics_diagnostics(BOINC_DIAG_DEFAULTS);
}
#ifdef __APPLE__
char dir [MAXPATHLEN];
getcwd(dir, MAXPATHLEN);
#endif
for (int i=1; i<argc; i++) {
if (!strcmp(argv[i], "--fullscreen")) {
fullscreen = true;
}
}
#ifdef __APPLE__
char dir [MAXPATHLEN];
getcwd(dir, MAXPATHLEN);
if (fullscreen) {
pass_BOINC_gfx_lib_version_to_ss();
}
#endif
boinc_glut_init(&argc, argv);
make_window(title);
glutTimerFunc(TIMER_INTERVAL_MSEC, timer_handler, 0);
@ -299,4 +303,36 @@ bool UseSharedOffscreenBuffer() {
}
return false;
}
#include "shmem.h"
// struct ss_shmem_data must be kept in sync in these files:
// screensaver.cpp
// gfx_switcher.cpp
// gfx_cleanup.mm
// graphics2_unix.cpp
struct ss_shmem_data {
pid_t gfx_pid;
int gfx_slot;
int major_version;
int minor_version;
int release;
};
void pass_BOINC_gfx_lib_version_to_ss() {
struct ss_shmem_data* ss_shmem = NULL;
char userName[64];
char shmem_name[MAXPATHLEN];
strlcpy(userName, getenv("USER"), sizeof(userName));
snprintf(shmem_name, sizeof(shmem_name), "/tmp/boinc_ss_%s", userName);
attach_shmem_mmap(shmem_name, (void**)&ss_shmem);
if (ss_shmem) {
ss_shmem->major_version = BOINC_MAJOR_VERSION;
ss_shmem->minor_version = BOINC_MINOR_VERSION;
ss_shmem->release = BOINC_RELEASE;
}
}
#endif

View File

@ -1,6 +1,6 @@
// Berkeley Open Infrastructure for Network Computing
// http://boinc.berkeley.edu
// Copyright (C) 2020 University of California
// Copyright (C) 2024 University of California
//
// This is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public
@ -190,14 +190,12 @@ void HideThisApp() {
@interface ServerController : NSObject <NSMachPortDelegate>
{
NSMachPort *serverPort;
NSMachPort *localPort;
uint32_t serverPortName;
uint32_t localPortName;
NSMachPort *clientPort[16];
uint32_t clientPortNames[16];
uint32_t clientPortCount;
bool mach_bootstrap_unavailable_to_screensavers;
}
- (ServerController *)init;
- (kern_return_t)checkInClient:(mach_port_t)client_port index:(int32_t *)client_index;
@ -220,30 +218,42 @@ static GLuint depthBufferName;
- (ServerController *)init
{
mach_port_t servicePortNum = MACH_PORT_NULL;
kern_return_t machErr;
char *portNameV1 = "edu.berkeley.boincsaver";
char *portNameV2 = "edu.berkeley.boincsaver-v2";
mach_bootstrap_unavailable_to_screensavers = false;
// NSMachBootstrapServer is deprecated in OS 10.13, so use bootstrap_look_up
// serverPort = [(NSMachPort *)([[NSMachBootstrapServer sharedInstance] portForName:@"edu.berkeley.boincsaver"]) retain];
machErr = bootstrap_look_up(bootstrap_port, portNameV2, &servicePortNum);
if (machErr == KERN_SUCCESS) {
// As of MacOS 14.0, the legacyScreenSave sandbox prevents using
// bootstrap_look_up. I have filed bug report FB13300491 with
// Apple and hope they will change this in a future MacOS.
mach_bootstrap_unavailable_to_screensavers = true;
int32_t dummy_index;
[self checkInClient:servicePortNum index:&dummy_index];
} else {
// NSMachBootstrapServer is deprecated in OS 10.13, so use bootstrap_check_in
// serverPort = [(NSMachPort *)([[NSMachBootstrapServer sharedInstance] servicePortWithName:@"edu.berkeley.boincsaver"]) retain];
machErr = bootstrap_check_in(bootstrap_port, portNameV1, &servicePortNum);
if (machErr != KERN_SUCCESS) { // maybe BOOTSTRAP_UNKNOWN_SERVICE
[NSApp terminate:self];
}
}
serverPort = (NSMachPort*)[NSMachPort portWithMachPort:servicePortNum];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(portDied:) name:NSPortDidBecomeInvalidNotification object:nil];
mach_port_t servicePortNum = MACH_PORT_NULL;
kern_return_t machErr;
char *portName = "edu.berkeley.boincsaver";
// NSMachBootstrapServer is deprecated in OS 10.13, so use bootstrap_look_up
// serverPort = [(NSMachPort *)([[NSMachBootstrapServer sharedInstance] servicePortWithName:@"edu.berkeley.boincsaver"]) retain];
machErr = bootstrap_check_in(bootstrap_port, portName, &servicePortNum);
if (machErr != KERN_SUCCESS) {
[NSApp terminate:self];
if (!mach_bootstrap_unavailable_to_screensavers) {
// Register server port with the current runloop.
[serverPort setDelegate:self]; // CAF STD
[serverPort scheduleInRunLoop:[NSRunLoop currentRunLoop] forMode:NSRunLoopCommonModes]; // CAF STD
}
serverPort = (NSMachPort*)[NSMachPort portWithMachPort:servicePortNum];
// Create a local dummy reply port to use with the mig reply stuff
localPort = [[NSMachPort alloc] init];
// Retrieve raw mach port names.
serverPortName = [serverPort machPort];
localPortName = [localPort machPort];
[serverPort setDelegate:self];
[serverPort scheduleInRunLoop:[NSRunLoop currentRunLoop] forMode:NSRunLoopCommonModes];
// NOT USED: See comments in animateOneFrame in Mac_Saver_ModuleView.m
#if 0

View File

@ -1,6 +1,6 @@
// This file is part of BOINC.
// http://boinc.berkeley.edu
// Copyright (C) 2020 University of California
// Copyright (C) 2024 University of California
//
// BOINC is free software; you can redistribute it and/or modify it
// under the terms of the GNU Lesser General Public License
@ -32,6 +32,7 @@ extern void BringAppToFront(void);
extern void HideThisApp(void);
extern bool UseSharedOffscreenBuffer(void);
extern bool debugSharedOffscreenBuffer;
void pass_BOINC_gfx_lib_version_to_ss(void);
extern void print_to_log_file(const char *format, ...);