1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 05:57:44 +00:00

Kernel: Make FrameBufferDevice::try_to_set_resolution() return KResult

This commit is contained in:
Andreas Kling 2021-10-22 01:21:34 +02:00
parent 21bfa02dd2
commit 4ffee78146
3 changed files with 6 additions and 10 deletions

View file

@ -45,7 +45,7 @@ Console::Console(RefPtr<FrameBufferDevice> const& framebuffer_device)
void Console::set_resolution(size_t width, size_t height, size_t) void Console::set_resolution(size_t width, size_t height, size_t)
{ {
auto did_set_resolution = m_framebuffer_device->try_to_set_resolution(width, height); auto did_set_resolution = m_framebuffer_device->try_to_set_resolution(width, height);
VERIFY(did_set_resolution); VERIFY(!did_set_resolution.is_error());
} }
void Console::flush(size_t x, size_t y, size_t width, size_t height) void Console::flush(size_t x, size_t y, size_t width, size_t height)

View file

@ -114,10 +114,10 @@ void FrameBufferDevice::flush_displayed_image(Protocol::Rect const& dirty_rect,
m_gpu.flush_displayed_image(dirty_rect, buffer.resource_id); m_gpu.flush_displayed_image(dirty_rect, buffer.resource_id);
} }
bool FrameBufferDevice::try_to_set_resolution(size_t width, size_t height) KResult FrameBufferDevice::try_to_set_resolution(size_t width, size_t height)
{ {
if (width > MAX_VIRTIOGPU_RESOLUTION_WIDTH || height > MAX_VIRTIOGPU_RESOLUTION_HEIGHT) if (width > MAX_VIRTIOGPU_RESOLUTION_WIDTH || height > MAX_VIRTIOGPU_RESOLUTION_HEIGHT)
return false; return EINVAL;
auto& info = display_info(); auto& info = display_info();
@ -130,10 +130,7 @@ bool FrameBufferDevice::try_to_set_resolution(size_t width, size_t height)
.height = (u32)height, .height = (u32)height,
}; };
// FIXME: Would be nice to be able to return KResultOr here. return create_framebuffer();
if (auto result = create_framebuffer(); result.is_error())
return false;
return true;
} }
void FrameBufferDevice::set_buffer(int buffer_index) void FrameBufferDevice::set_buffer(int buffer_index)
@ -161,8 +158,7 @@ KResult FrameBufferDevice::ioctl(OpenFileDescription&, unsigned request, Userspa
auto user_resolution = static_ptr_cast<FBResolution*>(arg); auto user_resolution = static_ptr_cast<FBResolution*>(arg);
FBResolution resolution; FBResolution resolution;
TRY(copy_from_user(&resolution, user_resolution)); TRY(copy_from_user(&resolution, user_resolution));
if (!try_to_set_resolution(resolution.width, resolution.height)) TRY(try_to_set_resolution(resolution.width, resolution.height));
return EINVAL;
resolution.pitch = pitch(); resolution.pitch = pitch();
return copy_to_user(user_resolution, &resolution); return copy_to_user(user_resolution, &resolution);
} }

View file

@ -29,7 +29,7 @@ public:
virtual void deactivate_writes(); virtual void deactivate_writes();
virtual void activate_writes(); virtual void activate_writes();
bool try_to_set_resolution(size_t width, size_t height); KResult try_to_set_resolution(size_t width, size_t height);
void clear_to_black(Buffer&); void clear_to_black(Buffer&);
size_t width() const { return display_info().rect.width; } size_t width() const { return display_info().rect.width; }