From 4d4d63a067ee00ccecfaf21f3bcef955a2f24268 Mon Sep 17 00:00:00 2001 From: Sam Lantinga Date: Wed, 16 Dec 2009 02:08:59 +0000 Subject: [PATCH] Added testfill to test raw fill performance --- test/Makefile.in | 5 ++- test/testfill.c | 107 +++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 111 insertions(+), 1 deletion(-) create mode 100644 test/testfill.c diff --git a/test/Makefile.in b/test/Makefile.in index 816bae5c0..83e71a5d9 100644 --- a/test/Makefile.in +++ b/test/Makefile.in @@ -7,7 +7,7 @@ EXE = @EXE@ CFLAGS = @CFLAGS@ LIBS = @LIBS@ -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) +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) all: Makefile $(TARGETS) @@ -65,6 +65,9 @@ testerror$(EXE): $(srcdir)/testerror.c testfile$(EXE): $(srcdir)/testfile.c $(CC) -o $@ $? $(CFLAGS) $(LIBS) +testfill$(EXE): $(srcdir)/testfill.c + $(CC) -o $@ $? $(CFLAGS) $(LIBS) + testgamma$(EXE): $(srcdir)/testgamma.c $(CC) -o $@ $? $(CFLAGS) $(LIBS) @MATHLIB@ diff --git a/test/testfill.c b/test/testfill.c new file mode 100644 index 000000000..98086485a --- /dev/null +++ b/test/testfill.c @@ -0,0 +1,107 @@ +/* Simple program: Fill the screen with colors as fast as possible */ + +#include +#include +#include +#include + +#include "SDL.h" + +/* Call this instead of exit(), so we can clean up SDL: atexit() is evil. */ +static void +quit(int rc) +{ + SDL_Quit(); + exit(rc); +} + +int +main(int argc, char *argv[]) +{ + SDL_Surface *screen; + int width, height; + Uint8 video_bpp; + Uint32 videoflags; + Uint32 colors[3]; + int i, done; + SDL_Event event; + Uint32 then, now, frames; + + /* Initialize SDL */ + if (SDL_Init(SDL_INIT_VIDEO) < 0) { + fprintf(stderr, "Couldn't initialize SDL: %s\n", SDL_GetError()); + return (1); + } + + width = 640; + height = 480; + video_bpp = 8; + videoflags = 0; + while (argc > 1) { + --argc; + if (strcmp(argv[argc - 1], "-width") == 0) { + width = atoi(argv[argc]); + --argc; + } else if (strcmp(argv[argc - 1], "-height") == 0) { + height = atoi(argv[argc]); + --argc; + } else if (strcmp(argv[argc - 1], "-bpp") == 0) { + video_bpp = atoi(argv[argc]); + --argc; + } else if (strcmp(argv[argc], "-fullscreen") == 0) { + videoflags ^= SDL_FULLSCREEN; + } else { + fprintf(stderr, + "Usage: %s [-width N] [-height N] [-bpp N] [-fullscreen]\n", + argv[0]); + quit(1); + } + } + + /* Set video mode */ + screen = SDL_SetVideoMode(width, height, video_bpp, 0); + if (!screen) { + fprintf(stderr, "Couldn't set %dx%d video mode: %s\n", + width, height, SDL_GetError()); + quit(2); + } + + /* Get the colors */ + colors[0] = SDL_MapRGB(screen->format, 0xFF, 0x00, 0x00); + colors[1] = SDL_MapRGB(screen->format, 0x00, 0xFF, 0x00); + colors[2] = SDL_MapRGB(screen->format, 0x00, 0x00, 0xFF); + + /* Loop, filling and waiting for a keystroke */ + frames = 0; + then = SDL_GetTicks(); + done = 0; + while (!done) { + /* Check for events */ + ++frames; + while (SDL_PollEvent(&event)) { + switch (event.type) { + case SDL_MOUSEBUTTONDOWN: + SDL_WarpMouse(screen->w / 2, screen->h / 2); + break; + case SDL_KEYDOWN: + /* Any keypress quits the app... */ + case SDL_QUIT: + done = 1; + break; + default: + break; + } + } + SDL_FillRect(screen, NULL, colors[frames%3]); + SDL_Flip(screen); + } + + /* Print out some timing information */ + now = SDL_GetTicks(); + if (now > then) { + double fps = ((double) frames * 1000) / (now - then); + printf("%2.2f frames per second\n", fps); + } + SDL_Quit(); + return (0); +}