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