all repos — mgba @ 67c3f386a4106d5d3017aea882f64dc0ae94a375

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