Line data Source code
1 :
2 : /* Copyright (c) 2009-2016, Stefan Eilemann <eile@equalizergraphics.com>
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_LAYOUT_H
19 : #define EQFABRIC_LAYOUT_H
20 :
21 : #include <eq/fabric/object.h> // base class
22 : #include <eq/fabric/pixelViewport.h> // member
23 : #include <eq/fabric/types.h>
24 : #include <string>
25 :
26 : namespace eq
27 : {
28 : namespace fabric
29 : {
30 : /** Base data transport class for layouts. @sa eq::Layout */
31 : // cppcheck-suppress noConstructor
32 : template <class C, class L, class V>
33 : class Layout : public Object
34 : {
35 : public:
36 : /** @name Data Access */
37 : //@{
38 : /** A vector of pointers to views. @version 1.0 */
39 : typedef std::vector<V*> Views;
40 : /** The layout visitor type. @version 1.0 */
41 : typedef ElementVisitor<L, LeafVisitor<V>> Visitor;
42 :
43 : /** @return the current config. @version 1.0 */
44 2606 : C* getConfig() { return _config; }
45 : /** @return the current config. @version 1.0 */
46 371 : const C* getConfig() const { return _config; }
47 : /** Get the list of views. @version 1.0 */
48 19914 : const Views& getViews() const { return _views; }
49 : /**
50 : * @return true if the layout is activated in at least one canvas.
51 : * @version 1.1.5
52 : */
53 : EQFABRIC_INL bool isActive() const;
54 :
55 : /** @internal @return the view of the given path. */
56 : V* getView(const ViewPath& path);
57 :
58 : /** @internal @return the first view of the given name. */
59 : V* findView(const std::string& name);
60 :
61 : /** @internal @return the index path to this layout. */
62 : LayoutPath getPath() const;
63 : //@}
64 :
65 : /** @name Operations */
66 : //@{
67 : /**
68 : * Traverse this layout and all children using a layout visitor.
69 : *
70 : * @param visitor the visitor.
71 : * @return the result of the visitor traversal.
72 : * @version 1.0
73 : */
74 : EQFABRIC_INL VisitorResult accept(Visitor& visitor);
75 :
76 : /** Const-version of accept(). @version 1.0 */
77 : EQFABRIC_INL VisitorResult accept(Visitor& visitor) const;
78 :
79 : /**
80 : * Resize the underlying channels to form a layout of the given size.
81 : *
82 : * Resizes the virtual canvas so that the union of output channels covers
83 : * the given pixel viewport. Relative or absolute addressing of the
84 : * channel's viewport or pixel viewport is retained. Windows are resized as
85 : * necessary, so that the channel has the correct size (for channels with
86 : * relative viewports) or the channel fits into the window (for channels
87 : * with absolute pixel viewports).
88 : *
89 : * @param pvp the full layout size in pixels.
90 : * @version 2.1
91 : */
92 : EQFABRIC_INL void setPixelViewport(const PixelViewport& pvp);
93 :
94 : /** @return the last set pixel viewport. @version 2.1 */
95 : EQFABRIC_INL const PixelViewport& getPixelViewport() const;
96 :
97 : void create(V** view); //!< @internal
98 : void release(V* view); //!< @internal
99 : //@}
100 :
101 : protected:
102 : /** @internal Construct a new layout. */
103 : EQFABRIC_INL explicit Layout(C* config);
104 :
105 : /** @internal Destruct this layout. */
106 : EQFABRIC_INL virtual ~Layout();
107 :
108 : /** @internal */
109 : EQFABRIC_INL virtual void attach(const uint128_t& id,
110 : const uint32_t instanceID);
111 :
112 : /** @internal */
113 : EQFABRIC_INL virtual void serialize(co::DataOStream& os,
114 : const uint64_t dirtyBits);
115 : /** @internal */
116 : EQFABRIC_INL virtual void deserialize(co::DataIStream& is,
117 : const uint64_t dirtyBits);
118 :
119 : EQFABRIC_INL virtual void notifyDetach(); //!< @internal
120 7 : virtual void notifyViewportChanged() {} //!< @internal
121 : /** @internal */
122 : EQFABRIC_INL virtual void setDirty(const uint64_t bits);
123 :
124 : /** @internal */
125 : enum DirtyBits
126 : {
127 : DIRTY_VIEWS = Object::DIRTY_CUSTOM << 0,
128 : DIRTY_VIEWPORT = Object::DIRTY_CUSTOM << 1,
129 : DIRTY_LAYOUT_BITS = DIRTY_VIEWS | DIRTY_VIEWPORT | DIRTY_OBJECT_BITS
130 : };
131 :
132 : /** @internal @return the bits to be re-committed by the master. */
133 16 : virtual uint64_t getRedistributableBits() const
134 : {
135 16 : return DIRTY_LAYOUT_BITS;
136 : }
137 :
138 : private:
139 : /** The parent Config. */
140 : C* const _config;
141 :
142 : /** Child views on this layout. */
143 : Views _views;
144 :
145 : PixelViewport _pvp; //!< application-provided pixel viewport
146 :
147 : template <class, class, class>
148 : friend class View;
149 : friend class Object;
150 : void _addChild(V* view);
151 : bool _removeChild(V* view);
152 :
153 : /** @internal */
154 : EQFABRIC_INL virtual uint128_t commit(const uint32_t incarnation);
155 :
156 : template <class O>
157 : void _removeObserver(const O* observer);
158 : template <class, class, class, class, class, class, class>
159 : friend class Config;
160 :
161 : typedef co::CommandFunc<Layout<C, L, V>> CmdFunc;
162 : bool _cmdNewView(co::ICommand& command);
163 : bool _cmdNewViewReply(co::ICommand& command);
164 : };
165 :
166 : template <class C, class L, class V>
167 : std::ostream& operator<<(std::ostream&, const Layout<C, L, V>&);
168 : }
169 : }
170 : #endif // EQFABRIC_LAYOUT_H
|