3 * (c) 2008-2009 Adam Lackorzynski <adam@os.inf.tu-dresden.de>,
4 * Alexander Warg <warg@os.inf.tu-dresden.de>
5 * economic rights: Technische Universität Dresden (Germany)
7 * This file is part of TUD:OS and distributed under the terms of the
8 * GNU General Public License 2.
9 * Please see the COPYING-GPL-2 file for details.
11 * As a special exception, you may use this file as part of a free software
12 * library without restriction. Specifically, if other files instantiate
13 * templates or use macros or inline functions from this file, or you compile
14 * this file and link it with other files to produce an executable, this
15 * file does not by itself cause the resulting executable to be covered by
16 * the GNU General Public License. This exception does not however
17 * invalidate any other reasons why the executable file might be covered by
18 * the GNU General Public License.
22 #include <l4/sys/capability>
23 #include <l4/re/dataspace>
24 #include <l4/re/video/colors>
26 namespace L4Re { namespace Video {
32 * \ingroup api_l4re_goos
42 View(l4_cap_idx_t goos, unsigned idx) : _goos(goos), _view_idx(idx) {}
44 unsigned view_index() const throw()
45 { return _goos.is_valid() ? _view_idx : ~0U; }
48 View() : _goos(L4::Cap<Goos>::Invalid) {}
51 * \brief Flags on a view.
55 F_none = 0x00, ///< everything for this view is static (the VESA-FB case)
56 F_set_buffer = 0x01, ///< buffer object for this view can be changed
57 F_set_buffer_offset = 0x02, ///< buffer offset can be set
58 F_set_bytes_per_line = 0x04, ///< bytes per line can be set
59 F_set_pixel = 0x08, ///< pixel type can be set
60 F_set_position = 0x10, ///< position on screen can be set
61 F_dyn_allocated = 0x20, ///< View is dynamically allocated
63 /** Flags for a fully dynamic view */
64 F_fully_dynamic = F_set_buffer | F_set_buffer_offset | F_set_bytes_per_line
65 | F_set_pixel | F_set_position | F_dyn_allocated,
69 * \brief Information structure of a view.
73 unsigned flags; ///< Flags, see \a Flags
74 unsigned view_index; ///< Index of the view
76 unsigned long xpos; ///< X position in pixels of the view in the goos
77 unsigned long ypos; ///< Y position in pixels of the view in the goos
78 unsigned long width; ///< Width of the view in pixels
79 unsigned long height; ///< Height of the view in pixels
80 unsigned long buffer_offset; ///< Offset in the memory buffer in bytes
81 unsigned long bytes_per_line; ///< Bytes per line
82 Pixel_info pixel_info; ///< Pixel information
83 unsigned buffer_index; ///< Number of the buffer used for this view
85 /** Return whether the view has a static buffer */
86 bool has_static_buffer() const { return !(flags & F_set_buffer); }
87 /** Return whether the static buffer offset is available */
88 bool has_static_buffer_offset() const { return !(flags & F_set_buffer_offset); }
90 /** Return whether a buffer is set */
91 bool has_set_buffer() const { return flags & F_set_buffer; }
92 /** Return whether the given buffer offset is valid */
93 bool has_set_buffer_offset() const { return flags & F_set_buffer_offset; }
94 /** Return whether the given bytes-per-line value is valid */
95 bool has_set_bytes_per_line() const { return flags & F_set_bytes_per_line; }
96 /** Return whether the given pixel information is valid */
97 bool has_set_pixel() const { return flags & F_set_pixel; }
98 /** Return whether the position information given is valid */
99 bool has_set_position() const { return flags & F_set_position; }
101 /** Dump information on the view information to a stream */
102 template< typename STREAM >
103 STREAM &dump(STREAM &s) const
105 s << "View::Info:" << '\n'
106 << " flags: " << flags << '\n'
107 << " size: " << (int)width << 'x' << (int)height
108 << " pos: " << (int)xpos << ", " << (int)ypos << '\n'
109 << " bytes_per_line: " << bytes_per_line << '\n'
110 << " buffer_offset: " << buffer_offset << '\n'
112 pixel_info.dump(s) << '\n';
118 * \brief Return the view information of the view.
119 * \retval info Information structure pointer.
120 * \return 0 on success, error otherwise
122 int info(Info *info) const throw();
125 * \brief Set the information structure for this view.
126 * \param info Information structure.
127 * \return 0 on success, error otherwise
129 * The function will also set the view port according to the values given
130 * in the information structure.
132 int set_info(Info const &info) const throw();
135 * \brief Set the position of the view in the goos.
136 * \param scr_x X position
137 * \param scr_y Y position
140 * \param buf_offset Offset in the buffer in bytes
141 * \return 0 on success, error otherwise
143 int set_viewport(int scr_x, int scr_y, int w, int h, unsigned long buf_offset) const throw();
146 * \brief Move this view in the view stack.
147 * \param pivot View to move relative to
148 * \param behind When true move the view behind the pivit view, if false
149 * move the view before the pivot view.
150 * \return 0 on success, error otherwise
152 int stack(View const &pivot, bool behind = true) const throw();
154 /** Make this view the top-most view */
155 int push_top() const throw()
156 { return stack(View(), false); }
158 /** Push this view the back */
159 int push_bottom() const throw()
160 { return stack(View(), true); }
163 * \brief Refresh/Redraw the view.
164 * \param x X position.
165 * \param y Y position.
168 * \return 0 on success, error otherwise
170 int refresh(int x, int y, int w, int h) const throw();
172 /** \brief Return whether this view is valid */
173 bool valid() const { return _goos.is_valid(); }