]> git.sesse.net Git - nageru/blobdiff - glwidget.cpp
Refcount the input frames directly instead of trying to free them after-the-fact...
[nageru] / glwidget.cpp
index 8ccba20f69de87226e422316bbbd37216963064a..3fb4889dc314c7ce163d389477926dfe110d51bc 100644 (file)
@@ -1,24 +1,31 @@
-#include <qmetatype.h>
-#include <qdatastream.h>
-#include <qtextstream.h>
-#include <qcursor.h>
-#include <qcoreevent.h>
+#include <qmetatype.h>  // Needs to come before egl.h.
+#include <qdatastream.h>  // Needs to come before egl.h.
+#include <qtextstream.h>  // Needs to come before egl.h.
+#include <qcursor.h>  // Needs to come before egl.h.
+#include <qcoreevent.h>  // Needs to come before egl.h.
 #include <epoxy/gl.h>
 #include <epoxy/egl.h>
-#include "context.h"
+#include <QSurfaceFormat>
+
 #include "glwidget.h"
-#include "mixer.h"
-#include <QCoreApplication>
-#include <QGuiApplication>
-#include <QThread>
-#include <math.h>
-#include <thread>
+
 #include <movit/resource_pool.h>
+#include <stdio.h>
+#include <mutex>
+
+#include "context.h"
+#include "mixer.h"
+#include "ref_counted_gl_sync.h"
+
+class QSurface;
+class QWidget;
+
 #undef Success
 #include <movit/util.h>
+#include <string>
 
 GLWidget::GLWidget(QWidget *parent)
-    : QOpenGLWidget(parent),
+    : QGLWidget(parent, global_share_widget),
       resource_pool(new movit::ResourcePool)
 {
 }
@@ -32,16 +39,14 @@ void GLWidget::initializeGL()
        printf("egl context=%p\n", eglGetCurrentContext());
        //printf("threads: %p %p\n", QThread::currentThread(), qGuiApp->thread());
 
-       GLWidget *t = this;
-       set_frame_ready_fallback([t]{
-               QMetaObject::invokeMethod(t, "update", Qt::AutoConnection);
+       static std::once_flag flag;
+       std::call_once(flag, [this]{
+               global_mixer = new Mixer(QGLFormat::toSurfaceFormat(format()));
+               global_mixer->start();
+       });
+       global_mixer->set_frame_ready_callback(output, [this]{
+               QMetaObject::invokeMethod(this, "update", Qt::AutoConnection);
        });
-
-       QSurface *surface = create_surface(format());
-       QSurface *surface2 = create_surface(format());
-       QSurface *surface3 = create_surface(format());
-       QSurface *surface4 = create_surface(format());
-       start_mixer(surface, surface2, surface3, surface4);
 
        // Prepare the shaders to actually get the texture shown (ick).
        glDisable(GL_BLEND);
@@ -76,8 +81,8 @@ void GLWidget::initializeGL()
        };
        glGenVertexArrays(1, &vao);
        glBindVertexArray(vao);
-       GLuint position_vbo = movit::fill_vertex_attribute(program_num, "position", 2, GL_FLOAT, sizeof(vertices), vertices);
-       GLuint texcoord_vbo = movit::fill_vertex_attribute(program_num, "texcoord", 2, GL_FLOAT, sizeof(vertices), vertices);  // Same as vertices.
+       position_vbo = movit::fill_vertex_attribute(program_num, "position", 2, GL_FLOAT, sizeof(vertices), vertices);
+       texcoord_vbo = movit::fill_vertex_attribute(program_num, "texcoord", 2, GL_FLOAT, sizeof(vertices), vertices);  // Same as vertices.
 
 #if 0
        // Cleanup.
@@ -89,10 +94,16 @@ void GLWidget::initializeGL()
 #endif
 }
 
+void GLWidget::resizeGL(int width, int height)
+{
+       glViewport(0, 0, width, height);
+       global_mixer->set_preview_size(output, width, height);
+}
+
 void GLWidget::paintGL()
 {
-       DisplayFrame frame;
-       if (!mixer_get_display_frame(&frame)) {
+       Mixer::DisplayFrame frame;
+       if (!global_mixer->get_display_frame(output, &frame)) {
                glClearColor(0.0f, 1.0f, 0.0f, 1.0f);
                glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
                return;