2013-09-15 17:48:10 +02:00
|
|
|
/*
|
|
|
|
* \brief Framebuffer driver for Raspberry Pi
|
|
|
|
* \author Norman Feske
|
|
|
|
* \date 2013-09-14
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Copyright (C) 2013 Genode Labs GmbH
|
|
|
|
*
|
|
|
|
* This file is part of the Genode OS framework, which is distributed
|
|
|
|
* under the terms of the GNU General Public License version 2.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* Genode includes */
|
2016-12-01 17:37:08 +01:00
|
|
|
#include <util/reconstructible.h>
|
2013-09-15 17:48:10 +02:00
|
|
|
#include <os/attached_io_mem_dataspace.h>
|
2014-11-09 19:45:50 +01:00
|
|
|
#include <os/attached_ram_dataspace.h>
|
2013-09-15 17:48:10 +02:00
|
|
|
#include <os/static_root.h>
|
2014-11-09 19:45:50 +01:00
|
|
|
#include <os/config.h>
|
2013-09-15 17:48:10 +02:00
|
|
|
#include <cap_session/connection.h>
|
|
|
|
#include <base/sleep.h>
|
|
|
|
#include <framebuffer_session/framebuffer_session.h>
|
|
|
|
#include <base/rpc_server.h>
|
|
|
|
#include <platform_session/connection.h>
|
2014-11-09 19:45:50 +01:00
|
|
|
#include <blit/blit.h>
|
2015-01-29 14:11:14 +01:00
|
|
|
#include <timer_session/connection.h>
|
2013-09-15 17:48:10 +02:00
|
|
|
|
|
|
|
namespace Framebuffer {
|
|
|
|
using namespace Genode;
|
|
|
|
class Session_component;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
class Framebuffer::Session_component : public Genode::Rpc_object<Framebuffer::Session>
|
|
|
|
{
|
|
|
|
private:
|
|
|
|
|
2016-12-01 17:37:08 +01:00
|
|
|
size_t const _width;
|
|
|
|
size_t const _height;
|
|
|
|
Constructible<Attached_ram_dataspace> _bb_mem;
|
|
|
|
Attached_io_mem_dataspace _fb_mem;
|
|
|
|
Timer::Connection _timer;
|
2014-11-09 19:45:50 +01:00
|
|
|
|
|
|
|
void _refresh_buffered(int x, int y, int w, int h)
|
|
|
|
{
|
|
|
|
Mode _mode = mode();
|
|
|
|
|
|
|
|
/* clip specified coordinates against screen boundaries */
|
|
|
|
int x2 = min(x + w - 1, (int)_mode.width() - 1),
|
|
|
|
y2 = min(y + h - 1, (int)_mode.height() - 1);
|
|
|
|
int x1 = max(x, 0),
|
|
|
|
y1 = max(y, 0);
|
|
|
|
if (x1 > x2 || y1 > y2) return;
|
|
|
|
|
|
|
|
int bypp = _mode.bytes_per_pixel();
|
|
|
|
|
|
|
|
/* copy pixels from back buffer to physical frame buffer */
|
|
|
|
char *src = _bb_mem->local_addr<char>() + bypp*(_width*y1 + x1),
|
|
|
|
*dst = _fb_mem.local_addr<char>() + bypp*(_width*y1 + x1);
|
|
|
|
|
|
|
|
blit(src, bypp*_width, dst, bypp*_width,
|
|
|
|
bypp*(x2 - x1 + 1), y2 - y1 + 1);
|
|
|
|
}
|
2013-09-15 17:48:10 +02:00
|
|
|
|
|
|
|
public:
|
|
|
|
|
2014-11-09 19:45:50 +01:00
|
|
|
Session_component(addr_t phys_addr, size_t size,
|
|
|
|
size_t width, size_t height,
|
|
|
|
bool buffered)
|
2013-09-15 17:48:10 +02:00
|
|
|
:
|
|
|
|
_width(width), _height(height), _fb_mem(phys_addr, size)
|
2014-11-09 19:45:50 +01:00
|
|
|
{
|
|
|
|
if (buffered) {
|
|
|
|
_bb_mem.construct(env()->ram_session(), size);
|
|
|
|
}
|
|
|
|
}
|
2013-09-15 17:48:10 +02:00
|
|
|
|
|
|
|
/************************************
|
|
|
|
** Framebuffer::Session interface **
|
|
|
|
************************************/
|
|
|
|
|
2014-11-09 19:45:50 +01:00
|
|
|
Dataspace_capability dataspace() override
|
|
|
|
{
|
2016-05-11 18:21:47 +02:00
|
|
|
if (_bb_mem.constructed())
|
2014-11-09 19:45:50 +01:00
|
|
|
return _bb_mem->cap();
|
|
|
|
else
|
|
|
|
return _fb_mem.cap();
|
|
|
|
}
|
2013-09-15 17:48:10 +02:00
|
|
|
|
2014-04-29 15:32:09 +02:00
|
|
|
Mode mode() const override
|
2013-09-15 17:48:10 +02:00
|
|
|
{
|
|
|
|
return Mode(_width, _height, Mode::RGB565);
|
|
|
|
}
|
|
|
|
|
2014-04-29 15:32:09 +02:00
|
|
|
void mode_sigh(Genode::Signal_context_capability) override { }
|
2013-09-15 17:48:10 +02:00
|
|
|
|
2014-04-29 15:32:09 +02:00
|
|
|
void sync_sigh(Genode::Signal_context_capability sigh) override
|
|
|
|
{
|
2015-01-29 14:11:14 +01:00
|
|
|
_timer.sigh(sigh);
|
|
|
|
_timer.trigger_periodic(10*1000);
|
2014-04-29 15:32:09 +02:00
|
|
|
}
|
|
|
|
|
2014-11-09 19:45:50 +01:00
|
|
|
void refresh(int x, int y, int w, int h) override
|
2014-04-29 15:32:09 +02:00
|
|
|
{
|
2016-05-11 18:21:47 +02:00
|
|
|
if (_bb_mem.constructed())
|
2014-11-09 19:45:50 +01:00
|
|
|
_refresh_buffered(x, y, w, h);
|
2014-04-29 15:32:09 +02:00
|
|
|
}
|
2013-09-15 17:48:10 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2014-11-09 19:45:50 +01:00
|
|
|
static bool config_is_buffered()
|
|
|
|
{
|
2016-06-09 15:55:13 +02:00
|
|
|
return Genode::config()->xml_node().attribute_value("buffered", false);
|
2014-11-09 19:45:50 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-09-15 17:48:10 +02:00
|
|
|
int main(int, char **)
|
|
|
|
{
|
|
|
|
using namespace Framebuffer;
|
|
|
|
using namespace Genode;
|
|
|
|
|
base: avoid use of deprecated base/printf.h
Besides adapting the components to the use of base/log.h, the patch
cleans up a few base headers, i.e., it removes unused includes from
root/component.h, specifically base/heap.h and
ram_session/ram_session.h. Hence, components that relied on the implicit
inclusion of those headers have to manually include those headers now.
While adjusting the log messages, I repeatedly stumbled over the problem
that printing char * arguments is ambiguous. It is unclear whether to
print the argument as pointer or null-terminated string. To overcome
this problem, the patch introduces a new type 'Cstring' that allows the
caller to express that the argument should be handled as null-terminated
string. As a nice side effect, with this type in place, the optional len
argument of the 'String' class could be removed. Instead of supplying a
pair of (char const *, size_t), the constructor accepts a 'Cstring'.
This, in turn, clears the way let the 'String' constructor use the new
output mechanism to assemble a string from multiple arguments (and
thereby getting rid of snprintf within Genode in the near future).
To enforce the explicit resolution of the char * ambiguity, the 'char *'
overload of the 'print' function is marked as deleted.
Issue #1987
2016-07-13 19:07:09 +02:00
|
|
|
log("--- fb_drv started ---");
|
2013-09-15 17:48:10 +02:00
|
|
|
|
|
|
|
static Platform::Connection platform;
|
|
|
|
|
|
|
|
Platform::Framebuffer_info fb_info(1024, 768, 16);
|
|
|
|
platform.setup_framebuffer(fb_info);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Initialize server entry point
|
|
|
|
*/
|
|
|
|
enum { STACK_SIZE = 4096 };
|
|
|
|
static Cap_connection cap;
|
|
|
|
static Rpc_entrypoint ep(&cap, STACK_SIZE, "fb_ep");
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Let the entry point serve the framebuffer session and root interfaces
|
|
|
|
*/
|
|
|
|
static Session_component fb_session(fb_info.addr,
|
|
|
|
fb_info.size,
|
|
|
|
fb_info.phys_width,
|
2014-11-09 19:45:50 +01:00
|
|
|
fb_info.phys_height,
|
|
|
|
config_is_buffered());
|
2013-09-15 17:48:10 +02:00
|
|
|
static Static_root<Framebuffer::Session> fb_root(ep.manage(&fb_session));
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Announce service
|
|
|
|
*/
|
|
|
|
env()->parent()->announce(ep.manage(&fb_root));
|
|
|
|
|
|
|
|
sleep_forever();
|
|
|
|
return 0;
|
|
|
|
}
|