1 #include <qmetatype.h> // Needs to come before egl.h.
2 #include <qdatastream.h> // Needs to come before egl.h.
3 #include <qtextstream.h> // Needs to come before egl.h.
4 #include <qcursor.h> // Needs to come before egl.h.
5 #include <qcoreevent.h> // Needs to come before egl.h.
6 #include <qevent.h> // Needs to come before egl.h.
9 #include <QSurfaceFormat>
12 #include "mainwindow.h"
14 #include <movit/resource_pool.h>
20 #include "ref_counted_gl_sync.h"
28 #include <movit/util.h>
33 GLWidget::GLWidget(QWidget *parent)
34 : QGLWidget(parent, global_share_widget),
35 resource_pool(new movit::ResourcePool)
43 void GLWidget::initializeGL()
45 printf("egl context=%p\n", eglGetCurrentContext());
46 //printf("threads: %p %p\n", QThread::currentThread(), qGuiApp->thread());
48 static std::once_flag flag;
49 std::call_once(flag, [this]{
50 global_mixer = new Mixer(QGLFormat::toSurfaceFormat(format()));
51 global_mixer->set_audio_level_callback([this](float level){
52 global_vu_meter->set_level(level);
54 global_mixer->start();
56 global_mixer->set_frame_ready_callback(output, [this]{
57 QMetaObject::invokeMethod(this, "update", Qt::AutoConnection);
58 emit transition_names_updated(global_mixer->get_transition_names());
62 glDisable(GL_DEPTH_TEST);
63 glDepthMask(GL_FALSE);
66 void GLWidget::resizeGL(int width, int height)
68 glViewport(0, 0, width, height);
71 void GLWidget::paintGL()
73 Mixer::DisplayFrame frame;
74 if (!global_mixer->get_display_frame(output, &frame)) {
75 glClearColor(0.0f, 1.0f, 0.0f, 1.0f);
76 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
80 glWaitSync(frame.ready_fence.get(), /*flags=*/0, GL_TIMEOUT_IGNORED);
82 frame.chain->render_to_screen();
86 void GLWidget::mousePressEvent(QMouseEvent *event)