mirror of
https://github.com/RGBCube/serenity
synced 2025-07-28 04:07:46 +00:00
Kernel: Replace KResult and KResultOr<T> with Error and ErrorOr<T>
We now use AK::Error and AK::ErrorOr<T> in both kernel and userspace! This was a slightly tedious refactoring that took a long time, so it's not unlikely that some bugs crept in. Nevertheless, it does pass basic functionality testing, and it's just real nice to finally see the same pattern in all contexts. :^)
This commit is contained in:
parent
7ee10c6926
commit
79fa9765ca
262 changed files with 2415 additions and 2600 deletions
|
@ -128,7 +128,7 @@ UNMAP_AFTER_INIT void BochsGraphicsAdapter::initialize_framebuffer_devices()
|
|||
{
|
||||
// FIXME: Find a better way to determine default resolution...
|
||||
m_framebuffer_device = FramebufferDevice::create(*this, PhysicalAddress(PCI::get_BAR0(pci_address()) & 0xfffffff0), 1024, 768, 1024 * sizeof(u32));
|
||||
// FIXME: Would be nice to be able to return a KResult here.
|
||||
// FIXME: Would be nice to be able to return a ErrorOr<void> here.
|
||||
VERIFY(!m_framebuffer_device->try_to_initialize().is_error());
|
||||
}
|
||||
|
||||
|
|
|
@ -27,7 +27,7 @@ NonnullRefPtr<FramebufferDevice> FramebufferDevice::create(const GenericGraphics
|
|||
return framebuffer_device_or_error.release_value();
|
||||
}
|
||||
|
||||
KResultOr<Memory::Region*> FramebufferDevice::mmap(Process& process, OpenFileDescription&, Memory::VirtualRange const& range, u64 offset, int prot, bool shared)
|
||||
ErrorOr<Memory::Region*> FramebufferDevice::mmap(Process& process, OpenFileDescription&, Memory::VirtualRange const& range, u64 offset, int prot, bool shared)
|
||||
{
|
||||
SpinlockLocker lock(m_activation_lock);
|
||||
REQUIRE_PROMISE(video);
|
||||
|
@ -92,7 +92,7 @@ void FramebufferDevice::activate_writes()
|
|||
m_graphical_writes_enabled = true;
|
||||
}
|
||||
|
||||
UNMAP_AFTER_INIT KResult FramebufferDevice::try_to_initialize()
|
||||
UNMAP_AFTER_INIT ErrorOr<void> FramebufferDevice::try_to_initialize()
|
||||
{
|
||||
// FIXME: Would be nice to be able to unify this with mmap above, but this
|
||||
// function is UNMAP_AFTER_INIT for the time being.
|
||||
|
@ -101,7 +101,7 @@ UNMAP_AFTER_INIT KResult FramebufferDevice::try_to_initialize()
|
|||
m_swapped_framebuffer_vmobject = TRY(Memory::AnonymousVMObject::try_create_with_size(Memory::page_round_up(framebuffer_length), AllocationStrategy::AllocateNow));
|
||||
m_real_framebuffer_region = TRY(MM.allocate_kernel_region_with_vmobject(*m_real_framebuffer_vmobject, Memory::page_round_up(framebuffer_length), "Framebuffer", Memory::Region::Access::ReadWrite));
|
||||
m_swapped_framebuffer_region = TRY(MM.allocate_kernel_region_with_vmobject(*m_swapped_framebuffer_vmobject, Memory::page_round_up(framebuffer_length), "Framebuffer Swap (Blank)", Memory::Region::Access::ReadWrite));
|
||||
return KSuccess;
|
||||
return {};
|
||||
}
|
||||
|
||||
UNMAP_AFTER_INIT FramebufferDevice::FramebufferDevice(const GenericGraphicsAdapter& adapter, PhysicalAddress addr, size_t width, size_t height, size_t pitch)
|
||||
|
@ -118,7 +118,7 @@ UNMAP_AFTER_INIT FramebufferDevice::FramebufferDevice(const GenericGraphicsAdapt
|
|||
dbgln("Framebuffer {}: address={}, pitch={}, width={}, height={}", minor(), addr, pitch, width, height);
|
||||
}
|
||||
|
||||
KResultOr<size_t> FramebufferDevice::buffer_length(size_t head) const
|
||||
ErrorOr<size_t> FramebufferDevice::buffer_length(size_t head) const
|
||||
{
|
||||
// Note: This FramebufferDevice class doesn't support multihead setup.
|
||||
// We take care to verify this at the GenericFramebufferDevice::ioctl method
|
||||
|
@ -127,13 +127,13 @@ KResultOr<size_t> FramebufferDevice::buffer_length(size_t head) const
|
|||
MutexLocker locker(m_resolution_lock);
|
||||
auto adapter = m_graphics_adapter.strong_ref();
|
||||
if (!adapter)
|
||||
return KResult(EIO);
|
||||
return Error::from_errno(EIO);
|
||||
if (adapter->double_framebuffering_capable())
|
||||
return m_framebuffer_pitch * m_framebuffer_height * 2;
|
||||
return m_framebuffer_pitch * m_framebuffer_height;
|
||||
}
|
||||
|
||||
KResultOr<size_t> FramebufferDevice::pitch(size_t head) const
|
||||
ErrorOr<size_t> FramebufferDevice::pitch(size_t head) const
|
||||
{
|
||||
// Note: This FramebufferDevice class doesn't support multihead setup.
|
||||
// We take care to verify this at the GenericFramebufferDevice::ioctl method
|
||||
|
@ -142,7 +142,7 @@ KResultOr<size_t> FramebufferDevice::pitch(size_t head) const
|
|||
MutexLocker locker(m_resolution_lock);
|
||||
return m_framebuffer_pitch;
|
||||
}
|
||||
KResultOr<size_t> FramebufferDevice::height(size_t head) const
|
||||
ErrorOr<size_t> FramebufferDevice::height(size_t head) const
|
||||
{
|
||||
// Note: This FramebufferDevice class doesn't support multihead setup.
|
||||
// We take care to verify this at the GenericFramebufferDevice::ioctl method
|
||||
|
@ -151,7 +151,7 @@ KResultOr<size_t> FramebufferDevice::height(size_t head) const
|
|||
MutexLocker locker(m_resolution_lock);
|
||||
return m_framebuffer_height;
|
||||
}
|
||||
KResultOr<size_t> FramebufferDevice::width(size_t head) const
|
||||
ErrorOr<size_t> FramebufferDevice::width(size_t head) const
|
||||
{
|
||||
// Note: This FramebufferDevice class doesn't support multihead setup.
|
||||
// We take care to verify this at the GenericFramebufferDevice::ioctl method
|
||||
|
@ -160,7 +160,7 @@ KResultOr<size_t> FramebufferDevice::width(size_t head) const
|
|||
MutexLocker locker(m_resolution_lock);
|
||||
return m_framebuffer_width;
|
||||
}
|
||||
KResultOr<size_t> FramebufferDevice::vertical_offset(size_t head) const
|
||||
ErrorOr<size_t> FramebufferDevice::vertical_offset(size_t head) const
|
||||
{
|
||||
// Note: This FramebufferDevice class doesn't support multihead setup.
|
||||
// We take care to verify this at the GenericFramebufferDevice::ioctl method
|
||||
|
@ -169,7 +169,7 @@ KResultOr<size_t> FramebufferDevice::vertical_offset(size_t head) const
|
|||
MutexLocker locker(m_buffer_offset_lock);
|
||||
return m_y_offset;
|
||||
}
|
||||
KResultOr<bool> FramebufferDevice::vertical_offseted(size_t head) const
|
||||
ErrorOr<bool> FramebufferDevice::vertical_offseted(size_t head) const
|
||||
{
|
||||
// Note: This FramebufferDevice class doesn't support multihead setup.
|
||||
// We take care to verify this at the GenericFramebufferDevice::ioctl method
|
||||
|
@ -179,7 +179,7 @@ KResultOr<bool> FramebufferDevice::vertical_offseted(size_t head) const
|
|||
return m_y_offset == 0 ? 0 : 1;
|
||||
}
|
||||
|
||||
KResult FramebufferDevice::set_head_resolution(size_t head, size_t width, size_t height, size_t)
|
||||
ErrorOr<void> FramebufferDevice::set_head_resolution(size_t head, size_t width, size_t height, size_t)
|
||||
{
|
||||
// Note: This FramebufferDevice class doesn't support multihead setup.
|
||||
// We take care to verify this at the GenericFramebufferDevice::ioctl method
|
||||
|
@ -189,17 +189,17 @@ KResult FramebufferDevice::set_head_resolution(size_t head, size_t width, size_t
|
|||
MutexLocker resolution_locker(m_resolution_lock);
|
||||
auto adapter = m_graphics_adapter.strong_ref();
|
||||
if (!adapter)
|
||||
return KResult(EIO);
|
||||
return Error::from_errno(EIO);
|
||||
auto result = adapter->try_to_set_resolution(0, width, height);
|
||||
// FIXME: Find a better way to return here a KResult.
|
||||
// FIXME: Find a better way to return here a ErrorOr<void>.
|
||||
if (!result)
|
||||
return KResult(ENOTSUP);
|
||||
return Error::from_errno(ENOTSUP);
|
||||
m_framebuffer_width = width;
|
||||
m_framebuffer_height = height;
|
||||
m_framebuffer_pitch = width * sizeof(u32);
|
||||
return KSuccess;
|
||||
return {};
|
||||
}
|
||||
KResult FramebufferDevice::set_head_buffer(size_t head, bool second_buffer)
|
||||
ErrorOr<void> FramebufferDevice::set_head_buffer(size_t head, bool second_buffer)
|
||||
{
|
||||
// Note: This FramebufferDevice class doesn't support multihead setup.
|
||||
// We take care to verify this at the GenericFramebufferDevice::ioctl method
|
||||
|
@ -208,30 +208,30 @@ KResult FramebufferDevice::set_head_buffer(size_t head, bool second_buffer)
|
|||
MutexLocker locker(m_buffer_offset_lock);
|
||||
auto adapter = m_graphics_adapter.strong_ref();
|
||||
if (!adapter)
|
||||
return KResult(EIO);
|
||||
return Error::from_errno(EIO);
|
||||
if (second_buffer) {
|
||||
if (!adapter->set_y_offset(0, m_framebuffer_height)) {
|
||||
// FIXME: Find a better KResult here.
|
||||
return KResult(ENOTSUP);
|
||||
// FIXME: Find a better ErrorOr<void> here.
|
||||
return Error::from_errno(ENOTSUP);
|
||||
}
|
||||
m_y_offset = m_framebuffer_height;
|
||||
} else {
|
||||
if (!adapter->set_y_offset(0, 0)) {
|
||||
// FIXME: Find a better KResult here.
|
||||
return KResult(ENOTSUP);
|
||||
// FIXME: Find a better ErrorOr<void> here.
|
||||
return Error::from_errno(ENOTSUP);
|
||||
}
|
||||
m_y_offset = 0;
|
||||
}
|
||||
return KSuccess;
|
||||
return {};
|
||||
}
|
||||
KResult FramebufferDevice::flush_head_buffer(size_t)
|
||||
ErrorOr<void> FramebufferDevice::flush_head_buffer(size_t)
|
||||
{
|
||||
// Note: This FramebufferDevice class doesn't support flushing.
|
||||
// We take care to verify this at the GenericFramebufferDevice::ioctl method
|
||||
// so if we happen to accidentally reach this code, assert.
|
||||
VERIFY_NOT_REACHED();
|
||||
}
|
||||
KResult FramebufferDevice::flush_rectangle(size_t, FBRect const&)
|
||||
ErrorOr<void> FramebufferDevice::flush_rectangle(size_t, FBRect const&)
|
||||
{
|
||||
// Note: This FramebufferDevice class doesn't support partial flushing.
|
||||
// We take care to verify this at the GenericFramebufferDevice::ioctl method
|
||||
|
|
|
@ -24,29 +24,29 @@ class FramebufferDevice final : public GenericFramebufferDevice {
|
|||
public:
|
||||
static NonnullRefPtr<FramebufferDevice> create(const GenericGraphicsAdapter&, PhysicalAddress, size_t, size_t, size_t);
|
||||
|
||||
virtual KResultOr<Memory::Region*> mmap(Process&, OpenFileDescription&, Memory::VirtualRange const&, u64 offset, int prot, bool shared) override;
|
||||
virtual ErrorOr<Memory::Region*> mmap(Process&, OpenFileDescription&, Memory::VirtualRange const&, u64 offset, int prot, bool shared) override;
|
||||
|
||||
virtual void deactivate_writes() override;
|
||||
virtual void activate_writes() override;
|
||||
|
||||
virtual KResult try_to_initialize() override;
|
||||
virtual ErrorOr<void> try_to_initialize() override;
|
||||
|
||||
virtual bool multihead_support() const override { return false; }
|
||||
virtual bool flushing_support() const override { return false; }
|
||||
virtual bool partial_flushing_support() const override { return false; }
|
||||
virtual size_t heads_count() const override { return 1; }
|
||||
virtual KResultOr<size_t> buffer_length(size_t head) const override;
|
||||
virtual KResultOr<size_t> pitch(size_t head) const override;
|
||||
virtual KResultOr<size_t> height(size_t head) const override;
|
||||
virtual KResultOr<size_t> width(size_t head) const override;
|
||||
virtual KResultOr<size_t> vertical_offset(size_t head) const override;
|
||||
virtual KResultOr<bool> vertical_offseted(size_t head) const override;
|
||||
virtual ErrorOr<size_t> buffer_length(size_t head) const override;
|
||||
virtual ErrorOr<size_t> pitch(size_t head) const override;
|
||||
virtual ErrorOr<size_t> height(size_t head) const override;
|
||||
virtual ErrorOr<size_t> width(size_t head) const override;
|
||||
virtual ErrorOr<size_t> vertical_offset(size_t head) const override;
|
||||
virtual ErrorOr<bool> vertical_offseted(size_t head) const override;
|
||||
|
||||
private:
|
||||
virtual KResult set_head_resolution(size_t head, size_t width, size_t height, size_t pitch) override;
|
||||
virtual KResult set_head_buffer(size_t head, bool second_buffer) override;
|
||||
virtual KResult flush_head_buffer(size_t head) override;
|
||||
virtual KResult flush_rectangle(size_t head, FBRect const&) override;
|
||||
virtual ErrorOr<void> set_head_resolution(size_t head, size_t width, size_t height, size_t pitch) override;
|
||||
virtual ErrorOr<void> set_head_buffer(size_t head, bool second_buffer) override;
|
||||
virtual ErrorOr<void> flush_head_buffer(size_t head) override;
|
||||
virtual ErrorOr<void> flush_rectangle(size_t head, FBRect const&) override;
|
||||
|
||||
FramebufferDevice(const GenericGraphicsAdapter&, PhysicalAddress, size_t, size_t, size_t);
|
||||
|
||||
|
|
|
@ -22,16 +22,16 @@
|
|||
|
||||
namespace Kernel {
|
||||
|
||||
KResult GenericFramebufferDevice::verify_head_index(int head_index) const
|
||||
ErrorOr<void> GenericFramebufferDevice::verify_head_index(int head_index) const
|
||||
{
|
||||
if (head_index < 0)
|
||||
return KResult(EINVAL);
|
||||
return Error::from_errno(EINVAL);
|
||||
if (!multihead_support() && head_index > 0)
|
||||
return KResult(ENOTSUP);
|
||||
return KSuccess;
|
||||
return Error::from_errno(ENOTSUP);
|
||||
return {};
|
||||
}
|
||||
|
||||
KResult GenericFramebufferDevice::ioctl(OpenFileDescription&, unsigned request, Userspace<void*> arg)
|
||||
ErrorOr<void> GenericFramebufferDevice::ioctl(OpenFileDescription&, unsigned request, Userspace<void*> arg)
|
||||
{
|
||||
REQUIRE_PROMISE(video);
|
||||
switch (request) {
|
||||
|
@ -40,7 +40,7 @@ KResult GenericFramebufferDevice::ioctl(OpenFileDescription&, unsigned request,
|
|||
FBProperties properties;
|
||||
auto adapter = m_graphics_adapter.strong_ref();
|
||||
if (!adapter)
|
||||
return KResult(EIO);
|
||||
return Error::from_errno(EIO);
|
||||
properties.multihead_support = multihead_support();
|
||||
properties.flushing_support = flushing_support();
|
||||
properties.doublebuffer_support = adapter->double_framebuffering_capable();
|
||||
|
@ -67,13 +67,13 @@ KResult GenericFramebufferDevice::ioctl(OpenFileDescription&, unsigned request,
|
|||
TRY(verify_head_index(head_resolution.head_index));
|
||||
|
||||
if (head_resolution.pitch < 0)
|
||||
return KResult(EINVAL);
|
||||
return Error::from_errno(EINVAL);
|
||||
if (head_resolution.width < 0)
|
||||
return KResult(EINVAL);
|
||||
return Error::from_errno(EINVAL);
|
||||
if (head_resolution.height < 0)
|
||||
return KResult(EINVAL);
|
||||
return Error::from_errno(EINVAL);
|
||||
TRY(set_head_resolution(head_resolution.head_index, head_resolution.width, head_resolution.height, head_resolution.pitch));
|
||||
return KSuccess;
|
||||
return {};
|
||||
}
|
||||
case FB_IOCTL_SET_HEAD_VERTICAL_OFFSET_BUFFER: {
|
||||
auto user_head_vertical_buffer_offset = static_ptr_cast<FBHeadVerticalOffset*>(arg);
|
||||
|
@ -82,9 +82,9 @@ KResult GenericFramebufferDevice::ioctl(OpenFileDescription&, unsigned request,
|
|||
TRY(verify_head_index(head_vertical_buffer_offset.head_index));
|
||||
|
||||
if (head_vertical_buffer_offset.offseted < 0 || head_vertical_buffer_offset.offseted > 1)
|
||||
return KResult(EINVAL);
|
||||
return Error::from_errno(EINVAL);
|
||||
TRY(set_head_buffer(head_vertical_buffer_offset.head_index, head_vertical_buffer_offset.offseted));
|
||||
return KSuccess;
|
||||
return {};
|
||||
}
|
||||
case FB_IOCTL_GET_HEAD_VERTICAL_OFFSET_BUFFER: {
|
||||
auto user_head_vertical_buffer_offset = static_ptr_cast<FBHeadVerticalOffset*>(arg);
|
||||
|
@ -97,12 +97,12 @@ KResult GenericFramebufferDevice::ioctl(OpenFileDescription&, unsigned request,
|
|||
}
|
||||
case FB_IOCTL_FLUSH_HEAD_BUFFERS: {
|
||||
if (!partial_flushing_support())
|
||||
return KResult(ENOTSUP);
|
||||
return Error::from_errno(ENOTSUP);
|
||||
auto user_flush_rects = static_ptr_cast<FBFlushRects*>(arg);
|
||||
FBFlushRects flush_rects;
|
||||
TRY(copy_from_user(&flush_rects, user_flush_rects));
|
||||
if (Checked<unsigned>::multiplication_would_overflow(flush_rects.count, sizeof(FBRect)))
|
||||
return KResult(EFAULT);
|
||||
return Error::from_errno(EFAULT);
|
||||
MutexLocker locker(m_flushing_lock);
|
||||
if (flush_rects.count > 0) {
|
||||
for (unsigned i = 0; i < flush_rects.count; i++) {
|
||||
|
@ -111,11 +111,11 @@ KResult GenericFramebufferDevice::ioctl(OpenFileDescription&, unsigned request,
|
|||
TRY(flush_rectangle(flush_rects.buffer_index, user_dirty_rect));
|
||||
}
|
||||
}
|
||||
return KSuccess;
|
||||
return {};
|
||||
};
|
||||
case FB_IOCTL_FLUSH_HEAD: {
|
||||
if (!flushing_support())
|
||||
return KResult(ENOTSUP);
|
||||
return Error::from_errno(ENOTSUP);
|
||||
// Note: We accept a FBRect, but we only really care about the head_index value.
|
||||
auto user_rect = static_ptr_cast<FBRect*>(arg);
|
||||
FBRect rect;
|
||||
|
@ -123,7 +123,7 @@ KResult GenericFramebufferDevice::ioctl(OpenFileDescription&, unsigned request,
|
|||
TRY(verify_head_index(rect.head_index));
|
||||
|
||||
TRY(flush_head_buffer(rect.head_index));
|
||||
return KSuccess;
|
||||
return {};
|
||||
}
|
||||
default:
|
||||
return EINVAL;
|
||||
|
|
|
@ -6,9 +6,9 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#include <AK/Error.h>
|
||||
#include <AK/String.h>
|
||||
#include <AK/Types.h>
|
||||
#include <Kernel/API/KResult.h>
|
||||
#include <Kernel/Devices/BlockDevice.h>
|
||||
#include <Kernel/Graphics/GenericGraphicsAdapter.h>
|
||||
#include <Kernel/Locking/Mutex.h>
|
||||
|
@ -21,7 +21,7 @@ class GenericFramebufferDevice : public BlockDevice {
|
|||
friend class DeviceManagement;
|
||||
|
||||
public:
|
||||
virtual KResult try_to_initialize() = 0;
|
||||
virtual ErrorOr<void> try_to_initialize() = 0;
|
||||
|
||||
virtual void deactivate_writes() = 0;
|
||||
virtual void activate_writes() = 0;
|
||||
|
@ -29,8 +29,8 @@ public:
|
|||
virtual ~GenericFramebufferDevice() = default;
|
||||
|
||||
// ^File
|
||||
virtual KResultOr<Memory::Region*> mmap(Process&, OpenFileDescription&, Memory::VirtualRange const&, u64 offset, int prot, bool shared) = 0;
|
||||
virtual KResult ioctl(OpenFileDescription&, unsigned request, Userspace<void*> arg) override final;
|
||||
virtual ErrorOr<Memory::Region*> mmap(Process&, OpenFileDescription&, Memory::VirtualRange const&, u64 offset, int prot, bool shared) = 0;
|
||||
virtual ErrorOr<void> ioctl(OpenFileDescription&, unsigned request, Userspace<void*> arg) override final;
|
||||
virtual StringView class_name() const override final { return "FramebufferDevice"sv; }
|
||||
|
||||
private:
|
||||
|
@ -38,28 +38,28 @@ private:
|
|||
virtual bool can_read(const OpenFileDescription&, size_t) const override final { return true; }
|
||||
virtual bool can_write(const OpenFileDescription&, size_t) const override final { return true; }
|
||||
virtual void start_request(AsyncBlockDeviceRequest& request) override final { request.complete(AsyncDeviceRequest::Failure); }
|
||||
virtual KResultOr<size_t> read(OpenFileDescription&, u64, UserOrKernelBuffer&, size_t) override { return EINVAL; }
|
||||
virtual KResultOr<size_t> write(OpenFileDescription&, u64, const UserOrKernelBuffer&, size_t) override { return EINVAL; }
|
||||
virtual ErrorOr<size_t> read(OpenFileDescription&, u64, UserOrKernelBuffer&, size_t) override { return EINVAL; }
|
||||
virtual ErrorOr<size_t> write(OpenFileDescription&, u64, const UserOrKernelBuffer&, size_t) override { return EINVAL; }
|
||||
|
||||
protected:
|
||||
virtual bool multihead_support() const = 0;
|
||||
virtual bool flushing_support() const = 0;
|
||||
virtual bool partial_flushing_support() const = 0;
|
||||
virtual size_t heads_count() const = 0;
|
||||
virtual KResultOr<size_t> buffer_length(size_t head) const = 0;
|
||||
virtual KResultOr<size_t> pitch(size_t head) const = 0;
|
||||
virtual KResultOr<size_t> height(size_t head) const = 0;
|
||||
virtual KResultOr<size_t> width(size_t head) const = 0;
|
||||
virtual KResultOr<size_t> vertical_offset(size_t head) const = 0;
|
||||
virtual KResultOr<bool> vertical_offseted(size_t head) const = 0;
|
||||
virtual ErrorOr<size_t> buffer_length(size_t head) const = 0;
|
||||
virtual ErrorOr<size_t> pitch(size_t head) const = 0;
|
||||
virtual ErrorOr<size_t> height(size_t head) const = 0;
|
||||
virtual ErrorOr<size_t> width(size_t head) const = 0;
|
||||
virtual ErrorOr<size_t> vertical_offset(size_t head) const = 0;
|
||||
virtual ErrorOr<bool> vertical_offseted(size_t head) const = 0;
|
||||
|
||||
virtual KResult set_head_resolution(size_t head, size_t width, size_t height, size_t pitch) = 0;
|
||||
virtual KResult set_head_buffer(size_t head, bool second_buffer) = 0;
|
||||
virtual KResult flush_head_buffer(size_t head) = 0;
|
||||
virtual ErrorOr<void> set_head_resolution(size_t head, size_t width, size_t height, size_t pitch) = 0;
|
||||
virtual ErrorOr<void> set_head_buffer(size_t head, bool second_buffer) = 0;
|
||||
virtual ErrorOr<void> flush_head_buffer(size_t head) = 0;
|
||||
// FIXME: This method is too much specific to the VirtIO implementation (especially the buffer_index parameter)
|
||||
virtual KResult flush_rectangle(size_t buffer_index, FBRect const&) = 0;
|
||||
virtual ErrorOr<void> flush_rectangle(size_t buffer_index, FBRect const&) = 0;
|
||||
|
||||
KResult verify_head_index(int head_index) const;
|
||||
ErrorOr<void> verify_head_index(int head_index) const;
|
||||
|
||||
GenericFramebufferDevice(const GenericGraphicsAdapter&);
|
||||
mutable WeakPtr<GenericGraphicsAdapter> m_graphics_adapter;
|
||||
|
|
|
@ -643,7 +643,7 @@ void IntelNativeGraphicsAdapter::initialize_framebuffer_devices()
|
|||
VERIFY(m_framebuffer_height != 0);
|
||||
VERIFY(m_framebuffer_width != 0);
|
||||
m_framebuffer_device = FramebufferDevice::create(*this, address, m_framebuffer_width, m_framebuffer_height, m_framebuffer_pitch);
|
||||
// FIXME: Would be nice to be able to return a KResult here.
|
||||
// FIXME: Would be nice to be able to return a ErrorOr<void> here.
|
||||
auto framebuffer_result = m_framebuffer_device->try_to_initialize();
|
||||
VERIFY(!framebuffer_result.is_error());
|
||||
}
|
||||
|
|
|
@ -32,7 +32,7 @@ UNMAP_AFTER_INIT void VGACompatibleAdapter::initialize_framebuffer_devices()
|
|||
VERIFY(m_framebuffer_height != 0);
|
||||
VERIFY(m_framebuffer_pitch != 0);
|
||||
m_framebuffer_device = FramebufferDevice::create(*this, m_framebuffer_address, m_framebuffer_width, m_framebuffer_height, m_framebuffer_pitch);
|
||||
// FIXME: Would be nice to be able to return KResult here.
|
||||
// FIXME: Would be nice to be able to return ErrorOr<void> here.
|
||||
VERIFY(!m_framebuffer_device->try_to_initialize().is_error());
|
||||
}
|
||||
|
||||
|
|
|
@ -19,7 +19,7 @@ RefPtr<GraphicsAdapter> FramebufferDevice::adapter() const
|
|||
return static_cast<GraphicsAdapter&>(*adapter);
|
||||
}
|
||||
|
||||
KResultOr<size_t> FramebufferDevice::buffer_length(size_t head) const
|
||||
ErrorOr<size_t> FramebufferDevice::buffer_length(size_t head) const
|
||||
{
|
||||
// Note: This FramebufferDevice class doesn't support multihead setup.
|
||||
// We take care to verify this at the GenericFramebufferDevice::ioctl method
|
||||
|
@ -28,7 +28,7 @@ KResultOr<size_t> FramebufferDevice::buffer_length(size_t head) const
|
|||
MutexLocker locker(m_resolution_lock);
|
||||
return display_info().rect.width * display_info().rect.height * 4;
|
||||
}
|
||||
KResultOr<size_t> FramebufferDevice::pitch(size_t head) const
|
||||
ErrorOr<size_t> FramebufferDevice::pitch(size_t head) const
|
||||
{
|
||||
// Note: This FramebufferDevice class doesn't support multihead setup.
|
||||
// We take care to verify this at the GenericFramebufferDevice::ioctl method
|
||||
|
@ -37,7 +37,7 @@ KResultOr<size_t> FramebufferDevice::pitch(size_t head) const
|
|||
MutexLocker locker(m_resolution_lock);
|
||||
return display_info().rect.width * 4;
|
||||
}
|
||||
KResultOr<size_t> FramebufferDevice::height(size_t head) const
|
||||
ErrorOr<size_t> FramebufferDevice::height(size_t head) const
|
||||
{
|
||||
// Note: This FramebufferDevice class doesn't support multihead setup.
|
||||
// We take care to verify this at the GenericFramebufferDevice::ioctl method
|
||||
|
@ -46,7 +46,7 @@ KResultOr<size_t> FramebufferDevice::height(size_t head) const
|
|||
MutexLocker locker(m_resolution_lock);
|
||||
return display_info().rect.height;
|
||||
}
|
||||
KResultOr<size_t> FramebufferDevice::width(size_t head) const
|
||||
ErrorOr<size_t> FramebufferDevice::width(size_t head) const
|
||||
{
|
||||
// Note: This FramebufferDevice class doesn't support multihead setup.
|
||||
// We take care to verify this at the GenericFramebufferDevice::ioctl method
|
||||
|
@ -55,7 +55,7 @@ KResultOr<size_t> FramebufferDevice::width(size_t head) const
|
|||
MutexLocker locker(m_resolution_lock);
|
||||
return display_info().rect.width;
|
||||
}
|
||||
KResultOr<size_t> FramebufferDevice::vertical_offset(size_t head) const
|
||||
ErrorOr<size_t> FramebufferDevice::vertical_offset(size_t head) const
|
||||
{
|
||||
// Note: This FramebufferDevice class doesn't support multihead setup.
|
||||
// We take care to verify this at the GenericFramebufferDevice::ioctl method
|
||||
|
@ -63,7 +63,7 @@ KResultOr<size_t> FramebufferDevice::vertical_offset(size_t head) const
|
|||
VERIFY(head == 0);
|
||||
return 0;
|
||||
}
|
||||
KResultOr<bool> FramebufferDevice::vertical_offseted(size_t head) const
|
||||
ErrorOr<bool> FramebufferDevice::vertical_offseted(size_t head) const
|
||||
{
|
||||
// Note: This FramebufferDevice class doesn't support multihead setup.
|
||||
// We take care to verify this at the GenericFramebufferDevice::ioctl method
|
||||
|
@ -72,14 +72,14 @@ KResultOr<bool> FramebufferDevice::vertical_offseted(size_t head) const
|
|||
return false;
|
||||
}
|
||||
|
||||
KResult FramebufferDevice::set_head_resolution(size_t head, size_t width, size_t height, size_t)
|
||||
ErrorOr<void> FramebufferDevice::set_head_resolution(size_t head, size_t width, size_t height, size_t)
|
||||
{
|
||||
// Note: This class doesn't support multihead setup (yet!).
|
||||
// We take care to verify this at the GenericFramebufferDevice::ioctl method
|
||||
// so if we happen to accidentally have a value different than 0, assert.
|
||||
VERIFY(head == 0);
|
||||
if (width > MAX_VIRTIOGPU_RESOLUTION_WIDTH || height > MAX_VIRTIOGPU_RESOLUTION_HEIGHT)
|
||||
return KResult(ENOTSUP);
|
||||
return Error::from_errno(ENOTSUP);
|
||||
|
||||
auto& info = display_info();
|
||||
|
||||
|
@ -92,22 +92,22 @@ KResult FramebufferDevice::set_head_resolution(size_t head, size_t width, size_t
|
|||
.height = (u32)height,
|
||||
};
|
||||
|
||||
// FIXME: Would be nice to be able to return KResultOr here.
|
||||
// FIXME: Would be nice to be able to return ErrorOr here.
|
||||
TRY(create_framebuffer());
|
||||
return KSuccess;
|
||||
return {};
|
||||
}
|
||||
KResult FramebufferDevice::set_head_buffer(size_t, bool)
|
||||
ErrorOr<void> FramebufferDevice::set_head_buffer(size_t, bool)
|
||||
{
|
||||
return KResult(ENOTSUP);
|
||||
return Error::from_errno(ENOTSUP);
|
||||
}
|
||||
KResult FramebufferDevice::flush_head_buffer(size_t)
|
||||
ErrorOr<void> FramebufferDevice::flush_head_buffer(size_t)
|
||||
{
|
||||
// Note: This class doesn't support flushing.
|
||||
// We take care to verify this at the GenericFramebufferDevice::ioctl method
|
||||
// so if we happen to accidentally reach this code, assert.
|
||||
VERIFY_NOT_REACHED();
|
||||
}
|
||||
KResult FramebufferDevice::flush_rectangle(size_t buffer_index, FBRect const& rect)
|
||||
ErrorOr<void> FramebufferDevice::flush_rectangle(size_t buffer_index, FBRect const& rect)
|
||||
{
|
||||
MutexLocker locker(adapter()->operation_lock());
|
||||
Protocol::Rect dirty_rect {
|
||||
|
@ -116,9 +116,9 @@ KResult FramebufferDevice::flush_rectangle(size_t buffer_index, FBRect const& re
|
|||
.width = rect.width,
|
||||
.height = rect.height
|
||||
};
|
||||
// FIXME: Find a better KResult here.
|
||||
// FIXME: Find a better ErrorOr<void> here.
|
||||
if (!m_are_writes_active)
|
||||
return KResult(EIO);
|
||||
return Error::from_errno(EIO);
|
||||
auto& buffer = buffer_from_index(buffer_index);
|
||||
transfer_framebuffer_data_to_host(dirty_rect, buffer);
|
||||
if (&buffer == m_current_buffer) {
|
||||
|
@ -137,7 +137,7 @@ KResult FramebufferDevice::flush_rectangle(size_t buffer_index, FBRect const& re
|
|||
buffer.dirty_rect.height = max(current_dirty_bottom, dirty_rect.y + dirty_rect.height) - buffer.dirty_rect.y;
|
||||
}
|
||||
}
|
||||
return KSuccess;
|
||||
return {};
|
||||
}
|
||||
|
||||
FramebufferDevice::FramebufferDevice(GraphicsAdapter const& adapter, ScanoutID scanout)
|
||||
|
@ -155,7 +155,7 @@ FramebufferDevice::~FramebufferDevice()
|
|||
{
|
||||
}
|
||||
|
||||
KResult FramebufferDevice::create_framebuffer()
|
||||
ErrorOr<void> FramebufferDevice::create_framebuffer()
|
||||
{
|
||||
// First delete any existing framebuffers to free the memory first
|
||||
m_framebuffer = nullptr;
|
||||
|
@ -179,7 +179,7 @@ KResult FramebufferDevice::create_framebuffer()
|
|||
create_buffer(m_main_buffer, 0, m_buffer_size);
|
||||
create_buffer(m_back_buffer, m_buffer_size, m_buffer_size);
|
||||
|
||||
return KSuccess;
|
||||
return {};
|
||||
}
|
||||
|
||||
void FramebufferDevice::create_buffer(Buffer& buffer, size_t framebuffer_offset, size_t framebuffer_size)
|
||||
|
@ -255,7 +255,7 @@ void FramebufferDevice::set_buffer(int buffer_index)
|
|||
buffer.dirty_rect = {};
|
||||
}
|
||||
|
||||
KResultOr<Memory::Region*> FramebufferDevice::mmap(Process& process, OpenFileDescription&, Memory::VirtualRange const& range, u64 offset, int prot, bool shared)
|
||||
ErrorOr<Memory::Region*> FramebufferDevice::mmap(Process& process, OpenFileDescription&, Memory::VirtualRange const& range, u64 offset, int prot, bool shared)
|
||||
{
|
||||
REQUIRE_PROMISE(video);
|
||||
if (!shared)
|
||||
|
@ -295,7 +295,7 @@ void FramebufferDevice::deactivate_writes()
|
|||
if (m_userspace_mmap_region) {
|
||||
auto* region = m_userspace_mmap_region.unsafe_ptr();
|
||||
auto maybe_vm_object = m_framebuffer_sink_vmobject->try_clone();
|
||||
// FIXME: Would be nice to be able to return a KResult here.
|
||||
// FIXME: Would be nice to be able to return a ErrorOr<void> here.
|
||||
VERIFY(!maybe_vm_object.is_error());
|
||||
region->set_vmobject(maybe_vm_object.release_value());
|
||||
region->remap();
|
||||
|
|
|
@ -28,7 +28,7 @@ public:
|
|||
FramebufferDevice(GraphicsAdapter const&, ScanoutID);
|
||||
virtual ~FramebufferDevice() override;
|
||||
|
||||
virtual KResult try_to_initialize() override { return KSuccess; }
|
||||
virtual ErrorOr<void> try_to_initialize() override { return {}; }
|
||||
|
||||
virtual void deactivate_writes();
|
||||
virtual void activate_writes();
|
||||
|
@ -50,17 +50,17 @@ private:
|
|||
virtual bool flushing_support() const override { return false; }
|
||||
virtual bool partial_flushing_support() const override { return true; }
|
||||
virtual size_t heads_count() const override { return 1; }
|
||||
virtual KResultOr<size_t> buffer_length(size_t head) const override;
|
||||
virtual KResultOr<size_t> pitch(size_t head) const override;
|
||||
virtual KResultOr<size_t> height(size_t head) const override;
|
||||
virtual KResultOr<size_t> width(size_t head) const override;
|
||||
virtual KResultOr<size_t> vertical_offset(size_t head) const override;
|
||||
virtual KResultOr<bool> vertical_offseted(size_t head) const override;
|
||||
virtual ErrorOr<size_t> buffer_length(size_t head) const override;
|
||||
virtual ErrorOr<size_t> pitch(size_t head) const override;
|
||||
virtual ErrorOr<size_t> height(size_t head) const override;
|
||||
virtual ErrorOr<size_t> width(size_t head) const override;
|
||||
virtual ErrorOr<size_t> vertical_offset(size_t head) const override;
|
||||
virtual ErrorOr<bool> vertical_offseted(size_t head) const override;
|
||||
|
||||
virtual KResult set_head_resolution(size_t head, size_t width, size_t height, size_t pitch) override;
|
||||
virtual KResult set_head_buffer(size_t head, bool second_buffer) override;
|
||||
virtual KResult flush_head_buffer(size_t head) override;
|
||||
virtual KResult flush_rectangle(size_t head, FBRect const&) override;
|
||||
virtual ErrorOr<void> set_head_resolution(size_t head, size_t width, size_t height, size_t pitch) override;
|
||||
virtual ErrorOr<void> set_head_buffer(size_t head, bool second_buffer) override;
|
||||
virtual ErrorOr<void> flush_head_buffer(size_t head) override;
|
||||
virtual ErrorOr<void> flush_rectangle(size_t head, FBRect const&) override;
|
||||
|
||||
void flush_dirty_window(Protocol::Rect const&, Buffer&);
|
||||
void transfer_framebuffer_data_to_host(Protocol::Rect const&, Buffer&);
|
||||
|
@ -73,11 +73,11 @@ private:
|
|||
|
||||
void clear_to_black(Buffer&);
|
||||
|
||||
KResult create_framebuffer();
|
||||
ErrorOr<void> create_framebuffer();
|
||||
void create_buffer(Buffer&, size_t, size_t);
|
||||
void set_buffer(int);
|
||||
|
||||
virtual KResultOr<Memory::Region*> mmap(Process&, OpenFileDescription&, Memory::VirtualRange const&, u64 offset, int prot, bool shared) override;
|
||||
virtual ErrorOr<Memory::Region*> mmap(Process&, OpenFileDescription&, Memory::VirtualRange const&, u64 offset, int prot, bool shared) override;
|
||||
|
||||
static bool is_valid_buffer_index(int buffer_index)
|
||||
{
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue