From 66fb9eece63b206565e8be322556c76dd71bccbe Mon Sep 17 00:00:00 2001 From: Glenn Maynard Date: Mon, 14 Jun 2004 01:09:11 +0000 Subject: [PATCH] use RageSurface --- .../src/arch/ArchHooks/ArchHooks_Win32.cpp | 2 +- .../arch/LoadingWindow/LoadingWindow_SDL.cpp | 47 ++++++++++++------- .../LoadingWindow/LoadingWindow_Win32.cpp | 9 ++-- .../arch/MovieTexture/MovieTexture_DShow.cpp | 17 +++---- .../arch/MovieTexture/MovieTexture_FFMpeg.cpp | 7 +-- .../arch/MovieTexture/MovieTexture_FFMpeg.h | 2 +- .../arch/MovieTexture/MovieTexture_Null.cpp | 7 +-- 7 files changed, 53 insertions(+), 38 deletions(-) diff --git a/stepmania/src/arch/ArchHooks/ArchHooks_Win32.cpp b/stepmania/src/arch/ArchHooks/ArchHooks_Win32.cpp index dce05e1d04..7c8e0da336 100644 --- a/stepmania/src/arch/ArchHooks/ArchHooks_Win32.cpp +++ b/stepmania/src/arch/ArchHooks/ArchHooks_Win32.cpp @@ -14,7 +14,7 @@ #include "archutils/win32/WindowsResources.h" #include -#pragma comment(lib, "winmm.lib") // for GetMicrosecondsSinceStart +#pragma comment(lib, "winmm.lib") // for timeGetTime ArchHooks_Win32::ArchHooks_Win32() { diff --git a/stepmania/src/arch/LoadingWindow/LoadingWindow_SDL.cpp b/stepmania/src/arch/LoadingWindow/LoadingWindow_SDL.cpp index e569f24e56..1f8a2b4519 100644 --- a/stepmania/src/arch/LoadingWindow/LoadingWindow_SDL.cpp +++ b/stepmania/src/arch/LoadingWindow/LoadingWindow_SDL.cpp @@ -7,6 +7,8 @@ #include "LoadingWindow_SDL.h" #include "loading.xpm" #include "StepMania.xpm" /* icon */ +#include "RageSurface.h" +#include "RageSurfaceUtils.h" /* XXX: What is all this Xbox junk doing in LoadingWindow_SDL? */ @@ -27,34 +29,40 @@ LoadingWindow_SDL::LoadingWindow_SDL() SDL_WM_SetCaption("Loading StepMania", ""); CString error; - SDL_Surface *srf = RageSurface_Load_XPM( icon, error ); + RageSurface *srf = RageSurface_Load_XPM( icon, error ); - Uint32 color; - if( mySDL_MapRGBExact( srf->format, 0xFF, 0, 0xFF, color ) ) - mySDL_AddColorKey( srf, color ); + uint32_t color; + if( srf->fmt.MapRGBA( 0xFF, 0, 0xFF, 0xFF, color ) ) + srf->format->palette->colors[ color ].a = 0; -#if !defined(DARWIN) || !DARWIN - /* Windows icons are 32x32 and SDL can't resize them for us, which +#if !defined(DARWIN) + /* Windows icons are 32x32 and SDL can't resize them for us, which * causes mask corruption. (Actually, the above icon *is* 32x32; * this is here just in case it changes.) */ - ConvertSDLSurface(srf, srf->w, srf->h, + RageSurfaceUtils::ConvertSurface(srf, srf->w, srf->h, 32, 0xFF000000, 0x00FF0000, 0x0000FF00, 0x000000FF); zoomSurface(srf, 32, 32); - SDL_SetAlpha( srf, SDL_SRCALPHA, SDL_ALPHA_OPAQUE ); - SDL_WM_SetIcon(srf, NULL /* derive from alpha */); - SDL_FreeSurface(srf); + { + SDL_Surface *pSDLSurface = SDLSurfaceFromRageSurface( srf ); + + SDL_SetAlpha( pSDLSurface, SDL_SRCALPHA, SDL_ALPHA_OPAQUE ); + SDL_WM_SetIcon( pSDLSurface, NULL ); /* derive from alpha */ + SDL_FreeSurface( pSDLSurface ); + } + + delete srf; #endif /* Load the BMP - we need its dimensions */ - SDL_Surface *image = RageSurface_Load_XPM( loading, error ); - if( image == NULL ) - RageException::Throw("Couldn't load loading.bmp: %s",SDL_GetError()); + srf = RageSurface_Load_XPM( loading, error ); + if( srf == NULL ) // XXX SDL_GetError + RageException::Throw( "Couldn't load loading.bmp: %s",SDL_GetError() ); /* Initialize the window */ - loading_screen = SDL_SetVideoMode(image->w, image->h, 16, SDL_SWSURFACE|SDL_ANYFORMAT|SDL_NOFRAME); + loading_screen = SDL_SetVideoMode( srf->w, srf->h, 16, SDL_SWSURFACE|SDL_ANYFORMAT|SDL_NOFRAME ); if( loading_screen == NULL ) RageException::Throw( "Couldn't initialize loading window: %s", SDL_GetError() ); @@ -86,12 +94,15 @@ LoadingWindow_SDL::LoadingWindow_SDL() #endif - SDL_BlitSurface(image, NULL, loading_screen, NULL); + { + SDL_Surface *pSDLSurface = SDLSurfaceFromRageSurface( srf ); + SDL_BlitSurface( pSDLSurface, NULL, loading_screen, NULL ); + SDL_FreeSurface( pSDLSurface ); + } - SDL_FreeSurface(image); + delete srf; - SDL_UpdateRect(loading_screen, 0,0,0,0); - SDL_UpdateRect(loading_screen, 0,0,0,0); + SDL_UpdateRect( loading_screen, 0,0,0,0 ); } #ifdef _XBOX diff --git a/stepmania/src/arch/LoadingWindow/LoadingWindow_Win32.cpp b/stepmania/src/arch/LoadingWindow/LoadingWindow_Win32.cpp index 871db92b3f..461d18ada1 100644 --- a/stepmania/src/arch/LoadingWindow/LoadingWindow_Win32.cpp +++ b/stepmania/src/arch/LoadingWindow/LoadingWindow_Win32.cpp @@ -5,19 +5,20 @@ #include "RageFileManager.h" #include "archutils/win32/WindowsResources.h" #include -#include "SDL_utils.h" #include "RageSurface_Load.h" +#include "RageSurface.h" +#include "RageSurfaceUtils.h" static HBITMAP g_hBitmap = NULL; /* Load a file into a GDI surface. */ HBITMAP LoadWin32Surface( CString fn ) { - SDL_Surface *s = RageSurfaceUtils::LoadFile( fn ); + RageSurface *s = RageSurfaceUtils::LoadFile( fn ); if( s == NULL ) return NULL; - ConvertSDLSurface( s, s->w, s->h, 32, 0xFF000000, 0x00FF0000, 0x0000FF00, 0 ); + RageSurfaceUtils::ConvertSurface( s, s->w, s->h, 32, 0xFF000000, 0x00FF0000, 0x0000FF00, 0 ); HBITMAP bitmap = CreateCompatibleBitmap( GetDC(NULL), s->w, s->h ); ASSERT( bitmap ); @@ -40,7 +41,7 @@ HBITMAP LoadWin32Surface( CString fn ) SelectObject( BitmapDC, NULL ); DeleteObject( BitmapDC ); - SDL_FreeSurface( s ); + delete s; return bitmap; } diff --git a/stepmania/src/arch/MovieTexture/MovieTexture_DShow.cpp b/stepmania/src/arch/MovieTexture/MovieTexture_DShow.cpp index e795f84594..785d08c94f 100644 --- a/stepmania/src/arch/MovieTexture/MovieTexture_DShow.cpp +++ b/stepmania/src/arch/MovieTexture/MovieTexture_DShow.cpp @@ -18,6 +18,7 @@ #include "RageUtil.h" #include "RageLog.h" #include "RageException.h" +#include "RageSurface.h" #include "arch/Dialog/Dialog.h" #include "SDL_utils.h" @@ -212,14 +213,14 @@ void MovieTexture_DShow::CheckFrame() CreateTexture(); // DirectShow feeds us in BGR8 - SDL_Surface *fromDShow = SDL_CreateRGBSurfaceFrom( - (void*)buffer, m_iSourceWidth, m_iSourceHeight, + RageSurface *fromDShow = CreateSurfaceFrom( + m_iSourceWidth, m_iSourceHeight, 24, - m_iSourceWidth*3, 0xFF0000, 0x00FF00, 0x0000FF, - 0x000000 ); + 0x000000, + (uint8_t *) buffer, m_iSourceWidth*3 ); /* Optimization notes: * @@ -239,7 +240,7 @@ void MovieTexture_DShow::CheckFrame() m_iImageWidth, m_iImageHeight ); CHECKPOINT; - SDL_FreeSurface( fromDShow ); + delete fromDShow; buffer = NULL; @@ -464,12 +465,12 @@ void MovieTexture_DShow::CreateTexture() const RageDisplay::PixelFormatDesc *pfd = DISPLAY->GetPixelFormatDesc(pixfmt); - SDL_Surface *img = SDL_CreateRGBSurfaceSane(SDL_SWSURFACE, m_iTextureWidth, m_iTextureHeight, - pfd->bpp, pfd->masks[0], pfd->masks[1], pfd->masks[2], pfd->masks[3]); + RageSurface *img = CreateSurface( m_iTextureWidth, m_iTextureHeight, + pfd->bpp, pfd->masks[0], pfd->masks[1], pfd->masks[2], pfd->masks[3] ); m_uTexHandle = DISPLAY->CreateTexture( pixfmt, img, false ); - SDL_FreeSurface( img ); + delete img; } diff --git a/stepmania/src/arch/MovieTexture/MovieTexture_FFMpeg.cpp b/stepmania/src/arch/MovieTexture/MovieTexture_FFMpeg.cpp index 9aacc98d1a..5d87ca2990 100644 --- a/stepmania/src/arch/MovieTexture/MovieTexture_FFMpeg.cpp +++ b/stepmania/src/arch/MovieTexture/MovieTexture_FFMpeg.cpp @@ -6,6 +6,7 @@ #include "RageUtil.h" #include "RageTimer.h" #include "RageFile.h" +#include "RageSurface.h" #include "SDL_utils.h" #include "PrefsManager.h" @@ -629,7 +630,7 @@ void MovieTexture_FFMpeg::DestroyTexture() { if( m_img ) { - SDL_FreeSurface( m_img ); + delete m_img; m_img=NULL; } if(m_uTexHandle) @@ -712,8 +713,8 @@ void MovieTexture_FFMpeg::CreateTexture() LOG->Trace("format %i, %08x %08x %08x %08x", pfd->bpp, pfd->masks[0], pfd->masks[1], pfd->masks[2], pfd->masks[3]); - m_img = SDL_CreateRGBSurfaceSane(SDL_SWSURFACE, m_iTextureWidth, m_iTextureHeight, - pfd->bpp, pfd->masks[0], pfd->masks[1], pfd->masks[2], pfd->masks[3]); + m_img = CreateSurface( m_iTextureWidth, m_iTextureHeight, pfd->bpp, + pfd->masks[0], pfd->masks[1], pfd->masks[2], pfd->masks[3] ); } m_uTexHandle = DISPLAY->CreateTexture( pixfmt, m_img, false ); diff --git a/stepmania/src/arch/MovieTexture/MovieTexture_FFMpeg.h b/stepmania/src/arch/MovieTexture/MovieTexture_FFMpeg.h index a39d6be815..f0fa4c7398 100644 --- a/stepmania/src/arch/MovieTexture/MovieTexture_FFMpeg.h +++ b/stepmania/src/arch/MovieTexture/MovieTexture_FFMpeg.h @@ -65,7 +65,7 @@ private: unsigned m_uTexHandle; - SDL_Surface *m_img; + RageSurface *m_img; int m_AVTexfmt; /* AVPixelFormat_t of m_img */ SDL_sem *m_BufferFinished; diff --git a/stepmania/src/arch/MovieTexture/MovieTexture_Null.cpp b/stepmania/src/arch/MovieTexture/MovieTexture_Null.cpp index 50c94bde61..7bfe8a3ba6 100644 --- a/stepmania/src/arch/MovieTexture/MovieTexture_Null.cpp +++ b/stepmania/src/arch/MovieTexture/MovieTexture_Null.cpp @@ -6,6 +6,7 @@ #include "RageException.h" #include "MovieTexture_Null.h" #include "SDL_utils.h" +#include "RageSurface.h" MovieTexture_Null::MovieTexture_Null(RageTextureID ID) : RageMovieTexture(ID) { @@ -30,12 +31,12 @@ MovieTexture_Null::MovieTexture_Null(RageTextureID ID) : RageMovieTexture(ID) RageDisplay::PixelFormat pixfmt = RageDisplay::FMT_RGBA4; const RageDisplay::PixelFormatDesc *pfd = DISPLAY->GetPixelFormatDesc( pixfmt ); - SDL_Surface *img = SDL_CreateRGBSurfaceSane(SDL_SWSURFACE, size, size, pfd->bpp, pfd->masks[0], - pfd->masks[1], pfd->masks[2], pfd->masks[3]); + RageSurface *img = CreateSurface( size, size, pfd->bpp, + pfd->masks[0], pfd->masks[1], pfd->masks[2], pfd->masks[3] ); texHandle = DISPLAY->CreateTexture( pixfmt, img, false ); - SDL_FreeSurface(img); + delete img; } MovieTexture_Null::~MovieTexture_Null()