all repos — mgba @ 3d4faa41e281ff042451032190b3191af2737d5a

mGBA Game Boy Advance Emulator

src/platform/qt/Display.cpp (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#include "Display.h"
  7
  8#include "DisplayGL.h"
  9#include "DisplayQt.h"
 10#include "LogController.h"
 11
 12using namespace QGBA;
 13
 14#if defined(BUILD_GL) || defined(BUILD_GLES2) || defined(USE_EPOXY)
 15Display::Driver Display::s_driver = Display::Driver::OPENGL;
 16#else
 17Display::Driver Display::s_driver = Display::Driver::QT;
 18#endif
 19
 20Display* Display::create(QWidget* parent) {
 21#if defined(BUILD_GL) || defined(BUILD_GLES2) || defined(USE_EPOXY)
 22	QSurfaceFormat format;
 23	format.setSwapInterval(1);
 24	format.setSwapBehavior(QSurfaceFormat::DoubleBuffer);
 25#endif
 26
 27	switch (s_driver) {
 28#if defined(BUILD_GL) || defined(BUILD_GLES2) || defined(USE_EPOXY)
 29	case Driver::OPENGL:
 30		if (QOpenGLContext::openGLModuleType() == QOpenGLContext::LibGLES) {
 31			format.setVersion(2, 0);
 32		} else {
 33			format.setVersion(3, 2);
 34		}
 35		format.setProfile(QSurfaceFormat::CoreProfile);
 36		if (!DisplayGL::supportsFormat(format)) {
 37#ifdef BUILD_GL
 38			LOG(QT, WARN) << ("Failed to create an OpenGL Core context, trying old-style...");
 39			format.setVersion(1, 4);
 40			format.setOption(QSurfaceFormat::DeprecatedFunctions);
 41			if (!DisplayGL::supportsFormat(format)) {
 42				return nullptr;
 43			}
 44#else
 45			return nullptr;
 46#endif
 47		}
 48		return new DisplayGL(format, parent);
 49#endif
 50#ifdef BUILD_GL
 51	case Driver::OPENGL1:
 52		format.setVersion(1, 4);
 53		if (!DisplayGL::supportsFormat(format)) {
 54			return nullptr;
 55		}
 56		return new DisplayGL(format, parent);
 57#endif
 58
 59	case Driver::QT:
 60		return new DisplayQt(parent);
 61
 62	default:
 63#if defined(BUILD_GL) || defined(BUILD_GLES2) || defined(USE_EPOXY)
 64		return new DisplayGL(format, parent);
 65#else
 66		return new DisplayQt(parent);
 67#endif
 68	}
 69}
 70
 71Display::Display(QWidget* parent)
 72	: QWidget(parent)
 73{
 74	setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding);
 75	connect(&m_mouseTimer, &QTimer::timeout, this, &Display::hideCursor);
 76	m_mouseTimer.setSingleShot(true);
 77	m_mouseTimer.setInterval(MOUSE_DISAPPEAR_TIMER);
 78	setMouseTracking(true);
 79}
 80
 81void Display::resizeEvent(QResizeEvent*) {
 82	m_messagePainter.resize(size(), m_lockAspectRatio, devicePixelRatio());
 83}
 84
 85void Display::lockAspectRatio(bool lock) {
 86	m_lockAspectRatio = lock;
 87	m_messagePainter.resize(size(), m_lockAspectRatio, devicePixelRatio());
 88}
 89
 90void Display::lockIntegerScaling(bool lock) {
 91	m_lockIntegerScaling = lock;
 92}
 93
 94void Display::interframeBlending(bool lock) {
 95	m_interframeBlending = lock;
 96}
 97
 98void Display::showOSDMessages(bool enable) {
 99	m_showOSD = enable;
100}
101
102void Display::filter(bool filter) {
103	m_filter = filter;
104}
105
106void Display::showMessage(const QString& message) {
107	m_messagePainter.showMessage(message);
108	if (!isDrawing()) {
109		forceDraw();
110	}
111}
112
113void Display::mouseMoveEvent(QMouseEvent*) {
114	emit showCursor();
115	m_mouseTimer.stop();
116	m_mouseTimer.start();
117}