Equalizer 1.0

include/eq/pipe.h

00001 
00002 /* Copyright (c) 2005-2011, Stefan Eilemann <eile@equalizergraphics.com>
00003  *                    2010, Cedric Stalder <cedric.stalder@gmail.com> 
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 #ifndef EQ_PIPE_H
00020 #define EQ_PIPE_H
00021 
00022 #include <eq/eye.h>            // Eye enum
00023 #include <eq/gl.h>             // WGLEWContext
00024 #include <eq/types.h>
00025 #include <eq/visitorResult.h>  // enum
00026 #include <eq/windowSystem.h>   // enum
00027 
00028 #include <eq/fabric/pipe.h>           // base class
00029 
00030 #include <co/objectVersion.h>
00031 
00032 #include <co/base/lock.h>
00033 #include <co/base/refPtr.h>
00034 #include <co/base/thread.h>
00035 
00036 namespace eq
00037 {
00048     class Pipe : public fabric::Pipe< Node, Pipe, eq::Window, PipeVisitor >
00049     {
00050     public:
00052         EQ_API Pipe( Node* parent );
00053 
00055         EQ_API virtual ~Pipe();
00056 
00059         EQ_API co::CommandQueue* getPipeThreadQueue(); 
00060         co::CommandQueue* getMainThreadQueue(); 
00061         co::CommandQueue* getCommandThreadQueue(); 
00062 
00064         EQ_API Config* getConfig();
00066         EQ_API const Config* getConfig() const;
00067 
00069         EQ_API ClientPtr getClient();
00070 
00072         EQ_API ServerPtr getServer();
00073 
00078         bool isRunning() const;
00079 
00084         EQ_API bool isStopped() const;
00085 
00093         uint32_t getCurrentFrame()  const { return _currentFrame; }
00094         EQ_API uint32_t getFinishedFrame() const; 
00095 
00106         WindowSystem getWindowSystem() const { return _windowSystem; }
00108 
00122         Frame* getFrame( const co::ObjectVersion& frameVersion, 
00123                          const Eye eye, const bool output );
00124 
00126         void flushFrames();
00127 
00129         bool isCurrent( const Window* window ) const;
00130 
00136         void setCurrent( const Window* window ) const;
00137 
00139         const View* getView( const co::ObjectVersion& viewVersion ) const;
00140 
00142         View* getView( const co::ObjectVersion& viewVersion );
00144 
00145         void waitExited() const; 
00146         void notifyMapped(); 
00147         
00155         EQ_API void waitFrameFinished( const uint32_t frameNumber ) const;
00156 
00164         EQ_API void waitFrameLocal( const uint32_t frameNumber ) const;
00165 
00167         void startThread();
00168 
00170         void joinThread();
00171 
00184         void setSystemPipe( SystemPipe* pipe )  { _systemPipe = pipe; }
00185 
00187         SystemPipe* getSystemPipe() { return _systemPipe; }
00188 
00190         const SystemPipe* getSystemPipe() const { return _systemPipe; }
00192 
00199         void setComputeContext( ComputeContext* ctx ) { _computeContext = ctx; }
00200 
00202         const ComputeContext* getComputeContext() const
00203             { return _computeContext; }
00204 
00206         ComputeContext* getComputeContext() { return _computeContext; }
00208 
00223         EQ_API virtual MessagePump* createMessagePump();
00224 
00226         MessagePump* getMessagePump();
00228 
00230         EQ_API virtual void setDirty( const uint64_t bits );
00231 
00232     protected:
00241         EQ_API void startFrame( const uint32_t frameNumber );
00242 
00249         EQ_API void releaseFrame( const uint32_t frameNumber );
00250 
00257         EQ_API void releaseFrameLocal( const uint32_t frameNumber );
00259 
00275         EQ_API virtual bool supportsWindowSystem( const WindowSystem system )
00276                                    const;
00277 
00287         EQ_API virtual WindowSystem selectWindowSystem() const;
00288 
00295         EQ_API virtual bool configInit( const uint128_t& initID );
00296 
00303         EQ_API virtual bool configInitSystemPipe( const uint128_t& initID );
00304 
00309         EQ_API virtual bool configExit();
00310 
00328         EQ_API virtual void frameStart( const uint128_t& frameID, 
00329                                         const uint32_t frameNumber );
00330 
00345         EQ_API virtual void frameFinish( const uint128_t& frameID, 
00346                                          const uint32_t frameNumber );
00347 
00358         EQ_API virtual void frameDrawFinish( const uint128_t& frameID, 
00359                                              const uint32_t frameNumber );
00360 
00362         EQ_API virtual void attach( const UUID& id, const uint32_t instanceID );
00363 
00364     private:
00365         //-------------------- Members --------------------
00367         SystemPipe* _systemPipe;
00368 
00370         WindowSystem _windowSystem;
00371 
00372         enum State
00373         {
00374             STATE_MAPPED,
00375             STATE_INITIALIZING,
00376             STATE_RUNNING,
00377             STATE_STOPPED, // must come after running
00378             STATE_FAILED
00379         };
00381        co::base::Monitor< State > _state;
00382 
00384         uint32_t _currentFrame;
00385 
00387        co::base::Monitor< uint32_t > _finishedFrame;
00388 
00390        co::base::Monitor<uint32_t> _unlockedFrame;
00391 
00393         std::deque< int64_t > _frameTimes;
00394         co::base::Lock _frameTimeMutex;
00395 
00397         int64_t _frameTime;
00398 
00400         int64_t _waitTime;
00401 
00402         typedef stde::hash_map< uint128_t, Frame* > FrameHash;
00403         typedef stde::hash_map< uint128_t, FrameData* > FrameDataHash;
00404 
00406         FrameHash _frames;
00407 
00409         FrameDataHash _outputFrameDatas;
00410 
00411         typedef stde::hash_map< uint128_t, View* > ViewHash;
00413         ViewHash _views;
00414 
00416         class PipeThread : public co::base::Thread
00417         {
00418         public:
00419             PipeThread( Pipe* pipe ) 
00420                     : _pipe( pipe )
00421                 {}
00422             
00423             virtual void run(){ _pipe->_runThread(); }
00424 
00425         private:
00426             Pipe* _pipe;
00427         };
00428         PipeThread* _thread;
00429 
00431         eq::CommandQueue*   _pipeThreadQueue;
00432 
00434         const mutable Window* _currentWindow;
00435 
00437         ComputeContext *_computeContext;
00438 
00439         struct Private;
00440         Private* _private; // placeholder for binary-compatible changes
00441 
00442         //-------------------- Methods --------------------
00443         void _runThread();
00444         void _setupCommandQueue();
00445         void _exitCommandQueue();
00446 
00447         friend class Window;
00448 
00450         void _releaseViews();
00451 
00453         void _flushViews();
00454 
00455         /* The command functions. */
00456         bool _cmdCreateWindow( co::Command& command );
00457         bool _cmdDestroyWindow( co::Command& command );
00458         bool _cmdConfigInit( co::Command& command );
00459         bool _cmdConfigExit( co::Command& command );
00460         bool _cmdFrameStartClock( co::Command& command );
00461         bool _cmdFrameStart( co::Command& command );
00462         bool _cmdFrameFinish( co::Command& command );
00463         bool _cmdFrameDrawFinish( co::Command& command );
00464         bool _cmdExitThread( co::Command& command );
00465         bool _cmdDetachView( co::Command& command );
00466 
00467         EQ_TS_VAR( _pipeThread );
00468     };
00469 }
00470 
00471 #endif // EQ_PIPE_H
00472 
Generated on Sun May 8 2011 19:11:07 for Equalizer 1.0 by  doxygen 1.7.3