L4Re Operating System Framework
Interface and Usage Documentation
•All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
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 * License: see LICENSE.spdx (in this directory or the directories above)
8 */
9#pragma once
10
11#include <l4/re/env>
12#include <l4/re/namespace>
13#include <l4/re/rm>
14#include <l4/re/util/cap_alloc>
15#include <l4/re/util/env_ns>
16#include <l4/re/util/video/goos_fb>
17#include <l4/re/video/goos>
18
19namespace L4Re { namespace Util { namespace Video {
20
21class Goos_fb
22{
23private:
27
28 enum Flags
29 {
30 F_dyn_buffer = 0x01,
31 F_dyn_view = 0x02,
32 F_dyn_goos = 0x04,
33 };
34 unsigned _flags;
35
36 unsigned _buffer_index;
37
38private:
39 long init()
40 {
41 using namespace L4Re::Video;
42
43 Goos::Info gi;
44 long ret = _goos->info(&gi);
45 if (ret < 0)
46 return ret;
47
48 if (gi.has_dynamic_views())
49 {
50 ret = _goos->create_view(&_view);
51 if (ret < 0)
52 return ret;
53
54 _flags |= F_dyn_view;
55 }
56 else // we just assume view 0 to be our's and ignore other possible views
57 _view = _goos->view(0);
58
59 View::Info vi;
60 ret = _view.info(&vi);
61 if (ret < 0)
62 return ret;
63
64 _buffer = cap_alloc.alloc<L4Re::Dataspace>();
65 if (!_buffer)
66 return -L4_ENOMEM;
67
68 if (vi.has_static_buffer())
69 {
70 ret = _goos->get_static_buffer(vi.buffer_index, _buffer);
71 if (ret < 0)
72 return ret;
73 }
74 else
75 {
76 unsigned long buffer_sz = gi.pixel_info.bytes_per_pixel() * gi.width
77 * gi.height;
78 ret = _goos->create_buffer(buffer_sz, _buffer);
79 if (ret < 0)
80 return ret;
81
82 _buffer_index = static_cast<unsigned>(ret);
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 ret = _view.set_info(vi);
98 if (ret < 0)
99 return ret;
100
101 ret = _view.push_top();
102 if (ret < 0)
103 return ret;
104 }
105
106 return 0;
107 }
108
109 Goos_fb(Goos_fb const &);
110 void operator = (Goos_fb const &);
111
112public:
113 Goos_fb()
114 : _goos(L4_INVALID_CAP), _buffer(L4_INVALID_CAP), _flags(0), _buffer_index(0)
115 {}
116
117 long init(L4::Cap<L4Re::Video::Goos> goos)
118 {
119 _goos = goos;
120 return init();
121 }
122
123 long init(char const *name)
124 {
125 Env_ns ns;
126 _goos = ns.query<L4Re::Video::Goos>(name);
127 if (!_goos)
128 return _goos.cap();
129
130 _flags |= F_dyn_goos;
131
132 return 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 if (!_goos)
164 return nullptr;
165
166 long ret = L4Re::Env::env()->rm()
167 ->attach(&fb_addr, _buffer->size(),
170 if (ret < 0)
171 return nullptr;
172
173 return fb_addr;
174 }
175
176 int refresh(int x, int y, int w, int h)
177 { return _view.refresh(x, y, w, h); }
178
179 L4::Cap<L4Re::Video::Goos> goos() const { return _goos; }
180};
181}}}
Interface for memory-like objects.
Definition dataspace:53
static Env const * env() noexcept
Returns the initial environment for the current task.
Definition env:95
L4::Cap< Rm > rm() const noexcept
Object-capability to the region map.
Definition env:119
L4::Cap< void > alloc() noexcept override
Allocate a capability.
void free(L4::Cap< void > cap, l4_cap_idx_t task=L4_INVALID_CAP, unsigned unmap_flags=L4_FP_ALL_SPACES) noexcept override
Free a capability.
Class that abstracts framebuffers.
Definition goos:225
unsigned char bytes_per_pixel() const
Query size of pixel in bytes.
Definition colors:150
View of a framebuffer.
Definition goos:40
int set_info(Info const &info) const noexcept
Set the information structure for this view.
Definition goos:371
int info(Info *info) const noexcept
Return the view information of the view.
Definition goos:367
int push_top() const noexcept
Make this view the top-most view.
Definition goos:185
int refresh(int x, int y, int w, int h) const noexcept
Refresh/Redraw the view.
Definition goos:379
l4_cap_idx_t cap() const noexcept
Return capability selector.
Definition capability.h:49
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.
@ L4_INVALID_CAP
Invalid capability selector.
Definition consts.h:157
@ L4_ENOMEM
No memory.
Definition err.h:39
#define L4_SUPERPAGESHIFT
Size of a large page, log2-based.
Definition consts.h:31
_Cap_alloc & cap_alloc
Capability allocator.
L4Re C++ Interfaces.
Definition cmd_control:14
Namespace interface.
Region mapper interface.
@ RW
Readable and writable region.
Definition rm:139
@ Search_addr
Search for a suitable address range.
Definition rm:114
Information structure of a Goos.
Definition goos:238
unsigned long height
Height.
Definition goos:240
unsigned long width
Width.
Definition goos:239
Pixel_info pixel_info
Pixel information.
Definition goos:244
bool has_dynamic_views() const
Return whether dynamic view are supported.
Definition goos:252
Information structure of a view.
Definition goos:92
Pixel_info pixel_info
Pixel information.
Definition goos:102
unsigned long height
Height of the view in pixels.
Definition goos:99
unsigned long width
Width of the view in pixels.
Definition goos:98
unsigned buffer_index
Number of the buffer used for this view.
Definition goos:103
unsigned long xpos
X position in pixels of the view in the Goos.
Definition goos:96
unsigned long buffer_offset
Offset in the memory buffer in bytes.
Definition goos:100
unsigned long bytes_per_line
Bytes per line.
Definition goos:101
bool has_static_buffer() const
Return whether the view has a static buffer.
Definition goos:106
unsigned long ypos
Y position in pixels of the view in the Goos.
Definition goos:97
Capability allocator.