]> rtime.felk.cvut.cz Git - l4.git/blob - l4/pkg/l4re/include/video/view
update
[l4.git] / l4 / pkg / l4re / include / video / view
1 // vi:ft=cpp:
2 /*
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)
6  *
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.
10  *
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.
19  */
20 #pragma once
21
22 #include <l4/sys/capability>
23 #include <l4/re/dataspace>
24 #include <l4/re/video/colors>
25
26 namespace L4Re { namespace Video {
27
28 class Goos;
29
30 /**
31  * \brief View.
32  * \ingroup api_l4re_goos
33  */
34 class L4_EXPORT View
35 {
36 private:
37   friend class Goos;
38
39   L4::Cap<Goos> _goos;
40   unsigned _view_idx;
41
42   View(l4_cap_idx_t goos, unsigned idx) : _goos(goos), _view_idx(idx) {}
43
44   unsigned view_index() const throw()
45   { return _goos.is_valid() ? _view_idx : ~0U; }
46
47 public:
48   View() : _goos(L4::Cap<Goos>::Invalid) {}
49
50   /**
51    * \brief Flags on a view.
52    */
53   enum Flags
54   {
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
62     F_set_background     = 0x40, ///< Set view as background for session
63     F_set_flags          = 0x80, ///< Set view flags (\see V_flags)
64
65     /** Flags for a fully dynamic view */
66     F_fully_dynamic      =   F_set_buffer | F_set_buffer_offset | F_set_bytes_per_line
67                            | F_set_pixel | F_set_position | F_dyn_allocated,
68   };
69
70   /**
71    * \brief Property flags of a view.
72    *
73    * Such flags can be set or deleted with the #F_set_flags operation using
74    * the set_info() method.
75    */
76   enum V_flags
77   {
78     F_above              = 0x1000,  ///< Flag the view as stay on top
79     F_flags_mask         = 0xff000, ///< Mask containing all possible property flags
80   };
81
82   /**
83    * \brief Information structure of a view.
84    */
85   struct Info
86   {
87     unsigned flags;                 ///< Flags, \see \a Flags and \a V_flags
88     unsigned view_index;            ///< Index of the view
89
90     unsigned long xpos;             ///< X position in pixels of the view in the goos
91     unsigned long ypos;             ///< Y position in pixels of the view in the goos
92     unsigned long width;            ///< Width of the view in pixels
93     unsigned long height;           ///< Height of the view in pixels
94     unsigned long buffer_offset;    ///< Offset in the memory buffer in bytes
95     unsigned long bytes_per_line;   ///< Bytes per line
96     Pixel_info pixel_info;          ///< Pixel information
97     unsigned buffer_index;          ///< Number of the buffer used for this view
98
99     /** Return whether the view has a static buffer */
100     bool has_static_buffer() const { return !(flags & F_set_buffer); }
101     /** Return whether the static buffer offset is available */
102     bool has_static_buffer_offset() const { return !(flags & F_set_buffer_offset); }
103
104     /** Return whether a buffer is set */
105     bool has_set_buffer() const { return flags & F_set_buffer; }
106     /** Return whether the given buffer offset is valid */
107     bool has_set_buffer_offset() const { return flags & F_set_buffer_offset; }
108     /** Return whether the given bytes-per-line value is valid */
109     bool has_set_bytes_per_line() const { return flags & F_set_bytes_per_line; }
110     /** Return whether the given pixel information is valid */
111     bool has_set_pixel() const { return flags & F_set_pixel; }
112     /** Return whether the position information given is valid */
113     bool has_set_position() const { return flags & F_set_position; }
114
115     /** Dump information on the view information to a stream */
116     template< typename STREAM >
117     STREAM &dump(STREAM &s) const
118     {
119       s << "View::Info:" << '\n'
120         << "  flags: " << flags << '\n'
121         << "  size:  " << (int)width << 'x' << (int)height
122         << "  pos: " << (int)xpos << ", " << (int)ypos << '\n'
123         << "  bytes_per_line: " << bytes_per_line << '\n'
124         << "  buffer_offset:  " << buffer_offset << '\n'
125         << "  ";
126       pixel_info.dump(s) << '\n';
127       return s;
128     }
129   };
130
131   /**
132    * \brief Return the view information of the view.
133    * \retval info   Information structure pointer.
134    * \return 0 on success, error otherwise
135    */
136   int info(Info *info) const throw();
137
138   /**
139    * \brief Set the information structure for this view.
140    * \param info  Information structure.
141    * \return 0 on success, error otherwise
142    *
143    * The function will also set the view port according to the values given
144    * in the information structure.
145    */
146   int set_info(Info const &info) const throw();
147
148   /**
149    * \brief Set the position of the view in the goos.
150    * \param scr_x      X position
151    * \param scr_y      Y position
152    * \param w          Width
153    * \param h          Height
154    * \param buf_offset Offset in the buffer in bytes
155    * \return 0 on success, error otherwise
156    */
157   int set_viewport(int scr_x, int scr_y, int w, int h, unsigned long buf_offset) const throw();
158
159   /**
160    * \brief Move this view in the view stack.
161    * \param pivot   View to move relative to
162    * \param behind  When true move the view behind the pivit view, if false
163    *                move the view before the pivot view.
164    * \return 0 on success, error otherwise
165    */
166   int stack(View const &pivot, bool behind = true) const throw();
167
168   /** Make this view the top-most view */
169   int push_top() const throw()
170   { return stack(View(), true); }
171
172   /** Push this view the back */
173   int push_bottom() const throw()
174   { return stack(View(), false); }
175
176   /**
177    * \brief Refresh/Redraw the view.
178    * \param x  X position.
179    * \param y  Y position.
180    * \param w  Width.
181    * \param h  Height.
182    * \return 0 on success, error otherwise
183    */
184   int refresh(int x, int y, int w, int h) const throw();
185
186   /** \brief Return whether this view is valid */
187   bool valid() const { return _goos.is_valid(); }
188 };
189
190 }}
191