src/platform/qt/DisplayGL.h (view raw)
1/* Copyright (c) 2013-2015 Jeffrey Pfau
2 *
3 * This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6#ifndef QGBA_DISPLAY_GL
7#define QGBA_DISPLAY_GL
8
9#include "Display.h"
10
11#include <QGLWidget>
12#include <QList>
13#include <QMouseEvent>
14#include <QQueue>
15#include <QThread>
16#include <QTimer>
17
18struct GBAThread;
19struct VideoBackend;
20
21namespace QGBA {
22
23class EmptyGLWidget : public QGLWidget {
24public:
25 EmptyGLWidget(const QGLFormat& format, QWidget* parent) : QGLWidget(format, parent) { setAutoBufferSwap(false); }
26
27protected:
28 void paintEvent(QPaintEvent*) override {}
29 void resizeEvent(QResizeEvent*) override {}
30 void mouseMoveEvent(QMouseEvent* event) override { event->ignore(); }
31};
32
33class PainterGL;
34class DisplayGL : public Display {
35Q_OBJECT
36
37public:
38 DisplayGL(const QGLFormat& format, QWidget* parent = nullptr);
39 ~DisplayGL();
40
41 bool isDrawing() const override { return m_isDrawing; }
42
43public slots:
44 void startDrawing(GBAThread* context) override;
45 void stopDrawing() override;
46 void pauseDrawing() override;
47 void unpauseDrawing() override;
48 void forceDraw() override;
49 void lockAspectRatio(bool lock) override;
50 void filter(bool filter) override;
51 void framePosted(const uint32_t*) override;
52
53protected:
54 virtual void paintEvent(QPaintEvent*) override {}
55 virtual void resizeEvent(QResizeEvent*) override;
56
57private:
58 void resizePainter();
59
60 bool m_isDrawing;
61 QGLWidget* m_gl;
62 PainterGL* m_painter;
63 QThread* m_drawThread;
64 GBAThread* m_context;
65};
66
67class PainterGL : public QObject {
68Q_OBJECT
69
70public:
71 PainterGL(QGLWidget* parent, QGLFormat::OpenGLVersionFlags = QGLFormat::OpenGL_Version_1_1);
72 ~PainterGL();
73
74 void setContext(GBAThread*);
75 void setMessagePainter(MessagePainter*);
76 void enqueue(const uint32_t* backing);
77
78public slots:
79 void forceDraw();
80 void draw();
81 void start();
82 void stop();
83 void pause();
84 void unpause();
85 void resize(const QSize& size);
86 void lockAspectRatio(bool lock);
87 void filter(bool filter);
88
89private:
90 void performDraw();
91 void dequeue();
92 void dequeueAll();
93
94 QList<uint32_t*> m_free;
95 QQueue<uint32_t*> m_queue;
96 QPainter m_painter;
97 QMutex m_mutex;
98 QGLWidget* m_gl;
99 bool m_active;
100 GBAThread* m_context;
101 VideoBackend* m_backend;
102 QSize m_size;
103 MessagePainter* m_messagePainter;
104};
105
106}
107
108#endif