display_server_headless.h 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. /**************************************************************************/
  2. /* display_server_headless.h */
  3. /**************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /**************************************************************************/
  8. /* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
  9. /* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
  10. /* */
  11. /* Permission is hereby granted, free of charge, to any person obtaining */
  12. /* a copy of this software and associated documentation files (the */
  13. /* "Software"), to deal in the Software without restriction, including */
  14. /* without limitation the rights to use, copy, modify, merge, publish, */
  15. /* distribute, sublicense, and/or sell copies of the Software, and to */
  16. /* permit persons to whom the Software is furnished to do so, subject to */
  17. /* the following conditions: */
  18. /* */
  19. /* The above copyright notice and this permission notice shall be */
  20. /* included in all copies or substantial portions of the Software. */
  21. /* */
  22. /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
  23. /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
  24. /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
  25. /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
  26. /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
  27. /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
  28. /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
  29. /**************************************************************************/
  30. #ifndef DISPLAY_SERVER_HEADLESS_H
  31. #define DISPLAY_SERVER_HEADLESS_H
  32. #include "servers/display_server.h"
  33. #include "servers/rendering/dummy/rasterizer_dummy.h"
  34. class DisplayServerHeadless : public DisplayServer {
  35. private:
  36. friend class DisplayServer;
  37. static Vector<String> get_rendering_drivers_func() {
  38. Vector<String> drivers;
  39. drivers.push_back("dummy");
  40. return drivers;
  41. }
  42. static DisplayServer *create_func(const String &p_rendering_driver, DisplayServer::WindowMode p_mode, DisplayServer::VSyncMode p_vsync_mode, uint32_t p_flags, const Vector2i *p_position, const Vector2i &p_resolution, int p_screen, Error &r_error) {
  43. r_error = OK;
  44. RasterizerDummy::make_current();
  45. return memnew(DisplayServerHeadless());
  46. }
  47. public:
  48. bool has_feature(Feature p_feature) const override { return false; }
  49. String get_name() const override { return "headless"; }
  50. int get_screen_count() const override { return 0; }
  51. int get_primary_screen() const override { return 0; };
  52. Point2i screen_get_position(int p_screen = SCREEN_OF_MAIN_WINDOW) const override { return Point2i(); }
  53. Size2i screen_get_size(int p_screen = SCREEN_OF_MAIN_WINDOW) const override { return Size2i(); }
  54. Rect2i screen_get_usable_rect(int p_screen = SCREEN_OF_MAIN_WINDOW) const override { return Rect2i(); }
  55. int screen_get_dpi(int p_screen = SCREEN_OF_MAIN_WINDOW) const override { return 96; /* 0 might cause issues */ }
  56. float screen_get_scale(int p_screen = SCREEN_OF_MAIN_WINDOW) const override { return 1; }
  57. float screen_get_max_scale() const override { return 1; }
  58. float screen_get_refresh_rate(int p_screen = SCREEN_OF_MAIN_WINDOW) const override { return SCREEN_REFRESH_RATE_FALLBACK; }
  59. Vector<DisplayServer::WindowID> get_window_list() const override { return Vector<DisplayServer::WindowID>(); }
  60. WindowID create_sub_window(WindowMode p_mode, VSyncMode p_vsync_mode, uint32_t p_flags, const Rect2i &p_rect = Rect2i()) override { return 0; }
  61. void show_window(WindowID p_id) override {}
  62. void delete_sub_window(WindowID p_id) override {}
  63. WindowID get_window_at_screen_position(const Point2i &p_position) const override { return 0; }
  64. void window_attach_instance_id(ObjectID p_instance, WindowID p_window = MAIN_WINDOW_ID) override {}
  65. ObjectID window_get_attached_instance_id(WindowID p_window = MAIN_WINDOW_ID) const override { return ObjectID(); }
  66. void window_set_rect_changed_callback(const Callable &p_callable, WindowID p_window = MAIN_WINDOW_ID) override {}
  67. void window_set_window_event_callback(const Callable &p_callable, WindowID p_window = MAIN_WINDOW_ID) override {}
  68. void window_set_input_event_callback(const Callable &p_callable, WindowID p_window = MAIN_WINDOW_ID) override {}
  69. void window_set_input_text_callback(const Callable &p_callable, WindowID p_window = MAIN_WINDOW_ID) override {}
  70. void window_set_drop_files_callback(const Callable &p_callable, WindowID p_window = MAIN_WINDOW_ID) override {}
  71. void window_set_title(const String &p_title, WindowID p_window = MAIN_WINDOW_ID) override {}
  72. void window_set_mouse_passthrough(const Vector<Vector2> &p_region, WindowID p_window = MAIN_WINDOW_ID) override {}
  73. int window_get_current_screen(WindowID p_window = MAIN_WINDOW_ID) const override { return -1; }
  74. void window_set_current_screen(int p_screen, WindowID p_window = MAIN_WINDOW_ID) override {}
  75. Point2i window_get_position(WindowID p_window = MAIN_WINDOW_ID) const override { return Point2i(); }
  76. Point2i window_get_position_with_decorations(WindowID p_window = MAIN_WINDOW_ID) const override { return Point2i(); }
  77. void window_set_position(const Point2i &p_position, WindowID p_window = MAIN_WINDOW_ID) override {}
  78. void window_set_transient(WindowID p_window, WindowID p_parent) override {}
  79. void window_set_max_size(const Size2i p_size, WindowID p_window = MAIN_WINDOW_ID) override {}
  80. Size2i window_get_max_size(WindowID p_window = MAIN_WINDOW_ID) const override { return Size2i(); }
  81. void window_set_min_size(const Size2i p_size, WindowID p_window = MAIN_WINDOW_ID) override {}
  82. Size2i window_get_min_size(WindowID p_window = MAIN_WINDOW_ID) const override { return Size2i(); }
  83. void window_set_size(const Size2i p_size, WindowID p_window = MAIN_WINDOW_ID) override {}
  84. Size2i window_get_size(WindowID p_window = MAIN_WINDOW_ID) const override { return Size2i(); }
  85. Size2i window_get_size_with_decorations(WindowID p_window = MAIN_WINDOW_ID) const override { return Size2i(); }
  86. void window_set_mode(WindowMode p_mode, WindowID p_window = MAIN_WINDOW_ID) override {}
  87. WindowMode window_get_mode(WindowID p_window = MAIN_WINDOW_ID) const override { return WINDOW_MODE_MINIMIZED; }
  88. void window_set_vsync_mode(VSyncMode p_vsync_mode, WindowID p_window = MAIN_WINDOW_ID) override {}
  89. VSyncMode window_get_vsync_mode(WindowID p_window) const override { return VSyncMode::VSYNC_ENABLED; }
  90. bool window_is_maximize_allowed(WindowID p_window = MAIN_WINDOW_ID) const override { return false; }
  91. void window_set_flag(WindowFlags p_flag, bool p_enabled, WindowID p_window = MAIN_WINDOW_ID) override {}
  92. bool window_get_flag(WindowFlags p_flag, WindowID p_window = MAIN_WINDOW_ID) const override { return false; }
  93. void window_request_attention(WindowID p_window = MAIN_WINDOW_ID) override {}
  94. void window_move_to_foreground(WindowID p_window = MAIN_WINDOW_ID) override {}
  95. bool window_can_draw(WindowID p_window = MAIN_WINDOW_ID) const override { return false; }
  96. bool can_any_window_draw() const override { return false; }
  97. void window_set_ime_active(const bool p_active, WindowID p_window = MAIN_WINDOW_ID) override {}
  98. void window_set_ime_position(const Point2i &p_pos, WindowID p_window = MAIN_WINDOW_ID) override {}
  99. void process_events() override {}
  100. void set_icon(const Ref<Image> &p_icon) override {}
  101. DisplayServerHeadless() {}
  102. ~DisplayServerHeadless() {}
  103. };
  104. #endif // DISPLAY_SERVER_HEADLESS_H