test/testblitspeed.c
author Ryan C. Gordon <icculus@icculus.org>
Fri, 03 Jun 2011 16:03:10 -0400
changeset 5547 4ccecd0901e2
parent 5535 96594ac5fd1a
permissions -rw-r--r--
Assert code's stdio interface was reading from the wrong variable.

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