present_notify.c revision 35c4bbdf
135c4bbdfSmrg/*
235c4bbdfSmrg * Copyright © 2013 Keith Packard
335c4bbdfSmrg *
435c4bbdfSmrg * Permission to use, copy, modify, distribute, and sell this software and its
535c4bbdfSmrg * documentation for any purpose is hereby granted without fee, provided that
635c4bbdfSmrg * the above copyright notice appear in all copies and that both that copyright
735c4bbdfSmrg * notice and this permission notice appear in supporting documentation, and
835c4bbdfSmrg * that the name of the copyright holders not be used in advertising or
935c4bbdfSmrg * publicity pertaining to distribution of the software without specific,
1035c4bbdfSmrg * written prior permission.  The copyright holders make no representations
1135c4bbdfSmrg * about the suitability of this software for any purpose.  It is provided "as
1235c4bbdfSmrg * is" without express or implied warranty.
1335c4bbdfSmrg *
1435c4bbdfSmrg * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
1535c4bbdfSmrg * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
1635c4bbdfSmrg * EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY SPECIAL, INDIRECT OR
1735c4bbdfSmrg * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
1835c4bbdfSmrg * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
1935c4bbdfSmrg * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
2035c4bbdfSmrg * OF THIS SOFTWARE.
2135c4bbdfSmrg */
2235c4bbdfSmrg
2335c4bbdfSmrg#ifdef HAVE_XORG_CONFIG_H
2435c4bbdfSmrg#include <xorg-config.h>
2535c4bbdfSmrg#endif
2635c4bbdfSmrg
2735c4bbdfSmrg#include "present_priv.h"
2835c4bbdfSmrg
2935c4bbdfSmrg/*
3035c4bbdfSmrg * Mark all pending notifies for 'window' as invalid when
3135c4bbdfSmrg * the window is destroyed
3235c4bbdfSmrg */
3335c4bbdfSmrg
3435c4bbdfSmrgvoid
3535c4bbdfSmrgpresent_clear_window_notifies(WindowPtr window)
3635c4bbdfSmrg{
3735c4bbdfSmrg    present_notify_ptr          notify;
3835c4bbdfSmrg    present_window_priv_ptr     window_priv = present_window_priv(window);
3935c4bbdfSmrg
4035c4bbdfSmrg    if (!window_priv)
4135c4bbdfSmrg        return;
4235c4bbdfSmrg
4335c4bbdfSmrg    xorg_list_for_each_entry(notify, &window_priv->notifies, window_list) {
4435c4bbdfSmrg        notify->window = NULL;
4535c4bbdfSmrg    }
4635c4bbdfSmrg}
4735c4bbdfSmrg
4835c4bbdfSmrg/*
4935c4bbdfSmrg * 'notify' is being freed; remove it from the window's notify list
5035c4bbdfSmrg */
5135c4bbdfSmrg
5235c4bbdfSmrgvoid
5335c4bbdfSmrgpresent_free_window_notify(present_notify_ptr notify)
5435c4bbdfSmrg{
5535c4bbdfSmrg    xorg_list_del(&notify->window_list);
5635c4bbdfSmrg}
5735c4bbdfSmrg
5835c4bbdfSmrg/*
5935c4bbdfSmrg * 'notify' is new; add it to the specified window
6035c4bbdfSmrg */
6135c4bbdfSmrg
6235c4bbdfSmrgint
6335c4bbdfSmrgpresent_add_window_notify(present_notify_ptr notify)
6435c4bbdfSmrg{
6535c4bbdfSmrg    WindowPtr                   window = notify->window;
6635c4bbdfSmrg    present_window_priv_ptr     window_priv = present_get_window_priv(window, TRUE);
6735c4bbdfSmrg
6835c4bbdfSmrg    if (!window_priv)
6935c4bbdfSmrg        return BadAlloc;
7035c4bbdfSmrg
7135c4bbdfSmrg    xorg_list_add(&notify->window_list, &window_priv->notifies);
7235c4bbdfSmrg    return Success;
7335c4bbdfSmrg}
7435c4bbdfSmrg
7535c4bbdfSmrgint
7635c4bbdfSmrgpresent_create_notifies(ClientPtr client, int num_notifies, xPresentNotify *x_notifies, present_notify_ptr *p_notifies)
7735c4bbdfSmrg{
7835c4bbdfSmrg    present_notify_ptr  notifies;
7935c4bbdfSmrg    int                 i;
8035c4bbdfSmrg    int                 added = 0;
8135c4bbdfSmrg    int                 status;
8235c4bbdfSmrg
8335c4bbdfSmrg    notifies = calloc (num_notifies, sizeof (present_notify_rec));
8435c4bbdfSmrg    if (!notifies)
8535c4bbdfSmrg        return BadAlloc;
8635c4bbdfSmrg
8735c4bbdfSmrg    for (i = 0; i < num_notifies; i++) {
8835c4bbdfSmrg        status = dixLookupWindow(&notifies[i].window, x_notifies[i].window, client, DixGetAttrAccess);
8935c4bbdfSmrg        if (status != Success)
9035c4bbdfSmrg            goto bail;
9135c4bbdfSmrg
9235c4bbdfSmrg        notifies[i].serial = x_notifies[i].serial;
9335c4bbdfSmrg        status = present_add_window_notify(&notifies[i]);
9435c4bbdfSmrg        if (status != Success)
9535c4bbdfSmrg            goto bail;
9635c4bbdfSmrg
9735c4bbdfSmrg        added = i;
9835c4bbdfSmrg    }
9935c4bbdfSmrg    return Success;
10035c4bbdfSmrg
10135c4bbdfSmrgbail:
10235c4bbdfSmrg    present_destroy_notifies(notifies, added);
10335c4bbdfSmrg    return status;
10435c4bbdfSmrg}
10535c4bbdfSmrg
10635c4bbdfSmrgvoid
10735c4bbdfSmrgpresent_destroy_notifies(present_notify_ptr notifies, int num_notifies)
10835c4bbdfSmrg{
10935c4bbdfSmrg    int i;
11035c4bbdfSmrg    for (i = 0; i < num_notifies; i++)
11135c4bbdfSmrg        present_free_window_notify(&notifies[i]);
11235c4bbdfSmrg
11335c4bbdfSmrg    free(notifies);
11435c4bbdfSmrg}
115