vfs/ttf: support for watching font-size changes

This patch allows the use of the VFS watch mechanism for the glyph file
of the TTF VFS plugin so that clients become able to dynamically respond
to font reconfigurations.

Issue #3875
This commit is contained in:
Norman Feske 2020-09-07 15:55:30 +02:00 committed by Christian Helmuth
parent 3031fd2a7d
commit 4aca94b08b
2 changed files with 41 additions and 2 deletions

View File

@ -109,6 +109,11 @@ class Vfs::Glyphs_file_system : public Vfs::Single_file_system
bool read_ready() override { return true; }
};
typedef Registered<Vfs_watch_handle> Registered_watch_handle;
typedef Registry<Registered_watch_handle> Watch_handle_registry;
Watch_handle_registry _handle_registry { };
public:
Glyphs_file_system(Font const &font)
@ -123,6 +128,16 @@ class Vfs::Glyphs_file_system : public Vfs::Single_file_system
char const *type() override { return type_name(); }
/**
* Propagate font change to watch handlers
*/
void trigger_watch_response()
{
_handle_registry.for_each([this] (Registered_watch_handle &handle) {
handle.watch_response(); });
}
/*********************************
** Directory-service interface **
*********************************/
@ -139,8 +154,8 @@ class Vfs::Glyphs_file_system : public Vfs::Single_file_system
Vfs_handle(*this, *this, alloc, _font);
return OPEN_OK;
}
catch (Genode::Out_of_ram) { return OPEN_ERR_OUT_OF_RAM; }
catch (Genode::Out_of_caps) { return OPEN_ERR_OUT_OF_CAPS; }
catch (Out_of_ram) { return OPEN_ERR_OUT_OF_RAM; }
catch (Out_of_caps) { return OPEN_ERR_OUT_OF_CAPS; }
}
Stat_result stat(char const *path, Stat &out) override
@ -149,6 +164,29 @@ class Vfs::Glyphs_file_system : public Vfs::Single_file_system
out.size = FILE_SIZE;
return result;
}
Watch_result watch(char const *path,
Vfs_watch_handle **handle,
Allocator &alloc) override
{
if (!_single_file(path))
return WATCH_ERR_UNACCESSIBLE;
try {
*handle = new (alloc)
Registered_watch_handle(_handle_registry, *this, alloc);
return WATCH_OK;
}
catch (Out_of_ram) { return WATCH_ERR_OUT_OF_RAM; }
catch (Out_of_caps) { return WATCH_ERR_OUT_OF_CAPS; }
}
void close(Vfs_watch_handle *handle) override
{
destroy(handle->alloc(),
static_cast<Registered_watch_handle *>(handle));
}
};
#endif /* _GLYPHS_FILE_SYSTEM_H_ */

View File

@ -127,6 +127,7 @@ struct Vfs_ttf::Local_factory : File_system_factory
{
_font.construct(_env, config);
_update_attributes();
_glyphs_fs.trigger_watch_response();
}
};