summaryrefslogtreecommitdiff
path: root/platform/osx
diff options
context:
space:
mode:
Diffstat (limited to 'platform/osx')
-rw-r--r--platform/osx/SCsub2
-rw-r--r--platform/osx/crash_handler_osx.mm8
-rw-r--r--platform/osx/detect.py8
-rw-r--r--platform/osx/dir_access_osx.h2
-rw-r--r--platform/osx/export/export.cpp222
-rw-r--r--platform/osx/os_osx.h6
-rw-r--r--platform/osx/os_osx.mm171
-rw-r--r--platform/osx/platform_config.h4
-rw-r--r--platform/osx/power_osx.h4
-rw-r--r--platform/osx/sem_osx.cpp2
-rw-r--r--platform/osx/sem_osx.h2
11 files changed, 316 insertions, 115 deletions
diff --git a/platform/osx/SCsub b/platform/osx/SCsub
index 5c973c30c2..dc407eee9e 100644
--- a/platform/osx/SCsub
+++ b/platform/osx/SCsub
@@ -1,8 +1,8 @@
#!/usr/bin/env python
-import os
Import('env')
+import os
from platform_methods import run_in_subprocess
import platform_osx_builders
diff --git a/platform/osx/crash_handler_osx.mm b/platform/osx/crash_handler_osx.mm
index 1664c5ce8e..490155bb24 100644
--- a/platform/osx/crash_handler_osx.mm
+++ b/platform/osx/crash_handler_osx.mm
@@ -28,9 +28,9 @@
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/*************************************************************************/
+#include "core/project_settings.h"
#include "main/main.h"
#include "os_osx.h"
-#include "project_settings.h"
#include <string.h>
#include <unistd.h>
@@ -68,8 +68,9 @@ static uint64_t load_address() {
}
static void handle_crash(int sig) {
- if (OS::get_singleton() == NULL)
- return;
+ if (OS::get_singleton() == NULL) {
+ abort();
+ }
void *bt_buffer[256];
size_t size = backtrace(bt_buffer, 256);
@@ -151,6 +152,7 @@ CrashHandler::CrashHandler() {
}
CrashHandler::~CrashHandler() {
+ disable();
}
void CrashHandler::disable() {
diff --git a/platform/osx/detect.py b/platform/osx/detect.py
index 8a0883eca3..051836b66d 100644
--- a/platform/osx/detect.py
+++ b/platform/osx/detect.py
@@ -1,5 +1,6 @@
import os
import sys
+from methods import detect_darwin_sdk_path
def is_active():
@@ -23,6 +24,7 @@ def get_opts():
return [
('osxcross_sdk', 'OSXCross SDK version', 'darwin14'),
+ ('MACOS_SDK_PATH', 'Path to the macOS SDK', ''),
EnumVariable('debug_symbols', 'Add debugging symbols to release builds', 'yes', ('yes', 'no', 'full')),
BoolVariable('separate_debug_symbols', 'Create a separate file containing debugging symbols', False),
]
@@ -84,12 +86,16 @@ def configure(env):
env['AS'] = mpprefix + "/libexec/llvm-" + mpclangver + "/bin/llvm-as"
env.Append(CCFLAGS=['-D__MACPORTS__']) #hack to fix libvpx MM256_BROADCASTSI128_SI256 define
+ detect_darwin_sdk_path('osx', env)
+ env.Append(CPPFLAGS=['-isysroot', '$MACOS_SDK_PATH'])
+ env.Append(LINKFLAGS=['-isysroot', '$MACOS_SDK_PATH'])
+
else: # osxcross build
root = os.environ.get("OSXCROSS_ROOT", 0)
basecmd = root + "/target/bin/x86_64-apple-" + env["osxcross_sdk"] + "-"
ccache_path = os.environ.get("CCACHE")
- if ccache_path == None:
+ if ccache_path is None:
env['CC'] = basecmd + "cc"
env['CXX'] = basecmd + "c++"
else:
diff --git a/platform/osx/dir_access_osx.h b/platform/osx/dir_access_osx.h
index e01ff2fe4d..a9d6d63a8e 100644
--- a/platform/osx/dir_access_osx.h
+++ b/platform/osx/dir_access_osx.h
@@ -38,8 +38,8 @@
#include <sys/types.h>
#include <unistd.h>
+#include "core/os/dir_access.h"
#include "drivers/unix/dir_access_unix.h"
-#include "os/dir_access.h"
/**
@author Juan Linietsky <reduzio@gmail.com>
diff --git a/platform/osx/export/export.cpp b/platform/osx/export/export.cpp
index b630e4f223..12a0193521 100644
--- a/platform/osx/export/export.cpp
+++ b/platform/osx/export/export.cpp
@@ -29,18 +29,18 @@
/*************************************************************************/
#include "export.h"
+#include "core/io/marshalls.h"
+#include "core/io/resource_saver.h"
+#include "core/io/zip_io.h"
+#include "core/os/file_access.h"
+#include "core/os/os.h"
+#include "core/project_settings.h"
+#include "core/version.h"
#include "editor/editor_export.h"
#include "editor/editor_node.h"
#include "editor/editor_settings.h"
-#include "io/marshalls.h"
-#include "io/resource_saver.h"
-#include "io/zip_io.h"
-#include "os/file_access.h"
-#include "os/os.h"
#include "platform/osx/logo.gen.h"
-#include "project_settings.h"
#include "string.h"
-#include "version.h"
#include <sys/stat.h>
class EditorExportPlatformOSX : public EditorExportPlatform {
@@ -74,7 +74,14 @@ public:
virtual String get_os_name() const { return "OSX"; }
virtual Ref<Texture> get_logo() const { return logo; }
- virtual String get_binary_extension(const Ref<EditorExportPreset> &p_preset) const { return use_dmg() ? "dmg" : "zip"; }
+ virtual List<String> get_binary_extensions(const Ref<EditorExportPreset> &p_preset) const {
+ List<String> list;
+ if (use_dmg()) {
+ list.push_back("dmg");
+ }
+ list.push_back("zip");
+ return list;
+ }
virtual Error export_project(const Ref<EditorExportPreset> &p_preset, bool p_debug, const String &p_path, int p_flags = 0);
virtual bool can_export(const Ref<EditorExportPreset> &p_preset, String &r_error, bool &r_missing_templates) const;
@@ -86,6 +93,9 @@ public:
r_features->push_back("OSX");
}
+ virtual void resolve_platform_feature_priorities(const Ref<EditorExportPreset> &p_preset, Set<String> &p_features) {
+ }
+
EditorExportPlatformOSX();
~EditorExportPlatformOSX();
};
@@ -106,14 +116,14 @@ void EditorExportPlatformOSX::get_preset_features(const Ref<EditorExportPreset>
void EditorExportPlatformOSX::get_export_options(List<ExportOption> *r_options) {
- r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "custom_package/debug", PROPERTY_HINT_GLOBAL_FILE, "zip"), ""));
- r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "custom_package/release", PROPERTY_HINT_GLOBAL_FILE, "zip"), ""));
+ r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "custom_package/debug", PROPERTY_HINT_GLOBAL_FILE, "*.zip"), ""));
+ r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "custom_package/release", PROPERTY_HINT_GLOBAL_FILE, "*.zip"), ""));
- r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "application/name"), ""));
+ r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "application/name", PROPERTY_HINT_PLACEHOLDER_TEXT, "Game Name"), ""));
r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "application/info"), "Made with Godot Engine"));
- r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "application/icon", PROPERTY_HINT_FILE, "png"), ""));
- r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "application/identifier"), "org.godotengine.macgame"));
- r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "application/signature"), "godotmacgame"));
+ r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "application/icon", PROPERTY_HINT_FILE, "*.png"), ""));
+ r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "application/identifier", PROPERTY_HINT_PLACEHOLDER_TEXT, "com.example.game"), ""));
+ r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "application/signature"), ""));
r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "application/short_version"), "1.0"));
r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "application/version"), "1.0"));
r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "application/copyright"), ""));
@@ -129,10 +139,76 @@ void EditorExportPlatformOSX::get_export_options(List<ExportOption> *r_options)
r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "texture_format/etc2"), false));
}
+void _rgba8_to_packbits_encode(int p_ch, int p_size, PoolVector<uint8_t> &p_source, Vector<uint8_t> &p_dest) {
+
+ int src_len = p_size * p_size;
+
+ Vector<uint8_t> result;
+ result.resize(src_len * 1.25); //temp vector for rle encoded data, make it 25% larger for worst case scenario
+ int res_size = 0;
+
+ uint8_t buf[128];
+ int buf_size = 0;
+
+ int i = 0;
+ while (i < src_len) {
+ uint8_t cur = p_source.read()[i * 4 + p_ch];
+
+ if (i < src_len - 2) {
+
+ if ((p_source.read()[(i + 1) * 4 + p_ch] == cur) && (p_source.read()[(i + 2) * 4 + p_ch] == cur)) {
+ if (buf_size > 0) {
+ result.write[res_size++] = (uint8_t)(buf_size - 1);
+ copymem(&result.write[res_size], &buf, buf_size);
+ res_size += buf_size;
+ buf_size = 0;
+ }
+
+ uint8_t lim = i + 130 >= src_len ? src_len - i - 1 : 130;
+ bool hit_lim = true;
+
+ for (int j = 3; j <= lim; j++) {
+ if (p_source.read()[(i + j) * 4 + p_ch] != cur) {
+ hit_lim = false;
+ i = i + j - 1;
+ result.write[res_size++] = (uint8_t)(j - 3 + 0x80);
+ result.write[res_size++] = cur;
+ break;
+ }
+ }
+ if (hit_lim) {
+ result.write[res_size++] = (uint8_t)(lim - 3 + 0x80);
+ result.write[res_size++] = cur;
+ i = i + lim;
+ }
+ } else {
+ buf[buf_size++] = cur;
+ if (buf_size == 128) {
+ result.write[res_size++] = (uint8_t)(buf_size - 1);
+ copymem(&result.write[res_size], &buf, buf_size);
+ res_size += buf_size;
+ buf_size = 0;
+ }
+ }
+ } else {
+ buf[buf_size++] = cur;
+ result.write[res_size++] = (uint8_t)(buf_size - 1);
+ copymem(&result.write[res_size], &buf, buf_size);
+ res_size += buf_size;
+ buf_size = 0;
+ }
+
+ i++;
+ }
+
+ int ofs = p_dest.size();
+ p_dest.resize(p_dest.size() + res_size);
+ copymem(&p_dest.write[ofs], result.ptr(), res_size);
+}
+
void EditorExportPlatformOSX::_make_icon(const Ref<Image> &p_icon, Vector<uint8_t> &p_data) {
Ref<ImageTexture> it = memnew(ImageTexture);
- int size = 512;
Vector<uint8_t> data;
@@ -142,32 +218,82 @@ void EditorExportPlatformOSX::_make_icon(const Ref<Image> &p_icon, Vector<uint8_
data.write[2] = 'n';
data.write[3] = 's';
- const char *name[] = { "ic09", "ic08", "ic07", "icp6", "icp5", "icp4" };
- int index = 0;
-
- while (size >= 16) {
-
+ struct MacOSIconInfo {
+ const char *name;
+ const char *mask_name;
+ bool is_png;
+ int size;
+ };
+
+ static const MacOSIconInfo icon_infos[] = {
+ { "ic10", "", true, 1024 }, //1024x1024 32-bit PNG and 512x512@2x 32-bit "retina" PNG
+ { "ic09", "", true, 512 }, //512×512 32-bit PNG
+ { "ic14", "", true, 512 }, //256x256@2x 32-bit "retina" PNG
+ { "ic08", "", true, 256 }, //256×256 32-bit PNG
+ { "ic13", "", true, 256 }, //128x128@2x 32-bit "retina" PNG
+ { "ic07", "", true, 128 }, //128x128 32-bit PNG
+ { "ic12", "", true, 64 }, //32x32@2x 32-bit "retina" PNG
+ { "ic11", "", true, 32 }, //16x16@2x 32-bit "retina" PNG
+ { "il32", "l8mk", false, 32 }, //32x32 24-bit RLE + 8-bit uncompressed mask
+ { "is32", "s8mk", false, 16 } //16x16 24-bit RLE + 8-bit uncompressed mask
+ };
+
+ for (unsigned int i = 0; i < (sizeof(icon_infos) / sizeof(icon_infos[0])); ++i) {
Ref<Image> copy = p_icon; // does this make sense? doesn't this just increase the reference count instead of making a copy? Do we even need a copy?
copy->convert(Image::FORMAT_RGBA8);
- copy->resize(size, size);
- it->create_from_image(copy);
- String path = EditorSettings::get_singleton()->get_cache_dir().plus_file("icon.png");
- ResourceSaver::save(path, it);
-
- FileAccess *f = FileAccess::open(path, FileAccess::READ);
- ERR_FAIL_COND(!f);
-
- int ofs = data.size();
- uint32_t len = f->get_len();
- data.resize(data.size() + len + 8);
- f->get_buffer(&data.write[ofs + 8], len);
- memdelete(f);
- len += 8;
- len = BSWAP32(len);
- copymem(&data.write[ofs], name[index], 4);
- encode_uint32(len, &data.write[ofs + 4]);
- index++;
- size /= 2;
+ copy->resize(icon_infos[i].size, icon_infos[i].size);
+
+ if (icon_infos[i].is_png) {
+ //encode png icon
+ it->create_from_image(copy);
+ String path = EditorSettings::get_singleton()->get_cache_dir().plus_file("icon.png");
+ ResourceSaver::save(path, it);
+
+ FileAccess *f = FileAccess::open(path, FileAccess::READ);
+ ERR_FAIL_COND(!f);
+
+ int ofs = data.size();
+ uint32_t len = f->get_len();
+ data.resize(data.size() + len + 8);
+ f->get_buffer(&data.write[ofs + 8], len);
+ memdelete(f);
+ len += 8;
+ len = BSWAP32(len);
+ copymem(&data.write[ofs], icon_infos[i].name, 4);
+ encode_uint32(len, &data.write[ofs + 4]);
+ } else {
+ PoolVector<uint8_t> src_data = copy->get_data();
+
+ //encode 24bit RGB RLE icon
+ {
+ int ofs = data.size();
+ data.resize(data.size() + 8);
+
+ _rgba8_to_packbits_encode(0, icon_infos[i].size, src_data, data); // encode R
+ _rgba8_to_packbits_encode(1, icon_infos[i].size, src_data, data); // encode G
+ _rgba8_to_packbits_encode(2, icon_infos[i].size, src_data, data); // encode B
+
+ int len = data.size() - ofs;
+ len = BSWAP32(len);
+ copymem(&data.write[ofs], icon_infos[i].name, 4);
+ encode_uint32(len, &data.write[ofs + 4]);
+ }
+
+ //encode 8bit mask uncompressed icon
+ {
+ int ofs = data.size();
+ int len = copy->get_width() * copy->get_height();
+ data.resize(data.size() + len + 8);
+
+ for (int j = 0; j < len; j++) {
+ data.write[ofs + 8 + j] = src_data.read()[j * 4 + 3];
+ }
+ len += 8;
+ len = BSWAP32(len);
+ copymem(&data.write[ofs], icon_infos[i].mask_name, 4);
+ encode_uint32(len, &data.write[ofs + 4]);
+ }
+ }
}
uint32_t total_len = data.size();
@@ -331,7 +457,8 @@ Error EditorExportPlatformOSX::export_project(const Ref<EditorExportPreset> &p_p
io2.opaque = &dst_f;
zipFile dst_pkg_zip = NULL;
- if (use_dmg()) {
+ String export_format = use_dmg() && p_path.ends_with("dmg") ? "dmg" : "zip";
+ if (export_format == "dmg") {
// We're on OSX so we can export to DMG, but first we create our application bundle
tmp_app_path_name = EditorSettings::get_singleton()->get_cache_dir().plus_file(pkg_name + ".app");
print_line("Exporting to " + tmp_app_path_name);
@@ -377,7 +504,6 @@ Error EditorExportPlatformOSX::export_project(const Ref<EditorExportPreset> &p_p
String file = fname;
- print_line("READ: " + file);
Vector<uint8_t> data;
data.resize(info.uncompressed_size);
@@ -391,7 +517,6 @@ Error EditorExportPlatformOSX::export_project(const Ref<EditorExportPreset> &p_p
file = file.replace_first("osx_template.app/", "");
if (file == "Contents/Info.plist") {
- print_line("parse plist");
_fix_plist(p_preset, data, pkg_name);
}
@@ -412,13 +537,12 @@ Error EditorExportPlatformOSX::export_project(const Ref<EditorExportPreset> &p_p
iconpath = p_preset->get("application/icon");
else
iconpath = ProjectSettings::get_singleton()->get("application/config/icon");
- print_line("icon? " + iconpath);
+
if (iconpath != "") {
Ref<Image> icon;
icon.instance();
icon->load(iconpath);
if (!icon->empty()) {
- print_line("loaded?");
_make_icon(icon, data);
}
}
@@ -429,7 +553,7 @@ Error EditorExportPlatformOSX::export_project(const Ref<EditorExportPreset> &p_p
print_line("ADDING: " + file + " size: " + itos(data.size()));
total_size += data.size();
- if (use_dmg()) {
+ if (export_format == "dmg") {
// write it into our application bundle
file = tmp_app_path_name + "/" + file;
@@ -461,7 +585,7 @@ Error EditorExportPlatformOSX::export_project(const Ref<EditorExportPreset> &p_p
fi.internal_fa = info.internal_fa;
fi.external_fa = info.external_fa;
- int zerr = zipOpenNewFileInZip(dst_pkg_zip,
+ zipOpenNewFileInZip(dst_pkg_zip,
file.utf8().get_data(),
&fi,
NULL,
@@ -472,9 +596,7 @@ Error EditorExportPlatformOSX::export_project(const Ref<EditorExportPreset> &p_p
Z_DEFLATED,
Z_DEFAULT_COMPRESSION);
- print_line("OPEN ERR: " + itos(zerr));
- zerr = zipWriteInFileInZip(dst_pkg_zip, data.ptr(), data.size());
- print_line("WRITE ERR: " + itos(zerr));
+ zipWriteInFileInZip(dst_pkg_zip, data.ptr(), data.size());
zipCloseFileInZip(dst_pkg_zip);
}
}
@@ -493,7 +615,7 @@ Error EditorExportPlatformOSX::export_project(const Ref<EditorExportPreset> &p_p
if (err == OK) {
ep.step("Making PKG", 1);
- if (use_dmg()) {
+ if (export_format == "dmg") {
String pack_path = tmp_app_path_name + "/Contents/Resources/" + pkg_name + ".pck";
Vector<SharedObject> shared_objects;
err = save_pack(p_preset, pack_path, &shared_objects);
diff --git a/platform/osx/os_osx.h b/platform/osx/os_osx.h
index 686e3f8c90..546c88e74a 100644
--- a/platform/osx/os_osx.h
+++ b/platform/osx/os_osx.h
@@ -31,13 +31,13 @@
#ifndef OS_OSX_H
#define OS_OSX_H
+#include "core/os/input.h"
#include "crash_handler_osx.h"
#include "drivers/coreaudio/audio_driver_coreaudio.h"
#include "drivers/coremidi/core_midi.h"
#include "drivers/unix/os_unix.h"
#include "joypad_osx.h"
#include "main/input_default.h"
-#include "os/input.h"
#include "power_osx.h"
#include "servers/audio_server.h"
#include "servers/visual/rasterizer.h"
@@ -74,8 +74,12 @@ public:
IP_Unix *ip_unix;
+#ifdef COREAUDIO_ENABLED
AudioDriverCoreAudio audio_driver;
+#endif
+#ifdef COREMIDI_ENABLED
MIDIDriverCoreMidi midi_driver;
+#endif
InputDefault *input;
JoypadOSX *joypad_osx;
diff --git a/platform/osx/os_osx.mm b/platform/osx/os_osx.mm
index 7bf274310d..e7b3e35381 100644
--- a/platform/osx/os_osx.mm
+++ b/platform/osx/os_osx.mm
@@ -30,15 +30,15 @@
#include "os_osx.h"
+#include "core/os/keyboard.h"
+#include "core/print_string.h"
+#include "core/version_generated.gen.h"
#include "dir_access_osx.h"
#include "drivers/gles2/rasterizer_gles2.h"
#include "drivers/gles3/rasterizer_gles3.h"
#include "main/main.h"
-#include "os/keyboard.h"
-#include "print_string.h"
#include "sem_osx.h"
#include "servers/visual/visual_server_raster.h"
-#include "version_generated.gen.h"
#include <mach-o/dyld.h>
@@ -76,10 +76,12 @@
#define NSWindowStyleMaskBorderless NSBorderlessWindowMask
#endif
-static NSRect convertRectToBacking(NSRect contentRect) {
-
- return [OS_OSX::singleton->window_view convertRectToBacking:contentRect];
-}
+#ifndef NSAppKitVersionNumber10_12
+#define NSAppKitVersionNumber10_12 1504
+#endif
+#ifndef NSAppKitVersionNumber10_14
+#define NSAppKitVersionNumber10_14 1671
+#endif
static void get_key_modifier_state(unsigned int p_osx_state, Ref<InputEventWithModifiers> state) {
@@ -105,12 +107,13 @@ static int prev_mouse_y = 0;
static int button_mask = 0;
static bool mouse_down_control = false;
-static Vector2 get_mouse_pos(NSEvent *event) {
+static Vector2 get_mouse_pos(NSPoint locationInWindow, CGFloat backingScaleFactor) {
const NSRect contentRect = [OS_OSX::singleton->window_view frame];
- const NSPoint p = [event locationInWindow];
- mouse_x = p.x * OS_OSX::singleton->_mouse_scale([[event window] backingScaleFactor]);
- mouse_y = (contentRect.size.height - p.y) * OS_OSX::singleton->_mouse_scale([[event window] backingScaleFactor]);
+ const NSPoint p = locationInWindow;
+ const float s = OS_OSX::singleton->_mouse_scale(backingScaleFactor);
+ mouse_x = p.x * s;
+ mouse_y = (contentRect.size.height - p.y) * s;
return Vector2(mouse_x, mouse_y);
}
@@ -271,7 +274,7 @@ static Vector2 get_mouse_pos(NSEvent *event) {
float newDisplayScale = OS_OSX::singleton->is_hidpi_allowed() ? newBackingScaleFactor : 1.0;
const NSRect contentRect = [OS_OSX::singleton->window_view frame];
- const NSRect fbRect = contentRect; //convertRectToBacking(contentRect);
+ const NSRect fbRect = contentRect;
OS_OSX::singleton->window_size.width = fbRect.size.width * newDisplayScale;
OS_OSX::singleton->window_size.height = fbRect.size.height * newDisplayScale;
@@ -292,7 +295,7 @@ static Vector2 get_mouse_pos(NSEvent *event) {
[OS_OSX::singleton->context update];
const NSRect contentRect = [OS_OSX::singleton->window_view frame];
- const NSRect fbRect = contentRect; //convertRectToBacking(contentRect);
+ const NSRect fbRect = contentRect;
float displayScale = OS_OSX::singleton->_display_scale();
OS_OSX::singleton->window_size.width = fbRect.size.width * displayScale;
@@ -330,8 +333,15 @@ static Vector2 get_mouse_pos(NSEvent *event) {
- (void)windowDidBecomeKey:(NSNotification *)notification {
//_GodotInputWindowFocus(window, GL_TRUE);
//_GodotPlatformSetCursorMode(window, window->cursorMode);
- if (OS_OSX::singleton->get_main_loop())
+
+ if (OS_OSX::singleton->get_main_loop()) {
+ get_mouse_pos(
+ [OS_OSX::singleton->window_object mouseLocationOutsideOfEventStream],
+ [OS_OSX::singleton->window_view backingScaleFactor]);
+ OS_OSX::singleton->input->set_mouse_position(Point2(mouse_x, mouse_y));
+
OS_OSX::singleton->get_main_loop()->notification(MainLoop::NOTIFICATION_WM_FOCUS_IN);
+ }
}
- (void)windowDidResignKey:(NSNotification *)notification {
@@ -361,6 +371,8 @@ static Vector2 get_mouse_pos(NSEvent *event) {
bool imeMode;
}
- (void)cancelComposition;
+- (BOOL)wantsUpdateLayer;
+- (void)updateLayer;
@end
@implementation GodotContentView
@@ -371,6 +383,14 @@ static Vector2 get_mouse_pos(NSEvent *event) {
}
}
+- (BOOL)wantsUpdateLayer {
+ return YES;
+}
+
+- (void)updateLayer {
+ [OS_OSX::singleton->context update];
+}
+
- (id)init {
self = [super init];
trackingArea = nil;
@@ -598,12 +618,13 @@ static void _mouseDownEvent(NSEvent *event, int index, int mask, bool pressed) {
mm->set_button_mask(button_mask);
prev_mouse_x = mouse_x;
prev_mouse_y = mouse_y;
- const Vector2 pos = get_mouse_pos(event);
+ const CGFloat backingScaleFactor = [[event window] backingScaleFactor];
+ const Vector2 pos = get_mouse_pos([event locationInWindow], backingScaleFactor);
mm->set_position(pos);
mm->set_global_position(pos);
Vector2 relativeMotion = Vector2();
- relativeMotion.x = [event deltaX] * OS_OSX::singleton -> _mouse_scale([[event window] backingScaleFactor]);
- relativeMotion.y = [event deltaY] * OS_OSX::singleton -> _mouse_scale([[event window] backingScaleFactor]);
+ relativeMotion.x = [event deltaX] * OS_OSX::singleton -> _mouse_scale(backingScaleFactor);
+ relativeMotion.y = [event deltaY] * OS_OSX::singleton -> _mouse_scale(backingScaleFactor);
mm->set_relative(relativeMotion);
get_key_modifier_state([event modifierFlags], mm);
@@ -686,7 +707,7 @@ static void _mouseDownEvent(NSEvent *event, int index, int mask, bool pressed) {
Ref<InputEventMagnifyGesture> ev;
ev.instance();
get_key_modifier_state([event modifierFlags], ev);
- ev->set_position(get_mouse_pos(event));
+ ev->set_position(get_mouse_pos([event locationInWindow], [[event window] backingScaleFactor]));
ev->set_factor([event magnification] + 1.0);
OS_OSX::singleton->push_input(ev);
}
@@ -929,7 +950,7 @@ static int remapKey(unsigned int key) {
CFDataRef layoutData = (CFDataRef)TISGetInputSourceProperty(currentKeyboard, kTISPropertyUnicodeKeyLayoutData);
if (!layoutData)
- return 0;
+ return translateKey(key);
const UCKeyboardLayout *keyboardLayout = (const UCKeyboardLayout *)CFDataGetBytePtr(layoutData);
@@ -1078,6 +1099,8 @@ inline void sendPanEvent(double dx, double dy, int modifierFlags) {
- (void)scrollWheel:(NSEvent *)event {
double deltaX, deltaY;
+ get_mouse_pos([event locationInWindow], [[event window] backingScaleFactor]);
+
deltaX = [event scrollingDeltaX];
deltaY = [event scrollingDeltaY];
@@ -1221,6 +1244,9 @@ Error OS_OSX::initialize(const VideoMode &p_desired, int p_video_driver, int p_a
ERR_FAIL_COND_V(window_object == nil, ERR_UNAVAILABLE);
window_view = [[GodotContentView alloc] init];
+ if (NSAppKitVersionNumber >= NSAppKitVersionNumber10_14) {
+ [window_view setWantsLayer:TRUE];
+ }
float displayScale = 1.0;
if (is_hidpi_allowed()) {
@@ -1276,8 +1302,6 @@ Error OS_OSX::initialize(const VideoMode &p_desired, int p_video_driver, int p_a
ADD_ATTR2(NSOpenGLPFAOpenGLProfile, NSOpenGLProfileVersion3_2Core);
}
- video_driver_index = p_video_driver;
-
ADD_ATTR2(NSOpenGLPFAColorSize, colorBits);
/*
@@ -1333,26 +1357,59 @@ Error OS_OSX::initialize(const VideoMode &p_desired, int p_video_driver, int p_a
/*** END OSX INITIALIZATION ***/
- // only opengl support here...
+ bool gles3 = true;
if (p_video_driver == VIDEO_DRIVER_GLES2) {
- RasterizerGLES2::register_config();
- RasterizerGLES2::make_current();
- } else {
- RasterizerGLES3::register_config();
- RasterizerGLES3::make_current();
+ gles3 = false;
}
+ bool editor = Engine::get_singleton()->is_editor_hint();
+ bool gl_initialization_error = false;
+
+ while (true) {
+ if (gles3) {
+ if (RasterizerGLES3::is_viable() == OK) {
+ RasterizerGLES3::register_config();
+ RasterizerGLES3::make_current();
+ break;
+ } else {
+ if (GLOBAL_GET("rendering/quality/driver/driver_fallback") == "Best" || editor) {
+ p_video_driver = VIDEO_DRIVER_GLES2;
+ gles3 = false;
+ continue;
+ } else {
+ gl_initialization_error = true;
+ break;
+ }
+ }
+ } else {
+ if (RasterizerGLES2::is_viable() == OK) {
+ RasterizerGLES2::register_config();
+ RasterizerGLES2::make_current();
+ break;
+ } else {
+ gl_initialization_error = true;
+ break;
+ }
+ }
+ }
+
+ if (gl_initialization_error) {
+ OS::get_singleton()->alert("Your video card driver does not support any of the supported OpenGL versions.\n"
+ "Please update your drivers or if you have a very old or integrated GPU upgrade it.",
+ "Unable to initialize Video driver");
+ return ERR_UNAVAILABLE;
+ }
+
+ video_driver_index = p_video_driver;
+
visual_server = memnew(VisualServerRaster);
if (get_render_thread_mode() != RENDER_THREAD_UNSAFE) {
-
visual_server = memnew(VisualServerWrapMT(visual_server, get_render_thread_mode() == RENDER_SEPARATE_THREAD));
}
- visual_server->init();
+ visual_server->init();
AudioDriverManager::initialize(p_audio_driver);
- midi_driver.open();
-
input = memnew(InputDefault);
joypad_osx = memnew(JoypadOSX);
@@ -1370,6 +1427,10 @@ Error OS_OSX::initialize(const VideoMode &p_desired, int p_video_driver, int p_a
void OS_OSX::finalize() {
+#ifdef COREMIDI_ENABLED
+ midi_driver.close();
+#endif
+
CFNotificationCenterRemoveObserver(CFNotificationCenterGetDistributedCenter(), NULL, kTISNotifySelectedKeyboardInputSourceChanged, NULL);
CGDisplayRemoveReconfigurationCallback(displays_arrangement_changed, NULL);
@@ -1418,7 +1479,7 @@ public:
switch (p_type) {
case ERR_WARNING:
- if (floor(NSAppKitVersionNumber) >= NSAppKitVersionNumber10_12) {
+ if (NSAppKitVersionNumber >= NSAppKitVersionNumber10_12) {
os_log_info(OS_LOG_DEFAULT,
"WARNING: %{public}s: %{public}s\nAt: %{public}s:%i.",
p_function, err_details, p_file, p_line);
@@ -1428,7 +1489,7 @@ public:
logf_error("\E[0;33m At: %s:%i.\E[0m\n", p_file, p_line);
break;
case ERR_SCRIPT:
- if (floor(NSAppKitVersionNumber) >= NSAppKitVersionNumber10_12) {
+ if (NSAppKitVersionNumber >= NSAppKitVersionNumber10_12) {
os_log_error(OS_LOG_DEFAULT,
"SCRIPT ERROR: %{public}s: %{public}s\nAt: %{public}s:%i.",
p_function, err_details, p_file, p_line);
@@ -1438,7 +1499,7 @@ public:
logf_error("\E[0;35m At: %s:%i.\E[0m\n", p_file, p_line);
break;
case ERR_SHADER:
- if (floor(NSAppKitVersionNumber) >= NSAppKitVersionNumber10_12) {
+ if (NSAppKitVersionNumber >= NSAppKitVersionNumber10_12) {
os_log_error(OS_LOG_DEFAULT,
"SHADER ERROR: %{public}s: %{public}s\nAt: %{public}s:%i.",
p_function, err_details, p_file, p_line);
@@ -1449,7 +1510,7 @@ public:
break;
case ERR_ERROR:
default:
- if (floor(NSAppKitVersionNumber) >= NSAppKitVersionNumber10_12) {
+ if (NSAppKitVersionNumber >= NSAppKitVersionNumber10_12) {
os_log_error(OS_LOG_DEFAULT,
"ERROR: %{public}s: %{public}s\nAt: %{public}s:%i.",
p_function, err_details, p_file, p_line);
@@ -1570,7 +1631,9 @@ void OS_OSX::set_custom_mouse_cursor(const RES &p_cursor, CursorShape p_shape, c
}
ERR_FAIL_COND(!texture.is_valid());
+ ERR_FAIL_COND(p_hotspot.x < 0 || p_hotspot.y < 0);
ERR_FAIL_COND(texture_size.width > 256 || texture_size.height > 256);
+ ERR_FAIL_COND(p_hotspot.x > texture_size.width || p_hotspot.y > texture_size.height);
image = texture->get_data();
@@ -1626,8 +1689,10 @@ void OS_OSX::set_custom_mouse_cursor(const RES &p_cursor, CursorShape p_shape, c
[cursors[p_shape] release];
cursors[p_shape] = cursor;
- if (p_shape == CURSOR_ARROW) {
- [cursor set];
+ if (p_shape == cursor_shape) {
+ if (mouse_mode == MOUSE_MODE_VISIBLE || mouse_mode == MOUSE_MODE_CONFINED) {
+ [cursor set];
+ }
}
[imgrep release];
@@ -1635,8 +1700,10 @@ void OS_OSX::set_custom_mouse_cursor(const RES &p_cursor, CursorShape p_shape, c
} else {
// Reset to default system cursor
cursors[p_shape] = NULL;
+
+ CursorShape c = cursor_shape;
cursor_shape = CURSOR_MAX;
- set_cursor_shape(p_shape);
+ set_cursor_shape(c);
}
}
@@ -1824,28 +1891,30 @@ bool OS_OSX::can_draw() const {
void OS_OSX::set_clipboard(const String &p_text) {
- NSArray *types = [NSArray arrayWithObjects:NSStringPboardType, nil];
+ NSString *copiedString = [NSString stringWithUTF8String:p_text.utf8().get_data()];
+ NSArray *copiedStringArray = [NSArray arrayWithObject:copiedString];
NSPasteboard *pasteboard = [NSPasteboard generalPasteboard];
- [pasteboard declareTypes:types owner:nil];
- [pasteboard setString:[NSString stringWithUTF8String:p_text.utf8().get_data()]
- forType:NSStringPboardType];
+ [pasteboard clearContents];
+ [pasteboard writeObjects:copiedStringArray];
}
String OS_OSX::get_clipboard() const {
NSPasteboard *pasteboard = [NSPasteboard generalPasteboard];
+ NSArray *classArray = [NSArray arrayWithObject:[NSString class]];
+ NSDictionary *options = [NSDictionary dictionary];
- if (![[pasteboard types] containsObject:NSStringPboardType]) {
- return "";
- }
+ BOOL ok = [pasteboard canReadObjectForClasses:classArray options:options];
- NSString *object = [pasteboard stringForType:NSStringPboardType];
- if (!object) {
+ if (!ok) {
return "";
}
- char *utfs = strdup([object UTF8String]);
+ NSArray *objectsToPaste = [pasteboard readObjectsForClasses:classArray options:options];
+ NSString *string = [objectsToPaste objectAtIndex:0];
+
+ char *utfs = strdup([string UTF8String]);
String ret;
ret.parse_utf8(utfs);
free(utfs);
@@ -2112,11 +2181,7 @@ void OS_OSX::set_window_size(const Size2 p_size) {
if (menuBarHeight != 0.f) {
size.y += menuBarHeight;
} else {
-#if MAC_OS_X_VERSION_MAX_ALLOWED >= 101200
if (floor(NSAppKitVersionNumber) < NSAppKitVersionNumber10_12) {
-#else
- {
-#endif
size.y += [[NSStatusBar systemStatusBar] thickness];
}
}
@@ -2677,7 +2742,9 @@ OS_OSX::OS_OSX() {
[NSApp sendEvent:event];
}
+#ifdef COREAUDIO_ENABLED
AudioDriverManager::add_driver(&audio_driver);
+#endif
}
bool OS_OSX::_check_internal_feature_support(const String &p_feature) {
diff --git a/platform/osx/platform_config.h b/platform/osx/platform_config.h
index 3f72831d77..1d32d5b5b9 100644
--- a/platform/osx/platform_config.h
+++ b/platform/osx/platform_config.h
@@ -30,6 +30,6 @@
#include <alloca.h>
-#define GLES3_INCLUDE_H "glad/glad.h"
-#define GLES2_INCLUDE_H "glad/glad.h"
+#define GLES3_INCLUDE_H "thirdparty/glad/glad/glad.h"
+#define GLES2_INCLUDE_H "thirdparty/glad/glad/glad.h"
#define PTHREAD_RENAME_SELF
diff --git a/platform/osx/power_osx.h b/platform/osx/power_osx.h
index 7123e34a03..9ad51e505b 100644
--- a/platform/osx/power_osx.h
+++ b/platform/osx/power_osx.h
@@ -31,9 +31,9 @@
#ifndef PLATFORM_OSX_POWER_OSX_H_
#define PLATFORM_OSX_POWER_OSX_H_
+#include "core/os/file_access.h"
+#include "core/os/os.h"
#include "dir_access_osx.h"
-#include "os/file_access.h"
-#include "os/os.h"
#include <CoreFoundation/CoreFoundation.h>
class power_osx {
diff --git a/platform/osx/sem_osx.cpp b/platform/osx/sem_osx.cpp
index 92f749322e..9b42abdb8d 100644
--- a/platform/osx/sem_osx.cpp
+++ b/platform/osx/sem_osx.cpp
@@ -65,7 +65,7 @@ void cgsem_destroy(cgsem_t *cgsem) {
close(cgsem->pipefd[0]);
}
-#include "os/memory.h"
+#include "core/os/memory.h"
#include <errno.h>
Error SemaphoreOSX::wait() {
diff --git a/platform/osx/sem_osx.h b/platform/osx/sem_osx.h
index ce31e966b7..0ab82873c6 100644
--- a/platform/osx/sem_osx.h
+++ b/platform/osx/sem_osx.h
@@ -37,7 +37,7 @@ struct cgsem {
typedef struct cgsem cgsem_t;
-#include "os/semaphore.h"
+#include "core/os/semaphore.h"
class SemaphoreOSX : public Semaphore {