LCOV - code coverage report
Current view: top level - source/lib/external_libraries - libsdl.cpp (source / functions) Hit Total Coverage
Test: 0 A.D. test coverage report Lines: 1 56 1.8 %
Date: 2023-01-19 00:18:29 Functions: 2 5 40.0 %

          Line data    Source code
       1             : /* Copyright (C) 2022 Wildfire Games.
       2             :  *
       3             :  * Permission is hereby granted, free of charge, to any person obtaining
       4             :  * a copy of this software and associated documentation files (the
       5             :  * "Software"), to deal in the Software without restriction, including
       6             :  * without limitation the rights to use, copy, modify, merge, publish,
       7             :  * distribute, sublicense, and/or sell copies of the Software, and to
       8             :  * permit persons to whom the Software is furnished to do so, subject to
       9             :  * the following conditions:
      10             :  *
      11             :  * The above copyright notice and this permission notice shall be included
      12             :  * in all copies or substantial portions of the Software.
      13             :  *
      14             :  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
      15             :  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
      16             :  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
      17             :  * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
      18             :  * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
      19             :  * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
      20             :  * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
      21             :  */
      22             : 
      23             : #include "precompiled.h"
      24             : 
      25             : #include "libsdl.h"
      26             : 
      27             : #include "lib/debug.h"
      28             : 
      29             : #include <SDL_syswm.h>
      30             : 
      31             : 
      32             : #if defined(SDL_VIDEO_DRIVER_X11) && !CONFIG2_GLES
      33           0 : void* GetX11Display(SDL_Window* window)
      34             : {
      35             :     SDL_SysWMinfo wminfo;
      36           0 :     SDL_VERSION(&wminfo.version);
      37           0 :     const int ret = SDL_GetWindowWMInfo(window, &wminfo);
      38           0 :     if (ret && wminfo.subsystem == SDL_SYSWM_X11)
      39             :     {
      40           0 :         return reinterpret_cast<void*>(wminfo.info.x11.display);
      41             :     }
      42           0 :     return nullptr;
      43             : }
      44             : #endif
      45             : 
      46             : #if defined(SDL_VIDEO_DRIVER_WAYLAND) && !CONFIG2_GLES
      47           0 : void* GetWaylandDisplay(SDL_Window* window)
      48             : {
      49             :     SDL_SysWMinfo wminfo;
      50           0 :     SDL_VERSION(&wminfo.version);
      51           0 :     const int ret = SDL_GetWindowWMInfo(window, &wminfo);
      52           0 :     if (ret && wminfo.subsystem == SDL_SYSWM_WAYLAND)
      53             :     {
      54           0 :         return reinterpret_cast<void*>(wminfo.info.wl.display);
      55             :     }
      56           0 :     return nullptr;
      57             : }
      58             : #endif
      59             : 
      60           0 : const char* GetSDLSubsystem(SDL_Window* window)
      61             : {
      62             :     SDL_SysWMinfo wminfo;
      63             :     // The info structure must be initialized with the SDL version.
      64           0 :     SDL_VERSION(&wminfo.version);
      65             : 
      66           0 :     if (!SDL_GetWindowWMInfo(window, &wminfo))
      67             :     {
      68           0 :         debug_printf("Failed to query SDL WM info: %s", SDL_GetError());
      69           0 :         return nullptr;
      70             :     }
      71             : 
      72           0 :     const char* subsystem = "unknown";
      73           0 :     switch (wminfo.subsystem)
      74             :     {
      75           0 :     case SDL_SYSWM_WAYLAND:
      76           0 :         subsystem = "Wayland";
      77           0 :         break;
      78           0 :     case SDL_SYSWM_X11:
      79           0 :         subsystem = "X11";
      80           0 :         break;
      81           0 :     case SDL_SYSWM_WINDOWS:
      82           0 :         subsystem = "Windows";
      83           0 :         break;
      84           0 :     case SDL_SYSWM_COCOA:
      85           0 :         subsystem = "Cocoa";
      86           0 :         break;
      87           0 :     case SDL_SYSWM_UIKIT:
      88           0 :         subsystem = "UIKit";
      89           0 :         break;
      90           0 :     case SDL_SYSWM_DIRECTFB:
      91           0 :         subsystem = "DirectFB";
      92           0 :         break;
      93           0 :     case SDL_SYSWM_MIR:
      94           0 :         subsystem = "Mir";
      95           0 :         break;
      96             : #if SDL_VERSION_ATLEAST(2, 0, 3)
      97           0 :     case SDL_SYSWM_WINRT:
      98           0 :         subsystem = "WinRT";
      99           0 :         break;
     100             : #endif
     101             : #if SDL_VERSION_ATLEAST(2, 0, 4)
     102           0 :     case SDL_SYSWM_ANDROID:
     103           0 :         subsystem = "Android";
     104           0 :         break;
     105             : #endif
     106             : #if SDL_VERSION_ATLEAST(2, 0, 5)
     107           0 :     case SDL_SYSWM_VIVANTE:
     108           0 :         subsystem = "Vivante";
     109           0 :         break;
     110             : #endif
     111             : #if SDL_VERSION_ATLEAST(2, 0, 6)
     112           0 :     case SDL_SYSWM_OS2:
     113           0 :         subsystem = "OS/2";
     114           0 :         break;
     115             : #endif
     116             : #if SDL_VERSION_ATLEAST(2, 0, 12)
     117             :     case SDL_SYSWM_HAIKU:
     118             :         subsystem = "Haiku";
     119             :         break;
     120             : #endif
     121             : #if SDL_VERSION_ATLEAST(2, 0, 11)
     122             :     default:
     123             :         debug_printf("Unknown platform, please add it to source/lib/external_libraries/libsdl.cpp\n");
     124             : #endif
     125           0 :     case SDL_SYSWM_UNKNOWN:
     126           0 :         break;
     127             :     }
     128             : 
     129           0 :     return subsystem;
     130           3 : }

Generated by: LCOV version 1.13