annotate test/testblitspeed.c @ 1658:e49147870aac SDL-1.3

glSDL support
author Sam Lantinga <slouken@libsdl.org>
date Mon, 01 May 2006 06:58:33 +0000
parents cf59e7b91ed4
children 782fd950bd46
rev   line source
1039
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1 /*
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
2 * Benchmarks surface-to-surface blits in various formats.
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
3 *
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
4 * Written by Ryan C. Gordon.
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
5 */
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
6
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
7 #include <stdio.h>
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
8 #include <stdlib.h>
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
9 #include <string.h>
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
10
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
11 #include "SDL.h"
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
12
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
13 static SDL_Surface *dest = NULL;
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
14 static SDL_Surface *src = NULL;
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
15 static int testSeconds = 10;
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
16
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
17
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
18 static int percent(int val, int total)
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
19 {
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
20 return((int) ((((float) val) / ((float) total)) * 100.0f));
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
21 }
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
22
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
23 static int randRange(int lo, int hi)
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
24 {
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
25 return(lo + (int) (((double) hi)*rand()/(RAND_MAX+1.0)));
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
26 }
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
27
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
28 static void copy_trunc_str(char *str, size_t strsize, const char *flagstr)
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
29 {
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
30 if ( (strlen(str) + strlen(flagstr)) >= (strsize - 1) )
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
31 strcpy(str + (strsize - 5), " ...");
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
32 else
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
33 strcat(str, flagstr);
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
34 }
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
35
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
36 static void __append_sdl_surface_flag(SDL_Surface *_surface, char *str,
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
37 size_t strsize, Uint32 flag,
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
38 const char *flagstr)
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
39 {
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
40 if (_surface->flags & flag)
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
41 copy_trunc_str(str, strsize, flagstr);
1231
cf59e7b91ed4 testblitspeed.c improvements: cleaned up output, and allow user to set surface
Ryan C. Gordon <icculus@icculus.org>
parents: 1039
diff changeset
42 }
1039
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
43
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
44
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
45 #define append_sdl_surface_flag(a, b, c, fl) __append_sdl_surface_flag(a, b, c, fl, " " #fl)
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
46 #define print_tf_state(str, val) printf("%s: {%s}\n", str, (val) ? "true" : "false" )
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
47
1231
cf59e7b91ed4 testblitspeed.c improvements: cleaned up output, and allow user to set surface
Ryan C. Gordon <icculus@icculus.org>
parents: 1039
diff changeset
48 static void output_videoinfo_details(void)
cf59e7b91ed4 testblitspeed.c improvements: cleaned up output, and allow user to set surface
Ryan C. Gordon <icculus@icculus.org>
parents: 1039
diff changeset
49 {
cf59e7b91ed4 testblitspeed.c improvements: cleaned up output, and allow user to set surface
Ryan C. Gordon <icculus@icculus.org>
parents: 1039
diff changeset
50 const SDL_VideoInfo *info = SDL_GetVideoInfo();
cf59e7b91ed4 testblitspeed.c improvements: cleaned up output, and allow user to set surface
Ryan C. Gordon <icculus@icculus.org>
parents: 1039
diff changeset
51 printf("SDL_GetVideoInfo():\n");
cf59e7b91ed4 testblitspeed.c improvements: cleaned up output, and allow user to set surface
Ryan C. Gordon <icculus@icculus.org>
parents: 1039
diff changeset
52 if (info == NULL)
cf59e7b91ed4 testblitspeed.c improvements: cleaned up output, and allow user to set surface
Ryan C. Gordon <icculus@icculus.org>
parents: 1039
diff changeset
53 printf(" (null.)\n");
cf59e7b91ed4 testblitspeed.c improvements: cleaned up output, and allow user to set surface
Ryan C. Gordon <icculus@icculus.org>
parents: 1039
diff changeset
54 else
cf59e7b91ed4 testblitspeed.c improvements: cleaned up output, and allow user to set surface
Ryan C. Gordon <icculus@icculus.org>
parents: 1039
diff changeset
55 {
cf59e7b91ed4 testblitspeed.c improvements: cleaned up output, and allow user to set surface
Ryan C. Gordon <icculus@icculus.org>
parents: 1039
diff changeset
56 print_tf_state(" hardware surface available", info->hw_available);
cf59e7b91ed4 testblitspeed.c improvements: cleaned up output, and allow user to set surface
Ryan C. Gordon <icculus@icculus.org>
parents: 1039
diff changeset
57 print_tf_state(" window manager available", info->wm_available);
cf59e7b91ed4 testblitspeed.c improvements: cleaned up output, and allow user to set surface
Ryan C. Gordon <icculus@icculus.org>
parents: 1039
diff changeset
58 print_tf_state(" accelerated hardware->hardware blits", info->blit_hw);
cf59e7b91ed4 testblitspeed.c improvements: cleaned up output, and allow user to set surface
Ryan C. Gordon <icculus@icculus.org>
parents: 1039
diff changeset
59 print_tf_state(" accelerated hardware->hardware colorkey blits", info->blit_hw_CC);
cf59e7b91ed4 testblitspeed.c improvements: cleaned up output, and allow user to set surface
Ryan C. Gordon <icculus@icculus.org>
parents: 1039
diff changeset
60 print_tf_state(" accelerated hardware->hardware alpha blits", info->blit_hw_A);
cf59e7b91ed4 testblitspeed.c improvements: cleaned up output, and allow user to set surface
Ryan C. Gordon <icculus@icculus.org>
parents: 1039
diff changeset
61 print_tf_state(" accelerated software->hardware blits", info->blit_sw);
cf59e7b91ed4 testblitspeed.c improvements: cleaned up output, and allow user to set surface
Ryan C. Gordon <icculus@icculus.org>
parents: 1039
diff changeset
62 print_tf_state(" accelerated software->hardware colorkey blits", info->blit_sw_CC);
cf59e7b91ed4 testblitspeed.c improvements: cleaned up output, and allow user to set surface
Ryan C. Gordon <icculus@icculus.org>
parents: 1039
diff changeset
63 print_tf_state(" accelerated software->hardware alpha blits", info->blit_sw_A);
cf59e7b91ed4 testblitspeed.c improvements: cleaned up output, and allow user to set surface
Ryan C. Gordon <icculus@icculus.org>
parents: 1039
diff changeset
64 print_tf_state(" accelerated color fills", info->blit_fill);
cf59e7b91ed4 testblitspeed.c improvements: cleaned up output, and allow user to set surface
Ryan C. Gordon <icculus@icculus.org>
parents: 1039
diff changeset
65 printf(" video memory: (%d)\n", info->video_mem);
cf59e7b91ed4 testblitspeed.c improvements: cleaned up output, and allow user to set surface
Ryan C. Gordon <icculus@icculus.org>
parents: 1039
diff changeset
66 }
cf59e7b91ed4 testblitspeed.c improvements: cleaned up output, and allow user to set surface
Ryan C. Gordon <icculus@icculus.org>
parents: 1039
diff changeset
67
cf59e7b91ed4 testblitspeed.c improvements: cleaned up output, and allow user to set surface
Ryan C. Gordon <icculus@icculus.org>
parents: 1039
diff changeset
68 printf("\n");
cf59e7b91ed4 testblitspeed.c improvements: cleaned up output, and allow user to set surface
Ryan C. Gordon <icculus@icculus.org>
parents: 1039
diff changeset
69 }
cf59e7b91ed4 testblitspeed.c improvements: cleaned up output, and allow user to set surface
Ryan C. Gordon <icculus@icculus.org>
parents: 1039
diff changeset
70
1039
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
71 static void output_surface_details(const char *name, SDL_Surface *surface)
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
72 {
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
73 printf("Details for %s:\n", name);
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
74
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
75 if (surface == NULL)
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
76 {
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
77 printf("-WARNING- You've got a NULL surface!");
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
78 }
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
79 else
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
80 {
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
81 char f[256];
1231
cf59e7b91ed4 testblitspeed.c improvements: cleaned up output, and allow user to set surface
Ryan C. Gordon <icculus@icculus.org>
parents: 1039
diff changeset
82 printf(" width : %d\n", surface->w);
cf59e7b91ed4 testblitspeed.c improvements: cleaned up output, and allow user to set surface
Ryan C. Gordon <icculus@icculus.org>
parents: 1039
diff changeset
83 printf(" height : %d\n", surface->h);
cf59e7b91ed4 testblitspeed.c improvements: cleaned up output, and allow user to set surface
Ryan C. Gordon <icculus@icculus.org>
parents: 1039
diff changeset
84 printf(" depth : %d bits per pixel\n", surface->format->BitsPerPixel);
cf59e7b91ed4 testblitspeed.c improvements: cleaned up output, and allow user to set surface
Ryan C. Gordon <icculus@icculus.org>
parents: 1039
diff changeset
85 printf(" pitch : %d\n", (int) surface->pitch);
cf59e7b91ed4 testblitspeed.c improvements: cleaned up output, and allow user to set surface
Ryan C. Gordon <icculus@icculus.org>
parents: 1039
diff changeset
86 printf(" alpha : %d\n", (int) surface->format->alpha);
cf59e7b91ed4 testblitspeed.c improvements: cleaned up output, and allow user to set surface
Ryan C. Gordon <icculus@icculus.org>
parents: 1039
diff changeset
87 printf(" colorkey : 0x%X\n", (unsigned int) surface->format->colorkey);
1039
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
88
1231
cf59e7b91ed4 testblitspeed.c improvements: cleaned up output, and allow user to set surface
Ryan C. Gordon <icculus@icculus.org>
parents: 1039
diff changeset
89 printf(" red bits : 0x%08X mask, %d shift, %d loss\n",
1039
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
90 (int) surface->format->Rmask,
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
91 (int) surface->format->Rshift,
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
92 (int) surface->format->Rloss);
1231
cf59e7b91ed4 testblitspeed.c improvements: cleaned up output, and allow user to set surface
Ryan C. Gordon <icculus@icculus.org>
parents: 1039
diff changeset
93 printf(" green bits : 0x%08X mask, %d shift, %d loss\n",
1039
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
94 (int) surface->format->Gmask,
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
95 (int) surface->format->Gshift,
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
96 (int) surface->format->Gloss);
1231
cf59e7b91ed4 testblitspeed.c improvements: cleaned up output, and allow user to set surface
Ryan C. Gordon <icculus@icculus.org>
parents: 1039
diff changeset
97 printf(" blue bits : 0x%08X mask, %d shift, %d loss\n",
1039
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
98 (int) surface->format->Bmask,
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
99 (int) surface->format->Bshift,
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
100 (int) surface->format->Bloss);
1231
cf59e7b91ed4 testblitspeed.c improvements: cleaned up output, and allow user to set surface
Ryan C. Gordon <icculus@icculus.org>
parents: 1039
diff changeset
101 printf(" alpha bits : 0x%08X mask, %d shift, %d loss\n",
1039
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
102 (int) surface->format->Amask,
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
103 (int) surface->format->Ashift,
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
104 (int) surface->format->Aloss);
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
105
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
106 f[0] = '\0';
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
107
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
108 /*append_sdl_surface_flag(surface, f, sizeof (f), SDL_SWSURFACE);*/
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
109 if ((surface->flags & SDL_HWSURFACE) == 0)
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
110 copy_trunc_str(f, sizeof (f), " SDL_SWSURFACE");
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
111
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
112 append_sdl_surface_flag(surface, f, sizeof (f), SDL_HWSURFACE);
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
113 append_sdl_surface_flag(surface, f, sizeof (f), SDL_ASYNCBLIT);
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
114 append_sdl_surface_flag(surface, f, sizeof (f), SDL_ANYFORMAT);
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
115 append_sdl_surface_flag(surface, f, sizeof (f), SDL_HWPALETTE);
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
116 append_sdl_surface_flag(surface, f, sizeof (f), SDL_DOUBLEBUF);
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
117 append_sdl_surface_flag(surface, f, sizeof (f), SDL_FULLSCREEN);
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
118 append_sdl_surface_flag(surface, f, sizeof (f), SDL_OPENGL);
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
119 append_sdl_surface_flag(surface, f, sizeof (f), SDL_RESIZABLE);
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
120 append_sdl_surface_flag(surface, f, sizeof (f), SDL_NOFRAME);
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
121 append_sdl_surface_flag(surface, f, sizeof (f), SDL_HWACCEL);
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
122 append_sdl_surface_flag(surface, f, sizeof (f), SDL_SRCCOLORKEY);
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
123 append_sdl_surface_flag(surface, f, sizeof (f), SDL_RLEACCELOK);
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
124 append_sdl_surface_flag(surface, f, sizeof (f), SDL_RLEACCEL);
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
125 append_sdl_surface_flag(surface, f, sizeof (f), SDL_SRCALPHA);
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
126 append_sdl_surface_flag(surface, f, sizeof (f), SDL_PREALLOC);
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
127
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
128 if (f[0] == '\0')
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
129 strcpy(f, " (none)");
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
130
1231
cf59e7b91ed4 testblitspeed.c improvements: cleaned up output, and allow user to set surface
Ryan C. Gordon <icculus@icculus.org>
parents: 1039
diff changeset
131 printf(" flags :%s\n", f);
cf59e7b91ed4 testblitspeed.c improvements: cleaned up output, and allow user to set surface
Ryan C. Gordon <icculus@icculus.org>
parents: 1039
diff changeset
132 }
1039
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
133
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
134 printf("\n");
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
135 }
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
136
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
137 static void output_details(void)
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
138 {
1231
cf59e7b91ed4 testblitspeed.c improvements: cleaned up output, and allow user to set surface
Ryan C. Gordon <icculus@icculus.org>
parents: 1039
diff changeset
139 output_videoinfo_details();
1039
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
140 output_surface_details("Source Surface", src);
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
141 output_surface_details("Destination Surface", dest);
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
142 }
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
143
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
144 static Uint32 blit(SDL_Surface *dst, SDL_Surface *src, int x, int y)
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
145 {
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
146 Uint32 start = 0;
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
147 SDL_Rect srcRect;
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
148 SDL_Rect dstRect;
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
149
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
150 srcRect.x = 0;
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
151 srcRect.y = 0;
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
152 dstRect.x = x;
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
153 dstRect.y = y;
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
154 dstRect.w = srcRect.w = src->w; /* SDL will clip as appropriate. */
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
155 dstRect.h = srcRect.h = src->h;
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
156
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
157 start = SDL_GetTicks();
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
158 SDL_BlitSurface(src, &srcRect, dst, &dstRect);
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
159 return(SDL_GetTicks() - start);
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
160 }
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
161
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
162 static void blitCentered(SDL_Surface *dst, SDL_Surface *src)
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
163 {
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
164 int x = (dst->w - src->w) / 2;
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
165 int y = (dst->h - src->h) / 2;
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
166 blit(dst, src, x, y);
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
167 }
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
168
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
169 static int atoi_hex(const char *str)
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
170 {
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
171 if (str == NULL)
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
172 return 0;
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
173
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
174 if (strlen(str) > 2)
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
175 {
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
176 int retval = 0;
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
177 if ((str[0] == '0') && (str[1] == 'x'))
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
178 sscanf(str + 2, "%X", &retval);
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
179 return(retval);
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
180 }
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
181
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
182 return(atoi(str));
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
183 }
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
184
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
185
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
186 static int setup_test(int argc, char **argv)
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
187 {
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
188 const char *dumpfile = NULL;
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
189 SDL_Surface *bmp = NULL;
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
190 Uint32 dstbpp = 32;
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
191 Uint32 dstrmask = 0x00FF0000;
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
192 Uint32 dstgmask = 0x0000FF00;
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
193 Uint32 dstbmask = 0x000000FF;
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
194 Uint32 dstamask = 0x00000000;
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
195 Uint32 dstflags = 0;
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
196 int dstw = 640;
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
197 int dsth = 480;
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
198 Uint32 srcbpp = 32;
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
199 Uint32 srcrmask = 0x00FF0000;
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
200 Uint32 srcgmask = 0x0000FF00;
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
201 Uint32 srcbmask = 0x000000FF;
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
202 Uint32 srcamask = 0x00000000;
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
203 Uint32 srcflags = 0;
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
204 int srcw = 640;
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
205 int srch = 480;
1231
cf59e7b91ed4 testblitspeed.c improvements: cleaned up output, and allow user to set surface
Ryan C. Gordon <icculus@icculus.org>
parents: 1039
diff changeset
206 Uint32 origsrcalphaflags = 0;
cf59e7b91ed4 testblitspeed.c improvements: cleaned up output, and allow user to set surface
Ryan C. Gordon <icculus@icculus.org>
parents: 1039
diff changeset
207 Uint32 origdstalphaflags = 0;
cf59e7b91ed4 testblitspeed.c improvements: cleaned up output, and allow user to set surface
Ryan C. Gordon <icculus@icculus.org>
parents: 1039
diff changeset
208 Uint32 srcalphaflags = 0;
cf59e7b91ed4 testblitspeed.c improvements: cleaned up output, and allow user to set surface
Ryan C. Gordon <icculus@icculus.org>
parents: 1039
diff changeset
209 Uint32 dstalphaflags = 0;
cf59e7b91ed4 testblitspeed.c improvements: cleaned up output, and allow user to set surface
Ryan C. Gordon <icculus@icculus.org>
parents: 1039
diff changeset
210 int srcalpha = 255;
cf59e7b91ed4 testblitspeed.c improvements: cleaned up output, and allow user to set surface
Ryan C. Gordon <icculus@icculus.org>
parents: 1039
diff changeset
211 int dstalpha = 255;
1039
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
212 int screenSurface = 0;
1231
cf59e7b91ed4 testblitspeed.c improvements: cleaned up output, and allow user to set surface
Ryan C. Gordon <icculus@icculus.org>
parents: 1039
diff changeset
213 int i = 0;
1039
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
214
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
215 for (i = 1; i < argc; i++)
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
216 {
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
217 const char *arg = argv[i];
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
218
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
219 if (strcmp(arg, "--dstbpp") == 0)
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
220 dstbpp = atoi(argv[++i]);
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
221 else if (strcmp(arg, "--dstrmask") == 0)
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
222 dstrmask = atoi_hex(argv[++i]);
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
223 else if (strcmp(arg, "--dstgmask") == 0)
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
224 dstgmask = atoi_hex(argv[++i]);
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
225 else if (strcmp(arg, "--dstbmask") == 0)
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
226 dstbmask = atoi_hex(argv[++i]);
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
227 else if (strcmp(arg, "--dstamask") == 0)
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
228 dstamask = atoi_hex(argv[++i]);
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
229 else if (strcmp(arg, "--dstwidth") == 0)
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
230 dstw = atoi(argv[++i]);
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
231 else if (strcmp(arg, "--dstheight") == 0)
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
232 dsth = atoi(argv[++i]);
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
233 else if (strcmp(arg, "--dsthwsurface") == 0)
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
234 dstflags |= SDL_HWSURFACE;
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
235 else if (strcmp(arg, "--srcbpp") == 0)
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
236 srcbpp = atoi(argv[++i]);
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
237 else if (strcmp(arg, "--srcrmask") == 0)
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
238 srcrmask = atoi_hex(argv[++i]);
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
239 else if (strcmp(arg, "--srcgmask") == 0)
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
240 srcgmask = atoi_hex(argv[++i]);
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
241 else if (strcmp(arg, "--srcbmask") == 0)
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
242 srcbmask = atoi_hex(argv[++i]);
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
243 else if (strcmp(arg, "--srcamask") == 0)
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
244 srcamask = atoi_hex(argv[++i]);
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
245 else if (strcmp(arg, "--srcwidth") == 0)
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
246 srcw = atoi(argv[++i]);
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
247 else if (strcmp(arg, "--srcheight") == 0)
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
248 srch = atoi(argv[++i]);
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
249 else if (strcmp(arg, "--srchwsurface") == 0)
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
250 srcflags |= SDL_HWSURFACE;
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
251 else if (strcmp(arg, "--seconds") == 0)
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
252 testSeconds = atoi(argv[++i]);
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
253 else if (strcmp(arg, "--screen") == 0)
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
254 screenSurface = 1;
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
255 else if (strcmp(arg, "--dumpfile") == 0)
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
256 dumpfile = argv[++i];
1231
cf59e7b91ed4 testblitspeed.c improvements: cleaned up output, and allow user to set surface
Ryan C. Gordon <icculus@icculus.org>
parents: 1039
diff changeset
257 /* !!! FIXME: set colorkey. */
cf59e7b91ed4 testblitspeed.c improvements: cleaned up output, and allow user to set surface
Ryan C. Gordon <icculus@icculus.org>
parents: 1039
diff changeset
258 else if (0) /* !!! FIXME: we handle some commandlines elsewhere now */
1039
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
259 {
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
260 fprintf(stderr, "Unknown commandline option: %s\n", arg);
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
261 return(0);
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
262 }
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
263 }
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
264
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
265 if (SDL_Init(SDL_INIT_VIDEO) == -1)
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
266 {
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
267 fprintf(stderr, "SDL_Init failed: %s\n", SDL_GetError());
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
268 return(0);
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
269 }
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
270
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
271 bmp = SDL_LoadBMP("sample.bmp");
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
272 if (bmp == NULL)
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
273 {
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
274 fprintf(stderr, "SDL_LoadBMP failed: %s\n", SDL_GetError());
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
275 SDL_Quit();
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
276 return(0);
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
277 }
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
278
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
279 if ((dstflags & SDL_HWSURFACE) == 0) dstflags |= SDL_SWSURFACE;
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
280 if ((srcflags & SDL_HWSURFACE) == 0) srcflags |= SDL_SWSURFACE;
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
281
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
282 if (screenSurface)
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
283 dest = SDL_SetVideoMode(dstw, dsth, dstbpp, dstflags);
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
284 else
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
285 {
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
286 dest = SDL_CreateRGBSurface(dstflags, dstw, dsth, dstbpp,
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
287 dstrmask, dstgmask, dstbmask, dstamask);
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
288 }
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
289
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
290 if (dest == NULL)
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
291 {
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
292 fprintf(stderr, "dest surface creation failed: %s\n", SDL_GetError());
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
293 SDL_Quit();
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
294 return(0);
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
295 }
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
296
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
297 src = SDL_CreateRGBSurface(srcflags, srcw, srch, srcbpp,
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
298 srcrmask, srcgmask, srcbmask, srcamask);
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
299 if (src == NULL)
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
300 {
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
301 fprintf(stderr, "src surface creation failed: %s\n", SDL_GetError());
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
302 SDL_Quit();
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
303 return(0);
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
304 }
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
305
1231
cf59e7b91ed4 testblitspeed.c improvements: cleaned up output, and allow user to set surface
Ryan C. Gordon <icculus@icculus.org>
parents: 1039
diff changeset
306 /* handle alpha settings... */
cf59e7b91ed4 testblitspeed.c improvements: cleaned up output, and allow user to set surface
Ryan C. Gordon <icculus@icculus.org>
parents: 1039
diff changeset
307 srcalphaflags = (src->flags&SDL_SRCALPHA) | (src->flags&SDL_RLEACCEL);
cf59e7b91ed4 testblitspeed.c improvements: cleaned up output, and allow user to set surface
Ryan C. Gordon <icculus@icculus.org>
parents: 1039
diff changeset
308 dstalphaflags = (dest->flags&SDL_SRCALPHA) | (dest->flags&SDL_RLEACCEL);
cf59e7b91ed4 testblitspeed.c improvements: cleaned up output, and allow user to set surface
Ryan C. Gordon <icculus@icculus.org>
parents: 1039
diff changeset
309 origsrcalphaflags = srcalphaflags;
cf59e7b91ed4 testblitspeed.c improvements: cleaned up output, and allow user to set surface
Ryan C. Gordon <icculus@icculus.org>
parents: 1039
diff changeset
310 origdstalphaflags = dstalphaflags;
cf59e7b91ed4 testblitspeed.c improvements: cleaned up output, and allow user to set surface
Ryan C. Gordon <icculus@icculus.org>
parents: 1039
diff changeset
311 srcalpha = src->format->alpha;
cf59e7b91ed4 testblitspeed.c improvements: cleaned up output, and allow user to set surface
Ryan C. Gordon <icculus@icculus.org>
parents: 1039
diff changeset
312 dstalpha = dest->format->alpha;
cf59e7b91ed4 testblitspeed.c improvements: cleaned up output, and allow user to set surface
Ryan C. Gordon <icculus@icculus.org>
parents: 1039
diff changeset
313 for (i = 1; i < argc; i++)
cf59e7b91ed4 testblitspeed.c improvements: cleaned up output, and allow user to set surface
Ryan C. Gordon <icculus@icculus.org>
parents: 1039
diff changeset
314 {
cf59e7b91ed4 testblitspeed.c improvements: cleaned up output, and allow user to set surface
Ryan C. Gordon <icculus@icculus.org>
parents: 1039
diff changeset
315 const char *arg = argv[i];
cf59e7b91ed4 testblitspeed.c improvements: cleaned up output, and allow user to set surface
Ryan C. Gordon <icculus@icculus.org>
parents: 1039
diff changeset
316
cf59e7b91ed4 testblitspeed.c improvements: cleaned up output, and allow user to set surface
Ryan C. Gordon <icculus@icculus.org>
parents: 1039
diff changeset
317 if (strcmp(arg, "--srcalpha") == 0)
cf59e7b91ed4 testblitspeed.c improvements: cleaned up output, and allow user to set surface
Ryan C. Gordon <icculus@icculus.org>
parents: 1039
diff changeset
318 srcalpha = atoi(argv[++i]);
cf59e7b91ed4 testblitspeed.c improvements: cleaned up output, and allow user to set surface
Ryan C. Gordon <icculus@icculus.org>
parents: 1039
diff changeset
319 else if (strcmp(arg, "--dstalpha") == 0)
cf59e7b91ed4 testblitspeed.c improvements: cleaned up output, and allow user to set surface
Ryan C. Gordon <icculus@icculus.org>
parents: 1039
diff changeset
320 dstalpha = atoi(argv[++i]);
cf59e7b91ed4 testblitspeed.c improvements: cleaned up output, and allow user to set surface
Ryan C. Gordon <icculus@icculus.org>
parents: 1039
diff changeset
321 else if (strcmp(arg, "--srcsrcalpha") == 0)
cf59e7b91ed4 testblitspeed.c improvements: cleaned up output, and allow user to set surface
Ryan C. Gordon <icculus@icculus.org>
parents: 1039
diff changeset
322 srcalphaflags |= SDL_SRCALPHA;
cf59e7b91ed4 testblitspeed.c improvements: cleaned up output, and allow user to set surface
Ryan C. Gordon <icculus@icculus.org>
parents: 1039
diff changeset
323 else if (strcmp(arg, "--srcnosrcalpha") == 0)
cf59e7b91ed4 testblitspeed.c improvements: cleaned up output, and allow user to set surface
Ryan C. Gordon <icculus@icculus.org>
parents: 1039
diff changeset
324 srcalphaflags &= ~SDL_SRCALPHA;
cf59e7b91ed4 testblitspeed.c improvements: cleaned up output, and allow user to set surface
Ryan C. Gordon <icculus@icculus.org>
parents: 1039
diff changeset
325 else if (strcmp(arg, "--srcrleaccel") == 0)
cf59e7b91ed4 testblitspeed.c improvements: cleaned up output, and allow user to set surface
Ryan C. Gordon <icculus@icculus.org>
parents: 1039
diff changeset
326 srcalphaflags |= SDL_RLEACCEL;
cf59e7b91ed4 testblitspeed.c improvements: cleaned up output, and allow user to set surface
Ryan C. Gordon <icculus@icculus.org>
parents: 1039
diff changeset
327 else if (strcmp(arg, "--srcnorleaccel") == 0)
cf59e7b91ed4 testblitspeed.c improvements: cleaned up output, and allow user to set surface
Ryan C. Gordon <icculus@icculus.org>
parents: 1039
diff changeset
328 srcalphaflags &= ~SDL_RLEACCEL;
cf59e7b91ed4 testblitspeed.c improvements: cleaned up output, and allow user to set surface
Ryan C. Gordon <icculus@icculus.org>
parents: 1039
diff changeset
329 else if (strcmp(arg, "--dstsrcalpha") == 0)
cf59e7b91ed4 testblitspeed.c improvements: cleaned up output, and allow user to set surface
Ryan C. Gordon <icculus@icculus.org>
parents: 1039
diff changeset
330 dstalphaflags |= SDL_SRCALPHA;
cf59e7b91ed4 testblitspeed.c improvements: cleaned up output, and allow user to set surface
Ryan C. Gordon <icculus@icculus.org>
parents: 1039
diff changeset
331 else if (strcmp(arg, "--dstnosrcalpha") == 0)
cf59e7b91ed4 testblitspeed.c improvements: cleaned up output, and allow user to set surface
Ryan C. Gordon <icculus@icculus.org>
parents: 1039
diff changeset
332 dstalphaflags &= ~SDL_SRCALPHA;
cf59e7b91ed4 testblitspeed.c improvements: cleaned up output, and allow user to set surface
Ryan C. Gordon <icculus@icculus.org>
parents: 1039
diff changeset
333 else if (strcmp(arg, "--dstrleaccel") == 0)
cf59e7b91ed4 testblitspeed.c improvements: cleaned up output, and allow user to set surface
Ryan C. Gordon <icculus@icculus.org>
parents: 1039
diff changeset
334 dstalphaflags |= SDL_RLEACCEL;
cf59e7b91ed4 testblitspeed.c improvements: cleaned up output, and allow user to set surface
Ryan C. Gordon <icculus@icculus.org>
parents: 1039
diff changeset
335 else if (strcmp(arg, "--dstnorleaccel") == 0)
cf59e7b91ed4 testblitspeed.c improvements: cleaned up output, and allow user to set surface
Ryan C. Gordon <icculus@icculus.org>
parents: 1039
diff changeset
336 dstalphaflags &= ~SDL_RLEACCEL;
cf59e7b91ed4 testblitspeed.c improvements: cleaned up output, and allow user to set surface
Ryan C. Gordon <icculus@icculus.org>
parents: 1039
diff changeset
337 }
cf59e7b91ed4 testblitspeed.c improvements: cleaned up output, and allow user to set surface
Ryan C. Gordon <icculus@icculus.org>
parents: 1039
diff changeset
338 if ((dstalphaflags != origdstalphaflags) || (dstalpha != dest->format->alpha))
cf59e7b91ed4 testblitspeed.c improvements: cleaned up output, and allow user to set surface
Ryan C. Gordon <icculus@icculus.org>
parents: 1039
diff changeset
339 SDL_SetAlpha(dest, dstalphaflags, (Uint8) dstalpha);
cf59e7b91ed4 testblitspeed.c improvements: cleaned up output, and allow user to set surface
Ryan C. Gordon <icculus@icculus.org>
parents: 1039
diff changeset
340 if ((srcalphaflags != origsrcalphaflags) || (srcalpha != src->format->alpha))
cf59e7b91ed4 testblitspeed.c improvements: cleaned up output, and allow user to set surface
Ryan C. Gordon <icculus@icculus.org>
parents: 1039
diff changeset
341 SDL_SetAlpha(src, srcalphaflags, (Uint8) srcalpha);
cf59e7b91ed4 testblitspeed.c improvements: cleaned up output, and allow user to set surface
Ryan C. Gordon <icculus@icculus.org>
parents: 1039
diff changeset
342
1039
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
343 /* set some sane defaults so we can see if the blit code is broken... */
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
344 SDL_FillRect(dest, NULL, SDL_MapRGB(dest->format, 0, 0, 0));
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
345 SDL_FillRect(src, NULL, SDL_MapRGB(src->format, 0, 0, 0));
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
346
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
347 blitCentered(src, bmp);
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
348 SDL_FreeSurface(bmp);
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
349
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
350 if (dumpfile)
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
351 SDL_SaveBMP(src, dumpfile); /* make sure initial convert is sane. */
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
352
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
353 output_details();
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
354
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
355 return(1);
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
356 }
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
357
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
358
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
359 static void test_blit_speed(void)
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
360 {
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
361 Uint32 clearColor = SDL_MapRGB(dest->format, 0, 0, 0);
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
362 Uint32 iterations = 0;
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
363 Uint32 elasped = 0;
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
364 Uint32 end = 0;
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
365 Uint32 now = 0;
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
366 Uint32 last = 0;
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
367 int testms = testSeconds * 1000;
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
368 int wmax = (dest->w - src->w);
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
369 int hmax = (dest->h - src->h);
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
370 int isScreen = (SDL_GetVideoSurface() == dest);
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
371 SDL_Event event;
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
372
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
373 printf("Testing blit speed for %d seconds...\n", testSeconds);
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
374
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
375 now = SDL_GetTicks();
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
376 end = now + testms;
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
377
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
378 do
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
379 {
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
380 /* pump the event queue occasionally to keep OS happy... */
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
381 if (now - last > 1000)
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
382 {
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
383 last = now;
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
384 while (SDL_PollEvent(&event)) { /* no-op. */ }
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
385 }
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
386
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
387 iterations++;
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
388 elasped += blit(dest, src, randRange(0, wmax), randRange(0, hmax));
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
389 if (isScreen)
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
390 {
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
391 SDL_Flip(dest); /* show it! */
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
392 SDL_FillRect(dest, NULL, clearColor); /* blank it for next time! */
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
393 }
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
394
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
395 now = SDL_GetTicks();
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
396 } while (now < end);
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
397
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
398 printf("Non-blitting crap accounted for %d percent of this run.\n",
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
399 percent(testms - elasped, testms));
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
400
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
401 printf("%d blits took %d ms (%d fps).\n",
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
402 (int) iterations,
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
403 (int) elasped,
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
404 (int) (((float)iterations) / (((float)elasped) / 1000.0f)));
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
405 }
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
406
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
407 int main(int argc, char **argv)
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
408 {
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
409 int initialized = setup_test(argc, argv);
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
410 if (initialized)
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
411 {
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
412 test_blit_speed();
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
413 SDL_Quit();
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
414 }
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
415 return(!initialized);
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
416 }
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
417
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
418 /* end of testblitspeed.c ... */
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
419