diff options
Diffstat (limited to 'magnifier/zoom-region.c')
-rw-r--r-- | magnifier/zoom-region.c | 138 |
1 files changed, 33 insertions, 105 deletions
diff --git a/magnifier/zoom-region.c b/magnifier/zoom-region.c index b3dabfc..a3b426c 100644 --- a/magnifier/zoom-region.c +++ b/magnifier/zoom-region.c @@ -23,7 +23,6 @@ #include <stdlib.h> #include <string.h> #include <popt.h> -#include <sys/time.h> /* TODO: replace timeofday with g_timers */ #include <gdk/gdkwindow.h> #include <gtk/gtk.h> #ifdef USE_GDKPIXBUF_RENDER_TO_DRAWABLE @@ -107,82 +106,6 @@ typedef enum { ZOOM_REGION_ERROR_TOO_BIG } ZoomRegionPixmapCreationError; -/* - * When running the magnifier in timing test mode (--timing-pan-rate and/or --timing-iterations), - * then the following output is displayed: - * - * Pan Rate = 200 - * Frames Processed = 1225 - * Width/Height/Depth = 640/1024/8 - * Zoom Factor (x/y) = 3.000000/3.000000 - * Update Duration = (avg. 0.010232) (max. 0.002685) (tot. 1.084589) seconds - * Update Pixels = (avg. 3046) pixels/frame - * Update Rate = (avg. 97.732909) (max. 372.439485) updates/second - * Net Update Rate = (avg. 0.297724) (max. 0.457741) Mpex/second - * Pan Latency = (avg. 0.008229) (max. 0.562326) seconds - * Total Frame Duration = (avg. 0.008363) (max. 0.562485) (tot. 10.235981) seconds - * Frame Rate = (avg. 119.578189) (max. 4854.369141) frames/second - * Scroll Delta (x) = (avg. 0.000000) (tot. 0) lines - * Scroll Delta (y) = (avg. 5.019608) (tot. 6144) lines - * Scroll Rate (x) = (avg. 0.000000) lines/second - * Scroll Rate (y) = (avg. 600.235657) lines/second - * Net Render Rate = (avg. 8.685322) (max. 3181.359360) Mpex/second - * - * Pan Rate - Displays the pan rate specified on the command line. - * Only displayed if --timing-pan-rate is used. - * Frames Processed - Number of frames displayed - * Width/Height/Depth - The width/height/depth of magnifier display. - * Zoom Factor (x/y) - The zoom factor used. - * Update Duration - Average and total time spent updating new sections of the screen. - * Update Pixels - Number of pixels updated - * Update Rate - Number of updates possible per second. - * Net Update Rate - Number of Megapixels updated per second. - * Pan Latency - Time spent from the beginning of the setROI request until GTK+ - * has finished processing the update (in GDK's - * gdk_window_update_idle idle handler. - * Total Frame Duration - Average and total time processing frames. - * Frame Rate - Number of frames per second. - * Scroll Delta - Average and total number of lines scrolled. - * Scroll Rate - Number of lines scrolled per second. Note that this value - * will be equal to the --timing-pan-rate value times the - * y zoom factor. - * Net Render Rate - Number of Megapixels processed per second. - * - * When running with the --timing-output argument, similar information is displayed for - * each frame plus timing information for the frame. Update information is not - * displayed for frames where updates do not occur. Pan Rate, Frames Processed, - * and Width/Height/Depth is not displayed for each frame, only when displaying - * summary information. - */ - -typedef struct timing { - struct timeval process_start; - struct timeval process_end; - struct timeval frame_start; - struct timeval frame_end; - struct timeval scale_start; - struct timeval scale_end; - struct timeval idle_start; - struct timeval idle_end; - float scale_val; - float idle_val; - float frame_val; - int dx; - int dy; - float scale_total; - float idle_total; - float frame_total; - int dx_total; - int dy_total; - long update_pixels_total; - long num_scale_samples; - long num_idle_samples; - long num_frame_samples; - long num_line_samples; - float last_frame_val; - int last_dy; -} TimingStruct; - static float timing_scale_max = 0; static float timing_idle_max = 0; static float timing_frame_max = 0; @@ -193,7 +116,6 @@ static gboolean reset_timing = FALSE; static gboolean timing_test = FALSE; static guint pending_idle_handler = 0; -static TimingStruct mag_timing; static gboolean processing_updates = FALSE; static gboolean timing_start = FALSE; @@ -243,7 +165,7 @@ reset_timing_stats() mag_timing.dy_total = 0; mag_timing.last_frame_val = 0; mag_timing.last_dy = 0; - gettimeofday(&mag_timing.process_start, NULL); + g_timer_start (mag_timing.process); } /** DEBUG STUFF **/ @@ -863,7 +785,6 @@ zoom_region_paint_crosswire_cursor (ZoomRegion *zoom_region, GdkRectangle *clip_ GdkRectangle rect; GdkDrawable *cursor; GdkColor color = {0, 0, 0, 0}; - GdkColor tmp_color; int x_left_clip = 0, x_right_clip = 0, y_top_clip = 0, y_bottom_clip = 0; int csize = 0; @@ -1283,8 +1204,9 @@ zoom_region_expose_handler (GtkWindow * w, zoom_region_paint (zoom_region, &event->area); } -static void zoom_region_update_cursor (ZoomRegion *zoom_region, int dx, int dy, - GdkRectangle *clip_rect) +static void +zoom_region_update_cursor (ZoomRegion *zoom_region, int dx, int dy, + GdkRectangle *clip_rect) { #ifdef ZOOM_REGION_DEBUG g_assert (zoom_region->alive); @@ -1805,7 +1727,7 @@ zoom_region_update (ZoomRegion *zoom_region, if (subimage && zoom_region->priv->w && zoom_region->priv->w->window) { GdkRectangle paint_rect; - gettimeofday(&mag_timing.scale_start, NULL); + g_timer_start (mag_timing.scale); DEBUG_RECT ("source rect", source_rect); paint_rect = zoom_region_view_rect_from_source_rect (zoom_region, source_rect); /* paint_rect = zoom_region_clip_to_scaled_pixmap (zoom_region, paint_rect); */ @@ -1814,8 +1736,8 @@ zoom_region_update (ZoomRegion *zoom_region, _zoom_region_invert_pixbuf (subimage); /** - * XXX: We seem to be breaking with the original intention here, which was to - * keep a fullscreen scaled pixbuf in-sync. + * XXX: We seem to be breaking with the original intention + * here, which was to keep a fullscreen scaled pixbuf in-sync. **/ gdk_pixbuf_scale (subimage, zoom_region->priv->scaled_pixbuf, @@ -1870,13 +1792,15 @@ zoom_region_update (ZoomRegion *zoom_region, gdk_window_begin_paint_rect (zoom_region->priv->w->window, &paint_rect); zoom_region_paint (zoom_region, &paint_rect); gdk_window_end_paint (zoom_region->priv->w->window); - gettimeofday(&mag_timing.scale_end, NULL); + g_timer_stop (mag_timing.scale); if (timing_test) { mag_timing.num_scale_samples++; + + gulong microseconds; + mag_timing.scale_val = - (mag_timing.scale_end.tv_sec - mag_timing.scale_start.tv_sec) + - ((float)(mag_timing.scale_end.tv_usec - mag_timing.scale_start.tv_usec) / - 1000000.0); + g_timer_elapsed (mag_timing.scale, + µseconds); mag_timing.scale_total += mag_timing.scale_val; if (mag_timing.scale_val != 0 && (timing_scale_max == 0 || @@ -2049,10 +1973,12 @@ zoom_region_time_frame(ZoomRegion *zoom_region, Magnifier *magnifier) int height = magnifier->target_bounds.y2 - magnifier->target_bounds.y1; mag_timing.num_frame_samples++; - gettimeofday(&mag_timing.frame_end, NULL); - mag_timing.frame_val = (mag_timing.frame_end.tv_sec - mag_timing.frame_start.tv_sec) + - ((float)(mag_timing.frame_end.tv_usec - mag_timing.frame_start.tv_usec) / - 1000000.0); + g_timer_stop (mag_timing.frame); + + gulong microseconds; + + mag_timing.frame_val = g_timer_elapsed (mag_timing.frame, + µseconds); mag_timing.frame_total += mag_timing.frame_val; if (mag_timing.frame_val > timing_frame_max) @@ -2165,14 +2091,15 @@ gdk_timing_idle (gpointer data) /* Now update has finished, reset processing_updates */ processing_updates = FALSE; - gettimeofday(&mag_timing.idle_end, NULL); + g_timer_stop (mag_timing.idle); if (timing_test) { mag_timing.num_idle_samples++; - mag_timing.idle_val = - (mag_timing.idle_end.tv_sec - mag_timing.idle_start.tv_sec) + - ((float)(mag_timing.idle_end.tv_usec - mag_timing.idle_start.tv_usec) / - 1000000.0); + + gulong microseconds; + + mag_timing.idle_val = g_timer_elapsed (mag_timing.idle, + µseconds); mag_timing.idle_total += mag_timing.idle_val; if (mag_timing.idle_val > timing_idle_max) @@ -2199,7 +2126,7 @@ zoom_region_align (ZoomRegion *zoom_region) zoom_region_time_frame(zoom_region, magnifier); if (timing_test) { - gettimeofday(&mag_timing.frame_start, NULL); + g_timer_start (mag_timing.frame); if (zoom_region->timing_output) { gint x, y; @@ -2221,12 +2148,12 @@ zoom_region_align (ZoomRegion *zoom_region) * until we have processed an entire frame. */ if (!timing_start) - gettimeofday(&mag_timing.process_start, NULL); + g_timer_start (mag_timing.process); timing_start = TRUE; } - gettimeofday(&mag_timing.idle_start, NULL); + g_timer_start (mag_timing.idle); /* * zoom_region_align calls @@ -2556,10 +2483,11 @@ zoom_region_pan_test (gpointer data) roi.x1 = zoom_region->roi.x1; roi.x2 = zoom_region->roi.x2; - gettimeofday(&mag_timing.process_end, NULL); - total_time = (mag_timing.process_end.tv_sec - mag_timing.process_start.tv_sec) + - ((float)(mag_timing.process_end.tv_usec - mag_timing.process_start.tv_usec) / - 1000000.0); + g_timer_stop (mag_timing.process); + + gulong microseconds; + + total_time = g_timer_elapsed (mag_timing.process, µseconds); if (mag_timing.frame_total != 0.0) pixels_at_speed = total_time * zoom_region->timing_pan_rate; |