test/testblitspeed.c
author Patrice Mandin <patmandin@gmail.com>
Thu, 19 Jan 2006 21:28:52 +0000
changeset 1257 448a9a64537b
parent 1231 cf59e7b91ed4
child 1658 e49147870aac
child 1895 c121d94672cb
permissions -rw-r--r--
[PATCH] SDL_GetVideoMode() does not find best mode, part 2

Following commit 1.51, I come accross a problem when SDL must choose between
several video modes that could suit the one asked.

If I ask 320x240 with this list:
768x480 768x240 640x400 640x200 384x480 384x240 320x400 320x200

The smallest selectables modes are 384x240 and 320x400. And SDL choose the later
in this list, but 384x240 is more suitable. So I added a check to compare
the pixel count (surface) of modes, and select the one which has the smallest
pixel count.

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