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

Haiku port #735

Draft
wants to merge 9 commits into
base: master
Choose a base branch
from
Draft
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
8 changes: 8 additions & 0 deletions common/unix.mk
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion library/unix/build.mk
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
80 changes: 80 additions & 0 deletions nfd/nfd_haiku.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
#include "nfd.h"

#include <FilePanel.h>
#include <Window.h>
#include <Path.h>
#include <string.h>

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 {
const nfdnfilteritem_t * _filter;
nfdfiltersize_t _count;
public:
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 {
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;
}
};

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);
}
15 changes: 14 additions & 1 deletion nfd/nfd_portal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,20 @@
#include <string.h>
#include <unistd.h> // for access()

#if !defined(__has_include) || !defined(__linux__)
#if defined __HAIKU__
#include <uuid/uuid.h>
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 <sys/random.h> // for getrandom() - the random token string
#elif __has_include(<sys/random.h>)
#include <sys/random.h>
Expand Down
13 changes: 9 additions & 4 deletions profiler/build/unix/build.mk
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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

Expand Down
1 change: 1 addition & 0 deletions profiler/build/unix/debug.mk
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
CFLAGS := -g3 -Wall
LDFLAGS := -g3
DEFINES := -DDEBUG
BUILD := debug

Expand Down
13 changes: 9 additions & 4 deletions profiler/build/unix/legacy.mk
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
Expand Down
2 changes: 2 additions & 0 deletions profiler/src/HttpRequest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions profiler/src/imgui/imgui_impl_glfw.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 7 additions & 1 deletion profiler/src/imgui/imgui_impl_opengl3_loader.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
2 changes: 2 additions & 0 deletions public/client/TracyCallstack.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@
# define TRACY_HAS_CALLSTACK 4
# elif defined BSD
# define TRACY_HAS_CALLSTACK 6
# elif defined __HAIKU__
# define TRACY_HAS_CALLSTACK 2
# endif

#endif
Expand Down
2 changes: 1 addition & 1 deletion public/client/TracyOverride.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#ifdef TRACY_ENABLE
# ifdef __linux__
# if defined __linux__ || defined __HAIKU__
# include "TracyDebug.hpp"
# ifdef TRACY_VERBOSE
# include <dlfcn.h>
Expand Down
32 changes: 31 additions & 1 deletion public/client/TracyProfiler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@
# endif
#endif

#ifdef __APPLE__
#if defined __APPLE__ || defined __HAIKU__
# ifndef TRACY_DELAYED_INIT
# define TRACY_DELAYED_INIT
# endif
Expand Down Expand Up @@ -418,10 +418,31 @@ 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;
}


#if defined __HAIKU__
#include <image.h>
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
Expand Down Expand Up @@ -459,6 +480,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
Expand Down Expand Up @@ -539,6 +562,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\n" );
#else
ptr += sprintf( ptr, "OS: unknown\n" );
#endif
Expand Down Expand Up @@ -726,6 +751,11 @@ 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);
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
Expand Down
2 changes: 2 additions & 0 deletions public/client/TracyRingBuffer.hpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
#include <atomic>
#include <assert.h>
#include <errno.h>
#if !defined __HAIKU__
#include <linux/perf_event.h>
#endif
#include <stdint.h>
#include <string.h>
#include <sys/ioctl.h>
Expand Down
21 changes: 20 additions & 1 deletion public/client/TracySysTime.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion public/client/TracySysTime.hpp
Original file line number Diff line number Diff line change
@@ -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 <sys/param.h>
Expand Down
6 changes: 5 additions & 1 deletion public/common/TracySocket.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@
# define MSG_NOSIGNAL 0
#endif

#if defined __HAIKU__
#define TRACY_ONLY_IPV4
#endif

namespace tracy
{

Expand Down Expand Up @@ -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;
Expand Down
Loading