L4Re - L4 Runtime Environment
goos
1 // vi:set ft=cpp: -*- Mode: C++ -*-
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 #pragma once
21 
22 #include <l4/sys/capability>
23 #include <l4/re/dataspace>
24 #include <l4/re/video/colors>
25 #include <l4/sys/cxx/ipc_iface>
26 
27 namespace L4Re { namespace Video {
28 
29 class L4_EXPORT Goos;
30 
34 class L4_EXPORT View
35 {
36 private:
37  friend class Goos;
38 
39  L4::Cap<Goos> _goos;
40  unsigned _view_idx;
41 
42  View(l4_cap_idx_t goos, unsigned idx)
43  : _goos(goos), _view_idx(_goos.is_valid() ? idx : ~0U) {}
44 
45  unsigned view_index() const noexcept
46  { return _goos.is_valid() ? _view_idx : ~0U; }
47 
48 public:
49  View() : _goos(L4::Cap<Goos>::Invalid), _view_idx(~0U) {}
50 
54  enum Flags
55  {
56  F_none = 0x00,
57  F_set_buffer = 0x01,
58  F_set_buffer_offset = 0x02,
59  F_set_bytes_per_line = 0x04,
60  F_set_pixel = 0x08,
61  F_set_position = 0x10,
62  F_dyn_allocated = 0x20,
63  F_set_background = 0x40,
64  F_set_flags = 0x80,
65 
67  F_fully_dynamic = F_set_buffer | F_set_buffer_offset | F_set_bytes_per_line
68  | F_set_pixel | F_set_position | F_dyn_allocated,
69  };
70 
77  enum V_flags
78  {
79  F_above = 0x1000,
80  F_flags_mask = 0xff000,
81  };
82 
86  struct Info
87  {
88  unsigned flags;
89  unsigned view_index;
90 
91  unsigned long xpos;
92  unsigned long ypos;
93  unsigned long width;
94  unsigned long height;
95  unsigned long buffer_offset;
96  unsigned long bytes_per_line;
98  unsigned buffer_index;
99 
101  bool has_static_buffer() const { return !(flags & F_set_buffer); }
103  bool has_static_buffer_offset() const { return !(flags & F_set_buffer_offset); }
104 
106  bool has_set_buffer() const { return flags & F_set_buffer; }
108  bool has_set_buffer_offset() const { return flags & F_set_buffer_offset; }
110  bool has_set_bytes_per_line() const { return flags & F_set_bytes_per_line; }
112  bool has_set_pixel() const { return flags & F_set_pixel; }
114  bool has_set_position() const { return flags & F_set_position; }
115 
117  template< typename OUT >
118  void dump(OUT &s) const
119  {
120  s.printf("View::Info:\n"
121  " flags: %x\n"
122  " size: %ldx%ld\n"
123  " pos: %ldx%ld\n"
124  " bytes_per_line: %ld\n"
125  " buffer_offset: %lx\n"
126  " ",
127  flags, width, height, xpos, ypos,
128  bytes_per_line, buffer_offset);
129  pixel_info.dump(s);
130  s.printf("\n");
131  }
132  };
133 
141  int info(Info *info) const noexcept;
142 
153  int set_info(Info const &info) const noexcept;
154 
166  int set_viewport(int scr_x, int scr_y, int w, int h, unsigned long buf_offset) const noexcept;
167 
177  int stack(View const &pivot, bool behind = true) const noexcept;
178 
180  int push_top() const noexcept
181  { return stack(View(), true); }
182 
184  int push_bottom() const noexcept
185  { return stack(View(), false); }
186 
197  int refresh(int x, int y, int w, int h) const noexcept;
198 
200  bool valid() const { return _goos.is_valid(); }
201 };
202 
203 
207 class L4_EXPORT Goos :
208  public L4::Kobject_t<Goos, L4::Kobject, L4RE_PROTO_GOOS>
209 {
210 public:
212  enum Flags
213  {
214  F_auto_refresh = 0x01,
215  F_pointer = 0x02,
216  F_dynamic_views = 0x04,
217  F_dynamic_buffers = 0x08,
218  };
219 
221  struct Info
222  {
223  unsigned long width;
224  unsigned long height;
225  unsigned flags;
226  unsigned num_static_views;
229 
232  bool auto_refresh() const { return flags & F_auto_refresh; }
234  bool has_pointer() const { return flags & F_pointer; }
236  bool has_dynamic_views() const { return flags & F_dynamic_views; }
238  bool has_dynamic_buffers() const { return flags & F_dynamic_buffers; }
239 
240  Info()
241  : width(0), height(0), flags(0), num_static_views(0),
242  num_static_buffers(0) {}
243  };
244 
252  L4_INLINE_RPC(long, info, (Info *info));
253 
262  L4_RPC(long, get_static_buffer, (unsigned idx,
264 
273  L4_RPC(long, create_buffer, (unsigned long size,
275 
283  L4_INLINE_RPC(long, delete_buffer, (unsigned idx));
284 
285  // Use a wrapper for this RPC as we enacapsulate the View
286  L4_INLINE_RPC_NF(long, create_view, ());
287 
296  int create_view(View *view, l4_utcb_t *utcb = l4_utcb()) const noexcept
297  {
298  long r = create_view_t::call(c(), utcb);
299  if (r < 0)
300  return r;
301  *view = View(cap(), r);
302  return r;
303  }
304 
305  // Use a wrapper as Views are encapsulated
306  L4_INLINE_RPC_NF(long, delete_view, (unsigned index));
307 
316  int delete_view(View const &v, l4_utcb_t *utcb = l4_utcb()) const noexcept
317  {
318  return delete_view_t::call(c(), v._view_idx, utcb);
319  }
320 
326  View view(unsigned index) const noexcept;
327 
331  L4_INLINE_RPC(long, refresh, (int x, int y, int w, int h));
332 
333  // those are used by the View
334  L4_INLINE_RPC(long, view_info, (unsigned index, View::Info *info));
335  L4_INLINE_RPC(long, set_view_info, (unsigned index, View::Info const &info));
336  L4_INLINE_RPC(long, view_stack, (unsigned index, unsigned pivit, bool behind));
337  L4_INLINE_RPC(long, view_refresh, (unsigned index, int x, int y, int w, int h));
338 
339  typedef L4::Typeid::Rpcs<
340  info_t, get_static_buffer_t, create_buffer_t, create_view_t, delete_buffer_t,
341  delete_view_t, view_info_t, set_view_info_t, view_stack_t, view_refresh_t,
342  refresh_t
343  > Rpcs;
344 };
345 
346 inline View
347 Goos::view(unsigned index) const noexcept
348 { return View(cap(), index); }
349 
350 inline int
351 View::info(Info *info) const noexcept
352 { return _goos->view_info(_view_idx, info); }
353 
354 inline int
355 View::set_info(Info const &info) const noexcept
356 { return _goos->set_view_info(_view_idx, info); }
357 
358 inline int
359 View::stack(View const &pivot, bool behind) const noexcept
360 { return _goos->view_stack(_view_idx, pivot._view_idx, behind); }
361 
362 inline int
363 View::refresh(int x, int y, int w, int h) const noexcept
364 { return _goos->view_refresh(_view_idx, x, y, w, h); }
365 
366 inline int
367 View::set_viewport(int scr_x, int scr_y, int w, int h,
368  unsigned long buf_offset) const noexcept
369 {
370  Info i;
371  i.flags = F_set_buffer_offset | F_set_position;
372  i.buffer_offset = buf_offset;
373  i.xpos = scr_x;
374  i.ypos = scr_y;
375  i.width = w;
376  i.height = h;
377  return set_info(i);
378 }
379 
380 }}
unsigned long width
Width of the view in pixels.
Definition: goos:93
unsigned view_index
Index of the view.
Definition: goos:89
bool valid() const
Return whether this view is valid.
Definition: goos:200
unsigned long ypos
Y position in pixels of the view in the goos.
Definition: goos:92
V_flags
Property flags of a view.
Definition: goos:77
Information structure of a view.
Definition: goos:86
A goos.
Definition: goos:207
unsigned flags
Flags, see Flags and V_flags.
Definition: goos:88
int create_view(View *view, l4_utcb_t *utcb=l4_utcb()) const noexcept
Create a view.
Definition: goos:296
Standard list of RPCs of an interface.
Definition: __typeinfo.h:438
bool has_dynamic_views() const
Return whether dynamic view are supported.
Definition: goos:236
unsigned num_static_buffers
Number of static buffers.
Definition: goos:227
Pixel information.
Definition: colors:106
bool has_set_pixel() const
Return whether the given pixel information is valid.
Definition: goos:112
unsigned long l4_cap_idx_t
L4 Capability selector Type.
Definition: types.h:342
bool has_static_buffer() const
Return whether the view has a static buffer.
Definition: goos:101
L4Re C++ Interfaces.
Definition: cmd_control:15
struct l4_utcb_t l4_utcb_t
Opaque type for the UTCB.
Definition: utcb.h:67
unsigned flags
Flags, see Flags.
Definition: goos:225
Mark an argument as a output value in an RPC signature.
Definition: ipc_types:42
L4::Cap related definitions.
Pixel_info pixel_info
Pixel information.
Definition: goos:228
int delete_view(View const &v, l4_utcb_t *utcb=l4_utcb()) const noexcept
Delete a view.
Definition: goos:316
unsigned long height
Height.
Definition: goos:224
unsigned long buffer_offset
Offset in the memory buffer in bytes.
Definition: goos:95
int push_top() const noexcept
Make this view the top-most view.
Definition: goos:180
int set_info(Info const &info) const noexcept
Set the information structure for this view.
Definition: goos:355
int refresh(int x, int y, int w, int h) const noexcept
Refresh/Redraw the view.
Definition: goos:363
bool auto_refresh() const
Return whether this goos does auto refreshing or the view refresh functions must be used to make chan...
Definition: goos:232
bool has_set_bytes_per_line() const
Return whether the given bytes-per-line value is valid.
Definition: goos:110
#define L4_INLINE_RPC(res, name, args, attr...)
Define an inline RPC call (type and callable).
Definition: ipc_iface:469
Information structure of a goos.
Definition: goos:221
bool has_set_buffer() const
Return whether a buffer is set.
Definition: goos:106
void dump(OUT &s) const
Dump information on the pixel to a stream.
Definition: colors:238
void dump(OUT &s) const
Dump information on the view information to a stream.
Definition: goos:118
unsigned buffer_index
Number of the buffer used for this view.
Definition: goos:98
unsigned num_static_views
Number of static view.
Definition: goos:226
bool has_static_buffer_offset() const
Return whether the static buffer offset is available.
Definition: goos:103
Flags
Flags on a view.
Definition: goos:54
Interface Definition Language.
unsigned long bytes_per_line
Bytes per line.
Definition: goos:96
int stack(View const &pivot, bool behind=true) const noexcept
Move this view in the view stack.
Definition: goos:359
int push_bottom() const noexcept
Push this view the back.
Definition: goos:184
bool has_set_position() const
Return whether the position information given is valid.
Definition: goos:114
bool has_pointer() const
Return whether a pointer is used by the provider of the goos.
Definition: goos:234
l4_utcb_t * l4_utcb(void) L4_NOTHROW L4_PURE
Get the UTCB address.
Definition: utcb.h:340
unsigned long width
Width.
Definition: goos:223
unsigned long xpos
X position in pixels of the view in the goos.
Definition: goos:91
Pixel_info pixel_info
Pixel information.
Definition: goos:97
int set_viewport(int scr_x, int scr_y, int w, int h, unsigned long buf_offset) const noexcept
Set the position of the view in the goos.
Definition: goos:367
bool is_valid() const noexcept
Test whether the capability is a valid capability index (i.e., not L4_INVALID_CAP).
Definition: capability.h:60
Helper class to create an L4Re interface class that is derived from a single base class...
Definition: __typeinfo.h:759
unsigned long height
Height of the view in pixels.
Definition: goos:94
View view(unsigned index) const noexcept
Return a view.
Definition: goos:347
Dataspace interface.
bool has_dynamic_buffers() const
Return whether dynamic buffers are supported.
Definition: goos:238
int info(Info *info) const noexcept
Return the view information of the view.
Definition: goos:351
C++ interface for capabilities.
Definition: capability.h:13
bool has_set_buffer_offset() const
Return whether the given buffer offset is valid.
Definition: goos:108
View.
Definition: goos:34
#define L4_INLINE_RPC_NF(res, name, args...)
Define an inline RPC call type (the type only, no callable).
Definition: ipc_iface:440
Flags
Flags for a goos.
Definition: goos:212
#define L4_RPC(res, name, args, attr...)
Define an RPC call (type and callable).
Definition: ipc_iface:528