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#ifdef USE_EPOXY
12#include <epoxy/gl.h>
13#ifndef GLdouble
14#define GLdouble GLdouble
15#endif
16#endif
17
18#include <QElapsedTimer>
19#include <QGLWidget>
20#include <QList>
21#include <QMouseEvent>
22#include <QQueue>
23#include <QThread>
24
25#include "platform/video-backend.h"
26
27namespace QGBA {
28
29class EmptyGLWidget : public QGLWidget {
30public:
31 EmptyGLWidget(const QGLFormat& format, QWidget* parent) : QGLWidget(format, parent) { setAutoBufferSwap(false); }
32
33protected:
34 void paintEvent(QPaintEvent*) override {}
35 void resizeEvent(QResizeEvent*) override {}
36 void mouseMoveEvent(QMouseEvent* event) override { event->ignore(); }
37};
38
39class PainterGL;
40class DisplayGL : public Display {
41Q_OBJECT
42
43public:
44 DisplayGL(const QGLFormat& format, QWidget* parent = nullptr);
45 ~DisplayGL();
46
47 bool isDrawing() const override { return m_isDrawing; }
48 bool supportsShaders() const override;
49 VideoShader* shaders() override;
50
51public slots:
52 void startDrawing(mCoreThread* context) override;
53 void stopDrawing() override;
54 void pauseDrawing() override;
55 void unpauseDrawing() override;
56 void forceDraw() override;
57 void lockAspectRatio(bool lock) override;
58 void lockIntegerScaling(bool lock) override;
59 void filter(bool filter) override;
60 void framePosted(const uint32_t*) override;
61 void setShaders(struct VDir*) override;
62 void clearShaders() override;
63
64protected:
65 virtual void paintEvent(QPaintEvent*) override {}
66 virtual void resizeEvent(QResizeEvent*) override;
67
68private:
69 void resizePainter();
70
71 bool m_isDrawing;
72 QGLWidget* m_gl;
73 PainterGL* m_painter;
74 QThread* m_drawThread;
75 mCoreThread* m_context;
76};
77
78class PainterGL : public QObject {
79Q_OBJECT
80
81public:
82 PainterGL(int majorVersion, QGLWidget* parent);
83 ~PainterGL();
84
85 void setContext(mCoreThread*);
86 void setMessagePainter(MessagePainter*);
87 void enqueue(const uint32_t* backing);
88
89 bool supportsShaders() const { return m_supportsShaders; }
90
91public slots:
92 void forceDraw();
93 void draw();
94 void start();
95 void stop();
96 void pause();
97 void unpause();
98 void resize(const QSize& size);
99 void lockAspectRatio(bool lock);
100 void lockIntegerScaling(bool lock);
101 void filter(bool filter);
102
103 void setShaders(struct VDir*);
104 void clearShaders();
105 VideoShader* shaders();
106
107private:
108 void performDraw();
109 void dequeue();
110 void dequeueAll();
111
112 QList<uint32_t*> m_free;
113 QQueue<uint32_t*> m_queue;
114 QPainter m_painter;
115 QMutex m_mutex;
116 QGLWidget* m_gl;
117 bool m_active;
118 bool m_started;
119 mCoreThread* m_context;
120 bool m_supportsShaders;
121 VideoShader m_shader;
122 VideoBackend* m_backend;
123 QSize m_size;
124 MessagePainter* m_messagePainter;
125 QElapsedTimer m_delayTimer;
126};
127
128}
129
130#endif