aglPipe.cpp

00001 
00002 /* Copyright (c) 2009, Stefan Eilemann <eile@equalizergraphics.com>
00003                      , Makhinya Maxim
00004  *
00005  * This library is free software; you can redistribute it and/or modify it under
00006  * the terms of the GNU Lesser General Public License version 2.1 as published
00007  * by the Free Software Foundation.
00008  *  
00009  * This library is distributed in the hope that it will be useful, but WITHOUT
00010  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
00011  * FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License for more
00012  * details.
00013  * 
00014  * You should have received a copy of the GNU Lesser General Public License
00015  * along with this library; if not, write to the Free Software Foundation, Inc.,
00016  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
00017  */
00018 
00019 #include "aglPipe.h"
00020 
00021 #include "global.h"
00022 #include "pipe.h"
00023 
00024 #include <sstream>
00025 
00026 using namespace std;
00027 
00028 namespace eq
00029 {
00030 
00031 AGLPipe::AGLPipe( Pipe* parent )
00032     : OSPipe( parent )
00033     , _cgDisplayID( 0 )
00034 {
00035 }
00036 
00037 AGLPipe::~AGLPipe( )
00038 {
00039 }
00040 
00041 //---------------------------------------------------------------------------
00042 // AGL init
00043 //---------------------------------------------------------------------------
00044 bool AGLPipe::configInit()
00045 {
00046 #ifdef AGL
00047     CGDirectDisplayID displayID = CGMainDisplayID();
00048     const uint32_t device = _pipe->getDevice();
00049 
00050     if( device != EQ_UNDEFINED_UINT32 )
00051     {
00052         CGDirectDisplayID displayIDs[device+1];
00053         CGDisplayCount    nDisplays;
00054 
00055         if( CGGetOnlineDisplayList( device+1, displayIDs, &nDisplays ) !=
00056             kCGErrorSuccess )
00057         {
00058             ostringstream msg;
00059             msg << "Can't get display identifier for display " << device;
00060             setErrorMessage( msg.str( ));
00061             return false;
00062         }
00063 
00064         if( nDisplays <= device )
00065         {
00066             ostringstream msg;
00067             msg << "Can't get display identifier for display " << device
00068                 << ", not enough displays in this system";
00069             setErrorMessage( msg.str( ));
00070             return false;
00071         }
00072 
00073         displayID = displayIDs[device];
00074     }
00075 
00076     _setCGDisplayID( displayID );
00077     EQINFO << "Using CG displayID " << displayID << endl;
00078     return true;
00079 #else
00080     setErrorMessage( "Client library compiled without AGL support" );
00081     return false;
00082 #endif
00083 }
00084 
00085 
00086 void AGLPipe::_setCGDisplayID( CGDirectDisplayID id )
00087 {
00088 #ifdef AGL
00089     if( _cgDisplayID == id )
00090         return;
00091 
00092     _cgDisplayID = id; 
00093     PixelViewport pvp = _pipe->getPixelViewport();
00094 
00095     if( pvp.isValid( ))
00096         return;
00097 
00098     if( id )
00099     {
00100         const CGRect displayRect = CGDisplayBounds( id );
00101         pvp.x = (int32_t)displayRect.origin.x;
00102         pvp.y = (int32_t)displayRect.origin.y;
00103         pvp.w = (int32_t)displayRect.size.width;
00104         pvp.h = (int32_t)displayRect.size.height;
00105     }
00106     else
00107         pvp.invalidate();
00108 
00109     _pipe->setPixelViewport( pvp );
00110 #endif
00111 }
00112 
00113 
00114 void AGLPipe::configExit()
00115 {
00116 #ifdef AGL
00117     _setCGDisplayID( 0 );
00118     EQINFO << "Reset CG displayID " << endl;
00119 #endif
00120 }
00121 
00122 } //namespace eq
00123 
Generated on Mon Aug 10 18:58:31 2009 for Equalizer 0.9 by  doxygen 1.5.8