mirror of
https://github.com/genodelabs/genode.git
synced 2025-03-11 06:54:18 +00:00
parent
369ff2a001
commit
63e6dc05cd
@ -2,6 +2,7 @@
|
|||||||
* \brief Basic test for framebuffer session
|
* \brief Basic test for framebuffer session
|
||||||
* \author Martin Stein
|
* \author Martin Stein
|
||||||
* \author Christian Helmuth
|
* \author Christian Helmuth
|
||||||
|
* \author Stefan Kalkowski
|
||||||
* \date 2012-01-09
|
* \date 2012-01-09
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@ -13,101 +14,151 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
/* Genode includes */
|
/* Genode includes */
|
||||||
#include <framebuffer_session/connection.h>
|
#include <base/component.h>
|
||||||
|
#include <base/log.h>
|
||||||
#include <dataspace/client.h>
|
#include <dataspace/client.h>
|
||||||
#include <base/printf.h>
|
#include <framebuffer_session/connection.h>
|
||||||
#include <base/env.h>
|
#include <os/attached_dataspace.h>
|
||||||
#include <timer_session/connection.h>
|
#include <util/volatile_object.h>
|
||||||
|
|
||||||
|
|
||||||
class Test_environment
|
class Test_environment
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
|
|
||||||
Timer::Connection _timer;
|
using Ds = Genode::Lazy_volatile_object<Genode::Attached_dataspace>;
|
||||||
Framebuffer::Connection _fb;
|
|
||||||
Framebuffer::Mode const _mode{_fb.mode()};
|
|
||||||
|
|
||||||
Genode::Dataspace_capability const _ds_cap{_fb.dataspace()};
|
enum Color {
|
||||||
void * const _base{Genode::env()->rm_session()->attach(_ds_cap)};
|
|
||||||
|
|
||||||
public:
|
|
||||||
|
|
||||||
Test_environment()
|
|
||||||
{
|
|
||||||
PINF("framebuffer is %dx%d@%d",
|
|
||||||
_mode.width(), _mode.height(), _mode.format());
|
|
||||||
|
|
||||||
if (_mode.bytes_per_pixel() != 2) {
|
|
||||||
PERR("pixel format not supported");
|
|
||||||
throw -1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void complete_step()
|
|
||||||
{
|
|
||||||
_fb.refresh(0, 0, _mode.width(), _mode.height());
|
|
||||||
_timer.msleep(2000);
|
|
||||||
}
|
|
||||||
|
|
||||||
Framebuffer::Mode fb_mode() const { return _mode; }
|
|
||||||
unsigned fb_bpp() const { return _mode.bytes_per_pixel(); }
|
|
||||||
Genode::addr_t fb_base() const { return (Genode::addr_t) _base; }
|
|
||||||
Genode::size_t fb_size() const { return _mode.width()
|
|
||||||
* _mode.height()
|
|
||||||
* _mode.bytes_per_pixel(); }
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
int main()
|
|
||||||
{
|
|
||||||
using namespace Genode;
|
|
||||||
|
|
||||||
printf("--- Test framebuffer ---\n");
|
|
||||||
static Test_environment te;
|
|
||||||
|
|
||||||
addr_t const stripe_width = te.fb_mode().width() / 4;
|
|
||||||
while (1) {
|
|
||||||
enum {
|
|
||||||
BLACK = 0x0,
|
BLACK = 0x0,
|
||||||
BLUE = 0x1f,
|
BLUE = 0x1f,
|
||||||
GREEN = 0x7e0,
|
GREEN = 0x7e0,
|
||||||
RED = 0xf800,
|
RED = 0xf800,
|
||||||
WHITE = 0xffff,
|
WHITE = 0xffff,
|
||||||
};
|
};
|
||||||
PINF("black & white stripes");
|
|
||||||
addr_t stripe_o = 0;
|
enum State { STRIPES, ALL_BLUE, ALL_GREEN, ALL_RED, COLORED };
|
||||||
bool stripe = 0;
|
|
||||||
for (addr_t o = 0; o < te.fb_size(); o += te.fb_bpp()) {
|
Framebuffer::Connection _fb;
|
||||||
stripe_o++;
|
Framebuffer::Mode _mode;
|
||||||
if (stripe_o == stripe_width) {
|
Ds _fb_ds;
|
||||||
stripe_o = 0;
|
Genode::Signal_handler<Test_environment> _mode_sigh;
|
||||||
stripe = !stripe;
|
Genode::Signal_handler<Test_environment> _sync_sigh;
|
||||||
}
|
unsigned long _sync_cnt = 0;
|
||||||
*(uint16_t volatile *)(te.fb_base() + o) = stripe ? BLACK : WHITE;
|
State _state = STRIPES;
|
||||||
|
|
||||||
|
enum { FRAME_CNT = 200 };
|
||||||
|
|
||||||
|
void _draw();
|
||||||
|
void _mode_handle();
|
||||||
|
|
||||||
|
void _sync_handle() {
|
||||||
|
if (_sync_cnt++ % FRAME_CNT == 0) _draw(); }
|
||||||
|
|
||||||
|
Genode::size_t _fb_bpp() { return _mode.bytes_per_pixel(); }
|
||||||
|
Genode::size_t _fb_size() { return _fb_ds->size(); }
|
||||||
|
Genode::addr_t _fb_base() {
|
||||||
|
return (Genode::addr_t) _fb_ds->local_addr<void>(); }
|
||||||
|
|
||||||
|
public:
|
||||||
|
|
||||||
|
Test_environment(Genode::Entrypoint &ep)
|
||||||
|
: _mode_sigh(ep, *this, &Test_environment::_mode_handle),
|
||||||
|
_sync_sigh(ep, *this, &Test_environment::_sync_handle)
|
||||||
|
{
|
||||||
|
_fb.mode_sigh(_mode_sigh);
|
||||||
|
_fb.sync_sigh(_sync_sigh);
|
||||||
|
_mode_handle();
|
||||||
}
|
}
|
||||||
te.complete_step();
|
};
|
||||||
|
|
||||||
PINF("blue");
|
|
||||||
for (addr_t o = 0; o < te.fb_size(); o += te.fb_bpp())
|
|
||||||
*(uint16_t volatile *)(te.fb_base() + o) = BLUE;
|
|
||||||
te.complete_step();
|
|
||||||
|
|
||||||
PINF("green");
|
void Test_environment::_draw()
|
||||||
for (addr_t o = 0; o < te.fb_size(); o += te.fb_bpp())
|
{
|
||||||
*(uint16_t volatile *)(te.fb_base() + o) = GREEN;
|
using namespace Genode;
|
||||||
te.complete_step();
|
|
||||||
|
|
||||||
PINF("red");
|
switch(_state) {
|
||||||
for (addr_t o = 0; o < te.fb_size(); o += te.fb_bpp())
|
case STRIPES:
|
||||||
*(uint16_t volatile *)(te.fb_base() + o) = RED;
|
{
|
||||||
te.complete_step();
|
Genode::log("black & white stripes");
|
||||||
|
addr_t const stripe_width = _mode.width() / 4;
|
||||||
PINF("all colors mixed");
|
addr_t stripe_o = 0;
|
||||||
unsigned i = 0;
|
bool stripe = 0;
|
||||||
for (addr_t o = 0; o < te.fb_size(); o += te.fb_bpp(), i++)
|
for (addr_t o = 0; o < _fb_size(); o += _fb_bpp()) {
|
||||||
*(uint16_t volatile *)(te.fb_base() + o) = i;
|
stripe_o++;
|
||||||
te.complete_step();
|
if (stripe_o == stripe_width) {
|
||||||
}
|
stripe_o = 0;
|
||||||
|
stripe = !stripe;
|
||||||
|
}
|
||||||
|
*(uint16_t volatile *)(_fb_base() + o) = stripe ? BLACK : WHITE;
|
||||||
|
}
|
||||||
|
_state = ALL_BLUE;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case ALL_BLUE:
|
||||||
|
{
|
||||||
|
Genode::log("blue");
|
||||||
|
for (addr_t o = 0; o < _fb_size(); o += _fb_bpp())
|
||||||
|
*(uint16_t volatile *)(_fb_base() + o) = BLUE;
|
||||||
|
_state = ALL_GREEN;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case ALL_GREEN:
|
||||||
|
{
|
||||||
|
Genode::log("green");
|
||||||
|
for (addr_t o = 0; o < _fb_size(); o += _fb_bpp())
|
||||||
|
*(uint16_t volatile *)(_fb_base() + o) = GREEN;
|
||||||
|
_state = ALL_RED;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case ALL_RED:
|
||||||
|
{
|
||||||
|
Genode::log("red");
|
||||||
|
for (addr_t o = 0; o < _fb_size(); o += _fb_bpp())
|
||||||
|
*(uint16_t volatile *)(_fb_base() + o) = RED;
|
||||||
|
_state = COLORED;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case COLORED:
|
||||||
|
{
|
||||||
|
Genode::log("all colors mixed");
|
||||||
|
unsigned i = 0;
|
||||||
|
for (addr_t o = 0; o < _fb_size(); o += _fb_bpp(), i++)
|
||||||
|
*(uint16_t volatile *)(_fb_base() + o) = i;
|
||||||
|
_state = STRIPES;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
_fb.refresh(0, 0, _mode.width(), _mode.height());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void Test_environment::_mode_handle()
|
||||||
|
{
|
||||||
|
_mode = _fb.mode();
|
||||||
|
if (_fb_ds.is_constructed())
|
||||||
|
_fb_ds.destruct();
|
||||||
|
|
||||||
|
_fb_ds.construct(_fb.dataspace());
|
||||||
|
|
||||||
|
Genode::log("framebuffer is ", _mode.width(), "x", _mode.height(),
|
||||||
|
"@", (int)_mode.format());
|
||||||
|
|
||||||
|
if (_mode.bytes_per_pixel() != 2) {
|
||||||
|
Genode::error("pixel format not supported");
|
||||||
|
throw -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
_draw();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void Component::construct(Genode::Env &env)
|
||||||
|
{
|
||||||
|
using namespace Genode;
|
||||||
|
|
||||||
|
Genode::log("--- Test framebuffer ---\n");
|
||||||
|
static Test_environment te(env.ep());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Genode::size_t Component::stack_size() {
|
||||||
|
return 4*1024*sizeof(long); }
|
||||||
|
Loading…
x
Reference in New Issue
Block a user