2013-12-30 00:21:53 +00:00
|
|
|
/*
|
2020-06-12 09:23:57 +00:00
|
|
|
* \brief Graphics backend based on the GUI session interface
|
2013-12-30 00:21:53 +00:00
|
|
|
* \date 2013-12-30
|
|
|
|
* \author Norman Feske
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
2017-02-20 12:23:52 +00:00
|
|
|
* Copyright (C) 2013-2017 Genode Labs GmbH
|
2013-12-30 00:21:53 +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.
|
2013-12-30 00:21:53 +00:00
|
|
|
*/
|
|
|
|
|
2020-06-12 09:23:57 +00:00
|
|
|
#ifndef _INCLUDE__SCOUT__GRAPHICS_BACKEND_IMPL_H_
|
|
|
|
#define _INCLUDE__SCOUT__GRAPHICS_BACKEND_IMPL_H_
|
2013-12-30 00:21:53 +00:00
|
|
|
|
|
|
|
/* Genode includes */
|
2020-06-11 12:27:20 +00:00
|
|
|
#include <gui_session/connection.h>
|
2020-06-16 13:46:59 +00:00
|
|
|
#include <os/pixel_rgb888.h>
|
2017-01-11 15:06:26 +00:00
|
|
|
#include <base/attached_dataspace.h>
|
2013-12-30 00:21:53 +00:00
|
|
|
|
|
|
|
/* Scout includes */
|
|
|
|
#include <scout/graphics_backend.h>
|
|
|
|
|
|
|
|
|
|
|
|
namespace Scout {
|
2020-06-16 13:46:59 +00:00
|
|
|
using Genode::Pixel_rgb888;
|
2020-06-12 09:23:57 +00:00
|
|
|
class Graphics_backend_impl;
|
2013-12-30 00:21:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-06-12 09:23:57 +00:00
|
|
|
class Scout::Graphics_backend_impl : public Graphics_backend
|
2013-12-30 00:21:53 +00:00
|
|
|
{
|
|
|
|
private:
|
|
|
|
|
Follow practices suggested by "Effective C++"
The patch adjust the code of the base, base-<kernel>, and os repository.
To adapt existing components to fix violations of the best practices
suggested by "Effective C++" as reported by the -Weffc++ compiler
argument. The changes follow the patterns outlined below:
* A class with virtual functions can no longer publicly inherit base
classed without a vtable. The inherited object may either be moved
to a member variable, or inherited privately. The latter would be
used for classes that inherit 'List::Element' or 'Avl_node'. In order
to enable the 'List' and 'Avl_tree' to access the meta data, the
'List' must become a friend.
* Instead of adding a virtual destructor to abstract base classes,
we inherit the new 'Interface' class, which contains a virtual
destructor. This way, single-line abstract base classes can stay
as compact as they are now. The 'Interface' utility resides in
base/include/util/interface.h.
* With the new warnings enabled, all member variables must be explicitly
initialized. Basic types may be initialized with '='. All other types
are initialized with braces '{ ... }' or as class initializers. If
basic types and non-basic types appear in a row, it is nice to only
use the brace syntax (also for basic types) and align the braces.
* If a class contains pointers as members, it must now also provide a
copy constructor and assignment operator. In the most cases, one
would make them private, effectively disallowing the objects to be
copied. Unfortunately, this warning cannot be fixed be inheriting
our existing 'Noncopyable' class (the compiler fails to detect that
the inheriting class cannot be copied and still gives the error).
For now, we have to manually add declarations for both the copy
constructor and assignment operator as private class members. Those
declarations should be prepended with a comment like this:
/*
* Noncopyable
*/
Thread(Thread const &);
Thread &operator = (Thread const &);
In the future, we should revisit these places and try to replace
the pointers with references. In the presence of at least one
reference member, the compiler would no longer implicitly generate
a copy constructor. So we could remove the manual declaration.
Issue #465
2017-12-21 14:42:15 +00:00
|
|
|
/*
|
|
|
|
* Noncopyable
|
|
|
|
*/
|
2020-06-12 09:23:57 +00:00
|
|
|
Graphics_backend_impl(Graphics_backend_impl const &);
|
|
|
|
Graphics_backend_impl &operator = (Graphics_backend_impl const &);
|
Follow practices suggested by "Effective C++"
The patch adjust the code of the base, base-<kernel>, and os repository.
To adapt existing components to fix violations of the best practices
suggested by "Effective C++" as reported by the -Weffc++ compiler
argument. The changes follow the patterns outlined below:
* A class with virtual functions can no longer publicly inherit base
classed without a vtable. The inherited object may either be moved
to a member variable, or inherited privately. The latter would be
used for classes that inherit 'List::Element' or 'Avl_node'. In order
to enable the 'List' and 'Avl_tree' to access the meta data, the
'List' must become a friend.
* Instead of adding a virtual destructor to abstract base classes,
we inherit the new 'Interface' class, which contains a virtual
destructor. This way, single-line abstract base classes can stay
as compact as they are now. The 'Interface' utility resides in
base/include/util/interface.h.
* With the new warnings enabled, all member variables must be explicitly
initialized. Basic types may be initialized with '='. All other types
are initialized with braces '{ ... }' or as class initializers. If
basic types and non-basic types appear in a row, it is nice to only
use the brace syntax (also for basic types) and align the braces.
* If a class contains pointers as members, it must now also provide a
copy constructor and assignment operator. In the most cases, one
would make them private, effectively disallowing the objects to be
copied. Unfortunately, this warning cannot be fixed be inheriting
our existing 'Noncopyable' class (the compiler fails to detect that
the inheriting class cannot be copied and still gives the error).
For now, we have to manually add declarations for both the copy
constructor and assignment operator as private class members. Those
declarations should be prepended with a comment like this:
/*
* Noncopyable
*/
Thread(Thread const &);
Thread &operator = (Thread const &);
In the future, we should revisit these places and try to replace
the pointers with references. In the presence of at least one
reference member, the compiler would no longer implicitly generate
a copy constructor. So we could remove the manual declaration.
Issue #465
2017-12-21 14:42:15 +00:00
|
|
|
|
2017-01-11 15:06:26 +00:00
|
|
|
Genode::Region_map &_local_rm;
|
|
|
|
|
2020-06-12 09:23:57 +00:00
|
|
|
Gui::Connection &_gui;
|
2013-12-30 00:21:53 +00:00
|
|
|
|
|
|
|
Genode::Dataspace_capability _init_fb_ds(Area max_size)
|
|
|
|
{
|
2020-06-16 13:46:59 +00:00
|
|
|
Framebuffer::Mode const mode { .area = { max_size.w(), max_size.h()*2 }};
|
|
|
|
|
|
|
|
_gui.buffer(mode, false);
|
|
|
|
|
2020-06-12 09:23:57 +00:00
|
|
|
return _gui.framebuffer()->dataspace();
|
2013-12-30 00:21:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Area _max_size;
|
|
|
|
|
2017-01-11 15:06:26 +00:00
|
|
|
Genode::Attached_dataspace _fb_ds { _local_rm, _init_fb_ds(_max_size) };
|
2013-12-30 00:21:53 +00:00
|
|
|
|
2020-06-12 09:23:57 +00:00
|
|
|
typedef Gui::Session::View_handle View_handle;
|
2014-06-06 15:26:53 +00:00
|
|
|
|
|
|
|
Point _position;
|
|
|
|
Area _view_size;
|
2020-06-12 09:23:57 +00:00
|
|
|
View_handle _view { _gui.create_view() };
|
2014-06-06 15:26:53 +00:00
|
|
|
Canvas_base *_canvas[2];
|
|
|
|
bool _flip_state = { false };
|
2013-12-30 00:21:53 +00:00
|
|
|
|
|
|
|
void _update_viewport()
|
|
|
|
{
|
2020-06-12 09:23:57 +00:00
|
|
|
typedef Gui::Session::Command Command;
|
2014-06-06 15:26:53 +00:00
|
|
|
|
2020-06-12 09:23:57 +00:00
|
|
|
Gui::Rect rect(_position, _view_size);
|
|
|
|
_gui.enqueue<Command::Geometry>(_view, rect);
|
2014-06-06 15:26:53 +00:00
|
|
|
|
2020-06-12 09:23:57 +00:00
|
|
|
Gui::Point offset(0, _flip_state ? -_max_size.h() : 0);
|
|
|
|
_gui.enqueue<Command::Offset>(_view, offset);
|
2014-06-06 15:26:53 +00:00
|
|
|
|
2020-06-12 09:23:57 +00:00
|
|
|
_gui.execute();
|
2013-12-30 00:21:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void _refresh_view(Rect rect)
|
|
|
|
{
|
|
|
|
int const y_offset = _flip_state ? _max_size.h() : 0;
|
2020-06-12 09:23:57 +00:00
|
|
|
_gui.framebuffer()->refresh(rect.x1(), rect.y1() + y_offset,
|
|
|
|
rect.w(), rect.h());
|
2013-12-30 00:21:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
template <typename PT>
|
|
|
|
PT *_base(unsigned idx)
|
|
|
|
{
|
2017-01-11 15:06:26 +00:00
|
|
|
return (PT *)_fb_ds.local_addr<PT>() + idx*_max_size.count();
|
2013-12-30 00:21:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
unsigned _front_idx() const { return _flip_state ? 1 : 0; }
|
|
|
|
unsigned _back_idx() const { return _flip_state ? 0 : 1; }
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
2017-01-11 15:06:26 +00:00
|
|
|
/**
|
|
|
|
* Constructor
|
|
|
|
*
|
|
|
|
* \param alloc allocator used for allocating textures
|
|
|
|
*/
|
2020-06-12 09:23:57 +00:00
|
|
|
Graphics_backend_impl(Genode::Region_map &local_rm,
|
|
|
|
Gui::Connection &gui,
|
|
|
|
Genode::Allocator &alloc,
|
|
|
|
Area max_size, Point position, Area view_size)
|
2013-12-30 00:21:53 +00:00
|
|
|
:
|
2017-01-11 15:06:26 +00:00
|
|
|
_local_rm(local_rm),
|
2020-06-12 09:23:57 +00:00
|
|
|
_gui(gui),
|
2013-12-30 00:21:53 +00:00
|
|
|
_max_size(max_size),
|
|
|
|
_position(position),
|
2017-01-11 15:06:26 +00:00
|
|
|
_view_size(view_size)
|
2013-12-30 00:21:53 +00:00
|
|
|
{
|
|
|
|
bring_to_front();
|
|
|
|
|
2020-06-16 13:46:59 +00:00
|
|
|
typedef Genode::Pixel_rgb888 PT;
|
2017-01-11 15:06:26 +00:00
|
|
|
static Canvas<PT> canvas_0(_base<PT>(0), max_size, alloc);
|
|
|
|
static Canvas<PT> canvas_1(_base<PT>(1), max_size, alloc);
|
2013-12-30 00:21:53 +00:00
|
|
|
|
|
|
|
_canvas[0] = &canvas_0;
|
|
|
|
_canvas[1] = &canvas_1;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/********************************
|
|
|
|
** Graphics_backend interface **
|
|
|
|
********************************/
|
|
|
|
|
2017-01-11 15:06:26 +00:00
|
|
|
Canvas_base &front() override { return *_canvas[_front_idx()]; }
|
|
|
|
Canvas_base &back() override { return *_canvas[ _back_idx()]; }
|
2013-12-30 00:21:53 +00:00
|
|
|
|
2019-02-14 21:39:08 +00:00
|
|
|
void copy_back_to_front(Rect rect) override
|
2013-12-30 00:21:53 +00:00
|
|
|
{
|
|
|
|
|
2020-06-16 13:46:59 +00:00
|
|
|
typedef Genode::Pixel_rgb888 PT;
|
2013-12-30 00:21:53 +00:00
|
|
|
|
|
|
|
PT const *src = _base<PT>( _back_idx());
|
|
|
|
PT *dst = _base<PT>(_front_idx());
|
|
|
|
|
|
|
|
unsigned long const offset = rect.y1()*_max_size.w() + rect.x1();
|
|
|
|
|
|
|
|
src += offset;
|
|
|
|
dst += offset;
|
|
|
|
|
|
|
|
blit(src, sizeof(PT)*_max_size.w(),
|
|
|
|
dst, sizeof(PT)*_max_size.w(), sizeof(PT)*rect.w(), rect.h());
|
|
|
|
|
|
|
|
_refresh_view(rect);
|
|
|
|
}
|
|
|
|
|
2019-02-14 21:39:08 +00:00
|
|
|
void swap_back_and_front() override
|
2013-12-30 00:21:53 +00:00
|
|
|
{
|
|
|
|
_flip_state = !_flip_state;
|
|
|
|
_update_viewport();
|
|
|
|
}
|
|
|
|
|
2019-02-14 21:39:08 +00:00
|
|
|
void position(Point p) override
|
2013-12-30 00:21:53 +00:00
|
|
|
{
|
|
|
|
_position = p;
|
|
|
|
_update_viewport();
|
|
|
|
}
|
|
|
|
|
2019-02-14 21:39:08 +00:00
|
|
|
void bring_to_front() override
|
2013-12-30 00:21:53 +00:00
|
|
|
{
|
2020-06-12 09:23:57 +00:00
|
|
|
typedef Gui::Session::Command Command;
|
|
|
|
typedef Gui::Session::View_handle View_handle;
|
|
|
|
_gui.enqueue<Command::To_front>(_view, View_handle());
|
|
|
|
_gui.execute();
|
2013-12-30 00:21:53 +00:00
|
|
|
}
|
|
|
|
|
2019-02-14 21:39:08 +00:00
|
|
|
void view_area(Area area) override
|
2013-12-30 00:21:53 +00:00
|
|
|
{
|
|
|
|
_view_size = area;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2020-06-12 09:23:57 +00:00
|
|
|
#endif /* _INCLUDE__SCOUT__GRAPHICS_BACKEND_IMPL_H_ */
|