Added testfill to test raw fill performance
authorSam Lantinga <slouken@libsdl.org>
Wed, 16 Dec 2009 02:08:59 +0000
changeset 35765ea08f1c29d0
parent 3575 239ae83fc2f6
child 3577 72024425b437
Added testfill to test raw fill performance
test/Makefile.in
test/testfill.c
     1.1 --- a/test/Makefile.in	Wed Dec 16 01:19:58 2009 +0000
     1.2 +++ b/test/Makefile.in	Wed Dec 16 02:08:59 2009 +0000
     1.3 @@ -7,7 +7,7 @@
     1.4  CFLAGS  = @CFLAGS@
     1.5  LIBS	= @LIBS@
     1.6  
     1.7 -TARGETS = checkkeys$(EXE) graywin$(EXE) loopwave$(EXE) testalpha$(EXE) testatomic$(EXE) testaudioinfo$(EXE) testbitmap$(EXE) testblitspeed$(EXE) testcursor$(EXE) testdraw2$(EXE) testdyngles$(EXE) testdyngl$(EXE) testerror$(EXE) testfile$(EXE) testgamma$(EXE) testgl2$(EXE) testgles$(EXE) testgl$(EXE) testhaptic$(EXE) testhread$(EXE) testiconv$(EXE) testime$(EXE) testintersections$(EXE) testjoystick$(EXE) testkeys$(EXE) testloadso$(EXE) testlock$(EXE) testmmousetablet$(EXE) testmultiaudio$(EXE) testoverlay2$(EXE) testoverlay$(EXE) testpalette$(EXE) testplatform$(EXE) testpower$(EXE) testresample$(EXE) testsem$(EXE) testsprite2$(EXE) testsprite$(EXE) testspriteminimal$(EXE) testtimer$(EXE) testver$(EXE) testvidinfo$(EXE) testwin$(EXE) testwm2$(EXE) testwm$(EXE) threadwin$(EXE) torturethread$(EXE)
     1.8 +TARGETS = checkkeys$(EXE) graywin$(EXE) loopwave$(EXE) testalpha$(EXE) testatomic$(EXE) testaudioinfo$(EXE) testbitmap$(EXE) testblitspeed$(EXE) testcursor$(EXE) testdraw2$(EXE) testdyngles$(EXE) testdyngl$(EXE) testerror$(EXE) testfile$(EXE) testfill$(EXE) testgamma$(EXE) testgl2$(EXE) testgles$(EXE) testgl$(EXE) testhaptic$(EXE) testhread$(EXE) testiconv$(EXE) testime$(EXE) testintersections$(EXE) testjoystick$(EXE) testkeys$(EXE) testloadso$(EXE) testlock$(EXE) testmmousetablet$(EXE) testmultiaudio$(EXE) testoverlay2$(EXE) testoverlay$(EXE) testpalette$(EXE) testplatform$(EXE) testpower$(EXE) testresample$(EXE) testsem$(EXE) testsprite2$(EXE) testsprite$(EXE) testspriteminimal$(EXE) testtimer$(EXE) testver$(EXE) testvidinfo$(EXE) testwin$(EXE) testwm2$(EXE) testwm$(EXE) threadwin$(EXE) torturethread$(EXE)
     1.9  
    1.10  all: Makefile $(TARGETS)
    1.11  
    1.12 @@ -65,6 +65,9 @@
    1.13  testfile$(EXE): $(srcdir)/testfile.c
    1.14  	$(CC) -o $@ $? $(CFLAGS) $(LIBS)
    1.15  
    1.16 +testfill$(EXE): $(srcdir)/testfill.c
    1.17 +	$(CC) -o $@ $? $(CFLAGS) $(LIBS)
    1.18 +
    1.19  testgamma$(EXE): $(srcdir)/testgamma.c
    1.20  	$(CC) -o $@ $? $(CFLAGS) $(LIBS) @MATHLIB@
    1.21  
     2.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     2.2 +++ b/test/testfill.c	Wed Dec 16 02:08:59 2009 +0000
     2.3 @@ -0,0 +1,107 @@
     2.4 +/* Simple program:  Fill the screen with colors as fast as possible */
     2.5 +
     2.6 +#include <stdlib.h>
     2.7 +#include <stdio.h>
     2.8 +#include <string.h>
     2.9 +#include <time.h>
    2.10 +
    2.11 +#include "SDL.h"
    2.12 +
    2.13 +/* Call this instead of exit(), so we can clean up SDL: atexit() is evil. */
    2.14 +static void
    2.15 +quit(int rc)
    2.16 +{
    2.17 +    SDL_Quit();
    2.18 +    exit(rc);
    2.19 +}
    2.20 +
    2.21 +int
    2.22 +main(int argc, char *argv[])
    2.23 +{
    2.24 +    SDL_Surface *screen;
    2.25 +    int width, height;
    2.26 +    Uint8 video_bpp;
    2.27 +    Uint32 videoflags;
    2.28 +    Uint32 colors[3];
    2.29 +    int i, done;
    2.30 +    SDL_Event event;
    2.31 +    Uint32 then, now, frames;
    2.32 +
    2.33 +    /* Initialize SDL */
    2.34 +    if (SDL_Init(SDL_INIT_VIDEO) < 0) {
    2.35 +        fprintf(stderr, "Couldn't initialize SDL: %s\n", SDL_GetError());
    2.36 +        return (1);
    2.37 +    }
    2.38 +
    2.39 +    width = 640;
    2.40 +    height = 480;
    2.41 +    video_bpp = 8;
    2.42 +    videoflags = 0;
    2.43 +    while (argc > 1) {
    2.44 +        --argc;
    2.45 +        if (strcmp(argv[argc - 1], "-width") == 0) {
    2.46 +            width = atoi(argv[argc]);
    2.47 +            --argc;
    2.48 +        } else if (strcmp(argv[argc - 1], "-height") == 0) {
    2.49 +            height = atoi(argv[argc]);
    2.50 +            --argc;
    2.51 +        } else if (strcmp(argv[argc - 1], "-bpp") == 0) {
    2.52 +            video_bpp = atoi(argv[argc]);
    2.53 +            --argc;
    2.54 +        } else if (strcmp(argv[argc], "-fullscreen") == 0) {
    2.55 +            videoflags ^= SDL_FULLSCREEN;
    2.56 +        } else {
    2.57 +            fprintf(stderr,
    2.58 +                    "Usage: %s [-width N] [-height N] [-bpp N] [-fullscreen]\n",
    2.59 +                    argv[0]);
    2.60 +            quit(1);
    2.61 +        }
    2.62 +    }
    2.63 +
    2.64 +    /* Set video mode */
    2.65 +    screen = SDL_SetVideoMode(width, height, video_bpp, 0);
    2.66 +    if (!screen) {
    2.67 +        fprintf(stderr, "Couldn't set %dx%d video mode: %s\n",
    2.68 +                width, height, SDL_GetError());
    2.69 +        quit(2);
    2.70 +    }
    2.71 +
    2.72 +    /* Get the colors */
    2.73 +    colors[0] = SDL_MapRGB(screen->format, 0xFF, 0x00, 0x00);
    2.74 +    colors[1] = SDL_MapRGB(screen->format, 0x00, 0xFF, 0x00);
    2.75 +    colors[2] = SDL_MapRGB(screen->format, 0x00, 0x00, 0xFF);
    2.76 +
    2.77 +    /* Loop, filling and waiting for a keystroke */
    2.78 +    frames = 0;
    2.79 +    then = SDL_GetTicks();
    2.80 +    done = 0;
    2.81 +    while (!done) {
    2.82 +        /* Check for events */
    2.83 +        ++frames;
    2.84 +        while (SDL_PollEvent(&event)) {
    2.85 +            switch (event.type) {
    2.86 +            case SDL_MOUSEBUTTONDOWN:
    2.87 +                SDL_WarpMouse(screen->w / 2, screen->h / 2);
    2.88 +                break;
    2.89 +            case SDL_KEYDOWN:
    2.90 +                /* Any keypress quits the app... */
    2.91 +            case SDL_QUIT:
    2.92 +                done = 1;
    2.93 +                break;
    2.94 +            default:
    2.95 +                break;
    2.96 +            }
    2.97 +        }
    2.98 +        SDL_FillRect(screen, NULL, colors[frames%3]);
    2.99 +        SDL_Flip(screen);
   2.100 +    }
   2.101 +
   2.102 +    /* Print out some timing information */
   2.103 +    now = SDL_GetTicks();
   2.104 +    if (now > then) {
   2.105 +        double fps = ((double) frames * 1000) / (now - then);
   2.106 +        printf("%2.2f frames per second\n", fps);
   2.107 +    }
   2.108 +    SDL_Quit();
   2.109 +    return (0);
   2.110 +}