[Mir] Move to the new MirDisplayConfig API
authorBrandon Schaefer
Wed, 21 Sep 2016 15:57:15 -0700
changeset 10362070fe7c1fc85
parent 10361 de0c0d037e71
child 10363 7a2367601792
[Mir] Move to the new MirDisplayConfig API
configure.in
src/video/mir/SDL_mirevents.c
src/video/mir/SDL_mirframebuffer.c
src/video/mir/SDL_mirsym.h
src/video/mir/SDL_mirvideo.c
src/video/mir/SDL_mirvideo.h
     1.1 --- a/configure.in	Wed Sep 21 23:07:08 2016 +0200
     1.2 +++ b/configure.in	Wed Sep 21 15:57:15 2016 -0700
     1.3 @@ -1291,12 +1291,11 @@
     1.4                  save_CFLAGS="$CFLAGS"
     1.5                  CFLAGS="$save_CFLAGS $MIR_CFLAGS"
     1.6  
     1.7 -                dnl This will disable Mir if >= v0.24 is not available
     1.8 +                dnl This will disable Mir if >= v0.25 is not available
     1.9                  AC_TRY_COMPILE([
    1.10                  #include <mir_toolkit/mir_client_library.h>
    1.11                  ],[
    1.12 -                    MirPointerButton button = mir_pointer_button_primary;
    1.13 -                    MirPointerConfinementState confined = mir_pointer_unconfined;
    1.14 +                    MirTouchAction actions = mir_touch_actions
    1.15                  ],[
    1.16                  video_mir=yes
    1.17                  ])
     2.1 --- a/src/video/mir/SDL_mirevents.c	Wed Sep 21 23:07:08 2016 +0200
     2.2 +++ b/src/video/mir/SDL_mirevents.c	Wed Sep 21 15:57:15 2016 -0700
     2.3 @@ -185,6 +185,8 @@
     2.4              case mir_touch_action_change:
     2.5                  HandleTouchMotion(device_id, id, n_x, n_y, pressure);
     2.6                  break;
     2.7 +            case mir_touch_actions:
     2.8 +                break;
     2.9          }
    2.10      }
    2.11  }
     3.1 --- a/src/video/mir/SDL_mirframebuffer.c	Wed Sep 21 23:07:08 2016 +0200
     3.2 +++ b/src/video/mir/SDL_mirframebuffer.c	Wed Sep 21 15:57:15 2016 -0700
     3.3 @@ -33,25 +33,6 @@
     3.4  
     3.5  #include "SDL_mirdyn.h"
     3.6  
     3.7 -static const Uint32 mir_pixel_format_to_sdl_format[] = {
     3.8 -    SDL_PIXELFORMAT_UNKNOWN,  /* mir_pixel_format_invalid   */
     3.9 -    SDL_PIXELFORMAT_ABGR8888, /* mir_pixel_format_abgr_8888 */
    3.10 -    SDL_PIXELFORMAT_BGR888,   /* mir_pixel_format_xbgr_8888 */
    3.11 -    SDL_PIXELFORMAT_ARGB8888, /* mir_pixel_format_argb_8888 */
    3.12 -    SDL_PIXELFORMAT_RGB888,   /* mir_pixel_format_xrgb_8888 */
    3.13 -    SDL_PIXELFORMAT_BGR24,    /* mir_pixel_format_bgr_888   */
    3.14 -    SDL_PIXELFORMAT_RGB24,    /* mir_pixel_format_rgb_888   */
    3.15 -    SDL_PIXELFORMAT_RGB565,   /* mir_pixel_format_rgb_565   */
    3.16 -    SDL_PIXELFORMAT_RGBA5551, /* mir_pixel_format_rgba_5551 */
    3.17 -    SDL_PIXELFORMAT_RGBA4444  /* mir_pixel_format_rgba_4444 */
    3.18 -};
    3.19 -
    3.20 -Uint32
    3.21 -MIR_GetSDLPixelFormat(MirPixelFormat format)
    3.22 -{
    3.23 -    return mir_pixel_format_to_sdl_format[format];
    3.24 -}
    3.25 -
    3.26  int
    3.27  MIR_CreateWindowFramebuffer(_THIS, SDL_Window* window, Uint32* format,
    3.28                              void** pixels, int* pitch)
     4.1 --- a/src/video/mir/SDL_mirsym.h	Wed Sep 21 23:07:08 2016 +0200
     4.2 +++ b/src/video/mir/SDL_mirsym.h	Wed Sep 21 15:57:15 2016 -0700
     4.3 @@ -34,7 +34,6 @@
     4.4  #endif
     4.5  
     4.6  SDL_MIR_MODULE(MIR_CLIENT)
     4.7 -SDL_MIR_SYM(MirDisplayConfiguration*,mir_connection_create_display_config,(MirConnection *connection))
     4.8  SDL_MIR_SYM(MirSurface *,mir_surface_create_sync,(MirSurfaceSpec* spec))
     4.9  SDL_MIR_SYM(MirEGLNativeWindowType,mir_buffer_stream_get_egl_native_window,(MirBufferStream *surface))
    4.10  SDL_MIR_SYM(void,mir_buffer_stream_get_graphics_region,(MirBufferStream *stream, MirGraphicsRegion *graphics_region))
    4.11 @@ -85,7 +84,6 @@
    4.12  SDL_MIR_SYM(void,mir_connection_release,(MirConnection *connection))
    4.13  SDL_MIR_SYM(MirPixelFormat,mir_connection_get_egl_pixel_format,(MirConnection* connection, void* egldisplay, void* eglconfig))
    4.14  SDL_MIR_SYM(MirConnection *,mir_connect_sync,(char const *server, char const *app_name))
    4.15 -SDL_MIR_SYM(void,mir_display_config_destroy,(MirDisplayConfiguration* display_configuration))
    4.16  SDL_MIR_SYM(char const *,mir_surface_get_error_message,(MirSurface *surface))
    4.17  SDL_MIR_SYM(bool,mir_surface_is_valid,(MirSurface *surface))
    4.18  SDL_MIR_SYM(void,mir_surface_release_sync,(MirSurface *surface))
    4.19 @@ -99,6 +97,24 @@
    4.20  SDL_MIR_SYM(MirSurfaceAttrib,mir_surface_event_get_attribute,(MirSurfaceEvent const* surface_event))
    4.21  SDL_MIR_SYM(int,mir_surface_event_get_attribute_value,(MirSurfaceEvent const* surface_event))
    4.22  SDL_MIR_SYM(void,mir_wait_for,(MirWaitHandle* handle))
    4.23 +SDL_MIR_SYM(MirDisplayConfig*,mir_connection_create_display_configuration,(MirConnection* connection))
    4.24 +SDL_MIR_SYM(void,mir_display_config_release,(MirDisplayConfig* config))
    4.25 +SDL_MIR_SYM(int,mir_display_config_get_num_outputs,(MirDisplayConfig const* config))
    4.26 +SDL_MIR_SYM(MirOutput*,mir_display_config_get_mutable_output,(MirDisplayConfig* config, size_t index))
    4.27 +SDL_MIR_SYM(int,mir_output_get_num_modes,(MirOutput const* output))
    4.28 +SDL_MIR_SYM(MirPixelFormat,mir_output_get_current_pixel_format,(MirOutput const* output))
    4.29 +SDL_MIR_SYM(int,mir_output_get_position_x,(MirOutput const* output))
    4.30 +SDL_MIR_SYM(int,mir_output_get_position_y,(MirOutput const* output))
    4.31 +SDL_MIR_SYM(bool,mir_output_is_enabled,(MirOutput const* output))
    4.32 +SDL_MIR_SYM(MirOutputConnectionState,mir_output_get_connection_state,(MirOutput const* output))
    4.33 +SDL_MIR_SYM(size_t,mir_output_get_preferred_mode_index,(MirOutput const* output))
    4.34 +SDL_MIR_SYM(MirOutputType,mir_output_get_type,(MirOutput const* output))
    4.35 +SDL_MIR_SYM(char const*,mir_output_type_name,(MirOutputType type))
    4.36 +SDL_MIR_SYM(void,mir_output_set_current_mode,(MirOutput* output, MirOutputMode const* mode))
    4.37 +SDL_MIR_SYM(MirOutputMode const*,mir_output_get_mode,(MirOutput const* output, size_t index))
    4.38 +SDL_MIR_SYM(int,mir_output_mode_get_width,(MirOutputMode const* mode))
    4.39 +SDL_MIR_SYM(int,mir_output_mode_get_height,(MirOutputMode const* mode))
    4.40 +SDL_MIR_SYM(double,mir_output_mode_get_refresh_rate,(MirOutputMode const* mode))
    4.41  
    4.42  SDL_MIR_SYM_CONST(char const*,mir_omnidirectional_resize_cursor_name)
    4.43  SDL_MIR_SYM_CONST(char const*,mir_busy_cursor_name)
     5.1 --- a/src/video/mir/SDL_mirvideo.c	Wed Sep 21 23:07:08 2016 +0200
     5.2 +++ b/src/video/mir/SDL_mirvideo.c	Wed Sep 21 15:57:15 2016 -0700
     5.3 @@ -39,6 +39,25 @@
     5.4  
     5.5  #define MIR_DRIVER_NAME "mir"
     5.6  
     5.7 +static const Uint32 mir_pixel_format_to_sdl_format[] = {
     5.8 +    SDL_PIXELFORMAT_UNKNOWN,  /* mir_pixel_format_invalid   */
     5.9 +    SDL_PIXELFORMAT_ABGR8888, /* mir_pixel_format_abgr_8888 */
    5.10 +    SDL_PIXELFORMAT_BGR888,   /* mir_pixel_format_xbgr_8888 */
    5.11 +    SDL_PIXELFORMAT_ARGB8888, /* mir_pixel_format_argb_8888 */
    5.12 +    SDL_PIXELFORMAT_RGB888,   /* mir_pixel_format_xrgb_8888 */
    5.13 +    SDL_PIXELFORMAT_BGR24,    /* mir_pixel_format_bgr_888   */
    5.14 +    SDL_PIXELFORMAT_RGB24,    /* mir_pixel_format_rgb_888   */
    5.15 +    SDL_PIXELFORMAT_RGB565,   /* mir_pixel_format_rgb_565   */
    5.16 +    SDL_PIXELFORMAT_RGBA5551, /* mir_pixel_format_rgba_5551 */
    5.17 +    SDL_PIXELFORMAT_RGBA4444  /* mir_pixel_format_rgba_4444 */
    5.18 +};
    5.19 +
    5.20 +Uint32
    5.21 +MIR_GetSDLPixelFormat(MirPixelFormat format)
    5.22 +{
    5.23 +    return mir_pixel_format_to_sdl_format[format];
    5.24 +}
    5.25 +
    5.26  static int
    5.27  MIR_VideoInit(_THIS);
    5.28  
    5.29 @@ -94,7 +113,7 @@
    5.30      SDL_MIR_UnloadSymbols();
    5.31  }
    5.32  
    5.33 -void
    5.34 +static void
    5.35  MIR_PumpEvents(_THIS)
    5.36  {
    5.37  }
    5.38 @@ -206,68 +225,73 @@
    5.39      MIR_Available, MIR_CreateDevice
    5.40  };
    5.41  
    5.42 -static void
    5.43 -MIR_SetCurrentDisplayMode(MirDisplayOutput const* out, SDL_VideoDisplay* display)
    5.44 +static SDL_DisplayMode
    5.45 +MIR_ConvertModeToSDLMode(MirOutputMode const* mode, MirPixelFormat format)
    5.46  {
    5.47 -    SDL_DisplayMode mode = {
    5.48 -        .format = SDL_PIXELFORMAT_RGB888,
    5.49 -        .w = out->modes[out->current_mode].horizontal_resolution,
    5.50 -        .h = out->modes[out->current_mode].vertical_resolution,
    5.51 -        .refresh_rate = out->modes[out->current_mode].refresh_rate,
    5.52 -        .driverdata = NULL
    5.53 +    SDL_DisplayMode sdl_mode  = {
    5.54 +        .format = MIR_GetSDLPixelFormat(format),
    5.55 +        .w      = MIR_mir_output_mode_get_width(mode),
    5.56 +        .h      = MIR_mir_output_mode_get_height(mode),
    5.57 +        .refresh_rate = MIR_mir_output_mode_get_refresh_rate(mode),
    5.58 +        .driverdata   = NULL
    5.59      };
    5.60  
    5.61 -    display->desktop_mode = mode;
    5.62 -    display->current_mode = mode;
    5.63 +    return sdl_mode;
    5.64 +}
    5.65 +
    5.66 +static void
    5.67 +MIR_AddModeToDisplay(SDL_VideoDisplay* display, MirOutputMode const* mode, MirPixelFormat format)
    5.68 +{
    5.69 +    SDL_DisplayMode sdl_mode = MIR_ConvertModeToSDLMode(mode, format);
    5.70 +    SDL_AddDisplayMode(display, &sdl_mode);
    5.71  }
    5.72  
    5.73  static void
    5.74 -MIR_AddAllModesFromDisplay(MirDisplayOutput const* out, SDL_VideoDisplay* display)
    5.75 +MIR_InitDisplayFromOutput(_THIS, MirOutput* output)
    5.76  {
    5.77 -    int n_mode;
    5.78 -    for (n_mode = 0; n_mode < out->num_modes; ++n_mode) {
    5.79 -        SDL_DisplayMode mode = {
    5.80 -            .format = SDL_PIXELFORMAT_RGB888,
    5.81 -            .w = out->modes[n_mode].horizontal_resolution,
    5.82 -            .h = out->modes[n_mode].vertical_resolution,
    5.83 -            .refresh_rate = out->modes[n_mode].refresh_rate,
    5.84 -            .driverdata = NULL
    5.85 -        };
    5.86 +    SDL_VideoDisplay display;
    5.87 +    int m;
    5.88 +
    5.89 +    MirPixelFormat format = MIR_mir_output_get_current_pixel_format(output);
    5.90 +    int num_modes         = MIR_mir_output_get_num_modes(output);
    5.91 +    SDL_DisplayMode current_mode = MIR_ConvertModeToSDLMode(mir_output_get_current_mode(output), format);
    5.92 +
    5.93 +    SDL_zero(display);
    5.94  
    5.95 -        SDL_AddDisplayMode(display, &mode);
    5.96 +    // Unfortunate cast, but SDL_AddVideoDisplay will strdup this pointer so its read-only in this case.
    5.97 +    display.name = (char*)MIR_mir_output_type_name(MIR_mir_output_get_type(output));
    5.98 +
    5.99 +    for (m = 0; m < num_modes; m++) {
   5.100 +        MirOutputMode const* mode = MIR_mir_output_get_mode(output, m);
   5.101 +        MIR_AddModeToDisplay(&display, mode, format);
   5.102      }
   5.103 +
   5.104 +    display.desktop_mode = current_mode;
   5.105 +    display.current_mode = current_mode;
   5.106 +
   5.107 +    display.driverdata = output;
   5.108 +    SDL_AddVideoDisplay(&display);
   5.109  }
   5.110  
   5.111  static void
   5.112  MIR_InitDisplays(_THIS)
   5.113  {
   5.114      MIR_Data* mir_data = _this->driverdata;
   5.115 +    int num_outputs    = MIR_mir_display_config_get_num_outputs(mir_data->display_config);
   5.116      int d;
   5.117  
   5.118 -    MirDisplayConfiguration* display_config = MIR_mir_connection_create_display_config(mir_data->connection);
   5.119 -
   5.120 -    for (d = 0; d < display_config->num_outputs; d++) {
   5.121 -        MirDisplayOutput const* out = display_config->outputs + d;
   5.122 -
   5.123 -        SDL_VideoDisplay display;
   5.124 -        SDL_zero(display);
   5.125 +    for (d = 0; d < num_outputs; d++) {
   5.126 +        MirOutput* output = MIR_mir_display_config_get_mutable_output(mir_data->display_config, d);
   5.127 +        SDL_bool enabled  = MIR_mir_output_is_enabled(output);
   5.128 +        MirOutputConnectionState state = MIR_mir_output_get_connection_state(output);
   5.129  
   5.130 -        if (out->used &&
   5.131 -            out->connected &&
   5.132 -            out->num_modes &&
   5.133 -            out->current_mode < out->num_modes) {
   5.134 -
   5.135 -            MIR_SetCurrentDisplayMode(out, &display);
   5.136 -            MIR_AddAllModesFromDisplay(out, &display);
   5.137 -
   5.138 -            SDL_AddVideoDisplay(&display);
   5.139 +        if (enabled && state == mir_output_connection_state_connected) {
   5.140 +            MIR_InitDisplayFromOutput(_this, output);
   5.141          }
   5.142      }
   5.143 -
   5.144 -    MIR_mir_display_config_destroy(display_config);
   5.145  }
   5.146  
   5.147 -int
   5.148 +static int
   5.149  MIR_VideoInit(_THIS)
   5.150  {
   5.151      MIR_Data* mir_data = _this->driverdata;
   5.152 @@ -282,17 +306,35 @@
   5.153              MIR_mir_connection_get_error_message(mir_data->connection));
   5.154      }
   5.155  
   5.156 +    mir_data->display_config = MIR_mir_connection_create_display_configuration(mir_data->connection);
   5.157 +
   5.158      MIR_InitDisplays(_this);
   5.159      MIR_InitMouse();
   5.160  
   5.161      return 0;
   5.162  }
   5.163  
   5.164 -void
   5.165 +static void
   5.166 +MIR_CleanUpDisplayConfig(_THIS)
   5.167 +{
   5.168 +    MIR_Data* mir_data = _this->driverdata;
   5.169 +    int i;
   5.170 +
   5.171 +    // SDL_VideoQuit frees the display driverdata, we own it not them
   5.172 +    for (i = 0; i < _this->num_displays; ++i) {
   5.173 +        _this->displays[i].driverdata = NULL;
   5.174 +    }
   5.175 +
   5.176 +    MIR_mir_display_config_release(mir_data->display_config);
   5.177 +}
   5.178 +
   5.179 +static void
   5.180  MIR_VideoQuit(_THIS)
   5.181  {
   5.182      MIR_Data* mir_data = _this->driverdata;
   5.183  
   5.184 +    MIR_CleanUpDisplayConfig(_this);
   5.185 +
   5.186      MIR_FiniMouse();
   5.187  
   5.188      MIR_GL_DeleteContext(_this, NULL);
   5.189 @@ -307,40 +349,47 @@
   5.190  static int
   5.191  MIR_GetDisplayBounds(_THIS, SDL_VideoDisplay* display, SDL_Rect* rect)
   5.192  {
   5.193 -    MIR_Data* mir_data = _this->driverdata;
   5.194 -    int d;
   5.195 -
   5.196 -    MirDisplayConfiguration* display_config = MIR_mir_connection_create_display_config(mir_data->connection);
   5.197 -
   5.198 -    for (d = 0; d < display_config->num_outputs; d++) {
   5.199 -        MirDisplayOutput const* out = display_config->outputs + d;
   5.200 +    MirOutput const* output = display->driverdata;
   5.201  
   5.202 -        if (out->used &&
   5.203 -            out->connected &&
   5.204 -            out->num_modes &&
   5.205 -            out->current_mode < out->num_modes) {
   5.206 -
   5.207 -            rect->x = out->position_x;
   5.208 -            rect->y = out->position_y;
   5.209 -            rect->w = out->modes->horizontal_resolution;
   5.210 -            rect->h = out->modes->vertical_resolution;
   5.211 -        }
   5.212 -    }
   5.213 -
   5.214 -    MIR_mir_display_config_destroy(display_config);
   5.215 +    rect->x = MIR_mir_output_get_position_x(output);
   5.216 +    rect->y = MIR_mir_output_get_position_y(output);
   5.217 +    rect->w = display->current_mode.w;
   5.218 +    rect->h = display->current_mode.h;
   5.219  
   5.220      return 0;
   5.221  }
   5.222  
   5.223  static void
   5.224 -MIR_GetDisplayModes(_THIS, SDL_VideoDisplay* sdl_display)
   5.225 +MIR_GetDisplayModes(_THIS, SDL_VideoDisplay* display)
   5.226  {
   5.227  }
   5.228  
   5.229  static int
   5.230 -MIR_SetDisplayMode(_THIS, SDL_VideoDisplay* sdl_display, SDL_DisplayMode* mode)
   5.231 +MIR_SetDisplayMode(_THIS, SDL_VideoDisplay* display, SDL_DisplayMode* mode)
   5.232  {
   5.233 -    return 0;
   5.234 +    int m;
   5.235 +    MirOutput* output = display->driverdata;
   5.236 +    int num_modes     = MIR_mir_output_get_num_modes(output);
   5.237 +    Uint32 sdl_format = MIR_GetSDLPixelFormat(
   5.238 +                            MIR_mir_output_get_current_pixel_format(output));
   5.239 +
   5.240 +    for (m = 0; m < num_modes; m++) {
   5.241 +        MirOutputMode const* mir_mode = MIR_mir_output_get_mode(output, m);
   5.242 +        int width  = MIR_mir_output_mode_get_width(mir_mode);
   5.243 +        int height = MIR_mir_output_mode_get_height(mir_mode);
   5.244 +        double refresh_rate = MIR_mir_output_mode_get_refresh_rate(mir_mode);
   5.245 +
   5.246 +        if (mode->format == sdl_format &&
   5.247 +            mode->w      == width &&
   5.248 +            mode->h      == height &&
   5.249 +            mode->refresh_rate == refresh_rate) {
   5.250 +
   5.251 +            MIR_mir_output_set_current_mode(output, mir_mode);
   5.252 +            return 0;
   5.253 +        }
   5.254 +    }
   5.255 +
   5.256 +    return -1;
   5.257  }
   5.258  
   5.259  #endif /* SDL_VIDEO_DRIVER_MIR */
     6.1 --- a/src/video/mir/SDL_mirvideo.h	Wed Sep 21 23:07:08 2016 +0200
     6.2 +++ b/src/video/mir/SDL_mirvideo.h	Wed Sep 21 15:57:15 2016 -0700
     6.3 @@ -33,12 +33,16 @@
     6.4  
     6.5  typedef struct
     6.6  {
     6.7 -    MirConnection* connection;
     6.8 -    MIR_Window*    current_window;
     6.9 -    SDL_bool       software;
    6.10 -    MirPixelFormat pixel_format;
    6.11 +    MirConnection*    connection;
    6.12 +    MirDisplayConfig* display_config;
    6.13 +    MIR_Window*       current_window;
    6.14 +    SDL_bool          software;
    6.15 +    MirPixelFormat    pixel_format;
    6.16  } MIR_Data;
    6.17  
    6.18 +extern Uint32
    6.19 +MIR_GetSDLPixelFormat(MirPixelFormat format);
    6.20 +
    6.21  #endif /* _SDL_mirvideo_h_ */
    6.22  
    6.23  /* vi: set ts=4 sw=4 expandtab: */