Compare commits

..

6 Commits

Author SHA1 Message Date
Adam Scott
170394a5c4
Merge de6002fabd into 533c616cb8 2024-10-22 20:26:37 +00:00
Alex
de6002fabd
Android bindings for OS::get_tmp_dir() 2024-10-22 16:26:21 -04:00
Clay John
533c616cb8
Merge pull request #98391 from RandomShaper/rd_thread_switch
Some checks are pending
🔗 GHA / 📊 Static checks (push) Waiting to run
🔗 GHA / 🤖 Android (push) Blocked by required conditions
🔗 GHA / 🍏 iOS (push) Blocked by required conditions
🔗 GHA / 🐧 Linux (push) Blocked by required conditions
🔗 GHA / 🍎 macOS (push) Blocked by required conditions
🔗 GHA / 🏁 Windows (push) Blocked by required conditions
🔗 GHA / 🌐 Web (push) Blocked by required conditions
🔗 GHA / 🪲 Godot CPP (push) Blocked by required conditions
Implement thread ownership change for RenderingDevice
2024-10-22 13:10:32 -07:00
Adam Scott
152e24c7de
Windows prototype using GetTempPathW() 2024-10-22 11:57:12 -04:00
Adam Scott
ca7840073c
Add tmp utilities 2024-10-22 11:57:12 -04:00
Pedro J. Estébanez
d5d509bbd6 Implement thread ownership change for RenderingDevice 2024-10-21 20:56:42 +02:00
13 changed files with 92 additions and 31 deletions

View File

@ -580,6 +580,31 @@ bool DirAccess::is_case_sensitive(const String &p_path) const {
return true;
}
void DirAccess::_delete_tmp() {
// Remove created tmp directory.
if (!_is_tmp || _tmp_keep_after_free) {
return;
}
if (!DirAccess::exists(_tmp_path)) {
return;
}
Error err;
{
Ref<DirAccess> dir_access = DirAccess::open(_tmp_path, &err);
if (err != OK) {
return;
}
err = dir_access->erase_contents_recursive();
if (err != OK) {
return;
}
}
DirAccess::remove_absolute(_tmp_path);
}
void DirAccess::_bind_methods() {
ClassDB::bind_static_method("DirAccess", D_METHOD("open", "path"), &DirAccess::_open);
ClassDB::bind_static_method("DirAccess", D_METHOD("get_open_error"), &DirAccess::get_open_error);
@ -629,26 +654,5 @@ void DirAccess::_bind_methods() {
}
DirAccess::~DirAccess() {
// Remove created tmp directory.
if (_is_tmp && !_tmp_keep_after_free) {
[&]() -> void {
if (!DirAccess::exists(_tmp_path)) {
return;
}
Error err;
{
Ref<DirAccess> dir_access = DirAccess::open(_tmp_path, &err);
if (err != OK) {
return;
}
err = dir_access->erase_contents_recursive();
if (err != OK) {
return;
}
}
DirAccess::remove_absolute(_tmp_path);
}();
}
_delete_tmp();
}

View File

@ -64,6 +64,7 @@ private:
bool _is_tmp = false;
bool _tmp_keep_after_free = false;
String _tmp_path;
void _delete_tmp();
protected:
static void _bind_methods();

View File

@ -68,6 +68,19 @@ void FileAccess::_set_access_type(AccessType p_access) {
_access_type = p_access;
}
void FileAccess::_delete_tmp() {
// Remove created tmp file.
if (!_is_tmp_file || _tmp_keep_after_use) {
return;
}
if (!FileAccess::exists(_tmp_path)) {
return;
}
DirAccess::remove_absolute(_tmp_path);
}
Ref<FileAccess> FileAccess::create_for_path(const String &p_path) {
Ref<FileAccess> ret;
if (p_path.begins_with("res://")) {
@ -936,13 +949,5 @@ void FileAccess::_bind_methods() {
}
FileAccess::~FileAccess() {
// Remove created tmp file.
if (_is_tmp_file && !_tmp_keep_after_use) {
[&]() -> void {
if (!FileAccess::exists(_tmp_path)) {
return;
}
DirAccess::remove_absolute(_tmp_path);
}();
}
_delete_tmp();
}

View File

@ -125,6 +125,7 @@ private:
bool _is_tmp_file = false;
bool _tmp_keep_after_use = false;
String _tmp_path;
void _delete_tmp();
public:
static void set_file_close_fail_notify_callback(FileCloseFailNotify p_cbk) { close_fail_notify = p_cbk; }

View File

@ -131,6 +131,18 @@ public class GodotIO {
return activity.getCacheDir().getAbsolutePath();
}
public String getTmpDir() {
File tmpDir = new File(getCacheDir() + "/tmp");
if (!tmpDir.exists()) {
if (!tmpDir.mkdirs()) {
Log.e(TAG, "Unable to create tmp dir");
}
}
return tmpDir.getAbsolutePath();
}
public String getDataDir() {
return activity.getFilesDir().getAbsolutePath();
}

View File

@ -52,6 +52,7 @@ GodotIOJavaWrapper::GodotIOJavaWrapper(JNIEnv *p_env, jobject p_godot_io_instanc
_open_URI = p_env->GetMethodID(cls, "openURI", "(Ljava/lang/String;)I");
_get_cache_dir = p_env->GetMethodID(cls, "getCacheDir", "()Ljava/lang/String;");
_get_tmp_dir = p_env->GetMethodID(cls, "getTmpDir", "()Ljava/lang/String;");
_get_data_dir = p_env->GetMethodID(cls, "getDataDir", "()Ljava/lang/String;");
_get_display_cutouts = p_env->GetMethodID(cls, "getDisplayCutouts", "()[I"),
_get_display_safe_area = p_env->GetMethodID(cls, "getDisplaySafeArea", "()[I"),
@ -106,6 +107,17 @@ String GodotIOJavaWrapper::get_cache_dir() {
}
}
String GodotIOJavaWrapper::get_tmp_dir() {
if (_get_tmp_dir) {
JNIEnv *env = get_jni_env();
ERR_FAIL_NULL_V(env, String());
jstring s = (jstring)env->CallObjectMethod(godot_io_instance, _get_tmp_dir);
return jstring_to_string(s, env);
} else {
return String();
}
}
String GodotIOJavaWrapper::get_user_data_dir() {
if (_get_data_dir) {
JNIEnv *env = get_jni_env();

View File

@ -48,6 +48,7 @@ private:
jmethodID _open_URI = 0;
jmethodID _get_cache_dir = 0;
jmethodID _get_data_dir = 0;
jmethodID _get_tmp_dir = 0;
jmethodID _get_display_cutouts = 0;
jmethodID _get_display_safe_area = 0;
jmethodID _get_locale = 0;
@ -71,6 +72,7 @@ public:
Error open_uri(const String &p_uri);
String get_cache_dir();
String get_tmp_dir();
String get_user_data_dir();
String get_locale();
String get_model();

View File

@ -677,6 +677,19 @@ String OS_Android::get_cache_path() const {
return ".";
}
String OS_Android::get_tmp_path() const {
if (!tmp_dir_cache.is_empty()) {
return tmp_dir_cache;
}
String tmp_dir = godot_io_java->get_tmp_dir();
if (!tmp_dir.is_empty()) {
tmp_dir_cache = _remove_symlink(tmp_dir);
return tmp_dir_cache;
}
return ".";
}
String OS_Android::get_unique_id() const {
String unique_id = godot_io_java->get_unique_id();
if (!unique_id.is_empty()) {

View File

@ -58,6 +58,7 @@ private:
mutable String data_dir_cache;
mutable String cache_dir_cache;
mutable String tmp_dir_cache;
mutable String remote_fs_dir;
AudioDriverOpenSL audio_driver_android;
@ -148,6 +149,7 @@ public:
virtual String get_user_data_dir() const override;
virtual String get_data_path() const override;
virtual String get_cache_path() const override;
virtual String get_tmp_path() const override;
virtual String get_resource_dir() const override;
virtual String get_locale() const override;
virtual String get_model_name() const override;

View File

@ -1865,6 +1865,7 @@ String OS_Windows::get_tmp_path() const {
void *get_temp_path = (void *)GetProcAddress(GetModuleHandleA("kernel32.dll"), "GetTempPathW");
if (get_temp_path) {
Vector<WCHAR> tmp_path;
tmp_path.resize(MAX_PATH);
DWORD tmp_path_length = GetTempPathW(MAX_PATH, (LPWSTR)tmp_path.ptrw());
if (tmp_path_length > 0 && tmp_path_length < MAX_PATH) {
tmp_path_cache = String::utf16((const char16_t *)tmp_path.ptr(), tmp_path_length / sizeof(WCHAR));

View File

@ -7260,6 +7260,10 @@ void RenderingDevice::_bind_methods() {
BIND_ENUM_CONSTANT(DEBUG_PASS);
}
void RenderingDevice::make_current() {
render_thread_id = Thread::get_caller_id();
}
RenderingDevice::~RenderingDevice() {
finalize();

View File

@ -1496,6 +1496,8 @@ public:
static RenderingDevice *get_singleton();
void make_current();
RenderingDevice();
~RenderingDevice();

View File

@ -370,6 +370,8 @@ Size2i RenderingServerDefault::get_maximum_viewport_size() const {
void RenderingServerDefault::_assign_mt_ids(WorkerThreadPool::TaskID p_pump_task_id) {
server_thread = Thread::get_caller_id();
server_task_id = p_pump_task_id;
// This is needed because the main RD is created on the main thread.
RenderingDevice::get_singleton()->make_current();
}
void RenderingServerDefault::_thread_exit() {