Loading...
Searching...
No Matches
goos_fb
// vi:set ft=cpp: -*- Mode: C++ -*-
/*
* (c) 2008-2009 Adam Lackorzynski <adam@os.inf.tu-dresden.de>,
* Alexander Warg <warg@os.inf.tu-dresden.de>
* economic rights: Technische Universität Dresden (Germany)
*
* License: see LICENSE.spdx (in this directory or the directories above)
*/
#pragma once
#include <l4/re/env>
#include <l4/re/namespace>
#include <l4/re/rm>
#include <l4/re/util/cap_alloc>
#include <l4/re/util/env_ns>
#include <l4/re/util/video/goos_fb>
#include <l4/re/video/goos>
namespace L4Re { namespace Util { namespace Video {
class Goos_fb
{
private:
L4::Cap<L4Re::Video::Goos> _goos;
L4Re::Video::View _view;
L4::Cap<L4Re::Dataspace> _buffer;
enum Flags
{
F_dyn_buffer = 0x01,
F_dyn_view = 0x02,
F_dyn_goos = 0x04,
};
unsigned _flags;
unsigned _buffer_index;
private:
long init()
{
using namespace L4Re::Video;
Goos::Info gi;
long ret = _goos->info(&gi);
if (ret < 0)
return ret;
if (gi.has_dynamic_views())
{
ret = _goos->create_view(&_view);
if (ret < 0)
return ret;
_flags |= F_dyn_view;
}
else // we just assume view 0 to be our's and ignore other possible views
_view = _goos->view(0);
View::Info vi;
ret = _view.info(&vi);
if (ret < 0)
return ret;
_buffer = cap_alloc.alloc<L4Re::Dataspace>();
if (!_buffer)
return -L4_ENOMEM;
if (vi.has_static_buffer())
{
ret = _goos->get_static_buffer(vi.buffer_index, _buffer);
if (ret < 0)
return ret;
}
else
{
unsigned long buffer_sz = gi.pixel_info.bytes_per_pixel() * gi.width
* gi.height;
ret = _goos->create_buffer(buffer_sz, _buffer);
if (ret < 0)
return ret;
_buffer_index = static_cast<unsigned>(ret);
_flags |= F_dyn_buffer;
// use the allocated buffer, at offset 0
vi.buffer_index = _buffer_index;
vi.buffer_offset = 0;
vi.pixel_info = gi.pixel_info;
vi.bytes_per_line = gi.width * gi.pixel_info.bytes_per_pixel();
// we want a fullscreen view
vi.xpos = 0;
vi.ypos = 0;
vi.width = gi.width;
vi.height = gi.height;
ret = _view.set_info(vi);
if (ret < 0)
return ret;
ret = _view.push_top();
if (ret < 0)
return ret;
}
return 0;
}
Goos_fb(Goos_fb const &);
void operator = (Goos_fb const &);
public:
Goos_fb()
: _goos(L4_INVALID_CAP), _buffer(L4_INVALID_CAP), _flags(0), _buffer_index(0)
{}
long init(L4::Cap<L4Re::Video::Goos> goos)
{
_goos = goos;
return init();
}
long init(char const *name)
{
Env_ns ns;
_goos = ns.query<L4Re::Video::Goos>(name);
if (!_goos)
return _goos.cap();
_flags |= F_dyn_goos;
return init();
}
~Goos_fb()
{
if (!_goos.is_valid())
return;
if (_flags & F_dyn_view)
_goos->delete_view(_view);
if (_flags & F_dyn_buffer)
_goos->delete_buffer(_buffer_index);
if (_buffer.is_valid())
cap_alloc.free(_buffer);
if (_flags & F_dyn_goos)
cap_alloc.free(_goos);
}
int view_info(L4Re::Video::View::Info *info)
{ return _view.info(info); }
L4Re::Video::View const *view() const { return &_view; }
L4Re::Video::View *view() { return &_view; }
L4::Cap<L4Re::Dataspace> buffer() const { return _buffer; }
void *attach_buffer()
{
void *fb_addr = 0;
if (!_goos)
return nullptr;
long ret = L4Re::Env::env()->rm()
->attach(&fb_addr, _buffer->size(),
L4Re::Rm::F::Search_addr | L4Re::Rm::F::RW, _buffer,
0, L4_SUPERPAGESHIFT);
if (ret < 0)
return nullptr;
return fb_addr;
}
int refresh(int x, int y, int w, int h)
{ return _view.refresh(x, y, w, h); }
L4::Cap<L4Re::Video::Goos> goos() const { return _goos; }
};
}}}
L4Re::Env::env
static Env const * env() noexcept
Returns the initial environment for the current task.
Definition env:96
L4Re::Env::rm
L4::Cap< Rm > rm() const noexcept
Object-capability to the region map.
Definition env:120
L4Re::Util::_Cap_alloc::alloc
L4::Cap< void > alloc() noexcept override
Allocate a capability.
Definition cap_alloc_impl.h:75
L4Re::Util::_Cap_alloc::free
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.
Definition cap_alloc_impl.h:85
L4Re::Video::Pixel_info::bytes_per_pixel
unsigned char bytes_per_pixel() const
Query size of pixel in bytes.
Definition colors:150
env
Environment interface.
L4_INVALID_CAP
@ L4_INVALID_CAP
Invalid capability selector.
Definition consts.h:153
L4_ENOMEM
@ L4_ENOMEM
No memory.
Definition err.h:39
L4_SUPERPAGESHIFT
#define L4_SUPERPAGESHIFT
Size of a large page, log2-based.
Definition consts.h:31
L4Re::Util::cap_alloc
_Cap_alloc & cap_alloc
Capability allocator.
L4Re::Util
Documentation of the L4 Runtime Environment utility functionality in C++.
Definition l4re.dox:21
L4Re
L4Re C++ Interfaces.
Definition cmd_control:14
namespace
Namespace interface.
rm
Region mapper interface.
L4Re::Rm::F::RW
@ RW
Readable and writable region.
Definition rm:139
L4Re::Rm::F::Search_addr
@ Search_addr
Search for a suitable address range.
Definition rm:114
L4Re::Video::Goos::Info::height
unsigned long height
Height.
Definition goos:240
L4Re::Video::Goos::Info::width
unsigned long width
Width.
Definition goos:239
L4Re::Video::Goos::Info::pixel_info
Pixel_info pixel_info
Pixel information.
Definition goos:244
L4Re::Video::Goos::Info::has_dynamic_views
bool has_dynamic_views() const
Return whether dynamic view are supported.
Definition goos:252
L4Re::Video::View::Info::pixel_info
Pixel_info pixel_info
Pixel information.
Definition goos:102
L4Re::Video::View::Info::height
unsigned long height
Height of the view in pixels.
Definition goos:99
L4Re::Video::View::Info::width
unsigned long width
Width of the view in pixels.
Definition goos:98
L4Re::Video::View::Info::buffer_index
unsigned buffer_index
Number of the buffer used for this view.
Definition goos:103
L4Re::Video::View::Info::xpos
unsigned long xpos
X position in pixels of the view in the Goos.
Definition goos:96
L4Re::Video::View::Info::buffer_offset
unsigned long buffer_offset
Offset in the memory buffer in bytes.
Definition goos:100
L4Re::Video::View::Info::bytes_per_line
unsigned long bytes_per_line
Bytes per line.
Definition goos:101
L4Re::Video::View::Info::has_static_buffer
bool has_static_buffer() const
Return whether the view has a static buffer.
Definition goos:106
L4Re::Video::View::Info::ypos
unsigned long ypos
Y position in pixels of the view in the Goos.
Definition goos:97
cap_alloc
Capability allocator.