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