Mercurial > sdl-ios-xcode
annotate test/testfill.c @ 4426:1bceff8f008f
Fixed bug #943
Ozkan Sezer 2010-02-06 12:31:06 PST
Hi:
Here are some small fixes for compiling SDL against mingw-w64.
(see http://mingw-w64.sourceforge.net/ . Despite the name, it
supports both win32 and win64.)
src/audio/windx5/directx.h and src/video/windx5/directx.h (both
SDL-1.2 and SDL-1.3.) I get compilation errors about some union
not having a member named u1 and alike, because of other system
headers being included before this one and them already defining
DUMMYUNIONNAME and stuff. This header probably assumes that those
stuff are defined in windef.h, but mingw-w64 headers define them
in _mingw.h. Easily fixed by moving NONAMELESSUNION definition to
the top of the file.
src/thread/win32/SDL_systhread.c (both SDL-1.2 and SDL-1.3.) :
The __GNUC__ case for pfnSDL_CurrentBeginThread is 32-bit centric
because _beginthreadex returns uintptr_t, not unsigned long which
is 32 bits in win64. Changing the return type to uintptr_t fixes
it.
video/SDL_blit.h (and configure.in) (SDL-1.3-only) : MinGW-w64
uses msvcrt version of _aligned_malloc and _aligned_free and
they are defined in intrin.h (similar to VC). Adding proper
ifdefs fixes it. (Notes about macros to check: __MINGW32__ is
defined for both mingw.org and for mingw-w64 for both win32 and
win64, __MINGW64__ is only defined for _WIN64, so __MINGW64__
can't be used to detect mingw-w64: including _mingw.h and then
checking for __MINGW64_VERSION_MAJOR does the trick.)
SDL_win32video.h (SDL-1.3-only) : Tweaked the VINWER definition
and location in order to avoid multiple redefinition warnings.
Hope these are useful. Thanks.
author | Sam Lantinga <slouken@libsdl.org> |
---|---|
date | Wed, 10 Mar 2010 15:02:58 +0000 |
parents | 5ea08f1c29d0 |
children |
rev | line source |
---|---|
3576
5ea08f1c29d0
Added testfill to test raw fill performance
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
1 /* Simple program: Fill the screen with colors as fast as possible */ |
5ea08f1c29d0
Added testfill to test raw fill performance
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
2 |
5ea08f1c29d0
Added testfill to test raw fill performance
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
3 #include <stdlib.h> |
5ea08f1c29d0
Added testfill to test raw fill performance
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
4 #include <stdio.h> |
5ea08f1c29d0
Added testfill to test raw fill performance
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
5 #include <string.h> |
5ea08f1c29d0
Added testfill to test raw fill performance
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
6 #include <time.h> |
5ea08f1c29d0
Added testfill to test raw fill performance
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
7 |
5ea08f1c29d0
Added testfill to test raw fill performance
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
8 #include "SDL.h" |
5ea08f1c29d0
Added testfill to test raw fill performance
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
9 |
5ea08f1c29d0
Added testfill to test raw fill performance
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
10 /* Call this instead of exit(), so we can clean up SDL: atexit() is evil. */ |
5ea08f1c29d0
Added testfill to test raw fill performance
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
11 static void |
5ea08f1c29d0
Added testfill to test raw fill performance
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
12 quit(int rc) |
5ea08f1c29d0
Added testfill to test raw fill performance
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
13 { |
5ea08f1c29d0
Added testfill to test raw fill performance
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
14 SDL_Quit(); |
5ea08f1c29d0
Added testfill to test raw fill performance
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
15 exit(rc); |
5ea08f1c29d0
Added testfill to test raw fill performance
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
16 } |
5ea08f1c29d0
Added testfill to test raw fill performance
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
17 |
5ea08f1c29d0
Added testfill to test raw fill performance
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
18 int |
5ea08f1c29d0
Added testfill to test raw fill performance
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
19 main(int argc, char *argv[]) |
5ea08f1c29d0
Added testfill to test raw fill performance
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
20 { |
5ea08f1c29d0
Added testfill to test raw fill performance
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
21 SDL_Surface *screen; |
5ea08f1c29d0
Added testfill to test raw fill performance
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
22 int width, height; |
5ea08f1c29d0
Added testfill to test raw fill performance
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
23 Uint8 video_bpp; |
5ea08f1c29d0
Added testfill to test raw fill performance
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
24 Uint32 videoflags; |
5ea08f1c29d0
Added testfill to test raw fill performance
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
25 Uint32 colors[3]; |
5ea08f1c29d0
Added testfill to test raw fill performance
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
26 int i, done; |
5ea08f1c29d0
Added testfill to test raw fill performance
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
27 SDL_Event event; |
5ea08f1c29d0
Added testfill to test raw fill performance
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
28 Uint32 then, now, frames; |
5ea08f1c29d0
Added testfill to test raw fill performance
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
29 |
5ea08f1c29d0
Added testfill to test raw fill performance
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
30 /* Initialize SDL */ |
5ea08f1c29d0
Added testfill to test raw fill performance
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
31 if (SDL_Init(SDL_INIT_VIDEO) < 0) { |
5ea08f1c29d0
Added testfill to test raw fill performance
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
32 fprintf(stderr, "Couldn't initialize SDL: %s\n", SDL_GetError()); |
5ea08f1c29d0
Added testfill to test raw fill performance
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
33 return (1); |
5ea08f1c29d0
Added testfill to test raw fill performance
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
34 } |
5ea08f1c29d0
Added testfill to test raw fill performance
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
35 |
5ea08f1c29d0
Added testfill to test raw fill performance
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
36 width = 640; |
5ea08f1c29d0
Added testfill to test raw fill performance
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
37 height = 480; |
5ea08f1c29d0
Added testfill to test raw fill performance
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
38 video_bpp = 8; |
5ea08f1c29d0
Added testfill to test raw fill performance
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
39 videoflags = 0; |
5ea08f1c29d0
Added testfill to test raw fill performance
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
40 while (argc > 1) { |
5ea08f1c29d0
Added testfill to test raw fill performance
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
41 --argc; |
5ea08f1c29d0
Added testfill to test raw fill performance
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
42 if (strcmp(argv[argc - 1], "-width") == 0) { |
5ea08f1c29d0
Added testfill to test raw fill performance
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
43 width = atoi(argv[argc]); |
5ea08f1c29d0
Added testfill to test raw fill performance
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
44 --argc; |
5ea08f1c29d0
Added testfill to test raw fill performance
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
45 } else if (strcmp(argv[argc - 1], "-height") == 0) { |
5ea08f1c29d0
Added testfill to test raw fill performance
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
46 height = atoi(argv[argc]); |
5ea08f1c29d0
Added testfill to test raw fill performance
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
47 --argc; |
5ea08f1c29d0
Added testfill to test raw fill performance
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
48 } else if (strcmp(argv[argc - 1], "-bpp") == 0) { |
5ea08f1c29d0
Added testfill to test raw fill performance
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
49 video_bpp = atoi(argv[argc]); |
5ea08f1c29d0
Added testfill to test raw fill performance
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
50 --argc; |
5ea08f1c29d0
Added testfill to test raw fill performance
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
51 } else if (strcmp(argv[argc], "-fullscreen") == 0) { |
5ea08f1c29d0
Added testfill to test raw fill performance
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
52 videoflags ^= SDL_FULLSCREEN; |
5ea08f1c29d0
Added testfill to test raw fill performance
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
53 } else { |
5ea08f1c29d0
Added testfill to test raw fill performance
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
54 fprintf(stderr, |
5ea08f1c29d0
Added testfill to test raw fill performance
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
55 "Usage: %s [-width N] [-height N] [-bpp N] [-fullscreen]\n", |
5ea08f1c29d0
Added testfill to test raw fill performance
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
56 argv[0]); |
5ea08f1c29d0
Added testfill to test raw fill performance
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
57 quit(1); |
5ea08f1c29d0
Added testfill to test raw fill performance
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
58 } |
5ea08f1c29d0
Added testfill to test raw fill performance
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
59 } |
5ea08f1c29d0
Added testfill to test raw fill performance
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
60 |
5ea08f1c29d0
Added testfill to test raw fill performance
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
61 /* Set video mode */ |
5ea08f1c29d0
Added testfill to test raw fill performance
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
62 screen = SDL_SetVideoMode(width, height, video_bpp, 0); |
5ea08f1c29d0
Added testfill to test raw fill performance
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
63 if (!screen) { |
5ea08f1c29d0
Added testfill to test raw fill performance
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
64 fprintf(stderr, "Couldn't set %dx%d video mode: %s\n", |
5ea08f1c29d0
Added testfill to test raw fill performance
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
65 width, height, SDL_GetError()); |
5ea08f1c29d0
Added testfill to test raw fill performance
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
66 quit(2); |
5ea08f1c29d0
Added testfill to test raw fill performance
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
67 } |
5ea08f1c29d0
Added testfill to test raw fill performance
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
68 |
5ea08f1c29d0
Added testfill to test raw fill performance
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
69 /* Get the colors */ |
5ea08f1c29d0
Added testfill to test raw fill performance
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
70 colors[0] = SDL_MapRGB(screen->format, 0xFF, 0x00, 0x00); |
5ea08f1c29d0
Added testfill to test raw fill performance
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
71 colors[1] = SDL_MapRGB(screen->format, 0x00, 0xFF, 0x00); |
5ea08f1c29d0
Added testfill to test raw fill performance
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
72 colors[2] = SDL_MapRGB(screen->format, 0x00, 0x00, 0xFF); |
5ea08f1c29d0
Added testfill to test raw fill performance
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
73 |
5ea08f1c29d0
Added testfill to test raw fill performance
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
74 /* Loop, filling and waiting for a keystroke */ |
5ea08f1c29d0
Added testfill to test raw fill performance
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
75 frames = 0; |
5ea08f1c29d0
Added testfill to test raw fill performance
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
76 then = SDL_GetTicks(); |
5ea08f1c29d0
Added testfill to test raw fill performance
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
77 done = 0; |
5ea08f1c29d0
Added testfill to test raw fill performance
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
78 while (!done) { |
5ea08f1c29d0
Added testfill to test raw fill performance
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
79 /* Check for events */ |
5ea08f1c29d0
Added testfill to test raw fill performance
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
80 ++frames; |
5ea08f1c29d0
Added testfill to test raw fill performance
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
81 while (SDL_PollEvent(&event)) { |
5ea08f1c29d0
Added testfill to test raw fill performance
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
82 switch (event.type) { |
5ea08f1c29d0
Added testfill to test raw fill performance
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
83 case SDL_MOUSEBUTTONDOWN: |
5ea08f1c29d0
Added testfill to test raw fill performance
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
84 SDL_WarpMouse(screen->w / 2, screen->h / 2); |
5ea08f1c29d0
Added testfill to test raw fill performance
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
85 break; |
5ea08f1c29d0
Added testfill to test raw fill performance
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
86 case SDL_KEYDOWN: |
5ea08f1c29d0
Added testfill to test raw fill performance
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
87 /* Any keypress quits the app... */ |
5ea08f1c29d0
Added testfill to test raw fill performance
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
88 case SDL_QUIT: |
5ea08f1c29d0
Added testfill to test raw fill performance
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
89 done = 1; |
5ea08f1c29d0
Added testfill to test raw fill performance
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
90 break; |
5ea08f1c29d0
Added testfill to test raw fill performance
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
91 default: |
5ea08f1c29d0
Added testfill to test raw fill performance
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
92 break; |
5ea08f1c29d0
Added testfill to test raw fill performance
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
93 } |
5ea08f1c29d0
Added testfill to test raw fill performance
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
94 } |
5ea08f1c29d0
Added testfill to test raw fill performance
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
95 SDL_FillRect(screen, NULL, colors[frames%3]); |
5ea08f1c29d0
Added testfill to test raw fill performance
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
96 SDL_Flip(screen); |
5ea08f1c29d0
Added testfill to test raw fill performance
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
97 } |
5ea08f1c29d0
Added testfill to test raw fill performance
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
98 |
5ea08f1c29d0
Added testfill to test raw fill performance
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
99 /* Print out some timing information */ |
5ea08f1c29d0
Added testfill to test raw fill performance
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
100 now = SDL_GetTicks(); |
5ea08f1c29d0
Added testfill to test raw fill performance
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
101 if (now > then) { |
5ea08f1c29d0
Added testfill to test raw fill performance
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
102 double fps = ((double) frames * 1000) / (now - then); |
5ea08f1c29d0
Added testfill to test raw fill performance
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
103 printf("%2.2f frames per second\n", fps); |
5ea08f1c29d0
Added testfill to test raw fill performance
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
104 } |
5ea08f1c29d0
Added testfill to test raw fill performance
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
105 SDL_Quit(); |
5ea08f1c29d0
Added testfill to test raw fill performance
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
106 return (0); |
5ea08f1c29d0
Added testfill to test raw fill performance
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
107 } |