lib/client/frameData.h

00001 
00002 /* Copyright (c) 2006-2009, Stefan Eilemann <eile@equalizergraphics.com>
00003  *
00004  * This library is free software; you can redistribute it and/or modify it under
00005  * the terms of the GNU Lesser General Public License version 2.1 as published
00006  * by the Free Software Foundation.
00007  *  
00008  * This library is distributed in the hope that it will be useful, but WITHOUT
00009  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
00010  * FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License for more
00011  * details.
00012  * 
00013  * You should have received a copy of the GNU Lesser General Public License
00014  * along with this library; if not, write to the Free Software Foundation, Inc.,
00015  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
00016  */
00017 
00018 #ifndef EQ_FRAMEDATA_H
00019 #define EQ_FRAMEDATA_H
00020 
00021 #include <eq/client/frame.h>         // enum Frame::Buffer
00022 #include <eq/client/pixelViewport.h> // member
00023 #include <eq/client/pixel.h>         // member
00024 #include <eq/client/range.h>         // member
00025 #include <eq/client/types.h>         // member
00026 
00027 #include <eq/base/monitor.h>         // member
00028 #include <eq/net/object.h>           // base class
00029 
00030 #include <set>                       // member
00031 
00032 namespace eq
00033 {
00034 
00035 namespace server
00036 {
00037     class FrameData;
00038 }
00039 
00040     class  Image;
00041     class  ROIFinder;
00042     struct FrameDataTransmitPacket;
00043 
00048     class FrameData : public net::Object
00049     {
00050     public:
00051         EQ_EXPORT FrameData();
00052         EQ_EXPORT virtual ~FrameData();
00053 
00059         uint32_t getBuffers() const { return _data.buffers; }
00060         void     setBuffers( const uint32_t buffers ){ _data.buffers = buffers;}
00061 
00063         const Range& getRange() const { return _data.range; }
00064         void setRange( const Range& range ) { _data.range = range; }
00065         
00067         const Pixel& getPixel() const { return _data.pixel; }
00068         
00070         const ImageVector& getImages() const { return _images; }
00071 
00073         void setPixelViewport( const PixelViewport& pvp ) { _data.pvp = pvp; }
00074 
00075         /* Set color buffer type to read */
00076         void setColorType( const GLuint colorType ) { _colorType = colorType; }
00077         
00079         void setAlphaUsage( const bool useAlpha ) { _useAlpha = useAlpha; }
00081 
00086 
00088         void flush();
00089 
00095         EQ_EXPORT Image* newImage( const Frame::Type type = Frame::TYPE_MEMORY);
00096 
00098         EQ_EXPORT void clear();
00099 
00109         void startReadback( const Frame& frame, 
00110                             Window::ObjectManager* glObjects );
00111 
00113         void syncReadback();
00114 
00124         void transmit( net::NodePtr toNode, const uint32_t frameNumber );
00125 
00132         void setReady();
00133 
00135         bool isReady() const   { return _readyVersion >= getVersion(); }
00136 
00138         void waitReady() const { _readyVersion.waitGE( getVersion( )); }
00139 
00146         void addListener( base::Monitor<uint32_t>& listener );
00147 
00153         void removeListener( base::Monitor<uint32_t>& listener );
00154         
00160         void disableBuffer( const Frame::Buffer buffer )
00161             { _data.buffers &= ~buffer; }
00162  
00164         void useSendToken( const bool use ) { _useSendToken = use; }
00166 
00168         void update( const uint32_t version );
00169 
00170     protected:
00171         virtual ChangeType getChangeType() const { return INSTANCE; }
00172         virtual void getInstanceData( net::DataOStream& os );
00173         virtual void applyInstanceData( net::DataIStream& is );
00174 
00176         virtual void attachToSession( const uint32_t id, 
00177                                       const uint32_t instanceID, 
00178                                       net::Session* session );
00179 
00180     private:
00181         struct Data
00182         {
00183             Data() : offset( Vector2i::ZERO ), buffers( 0 ), format( 0 )
00184                    , type( 0 ), frameType( Frame::TYPE_MEMORY ){}
00185 
00186             PixelViewport pvp;
00187             Vector2i      offset;
00188             uint32_t      buffers;
00189             uint32_t      format;
00190             uint32_t      type;
00191             Frame::Type   frameType;
00192             Range         range;     //<! database-range of src wrt to dest
00193             Pixel         pixel;     //<! pixel decomposition of source
00194         } _data;
00195 
00196         friend class eq::server::FrameData;
00197 
00198         ImageVector  _images;
00199         ImageVector  _imageCache;
00200         base::Lock   _imageCacheLock;
00201 
00202         GLuint     _colorType; 
00203         ROIFinder* _roiFinder;
00204 
00205         struct ImageVersion
00206         {
00207             ImageVersion( Image* _image, const uint32_t _version )
00208                     : image( _image ), version( _version ) {}
00209 
00210             Image*   image;
00211             uint32_t version;
00212         };
00213         std::list<ImageVersion> _pendingImages;
00214         std::set< uint32_t >    _readyVersions;
00215 
00217         base::Monitor<uint32_t> _readyVersion;
00218 
00220         std::vector< base::Monitor<uint32_t>* > _listeners;
00221         base::Lock                              _listenersMutex;
00222 
00223         bool _useAlpha;
00224         bool _useSendToken;
00225         
00226         union // placeholder for binary-compatible changes
00227         {
00228             char dummy[64];
00229         };
00230 
00232         Image* _allocImage( const eq::Frame::Type type );
00233 
00235         void _applyVersion( const uint32_t version );
00236 
00238         void _setReady( const uint32_t version );
00239 
00240         /* The command handlers. */
00241         net::CommandResult _cmdTransmit( net::Command& command );
00242         net::CommandResult _cmdReady( net::Command& command );
00243         net::CommandResult _cmdUpdate( net::Command& command );
00244 
00245         CHECK_THREAD_DECLARE( _commandThread );
00246     };
00247     std::ostream& operator << ( std::ostream& os, const FrameData* data );
00248 }
00249 
00250 #endif // EQ_FRAMEDATA_H
00251 
Generated on Mon Aug 10 18:58:33 2009 for Equalizer 0.9 by  doxygen 1.5.8