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.
8 #include <QSurfaceFormat>
12 #include <movit/resource_pool.h>
18 #include "ref_counted_gl_sync.h"
24 #include <movit/util.h>
27 GLWidget::GLWidget(QWidget *parent)
28 : QGLWidget(parent, global_share_widget),
29 resource_pool(new movit::ResourcePool)
37 void GLWidget::initializeGL()
39 printf("egl context=%p\n", eglGetCurrentContext());
40 //printf("threads: %p %p\n", QThread::currentThread(), qGuiApp->thread());
42 static std::once_flag flag;
43 std::call_once(flag, [this]{
44 global_mixer = new Mixer(QGLFormat::toSurfaceFormat(format()));
45 global_mixer->start();
47 global_mixer->set_frame_ready_callback(output, [this]{
48 QMetaObject::invokeMethod(this, "update", Qt::AutoConnection);
52 glDisable(GL_DEPTH_TEST);
53 glDepthMask(GL_FALSE);
56 void GLWidget::resizeGL(int width, int height)
58 glViewport(0, 0, width, height);
61 void GLWidget::paintGL()
63 Mixer::DisplayFrame frame;
64 if (!global_mixer->get_display_frame(output, &frame)) {
65 glClearColor(0.0f, 1.0f, 0.0f, 1.0f);
66 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
70 glWaitSync(frame.ready_fence.get(), /*flags=*/0, GL_TIMEOUT_IGNORED);
72 frame.chain->render_to_screen();