menu_view: API transition

Issue #1987
This commit is contained in:
Norman Feske 2017-01-11 19:13:04 +01:00
parent 81862a41e1
commit 7180851b2f
5 changed files with 110 additions and 31 deletions

View File

@ -44,6 +44,7 @@ struct Nitpicker_buffer
typedef Genode::Attached_ram_dataspace Ram_ds;
Genode::Ram_session &ram;
Genode::Region_map &rm;
Nitpicker::Connection &nitpicker;
@ -65,7 +66,7 @@ struct Nitpicker_buffer
return nitpicker.framebuffer()->dataspace();
}
Genode::Attached_dataspace fb_ds { _ds_cap(nitpicker) };
Genode::Attached_dataspace fb_ds { rm, _ds_cap(nitpicker) };
Genode::size_t pixel_surface_num_bytes() const
{
@ -77,16 +78,30 @@ struct Nitpicker_buffer
return size().count();
}
Ram_ds pixel_surface_ds { &ram, pixel_surface_num_bytes() };
Ram_ds alpha_surface_ds { &ram, alpha_surface_num_bytes() };
Ram_ds pixel_surface_ds { ram, rm, pixel_surface_num_bytes() };
Ram_ds alpha_surface_ds { ram, rm, alpha_surface_num_bytes() };
/**
* Constructor
*/
Nitpicker_buffer(Nitpicker::Connection &nitpicker, Area size,
Genode::Ram_session &ram)
Genode::Ram_session &ram, Genode::Region_map &rm)
:
ram(ram), nitpicker(nitpicker),
ram(ram), rm(rm), nitpicker(nitpicker),
mode(Genode::max(1UL, size.w()), Genode::max(1UL, size.h()),
nitpicker.mode().format())
{ }
/**
* Constructor
*
* \deprecated
* \noapi
*/
Nitpicker_buffer(Nitpicker::Connection &nitpicker, Area size,
Genode::Ram_session &ram) __attribute__((deprecated))
:
ram(ram), rm(*Genode::env_deprecated()->rm_session()), nitpicker(nitpicker),
mode(Genode::max(1UL, size.w()), Genode::max(1UL, size.h()),
nitpicker.mode().format())
{ }

View File

@ -45,6 +45,10 @@ class Png_image
return arg;
};
Genode::Ram_session &_ram;
Genode::Region_map &_rm;
Genode::Allocator &_alloc;
struct Read_struct
{
/* start of PNG data */
@ -114,20 +118,22 @@ class Png_image
struct Row
{
Genode::Allocator &alloc;
size_t const row_num_bytes;
png_bytep const row_ptr;
Row(png_structp png_ptr, png_infop info_ptr)
Row(Genode::Allocator &alloc, png_structp png_ptr, png_infop info_ptr)
:
alloc(alloc),
row_num_bytes(png_get_rowbytes(png_ptr, info_ptr)*8),
row_ptr((png_bytep)Genode::env()->heap()->alloc(row_num_bytes))
row_ptr((png_bytep)alloc.alloc(row_num_bytes))
{ }
~Row()
{
Genode::env()->heap()->free(row_ptr, row_num_bytes);
alloc.free(row_ptr, row_num_bytes);
}
} _row { _read_struct.png_ptr, _info.info_ptr };
} _row { _alloc, _read_struct.png_ptr, _info.info_ptr };
public:
@ -137,7 +143,25 @@ class Png_image
* \throw Read_struct_failed
* \throw Info_failed
*/
Png_image(void *data) : _read_struct(data) { }
Png_image(Genode::Ram_session &ram, Genode::Region_map &rm,
Genode::Allocator &alloc, void *data)
:
_ram(ram), _rm(rm), _alloc(alloc), _read_struct(data)
{ }
/**
* Constructor
*
* \deprecated
* \noapi
*/
Png_image(void *data) __attribute__((deprecated))
:
_ram(*Genode::env_deprecated()->ram_session()),
_rm(*Genode::env_deprecated()->rm_session()),
_alloc(*Genode::env_deprecated()->heap()),
_read_struct(data)
{ }
/**
* Return size of PNG image
@ -153,8 +177,8 @@ class Png_image
template <typename PT>
Genode::Texture<PT> *texture()
{
Genode::Texture<PT> *texture = new (Genode::env()->heap())
Chunky_texture<PT>(*Genode::env()->ram_session(), size());
Genode::Texture<PT> *texture = new (_alloc)
Chunky_texture<PT>(_ram, _rm, size());
/* fill texture with PNG image data */
for (unsigned i = 0; i < size().h(); i++) {
@ -174,7 +198,7 @@ class Png_image
Chunky_texture<PT> *chunky_texture =
static_cast<Chunky_texture<PT> *>(texture);
Genode::destroy(Genode::env()->heap(), chunky_texture);
Genode::destroy(_alloc, chunky_texture);
}
};

View File

@ -17,14 +17,15 @@
#include <os/texture.h>
template <typename PT>
static void scale(Genode::Texture<PT> const &src, Genode::Texture<PT> &dst)
static void scale(Genode::Texture<PT> const &src, Genode::Texture<PT> &dst,
Genode::Allocator &alloc)
{
/* sanity check to prevent division by zero */
if (dst.size().count() == 0)
return;
Genode::size_t const row_num_bytes = dst.size().w()*4;
unsigned char *row = (unsigned char *)Genode::env()->heap()->alloc(row_num_bytes);
unsigned char *row = (unsigned char *)alloc.alloc(row_num_bytes);
unsigned const mx = (src.size().w() << 16) / dst.size().w();
unsigned const my = (src.size().h() << 16) / dst.size().h();
@ -53,21 +54,34 @@ static void scale(Genode::Texture<PT> const &src, Genode::Texture<PT> &dst)
dst.rgba(row, dst.size().w(), y);
}
Genode::env()->heap()->free(row, row_num_bytes);
alloc.free(row, row_num_bytes);
}
/*
* \deprecated
*/
template <typename PT>
static void scale(Genode::Texture<PT> const &src, Genode::Texture<PT> &dst) __attribute__ ((deprecated));
template <typename PT>
static void scale(Genode::Texture<PT> const &src, Genode::Texture<PT> &dst)
{
scale(src, dst, *Genode::env_deprecated()->heap());
}
template <typename SRC_PT, typename DST_PT>
static void convert_pixel_format(Genode::Texture<SRC_PT> const &src,
Genode::Texture<DST_PT> &dst,
unsigned alpha)
unsigned alpha,
Genode::Allocator &alloc)
{
/* sanity check */
if (src.size() != dst.size())
return;
Genode::size_t const row_num_bytes = dst.size().w()*4;
unsigned char *row = (unsigned char *)Genode::env()->heap()->alloc(row_num_bytes);
unsigned char *row = (unsigned char *)alloc.alloc(row_num_bytes);
/* shortcuts */
unsigned const w = dst.size().w(), h = dst.size().h();
@ -91,7 +105,23 @@ static void convert_pixel_format(Genode::Texture<SRC_PT> const &src,
dst.rgba(row, w, y);
}
Genode::env()->heap()->free(row, row_num_bytes);
alloc.free(row, row_num_bytes);
}
/*
* deprecated
*/
template <typename SRC_PT, typename DST_PT>
static void convert_pixel_format(Genode::Texture<SRC_PT> const &src,
Genode::Texture<DST_PT> &dst,
unsigned alpha) __attribute__((deprecated));
template <typename SRC_PT, typename DST_PT>
static void convert_pixel_format(Genode::Texture<SRC_PT> const &src,
Genode::Texture<DST_PT> &dst,
unsigned alpha)
{
convert_pixel_format(src, dst, alpha, *Genode::env_deprecated()->heap());
}
#endif /* _INCLUDE__GEMS__TEXTURE_UTILS_H_ */

View File

@ -59,19 +59,19 @@ struct Menu_view::Main
Signal_handler<Main> _dialog_update_handler = {
_env.ep(), *this, &Main::_handle_dialog_update};
Style_database _styles;
Heap _heap { _env.ram(), _env.rm() };
Style_database _styles { _env.ram(), _env.rm(), _heap };
Animator _animator;
Heap _heap { _env.ram(), _env.rm() };
Widget_factory _widget_factory { _heap, _styles, _animator };
Root_widget _root_widget { _widget_factory, Xml_node("<dialog/>"), Widget::Unique_id() };
Attached_rom_dataspace _dialog_rom { _env, "dialog" };
Attached_dataspace _input_ds { _nitpicker.input()->dataspace() };
Attached_dataspace _input_ds { _env.rm(), _nitpicker.input()->dataspace() };
Widget::Unique_id _hovered;
@ -107,7 +107,7 @@ struct Menu_view::Main
Signal_handler<Main> _frame_timer_handler = {
_env.ep(), *this, &Main::_handle_frame_timer};
Genode::Reporter _hover_reporter = { "hover" };
Genode::Reporter _hover_reporter = { _env, "hover" };
bool _schedule_redraw = false;
@ -254,7 +254,7 @@ void Menu_view::Main::_handle_frame_timer()
Area const size = _root_widget.min_size();
if (!_buffer.constructed() || size != old_size)
_buffer.construct(_nitpicker, size, _env.ram());
_buffer.construct(_nitpicker, size, _env.ram(), _env.rm());
else
_buffer->reset_surface();

View File

@ -42,11 +42,12 @@ class Menu_view::Style_database
*
* \throw Reading_failed
*/
Texture_entry(char const *path, Allocator &alloc)
Texture_entry(Ram_session &ram, Region_map &rm,
Allocator &alloc, char const *path)
:
path(path),
png_file(path, alloc),
png_image(png_file.data<void>()),
png_image(ram, rm, alloc, png_file.data<void>()),
texture(*png_image.texture<Pixel_rgb888>())
{ }
};
@ -70,6 +71,10 @@ class Menu_view::Style_database
{ }
};
Ram_session &_ram;
Region_map &_rm;
Allocator &_alloc;
/*
* The list is mutable because it is populated as a side effect of
* calling the const lookup function.
@ -103,6 +108,11 @@ class Menu_view::Style_database
public:
Style_database(Ram_session &ram, Region_map &rm, Allocator &alloc)
:
_ram(ram), _rm(rm), _alloc(alloc)
{ }
Texture<Pixel_rgb888> const *texture(Xml_node node, char const *png_name) const
{
Path const path = _construct_path(node, png_name, "png");
@ -114,8 +124,8 @@ class Menu_view::Style_database
* Load and remember PNG image
*/
try {
Texture_entry *e = new (env()->heap())
Texture_entry(path.string(), *env()->heap());
Texture_entry *e = new (_alloc)
Texture_entry(_ram, _rm, _alloc, path.string());
_textures.insert(e);
return &e->texture;
@ -140,8 +150,8 @@ class Menu_view::Style_database
* Load and remember font
*/
try {
Font_entry *e = new (env()->heap())
Font_entry(path.string(), *env()->heap());
Font_entry *e = new (_alloc)
Font_entry(path.string(), _alloc);
_fonts.insert(e);
return &e->font;