bootmanager.cpp 40 KB

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