]> rtime.felk.cvut.cz Git - l4.git/blob - l4/pkg/mag/plugins/client_fb/client_fb.h
Some minor fixes.
[l4.git] / l4 / pkg / mag / plugins / client_fb / client_fb.h
1 /*
2  * (c) 2010 Alexander Warg <warg@os.inf.tu-dresden.de>
3  *     economic rights: Technische Universität Dresden (Germany)
4  *
5  * This file is part of TUD:OS and distributed under the terms of the
6  * GNU General Public License 2.
7  * Please see the COPYING-GPL-2 file for details.
8  */
9 #include <l4/mag-gfx/canvas>
10
11 #include <l4/mag/server/view>
12 #include <l4/mag/server/session>
13
14 #include <l4/re/console>
15 #include <l4/re/util/video/goos_svr>
16 #include <l4/re/util/event_svr>
17 #include <l4/sys/cxx/ipc_epiface>
18 #include <l4/re/util/cap_alloc>
19 #include <l4/re/rm>
20 #include <l4/re/util/icu_svr>
21 #include <l4/mag/server/plugin>
22
23 namespace Mag_server {
24
25 class Client_fb
26 : public View, public Session,
27   public L4::Epiface_t<Client_fb, L4Re::Console, Object>,
28   public L4Re::Util::Video::Goos_svr,
29   public L4Re::Util::Icu_cap_array_svr<Client_fb>
30 {
31 private:
32   typedef L4Re::Util::Icu_cap_array_svr<Client_fb> Icu_svr;
33   Core_api const *_core;
34   Texture *_fb;
35   int _bar_height;
36
37   L4Re::Util::Auto_cap<L4Re::Dataspace>::Cap _ev_ds;
38   L4Re::Rm::Auto_region<void*> _ev_ds_m;
39   L4Re::Event_buffer _events;
40   Irq _ev_irq;
41
42   enum
43   {
44     F_fb_fixed_location = 1 << 0,
45     F_fb_shaded         = 1 << 1,
46     F_fb_focus          = 1 << 2,
47   };
48   unsigned _flags;
49
50 public:
51   int setup();
52   void view_setup();
53
54   explicit Client_fb(Core_api const *core);
55
56   void toggle_shaded();
57
58   void draw(Canvas *, View_stack const *, Mode) const;
59   void handle_event(Hid_report *e, Point const &mouse, bool core_dev);
60   bool handle_core_event(Hid_report *e, Point const &mouse);
61
62   int get_stream_info_for_id(l4_umword_t id, L4Re::Event_stream_info *info);
63   int get_abs_info(l4_umword_t id, unsigned naxes, unsigned const *axes,
64                    L4Re::Event_absinfo *infos);
65
66   using L4Re::Util::Video::Goos_svr::op_info;
67   using Icu_svr::op_info;
68   int refresh(int x, int y, int w, int h);
69
70   Area visible_size() const;
71
72   void destroy();
73
74   Session *session() const { return const_cast<Client_fb*>(this); }
75
76   static void set_geometry_prop(Session *s, Property_handler const *p, cxx::String const &v);
77   static void set_flags_prop(Session *s, Property_handler const *p, cxx::String const &v);
78   static void set_bar_height_prop(Session *s, Property_handler const *p, cxx::String const &v);
79
80   void put_event(l4_umword_t stream, int type, int code, int value,
81                  l4_uint64_t time);
82
83   long op_get_buffer(L4Re::Event::Rights, L4::Ipc::Cap<L4Re::Dataspace> &ds)
84   {
85     _events.reset();
86     ds = L4::Ipc::Cap<L4Re::Dataspace>(_ev_ds.get(), L4_CAP_FPAGE_RW);
87     return L4_EOK;
88   }
89
90   long op_get_num_streams(L4Re::Event::Rights)
91   { return -L4_ENOSYS; }
92
93   long op_get_stream_info(L4Re::Event::Rights, int, L4Re::Event_stream_info &)
94   { return -L4_ENOSYS; }
95
96   long op_get_stream_info_for_id(L4Re::Event::Rights, l4_umword_t id,
97                                  L4Re::Event_stream_info &info)
98   { return get_stream_info_for_id(id, &info); }
99
100   long op_get_axis_info(L4Re::Event::Rights, l4_umword_t id,
101                         L4::Ipc::Array_in_buf<unsigned, unsigned long> const &axes,
102                         L4::Ipc::Array_ref<L4Re::Event_absinfo, unsigned long> &info)
103   {
104     unsigned naxes = cxx::min<unsigned>(L4RE_ABS_MAX, axes.length);
105
106     info.length = 0;
107
108     L4Re::Event_absinfo _info[naxes];
109     int r = get_abs_info(id, naxes, axes.data, _info);
110     if (r < 0)
111       return r;
112
113     for (unsigned i = 0; i < naxes; ++i)
114       info.data[i] = _info[i];
115
116     info.length = naxes;
117     return r;
118   }
119
120   long op_get_stream_state_for_id(L4Re::Event::Rights, l4_umword_t,
121                                   L4Re::Event_stream_state &)
122   { return -L4_ENOSYS; }
123 };
124
125 }