Mercurial > sdl-ios-xcode
view test/testvidinfo.c @ 1629:ef4a796e7f24
Fixed bug #55
From Christian Walther:
When writing my patch for #12, I ended up doing all sorts of changes to the way
application/window activating/deactivating is handled in the Quartz backend,
resulting in the attached patch. It does make the code a bit cleaner IMHO, but
as it might be regarded as a case of "if it ain't broken, don't fix it" I'd
like to hear other people's opinion about it. Please shout if some change
strikes you as unnecessary or wrong, and I'll explain the reasons behind it. As
far as I tested it, it does not introduce any new bugs, but I may well have
missed some.
- The most fundamental change (that triggered most of the others) is irrelevant
for the usual single-window SDL applications, it only affects the people who
are crazy enough to display other Cocoa windows alongside the SDL window (I'm
actually doing this currently, although the additional window only displays
debugging info and won't be present in the final product): Before, some things
were done on the application becoming active, some on the window becoming key,
and some on the window becoming main. Conceptually, all these actions belong to
the window becoming key, so that's what I implemented. However, since in a
single-window application these three events always happen together, the
previous implementation "ain't broken".
- This slightly changed the meaning of the SDL_APPMOUSEFOCUS flag from
SDL_GetAppState(): Before, it meant "window is main and mouse is inside window
(or mode is fullscreen)". Now, it means "window is key and mouse is inside
window (or mode is fullscreen)". It makes more sense to me that way. (See
http://developer.apple.com/documentation/Cocoa/Conceptual/WinPanel/Concepts/ChangingMainKeyWindow.html
for a discussion of what key and main windows are.) The other two flags are
unchanged: SDL_APPACTIVE = application is not hidden and window is not
minimized, SDL_APPINPUTFOCUS = window is key (or mode is fullscreen).
- As a side effect, the reorganization fixes the following two issues (and
maybe others) (but they could also be fixed in less invasive ways):
* A regression that was introduced in revision 1.42 of SDL_QuartzVideo.m
(http://libsdl.org/cgi/cvsweb.cgi/SDL12/src/video/quartz/SDL_QuartzVideo.m.diff?r1=1.41&r2=1.42)
(from half-desirable to undesirable behavior):
Situation: While in windowed mode, hide the cursor using
SDL_ShowCursor(SDL_DISABLE), move the mouse outside of the window so that the
cursor becomes visible again, and SDL_SetVideoMode() to a fullscreen mode.
What happened before revision 1.42: The cursor is visible, but becomes
invisible as soon as the mouse is moved (half-desirable).
What happens in revision 1.42 and after (including current CVS): The cursor is
visible and stays visible (undesirable).
What happens after my patch: The cursor is invisible from the beginning
(desirable).
* When the cursor is hidden and grabbed, switch away from the application using
cmd-tab (which ungrabs and makes the cursor visible), move the cursor outside
of the SDL window, then cmd-tab back to the application. In 1.2.8 and in the
current CVS, the cursor is re-grabbed, but it stays visible (immovable in the
middle of the window). With my patch, the cursor is correctly re-grabbed and
hidden. (For some reason, it still doesn't work correctly if you switch back to
the application using the dock instead of cmd-tab. I haven't been able to
figure out why. I can step over [NSCursor hide] being called in the debugger,
but it seems to have no effect.)
- The patch includes my patch for #12 (it was easier to obtain using cvs diff
that way). If you apply both of them, you will end up with 6 duplicate lines in
SDL_QuartzEvents.m.
author | Sam Lantinga <slouken@libsdl.org> |
---|---|
date | Thu, 13 Apr 2006 14:17:48 +0000 |
parents | 8d9bb0cf2c2a |
children | 8b9d79e7eacf c121d94672cb |
line wrap: on
line source
/* Simple program -- figure out what kind of video display we have */ #include <stdlib.h> #include <stdio.h> #include <stdlib.h> #include <string.h> #include "SDL.h" #define NUM_BLITS 10 #define NUM_UPDATES 500 #define FLAG_MASK (SDL_HWSURFACE | SDL_FULLSCREEN | SDL_DOUBLEBUF | \ SDL_SRCCOLORKEY | SDL_SRCALPHA | SDL_RLEACCEL | \ SDL_RLEACCELOK) void PrintFlags(Uint32 flags) { printf("0x%8.8x", (flags & FLAG_MASK)); if ( flags & SDL_HWSURFACE ) { printf(" SDL_HWSURFACE"); } else { printf(" SDL_SWSURFACE"); } if ( flags & SDL_FULLSCREEN ) { printf(" | SDL_FULLSCREEN"); } if ( flags & SDL_DOUBLEBUF ) { printf(" | SDL_DOUBLEBUF"); } if ( flags & SDL_SRCCOLORKEY ) { printf(" | SDL_SRCCOLORKEY"); } if ( flags & SDL_SRCALPHA ) { printf(" | SDL_SRCALPHA"); } if ( flags & SDL_RLEACCEL ) { printf(" | SDL_RLEACCEL"); } if ( flags & SDL_RLEACCELOK ) { printf(" | SDL_RLEACCELOK"); } } int RunBlitTests(SDL_Surface *screen, SDL_Surface *bmp, int blitcount) { int i, j; int maxx; int maxy; SDL_Rect dst; maxx = (int)screen->w - bmp->w + 1; maxy = (int)screen->h - bmp->h + 1; for ( i = 0; i < NUM_UPDATES; ++i ) { for ( j = 0; j < blitcount; ++j ) { if ( maxx ) { dst.x = rand() % maxx; } else { dst.x = 0; } if ( maxy ) { dst.y = rand() % maxy; } else { dst.y = 0; } dst.w = bmp->w; dst.h = bmp->h; SDL_BlitSurface(bmp, NULL, screen, &dst); } SDL_Flip(screen); } return i; } int RunModeTests(SDL_Surface *screen) { Uint32 then, now; Uint32 frames; float seconds; int i; Uint8 r, g, b; SDL_Surface *bmp, *bmpcc, *tmp; SDL_Event event; while ( SDL_PollEvent(&event) ) { if ( event.type == SDL_KEYDOWN ) return 0; } /* First test fills and screen update speed */ printf("Running color fill and fullscreen update test\n"); then = SDL_GetTicks(); frames = 0; for ( i = 0; i < 256; ++i ) { r = i; g = 0; b = 0; SDL_FillRect(screen, NULL, SDL_MapRGB(screen->format, r, g, b)); SDL_Flip(screen); ++frames; } for ( i = 0; i < 256; ++i ) { r = 0; g = i; b = 0; SDL_FillRect(screen, NULL, SDL_MapRGB(screen->format, r, g, b)); SDL_Flip(screen); ++frames; } for ( i = 0; i < 256; ++i ) { r = 0; g = 0; b = i; SDL_FillRect(screen, NULL, SDL_MapRGB(screen->format, r, g, b)); SDL_Flip(screen); ++frames; } now = SDL_GetTicks(); seconds = (float)(now - then) / 1000.0f; if ( seconds > 0.0f ) { printf("%d fills and flips in %2.2f seconds, %2.2f FPS\n", frames, seconds, (float)frames / seconds); } else { printf("%d fills and flips in zero seconds!n", frames); } /* clear the screen after fill test */ SDL_FillRect(screen, NULL, SDL_MapRGB(screen->format, 0, 0, 0)); SDL_Flip(screen); while ( SDL_PollEvent(&event) ) { if ( event.type == SDL_KEYDOWN ) return 0; } /* run the generic blit test */ bmp = SDL_LoadBMP("sample.bmp"); if ( ! bmp ) { printf("Couldn't load sample.bmp: %s\n", SDL_GetError()); return 0; } printf("Running freshly loaded blit test: %dx%d at %d bpp, flags: ", bmp->w, bmp->h, bmp->format->BitsPerPixel); PrintFlags(bmp->flags); printf("\n"); then = SDL_GetTicks(); frames = RunBlitTests(screen, bmp, NUM_BLITS); now = SDL_GetTicks(); seconds = (float)(now - then) / 1000.0f; if ( seconds > 0.0f ) { printf("%d blits / %d updates in %2.2f seconds, %2.2f FPS\n", NUM_BLITS*frames, frames, seconds, (float)frames / seconds); } else { printf("%d blits / %d updates in zero seconds!\n", NUM_BLITS*frames, frames); } /* clear the screen after blit test */ SDL_FillRect(screen, NULL, SDL_MapRGB(screen->format, 0, 0, 0)); SDL_Flip(screen); while ( SDL_PollEvent(&event) ) { if ( event.type == SDL_KEYDOWN ) return 0; } /* run the colorkeyed blit test */ bmpcc = SDL_LoadBMP("sample.bmp"); if ( ! bmpcc ) { printf("Couldn't load sample.bmp: %s\n", SDL_GetError()); return 0; } printf("Running freshly loaded cc blit test: %dx%d at %d bpp, flags: ", bmpcc->w, bmpcc->h, bmpcc->format->BitsPerPixel); SDL_SetColorKey(bmpcc, SDL_SRCCOLORKEY | SDL_RLEACCEL, *(Uint8 *)bmpcc->pixels); PrintFlags(bmpcc->flags); printf("\n"); then = SDL_GetTicks(); frames = RunBlitTests(screen, bmpcc, NUM_BLITS); now = SDL_GetTicks(); seconds = (float)(now - then) / 1000.0f; if ( seconds > 0.0f ) { printf("%d cc blits / %d updates in %2.2f seconds, %2.2f FPS\n", NUM_BLITS*frames, frames, seconds, (float)frames / seconds); } else { printf("%d cc blits / %d updates in zero seconds!\n", NUM_BLITS*frames, frames); } /* clear the screen after cc blit test */ SDL_FillRect(screen, NULL, SDL_MapRGB(screen->format, 0, 0, 0)); SDL_Flip(screen); while ( SDL_PollEvent(&event) ) { if ( event.type == SDL_KEYDOWN ) return 0; } /* run the generic blit test */ tmp = bmp; bmp = SDL_DisplayFormat(bmp); SDL_FreeSurface(tmp); if ( ! bmp ) { printf("Couldn't convert sample.bmp: %s\n", SDL_GetError()); return 0; } printf("Running display format blit test: %dx%d at %d bpp, flags: ", bmp->w, bmp->h, bmp->format->BitsPerPixel); PrintFlags(bmp->flags); printf("\n"); then = SDL_GetTicks(); frames = RunBlitTests(screen, bmp, NUM_BLITS); now = SDL_GetTicks(); seconds = (float)(now - then) / 1000.0f; if ( seconds > 0.0f ) { printf("%d blits / %d updates in %2.2f seconds, %2.2f FPS\n", NUM_BLITS*frames, frames, seconds, (float)frames / seconds); } else { printf("%d blits / %d updates in zero seconds!\n", NUM_BLITS*frames, frames); } /* clear the screen after blit test */ SDL_FillRect(screen, NULL, SDL_MapRGB(screen->format, 0, 0, 0)); SDL_Flip(screen); while ( SDL_PollEvent(&event) ) { if ( event.type == SDL_KEYDOWN ) return 0; } /* run the colorkeyed blit test */ tmp = bmpcc; bmpcc = SDL_DisplayFormat(bmpcc); SDL_FreeSurface(tmp); if ( ! bmpcc ) { printf("Couldn't convert sample.bmp: %s\n", SDL_GetError()); return 0; } printf("Running display format cc blit test: %dx%d at %d bpp, flags: ", bmpcc->w, bmpcc->h, bmpcc->format->BitsPerPixel); PrintFlags(bmpcc->flags); printf("\n"); then = SDL_GetTicks(); frames = RunBlitTests(screen, bmpcc, NUM_BLITS); now = SDL_GetTicks(); seconds = (float)(now - then) / 1000.0f; if ( seconds > 0.0f ) { printf("%d cc blits / %d updates in %2.2f seconds, %2.2f FPS\n", NUM_BLITS*frames, frames, seconds, (float)frames / seconds); } else { printf("%d cc blits / %d updates in zero seconds!\n", NUM_BLITS*frames, frames); } /* clear the screen after cc blit test */ SDL_FillRect(screen, NULL, SDL_MapRGB(screen->format, 0, 0, 0)); SDL_Flip(screen); while ( SDL_PollEvent(&event) ) { if ( event.type == SDL_KEYDOWN ) return 0; } /* run the alpha blit test only if screen bpp>8 */ if (bmp->format->BitsPerPixel>8) { SDL_FreeSurface(bmp); bmp = SDL_LoadBMP("sample.bmp"); SDL_SetAlpha(bmp, SDL_SRCALPHA, 85); /* 85 - 33% alpha */ tmp = bmp; bmp = SDL_DisplayFormat(bmp); SDL_FreeSurface(tmp); if ( ! bmp ) { printf("Couldn't convert sample.bmp: %s\n", SDL_GetError()); return 0; } printf("Running display format alpha blit test: %dx%d at %d bpp, flags: ", bmp->w, bmp->h, bmp->format->BitsPerPixel); PrintFlags(bmp->flags); printf("\n"); then = SDL_GetTicks(); frames = RunBlitTests(screen, bmp, NUM_BLITS); now = SDL_GetTicks(); seconds = (float)(now - then) / 1000.0f; if ( seconds > 0.0f ) { printf("%d alpha blits / %d updates in %2.2f seconds, %2.2f FPS\n", NUM_BLITS*frames, frames, seconds, (float)frames / seconds); } else { printf("%d alpha blits / %d updates in zero seconds!\n", NUM_BLITS*frames, frames); } } /* clear the screen after alpha blit test */ SDL_FillRect(screen, NULL, SDL_MapRGB(screen->format, 0, 0, 0)); SDL_Flip(screen); while ( SDL_PollEvent(&event) ) { if ( event.type == SDL_KEYDOWN ) return 0; } /* run the cc+alpha blit test only if screen bpp>8 */ if (bmp->format->BitsPerPixel>8) { SDL_FreeSurface(bmpcc); bmpcc = SDL_LoadBMP("sample.bmp"); SDL_SetAlpha(bmpcc, SDL_SRCALPHA, 85); /* 85 - 33% alpha */ SDL_SetColorKey(bmpcc, SDL_SRCCOLORKEY | SDL_RLEACCEL, *(Uint8 *)bmpcc->pixels); tmp = bmpcc; bmpcc = SDL_DisplayFormat(bmpcc); SDL_FreeSurface(tmp); if ( ! bmpcc ) { printf("Couldn't convert sample.bmp: %s\n", SDL_GetError()); return 0; } printf("Running display format cc+alpha blit test: %dx%d at %d bpp, flags: ", bmpcc->w, bmpcc->h, bmpcc->format->BitsPerPixel); PrintFlags(bmpcc->flags); printf("\n"); then = SDL_GetTicks(); frames = RunBlitTests(screen, bmpcc, NUM_BLITS); now = SDL_GetTicks(); seconds = (float)(now - then) / 1000.0f; if ( seconds > 0.0f ) { printf("%d cc+alpha blits / %d updates in %2.2f seconds, %2.2f FPS\n", NUM_BLITS*frames, frames, seconds, (float)frames / seconds); } else { printf("%d cc+alpha blits / %d updates in zero seconds!\n", NUM_BLITS*frames, frames); } } SDL_FreeSurface(bmpcc); SDL_FreeSurface(bmp); while ( SDL_PollEvent(&event) ) { if ( event.type == SDL_KEYDOWN ) return 0; } return 1; } void RunVideoTests() { static const struct { int w, h, bpp; } mode_list[] = { { 640, 480, 8 }, { 640, 480, 16 }, { 640, 480, 32 }, { 800, 600, 8 }, { 800, 600, 16 }, { 800, 600, 32 }, { 1024, 768, 8 }, { 1024, 768, 16 }, { 1024, 768, 32 } }; static const Uint32 flags[] = { (SDL_SWSURFACE), (SDL_SWSURFACE | SDL_FULLSCREEN), (SDL_HWSURFACE | SDL_FULLSCREEN), (SDL_HWSURFACE | SDL_FULLSCREEN | SDL_DOUBLEBUF) }; int i, j; SDL_Surface *screen; /* Test out several different video mode combinations */ SDL_WM_SetCaption("SDL Video Benchmark", "vidtest"); SDL_ShowCursor(0); for ( i = 0; i < SDL_TABLESIZE(mode_list); ++i ) { for ( j = 0; j < SDL_TABLESIZE(flags); ++j ) { printf("===================================\n"); printf("Setting video mode: %dx%d at %d bpp, flags: ", mode_list[i].w, mode_list[i].h, mode_list[i].bpp); PrintFlags(flags[j]); printf("\n"); screen = SDL_SetVideoMode(mode_list[i].w, mode_list[i].h, mode_list[i].bpp, flags[j]); if ( ! screen ) { printf("Setting video mode failed: %s\n", SDL_GetError()); continue; } if ( (screen->flags & FLAG_MASK) != flags[j] ) { printf("Flags didn't match: "); PrintFlags(screen->flags); printf("\n"); continue; } if ( ! RunModeTests(screen) ) { return; } } } } int main(int argc, char *argv[]) { const SDL_VideoInfo *info; int i; SDL_Rect **modes; char driver[128]; if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) { fprintf(stderr, "Couldn't initialize SDL: %s\n", SDL_GetError()); exit(1); } if ( SDL_VideoDriverName(driver, sizeof(driver)) ) { printf("Video driver: %s\n", driver); } info = SDL_GetVideoInfo(); printf( "Current display: %dx%d, %d bits-per-pixel\n", info->current_w, info->current_h, info->vfmt->BitsPerPixel); if ( info->vfmt->palette == NULL ) { printf(" Red Mask = 0x%.8x\n", info->vfmt->Rmask); printf(" Green Mask = 0x%.8x\n", info->vfmt->Gmask); printf(" Blue Mask = 0x%.8x\n", info->vfmt->Bmask); } /* Print available fullscreen video modes */ modes = SDL_ListModes(NULL, SDL_FULLSCREEN); if ( modes == (SDL_Rect **)0 ) { printf("No available fullscreen video modes\n"); } else if ( modes == (SDL_Rect **)-1 ) { printf("No special fullscreen video modes\n"); } else { printf("Fullscreen video modes:\n"); for ( i=0; modes[i]; ++i ) { printf("\t%dx%dx%d\n", modes[i]->w, modes[i]->h, info->vfmt->BitsPerPixel); } } if ( info->wm_available ) { printf("A window manager is available\n"); } if ( info->hw_available ) { printf("Hardware surfaces are available (%dK video memory)\n", info->video_mem); } if ( info->blit_hw ) { printf( "Copy blits between hardware surfaces are accelerated\n"); } if ( info->blit_hw_CC ) { printf( "Colorkey blits between hardware surfaces are accelerated\n"); } if ( info->blit_hw_A ) { printf( "Alpha blits between hardware surfaces are accelerated\n"); } if ( info->blit_sw ) { printf( "Copy blits from software surfaces to hardware surfaces are accelerated\n"); } if ( info->blit_sw_CC ) { printf( "Colorkey blits from software surfaces to hardware surfaces are accelerated\n"); } if ( info->blit_sw_A ) { printf( "Alpha blits from software surfaces to hardware surfaces are accelerated\n"); } if ( info->blit_fill ) { printf( "Color fills on hardware surfaces are accelerated\n"); } if ( argv[1] && (strcmp(argv[1], "-benchmark") == 0) ) { RunVideoTests(); } SDL_Quit(); return(0); }