]> rtime.felk.cvut.cz Git - l4.git/blob - l4/pkg/l4re/util/include/video/goos_svr
4ddd46d150e22687dbac9aba52041faec7122daf
[l4.git] / l4 / pkg / l4re / util / include / video / goos_svr
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
21 #pragma once
22
23 #include <l4/re/dataspace>
24 #include <l4/re/protocols>
25 #include <l4/re/video/goos>
26 #include <l4/re/video/goos-sys.h>
27
28 #include <l4/sys/capability>
29 #include <l4/cxx/ipc_server>
30
31
32 namespace L4Re { namespace Util { namespace Video {
33
34 /**
35  * \brief Goos server class.
36  * \ingroup api_l4re_util
37  */
38 class Goos_svr
39 {
40 protected:
41   /** Goos memory dataspace */
42   L4::Cap<L4Re::Dataspace> _fb_ds;
43   /** Goos information */
44   L4Re::Video::Goos::Info _screen_info;
45   /** View information */
46   L4Re::Video::View::Info _view_info;
47
48 public:
49   /**
50    * \brief Return framebuffer memory dataspace.
51    * \return Goos memory dataspace
52    */
53   L4::Cap<L4Re::Dataspace> get_fb() const { return _fb_ds; }
54
55   /**
56    * \brief Goos information structure.
57    * \return Return goos information structure.
58    */
59   L4Re::Video::Goos::Info const *screen_info() const { return &_screen_info; }
60
61   /**
62    * \brief View information structure.
63    * \return Return view information structure.
64    */
65   L4Re::Video::View::Info const *view_info() const { return &_view_info; }
66
67   /**
68    * \brief Refresh area of the framebuffer
69    *
70    * \param x X coordinate (pixels)
71    * \param y Y coordinate (pixels)
72    * \param w Width of area in pixels
73    * \param h Height of area in pixels
74    *
75    * \return 0 on success, negative error code otherwise
76    */
77   virtual int refresh(int x, int y, int w, int h)
78   { (void)x; (void)y; (void)w; (void)h; return -L4_ENOSYS; }
79
80   /**
81    * \brief Server dispatch function.
82    *
83    * \param obj Server object ID to work on
84    * \param ios Input/Output stream.
85    *
86    * \return error code.
87    */
88   int dispatch(l4_umword_t obj, L4::Ipc_iostream &ios);
89
90   /**
91    * \brief Initialize the view information structure of this object.
92    *
93    * This function initializes the view info structure of this goos object
94    * based on the information in the goos information, i.e. the width,
95    * height and pixel_info of the goos information has to contain valid
96    * values before calling init_info().
97    */
98   void init_infos()
99   {
100     using L4Re::Video::View;
101
102     _view_info.flags = View::F_none;
103
104     _view_info.view_index = 0;
105     _view_info.xpos = 0;
106     _view_info.ypos = 0;
107     _view_info.width = _screen_info.width;
108     _view_info.height = _screen_info.height;
109     _view_info.pixel_info = _screen_info.pixel_info;
110     _view_info.buffer_index = 0;
111   }
112
113   /**
114    * \brief Destructor.
115    */
116   virtual ~Goos_svr() {}
117 };
118
119 inline
120 int
121 Goos_svr::dispatch(l4_umword_t, L4::Ipc_iostream &ios)
122 {
123   l4_msgtag_t tag;
124   ios >> tag;
125
126   if (tag.label() != L4Re::Protocol::Goos)
127     return -L4_EBADPROTO;
128
129   L4::Opcode op;
130   ios >> op;
131   switch (op)
132     {
133     case L4Re::Video::Goos_::View_info:
134         {
135           unsigned idx;
136           ios >> idx;
137           if (idx != 0)
138             return -L4_ERANGE;
139         }
140       ios.put(_view_info);
141       return L4_EOK;
142     case L4Re::Video::Goos_::Info:
143       ios.put(_screen_info);
144       return L4_EOK;
145     case L4Re::Video::Goos_::Get_buffer:
146         {
147           unsigned idx;
148           ios >> idx;
149           if (idx != 0)
150             return -L4_ERANGE;
151         }
152       ios << L4::Ipc::Snd_fpage(_fb_ds, L4_CAP_FPAGE_RW);
153       return L4_EOK;
154     case L4Re::Video::Goos_::View_refresh:
155         {
156           unsigned idx;
157           int x,y,w,h;
158           ios >> idx >> x >> y >> w >> h;
159           if (idx != 0)
160             return -L4_ERANGE;
161
162           return refresh(x, y, w, h);
163         }
164     default:
165       return -L4_ENOSYS;
166     }
167 }
168
169 }}}