/* Copyright (c) 2013-2015 Jeffrey Pfau * * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ #pragma once #if defined(BUILD_GL) || defined(BUILD_GLES2) #include "Display.h" #ifdef USE_EPOXY #include #ifndef GLdouble #define GLdouble GLdouble #endif #endif #include #include #include #include #include #include #include #include "VideoProxy.h" #include "platform/video-backend.h" namespace QGBA { class PainterGL; class DisplayGL : public Display { Q_OBJECT public: DisplayGL(const QSurfaceFormat& format, QWidget* parent = nullptr); ~DisplayGL(); void startDrawing(std::shared_ptr) override; bool isDrawing() const override { return m_isDrawing; } bool supportsShaders() const override; VideoShader* shaders() override; VideoProxy* videoProxy() override; int framebufferHandle() override; public slots: void stopDrawing() override; void pauseDrawing() override; void unpauseDrawing() override; void forceDraw() override; void lockAspectRatio(bool lock) override; void lockIntegerScaling(bool lock) override; void filter(bool filter) override; void framePosted() override; void setShaders(struct VDir*) override; void clearShaders() override; void resizeContext() override; protected: virtual void paintEvent(QPaintEvent*) override {} virtual void resizeEvent(QResizeEvent*) override; private: void resizePainter(); bool m_isDrawing = false; QOpenGLContext* m_gl; PainterGL* m_painter; QThread* m_drawThread = nullptr; std::shared_ptr m_context; VideoProxy m_videoProxy; }; class PainterGL : public QObject { Q_OBJECT public: PainterGL(VideoProxy* proxy, QWindow* surface, QOpenGLContext* parent); ~PainterGL(); void setContext(std::shared_ptr); void setMessagePainter(MessagePainter*); void enqueue(const uint32_t* backing); bool supportsShaders() const { return m_supportsShaders; } public slots: void forceDraw(); void draw(); void start(); void stop(); void pause(); void unpause(); void resize(const QSize& size); void lockAspectRatio(bool lock); void lockIntegerScaling(bool lock); void filter(bool filter); void resizeContext(); void setShaders(struct VDir*); void clearShaders(); VideoShader* shaders(); int glTex(); private: void performDraw(); void dequeue(); void dequeueAll(); QList m_free; QQueue m_queue; QPainter m_painter; QMutex m_mutex; QWindow* m_surface; QPaintDevice* m_window; QOpenGLContext* m_gl; bool m_active = false; bool m_started = false; std::shared_ptr m_context = nullptr; bool m_supportsShaders; VideoShader m_shader{}; VideoBackend* m_backend = nullptr; QSize m_size; MessagePainter* m_messagePainter = nullptr; QElapsedTimer m_delayTimer; VideoProxy* m_videoProxy; }; } #endif