1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
|
/*
* hardinfo2 - System Information and Benchmark
* Copyright (C) 2024-2024 hwspeedy - hardinfo2 project
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, version 2 or later.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include <gtk/gtk.h>
#include <cairo.h>
#include "iconcache.h"
#include "config.h"
#define CRUNCH_TIME 3
static int count=0;
static int testnumber=0;
static GTimer *timer,*frametimer;
static gdouble score = 0.0f;
static GdkPixbuf *pixbufs[3];
static GRand *r;
double *frametime;
int *framecount;
gboolean on_draw (GtkWidget *widget, GdkEventExpose *event, gpointer data) {
#if GTK_CHECK_VERSION(3,0,0)
const int divfactor[5]={2231,2122,2113,2334,2332};
#else //Note: OLD GTK does not do the same amount of work
const int divfactor[5]={12231,12122,12113,12334,12332};
#endif
const int iterations[5]={100,300,100,300,100};
int i;
cairo_t * cr;
GdkWindow* window = gtk_widget_get_window(widget);
cairo_region_t * cairoRegion = cairo_region_create();
#if GTK_CHECK_VERSION(3,0,0)
GdkDrawingContext * drawingContext;
drawingContext = gdk_window_begin_draw_frame (window,cairoRegion);
cr = gdk_drawing_context_get_cairo_context (drawingContext);
#else
cr = gdk_cairo_create(window);
#endif
g_timer_continue(frametimer);
for (i = iterations[testnumber]; i >= 0; i--) {
switch(testnumber) {
case 0 : //Line Drawing
cairo_move_to(cr, g_rand_int_range(r,0,1024), g_rand_int_range(r,0,800));
cairo_set_source_rgb(cr,g_rand_double_range(r,0,1),g_rand_double_range(r,0,1),g_rand_double_range(r,0,1));
cairo_line_to(cr, g_rand_int_range(r,0,1024), g_rand_int_range(r,0,800));
cairo_stroke(cr);
break;
case 1 : //Shape Drawing
cairo_rectangle(cr,g_rand_int_range(r,0,1024-200),g_rand_int_range(r,0,800-200),g_rand_int_range(r,0,400),g_rand_int_range(r,0,300));
cairo_set_source_rgb(cr,g_rand_double_range(r,0,1),g_rand_double_range(r,0,1),g_rand_double_range(r,0,1));
cairo_stroke(cr);
break;
case 2 : //Filled Shape Drawing
cairo_rectangle(cr,g_rand_int_range(r,0,1024-200),g_rand_int_range(r,0,800-200),g_rand_int_range(r,0,400),g_rand_int_range(r,0,300));
cairo_set_source_rgb(cr,g_rand_double_range(r,0,1),g_rand_double_range(r,0,1),g_rand_double_range(r,0,1));
cairo_fill(cr);
break;
case 3 : //Text Drawing
cairo_move_to(cr,g_rand_int_range(r,0,1024-100),g_rand_int_range(r,0,800));
cairo_set_font_size(cr,25);
cairo_set_source_rgb(cr,g_rand_double_range(r,0,1),g_rand_double_range(r,0,1),g_rand_double_range(r,0,1));
cairo_show_text(cr, "I \342\231\245 hardinfo2");
break;
//
case 4 : //Icon Blitting
gdk_cairo_set_source_pixbuf (cr, pixbufs[g_rand_int_range(r,0,3)],g_rand_int_range(r,0,1024-64), g_rand_int_range(r,0,800-64));
cairo_paint(cr);
break;
}
}
g_timer_stop(frametimer);
#if GTK_CHECK_VERSION(3,0,0)
gdk_window_end_draw_frame(window,drawingContext);
#endif
count++;
if(g_timer_elapsed(timer, NULL)<CRUNCH_TIME) {
gtk_widget_queue_draw_area(widget,0,0,1024,800);
} else {
score += ((double)iterations[testnumber]*count/g_timer_elapsed(frametimer,NULL)) / divfactor[testnumber];
frametime[testnumber]=g_timer_elapsed(frametimer,NULL);
framecount[testnumber]=count;
DEBUG("GPU Test %d => %d =>score:%f (frametime=%f)",testnumber,count,score,g_timer_elapsed(frametimer,NULL));
count=0;
testnumber++;
//Done
if(testnumber>=5){
gtk_main_quit();
} else {
g_timer_start(frametimer);
g_timer_stop(frametimer);
g_timer_start(timer);
gtk_widget_queue_draw_area(widget,0,0,1024,800);
}
}
// cleanup
cairo_region_destroy(cairoRegion);
return FALSE;
}
double guibench(double *frameTime, int *frameCount)
{
GtkWindow * window;
cairo_region_t *region;
cairo_t *cr;
frametime=frameTime;
framecount=frameCount;
DEBUG("GUIBENCH");
pixbufs[0] = gdk_pixbuf_scale_simple(icon_cache_get_pixbuf("hardinfo2.png"),64,64,GDK_INTERP_BILINEAR);
pixbufs[1] = gdk_pixbuf_scale_simple(icon_cache_get_pixbuf("syncmanager.png"),64,64,GDK_INTERP_BILINEAR);
pixbufs[2] = gdk_pixbuf_scale_simple(icon_cache_get_pixbuf("report-large.png"),64,64,GDK_INTERP_BILINEAR);
r = g_rand_new();
// window setup
window = (GtkWindow*)gtk_window_new(GTK_WINDOW_TOPLEVEL);
gtk_window_set_default_size (window, 1024, 800);
gtk_window_set_position (window, GTK_WIN_POS_CENTER);
gtk_window_set_title (window, "GPU Benchmarking...");
g_signal_connect(window, "destroy", gtk_main_quit, NULL);
// create the are we can draw in
GtkDrawingArea* drawingArea;
drawingArea = (GtkDrawingArea*) gtk_drawing_area_new();
gtk_container_add(GTK_CONTAINER(window), (GtkWidget*)drawingArea);
#if GTK_CHECK_VERSION(3,0,0)
g_signal_connect((GtkWidget*)drawingArea, "draw", G_CALLBACK(on_draw), NULL);
#else
g_signal_connect((GtkWidget*)drawingArea, "expose-event", G_CALLBACK(on_draw), NULL);
#endif
frametimer = g_timer_new();
g_timer_stop(frametimer);
timer = g_timer_new();
gtk_widget_show_all ((GtkWidget*)window);
gtk_main();
g_timer_destroy(timer);
g_timer_destroy(frametimer);
g_rand_free(r);
g_object_unref(pixbufs[0]);
g_object_unref(pixbufs[1]);
g_object_unref(pixbufs[2]);
return score;
}
|