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