mirror of
https://github.com/genodelabs/genode.git
synced 2024-12-18 21:27:56 +00:00
gui_fb: update coding style
Avoid Genode:: prefix, indicate 'Main' members as being private.
This commit is contained in:
parent
f650f2e91b
commit
ce4f0cdd18
@ -20,18 +20,18 @@
|
|||||||
#include <base/attached_rom_dataspace.h>
|
#include <base/attached_rom_dataspace.h>
|
||||||
#include <base/component.h>
|
#include <base/component.h>
|
||||||
|
|
||||||
namespace Nit_fb {
|
namespace Gui_fb {
|
||||||
|
|
||||||
|
using namespace Genode;
|
||||||
|
|
||||||
|
struct View_updater;
|
||||||
struct Main;
|
struct Main;
|
||||||
|
|
||||||
using Genode::Static_root;
|
using Point = Gui::Point;
|
||||||
using Genode::Signal_handler;
|
using Area = Gui::Area;
|
||||||
using Genode::Xml_node;
|
using Rect = Gui::Rect;
|
||||||
using Genode::size_t;
|
|
||||||
|
|
||||||
using Point = Genode::Surface_base::Point;
|
static ::Input::Event translate_event(::Input::Event, Point, Area);
|
||||||
using Area = Genode::Surface_base::Area;
|
|
||||||
using Rect = Genode::Surface_base::Rect;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -42,16 +42,14 @@ namespace Nit_fb {
|
|||||||
/**
|
/**
|
||||||
* Translate input event
|
* Translate input event
|
||||||
*/
|
*/
|
||||||
static Input::Event translate_event(Input::Event ev,
|
static Input::Event Gui_fb::translate_event(Input::Event ev,
|
||||||
Nit_fb::Point const input_origin,
|
Point const input_origin,
|
||||||
Nit_fb::Area const boundary)
|
Area const boundary)
|
||||||
{
|
{
|
||||||
using Nit_fb::Point;
|
|
||||||
|
|
||||||
/* function to clamp point to bounday */
|
/* function to clamp point to bounday */
|
||||||
auto clamp = [boundary] (Point p) {
|
auto clamp = [boundary] (Point p) {
|
||||||
return Point(Genode::min((int)boundary.w - 1, Genode::max(0, p.x)),
|
return Point(min((int)boundary.w - 1, max(0, p.x)),
|
||||||
Genode::min((int)boundary.h - 1, Genode::max(0, p.y))); };
|
min((int)boundary.h - 1, max(0, p.y))); };
|
||||||
|
|
||||||
/* function to translate point to 'input_origin' */
|
/* function to translate point to 'input_origin' */
|
||||||
auto translate = [input_origin] (Point p) { return p - input_origin; };
|
auto translate = [input_origin] (Point p) { return p - input_origin; };
|
||||||
@ -70,7 +68,7 @@ static Input::Event translate_event(Input::Event ev,
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
struct View_updater : Genode::Interface
|
struct Gui_fb::View_updater : Genode::Interface
|
||||||
{
|
{
|
||||||
virtual void update_view() = 0;
|
virtual void update_view() = 0;
|
||||||
};
|
};
|
||||||
@ -80,18 +78,23 @@ struct View_updater : Genode::Interface
|
|||||||
** Virtualized framebuffer **
|
** Virtualized framebuffer **
|
||||||
*****************************/
|
*****************************/
|
||||||
|
|
||||||
namespace Framebuffer { struct Session_component; }
|
namespace Framebuffer {
|
||||||
|
|
||||||
|
using namespace Gui_fb;
|
||||||
|
|
||||||
|
struct Session_component;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
struct Framebuffer::Session_component : Genode::Rpc_object<Framebuffer::Session>
|
struct Framebuffer::Session_component : Genode::Rpc_object<Framebuffer::Session>
|
||||||
{
|
{
|
||||||
Genode::Pd_session const &_pd;
|
Pd_session const &_pd;
|
||||||
|
|
||||||
Gui::Connection &_gui;
|
Gui::Connection &_gui;
|
||||||
|
|
||||||
Genode::Signal_context_capability _mode_sigh { };
|
Signal_context_capability _mode_sigh { };
|
||||||
|
|
||||||
Genode::Signal_context_capability _sync_sigh { };
|
Signal_context_capability _sync_sigh { };
|
||||||
|
|
||||||
View_updater &_view_updater;
|
View_updater &_view_updater;
|
||||||
|
|
||||||
@ -101,8 +104,6 @@ struct Framebuffer::Session_component : Genode::Rpc_object<Framebuffer::Session>
|
|||||||
*/
|
*/
|
||||||
Framebuffer::Mode _next_mode;
|
Framebuffer::Mode _next_mode;
|
||||||
|
|
||||||
using size_t = Genode::size_t;
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Number of bytes used for backing the current virtual framebuffer at
|
* Number of bytes used for backing the current virtual framebuffer at
|
||||||
* the GUI server.
|
* the GUI server.
|
||||||
@ -134,7 +135,7 @@ struct Framebuffer::Session_component : Genode::Rpc_object<Framebuffer::Session>
|
|||||||
/**
|
/**
|
||||||
* Constructor
|
* Constructor
|
||||||
*/
|
*/
|
||||||
Session_component(Genode::Pd_session const &pd,
|
Session_component(Pd_session const &pd,
|
||||||
Gui::Connection &gui,
|
Gui::Connection &gui,
|
||||||
View_updater &view_updater,
|
View_updater &view_updater,
|
||||||
Framebuffer::Mode initial_mode)
|
Framebuffer::Mode initial_mode)
|
||||||
@ -152,14 +153,14 @@ struct Framebuffer::Session_component : Genode::Rpc_object<Framebuffer::Session>
|
|||||||
Framebuffer::Mode const mode { .area = size };
|
Framebuffer::Mode const mode { .area = size };
|
||||||
|
|
||||||
if (!_ram_suffices_for_mode(mode)) {
|
if (!_ram_suffices_for_mode(mode)) {
|
||||||
Genode::warning("insufficient RAM for mode ", mode);
|
warning("insufficient RAM for mode ", mode);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
_next_mode = mode;
|
_next_mode = mode;
|
||||||
|
|
||||||
if (_mode_sigh.valid())
|
if (_mode_sigh.valid())
|
||||||
Genode::Signal_transmitter(_mode_sigh).submit();
|
Signal_transmitter(_mode_sigh).submit();
|
||||||
}
|
}
|
||||||
|
|
||||||
Gui::Area size() const
|
Gui::Area size() const
|
||||||
@ -172,13 +173,12 @@ struct Framebuffer::Session_component : Genode::Rpc_object<Framebuffer::Session>
|
|||||||
** Framebuffer::Session interface **
|
** Framebuffer::Session interface **
|
||||||
************************************/
|
************************************/
|
||||||
|
|
||||||
Genode::Dataspace_capability dataspace() override
|
Dataspace_capability dataspace() override
|
||||||
{
|
{
|
||||||
_gui.buffer(_active_mode, false);
|
_gui.buffer(_active_mode, false);
|
||||||
|
|
||||||
_buffer_num_bytes =
|
_buffer_num_bytes =
|
||||||
Genode::max(_buffer_num_bytes,
|
max(_buffer_num_bytes, Gui::Session::ram_quota(_active_mode, false));
|
||||||
Gui::Session::ram_quota(_active_mode, false));
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* We defer the update of the view until the client calls refresh the
|
* We defer the update of the view until the client calls refresh the
|
||||||
@ -196,7 +196,7 @@ struct Framebuffer::Session_component : Genode::Rpc_object<Framebuffer::Session>
|
|||||||
return _active_mode;
|
return _active_mode;
|
||||||
}
|
}
|
||||||
|
|
||||||
void mode_sigh(Genode::Signal_context_capability sigh) override
|
void mode_sigh(Signal_context_capability sigh) override
|
||||||
{
|
{
|
||||||
_mode_sigh = sigh;
|
_mode_sigh = sigh;
|
||||||
}
|
}
|
||||||
@ -211,7 +211,7 @@ struct Framebuffer::Session_component : Genode::Rpc_object<Framebuffer::Session>
|
|||||||
_gui.framebuffer.refresh(x, y, w, h);
|
_gui.framebuffer.refresh(x, y, w, h);
|
||||||
}
|
}
|
||||||
|
|
||||||
void sync_sigh(Genode::Signal_context_capability sigh) override
|
void sync_sigh(Signal_context_capability sigh) override
|
||||||
{
|
{
|
||||||
/*
|
/*
|
||||||
* Keep a component-local copy of the signal capability. Otherwise,
|
* Keep a component-local copy of the signal capability. Otherwise,
|
||||||
@ -230,21 +230,21 @@ struct Framebuffer::Session_component : Genode::Rpc_object<Framebuffer::Session>
|
|||||||
** Main program **
|
** Main program **
|
||||||
******************/
|
******************/
|
||||||
|
|
||||||
struct Nit_fb::Main : View_updater
|
struct Gui_fb::Main : View_updater
|
||||||
{
|
{
|
||||||
Genode::Env &env;
|
Env &_env;
|
||||||
|
|
||||||
Genode::Attached_rom_dataspace config_rom { env, "config" };
|
Attached_rom_dataspace _config_rom { _env, "config" };
|
||||||
|
|
||||||
Gui::Connection gui { env };
|
Gui::Connection _gui { _env };
|
||||||
|
|
||||||
Point position { 0, 0 };
|
Point _position { 0, 0 };
|
||||||
|
|
||||||
unsigned refresh_rate = 0;
|
unsigned _refresh_rate = 0;
|
||||||
|
|
||||||
Gui::Top_level_view const view { gui };
|
Gui::Top_level_view const _view { _gui };
|
||||||
|
|
||||||
Genode::Attached_dataspace input_ds { env.rm(), gui.input.dataspace() };
|
Attached_dataspace _input_ds { _env.rm(), _gui.input.dataspace() };
|
||||||
|
|
||||||
struct Initial_size
|
struct Initial_size
|
||||||
{
|
{
|
||||||
@ -253,7 +253,7 @@ struct Nit_fb::Main : View_updater
|
|||||||
|
|
||||||
bool set { false };
|
bool set { false };
|
||||||
|
|
||||||
Initial_size(Genode::Xml_node config)
|
Initial_size(Xml_node config)
|
||||||
:
|
:
|
||||||
_width (config.attribute_value("initial_width", 0L)),
|
_width (config.attribute_value("initial_width", 0L)),
|
||||||
_height(config.attribute_value("initial_height", 0L))
|
_height(config.attribute_value("initial_height", 0L))
|
||||||
@ -275,21 +275,21 @@ struct Nit_fb::Main : View_updater
|
|||||||
|
|
||||||
bool valid() const { return _width != 0 && _height != 0; }
|
bool valid() const { return _width != 0 && _height != 0; }
|
||||||
|
|
||||||
} _initial_size { config_rom.xml() };
|
} _initial_size { _config_rom.xml() };
|
||||||
|
|
||||||
Framebuffer::Mode _initial_mode()
|
Framebuffer::Mode _initial_mode()
|
||||||
{
|
{
|
||||||
return Framebuffer::Mode { .area = { _initial_size.width (gui.mode()),
|
return Framebuffer::Mode { .area = { _initial_size.width (_gui.mode()),
|
||||||
_initial_size.height(gui.mode()) } };
|
_initial_size.height(_gui.mode()) } };
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Input and framebuffer sessions provided to our client
|
* Input and framebuffer sessions provided to our client
|
||||||
*/
|
*/
|
||||||
Input::Session_component input_session { env, env.ram() };
|
Input::Session_component _input_session { _env, _env.ram() };
|
||||||
Framebuffer::Session_component fb_session { env.pd(), gui, *this, _initial_mode() };
|
Framebuffer::Session_component _fb_session { _env.pd(), _gui, *this, _initial_mode() };
|
||||||
|
|
||||||
Static_root<Input::Session> input_root { env.ep().manage(input_session) };
|
Static_root<Input::Session> _input_root { _env.ep().manage(_input_session) };
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Attach root interfaces to the entry point
|
* Attach root interfaces to the entry point
|
||||||
@ -301,18 +301,18 @@ struct Nit_fb::Main : View_updater
|
|||||||
|
|
||||||
Fb_root(Main &main)
|
Fb_root(Main &main)
|
||||||
:
|
:
|
||||||
Static_root<Framebuffer::Session>(main.env.ep().manage(main.fb_session)),
|
Static_root<Framebuffer::Session>(main._env.ep().manage(main._fb_session)),
|
||||||
_main(main)
|
_main(main)
|
||||||
{ }
|
{ }
|
||||||
|
|
||||||
void close(Genode::Capability<Genode::Session>) override
|
void close(Capability<Session>) override
|
||||||
{
|
{
|
||||||
_main.fb_session.sync_sigh(Genode::Signal_context_capability());
|
_main._fb_session.sync_sigh(Signal_context_capability());
|
||||||
_main.fb_session.mode_sigh(Genode::Signal_context_capability());
|
_main._fb_session.mode_sigh(Signal_context_capability());
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
Fb_root fb_root { *this };
|
Fb_root _fb_root { *this };
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* View_updater interface
|
* View_updater interface
|
||||||
@ -320,9 +320,9 @@ struct Nit_fb::Main : View_updater
|
|||||||
void update_view() override
|
void update_view() override
|
||||||
{
|
{
|
||||||
using Command = Gui::Session::Command;
|
using Command = Gui::Session::Command;
|
||||||
gui.enqueue<Command::Geometry>(view.id(), Rect(position, fb_session.size()));
|
_gui.enqueue<Command::Geometry>(_view.id(), Rect(_position, _fb_session.size()));
|
||||||
gui.enqueue<Command::Front>(view.id());
|
_gui.enqueue<Command::Front>(_view.id());
|
||||||
gui.execute();
|
_gui.execute();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -335,7 +335,7 @@ struct Nit_fb::Main : View_updater
|
|||||||
if (!config.has_attribute(attr))
|
if (!config.has_attribute(attr))
|
||||||
return Point(0, 0);
|
return Point(0, 0);
|
||||||
|
|
||||||
using Value = Genode::String<32>;
|
using Value = String<32>;
|
||||||
Value const value = config.attribute_value(attr, Value());
|
Value const value = config.attribute_value(attr, Value());
|
||||||
|
|
||||||
if (value == "top_left") return Point(0, 0);
|
if (value == "top_left") return Point(0, 0);
|
||||||
@ -349,16 +349,16 @@ struct Nit_fb::Main : View_updater
|
|||||||
|
|
||||||
void _update_size()
|
void _update_size()
|
||||||
{
|
{
|
||||||
Xml_node const config = config_rom.xml();
|
Xml_node const config = _config_rom.xml();
|
||||||
|
|
||||||
Framebuffer::Mode const gui_mode = gui.mode();
|
Framebuffer::Mode const gui_mode = _gui.mode();
|
||||||
|
|
||||||
position = _coordinate_origin(gui_mode, config) + Point::from_xml(config);
|
_position = _coordinate_origin(gui_mode, config) + Point::from_xml(config);
|
||||||
|
|
||||||
bool const attr = config.has_attribute("width") ||
|
bool const attr = config.has_attribute("width") ||
|
||||||
config.has_attribute("height");
|
config.has_attribute("height");
|
||||||
if (_initial_size.valid() && attr) {
|
if (_initial_size.valid() && attr) {
|
||||||
Genode::warning("setting both inital and normal attributes not "
|
warning("setting both inital and normal attributes not "
|
||||||
" supported, ignore initial size");
|
" supported, ignore initial size");
|
||||||
/* force initial to disable check below */
|
/* force initial to disable check below */
|
||||||
_initial_size.set = true;
|
_initial_size.set = true;
|
||||||
@ -385,39 +385,36 @@ struct Nit_fb::Main : View_updater
|
|||||||
if (height < 0) height = gui_height + height;
|
if (height < 0) height = gui_height + height;
|
||||||
}
|
}
|
||||||
|
|
||||||
fb_session.size(Area((unsigned)width, (unsigned)height));
|
_fb_session.size(Area((unsigned)width, (unsigned)height));
|
||||||
}
|
}
|
||||||
|
|
||||||
void handle_config_update()
|
void _handle_config_update()
|
||||||
{
|
{
|
||||||
config_rom.update();
|
_config_rom.update();
|
||||||
|
|
||||||
_update_size();
|
_update_size();
|
||||||
|
|
||||||
update_view();
|
update_view();
|
||||||
}
|
}
|
||||||
|
|
||||||
Signal_handler<Main> config_update_handler =
|
Signal_handler<Main> _config_update_handler =
|
||||||
{ env.ep(), *this, &Main::handle_config_update };
|
{ _env.ep(), *this, &Main::_handle_config_update };
|
||||||
|
|
||||||
void handle_mode_update()
|
void _handle_mode_update() { _update_size(); }
|
||||||
|
|
||||||
|
Signal_handler<Main> _mode_update_handler =
|
||||||
|
{ _env.ep(), *this, &Main::_handle_mode_update };
|
||||||
|
|
||||||
|
void _handle_input()
|
||||||
{
|
{
|
||||||
_update_size();
|
Input::Event const * const events = _input_ds.local_addr<Input::Event>();
|
||||||
}
|
|
||||||
|
|
||||||
Signal_handler<Main> mode_update_handler =
|
unsigned const num = _gui.input.flush();
|
||||||
{ env.ep(), *this, &Main::handle_mode_update };
|
|
||||||
|
|
||||||
void handle_input()
|
|
||||||
{
|
|
||||||
Input::Event const * const events = input_ds.local_addr<Input::Event>();
|
|
||||||
|
|
||||||
unsigned const num = gui.input.flush();
|
|
||||||
bool update = false;
|
bool update = false;
|
||||||
|
|
||||||
for (unsigned i = 0; i < num; i++) {
|
for (unsigned i = 0; i < num; i++) {
|
||||||
update |= events[i].focus_enter();
|
update |= events[i].focus_enter();
|
||||||
input_session.submit(translate_event(events[i], position, fb_session.size()));
|
_input_session.submit(translate_event(events[i], _position, _fb_session.size()));
|
||||||
}
|
}
|
||||||
|
|
||||||
/* get to front if we got input focus */
|
/* get to front if we got input focus */
|
||||||
@ -425,36 +422,35 @@ struct Nit_fb::Main : View_updater
|
|||||||
update_view();
|
update_view();
|
||||||
}
|
}
|
||||||
|
|
||||||
Signal_handler<Main> input_handler =
|
Signal_handler<Main> _input_handler { _env.ep(), *this, &Main::_handle_input };
|
||||||
{ env.ep(), *this, &Main::handle_input };
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor
|
* Constructor
|
||||||
*/
|
*/
|
||||||
Main(Genode::Env &env) : env(env)
|
Main(Env &env) : _env(env)
|
||||||
{
|
{
|
||||||
input_session.event_queue().enabled(true);
|
_input_session.event_queue().enabled(true);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Announce services
|
* Announce services
|
||||||
*/
|
*/
|
||||||
env.parent().announce(env.ep().manage(fb_root));
|
_env.parent().announce(_env.ep().manage(_fb_root));
|
||||||
env.parent().announce(env.ep().manage(input_root));
|
_env.parent().announce(_env.ep().manage(_input_root));
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Apply initial configuration
|
* Apply initial configuration
|
||||||
*/
|
*/
|
||||||
handle_config_update();
|
_handle_config_update();
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Register signal handlers
|
* Register signal handlers
|
||||||
*/
|
*/
|
||||||
config_rom.sigh(config_update_handler);
|
_config_rom.sigh(_config_update_handler);
|
||||||
gui.mode_sigh(mode_update_handler);
|
_gui.mode_sigh(_mode_update_handler);
|
||||||
gui.input.sigh(input_handler);
|
_gui.input.sigh(_input_handler);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
void Component::construct(Genode::Env &env) { static Nit_fb::Main inst(env); }
|
void Component::construct(Genode::Env &env) { static Gui_fb::Main inst(env); }
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user