summaryrefslogtreecommitdiff
path: root/hw/xwayland/xwayland-pixmap.c
blob: 8e929f0295e35c1f30ee789ee36443e07f8db174 (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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
/*
 * Copyright © 2014 Intel Corporation
 *
 * Permission to use, copy, modify, distribute, and sell this software
 * and its documentation for any purpose is hereby granted without
 * fee, provided that the above copyright notice appear in all copies
 * and that both that copyright notice and this permission notice
 * appear in supporting documentation, and that the name of the
 * copyright holders not be used in advertising or publicity
 * pertaining to distribution of the software without specific,
 * written prior permission.  The copyright holders make no
 * representations about the suitability of this software for any
 * purpose.  It is provided "as is" without express or implied
 * warranty.
 *
 * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS
 * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
 * FITNESS, IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY
 * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN
 * AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
 * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
 * SOFTWARE.
 */

#include <xwayland-config.h>

#include <X11/X.h>

#include "os.h"
#include "privates.h"
#include "dix.h"
#include "fb.h"
#include "pixmapstr.h"

#ifdef XWL_HAS_GLAMOR
#include "xwayland-glamor.h"
#endif
#include "xwayland-types.h"
#include "xwayland-pixmap.h"
#include "xwayland-screen.h"
#include "xwayland-shm.h"
#include "xwayland-window-buffers.h"

static DevPrivateKeyRec xwl_pixmap_private_key;
static DevPrivateKeyRec xwl_pixmap_cb_private_key;

struct xwl_pixmap_buffer_release_callback {
    xwl_buffer_release_cb callback;
    void *data;
};

void
xwl_pixmap_set_private(PixmapPtr pixmap, struct xwl_pixmap *xwl_pixmap)
{
    dixSetPrivate(&pixmap->devPrivates, &xwl_pixmap_private_key, xwl_pixmap);
}

struct xwl_pixmap *
xwl_pixmap_get(PixmapPtr pixmap)
{
    return dixLookupPrivate(&pixmap->devPrivates, &xwl_pixmap_private_key);
}

struct wl_buffer *
xwl_pixmap_get_wl_buffer(PixmapPtr pixmap)
{
#ifdef XWL_HAS_GLAMOR
    struct xwl_screen *xwl_screen = xwl_screen_get(pixmap->drawable.pScreen);

    if (xwl_screen->glamor)
        return xwl_glamor_pixmap_get_wl_buffer(pixmap);
    else
#endif
        return xwl_shm_pixmap_get_wl_buffer(pixmap);
}

Bool
xwl_pixmap_set_buffer_release_cb(PixmapPtr pixmap,
                                 xwl_buffer_release_cb func, void *data)
{
    struct xwl_pixmap_buffer_release_callback *xwl_pixmap_buffer_release_callback;

    xwl_pixmap_buffer_release_callback = dixLookupPrivate(&pixmap->devPrivates,
                                                          &xwl_pixmap_cb_private_key);

    if (xwl_pixmap_buffer_release_callback == NULL) {
        xwl_pixmap_buffer_release_callback =
            calloc(1, sizeof (struct xwl_pixmap_buffer_release_callback));

        if (xwl_pixmap_buffer_release_callback == NULL) {
            ErrorF("Failed to allocate pixmap callback data\n");
            return FALSE;
        }
        dixSetPrivate(&pixmap->devPrivates, &xwl_pixmap_cb_private_key,
                      xwl_pixmap_buffer_release_callback);
    }

    xwl_pixmap_buffer_release_callback->callback = func;
    xwl_pixmap_buffer_release_callback->data = data;

    return TRUE;
}

void
xwl_pixmap_del_buffer_release_cb(PixmapPtr pixmap)
{
    struct xwl_pixmap_buffer_release_callback *xwl_pixmap_buffer_release_callback;

    xwl_pixmap_buffer_release_callback = dixLookupPrivate(&pixmap->devPrivates,
                                                          &xwl_pixmap_cb_private_key);
    if (xwl_pixmap_buffer_release_callback) {
        dixSetPrivate(&pixmap->devPrivates, &xwl_pixmap_cb_private_key, NULL);
        free(xwl_pixmap_buffer_release_callback);
    }
}

void
xwl_pixmap_buffer_release_cb(void *data, struct wl_buffer *wl_buffer)
{
    PixmapPtr pixmap = data;
    struct xwl_pixmap_buffer_release_callback *xwl_pixmap_buffer_release_callback;

    xwl_pixmap_buffer_release_callback = dixLookupPrivate(&pixmap->devPrivates,
                                                          &xwl_pixmap_cb_private_key);
    if (xwl_pixmap_buffer_release_callback)
        (*xwl_pixmap_buffer_release_callback->callback)
            (xwl_pixmap_buffer_release_callback->data);
}

Bool
xwl_pixmap_init(void)
{
    if (!dixRegisterPrivateKey(&xwl_pixmap_private_key, PRIVATE_PIXMAP, 0))
        return FALSE;

    if (!dixRegisterPrivateKey(&xwl_pixmap_cb_private_key, PRIVATE_PIXMAP, 0))
        return FALSE;

    return TRUE;
}