1 /* RetroArch - A frontend for libretro. 2 * Copyright (c) 2011-2017 - Daniel De Matteis 3 * 4 * RetroArch is free software: you can redistribute it and/or modify it under the terms 5 * of the GNU General Public License as published by the Free Software Found- 6 * ation, either version 3 of the License, or (at your option) any later version. 7 * 8 * RetroArch is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; 9 * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 10 * PURPOSE. See the GNU General Public License for more details. 11 * 12 * You should have received a copy of the GNU General Public License along with RetroArch. 13 * If not, see <http://www.gnu.org/licenses/>. 14 */ 15 16 #ifndef __DRM_COMMON_H 17 #define __DRM_COMMON_H 18 19 #include <stdint.h> 20 #include <stddef.h> 21 22 #include <xf86drm.h> 23 #include <xf86drmMode.h> 24 #include <poll.h> 25 26 #include <boolean.h> 27 #include <retro_common_api.h> 28 #include <retro_inline.h> 29 30 #include "../../retroarch.h" 31 32 RETRO_BEGIN_DECLS 33 34 extern uint32_t g_connector_id; 35 extern int g_drm_fd; 36 extern uint32_t g_crtc_id; 37 38 extern struct pollfd g_drm_fds; 39 40 extern drmModeConnector *g_drm_connector; 41 extern drmModeModeInfo *g_drm_mode; 42 extern drmModeCrtc *g_orig_crtc; 43 44 extern drmEventContext g_drm_evctx; 45 46 float drm_calc_refresh_rate(drmModeModeInfo *mode); 47 48 bool drm_get_encoder(int fd); 49 50 /* Restore the original CRTC. */ 51 void drm_restore_crtc(void); 52 53 bool drm_get_resources(int fd); 54 55 void drm_setup(int fd); 56 57 void drm_free(void); 58 59 bool drm_get_connector(int fd, unsigned monitor_index); 60 61 float drm_get_refresh_rate(void *data); 62 drm_wait_flip(int timeout)63static INLINE bool drm_wait_flip(int timeout) 64 { 65 g_drm_fds.revents = 0; 66 67 if (poll(&g_drm_fds, 1, timeout) < 0) 68 return false; 69 70 if (g_drm_fds.revents & (POLLHUP | POLLERR)) 71 return false; 72 73 if (g_drm_fds.revents & POLLIN) 74 { 75 drmHandleEvent(g_drm_fd, &g_drm_evctx); 76 return true; 77 } 78 79 return false; 80 } 81 82 RETRO_END_DECLS 83 84 #endif 85