From aee8d6e59ed09f7ee603222a5f963354b0200f84 Mon Sep 17 00:00:00 2001 From: Jorge Acereda Date: Fri, 23 Feb 2024 21:46:51 +0100 Subject: [PATCH 1/9] WIP, Haiku port --- common/unix.mk | 8 +++++++ library/unix/build.mk | 2 +- nfd/nfd_portal.cpp | 15 ++++++++++++- profiler/build/unix/build.mk | 2 +- profiler/build/unix/debug.mk | 6 ++++++ profiler/build/unix/legacy.mk | 2 +- profiler/src/imgui/imgui_impl_glfw.cpp | 4 ++++ .../src/imgui/imgui_impl_opengl3_loader.h | 8 ++++++- public/client/TracyCallstack.h | 2 ++ public/client/TracyOverride.cpp | 2 +- public/client/TracyProfiler.cpp | 21 ++++++++++++++++++- public/client/TracyRingBuffer.hpp | 2 ++ public/client/TracySysTime.cpp | 21 ++++++++++++++++++- public/client/TracySysTime.hpp | 2 +- public/common/TracySocket.cpp | 6 +++++- public/common/TracySystem.cpp | 4 ++++ public/libbacktrace/elf.cpp | 5 +++++ server/TracyFileRead.hpp | 2 +- server/TracyView.cpp | 6 ++++++ server/TracyWeb.cpp | 2 +- test/Makefile | 7 ++++++- 21 files changed, 116 insertions(+), 13 deletions(-) diff --git a/common/unix.mk b/common/unix.mk index f836bdfc..491801c3 100644 --- a/common/unix.mk +++ b/common/unix.mk @@ -16,6 +16,14 @@ else ifeq (0,$(shell ld -ltbb -o /dev/null 2>/dev/null; echo $$?)) endif endif + +ifeq ($(shell uname -o),Haiku) + LIBS += -lroot -lnetwork -luuid +else + LIBS += -ldl +endif + + OBJDIRBASE := obj/$(BUILD) OBJDIR := $(OBJDIRBASE)/o/o/o diff --git a/library/unix/build.mk b/library/unix/build.mk index 9fa7c538..5ac6a48c 100644 --- a/library/unix/build.mk +++ b/library/unix/build.mk @@ -2,7 +2,7 @@ CFLAGS += CXXFLAGS := $(CFLAGS) -std=c++11 -fpic DEFINES += -DTRACY_ENABLE INCLUDES := -LIBS := -lpthread -ldl +LIBS := -lpthread PROJECT := libtracy IMAGE := $(PROJECT)-$(BUILD).so SHARED_LIBRARY := yes diff --git a/nfd/nfd_portal.cpp b/nfd/nfd_portal.cpp index 23e1f1f4..0db2bb38 100644 --- a/nfd/nfd_portal.cpp +++ b/nfd/nfd_portal.cpp @@ -16,7 +16,20 @@ #include #include // for access() -#if !defined(__has_include) || !defined(__linux__) +#if defined __HAIKU__ +#include +static inline size_t szmin(size_t a, size_t b) { + return a < b? a : b; +} +static inline ssize_t getrandom(unsigned char * buf, size_t buflen, unsigned int flags) { + for (size_t i = 0; i < buflen; i += sizeof(uuid_t)) { + uuid_t uuid; + uuid_generate_random(uuid); + memcpy(buf+i, uuid, szmin(buflen-i, sizeof(uuid))); + } + return buflen; +} +#elif !defined(__has_include) || !defined(__linux__) #include // for getrandom() - the random token string #elif __has_include() #include diff --git a/profiler/build/unix/build.mk b/profiler/build/unix/build.mk index 42a9ba0a..93b49385 100644 --- a/profiler/build/unix/build.mk +++ b/profiler/build/unix/build.mk @@ -2,7 +2,7 @@ CFLAGS += CXXFLAGS := $(CFLAGS) -std=c++17 DEFINES += -DIMGUI_ENABLE_FREETYPE INCLUDES := -I../../../imgui $(shell pkg-config --cflags freetype2 capstone wayland-egl egl wayland-cursor xkbcommon) -LIBS := $(shell pkg-config --libs freetype2 capstone wayland-egl egl wayland-cursor xkbcommon) -lpthread -ldl +LIBS := $(shell pkg-config --libs freetype2 capstone wayland-egl egl wayland-cursor xkbcommon) -lpthread PROJECT := Tracy IMAGE := $(PROJECT)-$(BUILD) diff --git a/profiler/build/unix/debug.mk b/profiler/build/unix/debug.mk index d9b31daf..0187f96c 100644 --- a/profiler/build/unix/debug.mk +++ b/profiler/build/unix/debug.mk @@ -1,4 +1,10 @@ +ifeq ($(shell uname -o),Haiku) +CFLAGS := -gdwarf-3 -Wall +LDFLAGS := -gdwarf-3 +else CFLAGS := -g3 -Wall +LDFLAGS := -g3 +endif DEFINES := -DDEBUG BUILD := debug diff --git a/profiler/build/unix/legacy.mk b/profiler/build/unix/legacy.mk index dc2923c8..87e15407 100644 --- a/profiler/build/unix/legacy.mk +++ b/profiler/build/unix/legacy.mk @@ -2,7 +2,7 @@ CFLAGS += CXXFLAGS := $(CFLAGS) -std=c++17 DEFINES += -DIMGUI_ENABLE_FREETYPE INCLUDES := -I../../../imgui $(shell pkg-config --cflags glfw3 freetype2 capstone) -LIBS := $(shell pkg-config --libs glfw3 freetype2 capstone) -lpthread -ldl +LIBS := $(shell pkg-config --libs glfw3 freetype2 capstone) -lpthread PROJECT := Tracy IMAGE := $(PROJECT)-$(BUILD) diff --git a/profiler/src/imgui/imgui_impl_glfw.cpp b/profiler/src/imgui/imgui_impl_glfw.cpp index 211acc8d..762aa81f 100644 --- a/profiler/src/imgui/imgui_impl_glfw.cpp +++ b/profiler/src/imgui/imgui_impl_glfw.cpp @@ -117,7 +117,11 @@ #endif #define GLFW_HAS_FOCUS_WINDOW (GLFW_VERSION_COMBINED >= 3200) // 3.2+ glfwFocusWindow #define GLFW_HAS_FOCUS_ON_SHOW (GLFW_VERSION_COMBINED >= 3300) // 3.3+ GLFW_FOCUS_ON_SHOW +#if defined __HAIKU__ +#define GLFW_HAS_MONITOR_WORK_AREA 0 // Crashes +#else #define GLFW_HAS_MONITOR_WORK_AREA (GLFW_VERSION_COMBINED >= 3300) // 3.3+ glfwGetMonitorWorkarea +#endif #define GLFW_HAS_OSX_WINDOW_POS_FIX (GLFW_VERSION_COMBINED >= 3301) // 3.3.1+ Fixed: Resizing window repositions it on MacOS #1553 #ifdef GLFW_RESIZE_NESW_CURSOR // Let's be nice to people who pulled GLFW between 2019-04-16 (3.4 define) and 2019-11-29 (cursors defines) // FIXME: Remove when GLFW 3.4 is released? #define GLFW_HAS_NEW_CURSORS (GLFW_VERSION_COMBINED >= 3400) // 3.4+ GLFW_RESIZE_ALL_CURSOR, GLFW_RESIZE_NESW_CURSOR, GLFW_RESIZE_NWSE_CURSOR, GLFW_NOT_ALLOWED_CURSOR diff --git a/profiler/src/imgui/imgui_impl_opengl3_loader.h b/profiler/src/imgui/imgui_impl_opengl3_loader.h index 9aefdb7c..616d1b4e 100644 --- a/profiler/src/imgui/imgui_impl_opengl3_loader.h +++ b/profiler/src/imgui/imgui_impl_opengl3_loader.h @@ -685,7 +685,13 @@ static int open_libgl(void) libgl = dlopen("libGL.so.3", RTLD_LAZY | RTLD_LOCAL); if (!libgl) return GL3W_ERROR_LIBRARY_OPEN; - *(void **)(&glx_get_proc_address) = dlsym(libgl, "glXGetProcAddressARB"); + *(void **)(&glx_get_proc_address) = dlsym(libgl, +#if defined __HAIKU__ + "_glapi_get_proc_address" +#else + "glXGetProcAddressARB" +#endif + ); return GL3W_OK; } diff --git a/public/client/TracyCallstack.h b/public/client/TracyCallstack.h index 2c7ecad9..c469df7c 100644 --- a/public/client/TracyCallstack.h +++ b/public/client/TracyCallstack.h @@ -28,6 +28,8 @@ # define TRACY_HAS_CALLSTACK 4 # elif defined BSD # define TRACY_HAS_CALLSTACK 6 +# elif defined __HAIKU__ +# define TRACY_HAS_CALLSTACK 5 # endif #endif diff --git a/public/client/TracyOverride.cpp b/public/client/TracyOverride.cpp index 591508a7..f26dec61 100644 --- a/public/client/TracyOverride.cpp +++ b/public/client/TracyOverride.cpp @@ -1,5 +1,5 @@ #ifdef TRACY_ENABLE -# ifdef __linux__ +# if defined __linux__ || defined __HAIKU__ # include "TracyDebug.hpp" # ifdef TRACY_VERBOSE # include diff --git a/public/client/TracyProfiler.cpp b/public/client/TracyProfiler.cpp index ebdc83dc..9c0ade0b 100644 --- a/public/client/TracyProfiler.cpp +++ b/public/client/TracyProfiler.cpp @@ -90,7 +90,7 @@ # endif #endif -#ifdef __APPLE__ +#if defined __APPLE__ || defined __HAIKU__ # ifndef TRACY_DELAYED_INIT # define TRACY_DELAYED_INIT # endif @@ -422,6 +422,21 @@ static const char* GetProcessName() return processName; } + +#if defined __HAIKU__ +#include +static char executable_path[MAXPATHLEN]; + +extern "C" void +initialize_before(image_id our_image) +{ + image_info ii; + get_image_info(our_image, &ii); + snprintf(executable_path, sizeof(executable_path), "%s", ii.name); +} +#endif + + static const char* GetProcessExecutablePath() { #ifdef _WIN32 @@ -459,6 +474,8 @@ static const char* GetProcessExecutablePath() static char buf[_PC_PATH_MAX + 1]; _cmdname(buf); return buf; +#elif defined __HAIKU__ + return executable_path; #else return nullptr; #endif @@ -539,6 +556,8 @@ static const char* GetHostInfo() ptr += sprintf( ptr, "OS: BSD (OpenBSD)\n" ); #elif defined __QNX__ ptr += sprintf( ptr, "OS: QNX\n" ); +#elif defined __HAIKU__ + ptr += sprintf( ptr, "OS: Haiku (Haiku)\n" ); #else ptr += sprintf( ptr, "OS: unknown\n" ); #endif diff --git a/public/client/TracyRingBuffer.hpp b/public/client/TracyRingBuffer.hpp index e9100e2d..17fb0579 100644 --- a/public/client/TracyRingBuffer.hpp +++ b/public/client/TracyRingBuffer.hpp @@ -1,7 +1,9 @@ #include #include #include +#if !defined __HAIKU__ #include +#endif #include #include #include diff --git a/public/client/TracySysTime.cpp b/public/client/TracySysTime.cpp index b690a911..24100a49 100644 --- a/public/client/TracySysTime.cpp +++ b/public/client/TracySysTime.cpp @@ -78,6 +78,25 @@ void SysTime::ReadTimes() idle = data[4]; } +# elif defined __HAIKU__ + +void SysTime::ReadTimes() +{ + bigtime_t now = system_time(); + system_info si; + get_system_info(&si); + cpu_info ci[256]; + get_cpu_info(0, si.cpu_count, ci); + bigtime_t tot = 0; + for (uint32 i = 0; i < si.cpu_count; i++) + tot += ci[i].active_time; + used = tot / si.cpu_count; + static bigtime_t prev; + bigtime_t interval = now - prev; + idle = interval - used; + prev = now; +} + #endif SysTime::SysTime() @@ -97,7 +116,7 @@ float SysTime::Get() #if defined _WIN32 return diffUsed == 0 ? -1 : ( diffUsed - diffIdle ) * 100.f / diffUsed; -#elif defined __linux__ || defined __APPLE__ || defined BSD +#elif defined __linux__ || defined __APPLE__ || defined BSD || defined __HAIKU__ const auto total = diffUsed + diffIdle; return total == 0 ? -1 : diffUsed * 100.f / total; #endif diff --git a/public/client/TracySysTime.hpp b/public/client/TracySysTime.hpp index cb5ebe73..e7fca3fb 100644 --- a/public/client/TracySysTime.hpp +++ b/public/client/TracySysTime.hpp @@ -1,7 +1,7 @@ #ifndef __TRACYSYSTIME_HPP__ #define __TRACYSYSTIME_HPP__ -#if defined _WIN32 || defined __linux__ || defined __APPLE__ +#if defined _WIN32 || defined __linux__ || defined __APPLE__ || defined __HAIKU__ # define TRACY_HAS_SYSTIME #else # include diff --git a/public/common/TracySocket.cpp b/public/common/TracySocket.cpp index 25967898..f82648f2 100644 --- a/public/common/TracySocket.cpp +++ b/public/common/TracySocket.cpp @@ -37,6 +37,10 @@ # define MSG_NOSIGNAL 0 #endif +#if defined __HAIKU__ +#define TRACY_ONLY_IPV4 +#endif + namespace tracy { @@ -492,7 +496,7 @@ bool ListenSocket::Listen( uint16_t port, int backlog ) #if defined _WIN32 unsigned long val = 0; setsockopt( m_sock, IPPROTO_IPV6, IPV6_V6ONLY, (const char*)&val, sizeof( val ) ); -#elif defined BSD +#elif defined BSD || defined __HAIKU__ int val = 0; setsockopt( m_sock, IPPROTO_IPV6, IPV6_V6ONLY, (const char*)&val, sizeof( val ) ); val = 1; diff --git a/public/common/TracySystem.cpp b/public/common/TracySystem.cpp index 0e26aeca..303b3cf3 100644 --- a/public/common/TracySystem.cpp +++ b/public/common/TracySystem.cpp @@ -31,6 +31,8 @@ #elif defined __QNX__ # include # include +#elif defined __HAIKU__ +# include #endif #ifdef __MINGW32__ @@ -86,6 +88,8 @@ TRACY_API uint32_t GetThreadHandleImpl() #elif defined __EMSCRIPTEN__ // Not supported, but let it compile. return 0; +#elif defined __HAIKU__ + return find_thread(0); #else // To add support for a platform, retrieve and return the kernel thread identifier here. // diff --git a/public/libbacktrace/elf.cpp b/public/libbacktrace/elf.cpp index 22a4ba20..fb2ebbdd 100644 --- a/public/libbacktrace/elf.cpp +++ b/public/libbacktrace/elf.cpp @@ -71,6 +71,11 @@ POSSIBILITY OF SUCH DAMAGE. */ #endif #endif +#if defined __HAIKU__ +#undef HAVE_DL_ITERATE_PHDR +#define ElfW(x) Elf_##x +#endif + namespace tracy { diff --git a/server/TracyFileRead.hpp b/server/TracyFileRead.hpp index dec67e9c..aa8b8e66 100644 --- a/server/TracyFileRead.hpp +++ b/server/TracyFileRead.hpp @@ -16,7 +16,7 @@ #ifdef _MSC_VER # define stat64 _stat64 #endif -#if defined __APPLE__ || defined __FreeBSD__ +#if defined __APPLE__ || defined __FreeBSD__ || defined __HAIKU__ # define stat64 stat #endif diff --git a/server/TracyView.cpp b/server/TracyView.cpp index 3584615a..5f4d8629 100644 --- a/server/TracyView.cpp +++ b/server/TracyView.cpp @@ -31,6 +31,8 @@ #elif defined __APPLE__ || defined BSD # include # include +#elif defined __HAIKU__ +# include #endif #include "IconsFontAwesome6.h" @@ -141,6 +143,10 @@ void View::InitMemory() size_t sz = sizeof( memSize ); sysctlbyname( "hw.physmem", &memSize, &sz, nullptr, 0 ); m_totalMemory = memSize; +#elif defined __HAIKU__ + system_info sysInfo; + get_system_info(&sysInfo); + m_totalMemory = sysInfo.max_pages * PAGESIZE; #else m_totalMemory = 0; #endif diff --git a/server/TracyWeb.cpp b/server/TracyWeb.cpp index 91986f8c..1250089d 100644 --- a/server/TracyWeb.cpp +++ b/server/TracyWeb.cpp @@ -17,7 +17,7 @@ void OpenWebpage( const char* url ) { #ifdef _WIN32 ShellExecuteA( nullptr, nullptr, url, nullptr, nullptr, 0 ); -#elif defined __APPLE__ +#elif defined __APPLE__ || defined __HAIKU__ char buf[1024]; sprintf( buf, "open %s", url ); system( buf ); diff --git a/test/Makefile b/test/Makefile index 19b34384..ee5c607b 100644 --- a/test/Makefile +++ b/test/Makefile @@ -3,7 +3,12 @@ CFLAGS := $(OPTFLAGS) -Wall -DTRACY_ENABLE CXXFLAGS := $(CFLAGS) -std=gnu++11 DEFINES += INCLUDES := -I../public/tracy -LIBS := -lpthread -ldl +LIBS := -lpthread +ifeq ($(shell uname -o),Haiku) +LIBS += -lroot -lnetwork +else +LIBS += -ldl +endif LDFLAGS := -rdynamic IMAGE := tracy_test From 370f568a41ce061d4698c4d225fab462fe6e923f Mon Sep 17 00:00:00 2001 From: Jorge Acereda Date: Sat, 24 Feb 2024 18:20:58 +0100 Subject: [PATCH 2/9] Report Haiku memory size --- public/client/TracyProfiler.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/public/client/TracyProfiler.cpp b/public/client/TracyProfiler.cpp index 9c0ade0b..c9491425 100644 --- a/public/client/TracyProfiler.cpp +++ b/public/client/TracyProfiler.cpp @@ -745,6 +745,10 @@ static const char* GetHostInfo() } memSize = memSize / 1024 / 1024; ptr += sprintf( ptr, "RAM: %llu MB\n", memSize); +#elif defined __HAIKU__ + system_info si; + get_system_info(&si); + ptr += sprintf( ptr, "RAM: %llu MB\n", si.max_pages * PAGESIZE / 1024 / 1024); #else ptr += sprintf( ptr, "RAM: unknown\n" ); #endif From b94728756c4466eeb500409668de49743bdd89f8 Mon Sep 17 00:00:00 2001 From: Jorge Acereda Date: Sun, 25 Feb 2024 12:42:19 +0100 Subject: [PATCH 3/9] Haiku OS info --- profiler/src/HttpRequest.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/profiler/src/HttpRequest.cpp b/profiler/src/HttpRequest.cpp index 62181b44..e3b81d83 100644 --- a/profiler/src/HttpRequest.cpp +++ b/profiler/src/HttpRequest.cpp @@ -68,6 +68,8 @@ static const char* GetOsInfo() sprintf( buf, "BSD (OpenBSD)" ); #elif defined __QNX__ sprintf( buf, "QNX" ); +#elif defined __HAIKU__ + sprintf( buf, "Haiku" ); #else sprintf( buf, "unknown" ); #endif From ab904132237b73e9e0c3330960522ba3786a12c3 Mon Sep 17 00:00:00 2001 From: Jorge Acereda Date: Sun, 25 Feb 2024 12:42:42 +0100 Subject: [PATCH 4/9] Haiku OS info --- public/client/TracyProfiler.cpp | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/public/client/TracyProfiler.cpp b/public/client/TracyProfiler.cpp index c9491425..c4504861 100644 --- a/public/client/TracyProfiler.cpp +++ b/public/client/TracyProfiler.cpp @@ -418,6 +418,12 @@ static const char* GetProcessName() if( buf ) processName = buf; #elif defined __QNX__ processName = __progname; +#elif defined __HAIKU__ + team_info ti; + get_team_info(B_CURRENT_TEAM, &ti); + static char name[B_OS_NAME_LENGTH]; + memcpy(name, ti.name, sizeof(name)); + processName = name; #endif return processName; } @@ -557,7 +563,7 @@ static const char* GetHostInfo() #elif defined __QNX__ ptr += sprintf( ptr, "OS: QNX\n" ); #elif defined __HAIKU__ - ptr += sprintf( ptr, "OS: Haiku (Haiku)\n" ); + ptr += sprintf( ptr, "OS: Haiku\n" ); #else ptr += sprintf( ptr, "OS: unknown\n" ); #endif @@ -748,7 +754,8 @@ static const char* GetHostInfo() #elif defined __HAIKU__ system_info si; get_system_info(&si); - ptr += sprintf( ptr, "RAM: %llu MB\n", si.max_pages * PAGESIZE / 1024 / 1024); + size_t memSize = si.max_pages * PAGESIZE; + ptr += sprintf( ptr, "RAM: %zu MB\n", memSize / 1024 / 1024); #else ptr += sprintf( ptr, "RAM: unknown\n" ); #endif From 945db73ec6ce7f850566ff59048204cdac91d6c6 Mon Sep 17 00:00:00 2001 From: Jorge Acereda Date: Sun, 25 Feb 2024 12:43:00 +0100 Subject: [PATCH 5/9] Haiku OS thread info --- public/common/TracySystem.cpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/public/common/TracySystem.cpp b/public/common/TracySystem.cpp index 303b3cf3..77b66d44 100644 --- a/public/common/TracySystem.cpp +++ b/public/common/TracySystem.cpp @@ -200,6 +200,8 @@ TRACY_API void SetThreadName( const char* name ) pthread_setname_np( pthread_self(), buf ); } }; +#elif defined __HAIKU__ + rename_thread(find_thread(0), name); #endif #ifdef TRACY_ENABLE { @@ -284,6 +286,10 @@ TRACY_API const char* GetThreadName( uint32_t id ) if (pthread_getname_np(static_cast(id), qnxNameBuf, _NTO_THREAD_NAME_MAX) == 0) { return qnxNameBuf; }; +#elif defined __HAIKU__ + thread_info ti; + get_thread_info(find_thread(NULL), &ti); + snprintf(buf, sizeof(buf), "%s", ti.name); #endif sprintf( buf, "%" PRIu32, id ); From dc3823c4913558a17e5592bb7265a22d0a776de6 Mon Sep 17 00:00:00 2001 From: Jorge Acereda Date: Sun, 25 Feb 2024 19:28:22 +0100 Subject: [PATCH 6/9] Incomplete file dialog implementation for Haiku --- nfd/nfd_haiku.cpp | 70 +++++++++++++++++++++++++++++++++++ profiler/build/unix/build.mk | 11 ++++-- profiler/build/unix/debug.mk | 5 --- profiler/build/unix/legacy.mk | 11 ++++-- 4 files changed, 86 insertions(+), 11 deletions(-) create mode 100644 nfd/nfd_haiku.cpp diff --git a/nfd/nfd_haiku.cpp b/nfd/nfd_haiku.cpp new file mode 100644 index 00000000..0c35c9de --- /dev/null +++ b/nfd/nfd_haiku.cpp @@ -0,0 +1,70 @@ +#include "nfd.h" + +#include +#include +#include +#include + +nfdresult_t NFD_Init(void) { + return NFD_OKAY; +} + +void NFD_Quit(void) {} + +static nfdresult_t dialog(BFilePanel &p, nfdnchar_t **outPath, + const nfdnfilteritem_t *filterList, + nfdfiltersize_t filterCount) { + p.Show(); + while (p.IsShowing()) + usleep(100000); + entry_ref sel; + if (p.GetNextSelectedRef(&sel) == B_OK) { + BEntry e(&sel); + BPath path; + if (e.GetPath(&path) == B_OK) { + outPath[0] = strdup(path.Path()); + return NFD_OKAY; + } + } + return NFD_CANCEL; +} + +class NFDFilter : public BRefFilter { +public: + NFDFilter(const nfdnfilteritem_t *filterList, nfdfiltersize_t filterCount) {} + + bool Filter(const entry_ref *ref, BNode *node, struct stat_beos *stat, + const char *mimeType) override { + return true; + } +}; + +nfdresult_t +NFD_OpenDialogN(nfdnchar_t **outPath, const nfdnfilteritem_t *filterList, + nfdfiltersize_t filterCount, const nfdnchar_t *defaultPath) { + NFDFilter f(filterList, filterCount); + BFilePanel p(B_OPEN_PANEL, NULL, NULL, 0, false, NULL, &f, true, true); + p.Window()->SetTitle(filterList[0].name); + if (defaultPath) + p.SetPanelDirectory(defaultPath); + return dialog(p, outPath, filterList, filterCount); +} + +nfdresult_t NFD_SaveDialogN(nfdnchar_t** outPath, + const nfdnfilteritem_t* filterList, + nfdfiltersize_t filterCount, + const nfdnchar_t* defaultPath, + const nfdnchar_t* defaultName) { + NFDFilter f(filterList, filterCount); + BFilePanel p(B_SAVE_PANEL, NULL, NULL, 0, false, NULL, &f, true, true); + p.Window()->SetTitle(filterList[0].name); + if (defaultPath) + p.SetPanelDirectory(defaultPath); + if (defaultName) + p.SetSaveText(defaultName); + return dialog(p, outPath, filterList, filterCount); +} + +void NFD_FreePathN(nfdnchar_t* filePath) { + free(filePath); +} diff --git a/profiler/build/unix/build.mk b/profiler/build/unix/build.mk index 93b49385..153dfb91 100644 --- a/profiler/build/unix/build.mk +++ b/profiler/build/unix/build.mk @@ -21,9 +21,14 @@ else INCLUDES += $(shell pkg-config --cflags gtk+-3.0) LIBS += $(shell pkg-config --libs gtk+-3.0) else - SRC += ../../../nfd/nfd_portal.cpp - INCLUDES += $(shell pkg-config --cflags dbus-1) - LIBS += $(shell pkg-config --libs dbus-1) + ifeq ($(shell uname -o),Haiku) + SRC += ../../../nfd/nfd_haiku.cpp + LIBS += -lbe -ltracker + else + SRC += ../../../nfd/nfd_portal.cpp + INCLUDES += $(shell pkg-config --cflags dbus-1) + LIBS += $(shell pkg-config --libs dbus-1) + endif endif endif diff --git a/profiler/build/unix/debug.mk b/profiler/build/unix/debug.mk index 0187f96c..2afc422d 100644 --- a/profiler/build/unix/debug.mk +++ b/profiler/build/unix/debug.mk @@ -1,10 +1,5 @@ -ifeq ($(shell uname -o),Haiku) -CFLAGS := -gdwarf-3 -Wall -LDFLAGS := -gdwarf-3 -else CFLAGS := -g3 -Wall LDFLAGS := -g3 -endif DEFINES := -DDEBUG BUILD := debug diff --git a/profiler/build/unix/legacy.mk b/profiler/build/unix/legacy.mk index 87e15407..f2410c7a 100644 --- a/profiler/build/unix/legacy.mk +++ b/profiler/build/unix/legacy.mk @@ -23,9 +23,14 @@ else INCLUDES += $(shell pkg-config --cflags gtk+-3.0) LIBS += $(shell pkg-config --libs gtk+-3.0) else - SRC += ../../../nfd/nfd_portal.cpp - INCLUDES += $(shell pkg-config --cflags dbus-1) - LIBS += $(shell pkg-config --libs dbus-1) + ifeq ($(shell uname -o),Haiku) + SRC += ../../../nfd/nfd_haiku.cpp + LIBS += -lbe -ltracker + else + SRC += ../../../nfd/nfd_portal.cpp + INCLUDES += $(shell pkg-config --cflags dbus-1) + LIBS += $(shell pkg-config --libs dbus-1) + endif endif endif endif From 9189b4293d1545ebf11131a18dabc286f863ed5c Mon Sep 17 00:00:00 2001 From: Jorge Acereda Date: Tue, 27 Feb 2024 23:18:39 +0100 Subject: [PATCH 7/9] Fix for Haiku --- update/src/update.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/update/src/update.cpp b/update/src/update.cpp index 06650436..fe587b81 100644 --- a/update/src/update.cpp +++ b/update/src/update.cpp @@ -17,7 +17,7 @@ #include "OfflineSymbolResolver.h" -#ifdef __APPLE__ +#if defined __APPLE__ || defined __HAIKU__ # define ftello64(x) ftello(x) #elif defined _WIN32 # define ftello64(x) _ftelli64(x) From fbe6bac72373c2344042a8b8c33ba03ea4b00362 Mon Sep 17 00:00:00 2001 From: Jorge Acereda Date: Tue, 27 Feb 2024 23:40:56 +0100 Subject: [PATCH 8/9] Use callstack method 2 on Haiku --- public/client/TracyCallstack.h | 2 +- public/libbacktrace/config.h | 6 ++++++ public/libbacktrace/elf.cpp | 5 ++--- test/Makefile | 2 +- 4 files changed, 10 insertions(+), 5 deletions(-) diff --git a/public/client/TracyCallstack.h b/public/client/TracyCallstack.h index c469df7c..8e9a8de7 100644 --- a/public/client/TracyCallstack.h +++ b/public/client/TracyCallstack.h @@ -29,7 +29,7 @@ # elif defined BSD # define TRACY_HAS_CALLSTACK 6 # elif defined __HAIKU__ -# define TRACY_HAS_CALLSTACK 5 +# define TRACY_HAS_CALLSTACK 2 # endif #endif diff --git a/public/libbacktrace/config.h b/public/libbacktrace/config.h index 87e38a95..e22b3b02 100644 --- a/public/libbacktrace/config.h +++ b/public/libbacktrace/config.h @@ -3,6 +3,12 @@ // include __WORDSIZE headers for musl # include #endif + +#ifdef __HAIKU__ +# include +# define __WORDSIZE __HAIKU_ARCH_BITS +#endif + #if __WORDSIZE == 64 # define BACKTRACE_ELF_SIZE 64 #else diff --git a/public/libbacktrace/elf.cpp b/public/libbacktrace/elf.cpp index fb2ebbdd..405a1759 100644 --- a/public/libbacktrace/elf.cpp +++ b/public/libbacktrace/elf.cpp @@ -71,9 +71,8 @@ POSSIBILITY OF SUCH DAMAGE. */ #endif #endif -#if defined __HAIKU__ -#undef HAVE_DL_ITERATE_PHDR -#define ElfW(x) Elf_##x +#ifdef __HAIKU__ +# define ElfW(x) Elf_##x #endif namespace tracy diff --git a/test/Makefile b/test/Makefile index ee5c607b..9f714b93 100644 --- a/test/Makefile +++ b/test/Makefile @@ -5,7 +5,7 @@ DEFINES += INCLUDES := -I../public/tracy LIBS := -lpthread ifeq ($(shell uname -o),Haiku) -LIBS += -lroot -lnetwork +LIBS += -lroot -lnetwork -lbsd else LIBS += -ldl endif From 85f14314d0146378d0d7a442697dc4abc79123c7 Mon Sep 17 00:00:00 2001 From: Jorge Acereda Date: Tue, 27 Feb 2024 23:59:10 +0100 Subject: [PATCH 9/9] Filtering --- nfd/nfd_haiku.cpp | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/nfd/nfd_haiku.cpp b/nfd/nfd_haiku.cpp index 0c35c9de..c8c0b316 100644 --- a/nfd/nfd_haiku.cpp +++ b/nfd/nfd_haiku.cpp @@ -30,12 +30,22 @@ static nfdresult_t dialog(BFilePanel &p, nfdnchar_t **outPath, } class NFDFilter : public BRefFilter { + const nfdnfilteritem_t * _filter; + nfdfiltersize_t _count; public: - NFDFilter(const nfdnfilteritem_t *filterList, nfdfiltersize_t filterCount) {} + NFDFilter(const nfdnfilteritem_t *filterList, nfdfiltersize_t filterCount) + : _filter(filterList) + , _count(filterCount) {} bool Filter(const entry_ref *ref, BNode *node, struct stat_beos *stat, const char *mimeType) override { - return true; + BString name(ref->name); + if (node->IsDirectory()) + return true; + for (auto i = 0; i < _count; i++) + if (name.EndsWith(_filter[0].spec)) + return true; + return false; } };