all repos — mgba @ e17e4fd19003209ff9db1f0ac1394e463c7b4a47

mGBA Game Boy Advance Emulator

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