]> rtime.felk.cvut.cz Git - l4.git/blob - l4/pkg/l4re/util/include/video/goos_svr
Inital import
[l4.git] / l4 / pkg / l4re / util / include / video / goos_svr
1 // vi:ft=cpp
2 /*
3  * (c) 2008-2009 Technische Universität Dresden
4  * This file is part of TUD:OS and distributed under the terms of the
5  * GNU General Public License 2.
6  * Please see the COPYING-GPL-2 file for details.
7  *
8  * As a special exception, you may use this file as part of a free software
9  * library without restriction.  Specifically, if other files instantiate
10  * templates or use macros or inline functions from this file, or you compile
11  * this file and link it with other files to produce an executable, this
12  * file does not by itself cause the resulting executable to be covered by
13  * the GNU General Public License.  This exception does not however
14  * invalidate any other reasons why the executable file might be covered by
15  * the GNU General Public License.
16  */
17
18 #pragma once
19
20 #include <l4/re/dataspace>
21 #include <l4/re/protocols>
22 #include <l4/re/video/goos>
23 #include <l4/re/video/goos-sys.h>
24
25 #include <l4/sys/capability>
26 #include <l4/cxx/ipc_server>
27
28
29 namespace L4Re { namespace Util { namespace Video {
30
31 /**
32  * \brief Goos server class.
33  * \ingroup api_l4re_util
34  */
35 class Goos_svr
36 {
37 protected:
38   /** Goos memory dataspace */
39   L4::Cap<L4Re::Dataspace> _fb_ds;
40   /** Goos information */
41   L4Re::Video::Goos::Info _screen_info;
42   /** View information */
43   L4Re::Video::View::Info _view_info;
44
45 public:
46   /**
47    * \brief Return framebuffer memory dataspace.
48    * \return Goos memory dataspace
49    */
50   L4::Cap<L4Re::Dataspace> get_fb() const { return _fb_ds; }
51
52   /**
53    * \brief Goos information structure.
54    * \return Return goos information structure.
55    */
56   L4Re::Video::Goos::Info const *screen_info() const { return &_screen_info; }
57
58   /**
59    * \brief View information structure.
60    * \return Return view information structure.
61    */
62   L4Re::Video::View::Info const *view_info() const { return &_view_info; }
63
64   /**
65    * \brief Refresh area of the framebuffer
66    *
67    * \param x X coordinate (pixels)
68    * \param y Y coordinate (pixels)
69    * \param w Width of area in pixels
70    * \param h Height of area in pixels
71    *
72    * \return 0 on success, negative error code otherwise
73    */
74   virtual int refresh(int x, int y, int w, int h)
75   { (void)x; (void)y; (void)w; (void)h; return -L4_ENOSYS; }
76
77   /**
78    * \brief Server dispatch function.
79    *
80    * \param obj Server object ID to work on
81    * \param ios Input/Output stream.
82    *
83    * \return error code.
84    */
85   int dispatch(l4_umword_t obj, L4::Ipc_iostream &ios);
86
87   /**
88    * \brief Initialize the view information structure of this object.
89    *
90    * This function initializes the view info structure of this goos object
91    * based on the information in the goos information, i.e. the width,
92    * height and pixel_info of the goos information has to contain valid
93    * values before calling init_info().
94    */
95   void init_infos()
96   {
97     using L4Re::Video::View;
98
99     _view_info.flags = View::F_none;
100
101     _view_info.view_index = 0;
102     _view_info.xpos = 0;
103     _view_info.ypos = 0;
104     _view_info.width = _screen_info.width;
105     _view_info.height = _screen_info.height;
106     _view_info.pixel_info = _screen_info.pixel_info;
107     _view_info.buffer_index = 0;
108   }
109
110   /**
111    * \brief Destructor.
112    */
113   virtual ~Goos_svr() {}
114 };
115
116 inline
117 int
118 Goos_svr::dispatch(l4_umword_t, L4::Ipc_iostream &ios)
119 {
120   l4_msgtag_t tag;
121   ios >> tag;
122
123   if (tag.label() != L4Re::Protocol::Goos)
124     return -L4_EBADPROTO;
125
126   L4::Opcode op;
127   ios >> op;
128   switch (op)
129     {
130     case L4Re::Video::Goos_::View_info:
131         {
132           unsigned idx;
133           ios >> idx;
134           if (idx != 0)
135             return -L4_ERANGE;
136         }
137       ios.put(_view_info);
138       return L4_EOK;
139     case L4Re::Video::Goos_::Info:
140       ios.put(_screen_info);
141       return L4_EOK;
142     case L4Re::Video::Goos_::Get_buffer:
143         {
144           unsigned idx;
145           ios >> idx;
146           if (idx != 0)
147             return -L4_ERANGE;
148         }
149       ios << L4::Ipc::Snd_fpage(_fb_ds, L4_CAP_FPAGE_RW);
150       return L4_EOK;
151     case L4Re::Video::Goos_::View_refresh:
152         {
153           unsigned idx;
154           int x,y,w,h;
155           ios >> idx >> x >> y >> w >> h;
156           if (idx != 0)
157             return -L4_ERANGE;
158
159           return refresh(x, y, w, h);
160         }
161     default:
162       return -L4_ENOSYS;
163     }
164 }
165
166 }}}