~canonical-dx-team/ubuntu/maverick/gtk+2.0/menuproxy

« back to all changes in this revision

Viewing changes to tests/testrgb.c

  • Committer: Bazaar Package Importer
  • Author(s): Sebastien Bacher
  • Date: 2007-05-04 12:24:25 UTC
  • mfrom: (1.1.21 upstream)
  • Revision ID: james.westby@ubuntu.com-20070504122425-0m8midgzrp40y8w2
Tags: 2.10.12-1ubuntu1
* Sync with Debian
* New upstream version:
  Fixed bugs:
  - 379414 file chooser warnings when changing path in the entry
  - 418585 GtkFileChooserDefault sizing code is not DPI independent
  - 419568 Crash in search if start with special letter
  - 435062 build dies with icon cache validation
  - 379399 Segfault to call gtk_print_operation_run twice.
  - 387889 cups backend has problems when there are too many printers
  - 418531 invalid read to gtkicontheme.c gtk_icon_theme_lookup_icon...
  - 423916 crash in color scheme code
  - 424042 Segmentation fault while quickly pressing Alt+arrows
  - 415260 Protect against negative indices when setting values in G...
  - 419171 XGetVisualInfo() may not set nxvisuals
  - 128852 Gdk cursors don't look good on win32
  - 344657 Ctrl-H doesn't toggle "Show Hidden Files" setting
  - 345345 PrintOperation::paginate is not emitted for class handler
  - 347567 GtkPrintOperation::end-print is not emitted if it's cance...
  - 369112 gtk_ui_manager_add_ui should accept unnamed separator
  - 392015 Selected menu item invisible on Windows Vista
  - 399253 MS-Windows Theme Bottom Tab placement rendering glitches
  - 399425 gtk_input_dialog_fill_axes() adds child to gtkscrolledwin...
  - 403251 [patch] little memory leak in GtkPrintJob
  - 403267 [patch] memory leak in GtkPageSetupUnixDialog
  - 403470 MS-Windows Theme tab placement other than on top leaks a ...
  - 404506 Windows system fonts that have multi-byte font names cann...
  - 405089 Incorrect window placement for GtkEventBox private window
  - 405515 Minor leak in gtkfilesystemmodel.c
  - 405539 gdk_pixbuf_save() for PNG saver can return FALSE without ...
  - 415681 gdk_window_clear_area includes an extra line and column o...
  - 418219 GtkRecentChooser should apply filter before sorting and c...
  - 418403 Scroll to printer after selecting it from settings
  - 421985 _gtk_print_operation_platform_backend_launch_preview
  - 421990 gtk_print_job_get_surface
  - 421993 gtk_print_operation_init
  - 423064 Conditional jump or move depends on uninitialised value(s...
  - 423722 Fix printing header in gtk-demo
  - 424168 gtk_print_operation_run on async preview
  - 425655 Don't install gtk+-unix-print-2.0.pc on non-UNIX platforms
  - 425786 GDK segfaults if XineramaQueryScreens fails
  - 428665 Lpr Backend gets stuck in infinite loop during gtk_enumer...
  - 429902 GtkPrintOperation leaks cairo contextes
  - 431997 First delay of GdkPixbufAnimationIter is wrong
  - 433242 Inconsistent scroll arrow position calculations
  - 433972 Placing gtk.Expander inside a gtk.TextView() changes gtk....
  - 434261 _gtk_toolbar_elide_underscores incorrectly handles some s...
  - 383354 ctrl-L should make 'Location' entry disappear
  - 418673 gtk_recent_manager_add_item
  - 429732 gtk_accel_group_finalize accesses invalid memory
  - 435028 WM_CLIENT_LEADER is wrong on the leader_window
  - 431067 Background of the header window is not updated
  - 338843 add recent files support inside the ui manager
  - 148535 add drop shadow to menus, tooltips, etc. under Windows XP
* debian/control.in:
  - Conflicts on ubuntulooks (<= 0.9.11-1)
* debian/patches/15_default-fallback-icon-theme.patch:
  - patch from Debian, fallback on gnome icon theme

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* GTK - The GIMP Toolkit
 
2
 * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
 
3
 *
 
4
 * This library is free software; you can redistribute it and/or
 
5
 * modify it under the terms of the GNU Lesser General Public
 
6
 * License as published by the Free Software Foundation; either
 
7
 * version 2 of the License, or (at your option) any later version.
 
8
 *
 
9
 * This library is distributed in the hope that it will be useful,
 
10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 
12
 * Lesser General Public License for more details.
 
13
 *
 
14
 * You should have received a copy of the GNU Lesser General Public
 
15
 * License along with this library; if not, write to the
 
16
 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
 
17
 * Boston, MA 02111-1307, USA.
 
18
 */
 
19
 
 
20
#include <config.h>
 
21
 
 
22
#include <glib.h>
 
23
 
 
24
/*
 
25
 * Modified by the GTK+ Team and others 1997-2000.  See the AUTHORS
 
26
 * file for a list of people on the GTK+ Team.  See the ChangeLog
 
27
 * files for a list of changes.  These files are distributed with
 
28
 * GTK+ at ftp://ftp.gtk.org/pub/gtk/. 
 
29
 */
 
30
 
 
31
 
 
32
/* Note: these #includes differ slightly from the testrgb.c file included
 
33
   in the GdkRgb release. */
 
34
 
 
35
#include <stdlib.h>
 
36
#ifdef HAVE_UNISTD_H
 
37
#include <unistd.h>
 
38
#endif
 
39
#include <string.h>
 
40
 
 
41
#include "gtk/gtk.h"
 
42
 
 
43
static void
 
44
quit_func (GtkWidget *widget, gpointer dummy)
 
45
{
 
46
  gtk_main_quit ();
 
47
}
 
48
 
 
49
#define WIDTH 640
 
50
#define HEIGHT 400
 
51
#define NUM_ITERS 50
 
52
 
 
53
static void
 
54
testrgb_rgb_test (GtkWidget *drawing_area)
 
55
{
 
56
  guchar *buf;
 
57
  gint i, j;
 
58
  gint offset;
 
59
  guchar val;
 
60
  gdouble start_time, total_time;
 
61
  gint x, y;
 
62
  gboolean dither;
 
63
  int dith_max;
 
64
  GTimer *timer;
 
65
  GdkPixbuf *pixbuf;
 
66
  gboolean to_pixmap;
 
67
  
 
68
  buf = g_malloc (WIDTH * HEIGHT * 8);
 
69
 
 
70
  val = 0;
 
71
  for (j = 0; j < WIDTH * HEIGHT * 8; j++)
 
72
    {
 
73
      val = (val + ((val + (rand () & 0xff)) >> 1)) >> 1;
 
74
      buf[j] = val;
 
75
    }
 
76
 
 
77
  /* Let's warm up the cache, and also wait for the window manager
 
78
     to settle. */
 
79
  for (i = 0; i < NUM_ITERS; i++)
 
80
    {
 
81
      offset = (rand () % (WIDTH * HEIGHT * 3)) & -4;
 
82
      gdk_draw_rgb_image (drawing_area->window,
 
83
                          drawing_area->style->white_gc,
 
84
                          0, 0, WIDTH, HEIGHT,
 
85
                          GDK_RGB_DITHER_NONE,
 
86
                          buf + offset, WIDTH * 3);
 
87
    }
 
88
 
 
89
  if (gdk_rgb_ditherable ())
 
90
    dith_max = 2;
 
91
  else
 
92
    dith_max = 1;
 
93
 
 
94
  timer = g_timer_new ();
 
95
  for (dither = 0; dither < dith_max; dither++)
 
96
    {
 
97
      start_time = g_timer_elapsed (timer, NULL);
 
98
      for (i = 0; i < NUM_ITERS; i++)
 
99
        {
 
100
          offset = (rand () % (WIDTH * HEIGHT * 3)) & -4;
 
101
          gdk_draw_rgb_image (drawing_area->window,
 
102
                              drawing_area->style->white_gc,
 
103
                              0, 0, WIDTH, HEIGHT,
 
104
                              dither ? GDK_RGB_DITHER_MAX :
 
105
                              GDK_RGB_DITHER_NONE,
 
106
                              buf + offset, WIDTH * 3);
 
107
        }
 
108
      gdk_flush ();
 
109
      total_time = g_timer_elapsed (timer, NULL) - start_time;
 
110
      g_print ("Color test%s time elapsed: %.2fs, %.1f fps, %.2f megapixels/s\n",
 
111
               dither ? " (dithered)" : "",
 
112
               total_time,
 
113
               NUM_ITERS / total_time,
 
114
               NUM_ITERS * (WIDTH * HEIGHT * 1e-6) / total_time);
 
115
    }
 
116
 
 
117
  for (dither = 0; dither < dith_max; dither++)
 
118
    {
 
119
      start_time = g_timer_elapsed (timer, NULL);
 
120
      for (i = 0; i < NUM_ITERS; i++)
 
121
        {
 
122
          offset = (rand () % (WIDTH * HEIGHT)) & -4;
 
123
          gdk_draw_gray_image (drawing_area->window,
 
124
                               drawing_area->style->white_gc,
 
125
                               0, 0, WIDTH, HEIGHT,
 
126
                               dither ? GDK_RGB_DITHER_MAX :
 
127
                               GDK_RGB_DITHER_NONE,
 
128
                               buf + offset, WIDTH);
 
129
        }
 
130
      gdk_flush ();
 
131
      total_time = g_timer_elapsed (timer, NULL) - start_time;
 
132
      g_print ("Grayscale test%s time elapsed: %.2fs, %.1f fps, %.2f megapixels/s\n",
 
133
               dither ? " (dithered)" : "",
 
134
               total_time,
 
135
               NUM_ITERS / total_time,
 
136
               NUM_ITERS * (WIDTH * HEIGHT * 1e-6) / total_time);
 
137
    }
 
138
 
 
139
  for (to_pixmap = FALSE; to_pixmap <= TRUE; to_pixmap++)
 
140
    {
 
141
      if (to_pixmap)
 
142
        {
 
143
          GdkRectangle rect = { 0, 0, WIDTH, HEIGHT };
 
144
          gdk_window_begin_paint_rect (drawing_area->window, &rect);
 
145
        }
 
146
        
 
147
      start_time = g_timer_elapsed (timer, NULL);
 
148
      for (i = 0; i < NUM_ITERS; i++)
 
149
        {
 
150
          offset = (rand () % (WIDTH * HEIGHT * 4)) & -4;
 
151
          pixbuf = gdk_pixbuf_new_from_data (buf + offset, GDK_COLORSPACE_RGB, TRUE,
 
152
                                             8, WIDTH, HEIGHT, WIDTH * 4,
 
153
                                             NULL, NULL);
 
154
          gdk_draw_pixbuf (drawing_area->window, drawing_area->style->black_gc,
 
155
                           pixbuf,
 
156
                           0, 0, 0, 0, WIDTH, HEIGHT,
 
157
                           GDK_RGB_DITHER_NORMAL,
 
158
                           0, 0);
 
159
          g_object_unref (pixbuf);
 
160
        }
 
161
      gdk_flush ();
 
162
      total_time = g_timer_elapsed (timer, NULL) - start_time;
 
163
 
 
164
      if (to_pixmap)
 
165
        gdk_window_end_paint (drawing_area->window);
 
166
      
 
167
      g_print ("Alpha test%s time elapsed: %.2fs, %.1f fps, %.2f megapixels/s\n",
 
168
               to_pixmap ? " (to pixmap)" : "",
 
169
               total_time,
 
170
               NUM_ITERS / total_time,
 
171
               NUM_ITERS * (WIDTH * HEIGHT * 1e-6) / total_time);
 
172
    }
 
173
      
 
174
  g_print ("Please submit these results to http://www.levien.com/gdkrgb/survey.html\n");
 
175
 
 
176
#if 1
 
177
  for (x = 0; x < WIDTH; x++)
 
178
    {
 
179
      int cindex;
 
180
 
 
181
      cindex = (x * 8) / WIDTH;
 
182
      buf[x * 3] = cindex & 4 ? 0 : 255;
 
183
      buf[x * 3 + 1] = cindex & 2 ? 0 : 255;
 
184
      buf[x * 3 + 2] = cindex & 1 ? 0 : 255;
 
185
    }
 
186
  for (y = 1; y < (HEIGHT * 19) / 32; y++)
 
187
    {
 
188
      memcpy (buf + y * WIDTH * 3, buf, WIDTH * 3);
 
189
    }
 
190
  for (; y < (HEIGHT * 20) / 32; y++)
 
191
    {
 
192
      for (x = 0; x < WIDTH; x++)
 
193
        {
 
194
          guchar gray;
 
195
 
 
196
          gray = (x * 255) / (WIDTH - 1);
 
197
          buf[y * WIDTH * 3 + x * 3] = gray;
 
198
          buf[y * WIDTH * 3 + x * 3 + 1] = 0;
 
199
          buf[y * WIDTH * 3 + x * 3 + 2] = 0;
 
200
        }
 
201
    }
 
202
  for (; y < (HEIGHT * 21) / 32; y++)
 
203
    {
 
204
      for (x = 0; x < WIDTH; x++)
 
205
        {
 
206
          guchar gray;
 
207
 
 
208
          gray = (x * 255) / (WIDTH - 1);
 
209
          buf[y * WIDTH * 3 + x * 3] = 0;
 
210
          buf[y * WIDTH * 3 + x * 3 + 1] = gray;
 
211
          buf[y * WIDTH * 3 + x * 3 + 2] = 0;
 
212
        }
 
213
    }
 
214
  for (; y < (HEIGHT * 22) / 32; y++)
 
215
    {
 
216
      for (x = 0; x < WIDTH; x++)
 
217
        {
 
218
          guchar gray;
 
219
 
 
220
          gray = (x * 255) / (WIDTH - 1);
 
221
          buf[y * WIDTH * 3 + x * 3] = 0;
 
222
          buf[y * WIDTH * 3 + x * 3 + 1] = 0;
 
223
          buf[y * WIDTH * 3 + x * 3 + 2] = gray;
 
224
        }
 
225
    }
 
226
  for (; y < (HEIGHT * 24) / 32; y++)
 
227
    {
 
228
      for (x = 0; x < WIDTH; x++)
 
229
        {
 
230
          guchar gray;
 
231
 
 
232
          gray = 112 + (x * 31) / (WIDTH - 1);
 
233
          buf[y * WIDTH * 3 + x * 3] = gray;
 
234
          buf[y * WIDTH * 3 + x * 3 + 1] = gray;
 
235
          buf[y * WIDTH * 3 + x * 3 + 2] = gray;
 
236
        }
 
237
    }
 
238
  for (; y < (HEIGHT * 26) / 32; y++)
 
239
    {
 
240
      for (x = 0; x < WIDTH; x++)
 
241
        {
 
242
          guchar gray;
 
243
 
 
244
          gray = (x * 255) / (WIDTH - 1);
 
245
          buf[y * WIDTH * 3 + x * 3] = gray;
 
246
          buf[y * WIDTH * 3 + x * 3 + 1] = gray;
 
247
          buf[y * WIDTH * 3 + x * 3 + 2] = gray;
 
248
        }
 
249
    }
 
250
 
 
251
  for (; y < HEIGHT; y++)
 
252
    {
 
253
      for (x = 0; x < WIDTH; x++)
 
254
        {
 
255
          int cindex;
 
256
          guchar gray;
 
257
 
 
258
          cindex = (x * 16) / WIDTH;
 
259
          gray = cindex < 3 ? 0 :
 
260
            cindex < 5 ? 255 :
 
261
            cindex < 7 ? 128 :
 
262
            0;
 
263
          buf[y * WIDTH * 3 + x * 3] = gray;
 
264
          buf[y * WIDTH * 3 + x * 3 + 1] = gray;
 
265
          buf[y * WIDTH * 3 + x * 3 + 2] = gray;
 
266
        }
 
267
    }
 
268
  gdk_draw_rgb_image (drawing_area->window,
 
269
                      drawing_area->style->white_gc,
 
270
                      0, 0, WIDTH, HEIGHT, GDK_RGB_DITHER_MAX,
 
271
                      buf, WIDTH * 3);
 
272
#endif
 
273
}
 
274
 
 
275
void
 
276
new_testrgb_window (void)
 
277
{
 
278
  GtkWidget *window;
 
279
  GtkWidget *vbox;
 
280
  GtkWidget *button;
 
281
  GtkWidget *drawing_area;
 
282
 
 
283
  window = gtk_widget_new (gtk_window_get_type (),
 
284
                           "GtkObject::user_data", NULL,
 
285
                           "GtkWindow::type", GTK_WINDOW_TOPLEVEL,
 
286
                           "GtkWindow::title", "testrgb",
 
287
                           "GtkWindow::allow_shrink", FALSE,
 
288
                           NULL);
 
289
  g_signal_connect (window, "destroy",
 
290
                    G_CALLBACK (quit_func), NULL);
 
291
 
 
292
  vbox = gtk_vbox_new (FALSE, 0);
 
293
 
 
294
  drawing_area = gtk_drawing_area_new ();
 
295
 
 
296
  gtk_widget_set_size_request (drawing_area, WIDTH, HEIGHT);
 
297
  gtk_box_pack_start (GTK_BOX (vbox), drawing_area, FALSE, FALSE, 0);
 
298
  gtk_widget_show (drawing_area);
 
299
 
 
300
  button = gtk_button_new_with_label ("Quit");
 
301
  gtk_box_pack_start (GTK_BOX (vbox), button, FALSE, FALSE, 0);
 
302
  g_signal_connect_swapped (button, "clicked",
 
303
                            G_CALLBACK (gtk_widget_destroy), window);
 
304
 
 
305
  gtk_widget_show (button);
 
306
 
 
307
  gtk_container_add (GTK_CONTAINER (window), vbox);
 
308
  gtk_widget_show (vbox);
 
309
 
 
310
  gtk_widget_show (window);
 
311
 
 
312
  testrgb_rgb_test (drawing_area);
 
313
}
 
314
 
 
315
int
 
316
main (int argc, char **argv)
 
317
{
 
318
  gtk_init (&argc, &argv);
 
319
 
 
320
  gdk_rgb_set_verbose (TRUE);
 
321
 
 
322
  gtk_widget_set_default_colormap (gdk_rgb_get_colormap ());
 
323
  new_testrgb_window ();
 
324
 
 
325
  gtk_main ();
 
326
 
 
327
  return 0;
 
328
}