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"
30 static struct xorg_list fake_vblank_queue
;
32 typedef struct present_fake_vblank
{
33 struct xorg_list list
;
37 } present_fake_vblank_rec
, *present_fake_vblank_ptr
;
40 present_fake_get_ust_msc(ScreenPtr screen
, uint64_t *ust
, uint64_t *msc
)
42 present_screen_priv_ptr screen_priv
= present_screen_priv(screen
);
44 *ust
= GetTimeInMicros();
45 *msc
= (*ust
+ screen_priv
->fake_interval
/ 2) / screen_priv
->fake_interval
;
50 present_fake_notify(ScreenPtr screen
, uint64_t event_id
)
54 present_fake_get_ust_msc(screen
, &ust
, &msc
);
55 present_event_notify(event_id
, ust
, msc
);
59 present_fake_do_timer(OsTimerPtr timer
,
63 present_fake_vblank_ptr fake_vblank
= arg
;
65 present_fake_notify(fake_vblank
->screen
, fake_vblank
->event_id
);
66 xorg_list_del(&fake_vblank
->list
);
72 present_fake_abort_vblank(ScreenPtr screen
, uint64_t event_id
, uint64_t msc
)
74 present_fake_vblank_ptr fake_vblank
, tmp
;
76 xorg_list_for_each_entry_safe(fake_vblank
, tmp
, &fake_vblank_queue
, list
) {
77 if (fake_vblank
->event_id
== event_id
) {
78 TimerCancel(fake_vblank
->timer
);
79 xorg_list_del(&fake_vblank
->list
);
87 present_fake_queue_vblank(ScreenPtr screen
,
91 present_screen_priv_ptr screen_priv
= present_screen_priv(screen
);
92 uint64_t ust
= msc
* screen_priv
->fake_interval
;
93 uint64_t now
= GetTimeInMicros();
94 INT32 delay
= ((int64_t) (ust
- now
)) / 1000;
95 present_fake_vblank_ptr fake_vblank
;
98 present_fake_notify(screen
, event_id
);
102 fake_vblank
= calloc (1, sizeof (present_fake_vblank_rec
));
106 fake_vblank
->screen
= screen
;
107 fake_vblank
->event_id
= event_id
;
108 fake_vblank
->timer
= TimerSet(NULL
, 0, delay
, present_fake_do_timer
, fake_vblank
);
109 if (!fake_vblank
->timer
) {
114 xorg_list_add(&fake_vblank
->list
, &fake_vblank_queue
);
120 present_fake_screen_init(ScreenPtr screen
)
122 present_screen_priv_ptr screen_priv
= present_screen_priv(screen
);
124 /* For screens with hardware vblank support, the fake code
125 * will be used for off-screen windows and while screens are blanked,
126 * in which case we want a slow interval here
128 * Otherwise, pretend that the screen runs at 60Hz
130 if (screen_priv
->info
&& screen_priv
->info
->get_crtc
)
131 screen_priv
->fake_interval
= 1000000;
133 screen_priv
->fake_interval
= 16667;
137 present_fake_queue_init(void)
139 xorg_list_init(&fake_vblank_queue
);