macOS: Splash Screen notice to about reduced performance on Rosetta

Implements a simple splash screen notice displayed if an x86/Intel macOS
Blender build is ran on an Apple Silicon Mac to warn against reduced
performance.

On the technical side of things, this adds a function that detects if
the current process is currently running through Rosetta using `sysctl`.
Implementation wise, I tried to keep this function contained in a single
conditional preprocessor macro block in the same file for simplicity.

Co-authored-by: Harley Acheson <harley.acheson@gmail.com>
Pull Request: https://projects.blender.org/blender/blender/pulls/124382
This commit is contained in:
Jonas Holzman
2024-09-19 16:38:08 +02:00
committed by Julian Eisel
parent 02d0c258d9
commit 9453ff6995

View File

@@ -40,6 +40,8 @@
#include "ED_datafiles.h"
#include "ED_screen.hh"
#include "RNA_access.hh"
#include "UI_interface.hh"
#include "UI_interface_icons.hh"
#include "UI_resources.hh"
@@ -198,6 +200,29 @@ static void wm_block_splash_close_on_fileselect(bContext *C, void *arg1, void *
}
}
#if defined(__APPLE__)
/* Check if Blender is running under Rosetta for the purpose of displaying a splash screen warning.
* From Apple's WWDC 2020 Session - Explore the new system architecture of Apple Silicon Macs.
* Timecode: 14:31 - https://developer.apple.com/videos/play/wwdc2020/10686/ */
# include <sys/sysctl.h>
static int is_using_macos_rosetta()
{
int ret = 0;
size_t size = sizeof(ret);
if (sysctlbyname("sysctl.proc_translated", &ret, &size, nullptr, 0) != -1) {
return ret;
}
/* If "sysctl.proc_translated" is not present then must be native. */
if (errno == ENOENT) {
return 0;
}
return -1;
}
#endif /* __APPLE__ */
static uiBlock *wm_block_splash_create(bContext *C, ARegion *region, void * /*arg*/)
{
const uiStyle *style = UI_style_get_dpi();
@@ -270,6 +295,34 @@ static uiBlock *wm_block_splash_create(bContext *C, ARegion *region, void * /*ar
UI_menutype_draw(C, mt, layout);
}
#if defined(__APPLE__)
if (is_using_macos_rosetta() > 0) {
uiItemS_ex(layout, 2.0f, LayoutSeparatorType::Line);
uiLayout *split = uiLayoutSplit(layout, 0.725, true);
uiLayout *row1 = uiLayoutRow(split, true);
uiLayout *row2 = uiLayoutRow(split, true);
uiItemL(row1, RPT_("Intel binary detected. Expect reduced performance."), ICON_ERROR);
PointerRNA op_ptr;
uiItemFullO(row2,
"WM_OT_url_open",
CTX_IFACE_(BLT_I18NCONTEXT_OPERATOR_DEFAULT, "Learn More"),
ICON_URL,
nullptr,
WM_OP_INVOKE_DEFAULT,
UI_ITEM_NONE,
&op_ptr);
RNA_string_set(
&op_ptr,
"url",
"https://docs.blender.org/manual/en/latest/getting_started/installing/macos.html");
uiItemS(layout);
}
#endif
UI_block_bounds_set_centered(block, 0);
return block;