00001 
00002 
00003 
00004 
00005 
00006 
00007 
00008 
00009 
00010 
00011 
00012 
00013 
00014 
00015 
00016 
00017 
00018 
00019 
00020 
00021 
00022 
00023 
00024 
00025 
00026 
00027 #include "OSDLVideo.h"
00028 
00029 #include "OSDLImage.h"          
00030 #include "OSDLSurface.h"        
00031 #include "OSDLVideoRenderer.h"  
00032 #include "OSDLUtils.h"          
00033 #include "OSDLBasic.h"          
00034 
00035 
00036 #include <list>
00037 using std::list ;
00038 
00039 using std::string ;
00040 using std::pair ;
00041 
00042 
00043 
00044 
00045 
00046 #ifdef OSDL_USES_CONFIG_H
00047 #include <OSDLConfig.h>              
00048 #endif // OSDL_USES_CONFIG_H
00049 
00050 
00051 #if OSDL_ARCH_NINTENDO_DS
00052 #include "OSDLConfigForNintendoDS.h" 
00053 #endif // OSDL_ARCH_NINTENDO_DS
00054 
00055 
00056 
00057 #if OSDL_USES_AGAR
00058 
00059 #include <agar/config/have_opengl.h>
00060 
00061 #include <agar/core.h>
00062 #include <agar/gui.h>
00063 #include <agar/gui/opengl.h>
00064 
00065 #endif // OSDL_USES_AGAR
00066 
00067 
00068 using namespace Ceylan ;
00069 using namespace Ceylan::Log ;
00070 
00071 using namespace OSDL::Video ;
00072 using namespace OSDL::Rendering ;
00073 using namespace OSDL::Video::OpenGL ;
00074 
00075 
00076 
00077 
00078 
00079 #if OSDL_VERBOSE_VIDEO_MODULE
00080 
00081 #define LOG_DEBUG_VIDEO(message)   LogPlug::debug(message)
00082 #define LOG_TRACE_VIDEO(message)   LogPlug::trace(message)
00083 #define LOG_WARNING_VIDEO(message) LogPlug::warning(message)
00084 
00085 #else // OSDL_DEBUG_AUDIO_PLAYBACK
00086 
00087 #define LOG_DEBUG_VIDEO(message)
00088 #define LOG_TRACE_VIDEO(message)
00089 #define LOG_WARNING_VIDEO(message)
00090 
00091 #endif // OSDL_DEBUG_AUDIO_PLAYBACK
00092 
00093 
00094 
00095 
00096 
00097 
00098 
00099 
00100 
00101 
00102 
00103 
00104 
00105 
00106 
00107 
00108 
00109 
00110 
00111 
00112 
00113 
00114 
00115 
00116 
00117 
00118 
00119 
00120 
00121 
00122 
00123 
00124 
00125 
00126 
00127 
00128 
00129 
00130 
00131 
00132 
00133 
00134 
00135 
00136 
00137 #if OSDL_USES_SDL
00138 
00139 #include "SDL.h"
00140 
00141 
00142 const Ceylan::Flags VideoModule::SoftwareSurface  = SDL_SWSURFACE ;
00143 const Ceylan::Flags VideoModule::HardwareSurface  = SDL_HWSURFACE ;
00144 const Ceylan::Flags VideoModule::AsynchronousBlit = SDL_ASYNCBLIT ;
00145 const Ceylan::Flags VideoModule::AnyPixelFormat   = SDL_ANYFORMAT ;
00146 const Ceylan::Flags VideoModule::ExclusivePalette = SDL_HWPALETTE ;
00147 const Ceylan::Flags VideoModule::DoubleBuffered   = SDL_DOUBLEBUF ;
00148 const Ceylan::Flags VideoModule::FullScreen       = SDL_FULLSCREEN ;
00149 const Ceylan::Flags VideoModule::OpenGL           = SDL_OPENGL ;
00150 const Ceylan::Flags VideoModule::Resizable        = SDL_RESIZABLE ;
00151 const Ceylan::Flags VideoModule::NoFrame          = SDL_NOFRAME ;
00152 
00153 
00154 
00156 const std::string VideoModule::_SDLEnvironmentVariables[] =
00157 {
00158 
00159         "SDL_FBACCEL",
00160         "SDL_FBDEV",
00161         "SDL_FULLSCREEN_UPDATE",
00162         "SDL_VIDEODRIVER",
00163         "SDL_VIDEO_CENTERED",
00164         "SDL_VIDEO_GL_DRIVER",
00165         "SDL_VIDEO_X11_DGAMOUSE",
00166         "SDL_VIDEO_X11_MOUSEACCEL",
00167         "SDL_VIDEO_X11_NODIRECTCOLOR",
00168         "SDL_VIDEO_X11_VISUALID",
00169         "SDL_VIDEO_YUV_DIRECT",
00170         "SDL_VIDEO_YUV_HWACCEL",
00171         "SDL_WINDOWID"
00172 
00173 } ;
00174 
00175 
00176 
00177 #else // OSDL_USES_SDL
00178 
00179 
00180 
00181 
00182 const Ceylan::Flags VideoModule::SoftwareSurface  = 0x00000000 ;
00183 const Ceylan::Flags VideoModule::HardwareSurface  = 0x00000001 ;
00184 const Ceylan::Flags VideoModule::AsynchronousBlit = 0x00000004 ;
00185 const Ceylan::Flags VideoModule::AnyPixelFormat   = 0x10000000 ;
00186 const Ceylan::Flags VideoModule::ExclusivePalette = 0x20000000 ;
00187 const Ceylan::Flags VideoModule::DoubleBuffered   = 0x40000000 ;
00188 const Ceylan::Flags VideoModule::FullScreen       = 0x80000000 ;
00189 const Ceylan::Flags VideoModule::OpenGL           = 0x00000002 ;
00190 const Ceylan::Flags VideoModule::Resizable        = 0x00000010 ;
00191 const Ceylan::Flags VideoModule::NoFrame          = 0x00000020 ;
00192 
00194 const std::string VideoModule::_SDLEnvironmentVariables[] = {} ;
00195 
00196 #endif // OSDL_USES_SDL
00197 
00198 
00199 
00200 
00201 bool VideoModule::_IsUsingOpenGL = false ;
00202 bool VideoModule::_DrawEndPoint  = false ;
00203 bool VideoModule::_AntiAliasing  = true  ;
00204 
00205 
00206 const Ceylan::Uint16 VideoModule::DriverNameMaximumLength = 50 ;
00207 
00208 const BitsPerPixel VideoModule::UseCurrentColorDepth = 0 ;
00209 
00210 
00211 
00212 
00213 
00214 #include "OSDLIncludeCorrecter.h"
00215 
00216 
00217 
00218 VideoModule::VideoModule() :
00219     Ceylan::Module(
00220         "OSDL video module",
00221         "This is the root video module of OSDL",
00222         "http://osdl.sourceforge.net",
00223         "Olivier Boudeville",
00224         "olivier.boudeville@online.fr",
00225         OSDL::GetVersion(),
00226         "disjunctive LGPL/GPL" ),
00227     _screen( 0 ),
00228     _displayInitialized( false ),
00229     _isGuiEnabled( false ),
00230     _renderer( 0 ),
00231     _openGLcontext( 0 ),
00232     _drawEndPoint( false ),
00233     _antiAliasing( true ),
00234     _screenStartingSecond( 0 ),
00235     _screenStartingMicrosecond( 0 )
00236 {
00237 
00238 #if OSDL_ARCH_NINTENDO_DS
00239 
00240 #ifdef OSDL_RUNS_ON_ARM7
00241 
00242     throw OSDL::Exception( "VideoModule constructor failed: "
00243         "not supported on the ARM7." ) ;
00244 
00245 #elif defined(OSDL_RUNS_ON_ARM9)
00246 
00247     send( "Initializing video subsystem." ) ;
00248 
00249     send( "Video subsystem initialized." ) ;
00250 
00251     dropIdentifier() ;
00252 
00253 #endif // OSDL_RUNS_ON_ARM7
00254 
00255 #else // OSDL_ARCH_NINTENDO_DS
00256 
00257 #if OSDL_USES_SDL
00258 
00259     send( "Initializing video subsystem." ) ;
00260 
00261     if ( SDL_InitSubSystem( CommonModule::UseVideo )
00262             != CommonModule::BackendSuccess )
00263         throw VideoException( "VideoModule constructor: "
00264             "unable to initialize video subsystem: "
00265             + Utils::getBackendLastError() ) ;
00266 
00267     send( "Video subsystem initialized." ) ;
00268 
00269     dropIdentifier() ;
00270 
00271 #else // OSDL_USES_SDL
00272 
00273     throw VideoException( "VideoModule constructor failed: "
00274         "no SDL support available" ) ;
00275 
00276 #endif // OSDL_USES_SDL
00277 
00278 #endif // OSDL_ARCH_NINTENDO_DS
00279 
00280 }
00281 
00282 
00283 
00284 VideoModule::~VideoModule() throw()
00285 {
00286 
00287 #if OSDL_USES_SDL
00288 
00289     send( "Stopping video subsystem." ) ;
00290 
00291     if ( _openGLcontext != 0 )
00292         delete _openGLcontext ;
00293 
00294     if ( _renderer != 0 )
00295         delete _renderer ;
00296 
00297     
00298     if ( _screen != 0 )
00299     {
00300 
00301         send( "Average frame-rate has been "
00302             + Ceylan::toString( getAverageRefreshRate(),  2 )
00303             + " frames per second." ) ;
00304 
00305         delete _screen ;
00306 
00307     }
00308 
00309 
00310     SDL_QuitSubSystem( CommonModule::UseVideo ) ;
00311 
00312     send( "Video subsystem stopped." ) ;
00313 
00314 #endif // OSDL_USES_SDL
00315 
00316 }
00317 
00318 
00319 
00320 bool VideoModule::hasScreenSurface() const
00321 {
00322 
00323     return ( _screen != 0 ) ;
00324 
00325 }
00326 
00327 
00328 
00329 Surface & VideoModule::getScreenSurface() const
00330 {
00331 
00332     if ( _screen == 0 )
00333         throw VideoException( "VideoModule::getScreenSurface: "
00334             "no available screen surface." ) ;
00335 
00336     return * _screen ;
00337 
00338 }
00339 
00340 
00341 
00342 void VideoModule::setScreenSurface( Surface & newScreenSurface )
00343 {
00344 
00345     send( "Setting screen surface to " + newScreenSurface.toString(), 8 ) ;
00346 
00347     if ( _screen->getDisplayType() == Surface::BackBuffer )
00348         throw VideoException(
00349             "VideoModule::setScreenSurface: from its display type, "
00350             "specified surface is not a screen surface" ) ;
00351 
00352     _screen = & newScreenSurface ;
00353 
00354 }
00355 
00356 
00357 
00358 bool VideoModule::hasRenderer() const
00359 {
00360 
00361     return ( _renderer != 0 ) ;
00362 
00363 }
00364 
00365 
00366 
00367 OSDL::Rendering::VideoRenderer & VideoModule::getRenderer() const
00368 {
00369 
00370     if ( _renderer == 0 )
00371         throw VideoException(
00372             "VideoModule::getRenderer: no video renderer available." ) ;
00373 
00374     return * _renderer ;
00375 
00376 }
00377 
00378 
00379 
00380 void VideoModule::setRenderer( VideoRenderer & newRenderer )
00381 {
00382 
00383     if (  _renderer != 0 )
00384         delete _renderer ;
00385 
00386     _renderer = & newRenderer ;
00387 
00388 }
00389 
00390 
00391 
00392 bool VideoModule::hasOpenGLContext() const
00393 {
00394 
00395     return ( _openGLcontext != 0 ) ;
00396 
00397 }
00398 
00399 
00400 
00401 OpenGL::OpenGLContext & VideoModule::getOpenGLContext() const
00402 {
00403 
00404     if ( _openGLcontext == 0 )
00405         throw VideoException(
00406             "VideoModule::getOpenGLContext: no OpenGL context available." ) ;
00407 
00408     return * _openGLcontext ;
00409 
00410 }
00411 
00412 
00413 
00414 void VideoModule::setOpenGLContext( OpenGL::OpenGLContext & newOpenGLContext )
00415 {
00416 
00417     if ( _openGLcontext != 0 )
00418         delete _openGLcontext ;
00419 
00420     _openGLcontext = & newOpenGLContext ;
00421 
00422     _IsUsingOpenGL = true ;
00423 
00424 }
00425 
00426 
00427 
00428 
00429 BitsPerPixel VideoModule::getBestColorDepthForMode(
00430     Length width, Length height, BitsPerPixel askedBpp, Ceylan::Flags flags )
00431 {
00432 
00433 #if OSDL_USES_SDL
00434 
00435     return SDL_VideoModeOK( width, height, askedBpp, flags ) ;
00436 
00437 #else // OSDL_USES_SDL
00438 
00439     return 0 ;
00440 
00441 #endif // OSDL_USES_SDL
00442 
00443 }
00444 
00445 
00446 
00447 bool VideoModule::isDisplayInitialized() const
00448 {
00449 
00450     return _displayInitialized ;
00451 
00452 }
00453 
00454 
00455 bool VideoModule::isGUIEnabled() const
00456 {
00457 
00458     return _isGuiEnabled ;
00459 
00460 }
00461 
00462 
00463 
00464 void VideoModule::setGUIEnableStatus( bool newStatus )
00465 {
00466 
00467     
00468 
00469     _isGuiEnabled = newStatus ;
00470 
00471 }
00472 
00473 
00474 
00475 Ceylan::Flags VideoModule::setMode( Length width, Length height,
00476     BitsPerPixel askedBpp, Ceylan::Flags flags, OpenGL::Flavour flavour )
00477 {
00478 
00479 #if OSDL_USES_SDL
00480 
00481     _displayInitialized = false ;
00482 
00483     _screenStartingSecond = 0 ;
00484     _screenStartingMicrosecond = 0 ;
00485 
00486     Ceylan::Flags userFlags = flags ;
00487 
00488     send( "Trying to set "
00489         + Ceylan::toString( width )    + 'x'
00490         + Ceylan::toString( height )   + " video mode, with "
00491         + ( ( askedBpp == 0 ) ?
00492             string( "current screen color depth" ):
00493             Ceylan::toString( static_cast<Ceylan::Uint16>( askedBpp ) )
00494             + " bits per pixel)" )
00495         + ", with user-defined flags. " + InterpretFlags( flags )
00496         + "The " + OpenGLContext::ToString( flavour )
00497         + " flavour is selected" ) ;
00498 
00499     if ( ( ( flags & OpenGL ) == 0 ) && ( flavour != OpenGL::None ) )
00500     {
00501 
00502         LOG_WARNING_VIDEO( "VideoModule::setMode: OpenGL flavour selected ("
00503             + OpenGLContext::ToString( flavour )
00504             + ") whereas OpenGL flag not set, adding it." ) ;
00505 
00506         flags |= OpenGL ;
00507 
00508     }
00509 
00510     bool useOpenGLRequested = ( ( flags & OpenGL ) != 0 ) ;
00511 
00512     if ( useOpenGLRequested && ( flags & DoubleBuffered ) )
00513     {
00514 
00515         
00516 
00517 
00518 
00519 
00520 
00521 
00522         flags &= ~ DoubleBuffered ;
00523 
00524     }
00525 
00526     if ( useOpenGLRequested )
00527     {
00528 
00529         
00530         OpenGLContext::SetUpForFlavour( flavour,  false ) ;
00531 
00532         if ( askedBpp != 0 )
00533              OpenGLContext::SetColorDepth( askedBpp ) ;
00534 
00535     }
00536 
00537 
00538     if ( userFlags != flags )
00539         send( "Initializing the display with following modified flags: "
00540             + InterpretFlags( flags ) ) ;
00541     else
00542         send( "Initializing the display with unchanged user flags") ;
00543 
00544     SDL_Surface * screen = SDL_SetVideoMode( width, height, askedBpp, flags ) ;
00545 
00546     if ( screen == 0 )
00547     {
00548 
00549         if ( useOpenGLRequested )
00550         {
00551 
00552             LogPlug::warning( "VideoModule::setMode: "
00553                 "failed to initialize OpenGL video mode (\""
00554                 + Utils::getBackendLastError()
00555                 + "\"), using safer settings as a fall-back." ) ;
00556 
00557             
00558 
00559 
00560 
00561 
00562 
00563             OpenGLContext::SetUpForFlavour( flavour,  true ) ;
00564 
00565             screen = SDL_SetVideoMode( width, height, askedBpp, flags ) ;
00566 
00567         }
00568 
00569         
00570 
00571 
00572 
00573 
00574 
00575     }
00576 
00577 
00578     if ( screen == 0 )
00579         throw VideoException( "Could not set "
00580             + Ceylan::toString( width )    + 'x'
00581             + Ceylan::toString( height )   + 'x'
00582             + Ceylan::toNumericalString( askedBpp )
00583             + " with flags " + Ceylan::toString( flags,  true )
00584             + " video mode: " + Utils::getBackendLastError() ) ;
00585 
00586 
00587     if ( useOpenGLRequested )
00588     {
00589 
00590         _screen = new Video::Surface( * screen,
00591              Surface::OpenGLScreenSurface ) ;
00592 
00593         send( OpenGLContext::InterpretFeatureAvailability() ) ;
00594 
00595     }
00596     else
00597     {
00598 
00599         _screen = new Video::Surface( * screen,
00600              Surface::ClassicalScreenSurface ) ;
00601 
00602     }
00603 
00604 
00605     int bpp = _screen->getBitsPerPixel() ;
00606 
00607     send( "Actual color depth is " + Ceylan::toString( bpp )
00608         + " bits per pixel." ) ;
00609 
00610     
00611     if ( ( askedBpp != bpp ) && ( askedBpp != 0 ) )
00612         LOG_WARNING_VIDEO( "Color depth is " + Ceylan::toString( bpp )
00613             + " bits per pixel (instead of the asked "
00614             + Ceylan::toString( static_cast<Ceylan::Uint16>( askedBpp ) )
00615             + " bits per pixel)." ) ;
00616 
00617 
00618     if ( useOpenGLRequested )
00619     {
00620 
00621         
00622 
00623 
00624 
00625 
00626         switch ( flavour )
00627         {
00628 
00629             case OpenGL::None:
00630                 if ( useOpenGLRequested )
00631                 {
00632                     if ( ! hasOpenGLContext() )
00633                         setOpenGLContext( * new OpenGLContext( flavour, bpp,
00634                             _screen->getWidth(), _screen->getHeight() ) ) ;
00635                     else
00636                         _openGLcontext->selectFlavour( flavour ) ;
00637                 }
00638                 break ;
00639 
00640             case OpenGL::OpenGLFor2D:
00641                 if ( ! hasOpenGLContext() )
00642                     setOpenGLContext( * new OpenGLContext( flavour, bpp,
00643                         _screen->getWidth(), _screen->getHeight() ) ) ;
00644                 else
00645                     _openGLcontext->selectFlavour( flavour ) ;
00646                 break ;
00647 
00648             case OpenGL::OpenGLFor3D:
00649                 if ( ! hasOpenGLContext() )
00650                     setOpenGLContext( * new OpenGLContext( flavour, bpp,
00651                         _screen->getWidth(), _screen->getHeight() ) ) ;
00652                 else
00653                     _openGLcontext->selectFlavour( flavour ) ;
00654                 break ;
00655 
00656             case OpenGL::Reload:
00657                 if ( hasOpenGLContext() )
00658                     _openGLcontext->reload() ;
00659                 else
00660                     throw VideoException( "VideoModule::setMode: "
00661                         "reload flavour selected whereas "
00662                         "no OpenGL context was available, nothing done." ) ;
00663                 break ;
00664 
00665             default:
00666                 throw VideoException( "VideoModule::setMode: unknown "
00667                     + OpenGLContext::ToString( flavour )
00668                     + " flavour selected." ) ;
00669                 break ;
00670 
00671         }
00672 
00673     }
00674 
00675     
00676 
00677 
00678 
00679 
00680 
00681     
00682 
00683 
00684 
00685 
00686 
00687 
00688 
00689 
00690     if ( useOpenGLRequested )
00691         _openGLcontext->setViewPort( _screen->getWidth(),
00692             _screen->getHeight() ) ;
00693 
00694 
00695     send( "After display creation, interpreting actually obtained surface: "
00696         + _screen->toString()
00697         + "The corresponding pixel format for this screen surface is: "
00698         + Pixels::toString( _screen->getPixelFormat() ) ) ;
00699 
00700     if ( _openGLcontext != 0 )
00701         send( "Current OpenGL context: " + _openGLcontext->toString() ) ;
00702 
00703 
00704     
00705     if ( _isGuiEnabled )
00706     {
00707 
00708 #if OSDL_USES_AGAR
00709 
00710       
00711 
00712 
00713 
00714       AG_InitVideoSDL( screen, AG_VIDEO_OVERLAY ) ;
00715 
00716       std::string usingGL  =
00717         ( AG_UsingGL(  0 )  ? "with" : "without" ) ;
00718 
00719       std::string usingSDL =
00720         ( AG_UsingGL(  0 )  ? "with" : "without" ) ;
00721 
00722       send( "The libagar GUI rendering will be done using a backend "
00723         + usingGL  + " OpenGL, and " + usingSDL + " SDL." ) ;
00724 
00725 #endif // OSDL_USES_AGAR
00726 
00727     }
00728 
00729 
00730     
00731     Ceylan::System::getPreciseTime( _screenStartingSecond,
00732         _screenStartingMicrosecond ) ;
00733 
00734     _displayInitialized = true ;
00735 
00736     return _screen->getFlags() ;
00737 
00738 #else // OSDL_USES_SDL
00739 
00740     throw VideoException( "VideoModule::setMode failed: "
00741         "no SDL support available" ) ;
00742 
00743 #endif // OSDL_USES_SDL
00744 
00745 }
00746 
00747 
00748 
00749 void VideoModule::resize( Length newWidth, Length newHeight )
00750 {
00751 
00752     send( "Resizing window to (" + Ceylan::toString( newWidth ) + ", "
00753         + Ceylan::toString( newHeight ) + ")." ) ;
00754 
00755 
00756     
00757 
00758 
00759 
00760 
00761 
00762 
00763     if ( _screen == 0 )
00764         throw VideoException(
00765             "VideoModule::resize: video mode was not set." ) ;
00766 
00767     if ( ( _openGLcontext != 0 ) && OpenGLContext::ContextIsLostOnResize )
00768         setMode( newWidth, newHeight, _screen->getBitsPerPixel(),
00769             _screen->getFlags(), OpenGL::Reload ) ;
00770     else
00771         setMode( newWidth, newHeight, _screen->getBitsPerPixel(),
00772             _screen->getFlags(), OpenGL::None ) ;
00773 
00774 
00775     
00776 
00777 
00778 
00779 
00780 
00781 
00782 }
00783 
00784 
00785 
00786 void VideoModule::redraw()
00787 {
00788 
00789     if ( _screen == 0 )
00790         throw VideoException(
00791             "VideoModule::redraw: video mode was not set." ) ;
00792 
00793     
00794 
00795 
00796 
00797 
00798 
00799 
00800     _screen->redraw() ;
00801 
00802 }
00803 
00804 
00805 
00806 void VideoModule::toggleFullscreen()
00807 {
00808 
00809 #if OSDL_USES_SDL
00810 
00811     if ( _screen == 0 )
00812         throw VideoException(
00813             "VideoModule::toggleFullscreen: video mode was not set." ) ;
00814 
00815     if ( SDL_WM_ToggleFullScreen( & _screen->getSDLSurface() ) == 0 )
00816         throw VideoException( "VideoModule::toggleFullscreen failed: "
00817             + Utils::getBackendLastError() ) ;
00818 
00819 #endif // OSDL_USES_SDL
00820 
00821 }
00822 
00823 
00824 
00825 
00826 #if OSDL_ARCH_NINTENDO_DS
00827 
00828 #if defined(OSDL_RUNS_ON_ARM9)
00829 
00830 
00835 void write16( Ceylan::Uint16* address, Ceylan::Uint16 value)
00836 {
00837 
00838     Ceylan::Uint8* first  = reinterpret_cast<Ceylan::Uint8*>( address ) ;
00839     Ceylan::Uint8* second = first + 1 ;
00840 
00841     *first  = value & 0xff ;
00842     *second = value >>8 ;
00843 
00844 }
00845 
00846 
00847 
00853 void write32( Ceylan::Uint32* address, Ceylan::Uint32 value)
00854 {
00855 
00856     Ceylan::Uint8* first  = reinterpret_cast<Ceylan::Uint8*>( address ) ;
00857     Ceylan::Uint8* second = first + 1 ;
00858     Ceylan::Uint8* third  = first + 2 ;
00859     Ceylan::Uint8* fourth = first + 3 ;
00860 
00861     *first  =  value      & 0xff ;
00862     *second = (value>>8)  & 0xff ;
00863     *third  = (value>>16) & 0xff ;
00864     *fourth = (value>>24) & 0xff ;
00865 
00866 }
00867 
00868 
00869 #endif //  defined(OSDL_RUNS_ON_ARM9)
00870 
00871 #endif // OSDL_ARCH_NINTENDO_DS
00872 
00873 
00874 
00875 void VideoModule::makeBMPScreenshot( const string & screenshotFilename )
00876 {
00877 
00878 #if OSDL_ARCH_NINTENDO_DS
00879 
00880 #ifdef OSDL_RUNS_ON_ARM7
00881 
00882     throw OSDL::Exception( "VideoModule::makeBMPScreenshot failed: "
00883         "not supported on the ARM7." ) ;
00884 
00885 #elif defined(OSDL_RUNS_ON_ARM9)
00886 
00887     
00888 
00889 
00890 
00891 
00892 
00893 
00894 
00895 
00896 
00897     
00898 
00899 
00900 
00901 
00902 
00903     try
00904     {
00905 
00906         vramSetBankD( VRAM_D_LCD ) ;
00907 
00908         
00909 
00910 
00911 
00912 
00913 
00914 
00915 
00916 
00917 
00918         REG_DISPCAPCNT = (unsigned int)
00919             ( DCAP_ENABLE | DCAP_BANK(3) | DCAP_SIZE(3) ) ;
00920 
00921 
00922         const System::Size sizeOfHeaders = sizeof(TwoDimensional::BMPInfoHeader)
00923             + sizeof(TwoDimensional::BMPHeader) ;
00924 
00925         
00926         const System::Size fileSize =
00927             SCREEN_WIDTH * SCREEN_HEIGHT * 3 + sizeOfHeaders ;
00928 
00929         
00930         Ceylan::Byte * temp = new Ceylan::Byte[ fileSize ] ;
00931 
00932         TwoDimensional::BMPHeader* header =
00933             reinterpret_cast<TwoDimensional::BMPHeader*>( temp ) ;
00934 
00935         TwoDimensional::BMPInfoHeader* infoHeader =
00936             reinterpret_cast<TwoDimensional::BMPInfoHeader*>(
00937                 temp + sizeof(TwoDimensional::BMPHeader) ) ;
00938 
00939         
00940         write16( &header->type,  0x4D42 ) ;
00941         write32( &header->size, fileSize ) ;
00942 
00943         write32( &header->offset, sizeOfHeaders ) ;
00944 
00945         write16( &header->firstReserved, 0 ) ;
00946         write16( &header->secondReserved, 0 ) ;
00947 
00948         write16( &infoHeader->bits, 24 ) ;
00949         write32( &infoHeader->size, sizeof(TwoDimensional::BMPInfoHeader) ) ;
00950         write32( &infoHeader->compression, 0 ) ;
00951         write32( &infoHeader->width, SCREEN_WIDTH ) ;
00952         write32( &infoHeader->height, SCREEN_HEIGHT ) ;
00953         write16( &infoHeader->planes, 1);
00954         write32( &infoHeader->imagesize, SCREEN_WIDTH*SCREEN_HEIGHT*3 ) ;
00955         write32( &infoHeader->xresolution, 0 ) ;
00956         write32( &infoHeader->yresolution, 0 ) ;
00957         write32( &infoHeader->importantcolours, 0 ) ;
00958         write32( &infoHeader->ncolours, 0 ) ;
00959 
00960         
00961         while( REG_DISPCAPCNT & DCAP_ENABLE )
00962             ;
00963 
00964         
00965 
00966 
00967 
00968 
00969         
00970         for( int y=0; y<SCREEN_HEIGHT; y++ )
00971             for( int x=0; x<SCREEN_WIDTH; x++ )
00972             {
00973 
00974                 
00975                 Ceylan::Uint16 color = VRAM_D[
00976                     SCREEN_WIDTH*SCREEN_HEIGHT - (y+1)*SCREEN_WIDTH + x ] ;
00977 
00978                 Ceylan::Uint8 b = (color      &31) << 3 ;
00979                 Ceylan::Uint8 g = ((color>>5) &31) << 3 ;
00980                 Ceylan::Uint8 r = ((color>>10)&31) << 3 ;
00981 
00982                 temp[ ( (y*SCREEN_WIDTH)+x)*3 + sizeOfHeaders + 0 ] = r ;
00983                 temp[ ( (y*SCREEN_WIDTH)+x)*3 + sizeOfHeaders + 1 ] = g ;
00984                 temp[ ( (y*SCREEN_WIDTH)+x)*3 + sizeOfHeaders + 2 ] = b ;
00985             }
00986 
00987         
00988         DC_FlushAll() ;
00989 
00990         Ceylan::System::File & outputFile =
00991             Ceylan::System::File::Create( screenshotFilename ) ;
00992 
00993         outputFile.write( temp, fileSize ) ;
00994 
00995         delete [] temp ;
00996 
00997         delete & outputFile ;
00998 
00999     }
01000     catch( Ceylan::Exception & e )
01001     {
01002 
01003         throw VideoException( "VideoModule::makeBMPScreenshot failed: "
01004             + e.toString() ) ;
01005     }
01006 
01007 
01008 #endif // OSDL_RUNS_ON_ARM7
01009 
01010 #else // OSDL_ARCH_NINTENDO_DS
01011 
01012     getScreenSurface().saveBMP( screenshotFilename ) ;
01013 
01014 #endif // OSDL_ARCH_NINTENDO_DS
01015 
01016 }
01017 
01018 
01019 
01020 bool VideoModule::getEndPointDrawState() const
01021 {
01022 
01023     return _drawEndPoint ;
01024 
01025 }
01026 
01027 
01028 
01029 void VideoModule::setEndPointDrawState( bool newState )
01030 {
01031 
01032     _drawEndPoint = newState ;
01033 
01034     
01035     _DrawEndPoint = newState ;
01036 
01037 }
01038 
01039 
01040 
01041 bool VideoModule::getAntiAliasingState() const
01042 {
01043 
01044     return _antiAliasing ;
01045 
01046 }
01047 
01048 
01049 
01050 void VideoModule::setAntiAliasingState( bool newState )
01051 {
01052 
01053     _antiAliasing = newState ;
01054 
01055     
01056     _AntiAliasing = newState ;
01057 
01058 }
01059 
01060 
01061 
01062 std::string VideoModule::getDriverName() const
01063 {
01064 
01065     return VideoModule::GetDriverName() ;
01066 
01067 }
01068 
01069 
01070 
01071 void VideoModule::setWindowCaption( const string & newTitle,
01072      const string & newIconName )
01073 {
01074 
01075 #if OSDL_USES_SDL
01076 
01077     SDL_WM_SetCaption( newTitle.c_str(), newIconName.c_str() ) ;
01078 
01079 #endif // OSDL_USES_SDL
01080 
01081 }
01082 
01083 
01084 
01085 void VideoModule::getWindowCaption( string & title, string & iconName )
01086 {
01087 
01088 #if OSDL_USES_SDL
01089 
01090     char newTitle[ 50 ] ;
01091     char newIconName[ 50 ] ;
01092 
01093     SDL_WM_GetCaption(
01094         reinterpret_cast<char **>( & newTitle ),
01095         reinterpret_cast<char **>( & newIconName ) ) ;
01096 
01097     title = newTitle  ;
01098     iconName = newIconName ;
01099 
01100 #endif // OSDL_USES_SDL
01101 
01102 }
01103 
01104 
01105 
01106 void VideoModule::setWindowIcon( const std::string & filename )
01107 {
01108 
01109 #if OSDL_USES_SDL
01110 
01111 
01112     if ( isDisplayInitialized() )
01113         throw VideoException( "VideoModule::setWindowIcon called whereas "
01114             "display was already initialized "
01115             "(VideoModule::setMode was already called)." ) ;
01116 
01117     
01118 
01119 
01120 
01121 
01122 
01123 
01124 
01125 
01126 
01127 
01128 
01129 
01130 
01131 
01132 
01133     Pixels::ColorElement * mask ;
01134 
01135     Surface * iconSurface ;
01136 
01137     try
01138     {
01139         iconSurface = & TwoDimensional::Image::LoadIcon( filename, & mask ) ;
01140     }
01141     catch( const TwoDimensional::ImageException & e )
01142     {
01143         throw VideoException( "VideoModule::setWindowIcon: "
01144             + e.toString() ) ;
01145     }
01146 
01147     LOG_DEBUG_VIDEO( "Setting icon now" ) ;
01148 
01149     SDL_WM_SetIcon( & iconSurface->getSDLSurface(), mask ) ;
01150     
01151 
01152     
01153 
01154 
01155 
01156 
01157 
01158 
01159 
01160 #endif // OSDL_USES_SDL
01161 
01162 }
01163 
01164 
01165 
01166 bool VideoModule::iconifyWindow()
01167 {
01168 
01169 #if OSDL_USES_SDL
01170 
01171     return ( SDL_WM_IconifyWindow() != 0 ) ;
01172 
01173 #else // OSDL_USES_SDL
01174 
01175     return false ;
01176 
01177 #endif // OSDL_USES_SDL
01178 
01179 
01180 }
01181 
01182 
01183 
01184 Ceylan::Float32 VideoModule::getAverageRefreshRate()
01185 {
01186 
01187     if ( _screen == 0 )
01188         throw VideoException( "VideoModule::getAverageRefreshRate failed: "
01189             "display is not initialized." ) ;
01190 
01191     System::Second currentSecond ;
01192     System::Microsecond currentMicrosecond ;
01193 
01194     System::getPreciseTime( currentSecond, currentMicrosecond ) ;
01195 
01196     System::Microsecond duration = System::getDurationBetween(
01197         _screenStartingSecond, _screenStartingMicrosecond,
01198         currentSecond, currentMicrosecond ) ;
01199 
01200     return static_cast<Ceylan::Float32>(
01201         ( 1000000.0f / duration ) * _screen->getUpdateCount() ) ;
01202 
01203 }
01204 
01205 
01206 
01207 bool VideoModule::isUsingOpenGL() const
01208 {
01209 
01210     return hasOpenGLContext() ;
01211 
01212 }
01213 
01214 
01215 const string VideoModule::toString( Ceylan::VerbosityLevels level ) const
01216 {
01217 
01218     string res = "Video module, " ;
01219 
01220     if ( _screen == 0 )
01221         res += "no video mode set, " ;
01222     else
01223         res += "video mode set, " ;
01224 
01225     if ( _renderer == 0 )
01226         res += "no video renderer set, " ;
01227     else
01228         res += "a video renderer is set, " ;
01229 
01230     if ( _openGLcontext == 0 )
01231         res += "no available OpenGL context, " ;
01232     else
01233         res += "an OpenGL context is available, " ;
01234 
01235     if ( _isGuiEnabled )
01236         res += "with GUI support enabled" ;
01237     else
01238         res += "with no GUI support enabled" ;
01239 
01240     if ( level == Ceylan::low )
01241         return res ;
01242 
01243     res += ". " + Ceylan::Module::toString() ;
01244 
01245     if ( _screen != 0 )
01246         res += " Screen surface information: "
01247             + _screen->toString( level ) ;
01248 
01249     if ( _renderer != 0 )
01250         res += ". Internal renderer: "
01251             + _renderer->toString( level ) ;
01252 
01253     if ( _openGLcontext != 0 )
01254         res += ". Current OpenGL context: "
01255             + _openGLcontext->toString( level ) ;
01256 
01257     return res ;
01258 
01259 }
01260 
01261 
01262 
01263 
01264 
01265 
01266 
01267 
01268 
01269 bool VideoModule::IsDisplayInitialized()
01270 {
01271 
01272     
01273 
01274 
01275 
01276 
01277 
01278     if ( ! OSDL::hasExistingCommonModule() )
01279         return false ;
01280 
01281     
01282     CommonModule & common = OSDL::getExistingCommonModule() ;
01283 
01284     if ( ! common.hasVideoModule() )
01285         return false ;
01286 
01287     VideoModule & video = common.getVideoModule() ;
01288 
01289     return video.isDisplayInitialized() ;
01290 
01291 }
01292 
01293 
01294 
01295 bool VideoModule::GetEndPointDrawState()
01296 {
01297 
01298 #if OSDL_CACHE_OVERALL_SETTINGS
01299 
01300     return _DrawEndPoint ;
01301 
01302 #else // OSDL_CACHE_OVERALL_SETTINGS
01303 
01304     
01305 
01306     if ( ! OSDL::hasExistingCommonModule() )
01307         Ceylan::emergencyShutdown(
01308             "VideoModule::GetEndPointDrawState() called "
01309             "whereas no common module available." ) ;
01310 
01311     
01312     CommonModule & common = OSDL::getExistingCommonModule() ;
01313 
01314     if ( ! common.hasVideoModule() )
01315         Ceylan::emergencyShutdown(
01316             "VideoModule::GetEndPointDrawState() called "
01317             "whereas no video module available." ) ;
01318 
01319     VideoModule & video = common.getVideoModule() ;
01320 
01321 #if OSDL_DEBUG_CACHED_STATES
01322 
01323     bool realState = video.getEndPointDrawState() ;
01324 
01325     if ( realState != _DrawEndPoint )
01326         Ceylan::emergencyShutdown(
01327             "VideoModule::GetEndPointDrawState() inconsistency detected: "
01328             "cached value should have been "
01329             + Ceylan::toString( realState ) + "." ) ;
01330 
01331     return realState ;
01332 
01333 #else // OSDL_DEBUG_CACHED_STATES
01334 
01335     return video.getEndPointDrawState() ;
01336 
01337 #endif // OSDL_DEBUG_CACHED_STATES
01338 
01339 #endif // OSDL_CACHE_OVERALL_SETTINGS
01340 
01341 }
01342 
01343 
01344 
01345 bool VideoModule::GetAntiAliasingState()
01346 {
01347 
01348 #if OSDL_CACHE_OVERALL_SETTINGS
01349 
01350     return _AntiAliasing ;
01351 
01352 #else // OSDL_CACHE_OVERALL_SETTINGS
01353 
01354     if ( ! OSDL::hasExistingCommonModule() )
01355         Ceylan::emergencyShutdown(
01356             "VideoModule::GetAntiAliasingState() called "
01357             "whereas no common module available." ) ;
01358 
01359     
01360     CommonModule & common = OSDL::getExistingCommonModule() ;
01361 
01362     if ( ! common.hasVideoModule() )
01363         Ceylan::emergencyShutdown(
01364             "VideoModule::GetAntiAliasingState() called "
01365             "whereas no video module available." ) ;
01366 
01367     VideoModule & video = common.getVideoModule() ;
01368 
01369 #if OSDL_DEBUG_CACHED_STATES
01370 
01371     bool realState = video.getAntiAliasingState() ;
01372 
01373     if ( realState != _AntiAliasing )
01374         Ceylan::emergencyShutdown(
01375             "VideoModule::GetAntiAliasingState() inconsistency detected: "
01376             "cached value should have been "
01377             + Ceylan::toString( realState ) + "." ) ;
01378 
01379     return realState ;
01380 
01381 #else // OSDL_DEBUG_CACHED_STATES
01382 
01383     return video.getAntiAliasingState() ;
01384 
01385 #endif // OSDL_DEBUG_CACHED_STATES
01386 
01387 #endif // OSDL_CACHE_OVERALL_SETTINGS
01388 
01389 }
01390 
01391 
01392 
01393 string VideoModule::GetDriverName()
01394 {
01395 
01396 #if OSDL_USES_SDL
01397 
01398     char driverName[ VideoModule::DriverNameMaximumLength + 1 ]  ;
01399 
01400     if ( SDL_VideoDriverName( driverName, DriverNameMaximumLength ) == 0 )
01401         throw VideoException( "VideoModule::GetDriverName failed: "
01402             "the video driver is probably not initialized." ) ;
01403 
01404     return std::string( driverName ) ;
01405 
01406 #else // OSDL_USES_SDL
01407 
01408     return "unknown (not using SDL)" ;
01409 
01410 #endif // OSDL_USES_SDL
01411 
01412 }
01413 
01414 
01415 
01416 string VideoModule::InterpretFlags( Ceylan::Flags flags )
01417 {
01418 
01419     std::list<string> res ;
01420 
01421     
01422 
01423 
01424 
01425 
01426 
01427     
01428 
01429 
01430 
01431 
01432 
01433 
01434 
01435 
01436 
01437 
01438     if ( flags & HardwareSurface )
01439         res.push_back(
01440             "Display surface requested to be created in video memory "
01441             "(HardwareSurface is set)." ) ;
01442     else
01443         res.push_back(
01444             "Display surface not requested to be created in video memory "
01445             "(HardwareSurface not set)." ) ;
01446 
01447     if ( flags & AsynchronousBlit )
01448         res.push_back(
01449             "Use, if possible, asynchronous updates of the display surface "
01450             "(AsynchronousBlit is set)." ) ;
01451     else
01452         res.push_back(
01453             "Do not use asynchronous blits (AsynchronousBlit not set)." ) ;
01454 
01455     if ( flags & AnyPixelFormat )
01456         res.push_back(
01457             "Display surface should use the available video surface, "
01458             "regardless of its pixel depth (AnyPixelFormat is set)." ) ;
01459     else
01460         res.push_back(
01461             "Display surface will emulate, thanks to a shadow surface, "
01462             "the specified bit-per-pixel mode if not available "
01463             "(AnyPixelFormat not set)." ) ;
01464 
01465     if ( flags & ExclusivePalette )
01466         res.push_back(
01467             "Display surface is given exclusive palette access, "
01468             "in order to always have the requested colors "
01469             "(ExclusivePalette is set)." ) ;
01470     else
01471         res.push_back(
01472             "Display surface is not required to have exclusive palette access, "
01473             "some colors might be different from the requested ones "
01474             "(ExclusivePalette not set)." ) ;
01475 
01476     if ( flags & DoubleBuffered )
01477         res.push_back(
01478             "Enable hardware double buffering, "
01479             "only valid with display surface in video memory "
01480             "and without OpenGL (DoubleBuffered is set)." ) ;
01481     else
01482         res.push_back( "No hardware double buffering requested, or OpenGL used "
01483             "(DoubleBuffered not set)." ) ;
01484 
01485     if ( flags & FullScreen )
01486         res.push_back(
01487             "Display surface should attempt to use full screen mode. "
01488             "If a hardware resolution change is not possible "
01489             "(for whatever reason), the next higher resolution "
01490             "will be used and the display window centered "
01491             "on a black background (FullScreen is set)." ) ;
01492     else
01493         res.push_back(
01494             "No full screen mode requested (FullScreen not set)." ) ;
01495 
01496     if ( flags & OpenGL )
01497         res.push_back(
01498             "Display surface should have an OpenGL rendering context, "
01499             "whose video attributes should already have been set "
01500             "(OpenGL is set)." ) ;
01501     else
01502         res.push_back(
01503             "Display surface is not requested to have an OpenGL context "
01504             "(OpenGL not set)." ) ;
01505 
01506     
01507 
01508     if ( flags & 0x0000000A  )
01509             res.push_back(
01510                 "Display surface should have an OpenGL rendering context, "
01511                 "and will allow normal blitting operations. "
01512                 "This SDL_OPENGLBLIT flag is deprecated and "
01513                 "should not be used for new applications." ) ;
01514 
01515     
01516 
01517 
01518 
01519 
01520 
01521 
01522 
01523     if ( flags & Resizable )
01524         res.push_back( "Requests a resizable window (Resizable is set)." ) ;
01525     else
01526         res.push_back( "No resizable window requested (Resizable not set)." ) ;
01527 
01528 
01529     if ( flags & NoFrame )
01530         res.push_back(
01531             "Requests creation of a window with no title bar or "
01532             "frame decoration (NoFrame is set)" ) ;
01533     else
01534         res.push_back(
01535             "Title bar and frame decoration allowed for display window "
01536             "(NoFrame not set)." ) ;
01537 
01538     return "The specified display surface mode flags, whose value is "
01539         + Ceylan::toString( flags,  true )
01540         + ", mean: " + Ceylan::formatStringList( res ) ;
01541 
01542 }
01543 
01544 
01545 
01546 bool VideoModule::HardwareSurfacesCanBeCreated()
01547 {
01548 
01549 #if OSDL_USES_SDL
01550 
01551     const SDL_VideoInfo * videoInfo = SDL_GetVideoInfo() ;
01552 
01553     if ( videoInfo == 0 )
01554         throw( "VideoModule::HardwareSurfacesCanBeCreated: "
01555             "unable to retrieve video informations." ) ;
01556 
01557     return static_cast<bool>( videoInfo->hw_available ) ;
01558 
01559 #else // OSDL_USES_SDL
01560 
01561     throw VideoException( "VideoModule::HardwareSurfacesCanBeCreated failed: "
01562         "no SDL support available" ) ;
01563 
01564 #endif // OSDL_USES_SDL
01565 
01566 }
01567 
01568 
01569 
01570 bool VideoModule::WindowManagerAvailable()
01571 {
01572 
01573 #if OSDL_USES_SDL
01574 
01575     const SDL_VideoInfo * videoInfo = SDL_GetVideoInfo() ;
01576 
01577     if ( videoInfo == 0 )
01578         throw( "VideoModule::WindowManagerAvailable: "
01579             "unable to retrieve video informations." ) ;
01580 
01581     return static_cast<bool>( videoInfo->wm_available ) ;
01582 
01583 #else // OSDL_USES_SDL
01584 
01585     throw VideoException( "VideoModule::WindowManagerAvailable failed: "
01586         "no SDL support available" ) ;
01587 
01588 #endif // OSDL_USES_SDL
01589 
01590 }
01591 
01592 
01593 
01594 bool VideoModule::HardwareToHardwareBlitsAccelerated()
01595 {
01596 
01597 #if OSDL_USES_SDL
01598 
01599 
01600     const SDL_VideoInfo * videoInfo = SDL_GetVideoInfo() ;
01601 
01602     if ( videoInfo == 0 )
01603         throw( "VideoModule::HardwareToHardwareBlitsAccelerated: "
01604             "unable to retrieve video informations." ) ;
01605 
01606     return static_cast<bool>( videoInfo->blit_hw ) ;
01607 
01608 #else // OSDL_USES_SDL
01609 
01610     throw VideoException(
01611         "VideoModule::HardwareToHardwareBlitsAccelerated failed: "
01612         "no SDL support available" ) ;
01613 
01614 #endif // OSDL_USES_SDL
01615 
01616 }
01617 
01618 
01619 
01620 bool VideoModule::HardwareToHardwareColorkeyBlitsAccelerated()
01621 {
01622 
01623 #if OSDL_USES_SDL
01624 
01625 
01626     const SDL_VideoInfo * videoInfo = SDL_GetVideoInfo() ;
01627 
01628     if ( videoInfo == 0 )
01629         throw( "VideoModule::HardwareToHardwareColorkeyBlitsAccelerated: "
01630             "unable to retrieve video informations." ) ;
01631 
01632     return static_cast<bool>( videoInfo->blit_hw_CC ) ;
01633 
01634 #else // OSDL_USES_SDL
01635 
01636     throw VideoException(
01637         "VideoModule::HardwareToHardwareColorkeyBlitsAccelerated failed: "
01638         "no SDL support available" ) ;
01639 
01640 #endif // OSDL_USES_SDL
01641 
01642 }
01643 
01644 
01645 
01646 bool VideoModule::HardwareToHardwareAlphaBlitsAccelerated()
01647 {
01648 
01649 #if OSDL_USES_SDL
01650 
01651     const SDL_VideoInfo * videoInfo = SDL_GetVideoInfo() ;
01652 
01653     if ( videoInfo == 0 )
01654         throw( "VideoModule::HardwareToHardwareAlphaBlitsAccelerated: "
01655             "unable to retrieve video informations." ) ;
01656 
01657     return static_cast<bool>( videoInfo->blit_hw_A ) ;
01658 
01659 #else // OSDL_USES_SDL
01660 
01661     throw VideoException(
01662         "VideoModule::HardwareToHardwareAlphaBlitsAccelerated failed: "
01663         "no SDL support available" ) ;
01664 
01665 #endif // OSDL_USES_SDL
01666 
01667 }
01668 
01669 
01670 
01671 bool VideoModule::SoftwareToHardwareBlitsAccelerated()
01672 {
01673 
01674 #if OSDL_USES_SDL
01675 
01676     const SDL_VideoInfo * videoInfo = SDL_GetVideoInfo() ;
01677 
01678     if ( videoInfo == 0 )
01679         throw( "VideoModule::SoftwareToHardwareBlitsAccelerated: "
01680             "unable to retrieve video informations." ) ;
01681 
01682     return static_cast<bool>( videoInfo->blit_sw ) ;
01683 
01684 #else // OSDL_USES_SDL
01685 
01686     throw VideoException(
01687         "VideoModule::SoftwareToHardwareBlitsAccelerated failed: "
01688         "no SDL support available" ) ;
01689 
01690 #endif // OSDL_USES_SDL
01691 
01692 }
01693 
01694 
01695 
01696 bool VideoModule::SoftwareToHardwareColorkeyBlitsAccelerated()
01697 {
01698 
01699 #if OSDL_USES_SDL
01700 
01701     const SDL_VideoInfo * videoInfo = SDL_GetVideoInfo() ;
01702 
01703     if ( videoInfo == 0 )
01704         throw( "VideoModule::SoftwareToHardwareColorkeyBlitsAccelerated: "
01705             "unable to retrieve video informations." ) ;
01706 
01707     return static_cast<bool>( videoInfo->blit_sw_CC ) ;
01708 
01709 #else // OSDL_USES_SDL
01710 
01711     throw VideoException(
01712         "VideoModule::SoftwareToHardwareColorkeyBlitsAccelerated failed: "
01713         "no SDL support available" ) ;
01714 
01715 #endif // OSDL_USES_SDL
01716 
01717 }
01718 
01719 
01720 
01721 bool VideoModule::SoftwareToHardwareAlphaBlitsAccelerated()
01722 {
01723 
01724 #if OSDL_USES_SDL
01725 
01726 
01727     const SDL_VideoInfo * videoInfo = SDL_GetVideoInfo() ;
01728 
01729     if ( videoInfo == 0 )
01730         throw( "VideoModule::SoftwareToHardwareAlphaBlitsAccelerated: "
01731             "unable to retrieve video informations." ) ;
01732 
01733     return static_cast<bool>( videoInfo->blit_sw_A ) ;
01734 
01735 #else // OSDL_USES_SDL
01736 
01737     throw VideoException(
01738         "VideoModule::SoftwareToHardwareAlphaBlitsAccelerated failed: "
01739         "no SDL support available" ) ;
01740 
01741 #endif // OSDL_USES_SDL
01742 
01743 }
01744 
01745 
01746 
01747 bool VideoModule::ColorFillsAccelerated()
01748 {
01749 
01750 #if OSDL_USES_SDL
01751 
01752 
01753     const SDL_VideoInfo * videoInfo = SDL_GetVideoInfo() ;
01754 
01755     if ( videoInfo == 0 )
01756         throw( "VideoModule::ColorFillsAccelerated: "
01757             "unable to retrieve video informations." ) ;
01758 
01759     return static_cast<bool>( videoInfo->blit_fill ) ;
01760 
01761 #else // OSDL_USES_SDL
01762 
01763     throw VideoException(
01764         "VideoModule::ColorFillsAccelerated failed: no SDL support available"
01765     ) ;
01766 
01767 #endif // OSDL_USES_SDL
01768 
01769 }
01770 
01771 
01772 
01773 Ceylan::Uint32 VideoModule::GetVideoMemorySize()
01774 {
01775 
01776 #if OSDL_USES_SDL
01777 
01778     const SDL_VideoInfo * videoInfo = SDL_GetVideoInfo() ;
01779 
01780     if ( videoInfo == 0 )
01781         throw( "VideoModule::GetVideoMemorySize: "
01782             "unable to retrieve video informations." ) ;
01783 
01784     return static_cast<Ceylan::Uint32>( videoInfo->video_mem ) ;
01785 
01786 #else // OSDL_USES_SDL
01787 
01788     throw VideoException( "VideoModule::GetVideoMemorySize failed: "
01789         "no SDL support available" ) ;
01790 
01791 #endif // OSDL_USES_SDL
01792 
01793 }
01794 
01795 
01796 
01797 Pixels::PixelFormat VideoModule::GetVideoDevicePixelFormat()
01798 {
01799 
01800 #if OSDL_USES_SDL
01801 
01802     const SDL_VideoInfo * videoInfo = SDL_GetVideoInfo() ;
01803 
01804     if ( videoInfo == 0 )
01805         throw( "VideoModule::GetVideoDevicePixelFormat: "
01806             "unable to retrieve video informations." ) ;
01807 
01808     return * static_cast<Pixels::PixelFormat *>( videoInfo->vfmt ) ;
01809 
01810 #else // OSDL_USES_SDL
01811 
01812     throw VideoException( "VideoModule::GetVideoDevicePixelFormat failed: "
01813         "no SDL support available" ) ;
01814 
01815 #endif // OSDL_USES_SDL
01816 
01817 }
01818 
01819 
01820 
01821 string VideoModule::DescribeVideoCapabilities()
01822 {
01823 
01824     string result ;
01825 
01826     try
01827     {
01828         result = "Video device capabilities for "
01829         + Ceylan::Network::getMostPreciseLocalHostName()
01830         + " are:" ;
01831     }
01832     catch ( const Ceylan::Network::NetworkException & e )
01833     {
01834         LogPlug::error( "VideoModule::getVideoCapabilities: "
01835             "error when retrieving host name: "
01836             + e.toString() ) ;
01837         result = "Video device capabilities are:" ;
01838 
01839     }
01840 
01841     std::list<string> l ;
01842 
01843     if ( HardwareSurfacesCanBeCreated() )
01844         l.push_back( "Hardware surfaces can be created." ) ;
01845     else
01846         l.push_back( "Only software surfaces can be created." ) ;
01847 
01848     if ( WindowManagerAvailable() )
01849         l.push_back( "A window manager is available." ) ;
01850     else
01851         l.push_back( "No window manager available." ) ;
01852 
01853 
01854 
01855     if ( HardwareToHardwareBlitsAccelerated() )
01856         l.push_back( "Hardware to hardware blits are accelerated." ) ;
01857     else
01858         l.push_back( "No hardware to hardware blit acceleration available." ) ;
01859 
01860 
01861     if ( HardwareToHardwareColorkeyBlitsAccelerated() )
01862         l.push_back( "Hardware to hardware colorkey blits are accelerated." ) ;
01863     else
01864         l.push_back(
01865             "No hardware to hardware colorkey blit acceleration available." ) ;
01866 
01867 
01868     if ( HardwareToHardwareAlphaBlitsAccelerated() )
01869         l.push_back( "Hardware to hardware alpha blits are accelerated." ) ;
01870     else
01871         l.push_back(
01872             "No hardware to hardware alpha blit acceleration available." ) ;
01873 
01874 
01875 
01876     if ( SoftwareToHardwareBlitsAccelerated() )
01877         l.push_back( "Software to hardware blits are accelerated." ) ;
01878     else
01879         l.push_back(
01880             "No software to hardware blit acceleration available." ) ;
01881 
01882 
01883     if ( SoftwareToHardwareColorkeyBlitsAccelerated() )
01884         l.push_back( "Software to hardware colorkey blits are accelerated." ) ;
01885     else
01886         l.push_back(
01887             "No software to hardware colorkey blit acceleration available." ) ;
01888 
01889 
01890     if ( SoftwareToHardwareAlphaBlitsAccelerated() )
01891         l.push_back( "Software to hardware alpha blits are accelerated." ) ;
01892     else
01893         l.push_back(
01894             "No software to hardware alpha blit acceleration available." ) ;
01895 
01896 
01897 
01898     if ( ColorFillsAccelerated() )
01899         l.push_back( "Color fills are accelerated." ) ;
01900     else
01901         l.push_back( "No color fill acceleration available." ) ;
01902 
01903 
01904     if ( GetVideoMemorySize() )
01905         l.push_back( "Total amount of video memory is "
01906             + Ceylan::toString( GetVideoMemorySize() ) + " kilobytes." ) ;
01907     else
01908         l.push_back( "Unable to get total amount of video memory." ) ;
01909 
01910     l.push_back( Pixels::toString( GetVideoDevicePixelFormat() ) ) ;
01911 
01912 
01913     return result + Ceylan::formatStringList( l ) ;
01914 
01915 }
01916 
01917 
01918 
01919 bool VideoModule::AreDefinitionsRestricted( list<Definition> & definitions,
01920     Ceylan::Flags flags, Pixels::PixelFormat * pixelFormat )
01921 {
01922 
01923 #if OSDL_USES_SDL
01924 
01925     SDL_Rect ** modes ;
01926 
01927 #if OSDL_DEBUG_VIDEO
01928     LOG_TRACE_VIDEO( "VideoModule::AreDefinitionsRestricted: "
01929         "getting available modes.", 8 ) ;
01930 #endif // OSDL_DEBUG_VIDEO
01931 
01932     modes = SDL_ListModes( pixelFormat, flags ) ;
01933 
01934 
01935     
01936 
01937 
01938 
01939 
01940 
01941 
01942 
01943 
01944 #ifdef OSDL_RUNS_ON_WINDOWS
01945 
01946     Ceylan::Uint64 numericModes =
01947         reinterpret_cast<Ceylan::Uint64>( modes ) ;
01948 
01949 #else // OSDL_RUNS_ON_WINDOWS
01950 
01951     
01952 
01953 
01954 
01955 
01956     Ceylan::SignedLongInteger numericModes =
01957         reinterpret_cast<Ceylan::SignedLongInteger>( modes ) ;
01958 
01959 #endif // OSDL_RUNS_ON_WINDOWS
01960 
01961 
01962     if ( numericModes == 0 )
01963     {
01964         LOG_DEBUG_VIDEO( "No screen dimensions available for format "
01965             + Pixels::toString( * pixelFormat ) + " !" ) ;
01966 
01967         
01968         return true ;
01969 
01970     }
01971 
01972     
01973 
01974     
01975     if ( numericModes == -1 )
01976     {
01977 
01978         
01979         return false ;
01980 
01981     }
01982 
01983     
01984 
01985     for ( Ceylan::Uint16 i = 0 ; modes[ i ] ; i++)
01986     {
01987         definitions.push_back( pair<Length, Length>(
01988             modes[ i ]->w, modes[ i ]->h ) ) ;
01989     }
01990 
01991     return true ;
01992 
01993 #else // OSDL_USES_SDL
01994 
01995     throw VideoException( "VideoModule::AreDefinitionsRestricted failed: "
01996         "no SDL support available" ) ;
01997 
01998 #endif // OSDL_USES_SDL
01999 
02000 }
02001 
02002 
02003 
02004 string VideoModule::DescribeAvailableDefinitions( Ceylan::Flags flags,
02005     Pixels::PixelFormat * pixelFormat )
02006 {
02007 
02008 #if OSDL_USES_SDL
02009 
02010     list<Definition> defList ;
02011 
02012 #if OSDL_DEBUG_VIDEO
02013     LOG_TRACE_VIDEO( "VideoModule::DescribeAvailableDefinitions: "
02014         "getting available modes.", 8 ) ;
02015 #endif // OSDL_DEBUG_VIDEO
02016 
02017     
02018 
02019     if ( ! AreDefinitionsRestricted( defList, flags, pixelFormat ) )
02020     {
02021 
02022         if ( pixelFormat == 0 )
02023             return "All screen dimensions are supported for "
02024                 "the best possible video mode" ;
02025         else
02026             return "All screen dimensions are supported for "
02027                 "the given pixel format" ;
02028 
02029     }
02030     else 
02031     {
02032 
02033         if ( defList.empty() )
02034         {
02035             return "No screen dimension available for "
02036                 "specified format and flags" ;
02037         }
02038         else
02039         {
02040 
02041             string result ;
02042 
02043             list<string> l ;
02044 
02045             
02046 
02047             if ( pixelFormat == 0 )
02048                 result = "Screen dimensions supported for "
02049                     "the best possible video mode are:" ;
02050             else
02051                 result = "Screen dimensions supported for "
02052                     "the given pixel format are:" ;
02053 
02054             for ( list<Definition>::const_iterator it = defList.begin();
02055                 it != defList.end(); it++ )
02056             {
02057                 l.push_back( Ceylan::toString( (*it).first )
02058                     + 'x' +  Ceylan::toString( (*it).second ) ) ;
02059             }
02060 
02061             return result + Ceylan::formatStringList( l ) ;
02062 
02063         }
02064 
02065     }
02066 
02067 #else // OSDL_USES_SDL
02068 
02069     throw VideoException( "VideoModule::DescribeAvailableDefinitions: "
02070         "no SDL support available" ) ;
02071 
02072 #endif // OSDL_USES_SDL
02073 
02074 }
02075 
02076 
02077 
02078 StandardScreenSize VideoModule::ToStandardScreenSize(
02079     const std::string & standardScreenSizeInText )
02080 {
02081 
02082     StandardScreenSize screenSize ;
02083 
02084     try
02085     {
02086 
02087         screenSize = static_cast<StandardScreenSize>(
02088             Ceylan::stringToUnsignedLong( standardScreenSizeInText ) ) ;
02089 
02090     }
02091     catch( const Ceylan::Exception & e )
02092     {
02093 
02094         throw VideoException( "VideoModule::ToStandardScreenSize: "
02095             "could not convert '" + standardScreenSizeInText
02096             + "' into a number designating a screen size." ) ;
02097     }
02098 
02099     switch( screenSize )
02100     {
02101 
02102         case Size_640x480:
02103         case Size_800x600:
02104         case Size_1024x780:
02105         case Size_1280x1024:
02106         case Size_1680x1050:
02107         case Size_FullScreen:
02108             return screenSize ;
02109             break ;
02110 
02111         default:
02112             throw VideoException( "VideoModule::ToStandardScreenSize: "
02113                 "'" + Ceylan::toString(screenSize)
02114                 + "' is not a known standard screen size." ) ;
02115 
02116     }
02117 
02118 }
02119 
02120 
02121 
02122 void VideoModule::ToScreenDimensions( StandardScreenSize screenSize,
02123     Length & screenWidth, Length & screenHeight )
02124 {
02125 
02126     switch( screenSize )
02127     {
02128 
02129         case Size_640x480:
02130             screenWidth  = 640 ;
02131             screenHeight = 480 ;
02132             break ;
02133 
02134         case Size_800x600:
02135             screenWidth  = 800 ;
02136             screenHeight = 600 ;
02137             break ;
02138 
02139         case Size_1024x780:
02140             screenWidth  = 1024 ;
02141             screenHeight = 780 ;
02142             break ;
02143 
02144         case Size_1280x1024:
02145             screenWidth  = 1280 ;
02146             screenHeight = 1024;
02147             break ;
02148 
02149         case Size_1680x1050:
02150             screenWidth  = 1680 ;
02151             screenHeight = 1050 ;
02152             break ;
02153 
02154         case Size_FullScreen:
02155             throw VideoException( "VideoModule::ToScreenDimensions: "
02156                 "'" + Ceylan::toString(screenSize)
02157                 + "' is a logical size which cannot be converted statically "
02158                 " into a physical one." ) ;
02159             break ;
02160 
02161         default:
02162             throw VideoException( "VideoModule::ToScreenDimensions: "
02163                 "'" + Ceylan::toString(screenSize)
02164                 + "' is not a known standard screen size." ) ;
02165 
02166     }
02167 
02168 }
02169 
02170 
02171 
02172 string VideoModule::DescribeEnvironmentVariables()
02173 {
02174 
02175     Ceylan::Uint16 varCount =
02176         sizeof( _SDLEnvironmentVariables ) / sizeof (string) ;
02177 
02178     string result = "Examining the " + Ceylan::toString( varCount )
02179         + " video-related environment variables for SDL backend:" ;
02180 
02181     list<string> variables ;
02182 
02183     string var, value ;
02184 
02185     TextOutputFormat htmlFormat = Ceylan::TextDisplayable::GetOutputFormat() ;
02186 
02187     for ( Ceylan::Uint16 i = 0; i < varCount; i++ )
02188     {
02189 
02190         var = _SDLEnvironmentVariables[ i ] ;
02191         value = Ceylan::System::getEnvironmentVariable( var ) ;
02192 
02193         if ( value.empty() )
02194         {
02195             if ( htmlFormat == TextDisplayable::html )
02196             {
02197                 variables.push_back( "<em>" + var + "</em> is not set." ) ;
02198             }
02199             else
02200             {
02201                 variables.push_back( var + " is not set." ) ;
02202             }
02203         }
02204         else
02205         {
02206             if ( htmlFormat == TextDisplayable::html )
02207             {
02208                 variables.push_back( "<b>" + var + "</b> set to ["
02209                     + value + "]." ) ;
02210             }
02211             else
02212             {
02213                 variables.push_back( var + " set to [" + value + "]." ) ;
02214             }
02215         }
02216 
02217     }
02218 
02219     return result + Ceylan::formatStringList( variables ) ;
02220 
02221 }
02222 
02223 
02224 
02225 bool VideoModule::IsUsingOpenGL()
02226 {
02227 
02228   return _IsUsingOpenGL ;
02229 
02230 }
02231 
02232 
02233 bool VideoModule::IsUsingDrawingPrimitives()
02234 {
02235 
02236 #if OSDL_USES_SDL_GFX
02237 
02238   return true ;
02239 
02240 #else // OSDL_USES_SDL_GFX
02241 
02242   return false ;
02243 
02244 #endif // OSDL_USES_SDL_GFX
02245 
02246 }