Exemplo n.º 1
0
bool Connection::is_xim_sync_reply_timeout(void)
{
    struct timeval cur_time, time_spent;
    X_GETTIMEOFDAY(&cur_time);
    TIMEDELTA(time_spent, cur_time, mSyncStartTime);
    if (time_spent.tv_sec >= XIM_SYNC_REPLY_TIMEOUT_SEC) {
	fprintf(stderr, "Warning: XIM_SYNC_REPLY timeout\n");
	return true;
    } else
	return false;
}
Exemplo n.º 2
0
static void AdjustHowLong (
	unsigned long *howlong,
	struct timeval *start_time)
{
	struct timeval new_time, time_spent, lstart_time;

	lstart_time = *start_time;
	X_GETTIMEOFDAY (&new_time);
	FIXUP_TIMEVAL(new_time);
	TIMEDELTA(time_spent, new_time, lstart_time);
	if(*howlong <= (unsigned long)(time_spent.tv_sec*1000+time_spent.tv_usec/1000))
	    *howlong = (unsigned long)0;  /* Timed out */
	else
	    *howlong -= (time_spent.tv_sec*1000+time_spent.tv_usec/1000);
}
Exemplo n.º 3
0
static void AdjustTimes (
    XtAppContext app,
    Boolean block,
    unsigned long* howlong,
    Boolean ignoreTimers,
    wait_times_ptr_t wt)
{
    if (app->timerQueue != NULL && !ignoreTimers && block) {
	if (IS_AFTER (wt->cur_time, app->timerQueue->te_timer_value)) {
	    TIMEDELTA (wt->wait_time, app->timerQueue->te_timer_value, wt->cur_time);
	    if (howlong == NULL || IS_AFTER (wt->wait_time, wt->max_wait_time))
#ifndef USE_POLL
		wt->wait_time_ptr = &wt->wait_time;
	    else
		wt->wait_time_ptr = &wt->max_wait_time;
	} else
	    wt->wait_time_ptr = &zero_time;
    }
#else
		wt->poll_wait = wt->wait_time.tv_sec * 1000 + wt->wait_time.tv_usec / 1000;
	    else
Exemplo n.º 4
0
int APIENTRY glutGet (GLenum type)
{
   
   switch (type) {
   case GLUT_WINDOW_RGBA:
      return 1;
   case GLUT_ELAPSED_TIME: {
      static int inited = 0;
      static struct timeval elapsed, beginning, now;
      if (!inited) {
	 gettimeofday(&beginning, 0);
	 inited = 1;
      }
      gettimeofday(&now, 0);
      TIMEDELTA(elapsed, now, beginning);
      /* Return elapsed milliseconds. */
      return (int) ((elapsed.tv_sec * 1000) + (elapsed.tv_usec / 1000));
   }
   default:
      return 0;
   }
}
Exemplo n.º 5
0
/* CENTRY */
int GLUTAPIENTRY
glutGet(GLenum param)
{
    Window win, root;
    int x, y, value;
    unsigned int width, height, border, depth;

    switch (param) {
    case GLUT_INIT_WINDOW_X:
        return __glutInitX;
    case GLUT_INIT_WINDOW_Y:
        return __glutInitY;
    case GLUT_INIT_WINDOW_WIDTH:
        return __glutInitWidth;
    case GLUT_INIT_WINDOW_HEIGHT:
        return __glutInitHeight;
    case GLUT_INIT_DISPLAY_MODE:
        return __glutDisplayMode;
    case GLUT_WINDOW_X:
        XTranslateCoordinates(__glutDisplay, __glutCurrentWindow->win,
                              __glutRoot, 0, 0, &x, &y, &win);
        return x;
    case GLUT_WINDOW_Y:
        XTranslateCoordinates(__glutDisplay, __glutCurrentWindow->win,
                              __glutRoot, 0, 0, &x, &y, &win);
        return y;
    case GLUT_WINDOW_WIDTH:
        if (!__glutCurrentWindow->reshape) {
            XGetGeometry(__glutDisplay, __glutCurrentWindow->win,
                         &root, &x, &y,
                         &width, &height, &border, &depth);
            return width;
        }
        return __glutCurrentWindow->width;
    case GLUT_WINDOW_HEIGHT:
        if (!__glutCurrentWindow->reshape) {
            XGetGeometry(__glutDisplay, __glutCurrentWindow->win,
                         &root, &x, &y,
                         &width, &height, &border, &depth);
            return height;
        }
        return __glutCurrentWindow->height;
#ifdef __OS2__
#define GET_CONFIG(attrib) \
  { if (__glutCurrentWindow->renderWin == __glutCurrentWindow->win)  \
       glXGetConfig( __glutCurrentWindow->vis, attrib, &value); \
    else  \
    glXGetConfig(__glutCurrentWindow->overlay->vis, attrib, &value); \
  } \

#else

#define GET_CONFIG(attrib) { \
  if (__glutCurrentWindow->renderWin == __glutCurrentWindow->win) { \
    glXGetConfig(__glutDisplay, __glutCurrentWindow->vis, \
      attrib, &value); \
  } else { \
    glXGetConfig(__glutDisplay, __glutCurrentWindow->overlay->vis, \
      attrib, &value); \
  } \
}
#endif

    case GLUT_WINDOW_BUFFER_SIZE:
        GET_CONFIG(GLX_BUFFER_SIZE);
        return value;
    case GLUT_WINDOW_STENCIL_SIZE:
        GET_CONFIG(GLX_STENCIL_SIZE);
        return value;
    case GLUT_WINDOW_DEPTH_SIZE:
        GET_CONFIG(GLX_DEPTH_SIZE);
        return value;
    case GLUT_WINDOW_RED_SIZE:
        GET_CONFIG(GLX_RED_SIZE);
        return value;
    case GLUT_WINDOW_GREEN_SIZE:
        GET_CONFIG(GLX_GREEN_SIZE);
        return value;
    case GLUT_WINDOW_BLUE_SIZE:
        GET_CONFIG(GLX_BLUE_SIZE);
        return value;
    case GLUT_WINDOW_ALPHA_SIZE:
        GET_CONFIG(GLX_ALPHA_SIZE);
        return value;
    case GLUT_WINDOW_ACCUM_RED_SIZE:
        GET_CONFIG(GLX_ACCUM_RED_SIZE);
        return value;
    case GLUT_WINDOW_ACCUM_GREEN_SIZE:
        GET_CONFIG(GLX_ACCUM_GREEN_SIZE);
        return value;
    case GLUT_WINDOW_ACCUM_BLUE_SIZE:
        GET_CONFIG(GLX_ACCUM_BLUE_SIZE);
        return value;
    case GLUT_WINDOW_ACCUM_ALPHA_SIZE:
        GET_CONFIG(GLX_ACCUM_ALPHA_SIZE);
        return value;
    case GLUT_WINDOW_DOUBLEBUFFER:
        GET_CONFIG(GLX_DOUBLEBUFFER);
        return value;
    case GLUT_WINDOW_RGBA:
        GET_CONFIG(GLX_RGBA);
        return value;
    case GLUT_WINDOW_COLORMAP_SIZE:
        GET_CONFIG(GLX_RGBA);
        if (value) {
            return 0;
        } else {
#if defined(_WIN32) || defined(__OS2__)
            /* KLUDGE: we always assume 256 colors in CI mode on
               Win32 */
            return 256;
#else
            if (__glutCurrentWindow->renderWin == __glutCurrentWindow->win) {
                return __glutCurrentWindow->vis->visual->map_entries;
            } else {
                return __glutCurrentWindow->overlay->vis->visual->map_entries;
            }
#endif /* _WIN32 */
        }
    case GLUT_WINDOW_PARENT:
        return __glutCurrentWindow->parent ?
               __glutCurrentWindow->parent->num + 1 : 0;
    case GLUT_WINDOW_NUM_CHILDREN:
    {
        int num = 0;
        GLUTwindow *children = __glutCurrentWindow->children;

        while (children) {
            num++;
            children = children->siblings;
        }
        return num;
    }
    case GLUT_WINDOW_NUM_SAMPLES:
#if defined(GLX_VERSION_1_1) && defined(GLX_SGIS_multisample)
        if (__glutIsSupportedByGLX("GLX_SGIS_multisample")) {
            GET_CONFIG(GLX_SAMPLES_SGIS);
            return value;
        } else {
            return 0;
        }
#else
        /* Independent of GLX server support, multisampling not
           supported by GLX client-side. */
        return 0;
#endif
    case GLUT_WINDOW_STEREO:
        GET_CONFIG(GLX_STEREO);
        return value;
    case GLUT_WINDOW_CURSOR:
        return __glutCurrentWindow->cursor;
    case GLUT_SCREEN_WIDTH:
        return DisplayWidth(__glutDisplay, __glutScreen);
    case GLUT_SCREEN_HEIGHT:
        return DisplayHeight(__glutDisplay, __glutScreen);
    case GLUT_SCREEN_WIDTH_MM:
        return DisplayWidthMM(__glutDisplay, __glutScreen);
    case GLUT_SCREEN_HEIGHT_MM:
        return DisplayHeightMM(__glutDisplay, __glutScreen);
    case GLUT_MENU_NUM_ITEMS:
        return __glutCurrentMenu->num;
    case GLUT_DISPLAY_MODE_POSSIBLE:
    {
        XVisualInfo *vi;
        Bool dummy, visAlloced;
        void *fbc;

#if defined(_WIN32)
        /* Our fake glXChooseVisual (which is called by
           __glutDetermineVisual) needs an HDC to work with, so grab one
           from the "root" window. */
        XHDC = GetDC(GetDesktopWindow());
#endif
        vi = __glutDetermineWindowVisual(&dummy, &visAlloced, &fbc);
#if defined(_WIN32)
        ReleaseDC(GetDesktopWindow(), XHDC);
#endif
        if (vi) {
            if (visAlloced)
                XFree(vi);
            return 1;
        }
        return 0;
    }
    case GLUT_ELAPSED_TIME:
    {
#ifdef OLD_VMS
        struct timeval6 elapsed, beginning, now;
#else
        struct timeval elapsed, beginning, now;
#endif

        __glutInitTime(&beginning);
        GETTIMEOFDAY(&now);
        TIMEDELTA(elapsed, now, beginning);
        /* Return elapsed milliseconds. */
#if defined(__vms) && ( __VMS_VER < 70000000 )
        return (int) (elapsed.val / TICKS_PER_MILLISECOND);
#else
        return (int) ((elapsed.tv_sec * 1000) + (elapsed.tv_usec / 1000));
#endif
    }
    case GLUT_WINDOW_FORMAT_ID:
#if defined(__OS2__)
        return wglGetPixelFormat(__glutCurrentWindow->hdc);
#elif defined(_WIN32)
        return GetPixelFormat(__glutCurrentWindow->hdc);
#else
        if (__glutCurrentWindow->renderWin == __glutCurrentWindow->win) {
            return (int) __glutCurrentWindow->vis->visualid;
        } else {
            return (int) __glutCurrentWindow->overlay->vis->visualid;
        }
#endif
    default:
        __glutWarning("invalid glutGet parameter: %d", param);
        return -1;
    }
}
Exemplo n.º 6
0
static void
waitForSomething(void)
{
#if defined(__vms) && ( __VMS_VER < 70000000 )
  static struct timeval6 zerotime =
  {0};
  unsigned int timer_efn;
#define timer_id 'glut' /* random :-) number */
  unsigned int wait_mask;
#else
  static struct timeval zerotime =
  {0, 0};
#if !defined(_WIN32)
  fd_set fds;
#endif
#endif
#ifdef OLD_VMS
   struct timeval6 now, timeout, waittime;
#else
   struct timeval now, timeout, waittime;
#endif
#if !defined(_WIN32)
  int rc;
#endif

  /* Flush X protocol since XPending does not do this
     implicitly. */
  XFlush(__glutDisplay);
  if (XPending(__glutDisplay)) {
    /* It is possible (but quite rare) that XFlush may have
       needed to wait for a writable X connection file
       descriptor, and in the process, may have had to read off
       X protocol from the file descriptor. If XPending is true,
       this case occured and we should avoid waiting in select
       since X protocol buffered within Xlib is due to be
       processed and potentially no more X protocol is on the
       file descriptor, so we would risk waiting improperly in
       select. */
    goto immediatelyHandleXinput;
  }
#if defined(__vms) && ( __VMS_VER < 70000000 )
  timeout = __glutTimerList->timeout;
  GETTIMEOFDAY(&now);
  wait_mask = 1 << (__glutConnectionFD & 31);
  if (IS_AFTER(now, timeout)) {
    /* We need an event flag for the timer. */
    /* XXX The `right' way to do this is to use LIB$GET_EF, but
       since it needs to be in the same cluster as the EFN for
       the display, we will have hack it. */
    timer_efn = __glutConnectionFD - 1;
    if ((timer_efn / 32) != (__glutConnectionFD / 32)) {
      timer_efn = __glutConnectionFD + 1;
    }
    rc = SYS$CLREF(timer_efn);
    rc = SYS$SETIMR(timer_efn, &timeout, NULL, timer_id, 0);
    wait_mask |= 1 << (timer_efn & 31);
  } else {
    timer_efn = 0;
  }
  rc = SYS$WFLOR(__glutConnectionFD, wait_mask);
  if (timer_efn != 0 && SYS$CLREF(timer_efn) == SS$_WASCLR) {
    rc = SYS$CANTIM(timer_id, PSL$C_USER);
  }
  /* XXX There does not seem to be checking of "rc" in the code
     above.  Can any of the SYS$ routines above fail? */
#else /* not vms6.2 or lower */
#if !defined(_WIN32)
  FD_ZERO(&fds);
  FD_SET(__glutConnectionFD, &fds);
#endif
  timeout = __glutTimerList->timeout;
  GETTIMEOFDAY(&now);
  if (IS_AFTER(now, timeout)) {
    TIMEDELTA(waittime, timeout, now);
  } else {
    waittime = zerotime;
  }
#if !defined(_WIN32)
  rc = select(__glutConnectionFD + 1, &fds,
    NULL, NULL, &waittime);
  if (rc < 0 && errno != EINTR)
    __glutFatalError("select error.");
#else

  MsgWaitForMultipleObjects(0, NULL, FALSE,
    waittime.tv_sec*1000 + waittime.tv_usec/1000, QS_ALLINPUT);

#endif
#endif /* not vms6.2 or lower */
  /* Without considering the cause of select unblocking, check
     for pending X events and handle any timeouts (by calling
     processEventsAndTimeouts).  We always look for X events
     even if select returned with 0 (indicating a timeout);
     otherwise we risk starving X event processing by continous
     timeouts. */
  if (XPending(__glutDisplay)) {
  immediatelyHandleXinput:
    processEventsAndTimeouts();
  } else {
    if (__glutTimerList)
      handleTimeouts();
  }
}