Add patch that contain Mali fixes.
[deb_xorg-server.git] / present / present_notify.c
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 "present_priv.h"
28
29 /*
30 * Mark all pending notifies for 'window' as invalid when
31 * the window is destroyed
32 */
33
34 void
35 present_clear_window_notifies(WindowPtr window)
36 {
37 present_notify_ptr notify;
38 present_window_priv_ptr window_priv = present_window_priv(window);
39
40 if (!window_priv)
41 return;
42
43 xorg_list_for_each_entry(notify, &window_priv->notifies, window_list) {
44 notify->window = NULL;
45 }
46 }
47
48 /*
49 * 'notify' is being freed; remove it from the window's notify list
50 */
51
52 void
53 present_free_window_notify(present_notify_ptr notify)
54 {
55 xorg_list_del(&notify->window_list);
56 }
57
58 /*
59 * 'notify' is new; add it to the specified window
60 */
61
62 int
63 present_add_window_notify(present_notify_ptr notify)
64 {
65 WindowPtr window = notify->window;
66 present_window_priv_ptr window_priv = present_get_window_priv(window, TRUE);
67
68 if (!window_priv)
69 return BadAlloc;
70
71 xorg_list_add(&notify->window_list, &window_priv->notifies);
72 return Success;
73 }
74
75 int
76 present_create_notifies(ClientPtr client, int num_notifies, xPresentNotify *x_notifies, present_notify_ptr *p_notifies)
77 {
78 present_notify_ptr notifies;
79 int i;
80 int added = 0;
81 int status;
82
83 notifies = calloc (num_notifies, sizeof (present_notify_rec));
84 if (!notifies)
85 return BadAlloc;
86
87 for (i = 0; i < num_notifies; i++) {
88 status = dixLookupWindow(&notifies[i].window, x_notifies[i].window, client, DixGetAttrAccess);
89 if (status != Success)
90 goto bail;
91
92 notifies[i].serial = x_notifies[i].serial;
93 status = present_add_window_notify(&notifies[i]);
94 if (status != Success)
95 goto bail;
96
97 added = i;
98 }
99 return Success;
100
101 bail:
102 present_destroy_notifies(notifies, added);
103 return status;
104 }
105
106 void
107 present_destroy_notifies(present_notify_ptr notifies, int num_notifies)
108 {
109 int i;
110 for (i = 0; i < num_notifies; i++)
111 present_free_window_notify(&notifies[i]);
112
113 free(notifies);
114 }