Equalizer  1.6.1
include/eq/client/frameData.h
1 
2 /* Copyright (c) 2006-2012, Stefan Eilemann <eile@equalizergraphics.com>
3  * 2011, Daniel Nachbaur <danielnachbaur@gmail.com>
4  *
5  * This library is free software; you can redistribute it and/or modify it under
6  * the terms of the GNU Lesser General Public License version 2.1 as published
7  * by the Free Software Foundation.
8  *
9  * This library is distributed in the hope that it will be useful, but WITHOUT
10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11  * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
12  * details.
13  *
14  * You should have received a copy of the GNU Lesser General Public License
15  * along with this library; if not, write to the Free Software Foundation, Inc.,
16  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
17  */
18 
19 #ifndef EQ_FRAMEDATA_H
20 #define EQ_FRAMEDATA_H
21 
22 #include <eq/client/frame.h> // enum Frame::Buffer
23 #include <eq/client/types.h>
24 
25 #include <eq/fabric/pixelViewport.h> // member
26 #include <eq/fabric/pixel.h> // member
27 #include <eq/fabric/range.h> // member
28 #include <eq/fabric/subPixel.h> // member
29 
30 #include <co/object.h> // base class
31 #include <lunchbox/monitor.h> // member
32 #include <lunchbox/spinLock.h> // member
33 
34 namespace eq
35 {
36 namespace server { class FrameData; }
37 
38  class ROIFinder;
39 
55  class FrameData : public co::Object, public lunchbox::Referenced
56  {
57  public:
58  void assembleFrame( Frame* frame, Channel* channel );
59  struct ImageHeader
60  {
61  uint32_t internalFormat;
62  uint32_t externalFormat;
63  uint32_t pixelSize;
65  uint32_t compressorName;
66  uint32_t compressorFlags;
67  uint32_t nChunks;
68  float quality;
69  };
70 
72  EQ_API FrameData();
73 
75  EQ_API virtual ~FrameData();
76 
80  Frame::Type getType() const { return _data.frameType; }
81 
83  void setType( const Frame::Type type ){ _data.frameType = type; }
84 
86  uint32_t getBuffers() const { return _data.buffers; }
87 
95  void setBuffers( const uint32_t buffers ){ _data.buffers = buffers;}
96 
106  const Range& getRange() const { return _data.range; }
107 
109  void setRange( const Range& range ) { _data.range = range; }
110 
115  const Pixel& getPixel() const { return _data.pixel; }
116 
121  const SubPixel& getSubPixel() const { return _data.subpixel; }
122 
127  uint32_t getPeriod() const { return _data.period; }
128 
133  uint32_t getPhase() const { return _data.phase; }
134 
136  const Images& getImages() const { return _images; }
137 
146  void setPixelViewport( const PixelViewport& pvp ) { _data.pvp = pvp; }
147 
149  const PixelViewport& getPixelViewport() const { return _data.pvp; }
150 
158  void setAlphaUsage( const bool useAlpha ) { _useAlpha = useAlpha; }
159 
169  void setQuality( const Frame::Buffer buffer, const float quality );
170 
172  void setZoom( const Zoom& zoom ) { _data.zoom = zoom; }
173 
175  const Zoom& getZoom() const { return _data.zoom; }
176 
187  void useCompressor( const Frame::Buffer buffer, const uint32_t name );
189 
202  EQ_API Image* newImage( const Frame::Type type,
203  const DrawableConfig& config );
204 
206  EQ_API void clear();
207 
209  void flush();
210 
212  void deleteGLObjects( ObjectManager* om );
213 
215  EQ_API void resetPlugins();
216 
217 #ifndef EQ_2_0_API
218 
230  void readback( const Frame& frame, ObjectManager* glObjects,
231  const DrawableConfig& config );
232 #endif
233 
247  Images startReadback( const Frame& frame, ObjectManager* glObjects,
248  const DrawableConfig& config,
249  const PixelViewports& regions );
250 
258  void setReady();
259 
261  bool isReady() const { return _readyVersion.get() >= _version; }
262 
264  void waitReady( const uint32_t timeout = LB_TIMEOUT_INDEFINITE ) const;
265 
267  void setVersion( const uint64_t version );
268 
278  void addListener( lunchbox::Monitor<uint32_t>& listener );
279 
286  void removeListener( lunchbox::Monitor<uint32_t>& listener );
287 
294  void disableBuffer( const Frame::Buffer buffer )
295  { _data.buffers &= ~buffer; }
297 
299  struct Data
300  {
301  Data() : frameType( Frame::TYPE_MEMORY ), buffers( 0 ), period( 1 )
302  , phase( 0 ) {}
303 
304  EQ_API Data& operator=( const Data& rhs );
305 
306  PixelViewport pvp;
307  fabric::Frame::Type frameType;
308  uint32_t buffers;
309  uint32_t period;
310  uint32_t phase;
311  Range range; //<! database-range of src wrt to dest
312  Pixel pixel; //<! pixel decomposition of source
313  SubPixel subpixel; //<! subpixel decomposition of source
314  Zoom zoom;
315 
316  EQ_API void serialize( co::DataOStream& os ) const;
317  EQ_API void deserialize( co::DataIStream& is );
318  } _data;
319 
321  bool addImage( const co::ObjectVersion& frameDataVersion,
322  const PixelViewport& pvp, const Zoom& zoom,
323  const uint32_t buffers, const bool useAlpha,
324  uint8_t* data );
325  void setReady( const co::ObjectVersion& frameData,
326  const FrameData::Data& data );
327 
328  protected:
329  virtual ChangeType getChangeType() const { return INSTANCE; }
330  virtual void getInstanceData( co::DataOStream& os );
331  virtual void applyInstanceData( co::DataIStream& is );
332 
333  private:
334  Images _images;
335  Images _imageCache;
336  lunchbox::Lock _imageCacheLock;
337 
338  ROIFinder* _roiFinder;
339 
340  Images _pendingImages;
341 
342  uint64_t _version;
343 
344  typedef lunchbox::Monitor< uint64_t > Monitor;
345 
347  Monitor _readyVersion;
348 
349  typedef lunchbox::Monitor< uint32_t > Listener;
350  typedef std::vector< Listener* > Listeners;
352  lunchbox::Lockable< Listeners, lunchbox::SpinLock > _listeners;
353 
354  bool _useAlpha;
355  float _colorQuality;
356  float _depthQuality;
357 
358  uint32_t _colorCompressor;
359  uint32_t _depthCompressor;
360 
361  struct Private;
362  Private* _private; // placeholder for binary-compatible changes
363 
365  Image* _allocImage( const Frame::Type type,
366  const DrawableConfig& config,
367  const bool setQuality );
368 
370  void _applyVersion( const uint128_t& version );
371 
373  void _setReady( const uint64_t version );
374 
375  LB_TS_VAR( _commandThread );
376  };
377 
379  EQ_API std::ostream& operator << ( std::ostream&, const FrameData& );
380 }
381 
382 namespace lunchbox
383 {
384 template<> inline void byteswap( eq::FrameData::Data& value )
385 {
386  byteswap( value.pvp );
387  byteswap( value.frameType );
388  byteswap( value.buffers );
389  byteswap( value.period );
390  byteswap( value.phase );
391  byteswap( value.range );
392  byteswap( value.pixel );
393  byteswap( value.subpixel );
394  byteswap( value.zoom );
395 }
396 }
397 
398 #endif // EQ_FRAMEDATA_H
399 
void removeListener(lunchbox::Monitor< uint32_t > &listener)
Remove a frame listener.
void setReady()
Set the frame data ready.
A holder for multiple images.
const Range & getRange() const
Get the range.
void deleteGLObjects(ObjectManager *om)
Delete data allocated by the given object manager on all images.
void clear()
Clear the frame by recycling the attached images.
void waitReady(const uint32_t timeout=LB_TIMEOUT_INDEFINITE) const
Wait for the frame data to become available.
uint32_t getPhase() const
A channel represents a two-dimensional viewport within a Window.
void setRange(const Range &range)
Set the range of this frame.
const Pixel & getPixel() const
A holder for pixel data.
Definition: image.h:35
void useCompressor(const Frame::Buffer buffer, const uint32_t name)
Sets a compressor which will be allocated and used during transmit of the image buffer.
void setQuality(const Frame::Buffer buffer, const float quality)
Set the minimum quality after download and compression.
void setBuffers(const uint32_t buffers)
Set the enabled frame buffer attachments.
std::vector< PixelViewport > PixelViewports
A vector of eq::PixelViewport.
void flush()
Flush the frame by deleting all images.
std::ostream & operator<<(std::ostream &os, const ConfigEvent *event)
Print the config event to the given output stream.
void addListener(lunchbox::Monitor< uint32_t > &listener)
Add a ready listener.
use main memory to store pixel data
Definition: fabric/frame.h:52
std::vector< Image * > Images
A vector of pointers to eq::Image.
void setAlphaUsage(const bool useAlpha)
Set alpha usage for newly allocated images.
void readback(const Frame &frame, ObjectManager *glObjects, const DrawableConfig &config)
Read back an image for this frame data.
virtual ~FrameData()
Destruct this frame data.
Frame::Type getType() const
uint32_t getPeriod() const
Holds a 2D pixel viewport with methods for manipulation.
Definition: pixelViewport.h:34
Image * newImage(const Frame::Type type, const DrawableConfig &config)
Allocate and add a new image.
A holder for a frame data and related parameters.
Definition: client/frame.h:42
void resetPlugins()
Deallocate all transfer and compression plugins on all images.
const SubPixel & getSubPixel() const
void disableBuffer(const Frame::Buffer buffer)
Disable the usage of a frame buffer attachment for all images.
uint32_t getBuffers() const
Buffer
The buffer format defines which components of the frame are to be used during readback and assembly...
Definition: fabric/frame.h:40
const Images & getImages() const
The images of this frame data holder.
util::ObjectManager< const void * > ObjectManager
The OpenGL object manager used in the client library.
void setPixelViewport(const PixelViewport &pvp)
Set the covered area for readbacks.
void setType(const Frame::Type type)
Set the storage type.
FrameData()
Construct a new frame data holder.
const PixelViewport & getPixelViewport() const
Type
The storage type for pixel data.
Definition: fabric/frame.h:50
Images startReadback(const Frame &frame, ObjectManager *glObjects, const DrawableConfig &config, const PixelViewports &regions)
Start reading back a set of images for this frame data.