RetroArch
drm_common.h
Go to the documentation of this file.
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 "../video_driver.h"
31 
33 
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 
43 extern drmEventContext g_drm_evctx;
44 
45 bool drm_get_encoder(int fd);
46 
47 /* Restore the original CRTC. */
48 void drm_restore_crtc(void);
49 
50 bool drm_get_resources(int fd);
51 
52 void drm_setup(int fd);
53 
54 void drm_free(void);
55 
57 
58 float drm_get_refresh_rate(void *data);
59 
60 static INLINE bool drm_wait_flip(int timeout)
61 {
62  g_drm_fds.revents = 0;
63 
64  if (poll(&g_drm_fds, 1, timeout) < 0)
65  return false;
66 
67  if (g_drm_fds.revents & (POLLHUP | POLLERR))
68  return false;
69 
70  if (g_drm_fds.revents & POLLIN)
71  {
72  drmHandleEvent(g_drm_fd, &g_drm_evctx);
73  return true;
74  }
75 
76  return false;
77 }
78 
80 
81 #endif
float drm_get_refresh_rate(void *data)
Definition: drm_common.c:171
RETRO_BEGIN_DECLS uint32_t g_connector_id
Definition: drm_common.c:26
GLbitfield GLuint64 timeout
Definition: glext.h:7831
uint32_t g_crtc_id
Definition: drm_common.c:28
#define INLINE
Definition: retro_inline.h:35
#define RETRO_BEGIN_DECLS
Definition: retro_common_api.h:41
#define POLLHUP
Definition: network.h:202
struct pollfd g_drm_fds
Definition: drm_common.c:24
void drm_setup(int fd)
Definition: drm_common.c:162
Definition: ibxm.h:9
bool drm_get_encoder(int fd)
Definition: drm_common.c:125
int g_drm_fd
Definition: drm_common.c:27
Definition: video_driver.h:405
Definition: video_driver.h:332
bool drm_get_connector(int fd, video_frame_info_t *video_info)
Definition: drm_common.c:67
void drm_free(void)
Definition: drm_common.c:183
#define RETRO_END_DECLS
Definition: retro_common_api.h:42
#define POLLIN
Definition: network.h:198
drmModeModeInfo * g_drm_mode
Definition: drm_common.c:35
bool drm_get_resources(int fd)
Definition: drm_common.c:55
#define POLLERR
Definition: network.h:201
drmEventContext g_drm_evctx
Definition: drm_common.c:37
unsigned int uint32_t
Definition: stdint.h:126
void drm_restore_crtc(void)
Definition: drm_common.c:40
static INLINE bool drm_wait_flip(int timeout)
Definition: drm_common.h:60
drmModeConnector * g_drm_connector
Definition: drm_common.c:33