fixup! *rest of the owl* sandbox/mmajewski2/virgl-cleanup
authorMateusz Majewski <m.majewski2@samsung.com>
Wed, 7 May 2025 10:17:11 +0000 (12:17 +0200)
committerMateusz Majewski <m.majewski2@samsung.com>
Wed, 7 May 2025 10:17:11 +0000 (12:17 +0200)
tizen/src/ui/displayglwidget.cpp
tizen/src/ui/qt5_supplement.cpp

index 4b55d25745156984d20e53fd20b4d374f114d734..2af84b6e6e38583bb47abd342d78aa08faeac322 100644 (file)
@@ -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
index 571457efacfd2b4f6adc01eff26ddbaa7b9d64f9..089f9a6098ba28520f1bea67549b528ef5dc399e 100644 (file)
@@ -29,6 +29,7 @@
  */
 
 #include <memory>
+#include <vector>
 
 #include <QApplication>
 #include <QOpenGLContext>
@@ -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<QOpenGLContext *> 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)