]> rtime.felk.cvut.cz Git - l4.git/blob - l4/pkg/l4re/include/video/view
f6d5c4ff9d8a60d663e26241c4c06e8c58a72d91
[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
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,
66   };
67
68   /**
69    * \brief Information structure of a view.
70    */
71   struct Info
72   {
73     unsigned flags;                 ///< Flags, see \a Flags
74     unsigned view_index;            ///< Index of the view
75
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
84
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); }
89
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; }
100
101     /** Dump information on the view information to a stream */
102     template< typename STREAM >
103     STREAM &dump(STREAM &s) const
104     {
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'
111         << "  ";
112       pixel_info.dump(s) << '\n';
113       return s;
114     }
115   };
116
117   /**
118    * \brief Return the view information of the view.
119    * \retval info   Information structure pointer.
120    * \return 0 on success, error otherwise
121    */
122   int info(Info *info) const throw();
123
124   /**
125    * \brief Set the information structure for this view.
126    * \param info  Information structure.
127    * \return 0 on success, error otherwise
128    *
129    * The function will also set the view port according to the values given
130    * in the information structure.
131    */
132   int set_info(Info const &info) const throw();
133
134   /**
135    * \brief Set the position of the view in the goos.
136    * \param scr_x      X position
137    * \param scr_y      Y position
138    * \param w          Width
139    * \param h          Height
140    * \param buf_offset Offset in the buffer in bytes
141    * \return 0 on success, error otherwise
142    */
143   int set_viewport(int scr_x, int scr_y, int w, int h, unsigned long buf_offset) const throw();
144
145   /**
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
151    */
152   int stack(View const &pivot, bool behind = true) const throw();
153
154   /** Make this view the top-most view */
155   int push_top() const throw()
156   { return stack(View(), false); }
157
158   /** Push this view the back */
159   int push_bottom() const throw()
160   { return stack(View(), true); }
161
162   /**
163    * \brief Refresh/Redraw the view.
164    * \param x  X position.
165    * \param y  Y position.
166    * \param w  Width.
167    * \param h  Height.
168    * \return 0 on success, error otherwise
169    */
170   int refresh(int x, int y, int w, int h) const throw();
171
172   /** \brief Return whether this view is valid */
173   bool valid() const { return _goos.is_valid(); }
174 };
175
176 }}
177