test/testblitspeed.c
author Sam Lantinga <slouken@libsdl.org>
Sun, 28 May 2006 13:04:16 +0000
branchSDL-1.3
changeset 1662 782fd950bd46
parent 1658 e49147870aac
child 1668 4da1ee79c9af
permissions -rw-r--r--
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.

WARNING: None of the video drivers have been updated for the new API yet! The API is still under design and very fluid.

The code is now run through a consistent indent format:
indent -i4 -nut -nsc -br -ce

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