OSDLOverlay.cc

Go to the documentation of this file.
00001 #include "OSDLOverlay.h"
00002 
00003 
00004 #include "OSDLVideo.h"    // for VideoModule
00005 #include "OSDLBasic.h"    // for CommonModule
00006 #include "OSDLUtils.h"    // for getBackendLastError
00007 
00008 #include "SDL.h"          // for SDL_Overlay
00009 
00010 
00011 
00012 using namespace OSDL::Video ;
00013 
00014 using std::string ;
00015 
00016 
00017 
00018 OverlayException::OverlayException( const std::string & message ) throw() :
00019     VideoException( message )
00020 {
00021 
00022 }
00023 
00024     
00025 OverlayException::~OverlayException() throw()
00026 {
00027 
00028 }
00029 
00030     
00031     
00032 // Overlay section.
00033 
00034     
00035 Overlay::Overlay( Length width, Length height, EncodingFormat format ) 
00036         throw( OverlayException ) :
00037     _overlay( 0 ),
00038     _width  ( 0 ),
00039     _height ( 0 )
00040 {
00041 
00042     if ( ! OSDL::hasExistingCommonModule() )
00043         throw OverlayException( "Overlay constructor : "
00044             "no OSDL common module available." ) ;
00045         
00046     CommonModule & common = OSDL::getExistingCommonModule() ;
00047 
00048     if ( ! common.hasVideoModule() )
00049         throw OverlayException( "Overlay constructor : "
00050             "no OSDL video module available." ) ;
00051             
00052     _overlay = SDL_CreateYUVOverlay( width, height, format,
00053         & common.getVideoModule().getScreenSurface().getSDLSurface() ) ;
00054 
00055     if ( _overlay == 0 )
00056         throw OverlayException( "Overlay constructor : "
00057             "overlay instanciation failed." ) ;
00058         
00059 }
00060 
00061 
00062 Overlay::~Overlay() throw()
00063 {
00064 
00065     if ( _overlay != 0 )
00066         SDL_FreeYUVOverlay( _overlay ) ;
00067         
00068 }
00069 
00070 
00071 void Overlay::blit( Coordinate x, Coordinate y ) const throw( OverlayException )
00072 {
00073 
00074     SDL_Rect destinationRect ;
00075     
00076     destinationRect.x = x ;
00077     destinationRect.y = y ;
00078     
00079     destinationRect.w = _width ;
00080     destinationRect.h = _height ;
00081     
00082     if ( SDL_DisplayYUVOverlay( _overlay, & destinationRect ) != 0 )
00083         throw OverlayException( "Overlay::blit failed : "
00084             + Utils::getBackendLastError() ) ;
00085     
00086 }
00087 
00088 
00089 void Overlay::blit() const throw( OverlayException )
00090 {
00091 
00092     blit( 0, 0 ) ;
00093 
00094 }
00095 
00096 
00097 bool Overlay::mustBeLocked() const throw()
00098 {
00099     
00100     // @fixme
00101     return true ; 
00102     
00103 }
00104 
00105 
00106 void Overlay::preUnlock() throw()
00107 {
00108 
00109     /*
00110      * Lockable framework ensures it is called only if necessary 
00111      * (i.e. only if 'must be locked') :
00112      *
00113      */
00114     SDL_UnlockYUVOverlay( _overlay ) ;
00115     
00116 }
00117 
00118 
00119 void Overlay::postLock() throw()
00120 {
00121 
00122     /*
00123      * Lockable framework ensures it is called only if necessary 
00124      * (i.e. only if 'must be locked') :
00125      *
00126      */
00127     SDL_LockYUVOverlay( _overlay ) ;
00128     
00129 }
00130 
00131 
00132 const string Overlay::toString( Ceylan::VerbosityLevels level ) const throw()
00133 {
00134 
00135     return "Overlay whose original size is width = " 
00136         + Ceylan::toString( _width )
00137         + ", height = " + Ceylan::toString( _height ) ;
00138         
00139 }
00140 

Generated on Fri Mar 30 14:46:59 2007 for OSDL by  doxygen 1.5.1