Add patch that contain Mali fixes.
[deb_xorg-server.git] / dri3 / dri3_event.c
CommitLineData
7217e0ca
ML
1/*
2 * Copyright © 2013 Keith Packard
3 *
4 * Permission to use, copy, modify, distribute, and sell this software and its
5 * documentation for any purpose is hereby granted without fee, provided that
6 * the above copyright notice appear in all copies and that both that copyright
7 * notice and this permission notice appear in supporting documentation, and
8 * that the name of the copyright holders not be used in advertising or
9 * publicity pertaining to distribution of the software without specific,
10 * written prior permission. The copyright holders make no representations
11 * about the suitability of this software for any purpose. It is provided "as
12 * is" without express or implied warranty.
13 *
14 * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
15 * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
16 * EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY SPECIAL, INDIRECT OR
17 * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
18 * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
19 * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
20 * OF THIS SOFTWARE.
21 */
22
23#ifdef HAVE_XORG_CONFIG_H
24#include <xorg-config.h>
25#endif
26
27#include "dri3_priv.h"
28
29RESTYPE dri3_event_type;
30
31static int
32dri3_free_event(pointer data, XID id)
33{
34 dri3_event_ptr dri3_event = (dri3_event_ptr) data;
35 dri3_window_priv_ptr window_priv = dri3_window_priv(dri3_event->window);
36 dri3_event_ptr *previous, current;
37
38 for (previous = &window_priv->events; (current = *previous); previous = &current->next) {
39 if (current == dri3_event) {
40 *previous = dri3_event->next;
41 break;
42 }
43 }
44 free((pointer) dri3_event);
45 return 1;
46
47}
48
49void
50dri3_free_events(WindowPtr window)
51{
52 dri3_window_priv_ptr window_priv = dri3_window_priv(window);
53 dri3_event_ptr event;
54
55 if (!window_priv)
56 return;
57
58 while ((event = window_priv->events))
59 FreeResource(event->id, RT_NONE);
60}
61
62static void
63dri3_event_swap(xGenericEvent *from, xGenericEvent *to)
64{
65 *to = *from;
66 swaps(&to->sequenceNumber);
67 swapl(&to->length);
68 swaps(&to->evtype);
69 switch (from->evtype) {
70 case DRI3_ConfigureNotify: {
71 xDRI3ConfigureNotify *c = (xDRI3ConfigureNotify *) to;
72
73 swapl(&c->eid);
74 swapl(&c->window);
75 swaps(&c->x);
76 swaps(&c->y);
77 swaps(&c->width);
78 swaps(&c->height);
79 swaps(&c->off_x);
80 swaps(&c->off_y);
81 swaps(&c->pixmap_width);
82 swaps(&c->pixmap_height);
83 swapl(&c->pixmap_flags);
84 break;
85 }
86 }
87}
88
89void
90dri3_send_config_notify(WindowPtr window, int x, int y, int w, int h, int bw, WindowPtr sibling)
91{
92 dri3_window_priv_ptr window_priv = dri3_window_priv(window);
93
94 if (window_priv) {
95 xDRI3ConfigureNotify cn = {
96 .type = GenericEvent,
97 .extension = dri3_request,
98 .length = (sizeof(xDRI3ConfigureNotify) - 32) >> 2,
99 .evtype = DRI3_ConfigureNotify,
100 .eid = 0,
101 .window = window->drawable.id,
102 .x = x,
103 .y = y,
104 .width = w,
105 .height = h,
106 .off_x = 0,
107 .off_y = 0,
108 .pixmap_width = w,
109 .pixmap_height = h,
110 .pixmap_flags = 0
111 };
112 dri3_event_ptr event;
113 dri3_screen_priv_ptr screen_priv = dri3_screen_priv(window->drawable.pScreen);
114
115 if (screen_priv->info && screen_priv->info->driver_config)
116 screen_priv->info->driver_config(window, &cn);
117
118 for (event = window_priv->events; event; event = event->next) {
119 if (event->mask & (1 << DRI3ConfigureNotify)) {
120 cn.eid = event->id;
121 WriteEventsToClient(event->client, 1, (xEvent *) &cn);
122 }
123 }
124 }
125}
126
127int
128dri3_select_input(ClientPtr client, XID eid, WindowPtr window, CARD32 mask)
129{
130 dri3_window_priv_ptr window_priv = dri3_window_priv(window);
131 dri3_event_ptr event;
132
133 if (!window_priv)
134 return BadAlloc;
135
136 event = calloc (1, sizeof (dri3_event_rec));
137 if (!event)
138 return BadAlloc;
139
140 event->client = client;
141 event->window = window;
142 event->id = eid;
143 event->mask = mask;
144
145 event->next = window_priv->events;
146 window_priv->events = event;
147
148 if (!AddResource(event->id, dri3_event_type, (pointer) event))
149 return BadAlloc;
150
151 return Success;
152}
153
154Bool
155dri3_event_init(void)
156{
157 dri3_event_type = CreateNewResourceType(dri3_free_event, "DRI3Event");
158 if (!dri3_event_type)
159 return FALSE;
160
161 GERegisterExtension(dri3_request, dri3_event_swap);
162 return TRUE;
163}