comparison test/testblitspeed.c @ 1231:cf59e7b91ed4

testblitspeed.c improvements: cleaned up output, and allow user to set surface alpha attributes.
author Ryan C. Gordon <icculus@icculus.org>
date Thu, 05 Jan 2006 16:37:46 +0000
parents 68f2b997758e
children e49147870aac c121d94672cb
comparison
equal deleted inserted replaced
1230:88c2d6aed428 1231:cf59e7b91ed4
37 size_t strsize, Uint32 flag, 37 size_t strsize, Uint32 flag,
38 const char *flagstr) 38 const char *flagstr)
39 { 39 {
40 if (_surface->flags & flag) 40 if (_surface->flags & flag)
41 copy_trunc_str(str, strsize, flagstr); 41 copy_trunc_str(str, strsize, flagstr);
42 } /* append_sdl_surface_flag */ 42 }
43 43
44 44
45 #define append_sdl_surface_flag(a, b, c, fl) __append_sdl_surface_flag(a, b, c, fl, " " #fl) 45 #define append_sdl_surface_flag(a, b, c, fl) __append_sdl_surface_flag(a, b, c, fl, " " #fl)
46 #define print_tf_state(str, val) printf("%s: {%s}\n", str, (val) ? "true" : "false" ) 46 #define print_tf_state(str, val) printf("%s: {%s}\n", str, (val) ? "true" : "false" )
47 47
48 static void output_videoinfo_details(void)
49 {
50 const SDL_VideoInfo *info = SDL_GetVideoInfo();
51 printf("SDL_GetVideoInfo():\n");
52 if (info == NULL)
53 printf(" (null.)\n");
54 else
55 {
56 print_tf_state(" hardware surface available", info->hw_available);
57 print_tf_state(" window manager available", info->wm_available);
58 print_tf_state(" accelerated hardware->hardware blits", info->blit_hw);
59 print_tf_state(" accelerated hardware->hardware colorkey blits", info->blit_hw_CC);
60 print_tf_state(" accelerated hardware->hardware alpha blits", info->blit_hw_A);
61 print_tf_state(" accelerated software->hardware blits", info->blit_sw);
62 print_tf_state(" accelerated software->hardware colorkey blits", info->blit_sw_CC);
63 print_tf_state(" accelerated software->hardware alpha blits", info->blit_sw_A);
64 print_tf_state(" accelerated color fills", info->blit_fill);
65 printf(" video memory: (%d)\n", info->video_mem);
66 }
67
68 printf("\n");
69 }
70
48 static void output_surface_details(const char *name, SDL_Surface *surface) 71 static void output_surface_details(const char *name, SDL_Surface *surface)
49 { 72 {
50 printf("Details for %s:\n", name); 73 printf("Details for %s:\n", name);
51 74
52 if (surface == NULL) 75 if (surface == NULL)
54 printf("-WARNING- You've got a NULL surface!"); 77 printf("-WARNING- You've got a NULL surface!");
55 } 78 }
56 else 79 else
57 { 80 {
58 char f[256]; 81 char f[256];
59 printf(" width : %d\n", surface->w); 82 printf(" width : %d\n", surface->w);
60 printf(" height : %d\n", surface->h); 83 printf(" height : %d\n", surface->h);
61 printf(" depth : %d bits per pixel\n", surface->format->BitsPerPixel); 84 printf(" depth : %d bits per pixel\n", surface->format->BitsPerPixel);
62 printf(" pitch : %d\n", (int) surface->pitch); 85 printf(" pitch : %d\n", (int) surface->pitch);
63 86 printf(" alpha : %d\n", (int) surface->format->alpha);
64 printf(" red : 0x%08X mask, %d shift, %d loss\n", 87 printf(" colorkey : 0x%X\n", (unsigned int) surface->format->colorkey);
88
89 printf(" red bits : 0x%08X mask, %d shift, %d loss\n",
65 (int) surface->format->Rmask, 90 (int) surface->format->Rmask,
66 (int) surface->format->Rshift, 91 (int) surface->format->Rshift,
67 (int) surface->format->Rloss); 92 (int) surface->format->Rloss);
68 printf(" green : 0x%08X mask, %d shift, %d loss\n", 93 printf(" green bits : 0x%08X mask, %d shift, %d loss\n",
69 (int) surface->format->Gmask, 94 (int) surface->format->Gmask,
70 (int) surface->format->Gshift, 95 (int) surface->format->Gshift,
71 (int) surface->format->Gloss); 96 (int) surface->format->Gloss);
72 printf(" blue : 0x%08X mask, %d shift, %d loss\n", 97 printf(" blue bits : 0x%08X mask, %d shift, %d loss\n",
73 (int) surface->format->Bmask, 98 (int) surface->format->Bmask,
74 (int) surface->format->Bshift, 99 (int) surface->format->Bshift,
75 (int) surface->format->Bloss); 100 (int) surface->format->Bloss);
76 printf(" alpha : 0x%08X mask, %d shift, %d loss\n", 101 printf(" alpha bits : 0x%08X mask, %d shift, %d loss\n",
77 (int) surface->format->Amask, 102 (int) surface->format->Amask,
78 (int) surface->format->Ashift, 103 (int) surface->format->Ashift,
79 (int) surface->format->Aloss); 104 (int) surface->format->Aloss);
80 105
81 f[0] = '\0'; 106 f[0] = '\0';
102 append_sdl_surface_flag(surface, f, sizeof (f), SDL_PREALLOC); 127 append_sdl_surface_flag(surface, f, sizeof (f), SDL_PREALLOC);
103 128
104 if (f[0] == '\0') 129 if (f[0] == '\0')
105 strcpy(f, " (none)"); 130 strcpy(f, " (none)");
106 131
107 printf(" flags :%s\n", f); 132 printf(" flags :%s\n", f);
108 133 }
109 #if 0
110 info = SDL_GetVideoInfo();
111 assert(info != NULL);
112
113 print_tf_state("hardware surface available", info->hw_available);
114 print_tf_state("window manager available", info->wm_available);
115 print_tf_state("accelerated hardware->hardware blits", info->blit_hw);
116 print_tf_state("accelerated hardware->hardware colorkey blits", info->blit_hw_CC);
117 print_tf_state("accelerated hardware->hardware alpha blits", info->blit_hw_A);
118 print_tf_state("accelerated software->hardware blits", info->blit_sw);
119 print_tf_state("accelerated software->hardware colorkey blits", info->blit_sw_CC);
120 print_tf_state("accelerated software->hardware alpha blits", info->blit_sw_A);
121 print_tf_state("accelerated color fills", info->blit_fill);
122
123 printf("video memory: (%d)\n", info->video_mem);
124 #endif
125 } /* else */
126 134
127 printf("\n"); 135 printf("\n");
128 } 136 }
129 137
130 static void output_details(void) 138 static void output_details(void)
131 { 139 {
140 output_videoinfo_details();
132 output_surface_details("Source Surface", src); 141 output_surface_details("Source Surface", src);
133 output_surface_details("Destination Surface", dest); 142 output_surface_details("Destination Surface", dest);
134 } 143 }
135 144
136 static Uint32 blit(SDL_Surface *dst, SDL_Surface *src, int x, int y) 145 static Uint32 blit(SDL_Surface *dst, SDL_Surface *src, int x, int y)
193 Uint32 srcbmask = 0x000000FF; 202 Uint32 srcbmask = 0x000000FF;
194 Uint32 srcamask = 0x00000000; 203 Uint32 srcamask = 0x00000000;
195 Uint32 srcflags = 0; 204 Uint32 srcflags = 0;
196 int srcw = 640; 205 int srcw = 640;
197 int srch = 480; 206 int srch = 480;
207 Uint32 origsrcalphaflags = 0;
208 Uint32 origdstalphaflags = 0;
209 Uint32 srcalphaflags = 0;
210 Uint32 dstalphaflags = 0;
211 int srcalpha = 255;
212 int dstalpha = 255;
198 int screenSurface = 0; 213 int screenSurface = 0;
199 int i; 214 int i = 0;
200 215
201 for (i = 1; i < argc; i++) 216 for (i = 1; i < argc; i++)
202 { 217 {
203 const char *arg = argv[i]; 218 const char *arg = argv[i];
204 219
238 testSeconds = atoi(argv[++i]); 253 testSeconds = atoi(argv[++i]);
239 else if (strcmp(arg, "--screen") == 0) 254 else if (strcmp(arg, "--screen") == 0)
240 screenSurface = 1; 255 screenSurface = 1;
241 else if (strcmp(arg, "--dumpfile") == 0) 256 else if (strcmp(arg, "--dumpfile") == 0)
242 dumpfile = argv[++i]; 257 dumpfile = argv[++i];
243 else 258 /* !!! FIXME: set colorkey. */
259 else if (0) /* !!! FIXME: we handle some commandlines elsewhere now */
244 { 260 {
245 fprintf(stderr, "Unknown commandline option: %s\n", arg); 261 fprintf(stderr, "Unknown commandline option: %s\n", arg);
246 return(0); 262 return(0);
247 } 263 }
248 } 264 }
285 { 301 {
286 fprintf(stderr, "src surface creation failed: %s\n", SDL_GetError()); 302 fprintf(stderr, "src surface creation failed: %s\n", SDL_GetError());
287 SDL_Quit(); 303 SDL_Quit();
288 return(0); 304 return(0);
289 } 305 }
306
307 /* handle alpha settings... */
308 srcalphaflags = (src->flags&SDL_SRCALPHA) | (src->flags&SDL_RLEACCEL);
309 dstalphaflags = (dest->flags&SDL_SRCALPHA) | (dest->flags&SDL_RLEACCEL);
310 origsrcalphaflags = srcalphaflags;
311 origdstalphaflags = dstalphaflags;
312 srcalpha = src->format->alpha;
313 dstalpha = dest->format->alpha;
314 for (i = 1; i < argc; i++)
315 {
316 const char *arg = argv[i];
317
318 if (strcmp(arg, "--srcalpha") == 0)
319 srcalpha = atoi(argv[++i]);
320 else if (strcmp(arg, "--dstalpha") == 0)
321 dstalpha = atoi(argv[++i]);
322 else if (strcmp(arg, "--srcsrcalpha") == 0)
323 srcalphaflags |= SDL_SRCALPHA;
324 else if (strcmp(arg, "--srcnosrcalpha") == 0)
325 srcalphaflags &= ~SDL_SRCALPHA;
326 else if (strcmp(arg, "--srcrleaccel") == 0)
327 srcalphaflags |= SDL_RLEACCEL;
328 else if (strcmp(arg, "--srcnorleaccel") == 0)
329 srcalphaflags &= ~SDL_RLEACCEL;
330 else if (strcmp(arg, "--dstsrcalpha") == 0)
331 dstalphaflags |= SDL_SRCALPHA;
332 else if (strcmp(arg, "--dstnosrcalpha") == 0)
333 dstalphaflags &= ~SDL_SRCALPHA;
334 else if (strcmp(arg, "--dstrleaccel") == 0)
335 dstalphaflags |= SDL_RLEACCEL;
336 else if (strcmp(arg, "--dstnorleaccel") == 0)
337 dstalphaflags &= ~SDL_RLEACCEL;
338 }
339 if ((dstalphaflags != origdstalphaflags) || (dstalpha != dest->format->alpha))
340 SDL_SetAlpha(dest, dstalphaflags, (Uint8) dstalpha);
341 if ((srcalphaflags != origsrcalphaflags) || (srcalpha != src->format->alpha))
342 SDL_SetAlpha(src, srcalphaflags, (Uint8) srcalpha);
290 343
291 /* set some sane defaults so we can see if the blit code is broken... */ 344 /* set some sane defaults so we can see if the blit code is broken... */
292 SDL_FillRect(dest, NULL, SDL_MapRGB(dest->format, 0, 0, 0)); 345 SDL_FillRect(dest, NULL, SDL_MapRGB(dest->format, 0, 0, 0));
293 SDL_FillRect(src, NULL, SDL_MapRGB(src->format, 0, 0, 0)); 346 SDL_FillRect(src, NULL, SDL_MapRGB(src->format, 0, 0, 0));
294 347