highgui Wayland xdg_shell

-enable using -DWITH_WAYLAND=ON
-adapted from https://github.com/pfpacket/opencv-wayland
-using xdg_shell stable protocol
-overrides HAVE_QT if HAVE_WAYLAND and WITH_WAYLAND are set

Signed-off-by: Joel Winarske <joel.winarske@gmail.com>

Co-authored-by: Ryo Munakata <afpacket@gmail.com>
This commit is contained in:
Joel Winarske 2022-06-14 15:16:51 -07:00 committed by Joel Winarske
parent b19683eb41
commit 0769bf416f
9 changed files with 2566 additions and 1 deletions

View File

@ -281,6 +281,9 @@ OCV_OPTION(WITH_GTK "Include GTK support" ON
OCV_OPTION(WITH_GTK_2_X "Use GTK version 2" OFF
VISIBLE_IF UNIX AND NOT APPLE AND NOT ANDROID
VERIFY HAVE_GTK AND NOT HAVE_GTK3)
OCV_OPTION(WITH_WAYLAND "Include Wayland support" OFF
VISIBLE_IF UNIX AND NOT APPLE AND NOT ANDROID
VERIFY HAVE_WAYLAND)
OCV_OPTION(WITH_IPP "Include Intel IPP support" (NOT MINGW AND NOT CV_DISABLE_OPTIMIZATION)
VISIBLE_IF (X86_64 OR X86) AND NOT WINRT AND NOT IOS
VERIFY HAVE_IPP)
@ -1260,6 +1263,24 @@ endif(WIN32)
status("")
status(" GUI: " "${OPENCV_HIGHGUI_BUILTIN_BACKEND}")
if(WITH_WAYLAND OR HAVE_WAYLAND)
if(HAVE_WAYLAND_CLIENT)
status(" Wayland Client:" "YES (ver ${WAYLAND_CLIENT_VERSION})")
endif()
if(HAVE_WAYLAND_CURSOR)
status(" Wayland Cursor:" "YES (ver ${WAYLAND_CURSOR_VERSION})")
endif()
if(HAVE_WAYLAND_PROTOCOL)
status(" Wayland Protocol:" "YES (ver ${WAYLAND_PROTOCOL_VERSION})")
endif()
if(HAVE_WAYLAND_EGL)
status(" Wayland EGL:" "YES (ver ${WAYLAND_EGL_VERSION})")
endif()
if(HAVE_XKBCOMMON)
status(" Xkbcommon:" "YES (ver ${XKBCOMMON_VERSION})")
endif()
endif()
if(WITH_QT OR HAVE_QT)
if(HAVE_QT)
status(" QT:" "YES (ver ${QT_VERSION_MAJOR}.${QT_VERSION_MINOR}.${QT_VERSION_PATCH} ${QT_EDITION})")

View File

@ -146,6 +146,7 @@ ocv_create_module(${extra_libs})
ocv_target_link_libraries(${the_module} PRIVATE
"${ZLIB_LIBRARIES}" "${OPENCL_LIBRARIES}" "${VA_LIBRARIES}"
"${OPENGL_LIBRARIES}"
"${GLX_LIBRARIES}"
"${LAPACK_LIBRARIES}" "${CPUFEATURES_LIBRARIES}" "${HALIDE_LIBRARIES}"
"${ITT_LIBRARIES}"
"${OPENCV_HAL_LINKER_LIBS}"

View File

@ -49,7 +49,31 @@ list(REMOVE_ITEM highgui_ext_hdrs "${CMAKE_CURRENT_LIST_DIR}/include/opencv2/${n
set(OPENCV_HIGHGUI_BUILTIN_BACKEND "")
if(HAVE_QT)
if(WITH_WAYLAND AND HAVE_WAYLAND)
set(OPENCV_HIGHGUI_BUILTIN_BACKEND "Wayland")
add_definitions(-DHAVE_WAYLAND)
set(CMAKE_INCLUDE_CURRENT_DIR ON)
if (HAVE_WAYLAND_PROTOCOLS)
ocv_wayland_generate(
${WAYLAND_PROTOCOLS_BASE}/stable/xdg-shell/xdg-shell.xml
xdg-shell-client-protocol)
endif()
list(APPEND highgui_srcs
${CMAKE_CURRENT_LIST_DIR}/src/window_wayland.cpp
${WAYLAND_PROTOCOL_SOURCES}
)
list(APPEND HIGHGUI_LIBRARIES "${WAYLAND_CLIENT_LINK_LIBRARIES};${WAYLAND_CURSOR_LINK_LIBRARIES};${XKBCOMMON_LINK_LIBRARIES}")
if(HAVE_WAYLAND_EGL)
if(WAYLAND_EGL_LIBRARIES)
list(APPEND HIGHGUI_LIBRARIES "${WAYLAND_EGL_LIBRARIES}")
endif()
endif()
elseif(HAVE_QT)
set(OPENCV_HIGHGUI_BUILTIN_BACKEND "QT${QT_VERSION_MAJOR}")
add_definitions(-DHAVE_QT)

View File

@ -0,0 +1,35 @@
# --- Wayland ---
macro(ocv_wayland_generate protocol_file output_file)
add_custom_command(OUTPUT ${output_file}.h
COMMAND ${WAYLAND_SCANNER_EXECUTABLE} client-header < ${protocol_file} > ${output_file}.h
DEPENDS ${protocol_file})
add_custom_command(OUTPUT ${output_file}.c
COMMAND ${WAYLAND_SCANNER_EXECUTABLE} private-code < ${protocol_file} > ${output_file}.c
DEPENDS ${protocol_file})
list(APPEND WAYLAND_PROTOCOL_SOURCES ${output_file}.h ${output_file}.c)
endmacro()
ocv_clear_vars(HAVE_WAYLAND_CLIENT HAVE_WAYLAND_CURSOR HAVE_XKBCOMMON HAVE_WAYLAND_PROTOCOLS)
if(WITH_WAYLAND)
ocv_check_modules(WAYLAND_CLIENT wayland-client)
if(WAYLAND_CLIENT_FOUND)
set(HAVE_WAYLAND_CLIENT ON)
endif()
ocv_check_modules(WAYLAND_CURSOR wayland-cursor)
if(WAYLAND_CURSOR_FOUND)
set(HAVE_WAYLAND_CURSOR ON)
endif()
ocv_check_modules(XKBCOMMON xkbcommon)
if(XKBCOMMON_FOUND)
set(HAVE_XKBCOMMON ON)
endif()
ocv_check_modules(WAYLAND_PROTOCOLS wayland-protocols>=1.13)
if(HAVE_WAYLAND_PROTOCOLS)
pkg_get_variable(WAYLAND_PROTOCOLS_BASE wayland-protocols pkgdatadir)
find_host_program(WAYLAND_SCANNER_EXECUTABLE NAMES wayland-scanner REQUIRED)
endif()
if(HAVE_WAYLAND_CLIENT AND HAVE_WAYLAND_CURSOR AND HAVE_XKBCOMMON AND HAVE_WAYLAND_PROTOCOLS)
set(HAVE_WAYLAND TRUE)
endif()
endif()

View File

@ -38,6 +38,7 @@ endmacro()
add_backend("gtk" WITH_GTK)
add_backend("win32ui" WITH_WIN32UI)
add_backend("wayland" WITH_WAYLAND)
# TODO cocoa
# TODO qt
# TODO opengl

View File

@ -130,6 +130,7 @@ void setWindowTitle_W32(const cv::String& name, const cv::String& title);
void setWindowTitle_GTK(const cv::String& name, const cv::String& title);
void setWindowTitle_QT(const cv::String& name, const cv::String& title);
void setWindowTitle_COCOA(const cv::String& name, const cv::String& title);
void setWindowTitle_WAYLAND(const cv::String& name, const cv::String& title);
int pollKey_W32();

View File

@ -613,6 +613,8 @@ void cv::setWindowTitle(const String& winname, const String& title)
return setWindowTitle_QT(winname, title);
#elif defined (HAVE_COCOA)
return setWindowTitle_COCOA(winname, title);
#elif defined (HAVE_WAYLAND)
return setWindowTitle_WAYLAND(winname, title);
#else
CV_Error(Error::StsNotImplemented, "The function is not implemented. "
"Rebuild the library with Windows, GTK+ 2.x or Cocoa support. "
@ -1226,6 +1228,7 @@ int cv::createButton(const String&, ButtonCallback, void*, int , bool )
#elif defined (HAVE_GTK) // see window_gtk.cpp
#elif defined (HAVE_COCOA) // see window_cocoa.mm
#elif defined (HAVE_QT) // see window_QT.cpp
#elif defined (HAVE_WAYLAND) // see window_wayland.cpp
#elif defined (WINRT) && !defined (WINRT_8_0) // see window_winrt.cpp
#else

File diff suppressed because it is too large Load Diff

View File

@ -58,6 +58,7 @@ inline void verify_size(const std::string &nm, const cv::Mat &img)
&& !defined HAVE_QT \
&& !defined HAVE_WIN32UI \
&& !defined HAVE_COCOA \
&& !defined HAVE_WAYLAND \
)
TEST(Highgui_GUI, DISABLED_regression)
#else
@ -135,6 +136,7 @@ static void Foo(int, void* counter)
&& !defined HAVE_GTK \
&& !defined HAVE_QT \
&& !defined HAVE_WIN32UI \
&& !defined HAVE_WAYLAND \
) \
|| defined(__APPLE__) // test fails on Mac (cocoa)
TEST(Highgui_GUI, DISABLED_trackbar_unsafe)
@ -174,6 +176,7 @@ void testTrackbarCallback(int pos, void* param)
&& !defined HAVE_GTK \
&& !defined HAVE_QT \
&& !defined HAVE_WIN32UI \
&& !defined HAVE_WAYLAND \
) \
|| defined(__APPLE__) // test fails on Mac (cocoa)
TEST(Highgui_GUI, DISABLED_trackbar)