From 585f0e3cc990c47689d3fae0f84a1f734ee05453 Mon Sep 17 00:00:00 2001 From: Mateusz Majewski Date: Wed, 7 May 2025 12:17:11 +0200 Subject: [PATCH] fixup! *rest of the owl* --- tizen/src/ui/displayglwidget.cpp | 6 ++++++ tizen/src/ui/qt5_supplement.cpp | 21 +++++++++++++++++++++ 2 files changed, 27 insertions(+) diff --git a/tizen/src/ui/displayglwidget.cpp b/tizen/src/ui/displayglwidget.cpp index 4b55d25745..2af84b6e6e 100644 --- a/tizen/src/ui/displayglwidget.cpp +++ b/tizen/src/ui/displayglwidget.cpp @@ -255,6 +255,12 @@ QOpenGLContext *DisplayGLWidget::createSharedContext(int major, int minor) QSurfaceFormat fmt; #ifdef CONFIG_DARWIN + /* On macOS, pre-GL3 and modern core GL are two separate GL implementations + * that cannot share resources with each other. Therefore we ignore the input + * version to ensure we always use the modern implementation. + * Additionally, we want to reuse contexts on macOS, see comment in + * qt5_gl_create_context_internal. This only really makes sense if they all + * have the same version. */ fmt.setVersion(4, 1); fmt.setProfile(QSurfaceFormat::CoreProfile); #else diff --git a/tizen/src/ui/qt5_supplement.cpp b/tizen/src/ui/qt5_supplement.cpp index 571457efac..089f9a6098 100644 --- a/tizen/src/ui/qt5_supplement.cpp +++ b/tizen/src/ui/qt5_supplement.cpp @@ -29,6 +29,7 @@ */ #include +#include #include #include @@ -455,7 +456,11 @@ void qt5_early_prepare(enum maru_display_type _display_type) Q_INIT_RESOURCE(resource); +#ifdef CONFIG_DARWIN if (display_type == MARU_DISPLAY_TYPE_ONSCREEN || display_type == MARU_DISPLAY_TYPE_GL) { +#else + if (display_type == MARU_DISPLAY_TYPE_ONSCREEN) { +#endif QCoreApplication::setAttribute(Qt::AA_UseDesktopOpenGL); QCoreApplication::setAttribute(Qt::AA_ShareOpenGLContexts); @@ -614,6 +619,7 @@ void qt5_update_texture(void *dpy_item) #define DPY_ITEM_NO 5 static dpy_item dpy_item_pool[DPY_ITEM_NO]; static uint64_t dpy_item_gen[DPY_ITEM_NO]; +static std::vector context_pool; void qt5_gl_init_items() { @@ -674,6 +680,17 @@ uint32_t qt5_gl_refresh_internal(uint32_t tex, uint32_t width, uint32_t height, void *qt5_gl_create_context_internal(int major, int minor) { +#ifdef CONFIG_DARWIN + /* It seems that there is a limit of GL contexts that can be created by a single application. + * After exhausting it, the application segfaults even if the old contexts are deleted. + * Therefore, we reuse contexts instead of destroying them. Note that all of the contexts + * have the same GL version, see DisplayGLWidget::createSharedContext. */ + if (!context_pool.empty()) { + auto ctx = context_pool.back(); + context_pool.pop_back(); + return ctx; + } +#endif if (mainwindow) { return ((DisplayGLWidget *)mainwindow->getDisplay())->createSharedContext(major, minor); } else { @@ -684,7 +701,11 @@ void *qt5_gl_create_context_internal(int major, int minor) void qt5_gl_destroy_context_internal(void *_ctx) { auto ctx = (QOpenGLContext *)_ctx; +#ifdef CONFIG_DARWIN + context_pool.push_back(ctx); +#else delete ctx; +#endif } int qt5_gl_make_context_current_internal(void *_ctx) -- 2.34.1