diff --git a/app/render/backend/dynamicrenderer.cpp b/app/render/backend/dynamicrenderer.cpp index ffc8d1644..a9708ccbd 100644 --- a/app/render/backend/dynamicrenderer.cpp +++ b/app/render/backend/dynamicrenderer.cpp @@ -3,6 +3,7 @@ #include #include #include +#include #include namespace olive @@ -39,8 +40,20 @@ QString DynamicRenderer::LibraryFilename() const #else const QString filename = QStringLiteral("lib") + base + QStringLiteral(".so"); #endif - return QDir(QCoreApplication::applicationDirPath()).filePath( - filename); + + const QDir app_dir(QCoreApplication::applicationDirPath()); + const QStringList candidates = { + app_dir.filePath(filename), + app_dir.filePath(QDir(QStringLiteral("render_backends")).filePath(filename)), + app_dir.filePath(QDir(QStringLiteral("../app")).filePath(filename)), + app_dir.filePath(QDir(QStringLiteral("../../app")).filePath(filename)) + }; + for (const QString &candidate : candidates) { + if (QFileInfo::exists(candidate)) { + return candidate; + } + } + return candidates.first(); } bool DynamicRenderer::Load() diff --git a/docs/zh/render-backend-dynamic-plan.md b/docs/zh/render-backend-dynamic-plan.md index 394f4bef6..2cc7a54a9 100644 --- a/docs/zh/render-backend-dynamic-plan.md +++ b/docs/zh/render-backend-dynamic-plan.md @@ -57,6 +57,8 @@ 当前实验构建已经可以通过 `OAK_ENABLE_DYNAMIC_RENDER_BACKEND=ON` 生成 `liboakgl.so`,做法是把相关 object/static 依赖切到 PIC 后链接进 OpenGL 后端库。这满足“动态库一侧 C++ 实现 + C ABI 导出”的第一步,但它仍不是最终边界:后端库暂时会带入较多 editor 代码和全局状态。 +已新增 `DynamicRenderBackend.LoadsExperimentalOpenGLBackend` smoke test:默认构建跳过,实验构建会实际加载 `liboakgl` 并验证 create/destroy C ABI 路径。 + 因此动态后端成为默认路径前,仍需要把 OpenGL 后端库的链接边界收敛到最小集合: - 后端库只拥有 OpenGL/Vulkan native 操作和必要的后端私有状态。 diff --git a/tests/gtest/CMakeLists.txt b/tests/gtest/CMakeLists.txt index fc25810c9..65c9082e6 100644 --- a/tests/gtest/CMakeLists.txt +++ b/tests/gtest/CMakeLists.txt @@ -30,6 +30,7 @@ add_executable(olive-gtest plugin_format_conversion_test.cpp audio_smoke_test.cpp viewer_smoke_test.cpp + dynamic_render_backend_test.cpp opengl_readback_guard_test.cpp plugin_render_pipeline_test.cpp plugin_renderer_readback_test.cpp @@ -80,6 +81,11 @@ target_compile_options( ${OLIVE_COMPILE_OPTIONS} ) +if (OAK_ENABLE_DYNAMIC_RENDER_BACKEND) + target_compile_definitions(olive-gtest PRIVATE OAK_ENABLE_DYNAMIC_RENDER_BACKEND) + add_dependencies(olive-gtest oakgl) +endif() + if (MSVC) add_test("Olive.gtest" olive-gtest) else() diff --git a/tests/gtest/dynamic_render_backend_test.cpp b/tests/gtest/dynamic_render_backend_test.cpp new file mode 100644 index 000000000..7e67a35bd --- /dev/null +++ b/tests/gtest/dynamic_render_backend_test.cpp @@ -0,0 +1,14 @@ +#include + +#include "render/backend/dynamicrenderer.h" + +TEST(DynamicRenderBackend, LoadsExperimentalOpenGLBackend) +{ +#ifndef OAK_ENABLE_DYNAMIC_RENDER_BACKEND + GTEST_SKIP() << "Dynamic render backend is not enabled in this build"; +#else + olive::DynamicRenderer renderer(QStringLiteral("opengl")); + ASSERT_TRUE(renderer.Load()); + EXPECT_EQ(renderer.OpenGLContext(), nullptr); +#endif +}