all repos — mgba @ 346d4210c61510a0eab78c23f7676aae5b93a42a

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