Kernel: Add ioctl to sync rectangular areas in framebuffer

msync is not really the best API for framebuffer synchronization
This commit is contained in:
2026-04-11 08:29:10 +03:00
parent 2b97587e9f
commit ac6e6f3ec1
3 changed files with 32 additions and 0 deletions

View File

@@ -37,6 +37,8 @@ namespace Kernel
virtual BAN::ErrorOr<size_t> read_impl(off_t, BAN::ByteSpan) override;
virtual BAN::ErrorOr<size_t> write_impl(off_t, BAN::ConstByteSpan) override;
BAN::ErrorOr<long> ioctl_impl(int cmd, void* arg) override;
virtual bool can_read_impl() const override { return true; }
virtual bool can_write_impl() const override { return true; }
virtual bool has_error_impl() const override { return false; }

View File

@@ -6,6 +6,7 @@
#include <kernel/Terminal/FramebufferTerminal.h>
#include <sys/framebuffer.h>
#include <sys/ioctl.h>
#include <sys/mman.h>
#include <sys/sysmacros.h>
@@ -133,6 +134,26 @@ namespace Kernel
return bytes_to_copy;
}
BAN::ErrorOr<long> FramebufferDevice::ioctl_impl(int cmd, void* arg)
{
switch (cmd)
{
case FB_MSYNC_RECTANGLE:
{
auto& rectangle = *static_cast<fb_msync_region*>(arg);
sync_pixels_rectangle(
rectangle.min_x,
rectangle.min_y,
rectangle.max_x - rectangle.min_x,
rectangle.max_y - rectangle.min_y
);
return 0;
}
}
return CharacterDevice::ioctl(cmd, arg);
}
uint32_t FramebufferDevice::get_pixel(uint32_t x, uint32_t y) const
{
ASSERT(x < m_width && y < m_height);

View File

@@ -74,6 +74,15 @@ struct snd_volume_info
#define JOYSTICK_GET_RUMBLE 82 /* get controller rumble strength to uint8_t argument */
#define JOYSTICK_SET_RUMBLE 83 /* set controller rumble strength to uint8_t argument */
struct fb_msync_region
{
uint32_t min_x;
uint32_t min_y;
uint32_t max_x;
uint32_t max_y;
};
#define FB_MSYNC_RECTANGLE 90 /* msync a rectangular area in mmap'd framebuffer device */
int ioctl(int, int, ...);
__END_DECLS