Skip to content

Commit

Permalink
Dynamic Config Refactor
Browse files Browse the repository at this point in the history
-generate wayland-protocols.h by CMake
-remove std::optional usage in registrar; depend on nullptr
-simplify Registrar

Signed-off-by: Joel Winarske <joel.winarske@gmail.com>
  • Loading branch information
jwinarske committed May 3, 2024
1 parent b816db5 commit 26d6e71
Show file tree
Hide file tree
Showing 32 changed files with 368 additions and 466 deletions.
55 changes: 32 additions & 23 deletions include/wayland-protocols.h → cmake/wayland-protocols.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -19,70 +19,79 @@

#include <wayland-client-protocol.h>

#if defined(ENABLE_XDG_CLIENT)

#cmakedefine01 ENABLE_XDG_CLIENT
#cmakedefine01 ENABLE_AGL_SHELL_CLIENT
#cmakedefine01 ENABLE_IVI_SHELL_CLIENT
#cmakedefine01 ENABLE_DRM_LEASE_CLIENT

#cmakedefine01 HAS_WAYLAND_PROTOCOL_XDG_SHELL
#cmakedefine01 HAS_WAYLAND_PROTOCOL_AGL_SHELL
#cmakedefine01 HAS_WAYLAND_PROTOCOL_AGL_SHELL_DESKTOP
#cmakedefine01 HAS_WAYLAND_PROTOCOL_AGL_SCREENSHOOTER
#cmakedefine01 HAS_WAYLAND_PROTOCOL_DRM_LEASE_V1
#cmakedefine01 HAS_WAYLAND_PROTOCOL_PRESENTATION_TIME
#cmakedefine01 HAS_WAYLAND_PROTOCOL_FRACTIONAL_SCALE_V1
#cmakedefine01 HAS_WAYLAND_PROTOCOL_VIEWPORTER
#cmakedefine01 HAS_WAYLAND_PROTOCOL_TEARING_CONTROL_V1
#cmakedefine01 HAS_WAYLAND_PROTOCOL_XDG_OUTPUT_UNSTABLE_V1
#cmakedefine01 HAS_WAYLAND_PROTOCOL_XDG_DECORATION_UNSTABLE_V1
#cmakedefine01 HAS_WAYLAND_PROTOCOL_LINUX_DMABUF_V1GLOBAL

#cmakedefine01 HAVE_MEMFD_CREATE
#cmakedefine01 HAVE_POSIX_FALLOCATE
#cmakedefine01 HAVE_MKOSTEMP


#if ENABLE_XDG_CLIENT
#include "xdg-shell-client-protocol.h"

#endif

#if defined(ENABLE_AGL_SHELL_CLIENT)
#if ENABLE_AGL_SHELL_CLIENT
#include "agl-shell-client-protocol.h"
#include "agl-shell-desktop-client-protocol.h"
#include "agl-screenshooter-client-protocol.h"
#endif

#if defined(ENABLE_IVI_SHELL_CLIENT)
#if ENABLE_IVI_SHELL_CLIENT
#include "ivi-wm-client-protocol.h"
#include "ivi-application-client-protocol.h"
#endif

#if defined(HAS_WAYLAND_PROTOCOL_DRM_LEASE_V1)

#if HAS_WAYLAND_PROTOCOL_DRM_LEASE_V1
#include "drm-lease-v1-client-protocol.h"

#endif

#if defined(HAS_WAYLAND_PROTOCOL_XDG_DECORATION_UNSTABLE_V1)

#if HAS_WAYLAND_PROTOCOL_XDG_DECORATION_UNSTABLE_V1
#include "xdg-decoration-unstable-v1-client-protocol.h"

#else
struct zxdg_decoration_manager_v1;
struct zxdg_toplevel_decoration_v1;
#endif

#include "presentation-time-client-protocol.h"

#if defined(HAS_WAYLAND_PROTOCOL_FRACTIONAL_SCALE_V1)

#if HAS_WAYLAND_PROTOCOL_FRACTIONAL_SCALE_V1
#include "fractional-scale-v1-client-protocol.h"

#else
struct wp_fractional_scale_manager_v1;
struct wp_fractional_scale_v1;
#endif

#if defined(HAS_WAYLAND_PROTOCOL_TEARING_CONTROL_V1)

#if HAS_WAYLAND_PROTOCOL_TEARING_CONTROL_V1
#include "tearing-control-v1-client-protocol.h"

#else
struct wp_tearing_control_manager_v1;
#endif

#if defined(HAS_WAYLAND_PROTOCOL_VIEWPORTER)

#if HAS_WAYLAND_PROTOCOL_VIEWPORTER
#include "viewporter-client-protocol.h"

#else
struct wp_viewporter;
struct wp_viewport;
#endif

#if defined(HAS_WAYLAND_PROTOCOL_XDG_OUTPUT_UNSTABLE_V1)

#if HAS_WAYLAND_PROTOCOL_XDG_OUTPUT_UNSTABLE_V1
#include "xdg-output-unstable-v1-client-protocol.h"

#else
struct zxdg_output_manager_v1;
struct zxdg_output_v1;
Expand Down
26 changes: 7 additions & 19 deletions cmake/wayland.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@ option(ENABLE_DRM_LEASE_CLIENT "Enable DRM Lease Client" OFF)
find_package(PkgConfig REQUIRED)
pkg_check_modules(WAYLAND REQUIRED IMPORTED_TARGET wayland-client wayland-egl wayland-cursor xkbcommon)

include(CheckFunctionExists)
check_function_exists(memfd_create HAVE_MEMFD_CREATE)
check_function_exists(posix_fallocate HAVE_POSIX_FALLOCATE)
check_function_exists(mkostemp HAVE_MKOSTEMP)

set(MIN_PROTOCOL_VER 1.13)
if (ENABLE_DRM_LEASE)
set(MIN_PROTOCOL_VER 1.22)
Expand Down Expand Up @@ -64,7 +69,6 @@ macro(add_protocol protocol_file)
endmacro()

set(WAYLAND_PROTOCOL_SOURCES)
set(LIST_WAYLAND_PROTOCOLS)

file(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/protocols)
include_directories(${CMAKE_CURRENT_BINARY_DIR}/protocols)
Expand Down Expand Up @@ -115,27 +119,11 @@ if (EXT_PROTOCOL)
endforeach ()
endif ()

message(STATUS "WAYLAND_PROTOCOL_SOURCES: ${WAYLAND_PROTOCOL_SOURCES}")
configure_file(cmake/wayland-protocols.h.in ${CMAKE_CURRENT_BINARY_DIR}/protocols/wayland-protocols.h)

add_library(wayland-gen STATIC ${WAYLAND_PROTOCOL_SOURCES})
target_link_libraries(wayland-gen PUBLIC PkgConfig::WAYLAND)

if (ENABLE_XDG_CLIENT)
target_compile_definitions(wayland-gen PUBLIC ENABLE_XDG_CLIENT)
endif ()
if (ENABLE_AGL_SHELL_CLIENT)
target_compile_definitions(wayland-gen PUBLIC ENABLE_AGL_SHELL_CLIENT)
endif ()
if (ENABLE_IVI_SHELL_CLIENT)
target_compile_definitions(wayland-gen PUBLIC ENABLE_IVI_SHELL_CLIENT)
endif ()
if (ENABLE_DRM_LEASE_CLIENT)
target_compile_definitions(wayland-gen PUBLIC ENABLE_DRM_LEASE_CLIENT)
endif ()

string(REPLACE ";" " " WAYLAND_PROTOCOL_DEFINES "${LIST_WAYLAND_PROTOCOLS}" GLOBAL)
message(STATUS "DEFINITIONS: ${WAYLAND_PROTOCOL_DEFINES}")
target_compile_definitions(wayland-gen PUBLIC ${WAYLAND_PROTOCOL_DEFINES})

if (IPO_SUPPORT_RESULT)
set_property(TARGET wayland-gen PROPERTY INTERPROCEDURAL_OPTIMIZATION TRUE)
endif ()
Expand Down
25 changes: 12 additions & 13 deletions examples/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,10 @@ if (ENABLE_XDG_CLIENT)

add_sanitizers(simple-shm)

#
# presentation-shm
#
if (FALSE)
#
# presentation-shm
#
add_executable(presentation-shm presentation-shm.cc)
target_include_directories(presentation-shm PRIVATE ${CMAKE_SOURCE_DIR}/include ${CMAKE_SOURCE_DIR}/src)

Expand Down Expand Up @@ -81,20 +81,19 @@ if (ENABLE_XDG_CLIENT)
add_sanitizers(simple-ext-protocol)
endif ()

endif ()

if (ENABLE_AGL_SHELL_CLIENT)
#
# agl-simple-shm
#
add_executable(agl-simple-shm agl-simple-shm.cc)
target_include_directories(agl-simple-shm PRIVATE ${CMAKE_SOURCE_DIR}/include ${CMAKE_SOURCE_DIR}/src)
if (ENABLE_AGL_SHELL_CLIENT)
add_executable(agl-simple-shm agl-simple-shm.cc)
target_include_directories(agl-simple-shm PRIVATE ${CMAKE_SOURCE_DIR}/include ${CMAKE_SOURCE_DIR}/src)

target_link_libraries(agl-simple-shm PRIVATE waypp wayland-gen cxxopts::cxxopts)
target_link_libraries(agl-simple-shm PRIVATE waypp wayland-gen cxxopts::cxxopts)

if (IPO_SUPPORT_RESULT)
set_property(TARGET agl-simple-shm PROPERTY INTERPROCEDURAL_OPTIMIZATION TRUE)
endif ()
if (IPO_SUPPORT_RESULT)
set_property(TARGET agl-simple-shm PROPERTY INTERPROCEDURAL_OPTIMIZATION TRUE)
endif ()

add_sanitizers(agl-simple-shm)
add_sanitizers(agl-simple-shm)
endif ()
endif ()
2 changes: 0 additions & 2 deletions examples/agl-simple-shm.cc
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,6 @@ static void paint_pixels(void *image, int padding, int width, int height, uint32
void draw_frame(void *data, const uint32_t time) {
auto window = static_cast<Window *>(data);

window->prune_old_released_buffers();

auto buffer = window->next_buffer();
if (!buffer) {
spdlog::error("Failed to acquire a buffer");
Expand Down
8 changes: 5 additions & 3 deletions examples/simple-egl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -152,10 +152,12 @@ void initialize_scene(Window *window) {
GLint status;
glGetProgramiv(program, GL_LINK_STATUS, &status);
if (!status) {
char log[1000];
GLsizei len;
glGetProgramInfoLog(program, 1000, &len, log);
fprintf(stderr, "Error: linking:\n%.*s\n", len, log);
auto buf = std::make_unique<char[]>(1024);
glGetProgramInfoLog(program, 1024, &len, buf.get());
std::string res{buf.get(), static_cast<size_t>(len)};
buf.reset();
spdlog::error("Error: linking:\n{}", res.c_str());
exit(1);
}

Expand Down
41 changes: 10 additions & 31 deletions examples/simple-ext-protocol.cc
Original file line number Diff line number Diff line change
Expand Up @@ -64,29 +64,29 @@ void handle_signal(int signal) {

static void
paint_pixels(void *image, int padding, int width, int height, uint32_t time) {
const int halfh = padding + (height - padding * 2) / 2;
const int halfw = padding + (width - padding * 2) / 2;
const int half_height = padding + (height - padding * 2) / 2;
const int half_width = padding + (width - padding * 2) / 2;
int ir, or_;
auto *pixel = static_cast<uint32_t *>(image);
int y;

/* squared radii thresholds */
or_ = (halfw < halfh ? halfw : halfh) - 8;
or_ = (half_width < half_height ? half_width : half_height) - 8;
ir = or_ - 32;
or_ *= or_;
ir *= ir;

pixel += padding * width;
for (y = padding; y < height - padding; y++) {
int x;
int y2 = (y - halfh) * (y - halfh);
int y2 = (y - half_height) * (y - half_height);

pixel += padding;
for (x = padding; x < width - padding; x++) {
uint32_t v;

/* squared distance from center */
int r2 = (x - halfw) * (x - halfw) + y2;
int r2 = (x - half_width) * (x - half_width) + y2;

if (r2 < ir)
v = (static_cast<uint32_t>(r2 / 32) + time / 64) * 0x0080401;
Expand All @@ -110,8 +110,6 @@ paint_pixels(void *image, int padding, int width, int height, uint32_t time) {
void draw_frame(void *data, const uint32_t time) {
auto window = static_cast<Window *>(data);

window->prune_old_released_buffers();

auto buffer = window->next_buffer();
if (!buffer) {
spdlog::error("Failed to acquire a buffer");
Expand All @@ -126,45 +124,26 @@ void draw_frame(void *data, const uint32_t time) {
buffer->set_busy();
}

static void handle_interface1_add(void * /* data */,
static void handle_interface1_add(Registrar * /* data */,
struct wl_registry * /* registry */,
uint32_t name,
const char *interface,
uint32_t version) {
spdlog::info("handle_interface1_add: name: {}, interface: {}, version: {}", name, interface, version);
}

static void handle_interface1_remove(void * /* data */,
static void handle_interface1_remove(Registrar * /* data */,
struct wl_registry * /* registry */,
uint32_t id) {
spdlog::info("handle_interface1_remove: id: {}", id);
}

static void handle_interface2_add(void * /* data */,
struct wl_registry * /* registry */,
uint32_t name,
const char *interface,
uint32_t version) {
spdlog::info("handle_interface2_add: name: {}, interface: {}, version: {}", name, interface, version);
}

static void handle_interface2_remove(void * /* data */,
struct wl_registry * /* registry */,
uint32_t id) {
spdlog::info("handle_interface2_remove: id: {}", id);
}

static constexpr
std::array<Registrar::RegistrarCallback, 2> ext_interfaces{{
std::array<Registrar::RegistrarCallback, 1> ext_interfaces{{
{
"zxdg_output_manager_v1",
"wl_drm",
handle_interface1_add,
handle_interface1_remove,
},
{
"wl_drm",
handle_interface2_add,
handle_interface2_remove,
}
}};

Expand Down Expand Up @@ -193,7 +172,7 @@ int main(int argc, char **argv) {
.tearing = result["tearing"].as<bool>(),
};

XdgWindowManager wm = XdgWindowManager(ext_interfaces.size(),
XdgWindowManager wm = XdgWindowManager(false, ext_interfaces.size(),
ext_interfaces.data()
);
spdlog::info("XDG Window Manager Version: {}", wm.get_version());
Expand Down
2 changes: 0 additions & 2 deletions examples/simple-shm.cc
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,6 @@ static void paint_pixels(void *image, int padding, int width, int height, uint32
void draw_frame(void *data, const uint32_t time) {
auto window = static_cast<Window *>(data);

window->prune_old_released_buffers();

auto buffer = window->next_buffer();
if (!buffer) {
spdlog::error("Failed to acquire a buffer");
Expand Down
27 changes: 4 additions & 23 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,20 +18,6 @@ find_package(PkgConfig REQUIRED)
pkg_check_modules(GLIB REQUIRED IMPORTED_TARGET glib-2.0)
find_package(OpenGL REQUIRED COMPONENTS EGL)

include(CheckFunctionExists)
check_function_exists(memfd_create HAVE_MEMFD_CREATE)
check_function_exists(posix_fallocate HAVE_POSIX_FALLOCATE)
check_function_exists(mkostemp HAVE_MKOSTEMP)
if (HAVE_MEMFD_CREATE)
add_compile_definitions(HAVE_MEMFD_CREATE)
endif ()
if (HAVE_POSIX_FALLOCATE)
add_compile_definitions(HAVE_POSIX_FALLOCATE)
endif ()
if (HAVE_MKOSTEMP)
add_compile_definitions(HAVE_MKOSTEMP)
endif ()

set(WINDOW_MANAGER_SRC
window_manager/output.cc
window_manager/registrar.cc
Expand All @@ -40,9 +26,7 @@ set(WINDOW_MANAGER_SRC
)

if (ENABLE_AGL_SHELL_CLIENT)
list(APPEND WINDOW_MANAGER_SRC
window_manager/agl_shell.cc
)
list(APPEND WINDOW_MANAGER_SRC window_manager/agl_shell.cc)
endif ()

set(SEAT_SRC
Expand Down Expand Up @@ -74,16 +58,13 @@ if (ENABLE_XDG_CLIENT)
window_manager/xdg_window_manager.cc)
endif ()
if (ENABLE_AGL_CLIENT)
target_sources(waypp PRIVATE
window_manager/agl_shell.cc)
target_sources(waypp PRIVATE window_manager/agl_shell.cc)
endif ()
if (ENABLE_IVI_SHELL_CLIENT)
target_sources(waypp PRIVATE
window_manager/ivi_window_manager.cc)
target_sources(waypp PRIVATE window_manager/ivi_window_manager.cc)
endif ()
if (ENABLE_DRM_LEASE_CLIENT)
target_sources(waypp PRIVATE
window_manager/drm_lease_device_v1.cc)
target_sources(waypp PRIVATE window_manager/drm_lease_device_v1.cc)
endif ()

target_include_directories(waypp PUBLIC .)
Expand Down
5 changes: 3 additions & 2 deletions src/command.cc
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,11 @@ bool Command::Execute(const char *cmd, std::string &result) {

SPDLOG_TRACE("[Command] Execute: {}", cmd);

auto buf = std::make_unique<char[]>(PATH_MAX);
while (fgets(&buf[0], PATH_MAX, fp) != nullptr) {
auto buf = std::make_unique<char[]>(1024);
while (fgets(&buf[0], 1024, fp) != nullptr) {
result.append(&buf[0]);
}
buf.reset();

SPDLOG_TRACE("[Command] Execute Result: [{}] {}", result.size(), result);

Expand Down
Loading

0 comments on commit 26d6e71

Please sign in to comment.