bootmanager.cpp 40 KB

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