bootmanager.cpp 40 KB

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