2 * Copyright © 2013 Keith Packard
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.
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
23 #ifdef HAVE_XORG_CONFIG_H
24 #include <xorg-config.h>
27 #include "present_priv.h"
29 RESTYPE present_event_type
;
32 present_free_event(pointer data
, XID id
)
34 present_event_ptr present_event
= (present_event_ptr
) data
;
35 present_window_priv_ptr window_priv
= present_window_priv(present_event
->window
);
36 present_event_ptr
*previous
, current
;
38 for (previous
= &window_priv
->events
; (current
= *previous
); previous
= ¤t
->next
) {
39 if (current
== present_event
) {
40 *previous
= present_event
->next
;
44 free((pointer
) present_event
);
50 present_free_events(WindowPtr window
)
52 present_window_priv_ptr window_priv
= present_window_priv(window
);
53 present_event_ptr event
;
58 while ((event
= window_priv
->events
))
59 FreeResource(event
->id
, RT_NONE
);
63 present_event_swap(xGenericEvent
*from
, xGenericEvent
*to
)
66 swaps(&to
->sequenceNumber
);
69 switch (from
->evtype
) {
70 case PresentConfigureNotify
: {
71 xPresentConfigureNotify
*c
= (xPresentConfigureNotify
*) to
;
81 swaps(&c
->pixmap_width
);
82 swaps(&c
->pixmap_height
);
83 swapl(&c
->pixmap_flags
);
86 case PresentCompleteNotify
:
88 xPresentCompleteNotify
*c
= (xPresentCompleteNotify
*) to
;
95 case PresentIdleNotify
:
97 xPresentIdleNotify
*c
= (xPresentIdleNotify
*) to
;
101 swapl(&c
->idle_fence
);
107 present_send_config_notify(WindowPtr window
, int x
, int y
, int w
, int h
, int bw
, WindowPtr sibling
)
109 present_window_priv_ptr window_priv
= present_window_priv(window
);
112 xPresentConfigureNotify cn
= {
113 .type
= GenericEvent
,
114 .extension
= present_request
,
115 .length
= (sizeof(xPresentConfigureNotify
) - 32) >> 2,
116 .evtype
= PresentConfigureNotify
,
118 .window
= window
->drawable
.id
,
129 present_event_ptr event
;
131 for (event
= window_priv
->events
; event
; event
= event
->next
) {
132 if (event
->mask
& (1 << PresentConfigureNotify
)) {
134 WriteEventsToClient(event
->client
, 1, (xEvent
*) &cn
);
140 static present_complete_notify_proc complete_notify
;
143 present_register_complete_notify(present_complete_notify_proc proc
)
145 complete_notify
= proc
;
149 present_send_complete_notify(WindowPtr window
, CARD8 kind
, CARD8 mode
, CARD32 serial
, uint64_t ust
, uint64_t msc
)
151 present_window_priv_ptr window_priv
= present_window_priv(window
);
154 xPresentCompleteNotify cn
= {
155 .type
= GenericEvent
,
156 .extension
= present_request
,
157 .length
= (sizeof(xPresentCompleteNotify
) - 32) >> 2,
158 .evtype
= PresentCompleteNotify
,
162 .window
= window
->drawable
.id
,
167 present_event_ptr event
;
169 for (event
= window_priv
->events
; event
; event
= event
->next
) {
170 if (event
->mask
& PresentCompleteNotifyMask
) {
172 WriteEventsToClient(event
->client
, 1, (xEvent
*) &cn
);
177 (*complete_notify
)(window
, mode
, serial
, ust
, msc
);
181 present_send_idle_notify(WindowPtr window
, CARD32 serial
, PixmapPtr pixmap
, struct present_fence
*idle_fence
)
183 present_window_priv_ptr window_priv
= present_window_priv(window
);
186 xPresentIdleNotify in
= {
187 .type
= GenericEvent
,
188 .extension
= present_request
,
189 .length
= (sizeof(xPresentIdleNotify
) - 32) >> 2,
190 .evtype
= PresentIdleNotify
,
192 .window
= window
->drawable
.id
,
194 .pixmap
= pixmap
->drawable
.id
,
195 .idle_fence
= present_fence_id(idle_fence
)
197 present_event_ptr event
;
199 for (event
= window_priv
->events
; event
; event
= event
->next
) {
200 if (event
->mask
& PresentIdleNotifyMask
) {
202 WriteEventsToClient(event
->client
, 1, (xEvent
*) &in
);
209 present_select_input(ClientPtr client
, XID eid
, WindowPtr window
, CARD32 mask
)
211 present_window_priv_ptr window_priv
= present_get_window_priv(window
, mask
!= 0);
212 present_event_ptr event
;
220 event
= calloc (1, sizeof (present_event_rec
));
224 event
->client
= client
;
225 event
->window
= window
;
229 event
->next
= window_priv
->events
;
230 window_priv
->events
= event
;
232 if (!AddResource(event
->id
, present_event_type
, (pointer
) event
))
239 present_event_init(void)
241 present_event_type
= CreateNewResourceType(present_free_event
, "PresentEvent");
242 if (!present_event_type
)
245 GERegisterExtension(present_request
, present_event_swap
);