src/video/mir/SDL_mirwindow.c
changeset 10089 25fda20d0173
parent 9998 f67cf37e9cd4
child 10095 0897c3accd52
     1.1 --- a/src/video/mir/SDL_mirwindow.c	Sun Feb 21 17:21:29 2016 -0500
     1.2 +++ b/src/video/mir/SDL_mirwindow.c	Sun Feb 21 15:19:35 2016 -0800
     1.3 @@ -46,52 +46,15 @@
     1.4      return 0;
     1.5  }
     1.6  
     1.7 -MirPixelFormat
     1.8 -FindValidPixelFormat(MIR_Data* mir_data)
     1.9 -{
    1.10 -    unsigned int pf_size = 32;
    1.11 -    unsigned int valid_formats;
    1.12 -    unsigned int f;
    1.13 -
    1.14 -    MirPixelFormat formats[pf_size];
    1.15 -    MIR_mir_connection_get_available_surface_formats(mir_data->connection, formats,
    1.16 -                                                 pf_size, &valid_formats);
    1.17 -
    1.18 -    for (f = 0; f < valid_formats; f++) {
    1.19 -        MirPixelFormat cur_pf = formats[f];
    1.20 -
    1.21 -        if (cur_pf == mir_pixel_format_abgr_8888 ||
    1.22 -            cur_pf == mir_pixel_format_xbgr_8888 ||
    1.23 -            cur_pf == mir_pixel_format_argb_8888 ||
    1.24 -            cur_pf == mir_pixel_format_xrgb_8888) {
    1.25 -
    1.26 -            return cur_pf;
    1.27 -        }
    1.28 -    }
    1.29 -
    1.30 -    return mir_pixel_format_invalid;
    1.31 -}
    1.32 -
    1.33  int
    1.34  MIR_CreateWindow(_THIS, SDL_Window* window)
    1.35  {
    1.36      MIR_Window* mir_window;
    1.37      MIR_Data* mir_data;
    1.38 +    MirPixelFormat pixel_format;
    1.39 +    MirBufferUsage buffer_usage;
    1.40  
    1.41 -    MirSurfaceParameters surfaceparm =
    1.42 -    {
    1.43 -        .name = "MirSurface",
    1.44 -        .width = window->w,
    1.45 -        .height = window->h,
    1.46 -        .pixel_format = mir_pixel_format_invalid,
    1.47 -        .buffer_usage = mir_buffer_usage_hardware,
    1.48 -        .output_id = mir_display_output_id_invalid
    1.49 -    };
    1.50 -
    1.51 -    MirEventDelegate delegate = {
    1.52 -        MIR_HandleInput,
    1.53 -        window
    1.54 -    };
    1.55 +    MirSurfaceSpec* spec;
    1.56  
    1.57      mir_window = SDL_calloc(1, sizeof(MIR_Window));
    1.58      if (!mir_window)
    1.59 @@ -100,9 +63,6 @@
    1.60      mir_data = _this->driverdata;
    1.61      window->driverdata = mir_window;
    1.62  
    1.63 -    if (mir_data->software)
    1.64 -        surfaceparm.buffer_usage = mir_buffer_usage_software;
    1.65 -
    1.66      if (window->x == SDL_WINDOWPOS_UNDEFINED)
    1.67          window->x = 0;
    1.68  
    1.69 @@ -112,12 +72,32 @@
    1.70      mir_window->mir_data = mir_data;
    1.71      mir_window->sdl_window = window;
    1.72  
    1.73 -    surfaceparm.pixel_format = FindValidPixelFormat(mir_data);
    1.74 -    if (surfaceparm.pixel_format == mir_pixel_format_invalid) {
    1.75 +    pixel_format = MIR_mir_connection_get_egl_pixel_format(mir_data->connection,
    1.76 +                                                           _this->egl_data->egl_display,
    1.77 +                                                           _this->egl_data->egl_config);
    1.78 +
    1.79 +    mir_data->pixel_format = pixel_format;
    1.80 +    if (pixel_format == mir_pixel_format_invalid) {
    1.81          return SDL_SetError("Failed to find a valid pixel format.");
    1.82      }
    1.83  
    1.84 -    mir_window->surface = MIR_mir_connection_create_surface_sync(mir_data->connection, &surfaceparm);
    1.85 +    buffer_usage = mir_buffer_usage_hardware;
    1.86 +    if (mir_data->software)
    1.87 +        buffer_usage = mir_buffer_usage_software;
    1.88 +
    1.89 +    spec = MIR_mir_connection_create_spec_for_normal_surface(mir_data->connection,
    1.90 +                                                             window->w,
    1.91 +                                                             window->h,
    1.92 +                                                             pixel_format);
    1.93 +
    1.94 +    MIR_mir_surface_spec_set_buffer_usage(spec, buffer_usage);
    1.95 +    MIR_mir_surface_spec_set_name(spec, "Mir surface");
    1.96 +
    1.97 +    mir_window->surface = MIR_mir_surface_create_sync(spec);
    1.98 +    MIR_mir_surface_set_event_handler(mir_window->surface, MIR_HandleEvent, window);
    1.99 +
   1.100 +    MIR_mir_surface_spec_release(spec);
   1.101 +
   1.102      if (!MIR_mir_surface_is_valid(mir_window->surface)) {
   1.103          const char* error = MIR_mir_surface_get_error_message(mir_window->surface);
   1.104          return SDL_SetError("Failed to created a mir surface: %s", error);
   1.105 @@ -125,7 +105,8 @@
   1.106  
   1.107      if (window->flags & SDL_WINDOW_OPENGL) {
   1.108          EGLNativeWindowType egl_native_window =
   1.109 -                        (EGLNativeWindowType)MIR_mir_surface_get_egl_native_window(mir_window->surface);
   1.110 +                        (EGLNativeWindowType)MIR_mir_buffer_stream_get_egl_native_window(
   1.111 +                                                       MIR_mir_surface_get_buffer_stream(mir_window->surface));
   1.112  
   1.113          mir_window->egl_surface = SDL_EGL_CreateSurface(_this, egl_native_window);
   1.114  
   1.115 @@ -138,7 +119,7 @@
   1.116          mir_window->egl_surface = EGL_NO_SURFACE;
   1.117      }
   1.118  
   1.119 -    MIR_mir_surface_set_event_handler(mir_window->surface, &delegate);
   1.120 +    mir_data->current_window = mir_window;
   1.121  
   1.122      return 0;
   1.123  }
   1.124 @@ -146,13 +127,15 @@
   1.125  void
   1.126  MIR_DestroyWindow(_THIS, SDL_Window* window)
   1.127  {
   1.128 -    MIR_Data* mir_data = _this->driverdata;
   1.129 +    MIR_Data* mir_data     = _this->driverdata;
   1.130      MIR_Window* mir_window = window->driverdata;
   1.131  
   1.132      if (mir_data) {
   1.133          SDL_EGL_DestroySurface(_this, mir_window->egl_surface);
   1.134          MIR_mir_surface_release_sync(mir_window->surface);
   1.135  
   1.136 +        mir_data->current_window = NULL;
   1.137 +
   1.138          SDL_free(mir_window);
   1.139      }
   1.140      window->driverdata = NULL;
   1.141 @@ -180,49 +163,166 @@
   1.142                          SDL_VideoDisplay* display,
   1.143                          SDL_bool fullscreen)
   1.144  {
   1.145 +    MIR_Data*   mir_data   = _this->driverdata;
   1.146      MIR_Window* mir_window = window->driverdata;
   1.147 +    MirSurfaceSpec* spec;
   1.148 +    MirSurfaceState state;
   1.149  
   1.150      if (IsSurfaceValid(mir_window) < 0)
   1.151          return;
   1.152  
   1.153      if (fullscreen) {
   1.154 -        MIR_mir_surface_set_state(mir_window->surface, mir_surface_state_fullscreen);
   1.155 +        state = mir_surface_state_fullscreen;
   1.156      } else {
   1.157 -        MIR_mir_surface_set_state(mir_window->surface, mir_surface_state_restored);
   1.158 +        state = mir_surface_state_restored;
   1.159      }
   1.160 +
   1.161 +    spec = MIR_mir_connection_create_spec_for_changes(mir_data->connection);
   1.162 +    MIR_mir_surface_spec_set_state(spec, state);
   1.163 +
   1.164 +    MIR_mir_surface_apply_spec(mir_window->surface, spec);
   1.165 +    MIR_mir_surface_spec_release(spec);
   1.166  }
   1.167  
   1.168  void
   1.169  MIR_MaximizeWindow(_THIS, SDL_Window* window)
   1.170  {
   1.171 +    MIR_Data*   mir_data   = _this->driverdata;
   1.172      MIR_Window* mir_window = window->driverdata;
   1.173 +    MirSurfaceSpec* spec;
   1.174  
   1.175      if (IsSurfaceValid(mir_window) < 0)
   1.176          return;
   1.177  
   1.178 -    MIR_mir_surface_set_state(mir_window->surface, mir_surface_state_maximized);
   1.179 +    spec = MIR_mir_connection_create_spec_for_changes(mir_data->connection);
   1.180 +    MIR_mir_surface_spec_set_state(spec, mir_surface_state_maximized);
   1.181 +
   1.182 +    MIR_mir_surface_apply_spec(mir_window->surface, spec);
   1.183 +    MIR_mir_surface_spec_release(spec);
   1.184  }
   1.185  
   1.186  void
   1.187  MIR_MinimizeWindow(_THIS, SDL_Window* window)
   1.188  {
   1.189 +    MIR_Data*   mir_data   = _this->driverdata;
   1.190      MIR_Window* mir_window = window->driverdata;
   1.191 +    MirSurfaceSpec* spec;
   1.192  
   1.193      if (IsSurfaceValid(mir_window) < 0)
   1.194          return;
   1.195  
   1.196 -    MIR_mir_surface_set_state(mir_window->surface, mir_surface_state_minimized);
   1.197 +    spec = MIR_mir_connection_create_spec_for_changes(mir_data->connection);
   1.198 +    MIR_mir_surface_spec_set_state(spec, mir_surface_state_minimized);
   1.199 +
   1.200 +    MIR_mir_surface_apply_spec(mir_window->surface, spec);
   1.201 +    MIR_mir_surface_spec_release(spec);
   1.202  }
   1.203  
   1.204  void
   1.205  MIR_RestoreWindow(_THIS, SDL_Window * window)
   1.206  {
   1.207 +    MIR_Data*   mir_data   = _this->driverdata;
   1.208      MIR_Window* mir_window = window->driverdata;
   1.209 +    MirSurfaceSpec* spec;
   1.210  
   1.211      if (IsSurfaceValid(mir_window) < 0)
   1.212          return;
   1.213  
   1.214 -    MIR_mir_surface_set_state(mir_window->surface, mir_surface_state_restored);
   1.215 +    spec = MIR_mir_connection_create_spec_for_changes(mir_data->connection);
   1.216 +    MIR_mir_surface_spec_set_state(spec, mir_surface_state_restored);
   1.217 +
   1.218 +    MIR_mir_surface_apply_spec(mir_window->surface, spec);
   1.219 +    MIR_mir_surface_spec_release(spec);
   1.220 +}
   1.221 +
   1.222 +void
   1.223 +MIR_HideWindow(_THIS, SDL_Window* window)
   1.224 +{
   1.225 +    MIR_Data*   mir_data   = _this->driverdata;
   1.226 +    MIR_Window* mir_window = window->driverdata;
   1.227 +    MirSurfaceSpec* spec;
   1.228 +
   1.229 +    if (IsSurfaceValid(mir_window) < 0)
   1.230 +        return;
   1.231 +
   1.232 +    spec = MIR_mir_connection_create_spec_for_changes(mir_data->connection);
   1.233 +    MIR_mir_surface_spec_set_state(spec, mir_surface_state_hidden);
   1.234 +
   1.235 +    MIR_mir_surface_apply_spec(mir_window->surface, spec);
   1.236 +    MIR_mir_surface_spec_release(spec);
   1.237 +}
   1.238 +
   1.239 +void
   1.240 +MIR_SetWindowSize(_THIS, SDL_Window* window)
   1.241 +{
   1.242 +    MIR_Data*   mir_data   = _this->driverdata;
   1.243 +    MIR_Window* mir_window = window->driverdata;
   1.244 +    MirSurfaceSpec* spec;
   1.245 +
   1.246 +    if (IsSurfaceValid(mir_window) < 0)
   1.247 +        return;
   1.248 +
   1.249 +    /* You cannot set the x/y of a mir window! So only update w/h */
   1.250 +    spec = MIR_mir_connection_create_spec_for_changes(mir_data->connection);
   1.251 +    MIR_mir_surface_spec_set_width (spec, window->w);
   1.252 +    MIR_mir_surface_spec_set_height(spec, window->h);
   1.253 +
   1.254 +    MIR_mir_surface_apply_spec(mir_window->surface, spec);
   1.255 +    MIR_mir_surface_spec_release(spec);
   1.256 +}
   1.257 +
   1.258 +void
   1.259 +MIR_SetWindowMinimumSize(_THIS, SDL_Window* window)
   1.260 +{
   1.261 +    MIR_Data*   mir_data   = _this->driverdata;
   1.262 +    MIR_Window* mir_window = window->driverdata;
   1.263 +    MirSurfaceSpec* spec;
   1.264 +
   1.265 +    if (IsSurfaceValid(mir_window) < 0)
   1.266 +        return;
   1.267 +
   1.268 +    spec = MIR_mir_connection_create_spec_for_changes(mir_data->connection);
   1.269 +    MIR_mir_surface_spec_set_min_width (spec, window->min_w);
   1.270 +    MIR_mir_surface_spec_set_min_height(spec, window->min_h);
   1.271 +
   1.272 +    MIR_mir_surface_apply_spec(mir_window->surface, spec);
   1.273 +    MIR_mir_surface_spec_release(spec);
   1.274 +}
   1.275 +
   1.276 +void
   1.277 +MIR_SetWindowMaximumSize(_THIS, SDL_Window* window)
   1.278 +{
   1.279 +    MIR_Data*   mir_data   = _this->driverdata;
   1.280 +    MIR_Window* mir_window = window->driverdata;
   1.281 +    MirSurfaceSpec* spec;
   1.282 +
   1.283 +    if (IsSurfaceValid(mir_window) < 0)
   1.284 +        return;
   1.285 +
   1.286 +    spec = MIR_mir_connection_create_spec_for_changes(mir_data->connection);
   1.287 +    MIR_mir_surface_spec_set_max_width (spec, window->max_w);
   1.288 +    MIR_mir_surface_spec_set_max_height(spec, window->max_h);
   1.289 +
   1.290 +    MIR_mir_surface_apply_spec(mir_window->surface, spec);
   1.291 +    MIR_mir_surface_spec_release(spec);
   1.292 +}
   1.293 +
   1.294 +void
   1.295 +MIR_SetWindowTitle(_THIS, SDL_Window* window)
   1.296 +{
   1.297 +    MIR_Data*   mir_data   = _this->driverdata;
   1.298 +    MIR_Window* mir_window = window->driverdata;
   1.299 +    char const* title = window->title ? window->title : "";
   1.300 +    MirSurfaceSpec* spec;
   1.301 +
   1.302 +    if (IsSurfaceValid(mir_window) < 0)
   1.303 +        return;
   1.304 +
   1.305 +    spec = MIR_mir_connection_create_spec_for_changes(mir_data->connection);
   1.306 +    MIR_mir_surface_spec_set_name(spec, title);
   1.307 +
   1.308 +    MIR_mir_surface_apply_spec(mir_window->surface, spec);
   1.309 +    MIR_mir_surface_spec_release(spec);
   1.310  }
   1.311  
   1.312  #endif /* SDL_VIDEO_DRIVER_MIR */