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 "OSDLOverlay.h"
00028
00029
00030 #include "OSDLVideo.h"
00031 #include "OSDLBasic.h"
00032 #include "OSDLUtils.h"
00033
00034
00035
00036 #ifdef OSDL_USES_CONFIG_H
00037 #include <OSDLConfig.h>
00038 #endif // OSDL_USES_CONFIG_H
00039
00040 #if OSDL_ARCH_NINTENDO_DS
00041 #include "OSDLConfigForNintendoDS.h"
00042 #endif // OSDL_ARCH_NINTENDO_DS
00043
00044
00045
00046 #if OSDL_USES_SDL
00047
00048 #include "SDL.h"
00049
00050 typedef SDL_Overlay LowLevelOverlay ;
00051
00052 #else // OSDL_USES_SDL
00053
00054 typedef struct LowLevelOverlay {} ;
00055
00056 #endif // OSDL_USES_SDL
00057
00058
00059
00060
00061
00062
00063
00064
00065 using namespace OSDL::Video ;
00066
00067 using std::string ;
00068
00069
00070
00071 OverlayException::OverlayException( const std::string & message ) :
00072 VideoException( message )
00073 {
00074
00075 }
00076
00077
00078
00079 OverlayException::~OverlayException() throw()
00080 {
00081
00082 }
00083
00084
00085
00086
00087
00088
00089
00090 Overlay::Overlay( Length width, Length height, EncodingFormat format ) :
00091 _overlay( 0 ),
00092 _width ( 0 ),
00093 _height ( 0 )
00094 {
00095
00096 #if OSDL_USES_SDL
00097
00098 if ( ! OSDL::hasExistingCommonModule() )
00099 throw OverlayException( "Overlay constructor: "
00100 "no OSDL common module available." ) ;
00101
00102 CommonModule & common = OSDL::getExistingCommonModule() ;
00103
00104 if ( ! common.hasVideoModule() )
00105 throw OverlayException( "Overlay constructor: "
00106 "no OSDL video module available." ) ;
00107
00108 _overlay = SDL_CreateYUVOverlay( width, height, format,
00109 & common.getVideoModule().getScreenSurface().getSDLSurface() ) ;
00110
00111 if ( _overlay == 0 )
00112 throw OverlayException( "Overlay constructor: "
00113 "overlay instanciation failed." ) ;
00114
00115 #else // OSDL_USES_SDL
00116
00117 throw OverlayException( "Overlay constructor failed: "
00118 "no SDL support available." ) ;
00119
00120 #endif // OSDL_USES_SDL
00121
00122 }
00123
00124
00125
00126 Overlay::~Overlay() throw()
00127 {
00128
00129 #if OSDL_USES_SDL
00130
00131 if ( _overlay != 0 )
00132 SDL_FreeYUVOverlay( _overlay ) ;
00133
00134 #endif // OSDL_USES_SDL
00135
00136 }
00137
00138
00139
00140 void Overlay::blit( Coordinate x, Coordinate y ) const
00141 {
00142
00143 #if OSDL_USES_SDL
00144
00145 SDL_Rect destinationRect ;
00146
00147 destinationRect.x = x ;
00148 destinationRect.y = y ;
00149
00150 destinationRect.w = _width ;
00151 destinationRect.h = _height ;
00152
00153 if ( SDL_DisplayYUVOverlay( _overlay, & destinationRect ) != 0 )
00154 throw OverlayException( "Overlay::blit failed: "
00155 + Utils::getBackendLastError() ) ;
00156
00157 #endif // OSDL_USES_SDL
00158
00159 }
00160
00161
00162
00163 void Overlay::blit() const
00164 {
00165
00166 blit( 0, 0 ) ;
00167
00168 }
00169
00170
00171
00172 bool Overlay::mustBeLocked() const
00173 {
00174
00175
00176 return true ;
00177
00178 }
00179
00180
00181
00182 void Overlay::preUnlock()
00183 {
00184
00185 #if OSDL_USES_SDL
00186
00187
00188
00189
00190
00191
00192 SDL_UnlockYUVOverlay( _overlay ) ;
00193
00194 #endif // OSDL_USES_SDL
00195
00196 }
00197
00198
00199
00200 void Overlay::postLock()
00201 {
00202
00203 #if OSDL_USES_SDL
00204
00205
00206
00207
00208
00209
00210 SDL_LockYUVOverlay( _overlay ) ;
00211
00212 #endif // OSDL_USES_SDL
00213
00214 }
00215
00216
00217
00218 const string Overlay::toString( Ceylan::VerbosityLevels level ) const
00219 {
00220
00221 return "Overlay whose original size is width = "
00222 + Ceylan::toString( _width )
00223 + ", height = " + Ceylan::toString( _height ) ;
00224
00225 }
00226