all repos — mgba @ c0120cd58608da068d1218796a02f2f3468608b0

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	void setVideoProxy(std::shared_ptr<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 interframeBlending(bool enable) override;
 56	void filter(bool filter) override;
 57	void framePosted() override;
 58	void setShaders(struct VDir*) override;
 59	void clearShaders() override;
 60	void resizeContext() override;
 61
 62protected:
 63	virtual void paintEvent(QPaintEvent*) override {}
 64	virtual void resizeEvent(QResizeEvent*) override;
 65
 66private:
 67	void resizePainter();
 68
 69	bool m_isDrawing = false;
 70	QOpenGLContext* m_gl;
 71	PainterGL* m_painter;
 72	QThread* m_drawThread = nullptr;
 73	std::shared_ptr<CoreController> m_context;
 74};
 75
 76class PainterGL : public QObject {
 77Q_OBJECT
 78
 79public:
 80	PainterGL(QWindow* surface, QOpenGLContext* parent, int forceVersion = 0);
 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
 89	void setVideoProxy(std::shared_ptr<VideoProxy>);
 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 interframeBlending(bool enable);
102	void filter(bool filter);
103	void resizeContext();
104
105	void setShaders(struct VDir*);
106	void clearShaders();
107	VideoShader* shaders();
108
109	int glTex();
110
111private slots:
112	void swap();
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	QWindow* m_surface;
124	QPaintDevice* m_window;
125	QOpenGLContext* m_gl;
126	bool m_active = false;
127	bool m_started = false;
128	std::shared_ptr<CoreController> m_context = nullptr;
129	bool m_supportsShaders;
130	VideoShader m_shader{};
131	VideoBackend* m_backend = nullptr;
132	QSize m_size;
133	MessagePainter* m_messagePainter = nullptr;
134	QTimer m_swapTimer{this};
135	bool m_needsUnlock = false;
136	bool m_frameReady = false;
137	std::shared_ptr<VideoProxy> m_videoProxy;
138};
139
140}
141
142#endif