1 /**
2 * \file
3 * \brief Framebuffer utility functionality.
4 */
5 /*
6 * (c) 2009 Adam Lackorzynski <adam@os.inf.tu-dresden.de>
7 * economic rights: Technische Universität Dresden (Germany)
8 *
9 * This file is part of TUD:OS and distributed under the terms of the
10 * GNU General Public License 2.
11 * Please see the COPYING-GPL-2 file for details.
12 *
13 * As a special exception, you may use this file as part of a free software
14 * library without restriction. Specifically, if other files instantiate
15 * templates or use macros or inline functions from this file, or you compile
16 * this file and link it with other files to produce an executable, this
17 * file does not by itself cause the resulting executable to be covered by
18 * the GNU General Public License. This exception does not however
19 * invalidate any other reasons why the executable file might be covered by
20 * the GNU General Public License.
21 */
22
23 #include <l4/re/util/video/goos_fb>
24 #include <l4/re/c/util/video/goos_fb.h>
25 #include <l4/cxx/exceptions>
26 #include <cstddef>
27
28 using L4Re::Util::Video::Goos_fb;
29 using L4Re::Video::Goos;
30 using L4Re::Video::View;
31
gcast(l4re_util_video_goos_fb_t * goosfb)32 static inline Goos_fb *gcast(l4re_util_video_goos_fb_t *goosfb)
33 {
34 (void)sizeof(char[sizeof(goosfb->_obj_buf) - sizeof(Goos_fb)]);
35 return (Goos_fb *)goosfb->_obj_buf;
36 }
37
operator new(size_t,void * addr)38 inline void *operator new(size_t, void *addr)
39 { return addr; }
40
init_goosfb(l4re_util_video_goos_fb_t * goosfb)41 static inline void init_goosfb(l4re_util_video_goos_fb_t *goosfb)
42 {
43 new (goosfb->_obj_buf) Goos_fb();
44 }
45
46 L4_CV int
l4re_util_video_goos_fb_setup_name(l4re_util_video_goos_fb_t * goosfb,char const * name)47 l4re_util_video_goos_fb_setup_name(l4re_util_video_goos_fb_t *goosfb,
48 char const *name) L4_NOTHROW
49 {
50 static_assert( offsetof(View::Info, pixel_info)
51 == offsetof(l4re_video_view_info_t, pixel_info),
52 "Structure alignment mismatch");
53 static_assert( offsetof(View::Info, buffer_index)
54 == offsetof(l4re_video_view_info_t, buffer_index),
55 "Structure alignment mismatch");
56 static_assert( offsetof(Goos::Info, pixel_info)
57 == offsetof(l4re_video_goos_info_t, pixel_info),
58 "Structure alignment mismatch");
59 try
60 {
61 init_goosfb(goosfb);
62 gcast(goosfb)->setup(name);
63 }
64 catch (L4::Runtime_error &e) { return e.err_no(); }
65 catch (...) { return -L4_EINVAL; }
66 return 0;
67 }
68
69 L4_CV int
l4re_util_video_goos_fb_view_info(l4re_util_video_goos_fb_t * goosfb,l4re_video_view_info_t * info)70 l4re_util_video_goos_fb_view_info(l4re_util_video_goos_fb_t *goosfb,
71 l4re_video_view_info_t *info) L4_NOTHROW
72 {
73 return gcast(goosfb)->view_info((L4Re::Video::View::Info *)info);
74 }
75
76 L4_CV void
l4re_util_video_goos_fb_destroy(l4re_util_video_goos_fb_t * goosfb)77 l4re_util_video_goos_fb_destroy(l4re_util_video_goos_fb_t *goosfb) L4_NOTHROW
78 {
79 gcast(goosfb)->~Goos_fb();
80 }
81
82 L4_CV void *
l4re_util_video_goos_fb_attach_buffer(l4re_util_video_goos_fb_t * goosfb)83 l4re_util_video_goos_fb_attach_buffer(l4re_util_video_goos_fb_t *goosfb) L4_NOTHROW
84 {
85 try
86 {
87 return gcast(goosfb)->attach_buffer();
88 }
89 catch (...)
90 {
91 return 0;
92 }
93 }
94
95 L4_CV int
l4re_util_video_goos_fb_refresh(l4re_util_video_goos_fb_t * goosfb,int x,int y,int w,int h)96 l4re_util_video_goos_fb_refresh(l4re_util_video_goos_fb_t *goosfb,
97 int x, int y, int w, int h) L4_NOTHROW
98 {
99 return gcast(goosfb)->refresh(x, y, w, h);
100 }
101
102 L4_CV l4re_ds_t
l4re_util_video_goos_fb_buffer(l4re_util_video_goos_fb_t * goosfb)103 l4re_util_video_goos_fb_buffer(l4re_util_video_goos_fb_t *goosfb) L4_NOTHROW
104 {
105 return gcast(goosfb)->buffer().cap();
106 }
107
108 L4_CV l4_cap_idx_t
l4re_util_video_goos_fb_goos(l4re_util_video_goos_fb_t * goosfb)109 l4re_util_video_goos_fb_goos(l4re_util_video_goos_fb_t *goosfb) L4_NOTHROW
110 {
111 return gcast(goosfb)->goos().cap();
112 }
113