summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorOwen W. Taylor <otaylor@fishsoup.net>2013-01-24 22:43:10 -0500
committerOwen W. Taylor <otaylor@fishsoup.net>2013-01-25 00:36:48 -0500
commit36bbcb083156926f50c0b3c3e0b42e24f42fdbf7 (patch)
treeb4617f01f1a4a672acbbf1628b79463e07f98760
parent67bc4064ea0f63fdc3a751c4cf1df3edfeeceb2f (diff)
downloadcogl-36bbcb083156926f50c0b3c3e0b42e24f42fdbf7.tar.gz
Switch presentation time to nanoseconds
In the future, we may want to track frame timings with very high precision for profiling purposes, so to be consistent with that, use nanoseconds, not microseconds. 63-bits in nanoseconds is 270+ years, so hopefully clock_gettime(CLOCK_MONOTONIC,) will fit.
-rw-r--r--cogl/cogl-frame-info.h2
-rw-r--r--cogl/winsys/cogl-winsys-glx.c29
2 files changed, 15 insertions, 16 deletions
diff --git a/cogl/cogl-frame-info.h b/cogl/cogl-frame-info.h
index 9ddad0c7..08e4df68 100644
--- a/cogl/cogl-frame-info.h
+++ b/cogl/cogl-frame-info.h
@@ -88,7 +88,7 @@ int64_t cogl_frame_info_get_frame_counter (CoglFrameInfo *info);
* Gets the presentation time for the frame. This is the time at which
* the frame became visible to the user.
*
- * The presentation time measured in microseconds is based on a
+ * The presentation time measured in nanoseconds is based on a
* monotonic time source. The time source is not necessarily
* correlated with system/wall clock time and may represent the time
* elapsed since some undefined system event such as when the system
diff --git a/cogl/winsys/cogl-winsys-glx.c b/cogl/winsys/cogl-winsys-glx.c
index 88acd9d4..03a2e64e 100644
--- a/cogl/winsys/cogl-winsys-glx.c
+++ b/cogl/winsys/cogl-winsys-glx.c
@@ -234,9 +234,9 @@ ensure_ust_type (CoglRenderer *renderer,
}
static int64_t
-ust_to_monotonic_time (CoglRenderer *renderer,
- GLXDrawable drawable,
- int64_t ust)
+ust_to_nanoseconds (CoglRenderer *renderer,
+ GLXDrawable drawable,
+ int64_t ust)
{
CoglGLXRenderer *glx_renderer = renderer->winsys;
@@ -257,13 +257,13 @@ ust_to_monotonic_time (CoglRenderer *renderer,
gettimeofday(&tv, NULL);
clock_gettime (CLOCK_MONOTONIC, &ts);
current_system_time = (tv.tv_sec * G_GINT64_CONSTANT (1000000)) + tv.tv_usec;
- current_monotonic_time = (ts.tv_sec * G_GINT64_CONSTANT (1000000)) +
- (ts.tv_nsec / G_GINT64_CONSTANT (1000));
+ current_monotonic_time =
+ ts.tv_sec * G_GINT64_CONSTANT (1000000000) + ts.tv_nsec;
- return ust + current_monotonic_time - current_system_time;
+ return current_monotonic_time + 1000 * (ust - current_system_time);
}
case COGL_GLX_UST_IS_MONOTONIC_TIME:
- return ust;
+ return 1000 * ust;
case COGL_GLX_UST_IS_OTHER:
/* In this case the scale of UST is undefined so we can't easily
* scale to nanoseconds.
@@ -320,9 +320,9 @@ notify_swap_buffers (CoglContext *context, GLXBufferSwapComplete *swap_event)
CoglFrameInfo *info = cogl_onscreen_get_frame_info (onscreen, frame_counter);
info->presentation_time =
- ust_to_monotonic_time (context->display->renderer,
- glx_onscreen->glxwin,
- swap_event->ust);
+ ust_to_nanoseconds (context->display->renderer,
+ glx_onscreen->glxwin,
+ swap_event->ust);
}
set_info_complete (onscreen);
@@ -1438,9 +1438,9 @@ _cogl_winsys_wait_for_vblank (CoglOnscreen *onscreen)
glx_renderer->glXWaitForMsc (xlib_renderer->xdpy, drawable,
0, 2, (msc + 1) % 2,
&ust, &msc, &sbc);
- info->presentation_time = ust_to_monotonic_time (ctx->display->renderer,
- drawable,
- ust);
+ info->presentation_time = ust_to_nanoseconds (ctx->display->renderer,
+ drawable,
+ ust);
}
else
{
@@ -1454,8 +1454,7 @@ _cogl_winsys_wait_for_vblank (CoglOnscreen *onscreen)
clock_gettime (CLOCK_MONOTONIC, &ts);
info->presentation_time =
- (ts.tv_sec * G_GINT64_CONSTANT (1000000)) +
- (ts.tv_nsec / G_GINT64_CONSTANT (1000));
+ ts.tv_sec * G_GINT64_CONSTANT (1000000000) + ts.tv_nsec;
}
}
}