2011-12-22 15:19:25 +00:00
|
|
|
/*
|
2020-06-12 09:23:57 +00:00
|
|
|
* \brief Connection to GUI service
|
2011-12-22 15:19:25 +00:00
|
|
|
* \author Norman Feske
|
|
|
|
* \date 2008-08-22
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
2024-08-05 11:47:22 +00:00
|
|
|
* Copyright (C) 2008-2024 Genode Labs GmbH
|
2011-12-22 15:19:25 +00:00
|
|
|
*
|
|
|
|
* This file is part of the Genode OS framework, which is distributed
|
2017-02-20 12:23:52 +00:00
|
|
|
* under the terms of the GNU Affero General Public License version 3.
|
2011-12-22 15:19:25 +00:00
|
|
|
*/
|
|
|
|
|
2020-06-11 12:27:20 +00:00
|
|
|
#ifndef _INCLUDE__GUI_SESSION__CONNECTION_H_
|
|
|
|
#define _INCLUDE__GUI_SESSION__CONNECTION_H_
|
2011-12-22 15:19:25 +00:00
|
|
|
|
2020-06-11 12:27:20 +00:00
|
|
|
#include <gui_session/client.h>
|
2011-12-22 15:19:25 +00:00
|
|
|
#include <framebuffer_session/client.h>
|
|
|
|
#include <input_session/client.h>
|
|
|
|
#include <base/connection.h>
|
|
|
|
|
2020-06-12 09:23:57 +00:00
|
|
|
namespace Gui { class Connection; }
|
2011-12-22 15:19:25 +00:00
|
|
|
|
|
|
|
|
2024-08-05 11:47:22 +00:00
|
|
|
class Gui::Connection : private Genode::Connection<Session>
|
2013-10-14 19:31:14 +00:00
|
|
|
{
|
|
|
|
private:
|
2011-12-22 15:19:25 +00:00
|
|
|
|
2024-08-05 11:47:22 +00:00
|
|
|
Env &_env;
|
|
|
|
|
|
|
|
Session_client _client { cap() };
|
|
|
|
|
|
|
|
Attached_dataspace _command_ds { _env.rm(), _client.command_dataspace() };
|
|
|
|
|
|
|
|
using Command_buffer = Gui::Session::Command_buffer;
|
|
|
|
|
|
|
|
Command_buffer &_command_buffer { *_command_ds.local_addr<Command_buffer>() };
|
|
|
|
|
|
|
|
Framebuffer::Session_client _framebuffer { _client.framebuffer_session() };
|
|
|
|
|
|
|
|
Input::Session_client _input { _env.rm(), _client.input_session() };
|
|
|
|
|
|
|
|
Ram_quota _ram_quota { }; /* session quota donated for virtual frame buffer */
|
2013-10-14 19:31:14 +00:00
|
|
|
|
|
|
|
public:
|
|
|
|
|
2024-08-05 11:47:22 +00:00
|
|
|
using View_handle = Session::View_handle;
|
|
|
|
using Genode::Connection<Session>::cap;
|
|
|
|
using Genode::Connection<Session>::upgrade;
|
|
|
|
using Genode::Connection<Session>::upgrade_ram;
|
|
|
|
using Genode::Connection<Session>::upgrade_caps;
|
|
|
|
|
2013-10-14 19:31:14 +00:00
|
|
|
/**
|
|
|
|
* Constructor
|
|
|
|
*/
|
2024-08-05 11:47:22 +00:00
|
|
|
Connection(Env &env, Session_label const &label = { })
|
2016-05-10 15:24:51 +00:00
|
|
|
:
|
2023-03-03 11:07:28 +00:00
|
|
|
Genode::Connection<Session>(env, label, Ram_quota { 36*1024 }, Args()),
|
2024-08-05 11:47:22 +00:00
|
|
|
_env(env)
|
2016-05-10 15:24:51 +00:00
|
|
|
{ }
|
|
|
|
|
2024-08-05 11:47:22 +00:00
|
|
|
/**
|
|
|
|
* Return sub session for GUI's input service
|
|
|
|
*/
|
|
|
|
Input::Session_client *input() { return &_input; }
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Return sub session for session's frame buffer
|
|
|
|
*/
|
|
|
|
Framebuffer::Session *framebuffer() { return &_framebuffer; }
|
|
|
|
|
|
|
|
View_handle create_view()
|
|
|
|
{
|
|
|
|
View_handle result { };
|
|
|
|
for (bool retry = false; ; ) {
|
|
|
|
using Error = Session_client::Create_view_error;
|
|
|
|
_client.create_view().with_result(
|
|
|
|
[&] (View_handle handle) { result = handle; },
|
|
|
|
[&] (Error e) {
|
|
|
|
switch (e) {
|
|
|
|
case Error::OUT_OF_RAM: upgrade_ram(8*1024); retry = true; return;
|
|
|
|
case Error::OUT_OF_CAPS: upgrade_caps(2); retry = true; return;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
if (!retry)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
View_handle create_child_view(View_handle parent)
|
|
|
|
{
|
|
|
|
View_handle result { };
|
|
|
|
for (bool retry = false; ; ) {
|
|
|
|
using Error = Session_client::Create_child_view_error;
|
|
|
|
_client.create_child_view(parent).with_result(
|
|
|
|
[&] (View_handle handle) { result = handle; },
|
|
|
|
[&] (Error e) {
|
|
|
|
switch (e) {
|
|
|
|
case Error::OUT_OF_RAM: upgrade_ram(8*1024); retry = true; return;
|
|
|
|
case Error::OUT_OF_CAPS: upgrade_caps(2); retry = true; return;
|
|
|
|
case Error::INVALID: break;
|
|
|
|
}
|
|
|
|
error("failed to create child view for invalid parent view");
|
|
|
|
});
|
|
|
|
if (!retry)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
void destroy_view(View_handle view)
|
|
|
|
{
|
|
|
|
_client.destroy_view(view);
|
|
|
|
}
|
|
|
|
|
|
|
|
void release_view_handle(View_handle handle)
|
|
|
|
{
|
|
|
|
_client.release_view_handle(handle);
|
|
|
|
}
|
|
|
|
|
|
|
|
View_capability view_capability(View_handle handle)
|
|
|
|
{
|
|
|
|
return _client.view_capability(handle);
|
|
|
|
}
|
|
|
|
|
|
|
|
View_handle view_handle(View_capability view, View_handle handle = { })
|
2013-10-14 19:31:14 +00:00
|
|
|
{
|
2024-08-05 11:47:22 +00:00
|
|
|
View_handle result { };
|
|
|
|
for (bool retry = false; ; ) {
|
|
|
|
using Error = Session_client::View_handle_error;
|
|
|
|
_client.view_handle(view, handle).with_result(
|
|
|
|
[&] (View_handle handle) { result = handle; },
|
|
|
|
[&] (Error e) {
|
|
|
|
switch (e) {
|
|
|
|
case Error::OUT_OF_RAM: upgrade_ram(8*1024); retry = true; return;
|
|
|
|
case Error::OUT_OF_CAPS: upgrade_caps(2); retry = true; return;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
if (!retry)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
void buffer(Framebuffer::Mode mode, bool use_alpha)
|
|
|
|
{
|
|
|
|
size_t const needed = Session_client::ram_quota(mode, use_alpha);
|
|
|
|
size_t const upgrade = needed > _ram_quota.value
|
|
|
|
? needed - _ram_quota.value : 0u;
|
2014-06-12 10:25:38 +00:00
|
|
|
if (upgrade > 0) {
|
2016-11-06 13:27:26 +00:00
|
|
|
this->upgrade_ram(upgrade);
|
2024-08-05 11:47:22 +00:00
|
|
|
_ram_quota.value += upgrade;
|
2014-06-12 10:25:38 +00:00
|
|
|
}
|
2013-10-14 19:31:14 +00:00
|
|
|
|
2024-08-05 11:47:22 +00:00
|
|
|
for (bool retry = false; ; ) {
|
|
|
|
using Result = Session_client::Buffer_result;
|
|
|
|
auto const result = _client.buffer(mode, use_alpha);
|
|
|
|
if (result == Result::OUT_OF_RAM) { upgrade_ram(8*1024); retry = true; }
|
|
|
|
if (result == Result::OUT_OF_CAPS) { upgrade_caps(2); retry = true; }
|
|
|
|
if (!retry)
|
|
|
|
break;
|
|
|
|
}
|
2013-10-14 19:31:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2024-08-05 11:47:22 +00:00
|
|
|
* Enqueue command to command buffer
|
|
|
|
*
|
|
|
|
* The submitted command is not executed immediately. To execute a
|
|
|
|
* batch of enqueued commands, the 'execute' method must be called.
|
|
|
|
* Only in the corner case when there is not space left in the command
|
|
|
|
* buffer, the 'execute' is called to make room in the buffer.
|
2013-10-14 19:31:14 +00:00
|
|
|
*/
|
2024-08-05 11:47:22 +00:00
|
|
|
template <typename CMD>
|
|
|
|
void enqueue(auto &&... args) { enqueue(Session::Command( CMD { args... } )); }
|
2013-10-14 19:31:14 +00:00
|
|
|
|
2024-08-05 11:47:22 +00:00
|
|
|
void enqueue(Session::Command const &command)
|
|
|
|
{
|
|
|
|
if (_command_buffer.full())
|
|
|
|
execute();
|
|
|
|
|
|
|
|
_command_buffer.enqueue(command);
|
|
|
|
}
|
|
|
|
|
|
|
|
void execute()
|
|
|
|
{
|
|
|
|
_client.execute();
|
|
|
|
_command_buffer.reset();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Return physical screen mode
|
|
|
|
*/
|
|
|
|
Framebuffer::Mode mode() { return _client.mode(); }
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Register signal handler to be notified about mode changes
|
|
|
|
*/
|
|
|
|
void mode_sigh(Signal_context_capability sigh) { _client.mode_sigh(sigh); }
|
|
|
|
|
|
|
|
void focus(Capability<Session> focused) { _client.focus(focused); }
|
2013-10-14 19:31:14 +00:00
|
|
|
};
|
2011-12-22 15:19:25 +00:00
|
|
|
|
2020-06-11 12:27:20 +00:00
|
|
|
#endif /* _INCLUDE__GUI_SESSION__CONNECTION_H_ */
|