present_notify.c 3.2 KB

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