2 * (c) 2010 Adam Lackorzynski <adam@os.inf.tu-dresden.de>,
3 * Alexander Warg <warg@os.inf.tu-dresden.de>
4 * economic rights: Technische Universität Dresden (Germany)
6 * This file is part of TUD:OS and distributed under the terms of the
7 * GNU General Public License 2.
8 * Please see the COPYING-GPL-2 file for details.
10 #include <l4/cxx/ipc_server>
11 #include <l4/re/util/object_registry>
13 #include <l4/re/protocols>
14 #include <l4/re/console>
15 #include <l4/re/util/cap_alloc>
16 #include <l4/re/error_helper>
18 #include <l4/re/dataspace>
19 #include <l4/re/mem_alloc>
20 #include <l4/re/util/meta>
26 #include "client_fb.h"
27 #include <l4/mag-gfx/canvas>
28 #include <l4/mag/server/user_state>
29 #include <l4/mag/server/factory>
32 #include <l4/sys/kdebug.h>
34 namespace Mag_server {
36 using L4Re::Util::Auto_cap;
38 void Service::start(Core_api *core)
41 if (!reg()->register_obj(cxx::Ref_ptr<Service>(this), "svc").is_valid())
42 printf("Service registration failed.\n");
44 printf("Plugin: Frame-buffer service started\n");
49 Service::create(char const *_msg, L4::Ipc_iostream &ios)
53 if (sscanf(_msg, "%dx%d", &w, &h) != 2)
56 if (w <= 0 || h <= 0 || h >= 10000 || w >= 10000)
61 if (char *a = strstr(_msg, "pos="))
64 px = strtol(a + 4, &endp, 0);
66 py = strtol(endp + 1, 0, 0);
71 if (px >= ust()->vstack()->canvas()->size().w())
72 px = ust()->vstack()->canvas()->size().w() - 10;
75 if (py >= ust()->vstack()->canvas()->size().h())
76 py = ust()->vstack()->canvas()->size().h() - 10;
79 Auto_cap<L4Re::Dataspace>::Cap ds(
80 L4Re::Util::cap_alloc.alloc<L4Re::Dataspace>());
82 Screen_factory *sf = dynamic_cast<Screen_factory*>(ust()->vstack()->canvas()->type()->factory);
84 L4Re::chksys(L4Re::Env::env()->mem_alloc()->alloc(sf->get_texture_size(res), ds.get()));
86 L4Re::Rm::Auto_region<void *> dsa;
87 L4Re::chksys(L4Re::Env::env()->rm()->attach(&dsa, ds->size(), L4Re::Rm::Search_addr, ds.get(), 0, L4_SUPERPAGESHIFT));
89 Texture *smpl = sf->create_texture(res, dsa.get());
91 cxx::Ref_ptr<Client_fb> x(new Client_fb(_core, Rect(Point(px, py), Area(res.w(), res.h() + 16)), Point(0, 0), smpl, ds.get()));
93 reg()->register_obj(x);
94 x->obj_cap()->dec_refcnt(1);
96 ust()->vstack()->push_top(x.ptr());
105 Service::dispatch(l4_umword_t, L4::Ipc_iostream &ios)
112 case L4::Meta::Protocol:
113 return L4Re::Util::handle_meta_request<L4::Factory>(ios);
114 case L4::Factory::Protocol:
115 if (L4::kobject_typeid<L4Re::Console>()->
116 has_proto(L4::Ipc::read<L4::Factory::Proto>(ios)))
121 if (!opt.is_of<char const *>())
125 int _l = sizeof(_msg) - 1;
127 _l = std::min(_l, opt.length());
128 strncpy(_msg, opt.value<char const *>(), _l);
131 return create(_msg, ios);
135 return -L4_EBADPROTO;
142 printf("MAG: destroying the fb_client_service, holla\n");
147 printf("MAG: destroy FB svc\n");
150 static Service _fb_service("frame-buffer");