Equalizer  1.2.1
include/eq/client/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/client/eye.h>            // Eye enum
00023 #include <eq/client/gl.h>             // WGLEWContext
00024 #include <eq/client/types.h>
00025 #include <eq/client/visitorResult.h>  // enum
00026 #include <eq/client/windowSystem.h>   // enum
00027 
00028 #include <eq/fabric/pipe.h>           // base class
00029 
00030 #include <co/objectVersion.h>
00031 #include <co/base/lock.h>
00032 #include <co/base/refPtr.h>
00033 #include <co/worker.h>
00034 
00035 namespace eq
00036 {
00047     class Pipe : public fabric::Pipe< Node, Pipe, eq::Window, PipeVisitor >
00048     {
00049     public:
00051         EQ_API Pipe( Node* parent );
00052 
00054         EQ_API virtual ~Pipe();
00055 
00058         EQ_API co::CommandQueue* getPipeThreadQueue(); 
00059         co::CommandQueue* getMainThreadQueue(); 
00060         co::CommandQueue* getCommandThreadQueue(); 
00061 
00063         EQ_API Config* getConfig();
00065         EQ_API const Config* getConfig() const;
00066 
00068         EQ_API ClientPtr getClient();
00069 
00071         EQ_API ServerPtr getServer();
00072 
00077         bool isRunning() const;
00078 
00083         EQ_API bool isStopped() const;
00084 
00092         EQ_API uint32_t getCurrentFrame() const;
00093         EQ_API uint32_t getFinishedFrame() const; 
00094 
00105         WindowSystem getWindowSystem() const { return _windowSystem; }
00107 
00121         Frame* getFrame( const co::ObjectVersion& frameVersion, 
00122                          const Eye eye, const bool output );
00123 
00125         co::QueueSlave* getQueue( const co::ObjectVersion& queueVersion );
00126 
00128         void flushFrames();
00129 
00131         bool isCurrent( const Window* window ) const;
00132 
00138         void setCurrent( const Window* window ) const;
00139 
00141         const View* getView( const co::ObjectVersion& viewVersion ) const;
00142 
00144         View* getView( const co::ObjectVersion& viewVersion );
00146 
00147         void waitExited() const; 
00148         void notifyMapped(); 
00149         
00157         EQ_API void waitFrameFinished( const uint32_t frameNumber ) const;
00158 
00166         EQ_API void waitFrameLocal( const uint32_t frameNumber ) const;
00167 
00169         void startThread();
00170 
00172         void exitThread();
00173 
00174         void cancelThread(); 
00175 
00188         void setSystemPipe( SystemPipe* pipe )  { _systemPipe = pipe; }
00189 
00191         SystemPipe* getSystemPipe() { return _systemPipe; }
00192 
00194         const SystemPipe* getSystemPipe() const { return _systemPipe; }
00196 
00203         void setComputeContext( ComputeContext* ctx ) { _computeContext = ctx; }
00204 
00206         const ComputeContext* getComputeContext() const
00207             { return _computeContext; }
00208 
00210         ComputeContext* getComputeContext() { return _computeContext; }
00212 
00227         EQ_API virtual MessagePump* createMessagePump();
00228 
00230         MessagePump* getMessagePump();
00232 
00234         EQ_API virtual void setDirty( const uint64_t bits );
00235 
00236     protected:
00245         EQ_API void startFrame( const uint32_t frameNumber );
00246 
00253         EQ_API void releaseFrame( const uint32_t frameNumber );
00254 
00261         EQ_API void releaseFrameLocal( const uint32_t frameNumber );
00263 
00271 #ifndef EQ_2_0_API
00272 
00283         virtual bool supportsWindowSystem( const WindowSystem system ) const
00284             { return true; }
00285 #endif
00286 
00295         EQ_API virtual WindowSystem selectWindowSystem() const;
00296 
00303         EQ_API virtual bool configInit( const uint128_t& initID );
00304 
00311         EQ_API virtual bool configInitSystemPipe( const uint128_t& initID );
00312 
00317         EQ_API virtual bool configExit();
00318 
00336         EQ_API virtual void frameStart( const uint128_t& frameID, 
00337                                         const uint32_t frameNumber );
00338 
00353         EQ_API virtual void frameFinish( const uint128_t& frameID, 
00354                                          const uint32_t frameNumber );
00355 
00366         EQ_API virtual void frameDrawFinish( const uint128_t& frameID, 
00367                                              const uint32_t frameNumber );
00368 
00370         EQ_API virtual void attach( const UUID& id, const uint32_t instanceID );
00371 
00372     private:
00373         //-------------------- Members --------------------
00375         SystemPipe* _systemPipe;
00376 
00378         WindowSystem _windowSystem;
00379 
00380         enum State
00381         {
00382             STATE_MAPPED,
00383             STATE_INITIALIZING,
00384             STATE_RUNNING,
00385             STATE_STOPPING, // must come after running
00386             STATE_STOPPED, // must come after running
00387             STATE_FAILED
00388         };
00390         co::base::Monitor< State > _state;
00391 
00393         uint32_t _currentFrame;
00394 
00396         co::base::Monitor< uint32_t > _finishedFrame;
00397 
00399         co::base::Monitor<uint32_t> _unlockedFrame;
00400 
00402         std::deque< int64_t > _frameTimes;
00403         co::base::Lock _frameTimeMutex;
00404 
00406         int64_t _frameTime;
00407 
00408         typedef stde::hash_map< uint128_t, Frame* > FrameHash;
00409         typedef stde::hash_map< uint128_t, FrameData* > FrameDataHash;
00410 
00412         FrameHash _frames;
00413 
00415         FrameDataHash _outputFrameDatas;
00416 
00417         typedef stde::hash_map< uint128_t, View* > ViewHash;
00419         ViewHash _views;
00420 
00421         typedef stde::hash_map< uint128_t, co::QueueSlave* > QueueHash;
00423         QueueHash _queues;
00424 
00426         class Thread;
00427         Thread* _thread;
00428 
00430         const mutable Window* _currentWindow;
00431 
00433         ComputeContext *_computeContext;
00434 
00435         struct Private;
00436         Private* _private; // placeholder for binary-compatible changes
00437 
00438         //-------------------- Methods --------------------
00439         void _setupCommandQueue();
00440         void _exitCommandQueue();
00441 
00442         friend class Window;
00443 
00445         void _releaseViews();
00446 
00448         void _flushViews();
00449 
00451         void _flushQueues();
00452 
00453         /* The command functions. */
00454         bool _cmdCreateWindow( co::Command& command );
00455         bool _cmdDestroyWindow( co::Command& command );
00456         bool _cmdConfigInit( co::Command& command );
00457         bool _cmdConfigExit( co::Command& command );
00458         bool _cmdFrameStartClock( co::Command& command );
00459         bool _cmdFrameStart( co::Command& command );
00460         bool _cmdFrameFinish( co::Command& command );
00461         bool _cmdFrameDrawFinish( co::Command& command );
00462         bool _cmdExitThread( co::Command& command );
00463         bool _cmdDetachView( co::Command& command );
00464 
00465         EQ_TS_VAR( _pipeThread );
00466     };
00467 }
00468 
00469 #endif // EQ_PIPE_H
00470 
Generated on Fri Jun 8 2012 15:44:32 for Equalizer 1.2.1 by  doxygen 1.8.0