From 254af6e70f7118cc008d5138f2cfc30f6e716132 Mon Sep 17 00:00:00 2001
From: Alexander Smorkalov <alexander.smorkalov@xperience.ai>
Date: Tue, 24 Jan 2023 18:32:18 +0300
Subject: [PATCH 1/3] Added Wayland plugin to Qt backend.

---
 .github/workflows/build_wheels_linux.yml     |  4 ++--
 .github/workflows/build_wheels_linux_arm.yml |  2 +-
 docker/manylinux2014/Dockerfile_aarch64      | 16 ++++++++--------
 docker/manylinux2014/Dockerfile_x86_64       | 16 ++++++++--------
 patches/patchQtPlugins                       |  2 +-
 setup.py                                     | 13 ++++++++++++-
 travis_config.sh                             |  1 -
 7 files changed, 32 insertions(+), 22 deletions(-)

diff --git a/.github/workflows/build_wheels_linux.yml b/.github/workflows/build_wheels_linux.yml
index 45a38d06..d57f7fd2 100644
--- a/.github/workflows/build_wheels_linux.yml
+++ b/.github/workflows/build_wheels_linux.yml
@@ -41,7 +41,7 @@ jobs:
       MB_ML_VER: 2014
       TRAVIS_BUILD_DIR: ${{ github.workspace }}
       CONFIG_PATH: travis_config.sh
-      DOCKER_IMAGE: quay.io/opencv-ci/opencv-python-manylinux2014-x86-64:20231225
+      DOCKER_IMAGE: quay.io/opencv-ci/opencv-python-manylinux2014-x86-64:20240513
       USE_CCACHE: 0
       UNICODE_WIDTH: 32
       PLAT: x86_64
@@ -139,7 +139,7 @@ jobs:
       NP_TEST_DEP: numpy==1.19.4
       TRAVIS_BUILD_DIR: ${{ github.workspace }}
       CONFIG_PATH: travis_config.sh
-      DOCKER_IMAGE: quay.io/opencv-ci/opencv-python-manylinux2014-x86-64:20231225
+      DOCKER_IMAGE: quay.io/opencv-ci/opencv-python-manylinux2014-x86-64:20240513
       USE_CCACHE: 1
       UNICODE_WIDTH: 32
       SDIST: ${{ matrix.build_sdist || 0 }}
diff --git a/.github/workflows/build_wheels_linux_arm.yml b/.github/workflows/build_wheels_linux_arm.yml
index 6371e360..60a8473c 100644
--- a/.github/workflows/build_wheels_linux_arm.yml
+++ b/.github/workflows/build_wheels_linux_arm.yml
@@ -42,7 +42,7 @@ jobs:
       MB_ML_VER: 2014
       TRAVIS_BUILD_DIR: ${{ github.workspace }}
       CONFIG_PATH: travis_config.sh
-      DOCKER_IMAGE: quay.io/opencv-ci/opencv-python-manylinux2014-aarch64:20231225
+      DOCKER_IMAGE: quay.io/opencv-ci/opencv-python-manylinux2014-aarch64:20240513
       USE_CCACHE: 0
       UNICODE_WIDTH: 32
       SDIST: ${{ matrix.build_sdist || 0 }}
diff --git a/docker/manylinux2014/Dockerfile_aarch64 b/docker/manylinux2014/Dockerfile_aarch64
index 196c97bb..7aa615e6 100644
--- a/docker/manylinux2014/Dockerfile_aarch64
+++ b/docker/manylinux2014/Dockerfile_aarch64
@@ -1,4 +1,4 @@
-# Version: 20231225
+# Version: 20240513
 # Image name: quay.io/opencv-ci/opencv-python-manylinux2014-aarch64
 
 FROM quay.io/pypa/manylinux2014_aarch64:latest
@@ -10,13 +10,13 @@ ARG LIBPNG_VERSION=1.6.40
 ARG VPX_VERSION=v1.13.1
 ARG NASM_VERSION=2.15.04
 ARG OPENSSL_VERSION=1_1_1w
-ARG QT_VERSION=5.15.0
+ARG QT_VERSION=5.15.13
 ARG YASM_VERSION=1.3.0
 
 ENV LD_LIBRARY_PATH /usr/local/lib:$LD_LIBRARY_PATH
 
 # epel-release need for aarch64 to get openblas packages
-RUN yum install zlib-devel curl-devel xcb-util-renderutil-devel xcb-util-devel xcb-util-image-devel xcb-util-keysyms-devel xcb-util-wm-devel mesa-libGL-devel libxkbcommon-devel libxkbcommon-x11-devel libXi-devel lapack-devel epel-release -y && \
+RUN yum install zlib-devel curl-devel xcb-util-renderutil-devel xcb-util-devel xcb-util-image-devel xcb-util-keysyms-devel xcb-util-wm-devel mesa-libGL-devel libxkbcommon-devel libxkbcommon-x11-devel libXi-devel lapack-devel epel-release wayland-devel libwayland-egl -y && \
     yum install openblas-devel dejavu-sans-fonts -y && \
     cp /usr/include/lapacke/lapacke*.h /usr/include/ && \
     curl https://raw.githubusercontent.com/xianyi/OpenBLAS/v0.3.3/cblas.h -o /usr/include/cblas.h && \
@@ -46,13 +46,12 @@ RUN mkdir ~/freetype_sources && \
     cd .. && \
     rm -rf ~/freetype_sources
 
-RUN curl -C - -O -L https://download.qt.io/official_releases/qt/5.15/${QT_VERSION}/single/qt-everywhere-src-${QT_VERSION}.tar.xz && \
-    tar -xf qt-everywhere-src-${QT_VERSION}.tar.xz && \
+RUN curl -O -L https://download.qt.io/archive/qt/5.15/${QT_VERSION}/single/qt-everywhere-opensource-src-${QT_VERSION}.tar.xz && \
+    tar -xf qt-everywhere-opensource-src-${QT_VERSION}.tar.xz && \
     cd qt-everywhere-src-${QT_VERSION} && \
     export MAKEFLAGS=-j$(nproc) && \
-    ./configure -prefix /opt/Qt${QT_VERSION} -release -opensource -confirm-license -qtnamespace QtOpenCVPython -xcb -xcb-xlib -bundled-xcb-xinput -no-openssl -no-dbus -skip qt3d -skip qtactiveqt -skip qtcanvas3d -skip qtconnectivity -skip qtdatavis3d -skip qtdoc -skip qtgamepad -skip qtgraphicaleffects -skip qtimageformats -skip qtlocation -skip qtmultimedia -skip qtpurchasing -skip qtqa -skip qtremoteobjects -skip qtrepotools -skip qtscript -skip qtscxml -skip qtsensors -skip qtserialbus -skip qtserialport -skip qtspeech -skip qttranslations -skip qtwayland -skip qtwebchannel -skip qtwebengine -skip qtwebsockets -skip qtwebview -skip xmlpatterns -skip declarative -make libs && \
-    make && \
-    make install && \
+    ./configure -prefix /opt/Qt${QT_VERSION} -release -opensource -confirm-license -qtnamespace QtOpenCVPython -xcb -xcb-xlib -bundled-xcb-xinput -no-openssl -no-dbus  -skip qt3d -skip qtactiveqt -skip qtcanvas3d -skip qtconnectivity -skip qtdatavis3d -skip qtdoc -skip qtgamepad -skip qtgraphicaleffects -skip qtimageformats -skip qtlocation -skip qtmultimedia -skip qtpurchasing -skip qtqa -skip qtremoteobjects -skip qtrepotools -skip qtscript -skip qtscxml -skip qtsensors -skip qtserialbus -skip qtserialport -skip qtspeech -skip qttranslations -skip qtwebchannel -skip qtwebengine -skip qtwebsockets -skip qtwebview -skip xmlpatterns -skip declarative -make libs && \
+    make && make install && \
     cd .. && \
     rm -rf qt-everywhere*
 
@@ -141,3 +140,4 @@ RUN git config --global --add safe.directory /io
 ENV PKG_CONFIG_PATH /usr/local/lib/pkgconfig:/ffmpeg_build/lib/pkgconfig
 ENV LDFLAGS -L/ffmpeg_build/lib
 ENV PATH "$HOME/bin:$PATH"
+ENV LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/opt/Qt${QT_VERSION}/lib
diff --git a/docker/manylinux2014/Dockerfile_x86_64 b/docker/manylinux2014/Dockerfile_x86_64
index ac28b689..160898ea 100644
--- a/docker/manylinux2014/Dockerfile_x86_64
+++ b/docker/manylinux2014/Dockerfile_x86_64
@@ -1,4 +1,4 @@
-# Version: 20231225
+# Version: 20240513
 # Image name: quay.io/opencv-ci/opencv-python-manylinux2014-x86-64
 
 FROM quay.io/pypa/manylinux2014_x86_64:latest
@@ -10,13 +10,13 @@ ARG LIBPNG_VERSION=1.6.40
 ARG VPX_VERSION=v1.13.1
 ARG NASM_VERSION=2.15.04
 ARG OPENSSL_VERSION=1_1_1w
-ARG QT_VERSION=5.15.0
+ARG QT_VERSION=5.15.13
 ARG YASM_VERSION=1.3.0
 
 ENV LD_LIBRARY_PATH /usr/local/lib:$LD_LIBRARY_PATH
 
 # epel-release need for aarch64 to get openblas packages
-RUN yum install zlib-devel curl-devel xcb-util-renderutil-devel xcb-util-devel xcb-util-image-devel xcb-util-keysyms-devel xcb-util-wm-devel mesa-libGL-devel libxkbcommon-devel libxkbcommon-x11-devel libXi-devel lapack-devel epel-release -y && \
+RUN yum install zlib-devel curl-devel xcb-util-renderutil-devel xcb-util-devel xcb-util-image-devel xcb-util-keysyms-devel xcb-util-wm-devel mesa-libGL-devel libxkbcommon-devel libxkbcommon-x11-devel libXi-devel lapack-devel epel-release wayland-devel libwayland-egl -y && \
     yum install openblas-devel dejavu-sans-fonts -y && \
     cp /usr/include/lapacke/lapacke*.h /usr/include/ && \
     curl https://raw.githubusercontent.com/xianyi/OpenBLAS/v0.3.3/cblas.h -o /usr/include/cblas.h && \
@@ -45,13 +45,12 @@ RUN mkdir ~/freetype_sources && \
     cd .. && \
     rm -rf ~/freetype_sources
 
-RUN curl -O -L https://download.qt.io/official_releases/qt/5.15/${QT_VERSION}/single/qt-everywhere-src-${QT_VERSION}.tar.xz && \
-    tar -xf qt-everywhere-src-${QT_VERSION}.tar.xz && \
+RUN curl -O -L https://download.qt.io/archive/qt/5.15/${QT_VERSION}/single/qt-everywhere-opensource-src-${QT_VERSION}.tar.xz && \
+    tar -xf qt-everywhere-opensource-src-${QT_VERSION}.tar.xz && \
     cd qt-everywhere-src-${QT_VERSION} && \
     export MAKEFLAGS=-j$(nproc) && \
-    ./configure -prefix /opt/Qt${QT_VERSION} -release -opensource -confirm-license -qtnamespace QtOpenCVPython -xcb -xcb-xlib -bundled-xcb-xinput -no-openssl -no-dbus -skip qt3d -skip qtactiveqt -skip qtcanvas3d -skip qtconnectivity -skip qtdatavis3d -skip qtdoc -skip qtgamepad -skip qtgraphicaleffects -skip qtimageformats -skip qtlocation -skip qtmultimedia -skip qtpurchasing -skip qtqa -skip qtremoteobjects -skip qtrepotools -skip qtscript -skip qtscxml -skip qtsensors -skip qtserialbus -skip qtserialport -skip qtspeech -skip qttranslations -skip qtwayland -skip qtwebchannel -skip qtwebengine -skip qtwebsockets -skip qtwebview -skip xmlpatterns -skip declarative -make libs && \
-    make && \
-    make install && \
+    ./configure -prefix /opt/Qt${QT_VERSION} -release -opensource -confirm-license -qtnamespace QtOpenCVPython -xcb -xcb-xlib -bundled-xcb-xinput -no-openssl -no-dbus -skip qt3d -skip qtactiveqt -skip qtcanvas3d -skip qtconnectivity -skip qtdatavis3d -skip qtdoc -skip qtgamepad -skip qtgraphicaleffects -skip qtimageformats -skip qtlocation -skip qtmultimedia -skip qtpurchasing -skip qtqa -skip qtremoteobjects -skip qtrepotools -skip qtscript -skip qtscxml -skip qtsensors -skip qtserialbus -skip qtserialport -skip qtspeech -skip qttranslations -skip qtwebchannel -skip qtwebengine -skip qtwebsockets -skip qtwebview -skip xmlpatterns -skip declarative -make libs && \
+    make && make install && \
     cd .. && \
     rm -rf qt-everywhere*
 
@@ -140,3 +139,4 @@ RUN git config --global --add safe.directory /io
 ENV PKG_CONFIG_PATH /usr/local/lib/pkgconfig:/ffmpeg_build/lib/pkgconfig
 ENV LDFLAGS -L/ffmpeg_build/lib
 ENV PATH "$HOME/bin:$PATH"
+ENV LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/opt/Qt${QT_VERSION}/lib
diff --git a/patches/patchQtPlugins b/patches/patchQtPlugins
index a05a5f83..70c6975a 100644
--- a/patches/patchQtPlugins
+++ b/patches/patchQtPlugins
@@ -9,7 +9,7 @@ index 4c0b3880fc..dffa0a4caa 100644
 +      install(DIRECTORY ${Qt5_DIR}/../../../plugins DESTINATION lib/qt)
 +    endif()
 +    if(UNIX AND NOT APPLE)
-+      install(DIRECTORY /opt/Qt5.15.0/plugins DESTINATION lib/qt)
++      install(DIRECTORY /opt/Qt5.15.13/plugins DESTINATION lib/qt)
 +      install(DIRECTORY /usr/share/fonts DESTINATION lib/qt)
 +    endif()
      if(HAVE_QT_OPENGL)
diff --git a/setup.py b/setup.py
index 766b4bb4..90f0ad58 100644
--- a/setup.py
+++ b/setup.py
@@ -236,7 +236,18 @@ def main():
 
             if sys.platform.startswith("linux"):
                 rearrange_cmake_output_data["cv2.qt.plugins.platforms"] = [
-                    (r"lib/qt/plugins/platforms/libqxcb\.so")
+                    (r"lib/qt/plugins/platforms/libqxcb\.so"),
+
+                    # wayland plugin parts
+                    (r"lib/qt/plugins/platforms/libqwayland-generic\.so"),
+                    (r"lib/qt/plugins/wayland-decoration-client/libbradient\.so"),
+                    (r"lib/qt/plugins/wayland-graphics-integration-client/libshm-emulation-server\.so"),
+                    (r"lib/qt/plugins/wayland-shell-integration/libfullscreen-shell-v1\.so"),
+                    (r"lib/qt/plugins/wayland-shell-integration/libivi-shell\.so"),
+                    (r"lib/qt/plugins/wayland-shell-integration/libwl-shell\.so"),
+                    (r"lib/qt/plugins/wayland-shell-integration/libxdg-shell\.so"),
+                    (r"lib/qt/plugins/wayland-shell-integration/libxdg-shell-v5\.so"),
+                    (r"lib/qt/plugins/wayland-shell-integration/libxdg-shell-v6\.so")
                 ]
 
                 # add fonts for Qt5
diff --git a/travis_config.sh b/travis_config.sh
index b91d63c4..54049fcb 100644
--- a/travis_config.sh
+++ b/travis_config.sh
@@ -34,7 +34,6 @@ if [ -n "$IS_OSX" ]; then
   export MAKEFLAGS="-j$(sysctl -n hw.ncpu)"
 else
   echo "    > Linux environment "
-  export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/opt/Qt5.15.0/lib
   export MAKEFLAGS="-j$(grep -E '^processor[[:space:]]*:' /proc/cpuinfo | wc -l)"
   CURRENT_ARCH=$(uname -m)
   if [[ $CURRENT_ARCH == 'aarch64' ]]; then

From 84ddef5c954325dafdd1a3da05e2bbf3c1df4c44 Mon Sep 17 00:00:00 2001
From: Alexander Smorkalov <alexander.smorkalov@xperience.ai>
Date: Mon, 13 May 2024 21:20:48 +0300
Subject: [PATCH 2/3] Added EGL packages.

---
 docker/manylinux2014/Dockerfile_x86_64 | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/docker/manylinux2014/Dockerfile_x86_64 b/docker/manylinux2014/Dockerfile_x86_64
index 160898ea..9e1da332 100644
--- a/docker/manylinux2014/Dockerfile_x86_64
+++ b/docker/manylinux2014/Dockerfile_x86_64
@@ -16,7 +16,7 @@ ARG YASM_VERSION=1.3.0
 ENV LD_LIBRARY_PATH /usr/local/lib:$LD_LIBRARY_PATH
 
 # epel-release need for aarch64 to get openblas packages
-RUN yum install zlib-devel curl-devel xcb-util-renderutil-devel xcb-util-devel xcb-util-image-devel xcb-util-keysyms-devel xcb-util-wm-devel mesa-libGL-devel libxkbcommon-devel libxkbcommon-x11-devel libXi-devel lapack-devel epel-release wayland-devel libwayland-egl -y && \
+RUN yum install zlib-devel curl-devel xcb-util-renderutil-devel xcb-util-devel xcb-util-image-devel xcb-util-keysyms-devel xcb-util-wm-devel mesa-libGL-devel libxkbcommon-devel libxkbcommon-x11-devel libXi-devel lapack-devel epel-release mesa-libEGL-devel wayland-devel libwayland-egl -y && \
     yum install openblas-devel dejavu-sans-fonts -y && \
     cp /usr/include/lapacke/lapacke*.h /usr/include/ && \
     curl https://raw.githubusercontent.com/xianyi/OpenBLAS/v0.3.3/cblas.h -o /usr/include/cblas.h && \
@@ -49,7 +49,7 @@ RUN curl -O -L https://download.qt.io/archive/qt/5.15/${QT_VERSION}/single/qt-ev
     tar -xf qt-everywhere-opensource-src-${QT_VERSION}.tar.xz && \
     cd qt-everywhere-src-${QT_VERSION} && \
     export MAKEFLAGS=-j$(nproc) && \
-    ./configure -prefix /opt/Qt${QT_VERSION} -release -opensource -confirm-license -qtnamespace QtOpenCVPython -xcb -xcb-xlib -bundled-xcb-xinput -no-openssl -no-dbus -skip qt3d -skip qtactiveqt -skip qtcanvas3d -skip qtconnectivity -skip qtdatavis3d -skip qtdoc -skip qtgamepad -skip qtgraphicaleffects -skip qtimageformats -skip qtlocation -skip qtmultimedia -skip qtpurchasing -skip qtqa -skip qtremoteobjects -skip qtrepotools -skip qtscript -skip qtscxml -skip qtsensors -skip qtserialbus -skip qtserialport -skip qtspeech -skip qttranslations -skip qtwebchannel -skip qtwebengine -skip qtwebsockets -skip qtwebview -skip xmlpatterns -skip declarative -make libs && \
+    ./configure -prefix /opt/Qt${QT_VERSION} -release -opensource -confirm-license -qtnamespace QtOpenCVPython -egl -xcb -xcb-xlib -bundled-xcb-xinput -no-openssl -no-dbus -skip qt3d -skip qtactiveqt -skip qtcanvas3d -skip qtconnectivity -skip qtdatavis3d -skip qtdoc -skip qtgamepad -skip qtgraphicaleffects -skip qtimageformats -skip qtlocation -skip qtmultimedia -skip qtpurchasing -skip qtqa -skip qtremoteobjects -skip qtrepotools -skip qtscript -skip qtscxml -skip qtsensors -skip qtserialbus -skip qtserialport -skip qtspeech -skip qttranslations -skip qtwebchannel -skip qtwebengine -skip qtwebsockets -skip qtwebview -skip xmlpatterns -skip declarative -make libs && \
     make && make install && \
     cd .. && \
     rm -rf qt-everywhere*

From f2b8a7586a572538c8e90961b9ff536d664701c1 Mon Sep 17 00:00:00 2001
From: Alexander Smorkalov <alexander.smorkalov@xperience.ai>
Date: Tue, 14 May 2024 12:04:53 +0300
Subject: [PATCH 3/3] More QT plugins.

---
 setup.py | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/setup.py b/setup.py
index 90f0ad58..b07d2efa 100644
--- a/setup.py
+++ b/setup.py
@@ -247,7 +247,11 @@ def main():
                     (r"lib/qt/plugins/wayland-shell-integration/libwl-shell\.so"),
                     (r"lib/qt/plugins/wayland-shell-integration/libxdg-shell\.so"),
                     (r"lib/qt/plugins/wayland-shell-integration/libxdg-shell-v5\.so"),
-                    (r"lib/qt/plugins/wayland-shell-integration/libxdg-shell-v6\.so")
+                    (r"lib/qt/plugins/wayland-shell-integration/libxdg-shell-v6\.so"),
+                    (r"lib/qt/plugins/wayland-graphics-integration-client/libdrm-egl-server.so"),
+                    (r"lib/qt/plugins/wayland-graphics-integration-client/libdmabuf-server.so"),
+                    (r"lib/qt/plugins/wayland-graphics-integration-client/libqt-plugin-wayland-egl.so"),
+                    (r"lib/qt/plugins/wayland-graphics-integration-client/libshm-emulation-server.so")
                 ]
 
                 # add fonts for Qt5