diff --git a/configure.in b/configure.in index 6fdcf6eae..6c47161d3 100644 --- a/configure.in +++ b/configure.in @@ -1291,12 +1291,11 @@ AC_HELP_STRING([--enable-video-mir], [use Mir video driver [[default=yes]]]), save_CFLAGS="$CFLAGS" CFLAGS="$save_CFLAGS $MIR_CFLAGS" - dnl This will disable Mir if >= v0.24 is not available + dnl This will disable Mir if >= v0.25 is not available AC_TRY_COMPILE([ #include ],[ - MirPointerButton button = mir_pointer_button_primary; - MirPointerConfinementState confined = mir_pointer_unconfined; + MirTouchAction actions = mir_touch_actions ],[ video_mir=yes ]) diff --git a/src/video/mir/SDL_mirevents.c b/src/video/mir/SDL_mirevents.c index 5577a3780..e36986835 100644 --- a/src/video/mir/SDL_mirevents.c +++ b/src/video/mir/SDL_mirevents.c @@ -185,6 +185,8 @@ HandleTouchEvent(MirTouchEvent const* touch, int device_id, SDL_Window* sdl_wind case mir_touch_action_change: HandleTouchMotion(device_id, id, n_x, n_y, pressure); break; + case mir_touch_actions: + break; } } } diff --git a/src/video/mir/SDL_mirframebuffer.c b/src/video/mir/SDL_mirframebuffer.c index 33158732e..775bc0797 100644 --- a/src/video/mir/SDL_mirframebuffer.c +++ b/src/video/mir/SDL_mirframebuffer.c @@ -33,25 +33,6 @@ #include "SDL_mirdyn.h" -static const Uint32 mir_pixel_format_to_sdl_format[] = { - SDL_PIXELFORMAT_UNKNOWN, /* mir_pixel_format_invalid */ - SDL_PIXELFORMAT_ABGR8888, /* mir_pixel_format_abgr_8888 */ - SDL_PIXELFORMAT_BGR888, /* mir_pixel_format_xbgr_8888 */ - SDL_PIXELFORMAT_ARGB8888, /* mir_pixel_format_argb_8888 */ - SDL_PIXELFORMAT_RGB888, /* mir_pixel_format_xrgb_8888 */ - SDL_PIXELFORMAT_BGR24, /* mir_pixel_format_bgr_888 */ - SDL_PIXELFORMAT_RGB24, /* mir_pixel_format_rgb_888 */ - SDL_PIXELFORMAT_RGB565, /* mir_pixel_format_rgb_565 */ - SDL_PIXELFORMAT_RGBA5551, /* mir_pixel_format_rgba_5551 */ - SDL_PIXELFORMAT_RGBA4444 /* mir_pixel_format_rgba_4444 */ -}; - -Uint32 -MIR_GetSDLPixelFormat(MirPixelFormat format) -{ - return mir_pixel_format_to_sdl_format[format]; -} - int MIR_CreateWindowFramebuffer(_THIS, SDL_Window* window, Uint32* format, void** pixels, int* pitch) diff --git a/src/video/mir/SDL_mirsym.h b/src/video/mir/SDL_mirsym.h index 217747f4a..2bd90997c 100644 --- a/src/video/mir/SDL_mirsym.h +++ b/src/video/mir/SDL_mirsym.h @@ -34,7 +34,6 @@ #endif SDL_MIR_MODULE(MIR_CLIENT) -SDL_MIR_SYM(MirDisplayConfiguration*,mir_connection_create_display_config,(MirConnection *connection)) SDL_MIR_SYM(MirSurface *,mir_surface_create_sync,(MirSurfaceSpec* spec)) SDL_MIR_SYM(MirEGLNativeWindowType,mir_buffer_stream_get_egl_native_window,(MirBufferStream *surface)) SDL_MIR_SYM(void,mir_buffer_stream_get_graphics_region,(MirBufferStream *stream, MirGraphicsRegion *graphics_region)) @@ -85,7 +84,6 @@ SDL_MIR_SYM(bool,mir_connection_is_valid,(MirConnection *connection)) SDL_MIR_SYM(void,mir_connection_release,(MirConnection *connection)) SDL_MIR_SYM(MirPixelFormat,mir_connection_get_egl_pixel_format,(MirConnection* connection, void* egldisplay, void* eglconfig)) SDL_MIR_SYM(MirConnection *,mir_connect_sync,(char const *server, char const *app_name)) -SDL_MIR_SYM(void,mir_display_config_destroy,(MirDisplayConfiguration* display_configuration)) SDL_MIR_SYM(char const *,mir_surface_get_error_message,(MirSurface *surface)) SDL_MIR_SYM(bool,mir_surface_is_valid,(MirSurface *surface)) SDL_MIR_SYM(void,mir_surface_release_sync,(MirSurface *surface)) @@ -99,6 +97,24 @@ SDL_MIR_SYM(char const*,mir_connection_get_error_message,(MirConnection* connect SDL_MIR_SYM(MirSurfaceAttrib,mir_surface_event_get_attribute,(MirSurfaceEvent const* surface_event)) SDL_MIR_SYM(int,mir_surface_event_get_attribute_value,(MirSurfaceEvent const* surface_event)) SDL_MIR_SYM(void,mir_wait_for,(MirWaitHandle* handle)) +SDL_MIR_SYM(MirDisplayConfig*,mir_connection_create_display_configuration,(MirConnection* connection)) +SDL_MIR_SYM(void,mir_display_config_release,(MirDisplayConfig* config)) +SDL_MIR_SYM(int,mir_display_config_get_num_outputs,(MirDisplayConfig const* config)) +SDL_MIR_SYM(MirOutput*,mir_display_config_get_mutable_output,(MirDisplayConfig* config, size_t index)) +SDL_MIR_SYM(int,mir_output_get_num_modes,(MirOutput const* output)) +SDL_MIR_SYM(MirPixelFormat,mir_output_get_current_pixel_format,(MirOutput const* output)) +SDL_MIR_SYM(int,mir_output_get_position_x,(MirOutput const* output)) +SDL_MIR_SYM(int,mir_output_get_position_y,(MirOutput const* output)) +SDL_MIR_SYM(bool,mir_output_is_enabled,(MirOutput const* output)) +SDL_MIR_SYM(MirOutputConnectionState,mir_output_get_connection_state,(MirOutput const* output)) +SDL_MIR_SYM(size_t,mir_output_get_preferred_mode_index,(MirOutput const* output)) +SDL_MIR_SYM(MirOutputType,mir_output_get_type,(MirOutput const* output)) +SDL_MIR_SYM(char const*,mir_output_type_name,(MirOutputType type)) +SDL_MIR_SYM(void,mir_output_set_current_mode,(MirOutput* output, MirOutputMode const* mode)) +SDL_MIR_SYM(MirOutputMode const*,mir_output_get_mode,(MirOutput const* output, size_t index)) +SDL_MIR_SYM(int,mir_output_mode_get_width,(MirOutputMode const* mode)) +SDL_MIR_SYM(int,mir_output_mode_get_height,(MirOutputMode const* mode)) +SDL_MIR_SYM(double,mir_output_mode_get_refresh_rate,(MirOutputMode const* mode)) SDL_MIR_SYM_CONST(char const*,mir_omnidirectional_resize_cursor_name) SDL_MIR_SYM_CONST(char const*,mir_busy_cursor_name) diff --git a/src/video/mir/SDL_mirvideo.c b/src/video/mir/SDL_mirvideo.c index 199fbd304..65f6b0327 100644 --- a/src/video/mir/SDL_mirvideo.c +++ b/src/video/mir/SDL_mirvideo.c @@ -39,6 +39,25 @@ #define MIR_DRIVER_NAME "mir" +static const Uint32 mir_pixel_format_to_sdl_format[] = { + SDL_PIXELFORMAT_UNKNOWN, /* mir_pixel_format_invalid */ + SDL_PIXELFORMAT_ABGR8888, /* mir_pixel_format_abgr_8888 */ + SDL_PIXELFORMAT_BGR888, /* mir_pixel_format_xbgr_8888 */ + SDL_PIXELFORMAT_ARGB8888, /* mir_pixel_format_argb_8888 */ + SDL_PIXELFORMAT_RGB888, /* mir_pixel_format_xrgb_8888 */ + SDL_PIXELFORMAT_BGR24, /* mir_pixel_format_bgr_888 */ + SDL_PIXELFORMAT_RGB24, /* mir_pixel_format_rgb_888 */ + SDL_PIXELFORMAT_RGB565, /* mir_pixel_format_rgb_565 */ + SDL_PIXELFORMAT_RGBA5551, /* mir_pixel_format_rgba_5551 */ + SDL_PIXELFORMAT_RGBA4444 /* mir_pixel_format_rgba_4444 */ +}; + +Uint32 +MIR_GetSDLPixelFormat(MirPixelFormat format) +{ + return mir_pixel_format_to_sdl_format[format]; +} + static int MIR_VideoInit(_THIS); @@ -94,7 +113,7 @@ MIR_DeleteDevice(SDL_VideoDevice* device) SDL_MIR_UnloadSymbols(); } -void +static void MIR_PumpEvents(_THIS) { } @@ -206,68 +225,73 @@ VideoBootStrap MIR_bootstrap = { MIR_Available, MIR_CreateDevice }; -static void -MIR_SetCurrentDisplayMode(MirDisplayOutput const* out, SDL_VideoDisplay* display) +static SDL_DisplayMode +MIR_ConvertModeToSDLMode(MirOutputMode const* mode, MirPixelFormat format) { - SDL_DisplayMode mode = { - .format = SDL_PIXELFORMAT_RGB888, - .w = out->modes[out->current_mode].horizontal_resolution, - .h = out->modes[out->current_mode].vertical_resolution, - .refresh_rate = out->modes[out->current_mode].refresh_rate, - .driverdata = NULL + SDL_DisplayMode sdl_mode = { + .format = MIR_GetSDLPixelFormat(format), + .w = MIR_mir_output_mode_get_width(mode), + .h = MIR_mir_output_mode_get_height(mode), + .refresh_rate = MIR_mir_output_mode_get_refresh_rate(mode), + .driverdata = NULL }; - display->desktop_mode = mode; - display->current_mode = mode; + return sdl_mode; } static void -MIR_AddAllModesFromDisplay(MirDisplayOutput const* out, SDL_VideoDisplay* display) +MIR_AddModeToDisplay(SDL_VideoDisplay* display, MirOutputMode const* mode, MirPixelFormat format) { - int n_mode; - for (n_mode = 0; n_mode < out->num_modes; ++n_mode) { - SDL_DisplayMode mode = { - .format = SDL_PIXELFORMAT_RGB888, - .w = out->modes[n_mode].horizontal_resolution, - .h = out->modes[n_mode].vertical_resolution, - .refresh_rate = out->modes[n_mode].refresh_rate, - .driverdata = NULL - }; + SDL_DisplayMode sdl_mode = MIR_ConvertModeToSDLMode(mode, format); + SDL_AddDisplayMode(display, &sdl_mode); +} - SDL_AddDisplayMode(display, &mode); +static void +MIR_InitDisplayFromOutput(_THIS, MirOutput* output) +{ + SDL_VideoDisplay display; + int m; + + MirPixelFormat format = MIR_mir_output_get_current_pixel_format(output); + int num_modes = MIR_mir_output_get_num_modes(output); + SDL_DisplayMode current_mode = MIR_ConvertModeToSDLMode(mir_output_get_current_mode(output), format); + + SDL_zero(display); + + // Unfortunate cast, but SDL_AddVideoDisplay will strdup this pointer so its read-only in this case. + display.name = (char*)MIR_mir_output_type_name(MIR_mir_output_get_type(output)); + + for (m = 0; m < num_modes; m++) { + MirOutputMode const* mode = MIR_mir_output_get_mode(output, m); + MIR_AddModeToDisplay(&display, mode, format); } + + display.desktop_mode = current_mode; + display.current_mode = current_mode; + + display.driverdata = output; + SDL_AddVideoDisplay(&display); } static void MIR_InitDisplays(_THIS) { MIR_Data* mir_data = _this->driverdata; + int num_outputs = MIR_mir_display_config_get_num_outputs(mir_data->display_config); int d; - MirDisplayConfiguration* display_config = MIR_mir_connection_create_display_config(mir_data->connection); + for (d = 0; d < num_outputs; d++) { + MirOutput* output = MIR_mir_display_config_get_mutable_output(mir_data->display_config, d); + SDL_bool enabled = MIR_mir_output_is_enabled(output); + MirOutputConnectionState state = MIR_mir_output_get_connection_state(output); - for (d = 0; d < display_config->num_outputs; d++) { - MirDisplayOutput const* out = display_config->outputs + d; - - SDL_VideoDisplay display; - SDL_zero(display); - - if (out->used && - out->connected && - out->num_modes && - out->current_mode < out->num_modes) { - - MIR_SetCurrentDisplayMode(out, &display); - MIR_AddAllModesFromDisplay(out, &display); - - SDL_AddVideoDisplay(&display); + if (enabled && state == mir_output_connection_state_connected) { + MIR_InitDisplayFromOutput(_this, output); } } - - MIR_mir_display_config_destroy(display_config); } -int +static int MIR_VideoInit(_THIS) { MIR_Data* mir_data = _this->driverdata; @@ -282,17 +306,35 @@ MIR_VideoInit(_THIS) MIR_mir_connection_get_error_message(mir_data->connection)); } + mir_data->display_config = MIR_mir_connection_create_display_configuration(mir_data->connection); + MIR_InitDisplays(_this); MIR_InitMouse(); return 0; } -void +static void +MIR_CleanUpDisplayConfig(_THIS) +{ + MIR_Data* mir_data = _this->driverdata; + int i; + + // SDL_VideoQuit frees the display driverdata, we own it not them + for (i = 0; i < _this->num_displays; ++i) { + _this->displays[i].driverdata = NULL; + } + + MIR_mir_display_config_release(mir_data->display_config); +} + +static void MIR_VideoQuit(_THIS) { MIR_Data* mir_data = _this->driverdata; + MIR_CleanUpDisplayConfig(_this); + MIR_FiniMouse(); MIR_GL_DeleteContext(_this, NULL); @@ -307,40 +349,47 @@ MIR_VideoQuit(_THIS) static int MIR_GetDisplayBounds(_THIS, SDL_VideoDisplay* display, SDL_Rect* rect) { - MIR_Data* mir_data = _this->driverdata; - int d; + MirOutput const* output = display->driverdata; - MirDisplayConfiguration* display_config = MIR_mir_connection_create_display_config(mir_data->connection); - - for (d = 0; d < display_config->num_outputs; d++) { - MirDisplayOutput const* out = display_config->outputs + d; - - if (out->used && - out->connected && - out->num_modes && - out->current_mode < out->num_modes) { - - rect->x = out->position_x; - rect->y = out->position_y; - rect->w = out->modes->horizontal_resolution; - rect->h = out->modes->vertical_resolution; - } - } - - MIR_mir_display_config_destroy(display_config); + rect->x = MIR_mir_output_get_position_x(output); + rect->y = MIR_mir_output_get_position_y(output); + rect->w = display->current_mode.w; + rect->h = display->current_mode.h; return 0; } static void -MIR_GetDisplayModes(_THIS, SDL_VideoDisplay* sdl_display) +MIR_GetDisplayModes(_THIS, SDL_VideoDisplay* display) { } static int -MIR_SetDisplayMode(_THIS, SDL_VideoDisplay* sdl_display, SDL_DisplayMode* mode) +MIR_SetDisplayMode(_THIS, SDL_VideoDisplay* display, SDL_DisplayMode* mode) { - return 0; + int m; + MirOutput* output = display->driverdata; + int num_modes = MIR_mir_output_get_num_modes(output); + Uint32 sdl_format = MIR_GetSDLPixelFormat( + MIR_mir_output_get_current_pixel_format(output)); + + for (m = 0; m < num_modes; m++) { + MirOutputMode const* mir_mode = MIR_mir_output_get_mode(output, m); + int width = MIR_mir_output_mode_get_width(mir_mode); + int height = MIR_mir_output_mode_get_height(mir_mode); + double refresh_rate = MIR_mir_output_mode_get_refresh_rate(mir_mode); + + if (mode->format == sdl_format && + mode->w == width && + mode->h == height && + mode->refresh_rate == refresh_rate) { + + MIR_mir_output_set_current_mode(output, mir_mode); + return 0; + } + } + + return -1; } #endif /* SDL_VIDEO_DRIVER_MIR */ diff --git a/src/video/mir/SDL_mirvideo.h b/src/video/mir/SDL_mirvideo.h index 0824b9e0b..71ef4ecc1 100644 --- a/src/video/mir/SDL_mirvideo.h +++ b/src/video/mir/SDL_mirvideo.h @@ -33,12 +33,16 @@ typedef struct MIR_Window MIR_Window; typedef struct { - MirConnection* connection; - MIR_Window* current_window; - SDL_bool software; - MirPixelFormat pixel_format; + MirConnection* connection; + MirDisplayConfig* display_config; + MIR_Window* current_window; + SDL_bool software; + MirPixelFormat pixel_format; } MIR_Data; +extern Uint32 +MIR_GetSDLPixelFormat(MirPixelFormat format); + #endif /* _SDL_mirvideo_h_ */ /* vi: set ts=4 sw=4 expandtab: */