// =====================================================================================================================
// fennec, a free and open source game engine
// Copyright © 2025 Medusa Slockbower
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see .
// =====================================================================================================================
#include
#include
#ifdef FENNEC_LIB_WAYLAND
#include
#include
#endif
namespace fennec
{
linux_platform::linux_platform(user _type)
: platform(_type)
, _display_driver(display_none) {
switch (_type) {
case user::client: {
_runtime_client_checks();
return;
}
case user::server: {
_runtime_server_checks();
}
}
}
linux_platform::~linux_platform() {
if (_display) {
delete _display;
_display = nullptr;
}
}
shared_object* linux_platform::load_object(const cstring& file) {
void* handle = dlopen(file, RTLD_NOW | RTLD_LOCAL);
const char* load_error = dlerror();
assert(handle != nullptr, load_error);
return static_cast(handle);
}
void linux_platform::unload_object(shared_object* obj) {
if (obj) {
dlclose(obj);
}
}
platform::function_pointer linux_platform::find_symbol(shared_object* hndl, const cstring& name) {
string _name = name;
void* symbol = dlsym(hndl, _name);
if (symbol == nullptr) {
_name = '_' + _name;
symbol = dlsym(hndl, _name);
}
return (function_pointer)symbol;
}
display* linux_platform::get_display() {
return _display;
}
void linux_platform::_runtime_client_checks() {
#ifdef FENNEC_LIB_WAYLAND
if (libwayland::load_symbols(this)) {
_display_driver = display_wayland;
_display = new wayland_display(this);
libwayland::unload_symbols(this); // Doesn't actually unload symbols, just resets ref counter to only consider
// the created display
}
#endif
assertf(_display != nullptr, "failed to find suitable display driver");
}
void linux_platform::_find_display_driver() {
}
void linux_platform::_runtime_server_checks() {
}
}