e8550b281244ed2332783d350adf335858565834
[mesa.git] / src / mesa / drivers / dri / common / vblank.h
1 /* -*- mode: c; c-basic-offset: 3 -*- */
2 /*
3 * (c) Copyright IBM Corporation 2002
4 * All Rights Reserved.
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the "Software"),
8 * to deal in the Software without restriction, including without limitation
9 * on the rights to use, copy, modify, merge, publish, distribute, sub
10 * license, and/or sell copies of the Software, and to permit persons to whom
11 * the Software is furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice (including the next
14 * paragraph) shall be included in all copies or substantial portions of the
15 * Software.
16 *
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
20 * VA LINUX SYSTEM, IBM AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM,
21 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
22 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
23 * USE OR OTHER DEALINGS IN THE SOFTWARE.
24 *
25 * Authors:
26 * Ian Romanick <idr@us.ibm.com>
27 */
28 /* $XFree86:$ */
29
30 #ifndef DRI_VBLANK_H
31 #define DRI_VBLANK_H
32
33 #include "context.h"
34 #include "dri_util.h"
35 #include "xmlconfig.h"
36
37 #define VBLANK_FLAG_INTERVAL (1U << 0) /* Respect the swap_interval setting
38 */
39 #define VBLANK_FLAG_THROTTLE (1U << 1) /* Wait 1 refresh since last call.
40 */
41 #define VBLANK_FLAG_SYNC (1U << 2) /* Sync to the next refresh.
42 */
43 #define VBLANK_FLAG_NO_IRQ (1U << 7) /* DRM has no IRQ to wait on.
44 */
45 #define VBLANK_FLAG_SECONDARY (1U << 8) /* Wait for secondary vblank.
46 */
47
48 extern int driGetMSC32( __DRIscreenPrivate * priv, int64_t * count );
49 extern int driDrawableGetMSC32( __DRIscreenPrivate * priv,
50 __DRIdrawablePrivate * drawablePrivate,
51 int64_t * count);
52 extern int driWaitForMSC32( __DRIdrawablePrivate *priv,
53 int64_t target_msc, int64_t divisor, int64_t remainder, int64_t * msc );
54 extern GLuint driGetDefaultVBlankFlags( const driOptionCache *optionCache );
55 extern void driDrawableInitVBlank ( __DRIdrawablePrivate *priv );
56 extern unsigned driGetVBlankInterval( const __DRIdrawablePrivate *priv,
57 GLuint flags );
58 extern void driGetCurrentVBlank( const __DRIdrawablePrivate *priv,
59 GLuint flags, GLuint *vbl_seq );
60 extern int driWaitForVBlank( const __DRIdrawablePrivate *priv,
61 GLuint * vbl_seq, GLuint flags, GLboolean * missed_deadline );
62
63 #undef usleep
64 #include <unistd.h> /* for usleep() */
65 #include <sched.h> /* for sched_yield() */
66
67 #ifdef linux
68 #include <sched.h> /* for sched_yield() */
69 #endif
70
71 #define DO_USLEEP(nr) \
72 do { \
73 if (0) fprintf(stderr, "%s: usleep for %u\n", __FUNCTION__, nr ); \
74 if (1) usleep( nr ); \
75 sched_yield(); \
76 } while( 0 )
77
78 #endif /* DRI_VBLANK_H */