src/video/mir/SDL_mirvideo.c
author Ryan C. Gordon <icculus@icculus.org>
Sun, 02 Feb 2014 23:54:10 -0500
changeset 8154 ea6b25de67b6
parent 8153 3e43c73ac79b
child 8157 f5d262613ed2
permissions -rw-r--r--
Cleaned up headers and footers on Mir code.
icculus@8153
     1
/*
icculus@8153
     2
  Simple DirectMedia Layer
icculus@8153
     3
  Copyright (C) 1997-2013 Sam Lantinga <slouken@libsdl.org>
icculus@8153
     4
icculus@8153
     5
  This software is provided 'as-is', without any express or implied
icculus@8153
     6
  warranty.  In no event will the authors be held liable for any damages
icculus@8153
     7
  arising from the use of this software.
icculus@8153
     8
icculus@8153
     9
  Permission is granted to anyone to use this software for any purpose,
icculus@8153
    10
  including commercial applications, and to alter it and redistribute it
icculus@8153
    11
  freely, subject to the following restrictions:
icculus@8153
    12
icculus@8153
    13
  1. The origin of this software must not be misrepresented; you must not
icculus@8153
    14
     claim that you wrote the original software. If you use this software
icculus@8153
    15
     in a product, an acknowledgment in the product documentation would be
icculus@8153
    16
     appreciated but is not required.
icculus@8153
    17
  2. Altered source versions must be plainly marked as such, and must not be
icculus@8153
    18
     misrepresented as being the original software.
icculus@8153
    19
  3. This notice may not be removed or altered from any source distribution.
icculus@8153
    20
*/
icculus@8153
    21
icculus@8153
    22
/*
icculus@8153
    23
  Contributed by Brandon Schaefer, <brandon.schaefer@canonical.com>
icculus@8153
    24
*/
icculus@8153
    25
icculus@8154
    26
#include "../../SDL_internal.h"
icculus@8154
    27
icculus@8154
    28
#if SDL_VIDEO_DRIVER_MIR
icculus@8154
    29
icculus@8153
    30
#include "SDL_video.h"
icculus@8153
    31
icculus@8153
    32
#include "SDL_mirframebuffer.h"
icculus@8153
    33
#include "SDL_mirmouse.h"
icculus@8153
    34
#include "SDL_miropengl.h"
icculus@8153
    35
#include "SDL_mirvideo.h"
icculus@8153
    36
#include "SDL_mirwindow.h"
icculus@8153
    37
icculus@8153
    38
#define MIR_DRIVER_NAME "mir"
icculus@8153
    39
icculus@8153
    40
static int
icculus@8153
    41
MIR_VideoInit(_THIS);
icculus@8153
    42
icculus@8153
    43
static void
icculus@8153
    44
MIR_VideoQuit(_THIS);
icculus@8153
    45
icculus@8153
    46
static int
icculus@8153
    47
MIR_GetDisplayBounds(_THIS, SDL_VideoDisplay* display, SDL_Rect* rect);
icculus@8153
    48
icculus@8153
    49
static void
icculus@8153
    50
MIR_GetDisplayModes(_THIS, SDL_VideoDisplay* sdl_display);
icculus@8153
    51
icculus@8153
    52
static int
icculus@8153
    53
MIR_SetDisplayMode(_THIS, SDL_VideoDisplay* sdl_display, SDL_DisplayMode* mode);
icculus@8153
    54
icculus@8153
    55
static SDL_WindowShaper*
icculus@8153
    56
MIR_CreateShaper(SDL_Window* window)
icculus@8153
    57
{
icculus@8153
    58
    /* FIXME Im not sure if mir support this atm, will have to come back to this */
icculus@8153
    59
    return NULL;
icculus@8153
    60
}
icculus@8153
    61
icculus@8153
    62
static int
icculus@8153
    63
MIR_SetWindowShape(SDL_WindowShaper* shaper, SDL_Surface* shape, SDL_WindowShapeMode* shape_mode)
icculus@8153
    64
{
icculus@8153
    65
    return SDL_Unsupported();
icculus@8153
    66
}
icculus@8153
    67
icculus@8153
    68
static int
icculus@8153
    69
MIR_ResizeWindowShape(SDL_Window* window)
icculus@8153
    70
{
icculus@8153
    71
    return SDL_Unsupported();
icculus@8153
    72
}
icculus@8153
    73
icculus@8153
    74
static int
icculus@8153
    75
MIR_Available()
icculus@8153
    76
{
icculus@8153
    77
    return 1;
icculus@8153
    78
}
icculus@8153
    79
icculus@8153
    80
static void
icculus@8153
    81
MIR_DeleteDevice(SDL_VideoDevice* device)
icculus@8153
    82
{
icculus@8153
    83
    SDL_free(device);
icculus@8153
    84
}
icculus@8153
    85
icculus@8153
    86
void
icculus@8153
    87
MIR_PumpEvents(_THIS)
icculus@8153
    88
{
icculus@8153
    89
}
icculus@8153
    90
icculus@8153
    91
static SDL_VideoDevice*
icculus@8153
    92
MIR_CreateDevice(int device_index)
icculus@8153
    93
{
icculus@8153
    94
    MIR_Data* mir_data;
icculus@8153
    95
    SDL_VideoDevice* device = SDL_calloc(1, sizeof(SDL_VideoDevice));
icculus@8153
    96
    if (!device) {
icculus@8153
    97
        SDL_OutOfMemory();
icculus@8153
    98
        return NULL;
icculus@8153
    99
    }
icculus@8153
   100
icculus@8153
   101
    mir_data = SDL_calloc(1, sizeof(MIR_Data));
icculus@8153
   102
    if (!mir_data) {
icculus@8153
   103
        SDL_OutOfMemory();
icculus@8153
   104
        SDL_free(device);
icculus@8153
   105
        return NULL;
icculus@8153
   106
    }
icculus@8153
   107
icculus@8153
   108
    device->driverdata = mir_data;
icculus@8153
   109
icculus@8153
   110
    /* mirvideo */
icculus@8153
   111
    device->VideoInit        = MIR_VideoInit;
icculus@8153
   112
    device->VideoQuit        = MIR_VideoQuit;
icculus@8153
   113
    device->GetDisplayBounds = MIR_GetDisplayBounds;
icculus@8153
   114
    device->GetDisplayModes  = MIR_GetDisplayModes;
icculus@8153
   115
    device->SetDisplayMode   = MIR_SetDisplayMode;
icculus@8153
   116
    device->free             = MIR_DeleteDevice;
icculus@8153
   117
icculus@8153
   118
    /* miropengles */
icculus@8153
   119
    device->GL_SwapWindow      = MIR_GL_SwapWindow;
icculus@8153
   120
    device->GL_MakeCurrent     = MIR_GL_MakeCurrent;
icculus@8153
   121
    device->GL_CreateContext   = MIR_GL_CreateContext;
icculus@8153
   122
    device->GL_DeleteContext   = MIR_GL_DeleteContext;
icculus@8153
   123
    device->GL_LoadLibrary     = MIR_GL_LoadLibrary;
icculus@8153
   124
    device->GL_UnloadLibrary   = MIR_GL_UnloadLibrary;
icculus@8153
   125
    device->GL_GetSwapInterval = MIR_GL_GetSwapInterval;
icculus@8153
   126
    device->GL_SetSwapInterval = MIR_GL_SetSwapInterval;
icculus@8153
   127
    device->GL_GetProcAddress  = MIR_GL_GetProcAddress;
icculus@8153
   128
icculus@8153
   129
    /* mirwindow */
icculus@8153
   130
    device->CreateWindow        = MIR_CreateWindow;
icculus@8153
   131
    device->DestroyWindow       = MIR_DestroyWindow;
icculus@8153
   132
    device->GetWindowWMInfo     = MIR_GetWindowWMInfo;
icculus@8153
   133
    device->SetWindowFullscreen = MIR_SetWindowFullscreen;
icculus@8153
   134
    device->MaximizeWindow      = MIR_MaximizeWindow;
icculus@8153
   135
    device->MinimizeWindow      = MIR_MinimizeWindow;
icculus@8153
   136
    device->RestoreWindow       = MIR_RestoreWindow;
icculus@8153
   137
icculus@8153
   138
    device->CreateWindowFrom     = NULL;
icculus@8153
   139
    device->SetWindowTitle       = NULL;
icculus@8153
   140
    device->SetWindowIcon        = NULL;
icculus@8153
   141
    device->SetWindowPosition    = NULL;
icculus@8153
   142
    device->SetWindowSize        = NULL;
icculus@8153
   143
    device->SetWindowMinimumSize = NULL;
icculus@8153
   144
    device->SetWindowMaximumSize = NULL;
icculus@8153
   145
    device->ShowWindow           = NULL;
icculus@8153
   146
    device->HideWindow           = NULL;
icculus@8153
   147
    device->RaiseWindow          = NULL;
icculus@8153
   148
    device->SetWindowBordered    = NULL;
icculus@8153
   149
    device->SetWindowGammaRamp   = NULL;
icculus@8153
   150
    device->GetWindowGammaRamp   = NULL;
icculus@8153
   151
    device->SetWindowGrab        = NULL;
icculus@8153
   152
    device->OnWindowEnter        = NULL;
icculus@8153
   153
icculus@8153
   154
    /* mirframebuffer */
icculus@8153
   155
    device->CreateWindowFramebuffer  = MIR_CreateWindowFramebuffer;
icculus@8153
   156
    device->UpdateWindowFramebuffer  = MIR_UpdateWindowFramebuffer;
icculus@8153
   157
    device->DestroyWindowFramebuffer = MIR_DestroyWindowFramebuffer;
icculus@8153
   158
icculus@8153
   159
    device->shape_driver.CreateShaper      = MIR_CreateShaper;
icculus@8153
   160
    device->shape_driver.SetWindowShape    = MIR_SetWindowShape;
icculus@8153
   161
    device->shape_driver.ResizeWindowShape = MIR_ResizeWindowShape;
icculus@8153
   162
icculus@8153
   163
    device->PumpEvents = MIR_PumpEvents;
icculus@8153
   164
icculus@8153
   165
    device->SuspendScreenSaver = NULL;
icculus@8153
   166
icculus@8153
   167
    device->StartTextInput   = NULL;
icculus@8153
   168
    device->StopTextInput    = NULL;
icculus@8153
   169
    device->SetTextInputRect = NULL;
icculus@8153
   170
icculus@8153
   171
    device->HasScreenKeyboardSupport = NULL;
icculus@8153
   172
    device->ShowScreenKeyboard       = NULL;
icculus@8153
   173
    device->HideScreenKeyboard       = NULL;
icculus@8153
   174
    device->IsScreenKeyboardShown    = NULL;
icculus@8153
   175
icculus@8153
   176
    device->SetClipboardText = NULL;
icculus@8153
   177
    device->GetClipboardText = NULL;
icculus@8153
   178
    device->HasClipboardText = NULL;
icculus@8153
   179
icculus@8153
   180
    device->ShowMessageBox = NULL;
icculus@8153
   181
icculus@8153
   182
    return device;
icculus@8153
   183
}
icculus@8153
   184
icculus@8153
   185
VideoBootStrap MIR_bootstrap = {
icculus@8153
   186
    MIR_DRIVER_NAME, "SDL Mir video driver",
icculus@8153
   187
    MIR_Available, MIR_CreateDevice
icculus@8153
   188
};
icculus@8153
   189
icculus@8153
   190
static void
icculus@8153
   191
MIR_SetCurrentDisplayMode(MirDisplayOutput const* out, SDL_VideoDisplay* display)
icculus@8153
   192
{
icculus@8153
   193
    SDL_DisplayMode mode = {
icculus@8153
   194
        .format = SDL_PIXELFORMAT_RGB888,
icculus@8153
   195
        .w = out->modes[out->current_mode].horizontal_resolution,
icculus@8153
   196
        .h = out->modes[out->current_mode].vertical_resolution,
icculus@8153
   197
        .refresh_rate = out->modes[out->current_mode].refresh_rate,
icculus@8153
   198
        .driverdata = NULL
icculus@8153
   199
    };
icculus@8153
   200
icculus@8153
   201
    display->desktop_mode = mode;
icculus@8153
   202
    display->current_mode = mode;
icculus@8153
   203
}
icculus@8153
   204
icculus@8153
   205
static void
icculus@8153
   206
MIR_AddAllModesFromDisplay(MirDisplayOutput const* out, SDL_VideoDisplay* display)
icculus@8153
   207
{
icculus@8153
   208
    int n_mode;
icculus@8153
   209
    for (n_mode = 0; n_mode < out->num_modes; ++n_mode) {
icculus@8153
   210
        SDL_DisplayMode mode = {
icculus@8153
   211
            .format = SDL_PIXELFORMAT_RGB888,
icculus@8153
   212
            .w = out->modes[n_mode].horizontal_resolution,
icculus@8153
   213
            .h = out->modes[n_mode].vertical_resolution,
icculus@8153
   214
            .refresh_rate = out->modes[n_mode].refresh_rate,
icculus@8153
   215
            .driverdata = NULL
icculus@8153
   216
        };
icculus@8153
   217
icculus@8153
   218
        SDL_AddDisplayMode(display, &mode);
icculus@8153
   219
    }
icculus@8153
   220
}
icculus@8153
   221
icculus@8153
   222
static void
icculus@8153
   223
MIR_InitDisplays(_THIS)
icculus@8153
   224
{
icculus@8153
   225
    MIR_Data* mir_data = _this->driverdata;
icculus@8153
   226
    int d;
icculus@8153
   227
icculus@8153
   228
    MirDisplayConfiguration* display_config =
icculus@8153
   229
            mir_connection_create_display_config(mir_data->connection);
icculus@8153
   230
icculus@8153
   231
    for (d = 0; d < display_config->num_outputs; d++) {
icculus@8153
   232
        MirDisplayOutput const* out = display_config->outputs + d;
icculus@8153
   233
icculus@8153
   234
        SDL_VideoDisplay display;
icculus@8153
   235
        SDL_zero(display);
icculus@8153
   236
icculus@8153
   237
        if (out->used &&
icculus@8153
   238
            out->connected &&
icculus@8153
   239
            out->num_modes &&
icculus@8153
   240
            out->current_mode < out->num_modes) {
icculus@8153
   241
icculus@8153
   242
            MIR_SetCurrentDisplayMode(out, &display);
icculus@8153
   243
            MIR_AddAllModesFromDisplay(out, &display);
icculus@8153
   244
icculus@8153
   245
            SDL_AddVideoDisplay(&display);
icculus@8153
   246
        }
icculus@8153
   247
    }
icculus@8153
   248
icculus@8153
   249
    mir_display_config_destroy(display_config);
icculus@8153
   250
}
icculus@8153
   251
icculus@8153
   252
int
icculus@8153
   253
MIR_VideoInit(_THIS)
icculus@8153
   254
{
icculus@8153
   255
    MIR_Data* mir_data = _this->driverdata;
icculus@8153
   256
icculus@8153
   257
    mir_data->connection = mir_connect_sync(NULL, __PRETTY_FUNCTION__);
icculus@8153
   258
icculus@8153
   259
    if (!mir_connection_is_valid(mir_data->connection))
icculus@8153
   260
        return SDL_SetError("Failed to connect to the Mir Server");
icculus@8153
   261
icculus@8153
   262
    MIR_InitDisplays(_this);
icculus@8153
   263
    MIR_InitMouse();
icculus@8153
   264
icculus@8153
   265
    return 0;
icculus@8153
   266
}
icculus@8153
   267
icculus@8153
   268
void
icculus@8153
   269
MIR_VideoQuit(_THIS)
icculus@8153
   270
{
icculus@8153
   271
    MIR_Data* mir_data = _this->driverdata;
icculus@8153
   272
icculus@8153
   273
    MIR_FiniMouse();
icculus@8153
   274
icculus@8153
   275
    MIR_GL_DeleteContext(_this, NULL);
icculus@8153
   276
    MIR_GL_UnloadLibrary(_this);
icculus@8153
   277
icculus@8153
   278
    mir_connection_release(mir_data->connection);
icculus@8153
   279
icculus@8153
   280
    SDL_free(mir_data);
icculus@8153
   281
    _this->driverdata = NULL;
icculus@8153
   282
}
icculus@8153
   283
icculus@8153
   284
static int
icculus@8153
   285
MIR_GetDisplayBounds(_THIS, SDL_VideoDisplay* display, SDL_Rect* rect)
icculus@8153
   286
{
icculus@8153
   287
    MIR_Data* mir_data = _this->driverdata;
icculus@8153
   288
    int d;
icculus@8153
   289
icculus@8153
   290
    MirDisplayConfiguration* display_config =
icculus@8153
   291
            mir_connection_create_display_config(mir_data->connection);
icculus@8153
   292
icculus@8153
   293
    for (d = 0; d < display_config->num_outputs; d++) {
icculus@8153
   294
        MirDisplayOutput const* out = display_config->outputs + d;
icculus@8153
   295
icculus@8153
   296
        if (out->used &&
icculus@8153
   297
            out->connected &&
icculus@8153
   298
            out->num_modes &&
icculus@8153
   299
            out->current_mode < out->num_modes) {
icculus@8153
   300
icculus@8153
   301
            rect->x = out->position_x;
icculus@8153
   302
            rect->y = out->position_y;
icculus@8153
   303
            rect->w = out->modes->horizontal_resolution;
icculus@8153
   304
            rect->h = out->modes->vertical_resolution;
icculus@8153
   305
        }
icculus@8153
   306
    }
icculus@8153
   307
icculus@8153
   308
    mir_display_config_destroy(display_config);
icculus@8153
   309
icculus@8153
   310
    return 0;
icculus@8153
   311
}
icculus@8153
   312
icculus@8153
   313
static void
icculus@8153
   314
MIR_GetDisplayModes(_THIS, SDL_VideoDisplay* sdl_display)
icculus@8153
   315
{
icculus@8153
   316
}
icculus@8153
   317
icculus@8153
   318
static int
icculus@8153
   319
MIR_SetDisplayMode(_THIS, SDL_VideoDisplay* sdl_display, SDL_DisplayMode* mode)
icculus@8153
   320
{
icculus@8153
   321
    return 0;
icculus@8153
   322
}
icculus@8154
   323
icculus@8154
   324
#endif /* SDL_VIDEO_DRIVER_MIR */
icculus@8154
   325
icculus@8154
   326
/* vi: set ts=4 sw=4 expandtab: */
icculus@8154
   327