Fixed bug 4980 - Build fails for SDL_kmsdrm*.c
authorSam Lantinga <slouken@libsdl.org>
Fri, 14 Feb 2020 16:17:17 -0800
changeset 135249761858bd6a3
parent 13523 30bc6f3e1ec6
child 13525 df0f883cc273
Fixed bug 4980 - Build fails for SDL_kmsdrm*.c

Malte Kie├čling

Since https://hg.libsdl.org/SDL/rev/045f218436fe / bug 4966 i cannot build SDL anymore. The error i get is, essentially, caused by -Werror=declaration-after-statement in SDL_kmsdrmvideo.c and SDL_kmsdrmopengles.c
src/video/kmsdrm/SDL_kmsdrmopengles.c
src/video/kmsdrm/SDL_kmsdrmvideo.c
     1.1 --- a/src/video/kmsdrm/SDL_kmsdrmopengles.c	Fri Feb 14 16:15:46 2020 -0800
     1.2 +++ b/src/video/kmsdrm/SDL_kmsdrmopengles.c	Fri Feb 14 16:17:17 2020 -0800
     1.3 @@ -62,7 +62,7 @@
     1.4      SDL_DisplayData *dispdata = (SDL_DisplayData *) SDL_GetDisplayForWindow(window)->driverdata;
     1.5      SDL_VideoData *viddata = ((SDL_VideoData *)_this->driverdata);
     1.6      KMSDRM_FBInfo *fb_info;
     1.7 -    int ret;
     1.8 +    int ret, timeout;
     1.9  
    1.10      /* Recreate the GBM / EGL surfaces if the display mode has changed */
    1.11      if (windata->egl_surface_dirty) {
    1.12 @@ -71,7 +71,7 @@
    1.13  
    1.14      /* Wait for confirmation that the next front buffer has been flipped, at which
    1.15         point the previous front buffer can be released */
    1.16 -    int timeout = 0;
    1.17 +    timeout = 0;
    1.18      if (_this->egl_data->egl_swapinterval == 1) {
    1.19          timeout = -1;
    1.20      }
     2.1 --- a/src/video/kmsdrm/SDL_kmsdrmvideo.c	Fri Feb 14 16:15:46 2020 -0800
     2.2 +++ b/src/video/kmsdrm/SDL_kmsdrmvideo.c	Fri Feb 14 16:17:17 2020 -0800
     2.3 @@ -258,6 +258,9 @@
     2.4  KMSDRM_FBFromBO(_THIS, struct gbm_bo *bo)
     2.5  {
     2.6      SDL_VideoData *viddata = ((SDL_VideoData *)_this->driverdata);
     2.7 +    unsigned w,h;
     2.8 +    int ret;
     2.9 +    Uint32 stride, handle;
    2.10  
    2.11      /* Check for an existing framebuffer */
    2.12      KMSDRM_FBInfo *fb_info = (KMSDRM_FBInfo *)KMSDRM_gbm_bo_get_user_data(bo);
    2.13 @@ -278,11 +281,11 @@
    2.14      fb_info->drm_fd = viddata->drm_fd;
    2.15  
    2.16      /* Create framebuffer object for the buffer */
    2.17 -    unsigned w = KMSDRM_gbm_bo_get_width(bo);
    2.18 -    unsigned h = KMSDRM_gbm_bo_get_height(bo);
    2.19 -    Uint32 stride = KMSDRM_gbm_bo_get_stride(bo);
    2.20 -    Uint32 handle = KMSDRM_gbm_bo_get_handle(bo).u32;
    2.21 -    int ret = KMSDRM_drmModeAddFB(viddata->drm_fd, w, h, 24, 32, stride, handle,
    2.22 +    w = KMSDRM_gbm_bo_get_width(bo);
    2.23 +    h = KMSDRM_gbm_bo_get_height(bo);
    2.24 +    stride = KMSDRM_gbm_bo_get_stride(bo);
    2.25 +    handle = KMSDRM_gbm_bo_get_handle(bo).u32;
    2.26 +    ret = KMSDRM_drmModeAddFB(viddata->drm_fd, w, h, 24, 32, stride, handle,
    2.27                                    &fb_info->fb_id);
    2.28      if (ret) {
    2.29        SDL_free(fb_info);
    2.30 @@ -307,12 +310,12 @@
    2.31  SDL_bool
    2.32  KMSDRM_WaitPageFlip(_THIS, SDL_WindowData *windata, int timeout) {
    2.33      SDL_VideoData *viddata = ((SDL_VideoData *)_this->driverdata);
    2.34 +    drmEventContext ev = {0};
    2.35 +    struct pollfd pfd = {0};
    2.36  
    2.37 -    drmEventContext ev = {0};
    2.38      ev.version = DRM_EVENT_CONTEXT_VERSION;
    2.39      ev.page_flip_handler = KMSDRM_FlipHandler;
    2.40  
    2.41 -    struct pollfd pfd = {0};
    2.42      pfd.fd = viddata->drm_fd;
    2.43      pfd.events = POLLIN;
    2.44  
    2.45 @@ -389,6 +392,7 @@
    2.46      Uint32 height = dispdata->mode.vdisplay;
    2.47      Uint32 surface_fmt = GBM_FORMAT_XRGB8888;
    2.48      Uint32 surface_flags = GBM_BO_USE_SCANOUT | GBM_BO_USE_RENDERING;
    2.49 +    EGLContext egl_context;
    2.50  
    2.51      if (!KMSDRM_gbm_device_is_format_supported(viddata->gbm, surface_fmt, surface_flags)) {
    2.52          SDL_LogWarn(SDL_LOG_CATEGORY_VIDEO, "GBM surface format not supported. Trying anyway.");
    2.53 @@ -396,8 +400,7 @@
    2.54  
    2.55  #if SDL_VIDEO_OPENGL_EGL
    2.56      SDL_EGL_SetRequiredVisualId(_this, surface_fmt);
    2.57 -
    2.58 -    EGLContext egl_context = (EGLContext)SDL_GL_GetCurrentContext();
    2.59 +    egl_context = (EGLContext)SDL_GL_GetCurrentContext();
    2.60  #endif
    2.61  
    2.62      KMSDRM_DestroySurfaces(_this, window);
    2.63 @@ -431,6 +434,8 @@
    2.64      SDL_DisplayData *dispdata = NULL;
    2.65      drmModeRes *resources = NULL;
    2.66      drmModeEncoder *encoder = NULL;
    2.67 +    char devname[32];
    2.68 +    SDL_VideoDisplay display = {0};
    2.69  
    2.70      dispdata = (SDL_DisplayData *) SDL_calloc(1, sizeof(SDL_DisplayData));
    2.71  
    2.72 @@ -441,7 +446,6 @@
    2.73      SDL_LogDebug(SDL_LOG_CATEGORY_VIDEO, "KMSDRM_VideoInit()");
    2.74  
    2.75      /* Open /dev/dri/cardNN */
    2.76 -    char devname[32];
    2.77      SDL_snprintf(devname, sizeof(devname), "/dev/dri/card%d", viddata->devindex);
    2.78  
    2.79      SDL_LogDebug(SDL_LOG_CATEGORY_VIDEO, "Opening device %s", devname);
    2.80 @@ -575,7 +579,7 @@
    2.81      }
    2.82  
    2.83      /* Setup the single display that's available */
    2.84 -    SDL_VideoDisplay display = {0};
    2.85 +
    2.86      display.desktop_mode.w = dispdata->mode.hdisplay;
    2.87      display.desktop_mode.h = dispdata->mode.vdisplay;
    2.88      display.desktop_mode.refresh_rate = dispdata->mode.vrefresh;
    2.89 @@ -685,6 +689,7 @@
    2.90  {
    2.91      SDL_DisplayData *dispdata = display->driverdata;
    2.92      drmModeConnector *conn = dispdata->conn;
    2.93 +    SDL_DisplayMode mode;
    2.94  
    2.95      for (int i = 0; i < conn->count_modes; i++) {
    2.96          SDL_DisplayModeData *modedata = SDL_calloc(1, sizeof(SDL_DisplayModeData));
    2.97 @@ -693,7 +698,6 @@
    2.98            modedata->mode_index = i;
    2.99          }
   2.100  
   2.101 -        SDL_DisplayMode mode;
   2.102          mode.w = conn->modes[i].hdisplay;
   2.103          mode.h = conn->modes[i].vdisplay;
   2.104          mode.refresh_rate = conn->modes[i].vrefresh;
   2.105 @@ -712,12 +716,12 @@
   2.106      SDL_VideoData *viddata = (SDL_VideoData *)_this->driverdata;
   2.107      SDL_DisplayData *dispdata = (SDL_DisplayData *)display->driverdata;
   2.108      SDL_DisplayModeData *modedata = (SDL_DisplayModeData *)mode->driverdata;
   2.109 +    drmModeConnector *conn = dispdata->conn;
   2.110  
   2.111      if (!modedata) {
   2.112          return SDL_SetError("Mode doesn't have an associated index");
   2.113      }
   2.114  
   2.115 -    drmModeConnector *conn = dispdata->conn;
   2.116      dispdata->mode = conn->modes[modedata->mode_index];
   2.117  
   2.118      for (int i = 0; i < viddata->num_windows; i++) {
   2.119 @@ -745,6 +749,8 @@
   2.120  KMSDRM_CreateWindow(_THIS, SDL_Window * window)
   2.121  {
   2.122      SDL_VideoData *viddata = (SDL_VideoData *)_this->driverdata;
   2.123 +    SDL_WindowData *windata;
   2.124 +    SDL_VideoDisplay *display;
   2.125  
   2.126  #if SDL_VIDEO_OPENGL_EGL
   2.127      if (!_this->egl_data) {
   2.128 @@ -755,7 +761,7 @@
   2.129  #endif
   2.130  
   2.131      /* Allocate window internal data */
   2.132 -    SDL_WindowData *windata = (SDL_WindowData *)SDL_calloc(1, sizeof(SDL_WindowData));
   2.133 +    windata = (SDL_WindowData *)SDL_calloc(1, sizeof(SDL_WindowData));
   2.134  
   2.135      if (!windata) {
   2.136          SDL_OutOfMemory();
   2.137 @@ -763,7 +769,7 @@
   2.138      }
   2.139  
   2.140      /* Windows have one size for now */
   2.141 -    SDL_VideoDisplay *display = SDL_GetDisplayForWindow(window);
   2.142 +    display = SDL_GetDisplayForWindow(window);
   2.143      window->w = display->desktop_mode.w;
   2.144      window->h = display->desktop_mode.h;
   2.145  
   2.146 @@ -815,13 +821,13 @@
   2.147  KMSDRM_DestroyWindow(_THIS, SDL_Window * window)
   2.148  {
   2.149      SDL_WindowData *windata = (SDL_WindowData *) window->driverdata;
   2.150 -
   2.151 +    SDL_VideoData *viddata;
   2.152      if (!windata) {
   2.153          return;
   2.154      }
   2.155  
   2.156      /* Remove from the internal window list */
   2.157 -    SDL_VideoData *viddata = windata->viddata;
   2.158 +    viddata = windata->viddata;
   2.159  
   2.160      for (int i = 0; i < viddata->num_windows; i++) {
   2.161          if (viddata->windows[i] == window) {