Drop GLcontext typedef and use struct gl_context instead
[mesa.git] / src / mesa / drivers / dri / common / vblank.c
index dc2cbcc84d4ad78cae91d96e801ed18514bd2d45..cb98dd0b3a38a8396cb64b0d6652e610c55e700d 100644 (file)
  * Authors:
  *    Ian Romanick <idr@us.ibm.com>
  */
-/* $XFree86:$ */
 
-#include "glheader.h"
+#include "main/glheader.h"
 #include "xf86drm.h"
-#include "mtypes.h"
-#include "macros.h"
-#include "dd.h"
+#include "main/mtypes.h"
+#include "main/macros.h"
+#include "main/dd.h"
 #include "vblank.h"
 #include "xmlpool.h"
 
-static unsigned int msc_to_vblank(__DRIdrawablePrivate * dPriv, int64_t msc)
+static unsigned int msc_to_vblank(__DRIdrawable * dPriv, int64_t msc)
 {
    return (unsigned int)(msc - dPriv->msc_base + dPriv->vblank_base);
 }
 
-static int64_t vblank_to_msc(__DRIdrawablePrivate * dPriv, unsigned int vblank)
+static int64_t vblank_to_msc(__DRIdrawable * dPriv, unsigned int vblank)
 {
    return (int64_t)(vblank - dPriv->vblank_base + dPriv->msc_base);
 }
@@ -65,8 +64,8 @@ static int64_t vblank_to_msc(__DRIdrawablePrivate * dPriv, unsigned int vblank)
  * \return       Zero is returned on success.  A negative errno value
  *               is returned on failure.
  */
-int driDrawableGetMSC32( __DRIscreenPrivate * priv,
-                        __DRIdrawablePrivate * dPriv,
+int driDrawableGetMSC32( __DRIscreen * priv,
+                        __DRIdrawable * dPriv,
                         int64_t * count)
 {
    drmVBlank vbl;
@@ -123,7 +122,7 @@ int driDrawableGetMSC32( __DRIscreenPrivate * priv,
  * \return            Zero on success or \c GLX_BAD_CONTEXT on failure.
  */
 
-int driWaitForMSC32( __DRIdrawablePrivate *priv,
+int driWaitForMSC32( __DRIdrawable *priv,
                     int64_t target_msc, int64_t divisor, int64_t remainder,
                     int64_t * msc )
 {
@@ -131,9 +130,8 @@ int driWaitForMSC32( __DRIdrawablePrivate *priv,
 
 
    if ( divisor != 0 ) {
-      unsigned int target = (unsigned int)target_msc;
-      unsigned int next = target;
-      unsigned int r;
+      int64_t next = target_msc;
+      int64_t r;
       int dont_wait = (target_msc == 0);
 
       do {
@@ -155,9 +153,9 @@ int driWaitForMSC32( __DRIdrawablePrivate *priv,
 
         *msc = vblank_to_msc(priv, vbl.reply.sequence);
 
-         dont_wait = 0;
-         if (target_msc != 0 && *msc == target)
+         if (!dont_wait && *msc == next)
             break;
+         dont_wait = 0;
 
          /* Assuming the wait-done test fails, the next refresh to wait for
           * will be one that satisfies (MSC % divisor) == remainder.  The
@@ -166,11 +164,12 @@ int driWaitForMSC32( __DRIdrawablePrivate *priv,
           * If this refresh has already happened, we add divisor to obtain 
           * the next refresh after the current one that will satisfy it.
           */
-         r = (*msc % (unsigned int)divisor);
-         next = (*msc - r + (unsigned int)remainder);
-         if (next <= *msc) next += (unsigned int)divisor;
+         r = ((uint64_t)*msc % divisor);
+         next = (*msc - r + remainder);
+         if (next <= *msc)
+           next += divisor;
 
-      } while ( r != (unsigned int)remainder );
+      } while (r != remainder);
    }
    else {
       /* If the \c divisor is zero, just wait until the MSC is greater
@@ -242,7 +241,7 @@ GLuint driGetDefaultVBlankFlags( const driOptionCache *optionCache )
  * the first time the \c drmWaitVBlank fails.  If \c drmWaitVBlank is
  * successful, \c vbl_seq will be set the sequence value in the reply.
  *
- * \param vbl      Pointer to drmVBlank packet desribing how to wait.
+ * \param vbl      Pointer to drmVBlank packet describing how to wait.
  * \param vbl_seq  Location to store the current refresh counter.
  * \param fd       File descriptor use to call into the DRM.
  * \return         Zero on success or -1 on failure.
@@ -279,7 +278,7 @@ static int do_wait( drmVBlank * vbl, GLuint * vbl_seq, int fd )
  */
 
 static unsigned
-driGetDefaultVBlankInterval( const  __DRIdrawablePrivate *priv )
+driGetDefaultVBlankInterval( const  __DRIdrawable *priv )
 {
    if ( (priv->vblFlags & (VBLANK_FLAG_THROTTLE | VBLANK_FLAG_SYNC)) != 0 ) {
       return 1;
@@ -296,7 +295,7 @@ driGetDefaultVBlankInterval( const  __DRIdrawablePrivate *priv )
  * direct rendering context.
  */
 
-void driDrawableInitVBlank( __DRIdrawablePrivate *priv )
+void driDrawableInitVBlank( __DRIdrawable *priv )
 {
    if ( priv->swap_interval == (unsigned)-1 &&
        !( priv->vblFlags & VBLANK_FLAG_NO_IRQ ) ) {
@@ -321,7 +320,7 @@ void driDrawableInitVBlank( __DRIdrawablePrivate *priv )
  */
 
 unsigned
-driGetVBlankInterval( const  __DRIdrawablePrivate *priv )
+driGetVBlankInterval( const  __DRIdrawable *priv )
 {
    if ( (priv->vblFlags & VBLANK_FLAG_INTERVAL) != 0 ) {
       /* this must have been initialized when the drawable was first bound
@@ -341,7 +340,7 @@ driGetVBlankInterval( const  __DRIdrawablePrivate *priv )
  */
 
 void
-driGetCurrentVBlank( __DRIdrawablePrivate *priv )
+driGetCurrentVBlank( __DRIdrawable *priv )
 {
    drmVBlank vbl;
 
@@ -367,7 +366,7 @@ driGetCurrentVBlank( __DRIdrawablePrivate *priv )
  */
 
 int
-driWaitForVBlank( __DRIdrawablePrivate *priv, GLboolean * missed_deadline )
+driWaitForVBlank( __DRIdrawable *priv, GLboolean * missed_deadline )
 {
    drmVBlank vbl;
    unsigned   original_seq;