bootmanager.cpp 39 KB

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