Skip to content

Commit

Permalink
Add ENABLE_EGL build flag
Browse files Browse the repository at this point in the history
-remove EGL deps with -DENABLE_EGL=OFF

Signed-off-by: Joel Winarske <joel.winarske@gmail.com>
  • Loading branch information
jwinarske committed May 14, 2024
1 parent 60ed50f commit d978933
Show file tree
Hide file tree
Showing 7 changed files with 68 additions and 21 deletions.
2 changes: 2 additions & 0 deletions cmake/options.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ option(ENABLE_AGL_CLIENT "Enable AGL Shell" OFF)
option(ENABLE_IVI_SHELL_CLIENT "Enable IVI Shell Client" OFF)
option(ENABLE_DRM_LEASE_CLIENT "Enable DRM Lease Client" OFF)

option(ENABLE_EGL "Enable EGL dependency" ON)

#
# Link Time Optimization
#
Expand Down
2 changes: 2 additions & 0 deletions cmake/wayland-protocols.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
#cmakedefine01 ENABLE_IVI_SHELL_CLIENT
#cmakedefine01 ENABLE_DRM_LEASE_CLIENT

#cmakedefine01 ENABLE_EGL

#cmakedefine01 HAS_WAYLAND_PROTOCOL_XDG_SHELL
#cmakedefine01 HAS_WAYLAND_PROTOCOL_AGL_SHELL
#cmakedefine01 HAS_WAYLAND_PROTOCOL_AGL_SHELL_DESKTOP
Expand Down
8 changes: 7 additions & 1 deletion cmake/wayland.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,10 @@ option(ENABLE_IVI_SHELL_CLIENT "Enable ivi-shell Client" OFF)
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)
pkg_check_modules(WAYLAND REQUIRED IMPORTED_TARGET wayland-client wayland-cursor xkbcommon)
if (ENABLE_EGL)
pkg_check_modules(WAYLAND_EGL REQUIRED IMPORTED_TARGET wayland-egl)
endif ()

include(CheckFunctionExists)
check_function_exists(memfd_create HAVE_MEMFD_CREATE)
Expand Down Expand Up @@ -120,6 +123,9 @@ configure_file(cmake/wayland-protocols.h.in ${CMAKE_CURRENT_BINARY_DIR}/protocol

add_library(wayland-gen STATIC ${WAYLAND_PROTOCOL_SOURCES})
target_link_libraries(wayland-gen PUBLIC PkgConfig::WAYLAND)
if (ENABLE_EGL)
target_link_libraries(wayland-gen PUBLIC PkgConfig::WAYLAND_EGL)
endif ()
target_include_directories(wayland-gen PUBLIC
${CMAKE_CURRENT_SOURCE_DIR}/include
${CMAKE_CURRENT_BINARY_DIR}/protocols
Expand Down
38 changes: 21 additions & 17 deletions examples/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,23 +15,32 @@
#


#
# simple-egl
#
find_package(PkgConfig REQUIRED)
pkg_check_modules(GLESv2 IMPORTED_TARGET glesv2)
if (ENABLE_EGL)

add_executable(simple-egl simple-egl.cc)
#
# simple-egl
#
find_package(PkgConfig REQUIRED)
pkg_check_modules(GLESv2 IMPORTED_TARGET glesv2)

target_compile_definitions(simple-egl PRIVATE EGL_NO_X11 MESA_EGL_NO_X11_HEADERS)
add_executable(simple-egl simple-egl.cc)

target_link_libraries(simple-egl PRIVATE waypp wayland-gen PkgConfig::GLESv2 cxxopts::cxxopts)
target_compile_definitions(simple-egl PRIVATE EGL_NO_X11 MESA_EGL_NO_X11_HEADERS)

if (IPO_SUPPORT_RESULT)
set_property(TARGET simple-egl PROPERTY INTERPROCEDURAL_OPTIMIZATION TRUE)
endif ()
target_link_libraries(simple-egl PRIVATE waypp wayland-gen PkgConfig::GLESv2 cxxopts::cxxopts)

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

add_sanitizers(simple-egl)
add_sanitizers(simple-egl)

#
# OpenGL
#
add_subdirectory(gl-shadertoy)

endif ()

#
# simple-shm
Expand Down Expand Up @@ -107,8 +116,3 @@ find_package(Vulkan)
if (VULKAN_FOUND)
add_subdirectory(vk-shadertoy)
endif ()

#
# GL
#
add_subdirectory(gl-shadertoy)
19 changes: 16 additions & 3 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@

find_package(PkgConfig REQUIRED)
pkg_check_modules(GLIB REQUIRED IMPORTED_TARGET glib-2.0)
find_package(OpenGL REQUIRED COMPONENTS EGL)

if (ENABLE_EGL)
find_package(OpenGL REQUIRED COMPONENTS EGL)
endif ()

set(WINDOW_MANAGER_SRC
window_manager/agl_shell.cc
Expand All @@ -37,7 +40,6 @@ set(SEAT_SRC
set(WINDOW_SRC
window/anonymous_file.cc
window/buffer.cc
window/egl.cc
window/feedback.cc
window/window.cc
)
Expand All @@ -54,6 +56,12 @@ if (BUILD_STANDALONE)
logging.cc)
endif ()

if (ENABLE_EGL)
target_sources(waypp PRIVATE
window/egl.cc
)
endif ()

if (ENABLE_XDG_CLIENT)
target_sources(waypp PRIVATE
window/xdg_toplevel.cc
Expand All @@ -74,8 +82,13 @@ target_include_directories(waypp PUBLIC .)
target_link_libraries(waypp PUBLIC
wayland-gen
PkgConfig::GLIB
OpenGL::EGL
spdlog
)

if (ENABLE_EGL)
target_link_libraries(waypp PUBLIC
OpenGL::EGL
)
endif ()

add_sanitizers(waypp)
18 changes: 18 additions & 0 deletions src/window/window.cc
Original file line number Diff line number Diff line change
Expand Up @@ -80,13 +80,15 @@ Window::Window(WindowManager *wm,
presentation_.clock_id = wm_->get_presentation_time_clk_id();
}

#if ENABLE_EGL
if (context_attribs_size && config_attribs_size) {
egl_ = std::make_unique<Egl>(wm->get_display(), wl_surface_, width, height,
context_attribs, context_attribs_size,
config_attribs, config_attribs_size,
buffer_bpp, type);
egl_->set_swap_interval(swap_interval);
}
#endif

if (wm->get_viewporter()) {
#if HAS_WAYLAND_PROTOCOL_VIEWPORTER
Expand Down Expand Up @@ -232,9 +234,11 @@ void Window::update_buffer_geometry() {
buffer_size_.height != new_buffer_size.height) {
buffer_size_.width = new_buffer_size.width;
buffer_size_.height = new_buffer_size.height;
#if ENABLE_EGL
if (egl_) {
egl_->resize(buffer_size_.width, buffer_size_.height, 0, 0);
}
#endif
}

if (fractional_buffer_scale_ > 0.0) {
Expand Down Expand Up @@ -388,48 +392,62 @@ void Window::handle_preferred_buffer_transform(void *data,
}

void Window::resize(int width, int height) {
#if ENABLE_EGL
if (egl_) {
logical_size_.width = width;
logical_size_.height = height;
egl_->resize(width, height, 0, 0);
}
#endif
}

void Window::make_current() {
#if ENABLE_EGL
if (egl_) {
egl_->make_current();
}
#endif
}

void Window::clear_current() {
#if ENABLE_EGL
if (egl_) {
egl_->clear_current();
}
#endif
}

void Window::swap_buffers() {
#if ENABLE_EGL
if (egl_) {
egl_->swap_buffers();
}
#endif
}

bool Window::have_swap_buffers_width_damage() {
#if ENABLE_EGL
if (egl_) {
return egl_->have_swap_buffers_width_damage();
}
#endif
return false;
}

void Window::get_buffer_age(EGLint &buffer_age) {
#if ENABLE_EGL
if (egl_) {
egl_->get_buffer_age(buffer_age);
}
#endif
}

void Window::swap_buffers_with_damage(const EGLint *rects, EGLint n_rects) {
#if ENABLE_EGL
if (egl_) {
egl_->swap_buffers_with_damage(rects, n_rects);
}
#endif
}

Buffer *Window::pick_free_buffer() {
Expand Down
2 changes: 2 additions & 0 deletions src/window/window.h
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,9 @@ class Window {
std::function<void(void *userdata, const uint32_t time)> frame_callback_;
void *user_data_{};

#if ENABLE_EGL
std::unique_ptr<Egl> egl_;
#endif

std::vector<std::unique_ptr<Buffer>> buffers_;

Expand Down

0 comments on commit d978933

Please sign in to comment.