Debian Codegraph @

Source/Core/DolphinNoGUI/PlatformFBDev.cpp

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