xegl_window.c 4.31 KB
Newer Older
Chad Versace's avatar
Chad Versace committed
1 2
// Copyright 2012 Intel Corporation
//
3
// All rights reserved.
Chad Versace's avatar
Chad Versace committed
4
//
5 6
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
Chad Versace's avatar
Chad Versace committed
7
//
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
// - Redistributions of source code must retain the above copyright notice, this
//   list of conditions and the following disclaimer.
//
// - Redistributions in binary form must reproduce the above copyright notice,
//   this list of conditions and the following disclaimer in the documentation
//   and/or other materials provided with the distribution.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
// OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Chad Versace's avatar
Chad Versace committed
25 26 27 28

#include <stdlib.h>
#include <string.h>

29 30
#include <xcb/xcb.h>

31
#include "wcore_attrib_list.h"
32 33 34
#include "wcore_error.h"

#include "wegl_config.h"
35
#include "wegl_platform.h"
36
#include "wegl_util.h"
Chad Versace's avatar
Chad Versace committed
37

38 39 40
#include "xegl_display.h"
#include "xegl_window.h"

41
bool
42 43 44 45 46 47 48 49
xegl_window_destroy(struct wcore_window *wc_self)
{
    struct xegl_window *self = xegl_window(wc_self);
    bool ok = true;

    if (!self)
        return ok;

50
    ok &= wegl_surface_teardown(&self->wegl);
51 52 53 54
    ok &= x11_window_teardown(&self->x11);
    free(self);
    return ok;
}
Chad Versace's avatar
Chad Versace committed
55

56 57 58
struct wcore_window*
xegl_window_create(struct wcore_platform *wc_plat,
                   struct wcore_config *wc_config,
59
                   int32_t width,
60 61
                   int32_t height,
                   const intptr_t attrib_list[])
Chad Versace's avatar
Chad Versace committed
62
{
63 64
    struct xegl_window *self;
    struct xegl_display *dpy = xegl_display(wc_config->display);
65
    struct wegl_config *config = wegl_config(wc_config);
66
    struct wegl_platform *plat = wegl_platform(wc_plat);
67
    xcb_visualid_t visual;
68
    bool ok = true;
Chad Versace's avatar
Chad Versace committed
69

70 71 72 73 74
    if (width == -1 && height == -1) {
        width = DisplayWidth(dpy->x11.xlib, dpy->x11.screen);
        height = DisplayHeight(dpy->x11.xlib, dpy->x11.screen);
    }

75 76 77 78 79
    if (wcore_attrib_list_length(attrib_list) > 0) {
        wcore_error_bad_attribute(attrib_list[0]);
        return NULL;
    }

80 81
    self = wcore_calloc(sizeof(*self));
    if (self == NULL)
Chad Versace's avatar
Chad Versace committed
82 83
        return NULL;

84 85 86 87
    ok = plat->eglGetConfigAttrib(dpy->wegl.egl,
                                  config->egl,
                                  EGL_NATIVE_VISUAL_ID,
                                  (EGLint*) &visual);
88
    if (!ok) {
89
        wegl_emit_error(plat, "eglGetConfigAttrib(EGL_NATIVE_VISUAL_ID)");
90
        goto error;
91
    }
92 93 94

    ok = x11_window_init(&self->x11,
                         &dpy->x11,
95
                         visual,
96 97 98
                         width,
                         height);
    if (!ok)
Chad Versace's avatar
Chad Versace committed
99 100
        goto error;

101 102 103 104
    ok = wegl_window_init(&self->wegl,
                          &config->wcore,
                          (intptr_t) self->x11.xcb);
    if (!ok)
105
        goto error;
Chad Versace's avatar
Chad Versace committed
106

107
    return &self->wegl.wcore;
Chad Versace's avatar
Chad Versace committed
108 109

error:
110
    xegl_window_destroy(&self->wegl.wcore);
Chad Versace's avatar
Chad Versace committed
111 112 113
    return NULL;
}

114
bool
115
xegl_window_show(struct wcore_window *wc_self)
Chad Versace's avatar
Chad Versace committed
116
{
117
    return x11_window_show(&xegl_window(wc_self)->x11);
Chad Versace's avatar
Chad Versace committed
118 119
}

120 121 122 123 124 125 126
bool
xegl_window_resize(struct wcore_window *wc_self,
                   int32_t width, int32_t height)
{
   return x11_window_resize(&xegl_window(wc_self)->x11, width, height);
}

127
union waffle_native_window*
128 129 130 131
xegl_window_get_native(struct wcore_window *wc_self)
{
    struct xegl_window *self = xegl_window(wc_self);
    struct xegl_display *dpy = xegl_display(wc_self->display);
132
    union waffle_native_window *n_window;
133

134 135
    WCORE_CREATE_NATIVE_UNION(n_window, x11_egl);
    if (!n_window)
136 137
        return NULL;

138 139
    xegl_display_fill_native(dpy, &n_window->x11_egl->display);
    n_window->x11_egl->xlib_window = self->x11.xcb;
140
    n_window->x11_egl->egl_surface = self->wegl.egl;;
141

142
    return n_window;
143
}