bootmanager.cpp 39 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075
  1. // SPDX-FileCopyrightText: 2014 Citra Emulator Project
  2. // SPDX-License-Identifier: GPL-2.0-or-later
  3. #include <algorithm>
  4. #include <array>
  5. #include <cmath>
  6. #include <cstring>
  7. #include <string>
  8. #include <tuple>
  9. #include <type_traits>
  10. #include <glad/glad.h>
  11. #include <QtCore/qglobal.h>
  12. #if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0)) && YUZU_USE_QT_MULTIMEDIA
  13. #include <QCamera>
  14. #include <QCameraImageCapture>
  15. #include <QCameraInfo>
  16. #endif
  17. #include <QCursor>
  18. #include <QEvent>
  19. #include <QGuiApplication>
  20. #include <QHBoxLayout>
  21. #include <QKeyEvent>
  22. #include <QLayout>
  23. #include <QList>
  24. #include <QMessageBox>
  25. #include <QScreen>
  26. #include <QSize>
  27. #include <QStringLiteral>
  28. #include <QSurfaceFormat>
  29. #include <QTimer>
  30. #include <QWindow>
  31. #include <QtCore/qobjectdefs.h>
  32. #ifdef HAS_OPENGL
  33. #include <QOffscreenSurface>
  34. #include <QOpenGLContext>
  35. #endif
  36. #include "common/microprofile.h"
  37. #include "common/polyfill_thread.h"
  38. #include "common/scm_rev.h"
  39. #include "common/settings.h"
  40. #include "common/settings_input.h"
  41. #include "common/thread.h"
  42. #include "core/core.h"
  43. #include "core/cpu_manager.h"
  44. #include "core/frontend/framebuffer_layout.h"
  45. #include "input_common/drivers/camera.h"
  46. #include "input_common/drivers/keyboard.h"
  47. #include "input_common/drivers/mouse.h"
  48. #include "input_common/drivers/tas_input.h"
  49. #include "input_common/drivers/touch_screen.h"
  50. #include "input_common/main.h"
  51. #include "video_core/gpu.h"
  52. #include "video_core/rasterizer_interface.h"
  53. #include "video_core/renderer_base.h"
  54. #include "yuzu/bootmanager.h"
  55. #include "yuzu/main.h"
  56. #include "yuzu/qt_common.h"
  57. class QObject;
  58. class QPaintEngine;
  59. class QSurface;
  60. EmuThread::EmuThread(Core::System& system) : m_system{system} {}
  61. EmuThread::~EmuThread() = default;
  62. void EmuThread::run() {
  63. const char* name = "EmuControlThread";
  64. MicroProfileOnThreadCreate(name);
  65. Common::SetCurrentThreadName(name);
  66. auto& gpu = m_system.GPU();
  67. auto stop_token = m_stop_source.get_token();
  68. m_system.RegisterHostThread();
  69. // Main process has been loaded. Make the context current to this thread and begin GPU and CPU
  70. // execution.
  71. gpu.ObtainContext();
  72. emit LoadProgress(VideoCore::LoadCallbackStage::Prepare, 0, 0);
  73. if (Settings::values.use_disk_shader_cache.GetValue()) {
  74. m_system.Renderer().ReadRasterizer()->LoadDiskResources(
  75. m_system.GetApplicationProcessProgramID(), stop_token,
  76. [this](VideoCore::LoadCallbackStage stage, std::size_t value, std::size_t total) {
  77. emit LoadProgress(stage, value, total);
  78. });
  79. }
  80. emit LoadProgress(VideoCore::LoadCallbackStage::Complete, 0, 0);
  81. gpu.ReleaseContext();
  82. gpu.Start();
  83. m_system.GetCpuManager().OnGpuReady();
  84. if (m_system.DebuggerEnabled()) {
  85. m_system.InitializeDebugger();
  86. }
  87. while (!stop_token.stop_requested()) {
  88. std::unique_lock lk{m_should_run_mutex};
  89. if (m_should_run) {
  90. m_system.Run();
  91. m_is_running.store(true);
  92. m_is_running.notify_all();
  93. Common::CondvarWait(m_should_run_cv, lk, stop_token, [&] { return !m_should_run; });
  94. } else {
  95. m_system.Pause();
  96. m_is_running.store(false);
  97. m_is_running.notify_all();
  98. EmulationPaused(lk);
  99. Common::CondvarWait(m_should_run_cv, lk, stop_token, [&] { return m_should_run; });
  100. EmulationResumed(lk);
  101. }
  102. }
  103. // Shutdown the main emulated process
  104. m_system.DetachDebugger();
  105. m_system.ShutdownMainProcess();
  106. #if MICROPROFILE_ENABLED
  107. MicroProfileOnThreadExit();
  108. #endif
  109. }
  110. // Unlock while emitting signals so that the main thread can
  111. // continue pumping events.
  112. void EmuThread::EmulationPaused(std::unique_lock<std::mutex>& lk) {
  113. lk.unlock();
  114. emit DebugModeEntered();
  115. lk.lock();
  116. }
  117. void EmuThread::EmulationResumed(std::unique_lock<std::mutex>& lk) {
  118. lk.unlock();
  119. emit DebugModeLeft();
  120. lk.lock();
  121. }
  122. #ifdef HAS_OPENGL
  123. class OpenGLSharedContext : public Core::Frontend::GraphicsContext {
  124. public:
  125. /// Create the original context that should be shared from
  126. explicit OpenGLSharedContext(QSurface* surface_) : surface{surface_} {
  127. QSurfaceFormat format;
  128. format.setVersion(4, 6);
  129. format.setProfile(QSurfaceFormat::CompatibilityProfile);
  130. format.setOption(QSurfaceFormat::FormatOption::DeprecatedFunctions);
  131. if (Settings::values.renderer_debug) {
  132. format.setOption(QSurfaceFormat::FormatOption::DebugContext);
  133. }
  134. // TODO: expose a setting for buffer value (ie default/single/double/triple)
  135. format.setSwapBehavior(QSurfaceFormat::DefaultSwapBehavior);
  136. format.setSwapInterval(0);
  137. context = std::make_unique<QOpenGLContext>();
  138. context->setFormat(format);
  139. if (!context->create()) {
  140. LOG_ERROR(Frontend, "Unable to create main openGL context");
  141. }
  142. }
  143. /// Create the shared contexts for rendering and presentation
  144. explicit OpenGLSharedContext(QOpenGLContext* share_context, QSurface* main_surface = nullptr) {
  145. // disable vsync for any shared contexts
  146. auto format = share_context->format();
  147. const int swap_interval =
  148. Settings::values.vsync_mode.GetValue() == Settings::VSyncMode::Immediate ? 0 : 1;
  149. format.setSwapInterval(main_surface ? swap_interval : 0);
  150. context = std::make_unique<QOpenGLContext>();
  151. context->setShareContext(share_context);
  152. context->setFormat(format);
  153. if (!context->create()) {
  154. LOG_ERROR(Frontend, "Unable to create shared openGL context");
  155. }
  156. if (!main_surface) {
  157. offscreen_surface = std::make_unique<QOffscreenSurface>(nullptr);
  158. offscreen_surface->setFormat(format);
  159. offscreen_surface->create();
  160. surface = offscreen_surface.get();
  161. } else {
  162. surface = main_surface;
  163. }
  164. }
  165. ~OpenGLSharedContext() {
  166. DoneCurrent();
  167. }
  168. void SwapBuffers() override {
  169. context->swapBuffers(surface);
  170. }
  171. void MakeCurrent() override {
  172. // We can't track the current state of the underlying context in this wrapper class because
  173. // Qt may make the underlying context not current for one reason or another. In particular,
  174. // the WebBrowser uses GL, so it seems to conflict if we aren't careful.
  175. // Instead of always just making the context current (which does not have any caching to
  176. // check if the underlying context is already current) we can check for the current context
  177. // in the thread local data by calling `currentContext()` and checking if its ours.
  178. if (QOpenGLContext::currentContext() != context.get()) {
  179. context->makeCurrent(surface);
  180. }
  181. }
  182. void DoneCurrent() override {
  183. context->doneCurrent();
  184. }
  185. QOpenGLContext* GetShareContext() {
  186. return context.get();
  187. }
  188. const QOpenGLContext* GetShareContext() const {
  189. return context.get();
  190. }
  191. private:
  192. // Avoid using Qt parent system here since we might move the QObjects to new threads
  193. // As a note, this means we should avoid using slots/signals with the objects too
  194. std::unique_ptr<QOpenGLContext> context;
  195. std::unique_ptr<QOffscreenSurface> offscreen_surface{};
  196. QSurface* surface;
  197. };
  198. #endif
  199. class DummyContext : public Core::Frontend::GraphicsContext {};
  200. class RenderWidget : public QWidget {
  201. public:
  202. explicit RenderWidget(GRenderWindow* parent) : QWidget(parent), render_window(parent) {
  203. setAttribute(Qt::WA_NativeWindow);
  204. setAttribute(Qt::WA_PaintOnScreen);
  205. if (YuzuQtCommon::GetWindowSystemType() == Core::Frontend::WindowSystemType::Wayland) {
  206. setAttribute(Qt::WA_DontCreateNativeAncestors);
  207. }
  208. }
  209. virtual ~RenderWidget() = default;
  210. QPaintEngine* paintEngine() const override {
  211. return nullptr;
  212. }
  213. private:
  214. GRenderWindow* render_window;
  215. };
  216. struct OpenGLRenderWidget : public RenderWidget {
  217. explicit OpenGLRenderWidget(GRenderWindow* parent) : RenderWidget(parent) {
  218. windowHandle()->setSurfaceType(QWindow::OpenGLSurface);
  219. }
  220. void SetContext(std::unique_ptr<Core::Frontend::GraphicsContext>&& context_) {
  221. context = std::move(context_);
  222. }
  223. private:
  224. std::unique_ptr<Core::Frontend::GraphicsContext> context;
  225. };
  226. struct VulkanRenderWidget : public RenderWidget {
  227. explicit VulkanRenderWidget(GRenderWindow* parent) : RenderWidget(parent) {
  228. windowHandle()->setSurfaceType(QWindow::VulkanSurface);
  229. }
  230. };
  231. struct NullRenderWidget : public RenderWidget {
  232. explicit NullRenderWidget(GRenderWindow* parent) : RenderWidget(parent) {}
  233. };
  234. GRenderWindow::GRenderWindow(GMainWindow* parent, EmuThread* emu_thread_,
  235. std::shared_ptr<InputCommon::InputSubsystem> input_subsystem_,
  236. Core::System& system_)
  237. : QWidget(parent),
  238. emu_thread(emu_thread_), input_subsystem{std::move(input_subsystem_)}, system{system_} {
  239. setWindowTitle(QStringLiteral("yuzu %1 | %2-%3")
  240. .arg(QString::fromUtf8(Common::g_build_name),
  241. QString::fromUtf8(Common::g_scm_branch),
  242. QString::fromUtf8(Common::g_scm_desc)));
  243. setAttribute(Qt::WA_AcceptTouchEvents);
  244. auto* layout = new QHBoxLayout(this);
  245. layout->setContentsMargins(0, 0, 0, 0);
  246. setLayout(layout);
  247. input_subsystem->Initialize();
  248. this->setMouseTracking(true);
  249. strict_context_required = QGuiApplication::platformName() == QStringLiteral("wayland") ||
  250. QGuiApplication::platformName() == QStringLiteral("wayland-egl");
  251. connect(this, &GRenderWindow::FirstFrameDisplayed, parent, &GMainWindow::OnLoadComplete);
  252. connect(this, &GRenderWindow::ExecuteProgramSignal, parent, &GMainWindow::OnExecuteProgram,
  253. Qt::QueuedConnection);
  254. connect(this, &GRenderWindow::ExitSignal, parent, &GMainWindow::OnExit, Qt::QueuedConnection);
  255. connect(this, &GRenderWindow::TasPlaybackStateChanged, parent, &GMainWindow::OnTasStateChanged);
  256. }
  257. void GRenderWindow::ExecuteProgram(std::size_t program_index) {
  258. emit ExecuteProgramSignal(program_index);
  259. }
  260. void GRenderWindow::Exit() {
  261. emit ExitSignal();
  262. }
  263. GRenderWindow::~GRenderWindow() {
  264. input_subsystem->Shutdown();
  265. }
  266. void GRenderWindow::OnFrameDisplayed() {
  267. input_subsystem->GetTas()->UpdateThread();
  268. const InputCommon::TasInput::TasState new_tas_state =
  269. std::get<0>(input_subsystem->GetTas()->GetStatus());
  270. if (!first_frame) {
  271. last_tas_state = new_tas_state;
  272. first_frame = true;
  273. emit FirstFrameDisplayed();
  274. }
  275. if (new_tas_state != last_tas_state) {
  276. last_tas_state = new_tas_state;
  277. emit TasPlaybackStateChanged();
  278. }
  279. }
  280. bool GRenderWindow::IsShown() const {
  281. return !isMinimized();
  282. }
  283. // On Qt 5.0+, this correctly gets the size of the framebuffer (pixels).
  284. //
  285. // Older versions get the window size (density independent pixels),
  286. // and hence, do not support DPI scaling ("retina" displays).
  287. // The result will be a viewport that is smaller than the extent of the window.
  288. void GRenderWindow::OnFramebufferSizeChanged() {
  289. // Screen changes potentially incur a change in screen DPI, hence we should update the
  290. // framebuffer size
  291. const qreal pixel_ratio = windowPixelRatio();
  292. const u32 width = this->width() * pixel_ratio;
  293. const u32 height = this->height() * pixel_ratio;
  294. UpdateCurrentFramebufferLayout(width, height);
  295. }
  296. void GRenderWindow::BackupGeometry() {
  297. geometry = QWidget::saveGeometry();
  298. }
  299. void GRenderWindow::RestoreGeometry() {
  300. // We don't want to back up the geometry here (obviously)
  301. QWidget::restoreGeometry(geometry);
  302. }
  303. void GRenderWindow::restoreGeometry(const QByteArray& geometry_) {
  304. // Make sure users of this class don't need to deal with backing up the geometry themselves
  305. QWidget::restoreGeometry(geometry_);
  306. BackupGeometry();
  307. }
  308. QByteArray GRenderWindow::saveGeometry() {
  309. // If we are a top-level widget, store the current geometry
  310. // otherwise, store the last backup
  311. if (parent() == nullptr) {
  312. return QWidget::saveGeometry();
  313. }
  314. return geometry;
  315. }
  316. qreal GRenderWindow::windowPixelRatio() const {
  317. return devicePixelRatioF();
  318. }
  319. std::pair<u32, u32> GRenderWindow::ScaleTouch(const QPointF& pos) const {
  320. const qreal pixel_ratio = windowPixelRatio();
  321. return {static_cast<u32>(std::max(std::round(pos.x() * pixel_ratio), qreal{0.0})),
  322. static_cast<u32>(std::max(std::round(pos.y() * pixel_ratio), qreal{0.0}))};
  323. }
  324. void GRenderWindow::closeEvent(QCloseEvent* event) {
  325. emit Closed();
  326. QWidget::closeEvent(event);
  327. }
  328. int GRenderWindow::QtKeyToSwitchKey(Qt::Key qt_key) {
  329. static constexpr std::array<std::pair<Qt::Key, Settings::NativeKeyboard::Keys>, 106> key_map = {
  330. std::pair<Qt::Key, Settings::NativeKeyboard::Keys>{Qt::Key_A, Settings::NativeKeyboard::A},
  331. {Qt::Key_A, Settings::NativeKeyboard::A},
  332. {Qt::Key_B, Settings::NativeKeyboard::B},
  333. {Qt::Key_C, Settings::NativeKeyboard::C},
  334. {Qt::Key_D, Settings::NativeKeyboard::D},
  335. {Qt::Key_E, Settings::NativeKeyboard::E},
  336. {Qt::Key_F, Settings::NativeKeyboard::F},
  337. {Qt::Key_G, Settings::NativeKeyboard::G},
  338. {Qt::Key_H, Settings::NativeKeyboard::H},
  339. {Qt::Key_I, Settings::NativeKeyboard::I},
  340. {Qt::Key_J, Settings::NativeKeyboard::J},
  341. {Qt::Key_K, Settings::NativeKeyboard::K},
  342. {Qt::Key_L, Settings::NativeKeyboard::L},
  343. {Qt::Key_M, Settings::NativeKeyboard::M},
  344. {Qt::Key_N, Settings::NativeKeyboard::N},
  345. {Qt::Key_O, Settings::NativeKeyboard::O},
  346. {Qt::Key_P, Settings::NativeKeyboard::P},
  347. {Qt::Key_Q, Settings::NativeKeyboard::Q},
  348. {Qt::Key_R, Settings::NativeKeyboard::R},
  349. {Qt::Key_S, Settings::NativeKeyboard::S},
  350. {Qt::Key_T, Settings::NativeKeyboard::T},
  351. {Qt::Key_U, Settings::NativeKeyboard::U},
  352. {Qt::Key_V, Settings::NativeKeyboard::V},
  353. {Qt::Key_W, Settings::NativeKeyboard::W},
  354. {Qt::Key_X, Settings::NativeKeyboard::X},
  355. {Qt::Key_Y, Settings::NativeKeyboard::Y},
  356. {Qt::Key_Z, Settings::NativeKeyboard::Z},
  357. {Qt::Key_1, Settings::NativeKeyboard::N1},
  358. {Qt::Key_2, Settings::NativeKeyboard::N2},
  359. {Qt::Key_3, Settings::NativeKeyboard::N3},
  360. {Qt::Key_4, Settings::NativeKeyboard::N4},
  361. {Qt::Key_5, Settings::NativeKeyboard::N5},
  362. {Qt::Key_6, Settings::NativeKeyboard::N6},
  363. {Qt::Key_7, Settings::NativeKeyboard::N7},
  364. {Qt::Key_8, Settings::NativeKeyboard::N8},
  365. {Qt::Key_9, Settings::NativeKeyboard::N9},
  366. {Qt::Key_0, Settings::NativeKeyboard::N0},
  367. {Qt::Key_Return, Settings::NativeKeyboard::Return},
  368. {Qt::Key_Escape, Settings::NativeKeyboard::Escape},
  369. {Qt::Key_Backspace, Settings::NativeKeyboard::Backspace},
  370. {Qt::Key_Tab, Settings::NativeKeyboard::Tab},
  371. {Qt::Key_Space, Settings::NativeKeyboard::Space},
  372. {Qt::Key_Minus, Settings::NativeKeyboard::Minus},
  373. {Qt::Key_Plus, Settings::NativeKeyboard::Plus},
  374. {Qt::Key_questiondown, Settings::NativeKeyboard::Plus},
  375. {Qt::Key_BracketLeft, Settings::NativeKeyboard::OpenBracket},
  376. {Qt::Key_BraceLeft, Settings::NativeKeyboard::OpenBracket},
  377. {Qt::Key_BracketRight, Settings::NativeKeyboard::CloseBracket},
  378. {Qt::Key_BraceRight, Settings::NativeKeyboard::CloseBracket},
  379. {Qt::Key_Bar, Settings::NativeKeyboard::Pipe},
  380. {Qt::Key_Dead_Tilde, Settings::NativeKeyboard::Tilde},
  381. {Qt::Key_Ntilde, Settings::NativeKeyboard::Semicolon},
  382. {Qt::Key_Semicolon, Settings::NativeKeyboard::Semicolon},
  383. {Qt::Key_Apostrophe, Settings::NativeKeyboard::Quote},
  384. {Qt::Key_Dead_Grave, Settings::NativeKeyboard::Backquote},
  385. {Qt::Key_Comma, Settings::NativeKeyboard::Comma},
  386. {Qt::Key_Period, Settings::NativeKeyboard::Period},
  387. {Qt::Key_Slash, Settings::NativeKeyboard::Slash},
  388. {Qt::Key_CapsLock, Settings::NativeKeyboard::CapsLockKey},
  389. {Qt::Key_F1, Settings::NativeKeyboard::F1},
  390. {Qt::Key_F2, Settings::NativeKeyboard::F2},
  391. {Qt::Key_F3, Settings::NativeKeyboard::F3},
  392. {Qt::Key_F4, Settings::NativeKeyboard::F4},
  393. {Qt::Key_F5, Settings::NativeKeyboard::F5},
  394. {Qt::Key_F6, Settings::NativeKeyboard::F6},
  395. {Qt::Key_F7, Settings::NativeKeyboard::F7},
  396. {Qt::Key_F8, Settings::NativeKeyboard::F8},
  397. {Qt::Key_F9, Settings::NativeKeyboard::F9},
  398. {Qt::Key_F10, Settings::NativeKeyboard::F10},
  399. {Qt::Key_F11, Settings::NativeKeyboard::F11},
  400. {Qt::Key_F12, Settings::NativeKeyboard::F12},
  401. {Qt::Key_Print, Settings::NativeKeyboard::PrintScreen},
  402. {Qt::Key_ScrollLock, Settings::NativeKeyboard::ScrollLockKey},
  403. {Qt::Key_Pause, Settings::NativeKeyboard::Pause},
  404. {Qt::Key_Insert, Settings::NativeKeyboard::Insert},
  405. {Qt::Key_Home, Settings::NativeKeyboard::Home},
  406. {Qt::Key_PageUp, Settings::NativeKeyboard::PageUp},
  407. {Qt::Key_Delete, Settings::NativeKeyboard::Delete},
  408. {Qt::Key_End, Settings::NativeKeyboard::End},
  409. {Qt::Key_PageDown, Settings::NativeKeyboard::PageDown},
  410. {Qt::Key_Right, Settings::NativeKeyboard::Right},
  411. {Qt::Key_Left, Settings::NativeKeyboard::Left},
  412. {Qt::Key_Down, Settings::NativeKeyboard::Down},
  413. {Qt::Key_Up, Settings::NativeKeyboard::Up},
  414. {Qt::Key_NumLock, Settings::NativeKeyboard::NumLockKey},
  415. // Numpad keys are missing here
  416. {Qt::Key_F13, Settings::NativeKeyboard::F13},
  417. {Qt::Key_F14, Settings::NativeKeyboard::F14},
  418. {Qt::Key_F15, Settings::NativeKeyboard::F15},
  419. {Qt::Key_F16, Settings::NativeKeyboard::F16},
  420. {Qt::Key_F17, Settings::NativeKeyboard::F17},
  421. {Qt::Key_F18, Settings::NativeKeyboard::F18},
  422. {Qt::Key_F19, Settings::NativeKeyboard::F19},
  423. {Qt::Key_F20, Settings::NativeKeyboard::F20},
  424. {Qt::Key_F21, Settings::NativeKeyboard::F21},
  425. {Qt::Key_F22, Settings::NativeKeyboard::F22},
  426. {Qt::Key_F23, Settings::NativeKeyboard::F23},
  427. {Qt::Key_F24, Settings::NativeKeyboard::F24},
  428. // {Qt::..., Settings::NativeKeyboard::KPComma},
  429. // {Qt::..., Settings::NativeKeyboard::Ro},
  430. {Qt::Key_Hiragana_Katakana, Settings::NativeKeyboard::KatakanaHiragana},
  431. {Qt::Key_yen, Settings::NativeKeyboard::Yen},
  432. {Qt::Key_Henkan, Settings::NativeKeyboard::Henkan},
  433. {Qt::Key_Muhenkan, Settings::NativeKeyboard::Muhenkan},
  434. // {Qt::..., Settings::NativeKeyboard::NumPadCommaPc98},
  435. {Qt::Key_Hangul, Settings::NativeKeyboard::HangulEnglish},
  436. {Qt::Key_Hangul_Hanja, Settings::NativeKeyboard::Hanja},
  437. {Qt::Key_Katakana, Settings::NativeKeyboard::KatakanaKey},
  438. {Qt::Key_Hiragana, Settings::NativeKeyboard::HiraganaKey},
  439. {Qt::Key_Zenkaku_Hankaku, Settings::NativeKeyboard::ZenkakuHankaku},
  440. // Modifier keys are handled by the modifier property
  441. };
  442. for (const auto& [qkey, nkey] : key_map) {
  443. if (qt_key == qkey) {
  444. return nkey;
  445. }
  446. }
  447. return Settings::NativeKeyboard::None;
  448. }
  449. int GRenderWindow::QtModifierToSwitchModifier(Qt::KeyboardModifiers qt_modifiers) {
  450. int modifier = 0;
  451. if ((qt_modifiers & Qt::KeyboardModifier::ShiftModifier) != 0) {
  452. modifier |= 1 << Settings::NativeKeyboard::LeftShift;
  453. }
  454. if ((qt_modifiers & Qt::KeyboardModifier::ControlModifier) != 0) {
  455. modifier |= 1 << Settings::NativeKeyboard::LeftControl;
  456. }
  457. if ((qt_modifiers & Qt::KeyboardModifier::AltModifier) != 0) {
  458. modifier |= 1 << Settings::NativeKeyboard::LeftAlt;
  459. }
  460. if ((qt_modifiers & Qt::KeyboardModifier::MetaModifier) != 0) {
  461. modifier |= 1 << Settings::NativeKeyboard::LeftMeta;
  462. }
  463. // TODO: These keys can't be obtained with Qt::KeyboardModifier
  464. // if ((qt_modifiers & 0x10) != 0) {
  465. // modifier |= 1 << Settings::NativeKeyboard::RightShift;
  466. // }
  467. // if ((qt_modifiers & 0x20) != 0) {
  468. // modifier |= 1 << Settings::NativeKeyboard::RightControl;
  469. // }
  470. // if ((qt_modifiers & 0x40) != 0) {
  471. // modifier |= 1 << Settings::NativeKeyboard::RightAlt;
  472. // }
  473. // if ((qt_modifiers & 0x80) != 0) {
  474. // modifier |= 1 << Settings::NativeKeyboard::RightMeta;
  475. // }
  476. // if ((qt_modifiers & 0x100) != 0) {
  477. // modifier |= 1 << Settings::NativeKeyboard::CapsLock;
  478. // }
  479. // if ((qt_modifiers & 0x200) != 0) {
  480. // modifier |= 1 << Settings::NativeKeyboard::NumLock;
  481. // }
  482. // if ((qt_modifiers & ???) != 0) {
  483. // modifier |= 1 << Settings::NativeKeyboard::ScrollLock;
  484. // }
  485. // if ((qt_modifiers & ???) != 0) {
  486. // modifier |= 1 << Settings::NativeKeyboard::Katakana;
  487. // }
  488. // if ((qt_modifiers & ???) != 0) {
  489. // modifier |= 1 << Settings::NativeKeyboard::Hiragana;
  490. // }
  491. return modifier;
  492. }
  493. void GRenderWindow::keyPressEvent(QKeyEvent* event) {
  494. /**
  495. * This feature can be enhanced with the following functions, but they do not provide
  496. * cross-platform behavior.
  497. *
  498. * event->nativeVirtualKey() can distinguish between keys on the numpad.
  499. * event->nativeModifiers() can distinguish between left and right keys and numlock,
  500. * capslock, scroll lock.
  501. */
  502. if (!event->isAutoRepeat()) {
  503. const auto modifier = QtModifierToSwitchModifier(event->modifiers());
  504. const auto key = QtKeyToSwitchKey(Qt::Key(event->key()));
  505. input_subsystem->GetKeyboard()->SetKeyboardModifiers(modifier);
  506. input_subsystem->GetKeyboard()->PressKeyboardKey(key);
  507. // This is used for gamepads that can have any key mapped
  508. input_subsystem->GetKeyboard()->PressKey(event->key());
  509. }
  510. }
  511. void GRenderWindow::keyReleaseEvent(QKeyEvent* event) {
  512. /**
  513. * This feature can be enhanced with the following functions, but they do not provide
  514. * cross-platform behavior.
  515. *
  516. * event->nativeVirtualKey() can distinguish between keys on the numpad.
  517. * event->nativeModifiers() can distinguish between left and right buttons and numlock,
  518. * capslock, scroll lock.
  519. */
  520. if (!event->isAutoRepeat()) {
  521. const auto modifier = QtModifierToSwitchModifier(event->modifiers());
  522. const auto key = QtKeyToSwitchKey(Qt::Key(event->key()));
  523. input_subsystem->GetKeyboard()->SetKeyboardModifiers(modifier);
  524. input_subsystem->GetKeyboard()->ReleaseKeyboardKey(key);
  525. // This is used for gamepads that can have any key mapped
  526. input_subsystem->GetKeyboard()->ReleaseKey(event->key());
  527. }
  528. }
  529. InputCommon::MouseButton GRenderWindow::QtButtonToMouseButton(Qt::MouseButton button) {
  530. switch (button) {
  531. case Qt::LeftButton:
  532. return InputCommon::MouseButton::Left;
  533. case Qt::RightButton:
  534. return InputCommon::MouseButton::Right;
  535. case Qt::MiddleButton:
  536. return InputCommon::MouseButton::Wheel;
  537. case Qt::BackButton:
  538. return InputCommon::MouseButton::Backward;
  539. case Qt::ForwardButton:
  540. return InputCommon::MouseButton::Forward;
  541. case Qt::TaskButton:
  542. return InputCommon::MouseButton::Task;
  543. default:
  544. return InputCommon::MouseButton::Extra;
  545. }
  546. }
  547. void GRenderWindow::mousePressEvent(QMouseEvent* event) {
  548. // Touch input is handled in TouchBeginEvent
  549. if (event->source() == Qt::MouseEventSynthesizedBySystem) {
  550. return;
  551. }
  552. // Qt sometimes returns the parent coordinates. To avoid this we read the global mouse
  553. // coordinates and map them to the current render area
  554. const auto pos = mapFromGlobal(QCursor::pos());
  555. const auto [x, y] = ScaleTouch(pos);
  556. const auto [touch_x, touch_y] = MapToTouchScreen(x, y);
  557. const auto button = QtButtonToMouseButton(event->button());
  558. input_subsystem->GetMouse()->PressMouseButton(button);
  559. input_subsystem->GetMouse()->PressButton(pos.x(), pos.y(), button);
  560. input_subsystem->GetMouse()->PressTouchButton(touch_x, touch_y, button);
  561. emit MouseActivity();
  562. }
  563. void GRenderWindow::mouseMoveEvent(QMouseEvent* event) {
  564. // Touch input is handled in TouchUpdateEvent
  565. if (event->source() == Qt::MouseEventSynthesizedBySystem) {
  566. return;
  567. }
  568. // Qt sometimes returns the parent coordinates. To avoid this we read the global mouse
  569. // coordinates and map them to the current render area
  570. const auto pos = mapFromGlobal(QCursor::pos());
  571. const auto [x, y] = ScaleTouch(pos);
  572. const auto [touch_x, touch_y] = MapToTouchScreen(x, y);
  573. const int center_x = width() / 2;
  574. const int center_y = height() / 2;
  575. input_subsystem->GetMouse()->MouseMove(touch_x, touch_y);
  576. input_subsystem->GetMouse()->TouchMove(touch_x, touch_y);
  577. input_subsystem->GetMouse()->Move(pos.x(), pos.y(), center_x, center_y);
  578. if (Settings::values.mouse_panning && !Settings::values.mouse_enabled) {
  579. QCursor::setPos(mapToGlobal(QPoint{center_x, center_y}));
  580. }
  581. emit MouseActivity();
  582. }
  583. void GRenderWindow::mouseReleaseEvent(QMouseEvent* event) {
  584. // Touch input is handled in TouchEndEvent
  585. if (event->source() == Qt::MouseEventSynthesizedBySystem) {
  586. return;
  587. }
  588. const auto button = QtButtonToMouseButton(event->button());
  589. input_subsystem->GetMouse()->ReleaseButton(button);
  590. }
  591. void GRenderWindow::wheelEvent(QWheelEvent* event) {
  592. const int x = event->angleDelta().x();
  593. const int y = event->angleDelta().y();
  594. input_subsystem->GetMouse()->MouseWheelChange(x, y);
  595. }
  596. void GRenderWindow::TouchBeginEvent(const QTouchEvent* event) {
  597. QList<QTouchEvent::TouchPoint> touch_points = event->touchPoints();
  598. for (const auto& touch_point : touch_points) {
  599. const auto [x, y] = ScaleTouch(touch_point.pos());
  600. const auto [touch_x, touch_y] = MapToTouchScreen(x, y);
  601. input_subsystem->GetTouchScreen()->TouchPressed(touch_x, touch_y, touch_point.id());
  602. }
  603. }
  604. void GRenderWindow::TouchUpdateEvent(const QTouchEvent* event) {
  605. QList<QTouchEvent::TouchPoint> touch_points = event->touchPoints();
  606. input_subsystem->GetTouchScreen()->ClearActiveFlag();
  607. for (const auto& touch_point : touch_points) {
  608. const auto [x, y] = ScaleTouch(touch_point.pos());
  609. const auto [touch_x, touch_y] = MapToTouchScreen(x, y);
  610. input_subsystem->GetTouchScreen()->TouchMoved(touch_x, touch_y, touch_point.id());
  611. }
  612. input_subsystem->GetTouchScreen()->ReleaseInactiveTouch();
  613. }
  614. void GRenderWindow::TouchEndEvent() {
  615. input_subsystem->GetTouchScreen()->ReleaseAllTouch();
  616. }
  617. void GRenderWindow::InitializeCamera() {
  618. #if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0)) && YUZU_USE_QT_MULTIMEDIA
  619. constexpr auto camera_update_ms = std::chrono::milliseconds{50}; // (50ms, 20Hz)
  620. if (!Settings::values.enable_ir_sensor) {
  621. return;
  622. }
  623. bool camera_found = false;
  624. const QList<QCameraInfo> cameras = QCameraInfo::availableCameras();
  625. for (const QCameraInfo& cameraInfo : cameras) {
  626. if (Settings::values.ir_sensor_device.GetValue() == cameraInfo.deviceName().toStdString() ||
  627. Settings::values.ir_sensor_device.GetValue() == "Auto") {
  628. camera = std::make_unique<QCamera>(cameraInfo);
  629. if (!camera->isCaptureModeSupported(QCamera::CaptureMode::CaptureViewfinder) &&
  630. !camera->isCaptureModeSupported(QCamera::CaptureMode::CaptureStillImage)) {
  631. LOG_ERROR(Frontend,
  632. "Camera doesn't support CaptureViewfinder or CaptureStillImage");
  633. continue;
  634. }
  635. camera_found = true;
  636. break;
  637. }
  638. }
  639. if (!camera_found) {
  640. return;
  641. }
  642. camera_capture = std::make_unique<QCameraImageCapture>(camera.get());
  643. if (!camera_capture->isCaptureDestinationSupported(
  644. QCameraImageCapture::CaptureDestination::CaptureToBuffer)) {
  645. LOG_ERROR(Frontend, "Camera doesn't support saving to buffer");
  646. return;
  647. }
  648. const auto camera_width = input_subsystem->GetCamera()->getImageWidth();
  649. const auto camera_height = input_subsystem->GetCamera()->getImageHeight();
  650. camera_data.resize(camera_width * camera_height);
  651. camera_capture->setCaptureDestination(QCameraImageCapture::CaptureDestination::CaptureToBuffer);
  652. connect(camera_capture.get(), &QCameraImageCapture::imageCaptured, this,
  653. &GRenderWindow::OnCameraCapture);
  654. camera->unload();
  655. if (camera->isCaptureModeSupported(QCamera::CaptureMode::CaptureViewfinder)) {
  656. camera->setCaptureMode(QCamera::CaptureViewfinder);
  657. } else if (camera->isCaptureModeSupported(QCamera::CaptureMode::CaptureStillImage)) {
  658. camera->setCaptureMode(QCamera::CaptureStillImage);
  659. }
  660. camera->load();
  661. camera->start();
  662. pending_camera_snapshots = 0;
  663. is_virtual_camera = false;
  664. camera_timer = std::make_unique<QTimer>();
  665. connect(camera_timer.get(), &QTimer::timeout, [this] { RequestCameraCapture(); });
  666. // This timer should be dependent of camera resolution 5ms for every 100 pixels
  667. camera_timer->start(camera_update_ms);
  668. #endif
  669. }
  670. void GRenderWindow::FinalizeCamera() {
  671. #if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0)) && YUZU_USE_QT_MULTIMEDIA
  672. if (camera_timer) {
  673. camera_timer->stop();
  674. }
  675. if (camera) {
  676. camera->unload();
  677. }
  678. #endif
  679. }
  680. void GRenderWindow::RequestCameraCapture() {
  681. #if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0)) && YUZU_USE_QT_MULTIMEDIA
  682. if (!Settings::values.enable_ir_sensor) {
  683. return;
  684. }
  685. // If the camera doesn't capture, test for virtual cameras
  686. if (pending_camera_snapshots > 5) {
  687. is_virtual_camera = true;
  688. }
  689. // Virtual cameras like obs need to reset the camera every capture
  690. if (is_virtual_camera) {
  691. camera->stop();
  692. camera->start();
  693. }
  694. pending_camera_snapshots++;
  695. camera_capture->capture();
  696. #endif
  697. }
  698. void GRenderWindow::OnCameraCapture(int requestId, const QImage& img) {
  699. #if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0)) && YUZU_USE_QT_MULTIMEDIA
  700. // TODO: Capture directly in the format and resolution needed
  701. const auto camera_width = input_subsystem->GetCamera()->getImageWidth();
  702. const auto camera_height = input_subsystem->GetCamera()->getImageHeight();
  703. const auto converted =
  704. img.scaled(static_cast<int>(camera_width), static_cast<int>(camera_height),
  705. Qt::AspectRatioMode::IgnoreAspectRatio,
  706. Qt::TransformationMode::SmoothTransformation)
  707. .mirrored(false, true);
  708. if (camera_data.size() != camera_width * camera_height) {
  709. camera_data.resize(camera_width * camera_height);
  710. }
  711. std::memcpy(camera_data.data(), converted.bits(), camera_width * camera_height * sizeof(u32));
  712. input_subsystem->GetCamera()->SetCameraData(camera_width, camera_height, camera_data);
  713. pending_camera_snapshots = 0;
  714. #endif
  715. }
  716. bool GRenderWindow::event(QEvent* event) {
  717. if (event->type() == QEvent::TouchBegin) {
  718. TouchBeginEvent(static_cast<QTouchEvent*>(event));
  719. return true;
  720. } else if (event->type() == QEvent::TouchUpdate) {
  721. TouchUpdateEvent(static_cast<QTouchEvent*>(event));
  722. return true;
  723. } else if (event->type() == QEvent::TouchEnd || event->type() == QEvent::TouchCancel) {
  724. TouchEndEvent();
  725. return true;
  726. }
  727. return QWidget::event(event);
  728. }
  729. void GRenderWindow::focusOutEvent(QFocusEvent* event) {
  730. QWidget::focusOutEvent(event);
  731. input_subsystem->GetKeyboard()->ReleaseAllKeys();
  732. input_subsystem->GetMouse()->ReleaseAllButtons();
  733. input_subsystem->GetTouchScreen()->ReleaseAllTouch();
  734. }
  735. void GRenderWindow::resizeEvent(QResizeEvent* event) {
  736. QWidget::resizeEvent(event);
  737. OnFramebufferSizeChanged();
  738. }
  739. std::unique_ptr<Core::Frontend::GraphicsContext> GRenderWindow::CreateSharedContext() const {
  740. #ifdef HAS_OPENGL
  741. if (Settings::values.renderer_backend.GetValue() == Settings::RendererBackend::OpenGL) {
  742. auto c = static_cast<OpenGLSharedContext*>(main_context.get());
  743. // Bind the shared contexts to the main surface in case the backend wants to take over
  744. // presentation
  745. return std::make_unique<OpenGLSharedContext>(c->GetShareContext(),
  746. child_widget->windowHandle());
  747. }
  748. #endif
  749. return std::make_unique<DummyContext>();
  750. }
  751. bool GRenderWindow::InitRenderTarget() {
  752. ReleaseRenderTarget();
  753. {
  754. // Create a dummy render widget so that Qt
  755. // places the render window at the correct position.
  756. const RenderWidget dummy_widget{this};
  757. }
  758. first_frame = false;
  759. switch (Settings::values.renderer_backend.GetValue()) {
  760. case Settings::RendererBackend::OpenGL:
  761. if (!InitializeOpenGL()) {
  762. return false;
  763. }
  764. break;
  765. case Settings::RendererBackend::Vulkan:
  766. if (!InitializeVulkan()) {
  767. return false;
  768. }
  769. break;
  770. case Settings::RendererBackend::Null:
  771. InitializeNull();
  772. break;
  773. }
  774. // Update the Window System information with the new render target
  775. window_info = YuzuQtCommon::GetWindowSystemInfo(child_widget->windowHandle());
  776. child_widget->resize(Layout::ScreenUndocked::Width, Layout::ScreenUndocked::Height);
  777. layout()->addWidget(child_widget);
  778. // Reset minimum required size to avoid resizing issues on the main window after restarting.
  779. setMinimumSize(1, 1);
  780. resize(Layout::ScreenUndocked::Width, Layout::ScreenUndocked::Height);
  781. OnMinimalClientAreaChangeRequest(GetActiveConfig().min_client_area_size);
  782. OnFramebufferSizeChanged();
  783. BackupGeometry();
  784. if (Settings::values.renderer_backend.GetValue() == Settings::RendererBackend::OpenGL) {
  785. if (!LoadOpenGL()) {
  786. return false;
  787. }
  788. }
  789. return true;
  790. }
  791. void GRenderWindow::ReleaseRenderTarget() {
  792. if (child_widget) {
  793. layout()->removeWidget(child_widget);
  794. child_widget->deleteLater();
  795. child_widget = nullptr;
  796. }
  797. main_context.reset();
  798. }
  799. void GRenderWindow::CaptureScreenshot(const QString& screenshot_path) {
  800. auto& renderer = system.Renderer();
  801. const f32 res_scale = Settings::values.resolution_info.up_factor;
  802. if (renderer.IsScreenshotPending()) {
  803. LOG_WARNING(Render,
  804. "A screenshot is already requested or in progress, ignoring the request");
  805. return;
  806. }
  807. const Layout::FramebufferLayout layout{Layout::FrameLayoutFromResolutionScale(res_scale)};
  808. screenshot_image = QImage(QSize(layout.width, layout.height), QImage::Format_RGB32);
  809. renderer.RequestScreenshot(
  810. screenshot_image.bits(),
  811. [=, this](bool invert_y) {
  812. const std::string std_screenshot_path = screenshot_path.toStdString();
  813. if (screenshot_image.mirrored(false, invert_y).save(screenshot_path)) {
  814. LOG_INFO(Frontend, "Screenshot saved to \"{}\"", std_screenshot_path);
  815. } else {
  816. LOG_ERROR(Frontend, "Failed to save screenshot to \"{}\"", std_screenshot_path);
  817. }
  818. },
  819. layout);
  820. }
  821. bool GRenderWindow::IsLoadingComplete() const {
  822. return first_frame;
  823. }
  824. void GRenderWindow::OnMinimalClientAreaChangeRequest(std::pair<u32, u32> minimal_size) {
  825. setMinimumSize(minimal_size.first, minimal_size.second);
  826. }
  827. bool GRenderWindow::InitializeOpenGL() {
  828. #ifdef HAS_OPENGL
  829. if (!QOpenGLContext::supportsThreadedOpenGL()) {
  830. QMessageBox::warning(this, tr("OpenGL not available!"),
  831. tr("OpenGL shared contexts are not supported."));
  832. return false;
  833. }
  834. // TODO: One of these flags might be interesting: WA_OpaquePaintEvent, WA_NoBackground,
  835. // WA_DontShowOnScreen, WA_DeleteOnClose
  836. auto child = new OpenGLRenderWidget(this);
  837. child_widget = child;
  838. child_widget->windowHandle()->create();
  839. auto context = std::make_shared<OpenGLSharedContext>(child->windowHandle());
  840. main_context = context;
  841. child->SetContext(
  842. std::make_unique<OpenGLSharedContext>(context->GetShareContext(), child->windowHandle()));
  843. return true;
  844. #else
  845. QMessageBox::warning(this, tr("OpenGL not available!"),
  846. tr("yuzu has not been compiled with OpenGL support."));
  847. return false;
  848. #endif
  849. }
  850. bool GRenderWindow::InitializeVulkan() {
  851. auto child = new VulkanRenderWidget(this);
  852. child_widget = child;
  853. child_widget->windowHandle()->create();
  854. main_context = std::make_unique<DummyContext>();
  855. return true;
  856. }
  857. void GRenderWindow::InitializeNull() {
  858. child_widget = new NullRenderWidget(this);
  859. main_context = std::make_unique<DummyContext>();
  860. }
  861. bool GRenderWindow::LoadOpenGL() {
  862. auto context = CreateSharedContext();
  863. auto scope = context->Acquire();
  864. if (!gladLoadGL()) {
  865. QMessageBox::warning(
  866. this, tr("Error while initializing OpenGL!"),
  867. tr("Your GPU may not support OpenGL, or you do not have the latest graphics driver."));
  868. return false;
  869. }
  870. const QString renderer =
  871. QString::fromUtf8(reinterpret_cast<const char*>(glGetString(GL_RENDERER)));
  872. if (!GLAD_GL_VERSION_4_6) {
  873. LOG_ERROR(Frontend, "GPU does not support OpenGL 4.6: {}", renderer.toStdString());
  874. QMessageBox::warning(this, tr("Error while initializing OpenGL 4.6!"),
  875. tr("Your GPU may not support OpenGL 4.6, or you do not have the "
  876. "latest graphics driver.<br><br>GL Renderer:<br>%1")
  877. .arg(renderer));
  878. return false;
  879. }
  880. QStringList unsupported_gl_extensions = GetUnsupportedGLExtensions();
  881. if (!unsupported_gl_extensions.empty()) {
  882. QMessageBox::warning(
  883. this, tr("Error while initializing OpenGL!"),
  884. tr("Your GPU may not support one or more required OpenGL extensions. Please ensure you "
  885. "have the latest graphics driver.<br><br>GL Renderer:<br>%1<br><br>Unsupported "
  886. "extensions:<br>%2")
  887. .arg(renderer)
  888. .arg(unsupported_gl_extensions.join(QStringLiteral("<br>"))));
  889. return false;
  890. }
  891. return true;
  892. }
  893. QStringList GRenderWindow::GetUnsupportedGLExtensions() const {
  894. QStringList unsupported_ext;
  895. // Extensions required to support some texture formats.
  896. if (!GLAD_GL_EXT_texture_compression_s3tc) {
  897. unsupported_ext.append(QStringLiteral("EXT_texture_compression_s3tc"));
  898. }
  899. if (!GLAD_GL_ARB_texture_compression_rgtc) {
  900. unsupported_ext.append(QStringLiteral("ARB_texture_compression_rgtc"));
  901. }
  902. if (!unsupported_ext.empty()) {
  903. const std::string gl_renderer{reinterpret_cast<const char*>(glGetString(GL_RENDERER))};
  904. LOG_ERROR(Frontend, "GPU does not support all required extensions: {}", gl_renderer);
  905. }
  906. for (const QString& ext : unsupported_ext) {
  907. LOG_ERROR(Frontend, "Unsupported GL extension: {}", ext.toStdString());
  908. }
  909. return unsupported_ext;
  910. }
  911. void GRenderWindow::OnEmulationStarting(EmuThread* emu_thread_) {
  912. emu_thread = emu_thread_;
  913. }
  914. void GRenderWindow::OnEmulationStopping() {
  915. emu_thread = nullptr;
  916. }
  917. void GRenderWindow::showEvent(QShowEvent* event) {
  918. QWidget::showEvent(event);
  919. // windowHandle() is not initialized until the Window is shown, so we connect it here.
  920. connect(windowHandle(), &QWindow::screenChanged, this, &GRenderWindow::OnFramebufferSizeChanged,
  921. Qt::UniqueConnection);
  922. }
  923. bool GRenderWindow::eventFilter(QObject* object, QEvent* event) {
  924. if (event->type() == QEvent::HoverMove) {
  925. if (Settings::values.mouse_panning || Settings::values.mouse_enabled) {
  926. auto* hover_event = static_cast<QMouseEvent*>(event);
  927. mouseMoveEvent(hover_event);
  928. return false;
  929. }
  930. emit MouseActivity();
  931. }
  932. return false;
  933. }