diff --git a/.github/actions/qt5-build/entrypoint.sh b/.github/actions/qt5-build/entrypoint.sh index 6add42fe8..614f2260d 100755 --- a/.github/actions/qt5-build/entrypoint.sh +++ b/.github/actions/qt5-build/entrypoint.sh @@ -16,7 +16,6 @@ cmake ../source/ \ -DCMAKE_CXX_COMPILER_LAUNCHER="ccache" \ -DCMAKE_INSTALL_PREFIX=../install \ -DMLN_WITH_QT=ON \ - -DMLN_QT_DEPLOYMENT=ON \ - -DMLN_QT_LIBRARY_ONLY=ON + -DMLN_QT_DEPLOYMENT=ON ninja ninja install diff --git a/.github/actions/qt6-build/entrypoint.sh b/.github/actions/qt6-build/entrypoint.sh index 8dce4ec63..95ed00009 100755 --- a/.github/actions/qt6-build/entrypoint.sh +++ b/.github/actions/qt6-build/entrypoint.sh @@ -14,8 +14,7 @@ qt-cmake ../source/ \ -DCMAKE_CXX_COMPILER_LAUNCHER="ccache" \ -DCMAKE_INSTALL_PREFIX=../install \ -DMLN_WITH_QT=ON \ - -DMLN_QT_DEPLOYMENT=ON \ - -DMLN_QT_LIBRARY_ONLY=ON + -DMLN_QT_DEPLOYMENT=ON ninja ninja install cd ../install diff --git a/.github/workflows/qt-ci.yml b/.github/workflows/qt-ci.yml index 143983c91..e8eabb3e6 100644 --- a/.github/workflows/qt-ci.yml +++ b/.github/workflows/qt-ci.yml @@ -195,8 +195,7 @@ jobs: -DCMAKE_OSX_DEPLOYMENT_TARGET="${DEPLOYMENT_TARGET}" \ -DCMAKE_OSX_ARCHITECTURES="${DEPLOYMENT_ARCH}" \ -DMLN_WITH_QT=ON \ - -DMLN_QT_DEPLOYMENT=ON \ - -DMLN_QT_LIBRARY_ONLY=ON + -DMLN_QT_DEPLOYMENT=ON ninja ninja install @@ -222,8 +221,7 @@ jobs: -DCMAKE_CXX_COMPILER_LAUNCHER="ccache.exe" \ -DCMAKE_INSTALL_PREFIX="../install" \ -DMLN_WITH_QT=ON \ - -DMLN_QT_DEPLOYMENT=ON \ - -DMLN_QT_LIBRARY_ONLY=ON + -DMLN_QT_DEPLOYMENT=ON ninja.exe ninja.exe install diff --git a/platform/default/include/mbgl/gl/headless_backend.hpp b/platform/default/include/mbgl/gl/headless_backend.hpp index c16dcc355..85ca7c5cb 100644 --- a/platform/default/include/mbgl/gl/headless_backend.hpp +++ b/platform/default/include/mbgl/gl/headless_backend.hpp @@ -24,6 +24,7 @@ public: class Impl { public: virtual ~Impl() = default; + virtual bool glNeedsActiveContextOnDestruction() const { return false; } virtual gl::ProcAddress getExtensionFunctionPointer(const char*) = 0; virtual void activateContext() = 0; virtual void deactivateContext() {} diff --git a/platform/default/src/mbgl/gl/headless_backend.cpp b/platform/default/src/mbgl/gl/headless_backend.cpp index 71178baa1..816c38e70 100644 --- a/platform/default/src/mbgl/gl/headless_backend.cpp +++ b/platform/default/src/mbgl/gl/headless_backend.cpp @@ -45,10 +45,19 @@ HeadlessBackend::HeadlessBackend(const Size size_, HeadlessBackend::~HeadlessBackend() { gfx::BackendScope guard{*this, gfx::BackendScope::ScopeType::Implicit}; + // Some implementations require active context for GL functions to work + if (impl != nullptr && impl->glNeedsActiveContextOnDestruction()) { + impl->activateContext(); + } + // Explicitly reset the renderable resource resource.reset(); // Explicitly reset the context so that it is destructed and cleaned up // before we destruct the impl object. context.reset(); + // Deactivate the context + if (impl != nullptr && impl->glNeedsActiveContextOnDestruction()) { + impl->deactivateContext(); + } } gl::ProcAddress HeadlessBackend::getExtensionFunctionPointer(const char* name) { diff --git a/platform/qt/qt.cmake b/platform/qt/qt.cmake index c00211562..cd9022012 100644 --- a/platform/qt/qt.cmake +++ b/platform/qt/qt.cmake @@ -33,6 +33,8 @@ else() endif() if(CMAKE_SYSTEM_NAME STREQUAL "Linux") + find_package(Threads REQUIRED) + option(MLN_QT_WITH_INTERNAL_ICU "Build MapLibre GL Qt bindings with internal ICU" OFF) if(NOT MLN_QT_WITH_INTERNAL_ICU) find_package(ICU COMPONENTS uc REQUIRED) @@ -134,6 +136,7 @@ endif() target_link_libraries( mbgl-core PRIVATE + $<$:${CMAKE_THREAD_LIBS_INIT}> $<$,$>>:z> Qt${QT_VERSION_MAJOR}::Core Qt${QT_VERSION_MAJOR}::Gui @@ -356,22 +359,16 @@ if(NOT MLN_QT_LIBRARY_ONLY) target_compile_definitions( mbgl-test-runner - PRIVATE WORK_DIRECTORY=${PROJECT_SOURCE_DIR} + PRIVATE + WORK_DIRECTORY=${PROJECT_SOURCE_DIR} + $<$:MBGL_BUILDING_LIB> ) - if(WIN32) - target_compile_definitions( - mbgl-test-runner - PRIVATE MBGL_BUILDING_LIB - ) - endif() - target_link_libraries( mbgl-test-runner PRIVATE Qt${QT_VERSION_MAJOR}::Gui mbgl-compiler-options - $<$>:pthread> ) if(CMAKE_SYSTEM_NAME STREQUAL Darwin) @@ -379,15 +376,6 @@ if(NOT MLN_QT_LIBRARY_ONLY) mbgl-test-runner PRIVATE -Wl,-force_load mbgl-test ) - elseif(MSVC) - target_link_options( - mbgl-test-runner - PRIVATE /WHOLEARCHIVE:mbgl-test.lib - ) - target_link_libraries( - mbgl-test-runner - PRIVATE mbgl-test - ) else() target_link_libraries( mbgl-test-runner diff --git a/platform/qt/src/mbgl/bidi.cpp b/platform/qt/src/mbgl/bidi.cpp index f6d7673aa..0523712b3 100644 --- a/platform/qt/src/mbgl/bidi.cpp +++ b/platform/qt/src/mbgl/bidi.cpp @@ -1,7 +1,7 @@ -#include - #include +#include + namespace mbgl { // This stub implementation is stateless and doesn't implement the private @@ -11,6 +11,7 @@ class BiDiImpl { }; std::u16string applyArabicShaping(const std::u16string& input) { + // Qt does not support raw Arabic shaping, so we just return the input return input; } diff --git a/platform/qt/src/mbgl/headless_backend_qt.cpp b/platform/qt/src/mbgl/headless_backend_qt.cpp index bce5ae0cf..0a5770be4 100644 --- a/platform/qt/src/mbgl/headless_backend_qt.cpp +++ b/platform/qt/src/mbgl/headless_backend_qt.cpp @@ -13,8 +13,8 @@ public: QtBackendImpl() { // QtBackendImpl must be created in the main/GUI thread on platforms // that have a QWindow-based QOffscreenSurface. - surface.create(); context.create(); + surface.create(); } ~QtBackendImpl() = default; @@ -27,6 +27,8 @@ public: void deactivateContext() { context.doneCurrent(); } + bool glNeedsActiveContextOnDestruction() const { return true; } + private: QOpenGLContext context; QOffscreenSurface surface; diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 47c866a9d..118fd100c 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -61,7 +61,7 @@ add_library( ${PROJECT_SOURCE_DIR}/test/style/style_image.test.cpp ${PROJECT_SOURCE_DIR}/test/style/style_layer.test.cpp ${PROJECT_SOURCE_DIR}/test/style/style_parser.test.cpp - $<$>:${PROJECT_SOURCE_DIR}/test/text/bidi.test.cpp> + $<$>,$>>:${PROJECT_SOURCE_DIR}/test/text/bidi.test.cpp> ${PROJECT_SOURCE_DIR}/test/text/calculate_tile_distances.test.cpp ${PROJECT_SOURCE_DIR}/test/text/cross_tile_symbol_index.test.cpp ${PROJECT_SOURCE_DIR}/test/text/formatted.test.cpp diff --git a/test/fixtures/.gitignore b/test/fixtures/.gitignore index 3a379d66b..2a693130b 100644 --- a/test/fixtures/.gitignore +++ b/test/fixtures/.gitignore @@ -1,2 +1,3 @@ diff.png -actual.png \ No newline at end of file +actual.png +*.db diff --git a/test/fixtures/local_glyphs/ping_fang_qt/expected.png b/test/fixtures/local_glyphs/ping_fang_qt/expected.png index 94d086f63..f11741278 100644 Binary files a/test/fixtures/local_glyphs/ping_fang_qt/expected.png and b/test/fixtures/local_glyphs/ping_fang_qt/expected.png differ diff --git a/test/fixtures/offline_database/offline_sideload.db b/test/fixtures/offline_database/offline_sideload.db deleted file mode 100644 index 67c98bb26..000000000 Binary files a/test/fixtures/offline_database/offline_sideload.db and /dev/null differ diff --git a/test/src/mbgl/test/test.cpp b/test/src/mbgl/test/test.cpp index 5b37ba191..ad1f1491f 100644 --- a/test/src/mbgl/test/test.cpp +++ b/test/src/mbgl/test/test.cpp @@ -7,6 +7,10 @@ namespace mbgl { int runTests(int argc, char *argv[]) { +#if TEST_HAS_SERVER && defined(__QT__) + auto server = std::make_unique(); +#endif + testing::InitGoogleTest(&argc, argv); // In order to run specific tests diff --git a/test/storage/offline_database.test.cpp b/test/storage/offline_database.test.cpp index 2ebfce093..0c82079a0 100644 --- a/test/storage/offline_database.test.cpp +++ b/test/storage/offline_database.test.cpp @@ -685,7 +685,9 @@ TEST(OfflineDatabase, TEST_REQUIRES_WRITE(DeleteRegion)) { { OfflineDatabase dbCreate(filename, fixture::tileServerOptions); } +#ifndef __QT__ // Qt doesn't decrease the size of the database file. size_t initialSize = util::read_file(filename).size(); +#endif { Response response; @@ -732,13 +734,17 @@ TEST(OfflineDatabase, TEST_REQUIRES_WRITE(DeleteRegion)) { // The tiles from the offline region will migrate to the // ambient cache and shrink the database to the maximum // size defined by default. +#ifndef __QT__ // Qt doesn't decrease the size of the database file. EXPECT_LE(sizeWithoutRegions, util::DEFAULT_MAX_CACHE_SIZE); +#endif ASSERT_EQ(0u, db.listRegions().value().size()); EXPECT_LT(sizeWithoutRegions, sizeWithOneRegion); } +#ifndef __QT__ // Qt doesn't decrease the size of the database file. EXPECT_EQ(initialSize, util::read_file(filename).size()); +#endif EXPECT_EQ(0u, log.uncheckedCount()); } @@ -769,7 +775,9 @@ TEST(OfflineDatabase, TEST_REQUIRES_WRITE(Pack)) { EXPECT_EQ(0u, log.uncheckedCount()); db.pack(); +#ifndef __QT__ // Qt doesn't decrease the size of the database file. EXPECT_EQ(initialSize, util::read_file(filename).size()); +#endif EXPECT_EQ(0u, log.uncheckedCount()); } @@ -976,7 +984,9 @@ TEST(OfflineDatabase, TEST_REQUIRES_WRITE(ClearAmbientCache)) { { OfflineDatabase dbCreate(filename, fixture::tileServerOptions); } +#ifndef __QT__ // Qt doesn't decrease the size of the database file. size_t initialSize = util::read_file(filename).size(); +#endif { Response response; @@ -996,7 +1006,9 @@ TEST(OfflineDatabase, TEST_REQUIRES_WRITE(ClearAmbientCache)) { db.clearAmbientCache(); } +#ifndef __QT__ // Qt doesn't decrease the size of the database file. EXPECT_EQ(initialSize, util::read_file(filename).size()); +#endif EXPECT_EQ(0u, log.uncheckedCount()); } @@ -1016,6 +1028,7 @@ TEST(OfflineDatabase, CreateRegionInfiniteMaxZoom) { }); } +#ifndef __QT__ // Qt doesn't support concurrent access to the same database. TEST(OfflineDatabase, TEST_REQUIRES_WRITE(ConcurrentUse)) { FixtureLog log; deleteDatabaseFiles(); @@ -1048,6 +1061,7 @@ TEST(OfflineDatabase, TEST_REQUIRES_WRITE(ConcurrentUse)) { EXPECT_EQ(0u, log.uncheckedCount()); } +#endif TEST(OfflineDatabase, PutReturnsSize) { FixtureLog log;