1
2 #include <gtk/gtk.h>
3
4 #include "appdata.h"
5 #include "callbacks.h"
6 #include "interface.h"
7 #include "support.h"
8 #include "tests.h"
9 #include "timing.h"
10
11
12 /* Global AppData variable */
13 AppData *appdata;
14
15
16 void
perform_test_type(AppData * data)17 perform_test_type (AppData * data)
18 {
19
20 switch (data->test_type)
21 {
22
23 case 1:
24 add_test_info (data, "GtkEntry");
25 data->test_idle_id = g_idle_add (on_idle_gtkentry_test, data);
26 break;
27
28 case 2:
29 add_test_info (data, "GtkComboBox");
30 data->test_idle_id =
31 g_idle_add (on_idle_gtkcombobox_test, data);
32 break;
33
34 case 3:
35 add_test_info (data, "GtkComboBoxEntry");
36 data->test_idle_id =
37 g_idle_add (on_idle_gtkcomboboxentry_test, data);
38 break;
39
40 case 4:
41 add_test_info (data, "GtkSpinButton");
42 data->test_idle_id =
43 g_idle_add (on_idle_gtkspinbutton_test, data);
44 break;
45
46 case 5:
47 add_test_info (data, "GtkProgressBar");
48 data->test_idle_id =
49 g_idle_add (on_idle_gtkprogressbar_test, data);
50 break;
51
52 case 6:
53 add_test_info (data, "GtkToggleButton");
54 data->test_idle_id =
55 g_idle_add (on_idle_gtktogglebutton_test, data);
56 break;
57
58 case 7:
59 add_test_info (data, "GtkCheckButton");
60 data->test_idle_id =
61 g_idle_add (on_idle_gtkcheckbutton_test, data);
62 break;
63
64 case 8:
65 add_test_info (data, "GtkRadioButton");
66 data->test_idle_id =
67 g_idle_add (on_idle_gtkradiobutton_test, data);
68 break;
69
70 case 9:
71 add_test_info (data, "GtkTextView - Add text");
72 data->test_idle_id =
73 g_idle_add (on_idle_gtktextview_addtext_test, data);
74 break;
75
76 case 10:
77 add_test_info (data, "GtkTextView - Scroll");
78 data->test_idle_id =
79 g_idle_add (on_idle_gtktextview_scroll_test, data);
80 break;
81
82 case 11:
83 add_test_info (data, "GtkDrawingArea - Lines");
84 data->test_idle_id =
85 g_idle_add (on_idle_gtkdrawingarea_lines_test, data);
86 break;
87
88 case 12:
89 add_test_info (data, "GtkDrawingArea - Circles");
90 data->test_idle_id =
91 g_idle_add (on_idle_gtkdrawingarea_circles_test,
92 data);
93 break;
94
95 case 13:
96 add_test_info (data, "GtkDrawingArea - Text");
97 data->test_idle_id =
98 g_idle_add (on_idle_gtkdrawingarea_text_test, data);
99 break;
100
101 case 14:
102 add_test_info (data, "GtkDrawingArea - Pixbufs");
103 data->test_idle_id =
104 g_idle_add (on_idle_gtkdrawingarea_pixbufs_test,
105 data);
106 break;
107
108 default:
109
110 /* testing has ended */
111 /* report end time */
112 add_test_info_end (data);
113 gtk_notebook_set_current_page (data->notebook_main, 0);
114 if (appdata->scripted)
115 {
116 on_cleanup_and_exit(); /*test*/
117 }
118 }
119
120 /* record start time for each test */
121 data->time_start_test = get_time ();
122 }
123
124
125 void
on_button_start_clicked(GtkButton * button,gpointer user_data)126 on_button_start_clicked (GtkButton * button, gpointer user_data)
127 {
128
129 gtk_notebook_set_current_page (appdata->notebook_main, 1);
130
131 /* get test count */
132 appdata->test_count_selected =
133 gtk_spin_button_get_value_as_int (GTK_SPIN_BUTTON
134 (appdata->
135 spinbutton_count));
136 appdata->test_count = appdata->test_count_selected;
137
138 /* get test type */
139 appdata->test_type =
140 gtk_combo_box_get_active (GTK_COMBO_BOX
141 (appdata->combobox_testtype));
142 if (appdata->test_type > 0)
143 {
144 appdata->test_only_one = TRUE;
145 }
146 else
147 {
148 appdata->test_only_one = FALSE;
149 appdata->test_type = 1;
150 }
151
152 /* Add statup info */
153 add_test_info_start (appdata);
154
155 /* reset test widgets state */
156 reset_test_widgets ();
157
158 /* enable idle callback */
159 appdata->idle_id = g_idle_add (on_idle, appdata);
160 }
161
162
163 void
on_cmdline_run_all()164 on_cmdline_run_all ()
165 {
166 gtk_notebook_set_current_page (appdata->notebook_main, 1);
167
168 /* get test count */
169 if (appdata->test_count_selected != DEFAULT_COUNT) {
170 appdata->test_count_selected =
171 gtk_spin_button_get_value_as_int (GTK_SPIN_BUTTON
172 (appdata->
173 spinbutton_count));
174 appdata->test_count = appdata->test_count_selected;
175 }
176
177 /* get test type */
178 appdata->test_type =
179 gtk_combo_box_get_active (GTK_COMBO_BOX
180 (appdata->combobox_testtype));
181 if (appdata->test_type > 0)
182 {
183 appdata->test_only_one = TRUE;
184 }
185 else
186 {
187 appdata->test_only_one = FALSE;
188 appdata->test_type = 1;
189 }
190
191 /* Add statup info */
192 add_test_info_start (appdata);
193
194 /* reset test widgets state */
195 reset_test_widgets ();
196
197 /* enable idle callback */
198 appdata->idle_id = g_idle_add (on_idle, appdata);
199 }
200
201
202 void
on_cmdline_help()203 on_cmdline_help () {
204 g_print("Usage: gtkperf [OPTION]...\n");
205 g_print("GtkPerf is an application designed to test GTK+ performance.\n");
206 g_print("\n");
207 g_print("Options:\n");
208 g_print(" -h, --help display this help and exit\n");
209 g_print(" -a, --automatic start the testing automatically and exit when ready\n");
210 g_print(" -c, --count=COUNT used testing count (default 100)\n");
211 g_print("\n");
212 }
213
214
215 void
on_cmdline_count(char * optarg)216 on_cmdline_count (char *optarg)
217 {
218 appdata->test_count_selected = atoi(optarg);
219 }
220
221
222 /* Initialize appdata */
223 void
setup_appdata(AppData * appdata_in)224 setup_appdata(AppData * appdata_in)
225 {
226
227 appdata = (AppData *) appdata_in;
228
229 appdata->textview_text_scroll_type = GTK_SCROLL_STEP_FORWARD;
230 appdata->idle_id = 0;
231 appdata->test_idle_id = 0;
232 appdata->test_count = 0;
233 appdata->test_count_selected = DEFAULT_COUNT;
234 appdata->test_type = 0;
235 appdata->test_state_data = 0;
236 appdata->test_only_one = FALSE;
237 }
238
239
240 /* Initialize UI */
241 void
on_window_main_show(AppData * appdata_in)242 on_window_main_show (AppData * appdata_in)
243 {
244
245 appdata = (AppData *) appdata_in;
246
247 /* Getting buffers of text views */
248 appdata->textview_text_buffer =
249 gtk_text_view_get_buffer (GTK_TEXT_VIEW
250 (appdata->textview_text));
251 appdata->textview_info_buffer =
252 gtk_text_view_get_buffer (GTK_TEXT_VIEW
253 (appdata->textview_info));
254
255 /* setup widgets */
256 setup_widgets ();
257
258 gtk_notebook_set_current_page (appdata->notebook_main, 0);
259
260 gtk_spin_button_set_value (GTK_SPIN_BUTTON
261 (appdata->spinbutton_count),
262 appdata->test_count_selected);
263
264 /* Set help text */
265 gtk_text_buffer_set_text (gtk_text_view_get_buffer
266 (GTK_TEXT_VIEW (appdata->textview_help)),
267 _
268 ("GtkPerf - \xC2\xA9 2005 Kaj Gr\303\266nholm\n==========\nGtkPerf is "
269 "an application designed to test GTK+ performance. The point is to "
270 "create common testing platform to run predefined GTK+ widgets "
271 "(opening comboboxes, toggling buttons, scrolling text etc.) and this "
272 "way define the speed of device/platform.\n\n\nTests\n==========\n\n"
273 "The tests are separate from each other with the same main logic: "
274 "making single test operation (opening combo box, drawing n circles, "
275 "etc.) and waiting for that to get processed are returned to g_idle. "
276 "So every test is jumping between test function and g_idle as fast as "
277 "possible. \n\nThese tests are provided (in 0.30).\n\n"
278 "GtkEntry (on_idle_gtkentry_test)\n----------\n"
279 "Switches between \"Test String\" and \"Longer test string\" texts for "
280 "[count] times.\n\n\n"
281 "GtkComboBox (on_idle_gtkcombobox_test)\n----------\n"
282 "GtkComboBox contains 10 entrys \"Selection 1\"...\"Selection 10\". "
283 "This test opens and closes GtkComboBox [count] times while selecting "
284 "next entry.\n\n\n"
285 "GtkComboBoxEntry (on_idle_gtkcomboboxentry_test)\n----------\n"
286 "GtkComboBoxEntry contains 10 entrys \"Selection 1\"...\"Selection 10\". "
287 "This test opens and closes GtkComboBoxEntry [count] times while "
288 "selecting next entry.\n\n\n"
289 "GtkSpinButton (on_idle_gtkspinbutton_test)\n----------\n"
290 "GtkSpinButton value is increased with one [count] times. "
291 "When 1000 is reached, value is changed back to 0.\n\n\n"
292 "GtkProgressBar (on_idle_gtkprogressbar_test)\n-----\n"
293 "GtkProgressBar is increased with 1% [count] times. Whenever bar gets "
294 "full, its value is set to 0.\n\n\n"
295 "GtkToggleButton (on_idle_gtktogglebutton_test)\n----------\n"
296 "GtkToggleButton state is toggled between on/off [count] times.\n\n\n"
297 "GtkCheckButton (on_idle_gtkcheckbutton_test)\n----------\n"
298 "GtkCheckButton state is toggled between on/off [count] times.\n\n\n"
299 "GtkRadioButton (on_idle_gtkradiobutton_test)\n----------\n"
300 "Two GtkRadioButtons inside same group are witched to be selected "
301 "alternately [count] times.\n\n\n"
302 "GtkTextView - Add text (on_idle_gtktextview_addtext_test)\n----------\n"
303 "Text \"Future is Open. \" is appended to GtkTextView [count] times.\n\n\n"
304 "GtkTextView - Scroll (on_idle_gtktextview_scroll_test)\n----------\n"
305 "Scrolls the text added in earlier test GTK_SCROLL_STEP_FORWARD and when "
306 "end is reached GTK_SCROLL_STEP_BACKWARD for [count times.\n\n\n"
307 "GtkDrawingArea - Lines (on_idle_gtkdrawingarea_lines_test)\n----------\n"
308 "Draws random size and color lines to GtkDrawingArea for 1000*[count] "
309 "times.\n\n\n"
310 "GtkDrawingArea - Circles (on_idle_gtkdrawingarea_circles_test)\n----------\n"
311 "Draws random size and color circles to GtkDrawingArea for 1000*[count] "
312 "times.\n\n\n"
313 "GtkDrawingArea - Text (on_idle_gtkdrawingarea_text_test)\n----------\n"
314 "Draws random size and color \"Future is Open.\" strings with "
315 "PangoLayout to GtkDrawingArea for 100*[count] times. Font used is "
316 "\"Sans Bold 16\".\n\n\n"
317 "GtkDrawingArea - Pixbuf (on_idle_gtkdrawingarea_pixbufs_test)\n----------\n"
318 "Draws Duck.png to random place in GtkDrawingArea for 10*[count] "
319 "times.\n"), -1);
320 }
321
322
323 gboolean
on_cleanup_and_exit()324 on_cleanup_and_exit()
325 {
326 g_print("Quitting..\n");
327 gtk_main_quit();
328 return FALSE;
329 }
330
331
332 gboolean
on_window_main_delete_event(GtkWidget * widget,GdkEvent * event,gpointer user_data)333 on_window_main_delete_event (GtkWidget * widget,
334 GdkEvent * event, gpointer user_data)
335 {
336 return on_cleanup_and_exit();
337 }
338
339 void
setup_widgets()340 setup_widgets ()
341 {
342
343 /* Add strings to comboboxes */
344 gtk_combo_box_append_text (GTK_COMBO_BOX (appdata->combobox_entrys),
345 "selection 1");
346 gtk_combo_box_append_text (GTK_COMBO_BOX (appdata->combobox_entrys),
347 "selection 2");
348 gtk_combo_box_append_text (GTK_COMBO_BOX (appdata->combobox_entrys),
349 "selection 3");
350 gtk_combo_box_append_text (GTK_COMBO_BOX (appdata->combobox_entrys),
351 "selection 4");
352 gtk_combo_box_append_text (GTK_COMBO_BOX (appdata->combobox_entrys),
353 "selection 5");
354 gtk_combo_box_append_text (GTK_COMBO_BOX (appdata->combobox_entrys),
355 "selection 6");
356 gtk_combo_box_append_text (GTK_COMBO_BOX (appdata->combobox_entrys),
357 "selection 7");
358 gtk_combo_box_append_text (GTK_COMBO_BOX (appdata->combobox_entrys),
359 "selection 8");
360 gtk_combo_box_append_text (GTK_COMBO_BOX (appdata->combobox_entrys),
361 "selection 9");
362 gtk_combo_box_append_text (GTK_COMBO_BOX (appdata->combobox_entrys),
363 "selection 10");
364
365 gtk_combo_box_append_text (GTK_COMBO_BOX
366 (appdata->comboboxentry_entrys),
367 "selection 1");
368 gtk_combo_box_append_text (GTK_COMBO_BOX
369 (appdata->comboboxentry_entrys),
370 "selection 2");
371 gtk_combo_box_append_text (GTK_COMBO_BOX
372 (appdata->comboboxentry_entrys),
373 "selection 3");
374 gtk_combo_box_append_text (GTK_COMBO_BOX
375 (appdata->comboboxentry_entrys),
376 "selection 4");
377 gtk_combo_box_append_text (GTK_COMBO_BOX
378 (appdata->comboboxentry_entrys),
379 "selection 5");
380 gtk_combo_box_append_text (GTK_COMBO_BOX
381 (appdata->comboboxentry_entrys),
382 "selection 6");
383 gtk_combo_box_append_text (GTK_COMBO_BOX
384 (appdata->comboboxentry_entrys),
385 "selection 7");
386 gtk_combo_box_append_text (GTK_COMBO_BOX
387 (appdata->comboboxentry_entrys),
388 "selection 8");
389 gtk_combo_box_append_text (GTK_COMBO_BOX
390 (appdata->comboboxentry_entrys),
391 "selection 9");
392 gtk_combo_box_append_text (GTK_COMBO_BOX
393 (appdata->comboboxentry_entrys),
394 "selection 10");
395
396 gchar *filename = g_build_filename (PACKAGE_PIXMAPS_DIR,
397 "duck.png", NULL);
398 appdata->pixbuf_drawing = gdk_pixbuf_new_from_file (filename, NULL);
399
400 gtk_combo_box_set_active (GTK_COMBO_BOX (appdata->combobox_testtype),
401 0);
402
403 /* create end mark to info textview */
404 GtkTextIter iter;
405 gtk_text_buffer_get_end_iter (appdata->textview_info_buffer, &iter);
406 appdata->end_mark_info =
407 gtk_text_buffer_create_mark (GTK_TEXT_BUFFER
408 (appdata->textview_info_buffer),
409 NULL, &iter, TRUE);
410
411 /* add version info to statusbar */
412 gtk_statusbar_push (GTK_STATUSBAR (appdata->statusbar_main), 0,
413 APP_VERSION);
414
415 }
416
417 /* Reset the stage of all testing widgets before starting the new test */
418 void
reset_test_widgets()419 reset_test_widgets ()
420 {
421
422 gtk_entry_set_text (GTK_ENTRY (appdata->entry_entrys), "");
423 gtk_combo_box_set_active (GTK_COMBO_BOX
424 (appdata->comboboxentry_entrys), 0);
425 gtk_combo_box_set_active (GTK_COMBO_BOX
426 (appdata->combobox_entrys), 0);
427 gtk_spin_button_set_value (GTK_SPIN_BUTTON
428 (appdata->spinbutton_entrys), 0);
429 gtk_progress_bar_set_fraction (GTK_PROGRESS_BAR
430 (appdata->progressbar_entrys), 0.0);
431 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON
432 (appdata->togglebutton_buttons), FALSE);
433 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON
434 (appdata->checkbutton_buttons), FALSE);
435 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON
436 (appdata->radiobutton_buttons_1), TRUE);
437 gtk_text_buffer_set_text (appdata->textview_text_buffer, "", 0);
438
439 }
440
441
442 void
set_random_drawing_color()443 set_random_drawing_color ()
444 {
445
446 appdata->current_color.red = g_random_int_range (1, 65535);
447 appdata->current_color.green = g_random_int_range (1, 65535);
448 appdata->current_color.blue = g_random_int_range (1, 65535);
449
450 gdk_colormap_alloc_color (gdk_colormap_get_system (),
451 &appdata->current_color, FALSE, TRUE);
452 gdk_gc_set_foreground (appdata->graphical_context,
453 &appdata->current_color);
454 }
455
456 void
on_button_clear_clicked(GtkButton * button,gpointer user_data)457 on_button_clear_clicked (GtkButton * button, gpointer user_data)
458 {
459 gtk_text_buffer_set_text (appdata->textview_info_buffer, "", 0);
460 }
461