annotate test/testblitspeed.c @ 1099:1ccbb2b7d905

Date: Fri, 15 Jul 2005 08:29:01 +0100 From: "alan buckley" Subject: SDL Improved semiphore implementation for RISC OS (version 2) I've attached a new version of the patch for the RISC OS semaphore processing (in a zip file) that updates it to use the improved semaphores support in UnixLiib.
author Sam Lantinga <slouken@libsdl.org>
date Thu, 21 Jul 2005 06:19:18 +0000
parents 68f2b997758e
children cf59e7b91ed4
rev   line source
1039
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1 /*
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
2 * Benchmarks surface-to-surface blits in various formats.
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
3 *
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
4 * Written by Ryan C. Gordon.
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
5 */
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
6
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
7 #include <stdio.h>
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
8 #include <stdlib.h>
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
9 #include <string.h>
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
10
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
11 #include "SDL.h"
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
12
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
13 static SDL_Surface *dest = NULL;
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
14 static SDL_Surface *src = NULL;
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
15 static int testSeconds = 10;
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
16
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
17
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
18 static int percent(int val, int total)
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
19 {
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
20 return((int) ((((float) val) / ((float) total)) * 100.0f));
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
21 }
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
22
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
23 static int randRange(int lo, int hi)
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
24 {
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
25 return(lo + (int) (((double) hi)*rand()/(RAND_MAX+1.0)));
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
26 }
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
27
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
28 static void copy_trunc_str(char *str, size_t strsize, const char *flagstr)
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
29 {
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
30 if ( (strlen(str) + strlen(flagstr)) >= (strsize - 1) )
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
31 strcpy(str + (strsize - 5), " ...");
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
32 else
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
33 strcat(str, flagstr);
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
34 }
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
35
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
36 static void __append_sdl_surface_flag(SDL_Surface *_surface, char *str,
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
37 size_t strsize, Uint32 flag,
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
38 const char *flagstr)
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
39 {
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
40 if (_surface->flags & flag)
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
41 copy_trunc_str(str, strsize, flagstr);
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
42 } /* append_sdl_surface_flag */
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
43
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
44
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
45 #define append_sdl_surface_flag(a, b, c, fl) __append_sdl_surface_flag(a, b, c, fl, " " #fl)
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
46 #define print_tf_state(str, val) printf("%s: {%s}\n", str, (val) ? "true" : "false" )
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
47
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
48 static void output_surface_details(const char *name, SDL_Surface *surface)
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
49 {
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
50 printf("Details for %s:\n", name);
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
51
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
52 if (surface == NULL)
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
53 {
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
54 printf("-WARNING- You've got a NULL surface!");
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
55 }
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
56 else
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
57 {
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
58 char f[256];
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
59 printf(" width : %d\n", surface->w);
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
60 printf(" height : %d\n", surface->h);
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
61 printf(" depth : %d bits per pixel\n", surface->format->BitsPerPixel);
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
62 printf(" pitch : %d\n", (int) surface->pitch);
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
63
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
64 printf(" red : 0x%08X mask, %d shift, %d loss\n",
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
65 (int) surface->format->Rmask,
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
66 (int) surface->format->Rshift,
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
67 (int) surface->format->Rloss);
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
68 printf(" green : 0x%08X mask, %d shift, %d loss\n",
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
69 (int) surface->format->Gmask,
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
70 (int) surface->format->Gshift,
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
71 (int) surface->format->Gloss);
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
72 printf(" blue : 0x%08X mask, %d shift, %d loss\n",
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
73 (int) surface->format->Bmask,
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
74 (int) surface->format->Bshift,
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
75 (int) surface->format->Bloss);
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
76 printf(" alpha : 0x%08X mask, %d shift, %d loss\n",
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
77 (int) surface->format->Amask,
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
78 (int) surface->format->Ashift,
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
79 (int) surface->format->Aloss);
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
80
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
81 f[0] = '\0';
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
82
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
83 /*append_sdl_surface_flag(surface, f, sizeof (f), SDL_SWSURFACE);*/
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
84 if ((surface->flags & SDL_HWSURFACE) == 0)
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
85 copy_trunc_str(f, sizeof (f), " SDL_SWSURFACE");
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
86
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
87 append_sdl_surface_flag(surface, f, sizeof (f), SDL_HWSURFACE);
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
88 append_sdl_surface_flag(surface, f, sizeof (f), SDL_ASYNCBLIT);
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
89 append_sdl_surface_flag(surface, f, sizeof (f), SDL_ANYFORMAT);
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
90 append_sdl_surface_flag(surface, f, sizeof (f), SDL_HWPALETTE);
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
91 append_sdl_surface_flag(surface, f, sizeof (f), SDL_DOUBLEBUF);
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
92 append_sdl_surface_flag(surface, f, sizeof (f), SDL_FULLSCREEN);
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
93 append_sdl_surface_flag(surface, f, sizeof (f), SDL_OPENGL);
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
94 append_sdl_surface_flag(surface, f, sizeof (f), SDL_OPENGLBLIT);
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
95 append_sdl_surface_flag(surface, f, sizeof (f), SDL_RESIZABLE);
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
96 append_sdl_surface_flag(surface, f, sizeof (f), SDL_NOFRAME);
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
97 append_sdl_surface_flag(surface, f, sizeof (f), SDL_HWACCEL);
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
98 append_sdl_surface_flag(surface, f, sizeof (f), SDL_SRCCOLORKEY);
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
99 append_sdl_surface_flag(surface, f, sizeof (f), SDL_RLEACCELOK);
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
100 append_sdl_surface_flag(surface, f, sizeof (f), SDL_RLEACCEL);
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
101 append_sdl_surface_flag(surface, f, sizeof (f), SDL_SRCALPHA);
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
102 append_sdl_surface_flag(surface, f, sizeof (f), SDL_PREALLOC);
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
103
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
104 if (f[0] == '\0')
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
105 strcpy(f, " (none)");
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
106
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
107 printf(" flags :%s\n", f);
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
108
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
109 #if 0
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
110 info = SDL_GetVideoInfo();
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
111 assert(info != NULL);
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
112
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
113 print_tf_state("hardware surface available", info->hw_available);
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
114 print_tf_state("window manager available", info->wm_available);
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
115 print_tf_state("accelerated hardware->hardware blits", info->blit_hw);
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
116 print_tf_state("accelerated hardware->hardware colorkey blits", info->blit_hw_CC);
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
117 print_tf_state("accelerated hardware->hardware alpha blits", info->blit_hw_A);
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
118 print_tf_state("accelerated software->hardware blits", info->blit_sw);
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
119 print_tf_state("accelerated software->hardware colorkey blits", info->blit_sw_CC);
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
120 print_tf_state("accelerated software->hardware alpha blits", info->blit_sw_A);
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
121 print_tf_state("accelerated color fills", info->blit_fill);
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
122
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
123 printf("video memory: (%d)\n", info->video_mem);
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
124 #endif
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
125 } /* else */
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
126
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
127 printf("\n");
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
128 }
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
129
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
130 static void output_details(void)
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
131 {
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
132 output_surface_details("Source Surface", src);
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
133 output_surface_details("Destination Surface", dest);
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
134 }
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
135
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
136 static Uint32 blit(SDL_Surface *dst, SDL_Surface *src, int x, int y)
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
137 {
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
138 Uint32 start = 0;
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
139 SDL_Rect srcRect;
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
140 SDL_Rect dstRect;
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
141
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
142 srcRect.x = 0;
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
143 srcRect.y = 0;
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
144 dstRect.x = x;
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
145 dstRect.y = y;
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
146 dstRect.w = srcRect.w = src->w; /* SDL will clip as appropriate. */
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
147 dstRect.h = srcRect.h = src->h;
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
148
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
149 start = SDL_GetTicks();
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
150 SDL_BlitSurface(src, &srcRect, dst, &dstRect);
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
151 return(SDL_GetTicks() - start);
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
152 }
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
153
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
154 static void blitCentered(SDL_Surface *dst, SDL_Surface *src)
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
155 {
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
156 int x = (dst->w - src->w) / 2;
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
157 int y = (dst->h - src->h) / 2;
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
158 blit(dst, src, x, y);
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
159 }
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
160
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
161 static int atoi_hex(const char *str)
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
162 {
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
163 if (str == NULL)
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
164 return 0;
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
165
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
166 if (strlen(str) > 2)
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
167 {
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
168 int retval = 0;
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
169 if ((str[0] == '0') && (str[1] == 'x'))
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
170 sscanf(str + 2, "%X", &retval);
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
171 return(retval);
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
172 }
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
173
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
174 return(atoi(str));
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
175 }
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
176
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
177
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
178 static int setup_test(int argc, char **argv)
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
179 {
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
180 const char *dumpfile = NULL;
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
181 SDL_Surface *bmp = NULL;
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
182 Uint32 dstbpp = 32;
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
183 Uint32 dstrmask = 0x00FF0000;
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
184 Uint32 dstgmask = 0x0000FF00;
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
185 Uint32 dstbmask = 0x000000FF;
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
186 Uint32 dstamask = 0x00000000;
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
187 Uint32 dstflags = 0;
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
188 int dstw = 640;
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
189 int dsth = 480;
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
190 Uint32 srcbpp = 32;
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
191 Uint32 srcrmask = 0x00FF0000;
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
192 Uint32 srcgmask = 0x0000FF00;
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
193 Uint32 srcbmask = 0x000000FF;
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
194 Uint32 srcamask = 0x00000000;
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
195 Uint32 srcflags = 0;
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
196 int srcw = 640;
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
197 int srch = 480;
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
198 int screenSurface = 0;
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
199 int i;
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
200
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
201 for (i = 1; i < argc; i++)
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
202 {
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
203 const char *arg = argv[i];
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
204
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
205 if (strcmp(arg, "--dstbpp") == 0)
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
206 dstbpp = atoi(argv[++i]);
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
207 else if (strcmp(arg, "--dstrmask") == 0)
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
208 dstrmask = atoi_hex(argv[++i]);
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
209 else if (strcmp(arg, "--dstgmask") == 0)
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
210 dstgmask = atoi_hex(argv[++i]);
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
211 else if (strcmp(arg, "--dstbmask") == 0)
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
212 dstbmask = atoi_hex(argv[++i]);
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
213 else if (strcmp(arg, "--dstamask") == 0)
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
214 dstamask = atoi_hex(argv[++i]);
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
215 else if (strcmp(arg, "--dstwidth") == 0)
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
216 dstw = atoi(argv[++i]);
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
217 else if (strcmp(arg, "--dstheight") == 0)
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
218 dsth = atoi(argv[++i]);
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
219 else if (strcmp(arg, "--dsthwsurface") == 0)
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
220 dstflags |= SDL_HWSURFACE;
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
221 else if (strcmp(arg, "--srcbpp") == 0)
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
222 srcbpp = atoi(argv[++i]);
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
223 else if (strcmp(arg, "--srcrmask") == 0)
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
224 srcrmask = atoi_hex(argv[++i]);
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
225 else if (strcmp(arg, "--srcgmask") == 0)
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
226 srcgmask = atoi_hex(argv[++i]);
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
227 else if (strcmp(arg, "--srcbmask") == 0)
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
228 srcbmask = atoi_hex(argv[++i]);
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
229 else if (strcmp(arg, "--srcamask") == 0)
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
230 srcamask = atoi_hex(argv[++i]);
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
231 else if (strcmp(arg, "--srcwidth") == 0)
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
232 srcw = atoi(argv[++i]);
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
233 else if (strcmp(arg, "--srcheight") == 0)
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
234 srch = atoi(argv[++i]);
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
235 else if (strcmp(arg, "--srchwsurface") == 0)
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
236 srcflags |= SDL_HWSURFACE;
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
237 else if (strcmp(arg, "--seconds") == 0)
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
238 testSeconds = atoi(argv[++i]);
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
239 else if (strcmp(arg, "--screen") == 0)
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
240 screenSurface = 1;
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
241 else if (strcmp(arg, "--dumpfile") == 0)
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
242 dumpfile = argv[++i];
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
243 else
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
244 {
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
245 fprintf(stderr, "Unknown commandline option: %s\n", arg);
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
246 return(0);
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
247 }
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
248 }
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
249
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
250 if (SDL_Init(SDL_INIT_VIDEO) == -1)
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
251 {
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
252 fprintf(stderr, "SDL_Init failed: %s\n", SDL_GetError());
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
253 return(0);
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
254 }
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
255
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
256 bmp = SDL_LoadBMP("sample.bmp");
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
257 if (bmp == NULL)
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
258 {
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
259 fprintf(stderr, "SDL_LoadBMP failed: %s\n", SDL_GetError());
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
260 SDL_Quit();
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
261 return(0);
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
262 }
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
263
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
264 if ((dstflags & SDL_HWSURFACE) == 0) dstflags |= SDL_SWSURFACE;
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
265 if ((srcflags & SDL_HWSURFACE) == 0) srcflags |= SDL_SWSURFACE;
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
266
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
267 if (screenSurface)
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
268 dest = SDL_SetVideoMode(dstw, dsth, dstbpp, dstflags);
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
269 else
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
270 {
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
271 dest = SDL_CreateRGBSurface(dstflags, dstw, dsth, dstbpp,
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
272 dstrmask, dstgmask, dstbmask, dstamask);
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
273 }
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
274
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
275 if (dest == NULL)
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
276 {
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
277 fprintf(stderr, "dest surface creation failed: %s\n", SDL_GetError());
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
278 SDL_Quit();
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
279 return(0);
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
280 }
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
281
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
282 src = SDL_CreateRGBSurface(srcflags, srcw, srch, srcbpp,
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
283 srcrmask, srcgmask, srcbmask, srcamask);
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
284 if (src == NULL)
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
285 {
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
286 fprintf(stderr, "src surface creation failed: %s\n", SDL_GetError());
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
287 SDL_Quit();
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
288 return(0);
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
289 }
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
290
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
291 /* set some sane defaults so we can see if the blit code is broken... */
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
292 SDL_FillRect(dest, NULL, SDL_MapRGB(dest->format, 0, 0, 0));
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
293 SDL_FillRect(src, NULL, SDL_MapRGB(src->format, 0, 0, 0));
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
294
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
295 blitCentered(src, bmp);
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
296 SDL_FreeSurface(bmp);
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
297
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
298 if (dumpfile)
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
299 SDL_SaveBMP(src, dumpfile); /* make sure initial convert is sane. */
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
300
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
301 output_details();
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
302
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
303 return(1);
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
304 }
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
305
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
306
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
307 static void test_blit_speed(void)
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
308 {
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
309 Uint32 clearColor = SDL_MapRGB(dest->format, 0, 0, 0);
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
310 Uint32 iterations = 0;
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
311 Uint32 elasped = 0;
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
312 Uint32 end = 0;
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
313 Uint32 now = 0;
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
314 Uint32 last = 0;
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
315 int testms = testSeconds * 1000;
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
316 int wmax = (dest->w - src->w);
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
317 int hmax = (dest->h - src->h);
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
318 int isScreen = (SDL_GetVideoSurface() == dest);
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
319 SDL_Event event;
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
320
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
321 printf("Testing blit speed for %d seconds...\n", testSeconds);
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
322
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
323 now = SDL_GetTicks();
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
324 end = now + testms;
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
325
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
326 do
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
327 {
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
328 /* pump the event queue occasionally to keep OS happy... */
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
329 if (now - last > 1000)
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
330 {
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
331 last = now;
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
332 while (SDL_PollEvent(&event)) { /* no-op. */ }
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
333 }
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
334
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
335 iterations++;
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
336 elasped += blit(dest, src, randRange(0, wmax), randRange(0, hmax));
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
337 if (isScreen)
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
338 {
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
339 SDL_Flip(dest); /* show it! */
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
340 SDL_FillRect(dest, NULL, clearColor); /* blank it for next time! */
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
341 }
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
342
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
343 now = SDL_GetTicks();
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
344 } while (now < end);
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
345
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
346 printf("Non-blitting crap accounted for %d percent of this run.\n",
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
347 percent(testms - elasped, testms));
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
348
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
349 printf("%d blits took %d ms (%d fps).\n",
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
350 (int) iterations,
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
351 (int) elasped,
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
352 (int) (((float)iterations) / (((float)elasped) / 1000.0f)));
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
353 }
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
354
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
355 int main(int argc, char **argv)
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
356 {
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
357 int initialized = setup_test(argc, argv);
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
358 if (initialized)
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
359 {
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
360 test_blit_speed();
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
361 SDL_Quit();
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
362 }
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
363 return(!initialized);
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
364 }
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
365
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
366 /* end of testblitspeed.c ... */
68f2b997758e Added testblitspeed to aid in profiling of SDL's blitters.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
367