rendering_context_driver.cpp 3.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. /**************************************************************************/
  2. /* rendering_context_driver.cpp */
  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. #include "rendering_context_driver.h"
  31. RenderingContextDriver::~RenderingContextDriver() {
  32. }
  33. RenderingContextDriver::SurfaceID RenderingContextDriver::surface_get_from_window(DisplayServer::WindowID p_window) const {
  34. HashMap<DisplayServer::WindowID, SurfaceID>::ConstIterator it = window_surface_map.find(p_window);
  35. if (it != window_surface_map.end()) {
  36. return it->value;
  37. } else {
  38. return SurfaceID();
  39. }
  40. }
  41. Error RenderingContextDriver::window_create(DisplayServer::WindowID p_window, const void *p_platform_data) {
  42. SurfaceID surface = surface_create(p_platform_data);
  43. if (surface != 0) {
  44. window_surface_map[p_window] = surface;
  45. return OK;
  46. } else {
  47. return ERR_CANT_CREATE;
  48. }
  49. }
  50. void RenderingContextDriver::window_set_size(DisplayServer::WindowID p_window, uint32_t p_width, uint32_t p_height) {
  51. SurfaceID surface = surface_get_from_window(p_window);
  52. if (surface) {
  53. surface_set_size(surface, p_width, p_height);
  54. }
  55. }
  56. void RenderingContextDriver::window_set_vsync_mode(DisplayServer::WindowID p_window, DisplayServer::VSyncMode p_vsync_mode) {
  57. SurfaceID surface = surface_get_from_window(p_window);
  58. if (surface) {
  59. surface_set_vsync_mode(surface, p_vsync_mode);
  60. }
  61. }
  62. DisplayServer::VSyncMode RenderingContextDriver::window_get_vsync_mode(DisplayServer::WindowID p_window) const {
  63. SurfaceID surface = surface_get_from_window(p_window);
  64. if (surface) {
  65. return surface_get_vsync_mode(surface);
  66. } else {
  67. return DisplayServer::VSYNC_DISABLED;
  68. }
  69. }
  70. void RenderingContextDriver::window_destroy(DisplayServer::WindowID p_window) {
  71. SurfaceID surface = surface_get_from_window(p_window);
  72. if (surface) {
  73. surface_destroy(surface);
  74. }
  75. window_surface_map.erase(p_window);
  76. }