L4Re Operating System Framework
Interface and Usage Documentation
Loading...
Searching...
No Matches
goos_fb
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/re/env>
23#include <l4/re/error_helper>
24#include <l4/re/namespace>
25#include <l4/re/rm>
26#include <l4/re/util/cap_alloc>
27#include <l4/re/util/env_ns>
28#include <l4/re/util/video/goos_fb>
29#include <l4/re/video/goos>
30
31namespace L4Re { namespace Util { namespace Video {
32
33class Goos_fb
34{
35private:
39
40 enum Flags
41 {
42 F_dyn_buffer = 0x01,
43 F_dyn_view = 0x02,
44 F_dyn_goos = 0x04,
45 };
46 unsigned _flags;
47
48 unsigned _buffer_index;
49
50private:
51 void init()
52 {
53 using namespace L4Re::Video;
54 using L4Re::chksys;
55 using L4Re::chkcap;
56
57 Goos::Info gi;
58 chksys(_goos->info(&gi), "requesting goos info");
59
60 if (gi.has_dynamic_views())
61 {
62 chksys(_goos->create_view(&_view), "creating dynamic goos view");
63 _flags |= F_dyn_view;
64 }
65 else // we just assume view 0 to be our's and ignore other possible views
66 _view = _goos->view(0);
67
68 View::Info vi;
69 chksys(_view.info(&vi), "requesting goos view information");
70
71 _buffer = chkcap(cap_alloc.alloc<L4Re::Dataspace>(),
72 "allocating goos buffer cap");
73
74 if (vi.has_static_buffer())
75 chksys(_goos->get_static_buffer(vi.buffer_index, _buffer),
76 "requesting static goos buffer");
77 else
78 {
79 unsigned long buffer_sz = gi.pixel_info.bytes_per_pixel() * gi.width
80 * gi.height;
81 _buffer_index = chksys(_goos->create_buffer(buffer_sz, _buffer),
82 "allocating goos buffer");
83 _flags |= F_dyn_buffer;
84
85 // use the allocated buffer, at offset 0
86 vi.buffer_index = _buffer_index;
87 vi.buffer_offset = 0;
88 vi.pixel_info = gi.pixel_info;
90
91 // we want a fullscreen view
92 vi.xpos = 0;
93 vi.ypos = 0;
94 vi.width = gi.width;
95 vi.height = gi.height;
96
97 chksys(_view.set_info(vi), "setting up dynamic view");
98 chksys(_view.push_top(), "bringing view to top");
99 }
100 }
101
102 Goos_fb(Goos_fb const &);
103 void operator = (Goos_fb const &);
104
105public:
106 Goos_fb()
107 : _goos(L4_INVALID_CAP), _buffer(L4_INVALID_CAP), _flags(0), _buffer_index(0)
108 {}
109
110 explicit Goos_fb(L4::Cap<L4Re::Video::Goos> goos)
111 : _goos(goos), _buffer(L4_INVALID_CAP), _flags(0)
112 { init(); }
113
114 explicit Goos_fb(char const *name)
115 : _goos(L4_INVALID_CAP), _buffer(L4_INVALID_CAP), _flags(0)
116 { setup(name); }
117
118 void setup(L4::Cap<L4Re::Video::Goos> goos)
119 {
120 _goos = goos;
121 init();
122 }
123
124 void setup(char const *name)
125 {
126 Env_ns ns;
127 //_goos = chkcap(cap_alloc.alloc<L4Re::Video::Goos>(), "allocating goos cap");
128 _goos = chkcap(ns.query<L4Re::Video::Goos>(name), "requesting goos cap", 0);
129 _flags |= F_dyn_goos;
130
131 //chksys(L4Re::Env::env()->names()->query(name, _goos), "requesting goos service");
132 init();
133 }
134
135 ~Goos_fb()
136 {
137 if (!_goos.is_valid())
138 return;
139
140 if (_flags & F_dyn_view)
141 _goos->delete_view(_view);
142
143 if (_flags & F_dyn_buffer)
144 _goos->delete_buffer(_buffer_index);
145
146 if (_buffer.is_valid())
147 cap_alloc.free(_buffer);
148
149 if (_flags & F_dyn_goos)
150 cap_alloc.free(_goos);
151 }
152
153 int view_info(L4Re::Video::View::Info *info)
154 { return _view.info(info); }
155
156 L4Re::Video::View const *view() const { return &_view; }
157 L4Re::Video::View *view() { return &_view; }
158
159 L4::Cap<L4Re::Dataspace> buffer() const { return _buffer; }
160 void *attach_buffer()
161 {
162 void *fb_addr = 0;
163 L4Re::chkcap(_goos);
165 ->attach(&fb_addr, _buffer->size(),
167 0, L4_SUPERPAGESHIFT), "attaching frame-buffer memory");
168 return fb_addr;
169 }
170
171 int refresh(int x, int y, int w, int h)
172 { return _view.refresh(x, y, w, h); }
173
174 L4::Cap<L4Re::Video::Goos> goos() const { return _goos; }
175};
176}}}
Interface for memory-like objects.
Definition dataspace:64
static Env const * env() noexcept
Returns the initial environment for the current task.
Definition env:103
Class that abstracts framebuffers.
Definition goos:228
unsigned char bytes_per_pixel() const
Query size of pixel in bytes.
Definition colors:161
View of a framebuffer.
Definition goos:43
int set_info(Info const &info) const noexcept
Set the information structure for this view.
Definition goos:374
int info(Info *info) const noexcept
Return the view information of the view.
Definition goos:370
int push_top() const noexcept
Make this view the top-most view.
Definition goos:188
int refresh(int x, int y, int w, int h) const noexcept
Refresh/Redraw the view.
Definition goos:382
bool is_valid() const noexcept
Test whether the capability is a valid capability index (i.e., not L4_INVALID_CAP).
Definition capability.h:57
C++ interface for capabilities.
Definition capability.h:219
Environment interface.
Error helper.
@ L4_INVALID_CAP
Invalid capability selector.
Definition consts.h:168
#define L4_SUPERPAGESHIFT
Size of a large page, log2-based.
Definition consts.h:42
_Cap_alloc & cap_alloc
Capability allocator.
L4Re C++ Interfaces.
Definition l4re.dox:17
long chksys(long err, char const *extra="", long ret=0)
Generate C++ exception on error.
Definition error_helper:68
T chkcap(T &&cap, char const *extra="", long err=-L4_ENOMEM)
Check for valid capability or raise C++ exception.
Definition error_helper:145
Namespace interface.
Region mapper interface.
@ RW
Readable and writable region.
Definition rm:150
@ Search_addr
Search for a suitable address range.
Definition rm:125
Information structure of a Goos.
Definition goos:241
unsigned long height
Height.
Definition goos:243
unsigned long width
Width.
Definition goos:242
Pixel_info pixel_info
Pixel information.
Definition goos:247
bool has_dynamic_views() const
Return whether dynamic view are supported.
Definition goos:255
Information structure of a view.
Definition goos:95
Pixel_info pixel_info
Pixel information.
Definition goos:105
unsigned long height
Height of the view in pixels.
Definition goos:102
unsigned long width
Width of the view in pixels.
Definition goos:101
unsigned buffer_index
Number of the buffer used for this view.
Definition goos:106
unsigned long xpos
X position in pixels of the view in the Goos.
Definition goos:99
unsigned long buffer_offset
Offset in the memory buffer in bytes.
Definition goos:103
unsigned long bytes_per_line
Bytes per line.
Definition goos:104
bool has_static_buffer() const
Return whether the view has a static buffer.
Definition goos:109
unsigned long ypos
Y position in pixels of the view in the Goos.
Definition goos:100
Capability allocator.