PlatformFBDev.cpp 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. // Copyright 2018 Dolphin Emulator Project
  2. // SPDX-License-Identifier: GPL-2.0-or-later
  3. #include <unistd.h>
  4. #include "DolphinNoGUI/Platform.h"
  5. #include "Common/MsgHandler.h"
  6. #include "Core/ConfigManager.h"
  7. #include "Core/Core.h"
  8. #include "Core/State.h"
  9. #include "Core/System.h"
  10. #include <climits>
  11. #include <cstdio>
  12. #include <thread>
  13. #include <fcntl.h>
  14. #include <linux/fb.h>
  15. #include <linux/kd.h>
  16. #include <linux/vt.h>
  17. #include <sys/ioctl.h>
  18. #include <sys/types.h>
  19. #include <termios.h>
  20. #include <unistd.h>
  21. namespace
  22. {
  23. class PlatformFBDev : public Platform
  24. {
  25. public:
  26. ~PlatformFBDev() override;
  27. bool Init() override;
  28. void SetTitle(const std::string& string) override;
  29. void MainLoop() override;
  30. WindowSystemInfo GetWindowSystemInfo() const override;
  31. private:
  32. bool OpenFramebuffer();
  33. int m_fb_fd = -1;
  34. };
  35. PlatformFBDev::~PlatformFBDev()
  36. {
  37. if (m_fb_fd >= 0)
  38. close(m_fb_fd);
  39. }
  40. bool PlatformFBDev::Init()
  41. {
  42. if (!OpenFramebuffer())
  43. return false;
  44. return true;
  45. }
  46. bool PlatformFBDev::OpenFramebuffer()
  47. {
  48. m_fb_fd = open("/dev/fb0", O_RDWR);
  49. if (m_fb_fd < 0)
  50. {
  51. std::fprintf(stderr, "open(/dev/fb0) failed\n");
  52. return false;
  53. }
  54. return true;
  55. }
  56. void PlatformFBDev::SetTitle(const std::string& string)
  57. {
  58. std::fprintf(stdout, "%s\n", string.c_str());
  59. }
  60. void PlatformFBDev::MainLoop()
  61. {
  62. while (IsRunning())
  63. {
  64. UpdateRunningFlag();
  65. Core::HostDispatchJobs(Core::System::GetInstance());
  66. // TODO: Is this sleep appropriate?
  67. std::this_thread::sleep_for(std::chrono::milliseconds(1));
  68. }
  69. }
  70. WindowSystemInfo PlatformFBDev::GetWindowSystemInfo() const
  71. {
  72. WindowSystemInfo wsi;
  73. wsi.type = WindowSystemType::FBDev;
  74. wsi.display_connection = nullptr; // EGL_DEFAULT_DISPLAY
  75. wsi.render_window = nullptr;
  76. wsi.render_surface = nullptr;
  77. return wsi;
  78. }
  79. } // namespace
  80. std::unique_ptr<Platform> Platform::CreateFBDevPlatform()
  81. {
  82. return std::make_unique<PlatformFBDev>();
  83. }