SDL_mirwindow.c
Go to the documentation of this file.
/*
Simple DirectMedia Layer
Copyright (C) 1997-2016 Sam Lantinga <slouken@libsdl.org>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
*/
/*
Contributed by Brandon Schaefer, <brandon.schaefer@canonical.com>
*/
#include "../../SDL_internal.h"
#if SDL_VIDEO_DRIVER_MIR
#include "../SDL_egl_c.h"
#include "../SDL_sysvideo.h"
#include "SDL_mirevents.h"
#include "SDL_mirwindow.h"
#include "SDL_mirdyn.h"
int
IsSurfaceValid(MIR_Window* mir_window)
{
if (!MIR_mir_surface_is_valid(mir_window->surface)) {
const char* error = MIR_mir_surface_get_error_message(mir_window->surface);
return SDL_SetError("Failed to created a mir surface: %s", error);
}
return 0;
}
int
MIR_CreateWindow(_THIS, SDL_Window* window)
{
MIR_Window* mir_window;
MIR_Data* mir_data;
MirPixelFormat pixel_format;
MirBufferUsage buffer_usage;
MirSurfaceSpec* spec;
mir_window = SDL_calloc(1, sizeof(MIR_Window));
if (!mir_window)
return SDL_OutOfMemory();
mir_data = _this->driverdata;
window->driverdata = mir_window;
if (window->x == SDL_WINDOWPOS_UNDEFINED)
window->x = 0;
if (window->y == SDL_WINDOWPOS_UNDEFINED)
window->y = 0;
mir_window->mir_data = mir_data;
mir_window->sdl_window = window;
pixel_format = MIR_mir_connection_get_egl_pixel_format(mir_data->connection,
_this->egl_data->egl_display,
_this->egl_data->egl_config);
mir_data->pixel_format = pixel_format;
if (pixel_format == mir_pixel_format_invalid) {
return SDL_SetError("Failed to find a valid pixel format.");
}
buffer_usage = mir_buffer_usage_hardware;
if (mir_data->software)
buffer_usage = mir_buffer_usage_software;
spec = MIR_mir_connection_create_spec_for_normal_surface(mir_data->connection,
window->w,
window->h,
pixel_format);
MIR_mir_surface_spec_set_buffer_usage(spec, buffer_usage);
MIR_mir_surface_spec_set_name(spec, "Mir surface");
mir_window->surface = MIR_mir_surface_create_sync(spec);
MIR_mir_surface_set_event_handler(mir_window->surface, MIR_HandleEvent, window);
MIR_mir_surface_spec_release(spec);
if (!MIR_mir_surface_is_valid(mir_window->surface)) {
const char* error = MIR_mir_surface_get_error_message(mir_window->surface);
return SDL_SetError("Failed to created a mir surface: %s", error);
}
if (window->flags & SDL_WINDOW_OPENGL) {
EGLNativeWindowType egl_native_window =
(EGLNativeWindowType)MIR_mir_buffer_stream_get_egl_native_window(
MIR_mir_surface_get_buffer_stream(mir_window->surface));
mir_window->egl_surface = SDL_EGL_CreateSurface(_this, egl_native_window);
if (mir_window->egl_surface == EGL_NO_SURFACE) {
return SDL_SetError("Failed to created a window surface %p",
_this->egl_data->egl_display);
}
}
else {
mir_window->egl_surface = EGL_NO_SURFACE;
}
mir_data->current_window = mir_window;
return 0;
}
void
MIR_DestroyWindow(_THIS, SDL_Window* window)
{
MIR_Data* mir_data = _this->driverdata;
MIR_Window* mir_window = window->driverdata;
if (mir_data) {
SDL_EGL_DestroySurface(_this, mir_window->egl_surface);
MIR_mir_surface_release_sync(mir_window->surface);
mir_data->current_window = NULL;
SDL_free(mir_window);
}
window->driverdata = NULL;
}
SDL_bool
MIR_GetWindowWMInfo(_THIS, SDL_Window* window, SDL_SysWMinfo* info)
{
if (info->version.major == SDL_MAJOR_VERSION &&
info->version.minor == SDL_MINOR_VERSION) {
MIR_Window* mir_window = window->driverdata;
info->subsystem = SDL_SYSWM_MIR;
info->info.mir.connection = mir_window->mir_data->connection;
info->info.mir.surface = mir_window->surface;
return SDL_TRUE;
}
return SDL_FALSE;
}
void
MIR_SetWindowFullscreen(_THIS, SDL_Window* window,
SDL_VideoDisplay* display,
SDL_bool fullscreen)
{
MIR_Data* mir_data = _this->driverdata;
MIR_Window* mir_window = window->driverdata;
MirSurfaceSpec* spec;
MirSurfaceState state;
if (IsSurfaceValid(mir_window) < 0)
return;
if (fullscreen) {
state = mir_surface_state_fullscreen;
} else {
state = mir_surface_state_restored;
}
spec = MIR_mir_connection_create_spec_for_changes(mir_data->connection);
MIR_mir_surface_spec_set_state(spec, state);
MIR_mir_surface_apply_spec(mir_window->surface, spec);
MIR_mir_surface_spec_release(spec);
}
void
MIR_MaximizeWindow(_THIS, SDL_Window* window)
{
MIR_Data* mir_data = _this->driverdata;
MIR_Window* mir_window = window->driverdata;
MirSurfaceSpec* spec;
if (IsSurfaceValid(mir_window) < 0)
return;
spec = MIR_mir_connection_create_spec_for_changes(mir_data->connection);
MIR_mir_surface_spec_set_state(spec, mir_surface_state_maximized);
MIR_mir_surface_apply_spec(mir_window->surface, spec);
MIR_mir_surface_spec_release(spec);
}
void
MIR_MinimizeWindow(_THIS, SDL_Window* window)
{
MIR_Data* mir_data = _this->driverdata;
MIR_Window* mir_window = window->driverdata;
MirSurfaceSpec* spec;
if (IsSurfaceValid(mir_window) < 0)
return;
spec = MIR_mir_connection_create_spec_for_changes(mir_data->connection);
MIR_mir_surface_spec_set_state(spec, mir_surface_state_minimized);
MIR_mir_surface_apply_spec(mir_window->surface, spec);
MIR_mir_surface_spec_release(spec);
}
void
MIR_RestoreWindow(_THIS, SDL_Window * window)
{
MIR_Data* mir_data = _this->driverdata;
MIR_Window* mir_window = window->driverdata;
MirSurfaceSpec* spec;
if (IsSurfaceValid(mir_window) < 0)
return;
spec = MIR_mir_connection_create_spec_for_changes(mir_data->connection);
MIR_mir_surface_spec_set_state(spec, mir_surface_state_restored);
MIR_mir_surface_apply_spec(mir_window->surface, spec);
MIR_mir_surface_spec_release(spec);
}
void
MIR_HideWindow(_THIS, SDL_Window* window)
{
MIR_Data* mir_data = _this->driverdata;
MIR_Window* mir_window = window->driverdata;
MirSurfaceSpec* spec;
if (IsSurfaceValid(mir_window) < 0)
return;
spec = MIR_mir_connection_create_spec_for_changes(mir_data->connection);
MIR_mir_surface_spec_set_state(spec, mir_surface_state_hidden);
MIR_mir_surface_apply_spec(mir_window->surface, spec);
MIR_mir_surface_spec_release(spec);
}
void
MIR_SetWindowSize(_THIS, SDL_Window* window)
{
MIR_Data* mir_data = _this->driverdata;
MIR_Window* mir_window = window->driverdata;
MirSurfaceSpec* spec;
if (IsSurfaceValid(mir_window) < 0)
return;
/* You cannot set the x/y of a mir window! So only update w/h */
spec = MIR_mir_connection_create_spec_for_changes(mir_data->connection);
MIR_mir_surface_spec_set_width (spec, window->w);
MIR_mir_surface_spec_set_height(spec, window->h);
MIR_mir_surface_apply_spec(mir_window->surface, spec);
MIR_mir_surface_spec_release(spec);
}
void
MIR_SetWindowMinimumSize(_THIS, SDL_Window* window)
{
MIR_Data* mir_data = _this->driverdata;
MIR_Window* mir_window = window->driverdata;
MirSurfaceSpec* spec;
if (IsSurfaceValid(mir_window) < 0)
return;
spec = MIR_mir_connection_create_spec_for_changes(mir_data->connection);
MIR_mir_surface_spec_set_min_width (spec, window->min_w);
MIR_mir_surface_spec_set_min_height(spec, window->min_h);
MIR_mir_surface_apply_spec(mir_window->surface, spec);
MIR_mir_surface_spec_release(spec);
}
void
MIR_SetWindowMaximumSize(_THIS, SDL_Window* window)
{
MIR_Data* mir_data = _this->driverdata;
MIR_Window* mir_window = window->driverdata;
MirSurfaceSpec* spec;
if (IsSurfaceValid(mir_window) < 0)
return;
spec = MIR_mir_connection_create_spec_for_changes(mir_data->connection);
MIR_mir_surface_spec_set_max_width (spec, window->max_w);
MIR_mir_surface_spec_set_max_height(spec, window->max_h);
MIR_mir_surface_apply_spec(mir_window->surface, spec);
MIR_mir_surface_spec_release(spec);
}
void
MIR_SetWindowTitle(_THIS, SDL_Window* window)
{
MIR_Data* mir_data = _this->driverdata;
MIR_Window* mir_window = window->driverdata;
char const* title = window->title ? window->title : "";
MirSurfaceSpec* spec;
if (IsSurfaceValid(mir_window) < 0)
return;
spec = MIR_mir_connection_create_spec_for_changes(mir_data->connection);
MIR_mir_surface_spec_set_name(spec, title);
MIR_mir_surface_apply_spec(mir_window->surface, spec);
MIR_mir_surface_spec_release(spec);
}
#endif /* SDL_VIDEO_DRIVER_MIR */
/* vi: set ts=4 sw=4 expandtab: */
SDL_SysWMinfo::mir
struct SDL_SysWMinfo::@18::@21 mir
SDL_MINOR_VERSION
#define SDL_MINOR_VERSION
Definition: SDL_version.h:61
MIR_MinimizeWindow
void MIR_MinimizeWindow(_THIS, SDL_Window *window)
MIR_HideWindow
void MIR_HideWindow(_THIS, SDL_Window *window)
SDL_mirevents.h
SDL_Window::w
int w
Definition: SDL_sysvideo.h:78
SDL_MAJOR_VERSION
#define SDL_MAJOR_VERSION
Definition: SDL_version.h:60
SDL_Window::x
int x
Definition: SDL_sysvideo.h:77
MIR_CreateWindow
int MIR_CreateWindow(_THIS, SDL_Window *window)
window
SDL_Window * window
Definition: testautomation_render.c:26
MIR_Data::pixel_format
MirPixelFormat pixel_format
Definition: SDL_mirvideo.h:39
state
struct xkb_state * state
Definition: SDL_waylandsym.h:97
SDL_VideoDevice::driverdata
void * driverdata
Definition: SDL_sysvideo.h:332
SDL_SysWMinfo::version
SDL_version version
Definition: SDL_syswm.h:183
SDL_version::major
Uint8 major
Definition: SDL_version.h:53
SDL_mirwindow.h
MIR_Window
Definition: SDL_mirwindow.h:34
MIR_DestroyWindow
void MIR_DestroyWindow(_THIS, SDL_Window *window)
SDL_SysWMinfo::subsystem
SDL_SYSWM_TYPE subsystem
Definition: SDL_syswm.h:184
SDL_WINDOWPOS_UNDEFINED
#define SDL_WINDOWPOS_UNDEFINED
Definition: SDL_video.h:120
MIR_Data
Definition: SDL_mirvideo.h:34
_this
static SDL_VideoDevice * _this
Definition: SDL_video.c:114
SDL_bool
SDL_bool
Definition: SDL_stdinc.h:126
spec
SDL_AudioSpec spec
Definition: loopwave.c:35
MIR_Data::connection
MirConnection * connection
Definition: SDL_mirvideo.h:36
MIR_Data::software
SDL_bool software
Definition: SDL_mirvideo.h:38
SDL_calloc
void * SDL_calloc(size_t nmemb, size_t size)
MIR_Data::current_window
MIR_Window * current_window
Definition: SDL_mirvideo.h:37
SDL_SysWMinfo
Definition: SDL_syswm.h:181
_THIS
#define _THIS
Definition: SDL_alsa_audio.h:31
MIR_RestoreWindow
void MIR_RestoreWindow(_THIS, SDL_Window *window)
SDL_free
void SDL_free(void *mem)
MIR_SetWindowFullscreen
void MIR_SetWindowFullscreen(_THIS, SDL_Window *window, SDL_VideoDisplay *display, SDL_bool fullscreen)
SDL_Window::min_w
int min_w
Definition: SDL_sysvideo.h:79
MIR_MaximizeWindow
void MIR_MaximizeWindow(_THIS, SDL_Window *window)
MIR_Window::mir_data
MIR_Data * mir_data
Definition: SDL_mirwindow.h:36
SDL_version::minor
Uint8 minor
Definition: SDL_version.h:54
SDL_Window::title
char * title
Definition: SDL_sysvideo.h:75
SDL_Window::y
int y
Definition: SDL_sysvideo.h:77
SDL_mirdyn.h
SDL_TRUE
Definition: SDL_stdinc.h:129
MIR_SetWindowTitle
void MIR_SetWindowTitle(_THIS, SDL_Window *window)
SDL_VideoDisplay
Definition: SDL_sysvideo.h:120
SDL_Window::h
int h
Definition: SDL_sysvideo.h:78
NULL
#define NULL
Definition: begin_code.h:143
SDL_OutOfMemory
#define SDL_OutOfMemory()
Definition: SDL_error.h:52
MIR_Window::egl_surface
EGLSurface egl_surface
Definition: SDL_mirwindow.h:39
SDL_Window::min_h
int min_h
Definition: SDL_sysvideo.h:79
SDL_SetError
#define SDL_SetError
Definition: SDL_dynapi_overrides.h:36
SDL_Window::max_w
int max_w
Definition: SDL_sysvideo.h:80
SDL_Window
The type used to identify a window.
Definition: SDL_sysvideo.h:71
SDL_FALSE
Definition: SDL_stdinc.h:128
pixel_format
Uint32 pixel_format
Definition: testoverlay2.c:152
SDL_Window::max_h
int max_h
Definition: SDL_sysvideo.h:80
SDL_SysWMinfo::info
union SDL_SysWMinfo::@18 info
SDL_WINDOW_OPENGL
Definition: SDL_video.h:99
SDL_Window::driverdata
void * driverdata
Definition: SDL_sysvideo.h:106
MIR_Window::surface
MirSurface * surface
Definition: SDL_mirwindow.h:38
SDL_Window::flags
Uint32 flags
Definition: SDL_sysvideo.h:81
MIR_GetWindowWMInfo
SDL_bool MIR_GetWindowWMInfo(_THIS, SDL_Window *window, SDL_SysWMinfo *info)
MIR_SetWindowMaximumSize
void MIR_SetWindowMaximumSize(_THIS, SDL_Window *window)
MIR_HandleEvent
void MIR_HandleEvent(MirSurface *surface, MirEvent const *ev, void *context)
SDL_SYSWM_MIR
Definition: SDL_syswm.h:121
MIR_SetWindowMinimumSize
void MIR_SetWindowMinimumSize(_THIS, SDL_Window *window)
MIR_SetWindowSize
void MIR_SetWindowSize(_THIS, SDL_Window *window)
MIR_Window::sdl_window
SDL_Window * sdl_window
Definition: SDL_mirwindow.h:35