LCOV - code coverage report
Current view: top level - eq/fabric - canvas.h (source / functions) Hit Total Coverage
Test: Equalizer Lines: 15 15 100.0 %
Date: 2017-12-16 05:07:20 Functions: 16 30 53.3 %

          Line data    Source code
       1             : 
       2             : /* Copyright (c) 2010-2016, Stefan Eilemann <eile@eyescale.ch>
       3             :  *
       4             :  * This library is free software; you can redistribute it and/or modify it under
       5             :  * the terms of the GNU Lesser General Public License version 2.1 as published
       6             :  * by the Free Software Foundation.
       7             :  *
       8             :  * This library is distributed in the hope that it will be useful, but WITHOUT
       9             :  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
      10             :  * FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License for more
      11             :  * details.
      12             :  *
      13             :  * You should have received a copy of the GNU Lesser General Public License
      14             :  * along with this library; if not, write to the Free Software Foundation, Inc.,
      15             :  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
      16             :  */
      17             : 
      18             : #ifndef EQFABRIC_CANVAS_H
      19             : #define EQFABRIC_CANVAS_H
      20             : 
      21             : #include <eq/fabric/frustum.h>     // base class
      22             : #include <eq/fabric/object.h>      // base class
      23             : #include <eq/fabric/swapBarrier.h> // RefPtr member
      24             : #include <eq/fabric/types.h>
      25             : 
      26             : #include <string>
      27             : 
      28             : namespace eq
      29             : {
      30             : namespace fabric
      31             : {
      32             : /** A canvas represents a logical 2D projection surface. */
      33             : template <class CFG, class C, class S, class L>
      34             : // cppcheck-suppress noConstructor
      35             : class Canvas : public Object, public Frustum
      36             : {
      37             : public:
      38             :     typedef std::vector<C*> Canvases; //!< A vector of canvases
      39             :     typedef std::vector<S*> Segments; //!< A vector of segments
      40             :     typedef std::vector<L*> Layouts;  //!< A vector of layouts
      41             :     /** A Canvas visitor */
      42             :     typedef ElementVisitor<C, LeafVisitor<S>> Visitor;
      43             : 
      44             :     /** @name Data Access */
      45             :     //@{
      46             :     /** @return the parent config. @version 1.0 */
      47        1643 :     CFG* getConfig() { return _config; }
      48             :     /** @return the parent config. @version 1.0 */
      49        1662 :     const CFG* getConfig() const { return _config; }
      50             :     /** @internal @return the index path to this canvas. */
      51             :     CanvasPath getPath() const;
      52             : 
      53             :     /** @return the index of the active layout. @version 1.0 */
      54           4 :     uint32_t getActiveLayoutIndex() const { return _data.activeLayout; }
      55             :     /** @return the active layout. @version 1.0 */
      56             :     EQFABRIC_INL const L* getActiveLayout() const;
      57             : 
      58             :     /** @return the active layout. @version 2.1 */
      59             :     EQFABRIC_INL L* getActiveLayout();
      60             : 
      61             :     /** @return the vector of child segments. @version 1.0 */
      62        6495 :     const Segments& getSegments() const { return _segments; }
      63             :     /** @internal Find the first segment of a given name. */
      64             :     S* findSegment(const std::string& name);
      65             : 
      66             :     /** @internal Find the first segment of a given name. */
      67             :     const S* findSegment(const std::string& name) const;
      68             : 
      69             :     /** @return the vector of possible layouts. @version 1.0 */
      70         637 :     const Layouts& getLayouts() const { return _layouts; }
      71             :     /** @internal Add a new allowed layout to this canvas, can be 0. */
      72             :     EQFABRIC_INL void addLayout(L* layout);
      73             : 
      74             :     /** @internal Remove a layout from this canvas, can be the 0 layout. */
      75             :     EQFABRIC_INL bool removeLayout(L* layout);
      76             : 
      77             :     /** @internal
      78             :      * Set a swap barrier.
      79             :      *
      80             :      * This barrier will be set as a barrier on all segments added
      81             :      * afterwards.
      82             :      *
      83             :      * @param barrier the swap barrier.
      84             :      */
      85             :     EQFABRIC_INL void setSwapBarrier(SwapBarrierPtr barrier);
      86             : 
      87             :     /** @internal @return the current swap barrier. */
      88         252 :     SwapBarrierConstPtr getSwapBarrier() const { return _swapBarrier; }
      89             :     /** @internal @return the current swap barrier. */
      90         793 :     SwapBarrierPtr getSwapBarrier() { return _swapBarrier; }
      91             :     /** @sa Frustum::setWall() */
      92             :     EQFABRIC_INL virtual void setWall(const Wall& wall);
      93             : 
      94             :     /** @sa Frustum::setProjection() */
      95             :     EQFABRIC_INL virtual void setProjection(const Projection&);
      96             : 
      97             :     /** @sa Frustum::unsetFrustum() */
      98             :     EQFABRIC_INL virtual void unsetFrustum();
      99             :     //@}
     100             : 
     101             :     /** @name Operations */
     102             :     //@{
     103             :     /**
     104             :      * Activate the given layout on this canvas.
     105             :      * @return true if the active layout changed.
     106             :      * @version 1.0
     107             :      */
     108             :     EQFABRIC_INL virtual bool useLayout(const uint32_t index);
     109             : 
     110             :     /**
     111             :      * Traverse this canvas and all children using a canvas visitor.
     112             :      *
     113             :      * @param visitor the visitor.
     114             :      * @return the result of the visitor traversal.
     115             :      * @version 1.0
     116             :      */
     117             :     EQFABRIC_INL VisitorResult accept(Visitor& visitor);
     118             : 
     119             :     /** Const-version of accept(). @version 1.0 */
     120             :     EQFABRIC_INL VisitorResult accept(Visitor& visitor) const;
     121             : 
     122             :     EQFABRIC_INL virtual void backup();  //!< @internal
     123             :     EQFABRIC_INL virtual void restore(); //!< @internal
     124             : 
     125             :     void create(S** segment); //!< @internal
     126             :     void release(S* segment); //!< @internal
     127             :     //@}
     128             : 
     129             : protected:
     130             :     /** Construct a new Canvas. @internal */
     131             :     EQFABRIC_INL explicit Canvas(CFG* config);
     132             : 
     133             :     /** Destruct this canvas. @internal */
     134             :     EQFABRIC_INL virtual ~Canvas();
     135             : 
     136             :     /** @internal */
     137             :     EQFABRIC_INL virtual void attach(const uint128_t& id,
     138             :                                      const uint32_t instanceID);
     139             : 
     140             :     /** @sa Frustum::serialize. @internal */
     141             :     EQFABRIC_INL void serialize(co::DataOStream& os, const uint64_t dirtyBits);
     142             :     /** @sa Frustum::deserialize. @internal */
     143             :     EQFABRIC_INL virtual void deserialize(co::DataIStream& is,
     144             :                                           const uint64_t dirtyBits);
     145             : 
     146             :     EQFABRIC_INL virtual void notifyDetach(); //!< @internal
     147             : 
     148             :     /** @sa Serializable::setDirty() @internal */
     149             :     EQFABRIC_INL virtual void setDirty(const uint64_t bits);
     150             : 
     151             :     /** @internal */
     152           3 :     virtual void activateLayout(const uint32_t index)
     153             :     {
     154           3 :         _data.activeLayout = index;
     155           3 :     }
     156             : 
     157             : private:
     158             :     /** The parent config. */
     159             :     CFG* const _config;
     160             : 
     161             :     struct BackupData
     162             :     {
     163         842 :         BackupData()
     164         842 :             : activeLayout(0)
     165             :         {
     166         842 :         }
     167             : 
     168             :         /** The currently active layout on this canvas. */
     169             :         uint32_t activeLayout;
     170             :     } _data, _backup;
     171             : 
     172             :     /** Allowed layouts on this canvas. */
     173             :     Layouts _layouts;
     174             : 
     175             :     /** Child segments on this canvas. */
     176             :     Segments _segments;
     177             : 
     178             :     SwapBarrierPtr _swapBarrier; //!< default segment swap barrier
     179             : 
     180             :     struct Private;
     181             :     Private* _private; // placeholder for binary-compatible changes
     182             : 
     183             :     enum DirtyBits
     184             :     {
     185             :         DIRTY_LAYOUT = Object::DIRTY_CUSTOM << 0,
     186             :         DIRTY_SEGMENTS = Object::DIRTY_CUSTOM << 1,
     187             :         DIRTY_LAYOUTS = Object::DIRTY_CUSTOM << 2,
     188             :         DIRTY_FRUSTUM = Object::DIRTY_CUSTOM << 3,
     189             :         DIRTY_CANVAS_BITS = DIRTY_LAYOUT | DIRTY_SEGMENTS | DIRTY_LAYOUTS |
     190             :                             DIRTY_FRUSTUM | DIRTY_OBJECT_BITS
     191             :     };
     192             : 
     193             :     /** @internal @return the bits to be re-committed by the master. */
     194           2 :     virtual uint64_t getRedistributableBits() const
     195             :     {
     196           2 :         return DIRTY_CANVAS_BITS;
     197             :     }
     198             : 
     199             :     template <class, class, class>
     200             :     friend class Segment;
     201             :     friend class Object;
     202             :     void _addChild(S* segment);    //!< @internal
     203             :     bool _removeChild(S* segment); //!< @internal
     204             : 
     205             :     /** @internal */
     206             :     EQFABRIC_INL virtual uint128_t commit(const uint32_t incarnation);
     207             :     bool _mapViewObjects();
     208             : 
     209             :     typedef co::CommandFunc<Canvas<CFG, C, S, L>> CmdFunc;
     210             :     bool _cmdNewSegment(co::ICommand& command);
     211             :     bool _cmdNewSegmentReply(co::ICommand& command);
     212             : };
     213             : 
     214             : template <class CFG, class C, class S, class L>
     215             : std::ostream& operator<<(std::ostream&, const Canvas<CFG, C, S, L>&);
     216             : }
     217             : }
     218             : #endif // EQFABRIC_CANVAS_H

Generated by: LCOV version 1.11