summaryrefslogtreecommitdiff
path: root/src/video/wayland/SDL_waylandwindow.c
blob: a9e71f08115a0da71bdc0ee90b06d5ed18580778 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
/*
    SDL - Simple DirectMedia Layer
    Copyright (C) 1997-2010 Sam Lantinga

    This library is free software; you can redistribute it and/or
    modify it under the terms of the GNU Lesser General Public
    License as published by the Free Software Foundation; either
    version 2.1 of the License, or (at your option) any later version.

    This library is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    Lesser General Public License for more details.

    You should have received a copy of the GNU Lesser General Public
    License along with this library; if not, write to the Free Software
    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA

    Sam Lantinga
    slouken@libsdl.org
*/

#include "SDL_config.h"

#include "../SDL_sysvideo.h"
#include "SDL_waylandwindow.h"
#include "SDL_waylandvideo.h"


void Wayland_ShowWindow(_THIS, SDL_Window * window)
{
    SDL_WaylandWindow *wind = (SDL_WaylandWindow*) window->driverdata;

    printf("sow window: %d,%d\n", window->w, window->h);
    if (window->flags & SDL_WINDOW_FULLSCREEN)
        wl_surface_map_fullscreen(wind->surface);
    else
        wl_surface_map_toplevel(wind->surface);
    /*
       wl_surface_map(wind->surface,
       window->x, window->y,
       window->w, window->h);
       */

    wayland_schedule_write((SDL_WaylandData *) _this->driverdata);
}


int Wayland_CreateWindow(_THIS, SDL_Window * window)
{
    SDL_WaylandWindow *data;
    struct wl_visual *visual;
    int i;
    SDL_WaylandData *c;

    data = malloc(sizeof *data);
    if (data == NULL)
        return 0;

    c = _this->driverdata;
    window->driverdata = data;

    if (!(window->flags & SDL_WINDOW_OPENGL)) {
        SDL_GL_LoadLibrary(NULL);
        window->flags &= SDL_WINDOW_OPENGL;
    }

    if (window->x == SDL_WINDOWPOS_UNDEFINED) {
        window->x = 0;
    }
    if (window->y == SDL_WINDOWPOS_UNDEFINED) {
        window->y = 0;
    }

    data->waylandData = c;
    data->sdlwindow = window;

    data->surface =
        wl_compositor_create_surface(c->compositor);
    wl_surface_set_user_data(data->surface, data);

    if (_this->gl_config.alpha_size == 0)
        visual = wl_display_get_rgb_visual(c->display);
    else
        visual = wl_display_get_premultiplied_argb_visual(c->display);
    data->egl_window = wl_egl_window_create(data->surface,
                                            window->w, window->h, visual);
    data->esurf =
        eglCreateWindowSurface(c->edpy, c->econf,
                               data->egl_window, NULL);

    if (data->esurf == EGL_NO_SURFACE) {
        SDL_SetError("failed to create a window surface\n");
        return -1;
    }

    wayland_schedule_write(c);

    printf("created window\n");

    return 0;
}

void Wayland_DestroyWindow(_THIS, SDL_Window * window)
{
    SDL_WaylandData *data = (SDL_WaylandData *) _this->driverdata;
    SDL_WaylandWindow *wind = (SDL_WaylandWindow *) window->driverdata;

    window->driverdata = NULL;
    int i;

    if (data) {
        eglDestroySurface(data->edpy, wind->esurf);
        wl_egl_window_destroy(wind->egl_window);
        wl_surface_destroy(wind->surface);
        SDL_free(wind);
        wayland_schedule_write(data);
    }

    printf("destroyed window\n");
}

/* vi: set ts=4 sw=4 expandtab: */