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

Fix screensaver on MacOS 14 #5611

Merged
merged 8 commits into from
May 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 41 additions & 5 deletions api/graphics2_unix.cpp
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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
54 changes: 32 additions & 22 deletions api/macglutfix.m
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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;
Expand All @@ -220,30 +218,42 @@ @implementation ServerController

- (ServerController *)init
{
[[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";
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] servicePortWithName:@"edu.berkeley.boincsaver"]) retain];
machErr = bootstrap_check_in(bootstrap_port, portName, &servicePortNum);
if (machErr != KERN_SUCCESS) {
[NSApp terminate:self];
// 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];

// 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 = (NSMachPort*)[NSMachPort portWithMachPort:servicePortNum];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(portDied:) name:NSPortDidBecomeInvalidNotification object:nil];

[serverPort setDelegate:self];
[serverPort scheduleInRunLoop:[NSRunLoop currentRunLoop] forMode:NSRunLoopCommonModes];
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
}

// NOT USED: See comments in animateOneFrame in Mac_Saver_ModuleView.m
#if 0
Expand Down
3 changes: 2 additions & 1 deletion api/x_opengl.h
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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, ...);

Expand Down
10 changes: 6 additions & 4 deletions clientscr/Mac_Saver_Module.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// This file is part of BOINC.
// http://boinc.berkeley.edu
// Copyright (C) 2023 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
Expand Down Expand Up @@ -47,14 +47,15 @@ bool getShow_default_ss_first();
double getGFXDefaultPeriod();
double getGFXSciencePeriod();
double getGGFXChangePeriod();
void incompatibleGfxApp(char * appPath, pid_t pid, int slot);
void incompatibleGfxApp(char * appPath, char * wuName, pid_t pid, int slot);
void setShow_default_ss_first(bool value);
void setGFXDefaultPeriod(double value);
void setGFXSciencePeriod(double value);
void setGGFXChangePeriod(double value);
double getDTime();
void doBoinc_Sleep(double seconds);
void launchedGfxApp(char * appPath, pid_t thePID, int slot);
void launchedGfxApp(char * appPath, char * wuName, pid_t thePID, int slot);
int compareBOINCLibVersionTo(int toMajor, int toMinor, int toRelease);
void print_to_log_file(const char *format, ...);
void strip_cr(char *buf);
void PrintBacktrace(void);
Expand All @@ -63,7 +64,8 @@ extern bool gIsMojave;
extern bool gIsCatalina;
extern bool gIsHighSierra;
extern bool gIsSonoma;
extern bool gCant_Use_Shared_Offscreen_Buffer;
extern bool gMach_bootstrap_unavailable_to_screensavers;
extern mach_port_name_t commsPort;

#ifdef __cplusplus
} // extern "C"
Expand Down
14 changes: 9 additions & 5 deletions clientscr/Mac_Saver_ModuleView.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// This file is part of BOINC.
// http://boinc.berkeley.edu
// Copyright (C) 2023 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
Expand Down Expand Up @@ -51,8 +51,9 @@

@property (NS_NONATOMIC_IOSONLY, readonly) GLuint currentTextureName;
- (void)init:(NSView*)saverView;
- (void)portDied:(NSNotification *)notification;
- (void)testConnection;
- (void)portDied:(NSNotification *)notification;
- (void)cleanUpOpenGL;

@end

Expand Down Expand Up @@ -84,14 +85,15 @@ bool getShow_default_ss_first();
double getGFXDefaultPeriod();
double getGFXSciencePeriod();
double getGGFXChangePeriod();
void incompatibleGfxApp(char * appPath, pid_t pid, int slot);
void incompatibleGfxApp(char * appPath, char * wuName, pid_t pid, int slot);
void setShow_default_ss_first(bool value);
void setGFXDefaultPeriod(double value);
void setGFXSciencePeriod(double value);
void setGGFXChangePeriod(double value);
double getDTime();
void doBoinc_Sleep(double seconds);
void launchedGfxApp(char * appPath, pid_t thePID, int slot);
void launchedGfxApp(char * appPath, char * wuName, pid_t thePID, int slot);
int compareBOINCLibVersionTo(int toMajor, int toMinor, int toRelease);
void print_to_log_file(const char *format, ...);
void strip_cr(char *buf);
void PrintBacktrace(void);
Expand All @@ -100,7 +102,9 @@ extern bool gIsCatalina;
extern bool gIsHighSierra;
extern bool gIsMojave;
extern bool gIsSonoma;
extern bool gCant_Use_Shared_Offscreen_Buffer;
extern bool gMach_bootstrap_unavailable_to_screensavers;
extern mach_port_name_t commsPort;


#ifdef __cplusplus
} // extern "C"
Expand Down
Loading
Loading