PlatformHeadless.cpp 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. // Copyright 2018 Dolphin Emulator Project
  2. // SPDX-License-Identifier: GPL-2.0-or-later
  3. #include <cstdio>
  4. #include <thread>
  5. #include "Core/Core.h"
  6. #include "Core/System.h"
  7. #include "DolphinNoGUI/Platform.h"
  8. namespace
  9. {
  10. class PlatformHeadless : public Platform
  11. {
  12. public:
  13. void SetTitle(const std::string& title) override;
  14. void MainLoop() override;
  15. WindowSystemInfo GetWindowSystemInfo() const override;
  16. };
  17. void PlatformHeadless::SetTitle(const std::string& title)
  18. {
  19. std::fprintf(stdout, "%s\n", title.c_str());
  20. }
  21. void PlatformHeadless::MainLoop()
  22. {
  23. while (m_running.IsSet())
  24. {
  25. UpdateRunningFlag();
  26. Core::HostDispatchJobs(Core::System::GetInstance());
  27. std::this_thread::sleep_for(std::chrono::milliseconds(100));
  28. }
  29. }
  30. WindowSystemInfo PlatformHeadless::GetWindowSystemInfo() const
  31. {
  32. WindowSystemInfo wsi;
  33. wsi.type = WindowSystemType::Headless;
  34. wsi.display_connection = nullptr;
  35. wsi.render_window = nullptr;
  36. wsi.render_surface = nullptr;
  37. return wsi;
  38. }
  39. } // namespace
  40. std::unique_ptr<Platform> Platform::CreateHeadlessPlatform()
  41. {
  42. return std::make_unique<PlatformHeadless>();
  43. }