diff options
author | Liav A <liavalb@gmail.com> | 2021-05-22 09:51:55 +0300 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2021-05-27 22:39:13 +0200 |
commit | c1a4dfeffbd8a2fcf10cfed014692f7cdaf37f50 (patch) | |
tree | e1a7427d3740e68d90a813f377b3de463422895f | |
parent | b8fd845885046d0333b6638b1b66d0eb3ad283a8 (diff) | |
download | serenity-c1a4dfeffbd8a2fcf10cfed014692f7cdaf37f50.zip |
Kernel/Graphics: Remove unnecessary derived FramebufferDevice classes
It seems like overly-specific classes were written for no good reason.
Instead of making each adapter to have its own unique FramebufferDevice
class, let's generalize everything to keep implementation more
consistent.
-rw-r--r-- | Kernel/CMakeLists.txt | 2 | ||||
-rw-r--r-- | Kernel/Debug.h.in | 4 | ||||
-rw-r--r-- | Kernel/Graphics/Bochs.h | 3 | ||||
-rw-r--r-- | Kernel/Graphics/BochsFramebufferDevice.cpp | 114 | ||||
-rw-r--r-- | Kernel/Graphics/BochsFramebufferDevice.h | 41 | ||||
-rw-r--r-- | Kernel/Graphics/BochsGraphicsAdapter.cpp | 27 | ||||
-rw-r--r-- | Kernel/Graphics/BochsGraphicsAdapter.h | 11 | ||||
-rw-r--r-- | Kernel/Graphics/FramebufferDevice.cpp | 67 | ||||
-rw-r--r-- | Kernel/Graphics/FramebufferDevice.h | 19 | ||||
-rw-r--r-- | Kernel/Graphics/GraphicsDevice.h | 8 | ||||
-rw-r--r-- | Kernel/Graphics/IntelNativeGraphicsAdapter.cpp | 2 | ||||
-rw-r--r-- | Kernel/Graphics/IntelNativeGraphicsAdapter.h | 2 | ||||
-rw-r--r-- | Kernel/Graphics/RawFramebufferDevice.cpp | 20 | ||||
-rw-r--r-- | Kernel/Graphics/RawFramebufferDevice.h | 31 | ||||
-rw-r--r-- | Kernel/Graphics/VGACompatibleAdapter.cpp | 11 | ||||
-rw-r--r-- | Kernel/Graphics/VGACompatibleAdapter.h | 10 | ||||
-rw-r--r-- | Meta/CMake/all_the_debug_macros.cmake | 1 |
17 files changed, 127 insertions, 246 deletions
diff --git a/Kernel/CMakeLists.txt b/Kernel/CMakeLists.txt index 1d7446c274..d7204d83cb 100644 --- a/Kernel/CMakeLists.txt +++ b/Kernel/CMakeLists.txt @@ -59,12 +59,10 @@ set(KERNEL_SOURCES Graphics/Console/FramebufferConsole.cpp Graphics/Console/TextModeConsole.cpp Graphics/Console/VGAConsole.cpp - Graphics/BochsFramebufferDevice.cpp Graphics/BochsGraphicsAdapter.cpp Graphics/FramebufferDevice.cpp Graphics/GraphicsManagement.cpp Graphics/IntelNativeGraphicsAdapter.cpp - Graphics/RawFramebufferDevice.cpp Graphics/VGACompatibleAdapter.cpp Storage/Partition/DiskPartition.cpp Storage/Partition/DiskPartitionMetadata.cpp diff --git a/Kernel/Debug.h.in b/Kernel/Debug.h.in index a51ab138d2..e12d176dc1 100644 --- a/Kernel/Debug.h.in +++ b/Kernel/Debug.h.in @@ -66,6 +66,10 @@ #cmakedefine01 EXT2_DEBUG #endif +#ifndef FRAMEBUFFER_DEVICE_DEBUG +#cmakedefine01 FRAMEBUFFER_DEVICE_DEBUG +#endif + #ifndef EXT2_VERY_DEBUG #cmakedefine01 EXT2_VERY_DEBUG #endif diff --git a/Kernel/Graphics/Bochs.h b/Kernel/Graphics/Bochs.h index 19b9d08a4b..0f1faec4e5 100644 --- a/Kernel/Graphics/Bochs.h +++ b/Kernel/Graphics/Bochs.h @@ -6,9 +6,6 @@ #pragma once -#define MAX_RESOLUTION_WIDTH 4096 -#define MAX_RESOLUTION_HEIGHT 2160 - #define VBE_DISPI_IOPORT_INDEX 0x01CE #define VBE_DISPI_IOPORT_DATA 0x01CF diff --git a/Kernel/Graphics/BochsFramebufferDevice.cpp b/Kernel/Graphics/BochsFramebufferDevice.cpp deleted file mode 100644 index 23c3108d96..0000000000 --- a/Kernel/Graphics/BochsFramebufferDevice.cpp +++ /dev/null @@ -1,114 +0,0 @@ -/* - * Copyright (c) 2021, Liav A. <liavalb@hotmail.co.il> - * - * SPDX-License-Identifier: BSD-2-Clause - */ - -#include <AK/Checked.h> -#include <AK/Singleton.h> -#include <Kernel/Debug.h> -#include <Kernel/Graphics/Bochs.h> -#include <Kernel/Graphics/BochsFramebufferDevice.h> -#include <Kernel/IO.h> -#include <Kernel/PCI/Access.h> -#include <Kernel/Process.h> -#include <LibC/errno_numbers.h> -#include <LibC/sys/ioctl_numbers.h> - -namespace Kernel { - -UNMAP_AFTER_INIT NonnullRefPtr<BochsFramebufferDevice> BochsFramebufferDevice::create(const BochsGraphicsAdapter& adapter, PhysicalAddress framebuffer_address, size_t width, size_t height, size_t pitch) -{ - return adopt_ref(*new BochsFramebufferDevice(adapter, framebuffer_address, pitch, width, height)); -} - -UNMAP_AFTER_INIT BochsFramebufferDevice::BochsFramebufferDevice(const BochsGraphicsAdapter& adapter, PhysicalAddress framebuffer_address, size_t width, size_t height, size_t pitch) - : FramebufferDevice(framebuffer_address, width, height, pitch) - , m_bochs_adapter(adapter) -{ - m_bochs_adapter->set_safe_resolution(); - m_framebuffer_width = 1024; - m_framebuffer_height = 768; - m_framebuffer_pitch = m_framebuffer_width * sizeof(u32); -} - -void BochsFramebufferDevice::set_y_offset(size_t y_offset) -{ - VERIFY(y_offset == 0 || y_offset == m_framebuffer_height); - m_y_offset = y_offset; - m_bochs_adapter->set_y_offset(y_offset); -} - -int BochsFramebufferDevice::ioctl(FileDescription&, unsigned request, FlatPtr arg) -{ - REQUIRE_PROMISE(video); - switch (request) { - case FB_IOCTL_GET_SIZE_IN_BYTES: { - auto* out = (size_t*)arg; - size_t value = framebuffer_size_in_bytes(); - if (!copy_to_user(out, &value)) - return -EFAULT; - return 0; - } - case FB_IOCTL_GET_BUFFER: { - auto* index = (int*)arg; - int value = m_y_offset == 0 ? 0 : 1; - if (!copy_to_user(index, &value)) - return -EFAULT; - return 0; - } - case FB_IOCTL_SET_BUFFER: { - if (arg != 0 && arg != 1) - return -EINVAL; - set_y_offset(arg == 0 ? 0 : m_framebuffer_height); - return 0; - } - case FB_IOCTL_GET_RESOLUTION: { - auto* user_resolution = (FBResolution*)arg; - FBResolution resolution; - resolution.pitch = m_framebuffer_pitch; - resolution.width = m_framebuffer_width; - resolution.height = m_framebuffer_height; - if (!copy_to_user(user_resolution, &resolution)) - return -EFAULT; - return 0; - } - case FB_IOCTL_SET_RESOLUTION: { - auto* user_resolution = (FBResolution*)arg; - FBResolution resolution; - if (!copy_from_user(&resolution, user_resolution)) - return -EFAULT; - if (resolution.width > MAX_RESOLUTION_WIDTH || resolution.height > MAX_RESOLUTION_HEIGHT) - return -EINVAL; - - if (!m_bochs_adapter->set_resolution(resolution.width, resolution.height)) { - m_framebuffer_pitch = m_framebuffer_width * sizeof(u32); - dbgln_if(BXVGA_DEBUG, "Reverting resolution: [{}x{}]", m_framebuffer_width, m_framebuffer_height); - // Note: We try to revert everything back, and if it doesn't work, just assert. - if (!m_bochs_adapter->set_resolution(m_framebuffer_width, m_framebuffer_height)) { - VERIFY_NOT_REACHED(); - } - resolution.pitch = m_framebuffer_pitch; - resolution.width = m_framebuffer_width; - resolution.height = m_framebuffer_height; - if (!copy_to_user(user_resolution, &resolution)) - return -EFAULT; - return -EINVAL; - } - m_framebuffer_width = resolution.width; - m_framebuffer_height = resolution.height; - m_framebuffer_pitch = m_framebuffer_width * sizeof(u32); - - dbgln_if(BXVGA_DEBUG, "New resolution: [{}x{}]", m_framebuffer_width, m_framebuffer_height); - resolution.pitch = m_framebuffer_pitch; - resolution.width = m_framebuffer_width; - resolution.height = m_framebuffer_height; - if (!copy_to_user(user_resolution, &resolution)) - return -EFAULT; - return 0; - } - default: - return -EINVAL; - }; -} -} diff --git a/Kernel/Graphics/BochsFramebufferDevice.h b/Kernel/Graphics/BochsFramebufferDevice.h deleted file mode 100644 index 5133c3320f..0000000000 --- a/Kernel/Graphics/BochsFramebufferDevice.h +++ /dev/null @@ -1,41 +0,0 @@ -/* - * Copyright (c) 2021, Liav A. <liavalb@hotmail.co.il> - * - * SPDX-License-Identifier: BSD-2-Clause - */ - -#pragma once - -#include <AK/String.h> -#include <AK/Types.h> -#include <Kernel/Graphics/BochsGraphicsAdapter.h> -#include <Kernel/Graphics/FramebufferDevice.h> -#include <Kernel/PhysicalAddress.h> - -namespace Kernel { - -class BochsFramebufferDevice final : public FramebufferDevice { - AK_MAKE_ETERNAL - friend class BochsGraphicsAdapter; - -public: - static NonnullRefPtr<BochsFramebufferDevice> create(const BochsGraphicsAdapter&, PhysicalAddress, size_t, size_t, size_t); - - virtual size_t framebuffer_size_in_bytes() const override { return m_framebuffer_pitch * m_framebuffer_height * 2; } - - virtual ~BochsFramebufferDevice() = default; - -private: - virtual int ioctl(FileDescription&, unsigned request, FlatPtr arg) override; - - BochsFramebufferDevice(const BochsGraphicsAdapter&, PhysicalAddress, size_t, size_t, size_t); - virtual const char* class_name() const override { return "BXVGA"; } - - void set_y_offset(size_t); - - size_t m_y_offset { 0 }; - - NonnullRefPtr<BochsGraphicsAdapter> m_bochs_adapter; -}; - -} diff --git a/Kernel/Graphics/BochsGraphicsAdapter.cpp b/Kernel/Graphics/BochsGraphicsAdapter.cpp index e15d1d24ee..0cfd1dd278 100644 --- a/Kernel/Graphics/BochsGraphicsAdapter.cpp +++ b/Kernel/Graphics/BochsGraphicsAdapter.cpp @@ -9,7 +9,6 @@ #include <AK/Singleton.h> #include <Kernel/Debug.h> #include <Kernel/Graphics/Bochs.h> -#include <Kernel/Graphics/BochsFramebufferDevice.h> #include <Kernel/Graphics/BochsGraphicsAdapter.h> #include <Kernel/Graphics/Console/FramebufferConsole.h> #include <Kernel/Graphics/GraphicsManagement.h> @@ -63,7 +62,7 @@ UNMAP_AFTER_INIT BochsGraphicsAdapter::BochsGraphicsAdapter(PCI::Address pci_add UNMAP_AFTER_INIT void BochsGraphicsAdapter::initialize_framebuffer_devices() { // FIXME: Find a better way to determine default resolution... - m_framebuffer_device = BochsFramebufferDevice::create(*this, PhysicalAddress(PCI::get_BAR0(pci_address()) & 0xfffffff0), 1024, 768, 1024 * sizeof(u32)); + m_framebuffer_device = FramebufferDevice::create(*this, 0, PhysicalAddress(PCI::get_BAR0(pci_address()) & 0xfffffff0), 1024, 768, 1024 * sizeof(u32)); m_framebuffer_device->initialize(); } @@ -77,7 +76,8 @@ GraphicsDevice::Type BochsGraphicsAdapter::type() const void BochsGraphicsAdapter::set_safe_resolution() { VERIFY(m_framebuffer_console); - set_resolution(1024, 768); + auto result = try_to_set_resolution(0, 1024, 768); + VERIFY(result); } void BochsGraphicsAdapter::set_resolution_registers(size_t width, size_t height) @@ -97,20 +97,17 @@ void BochsGraphicsAdapter::set_resolution_registers(size_t width, size_t height) registers->bochs_regs.bank = 0; } -bool BochsGraphicsAdapter::try_to_set_resolution(size_t width, size_t height) -{ - dbgln_if(BXVGA_DEBUG, "BochsGraphicsAdapter resolution test - {}x{}", width, height); - set_resolution_registers(width, height); - return validate_setup_resolution(width, height); -} - -bool BochsGraphicsAdapter::set_resolution(size_t width, size_t height) +bool BochsGraphicsAdapter::try_to_set_resolution(size_t output_port_index, size_t width, size_t height) { + // Note: There's only one output port for this adapter + VERIFY(output_port_index == 0); VERIFY(m_framebuffer_console); if (Checked<size_t>::multiplication_would_overflow(width, height, sizeof(u32))) return false; - if (!try_to_set_resolution(width, height)) + set_resolution_registers(width, height); + dbgln_if(BXVGA_DEBUG, "BochsGraphicsAdapter resolution test - {}x{}", width, height); + if (!validate_setup_resolution(width, height)) return false; dbgln("BochsGraphicsAdapter: resolution set to {}x{}", width, height); @@ -127,12 +124,14 @@ bool BochsGraphicsAdapter::validate_setup_resolution(size_t width, size_t height return true; } -void BochsGraphicsAdapter::set_y_offset(size_t y_offset) +bool BochsGraphicsAdapter::set_y_offset(size_t output_port_index, size_t y_offset) { + VERIFY(output_port_index == 0); if (m_console_enabled) - return; + return false; auto registers = map_typed_writable<volatile BochsDisplayMMIORegisters>(m_mmio_registers); registers->bochs_regs.y_offset = y_offset; + return true; } void BochsGraphicsAdapter::enable_consoles() diff --git a/Kernel/Graphics/BochsGraphicsAdapter.h b/Kernel/Graphics/BochsGraphicsAdapter.h index af647e0a87..6a3816b54d 100644 --- a/Kernel/Graphics/BochsGraphicsAdapter.h +++ b/Kernel/Graphics/BochsGraphicsAdapter.h @@ -9,6 +9,7 @@ #include <AK/String.h> #include <AK/Types.h> #include <Kernel/Graphics/Console/FramebufferConsole.h> +#include <Kernel/Graphics/FramebufferDevice.h> #include <Kernel/Graphics/GraphicsDevice.h> #include <Kernel/PCI/DeviceController.h> #include <Kernel/PhysicalAddress.h> @@ -28,8 +29,14 @@ public: virtual ~BochsGraphicsAdapter() = default; virtual bool framebuffer_devices_initialized() const override { return !m_framebuffer_device.is_null(); } + virtual bool modesetting_capable() const override { return true; } + virtual bool double_framebuffering_capable() const override { return true; } + private: // ^GraphicsDevice + virtual bool try_to_set_resolution(size_t output_port_index, size_t width, size_t height) override; + virtual bool set_y_offset(size_t output_port_index, size_t y) override; + virtual void initialize_framebuffer_devices() override; virtual Type type() const override; @@ -42,13 +49,11 @@ private: bool validate_setup_resolution(size_t width, size_t height); u32 find_framebuffer_address(); - bool try_to_set_resolution(size_t width, size_t height); - bool set_resolution(size_t width, size_t height); void set_resolution_registers(size_t width, size_t height); void set_y_offset(size_t); PhysicalAddress m_mmio_registers; - RefPtr<BochsFramebufferDevice> m_framebuffer_device; + RefPtr<FramebufferDevice> m_framebuffer_device; RefPtr<Graphics::FramebufferConsole> m_framebuffer_console; SpinLock<u8> m_console_mode_switch_lock; bool m_console_enabled { false }; diff --git a/Kernel/Graphics/FramebufferDevice.cpp b/Kernel/Graphics/FramebufferDevice.cpp index 0d41e8a3ec..7f4447b144 100644 --- a/Kernel/Graphics/FramebufferDevice.cpp +++ b/Kernel/Graphics/FramebufferDevice.cpp @@ -18,8 +18,16 @@ #include <Kernel/Panic.h> +#define MAX_RESOLUTION_WIDTH 4096 +#define MAX_RESOLUTION_HEIGHT 2160 + namespace Kernel { +NonnullRefPtr<FramebufferDevice> FramebufferDevice::create(const GraphicsDevice& adapter, size_t output_port_index, PhysicalAddress paddr, size_t width, size_t height, size_t pitch) +{ + return adopt_ref(*new FramebufferDevice(adapter, output_port_index, paddr, width, height, pitch)); +} + KResultOr<Region*> FramebufferDevice::mmap(Process& process, FileDescription&, const Range& range, u64 offset, int prot, bool shared) { ScopedSpinLock lock(m_activation_lock); @@ -103,12 +111,14 @@ UNMAP_AFTER_INIT void FramebufferDevice::initialize() VERIFY(m_swapped_framebuffer_region); } -UNMAP_AFTER_INIT FramebufferDevice::FramebufferDevice(PhysicalAddress addr, size_t width, size_t height, size_t pitch) +UNMAP_AFTER_INIT FramebufferDevice::FramebufferDevice(const GraphicsDevice& adapter, size_t output_port_index, PhysicalAddress addr, size_t width, size_t height, size_t pitch) : BlockDevice(29, GraphicsManagement::the().allocate_minor_device_number()) , m_framebuffer_address(addr) , m_framebuffer_pitch(pitch) , m_framebuffer_width(width) , m_framebuffer_height(height) + , m_output_port_index(output_port_index) + , m_graphics_adapter(adapter) { VERIFY(!m_framebuffer_address.is_null()); VERIFY(m_framebuffer_pitch); @@ -117,9 +127,11 @@ UNMAP_AFTER_INIT FramebufferDevice::FramebufferDevice(PhysicalAddress addr, size dbgln("Framebuffer {}: address={}, pitch={}, width={}, height={}", minor(), addr, pitch, width, height); } -bool FramebufferDevice::set_resolution(size_t, size_t, size_t) +size_t FramebufferDevice::framebuffer_size_in_bytes() const { - VERIFY_NOT_REACHED(); + if (m_graphics_adapter->double_framebuffering_capable()) + return m_framebuffer_pitch * m_framebuffer_height * 2; + return m_framebuffer_pitch * m_framebuffer_height; } int FramebufferDevice::ioctl(FileDescription&, unsigned request, FlatPtr arg) @@ -134,7 +146,21 @@ int FramebufferDevice::ioctl(FileDescription&, unsigned request, FlatPtr arg) return 0; } case FB_IOCTL_GET_BUFFER: { - return -ENOTIMPL; + auto* index = (int*)arg; + int value = m_y_offset == 0 ? 0 : 1; + if (!copy_to_user(index, &value)) + return -EFAULT; + if (!m_graphics_adapter->double_framebuffering_capable()) + return -ENOTIMPL; + return 0; + } + case FB_IOCTL_SET_BUFFER: { + if (arg != 0 && arg != 1) + return -EINVAL; + if (!m_graphics_adapter->double_framebuffering_capable()) + return -ENOTIMPL; + m_graphics_adapter->set_y_offset(m_output_port_index, arg == 0 ? 0 : m_framebuffer_height); + return 0; } case FB_IOCTL_GET_RESOLUTION: { auto* user_resolution = (FBResolution*)arg; @@ -149,6 +175,39 @@ int FramebufferDevice::ioctl(FileDescription&, unsigned request, FlatPtr arg) case FB_IOCTL_SET_RESOLUTION: { auto* user_resolution = (FBResolution*)arg; FBResolution resolution; + if (!copy_from_user(&resolution, user_resolution)) + return -EFAULT; + if (resolution.width > MAX_RESOLUTION_WIDTH || resolution.height > MAX_RESOLUTION_HEIGHT) + return -EINVAL; + + if (!m_graphics_adapter->modesetting_capable()) { + resolution.pitch = m_framebuffer_pitch; + resolution.width = m_framebuffer_width; + resolution.height = m_framebuffer_height; + if (!copy_to_user(user_resolution, &resolution)) + return -EFAULT; + return -ENOTIMPL; + } + + if (!m_graphics_adapter->try_to_set_resolution(m_output_port_index, resolution.width, resolution.height)) { + m_framebuffer_pitch = m_framebuffer_width * sizeof(u32); + dbgln_if(FRAMEBUFFER_DEVICE_DEBUG, "Reverting resolution: [{}x{}]", m_framebuffer_width, m_framebuffer_height); + // Note: We try to revert everything back, and if it doesn't work, just assert. + if (!m_graphics_adapter->try_to_set_resolution(m_output_port_index, m_framebuffer_width, m_framebuffer_height)) { + VERIFY_NOT_REACHED(); + } + resolution.pitch = m_framebuffer_pitch; + resolution.width = m_framebuffer_width; + resolution.height = m_framebuffer_height; + if (!copy_to_user(user_resolution, &resolution)) + return -EFAULT; + return -EINVAL; + } + m_framebuffer_width = resolution.width; + m_framebuffer_height = resolution.height; + m_framebuffer_pitch = m_framebuffer_width * sizeof(u32); + + dbgln_if(FRAMEBUFFER_DEVICE_DEBUG, "New resolution: [{}x{}]", m_framebuffer_width, m_framebuffer_height); resolution.pitch = m_framebuffer_pitch; resolution.width = m_framebuffer_width; resolution.height = m_framebuffer_height; diff --git a/Kernel/Graphics/FramebufferDevice.h b/Kernel/Graphics/FramebufferDevice.h index 5391f91e9c..c716e0959c 100644 --- a/Kernel/Graphics/FramebufferDevice.h +++ b/Kernel/Graphics/FramebufferDevice.h @@ -20,6 +20,8 @@ namespace Kernel { class FramebufferDevice : public BlockDevice { AK_MAKE_ETERNAL public: + static NonnullRefPtr<FramebufferDevice> create(const GraphicsDevice&, size_t, PhysicalAddress, size_t, size_t, size_t); + virtual int ioctl(FileDescription&, unsigned request, FlatPtr arg) override; virtual KResultOr<Region*> mmap(Process&, FileDescription&, const Range&, u64 offset, int prot, bool shared) override; @@ -29,15 +31,14 @@ public: virtual void deactivate_writes(); virtual void activate_writes(); - virtual size_t framebuffer_size_in_bytes() const { return m_framebuffer_pitch * m_framebuffer_height; } + size_t framebuffer_size_in_bytes() const; virtual ~FramebufferDevice() {}; void initialize(); -protected: - virtual bool set_resolution(size_t framebuffer_width, size_t framebuffer_height, size_t framebuffer_pitch); - - FramebufferDevice(PhysicalAddress, size_t, size_t, size_t); +private: + // ^File + virtual const char* class_name() const { return "FramebufferDevice"; } virtual bool can_read(const FileDescription&, size_t) const override final { return true; } virtual bool can_write(const FileDescription&, size_t) const override final { return true; } @@ -45,13 +46,13 @@ protected: virtual KResultOr<size_t> read(FileDescription&, u64, UserOrKernelBuffer&, size_t) override { return -EINVAL; } virtual KResultOr<size_t> write(FileDescription&, u64, const UserOrKernelBuffer&, size_t) override { return -EINVAL; } -protected: + FramebufferDevice(const GraphicsDevice&, size_t, PhysicalAddress, size_t, size_t, size_t); + PhysicalAddress m_framebuffer_address; size_t m_framebuffer_pitch { 0 }; size_t m_framebuffer_width { 0 }; size_t m_framebuffer_height { 0 }; -private: SpinLock<u8> m_activation_lock; RefPtr<AnonymousVMObject> m_real_framebuffer_vmobject; @@ -63,6 +64,10 @@ private: RefPtr<AnonymousVMObject> m_userspace_real_framebuffer_vmobject; Region* m_userspace_framebuffer_region { nullptr }; + + size_t m_y_offset { 0 }; + size_t m_output_port_index; + NonnullRefPtr<GraphicsDevice> m_graphics_adapter; }; } diff --git a/Kernel/Graphics/GraphicsDevice.h b/Kernel/Graphics/GraphicsDevice.h index 2279338f4f..acc6b9ac0f 100644 --- a/Kernel/Graphics/GraphicsDevice.h +++ b/Kernel/Graphics/GraphicsDevice.h @@ -9,11 +9,9 @@ #include <AK/String.h> #include <AK/Types.h> #include <Kernel/Devices/BlockDevice.h> -#include <Kernel/Graphics/FramebufferDevice.h> #include <Kernel/PhysicalAddress.h> namespace Kernel { -class FramebufferDevice; class GraphicsDevice : public RefCounted<GraphicsDevice> { public: enum class Type { @@ -30,6 +28,12 @@ public: bool consoles_enabled() const { return m_consoles_enabled; } virtual bool framebuffer_devices_initialized() const = 0; + virtual bool modesetting_capable() const = 0; + virtual bool double_framebuffering_capable() const = 0; + + virtual bool try_to_set_resolution(size_t output_port_index, size_t width, size_t height) = 0; + virtual bool set_y_offset(size_t output_port_index, size_t y) = 0; + protected: GraphicsDevice() = default; diff --git a/Kernel/Graphics/IntelNativeGraphicsAdapter.cpp b/Kernel/Graphics/IntelNativeGraphicsAdapter.cpp index dfd00638fb..2e1b98bc79 100644 --- a/Kernel/Graphics/IntelNativeGraphicsAdapter.cpp +++ b/Kernel/Graphics/IntelNativeGraphicsAdapter.cpp @@ -625,7 +625,7 @@ void IntelNativeGraphicsAdapter::initialize_framebuffer_devices() VERIFY(m_framebuffer_pitch != 0); VERIFY(m_framebuffer_height != 0); VERIFY(m_framebuffer_width != 0); - m_framebuffer_device = RawFramebufferDevice::create(*this, address, m_framebuffer_width, m_framebuffer_height, m_framebuffer_pitch); + m_framebuffer_device = FramebufferDevice::create(*this, 0, address, m_framebuffer_width, m_framebuffer_height, m_framebuffer_pitch); m_framebuffer_device->initialize(); } } diff --git a/Kernel/Graphics/IntelNativeGraphicsAdapter.h b/Kernel/Graphics/IntelNativeGraphicsAdapter.h index 48cd0fac36..a58bae009f 100644 --- a/Kernel/Graphics/IntelNativeGraphicsAdapter.h +++ b/Kernel/Graphics/IntelNativeGraphicsAdapter.h @@ -9,7 +9,7 @@ #include <AK/String.h> #include <AK/Types.h> #include <Kernel/Graphics/Definitions.h> -#include <Kernel/Graphics/RawFramebufferDevice.h> +#include <Kernel/Graphics/FramebufferDevice.h> #include <Kernel/Graphics/VGACompatibleAdapter.h> #include <Kernel/PCI/DeviceController.h> #include <Kernel/PhysicalAddress.h> diff --git a/Kernel/Graphics/RawFramebufferDevice.cpp b/Kernel/Graphics/RawFramebufferDevice.cpp deleted file mode 100644 index 993e513441..0000000000 --- a/Kernel/Graphics/RawFramebufferDevice.cpp +++ /dev/null @@ -1,20 +0,0 @@ -/* - * Copyright (c) 2021, Liav A. <liavalb@hotmail.co.il> - * - * SPDX-License-Identifier: BSD-2-Clause - */ - -#include <Kernel/Graphics/RawFramebufferDevice.h> - -namespace Kernel { - -UNMAP_AFTER_INIT NonnullRefPtr<RawFramebufferDevice> RawFramebufferDevice::create(const GraphicsDevice&, PhysicalAddress framebuffer_address, size_t width, size_t height, size_t pitch) -{ - return adopt_ref(*new RawFramebufferDevice(framebuffer_address, width, height, pitch)); -} -UNMAP_AFTER_INIT RawFramebufferDevice::RawFramebufferDevice(PhysicalAddress framebuffer_address, size_t width, size_t height, size_t pitch) - : FramebufferDevice(framebuffer_address, width, height, pitch) -{ -} - -} diff --git a/Kernel/Graphics/RawFramebufferDevice.h b/Kernel/Graphics/RawFramebufferDevice.h deleted file mode 100644 index 53ef6920fe..0000000000 --- a/Kernel/Graphics/RawFramebufferDevice.h +++ /dev/null @@ -1,31 +0,0 @@ -/* - * Copyright (c) 2021, Liav A. <liavalb@hotmail.co.il> - * - * SPDX-License-Identifier: BSD-2-Clause - */ - -#pragma once - -#include <AK/String.h> -#include <AK/Types.h> -#include <Kernel/Graphics/FramebufferDevice.h> -#include <Kernel/Graphics/GraphicsDevice.h> -#include <Kernel/PhysicalAddress.h> - -namespace Kernel { - -class RawFramebufferDevice : public FramebufferDevice { - AK_MAKE_ETERNAL - friend class GraphicsDevice; - -public: - static NonnullRefPtr<RawFramebufferDevice> create(const GraphicsDevice&, PhysicalAddress, size_t width, size_t height, size_t pitch); - - virtual ~RawFramebufferDevice() {}; - -private: - RawFramebufferDevice(PhysicalAddress, size_t width, size_t height, size_t pitch); - virtual const char* class_name() const override { return "RawFramebuffer"; } -}; - -} diff --git a/Kernel/Graphics/VGACompatibleAdapter.cpp b/Kernel/Graphics/VGACompatibleAdapter.cpp index 8ee96023d3..f2bf1cc232 100644 --- a/Kernel/Graphics/VGACompatibleAdapter.cpp +++ b/Kernel/Graphics/VGACompatibleAdapter.cpp @@ -31,7 +31,7 @@ UNMAP_AFTER_INIT void VGACompatibleAdapter::initialize_framebuffer_devices() VERIFY(m_framebuffer_width != 0); VERIFY(m_framebuffer_height != 0); VERIFY(m_framebuffer_pitch != 0); - m_framebuffer_device = RawFramebufferDevice::create(*this, m_framebuffer_address, m_framebuffer_width, m_framebuffer_height, m_framebuffer_pitch); + m_framebuffer_device = FramebufferDevice::create(*this, 0, m_framebuffer_address, m_framebuffer_width, m_framebuffer_height, m_framebuffer_pitch); m_framebuffer_device->initialize(); } @@ -70,4 +70,13 @@ void VGACompatibleAdapter::disable_consoles() m_framebuffer_device->activate_writes(); } +bool VGACompatibleAdapter::try_to_set_resolution(size_t, size_t, size_t) +{ + return false; +} +bool VGACompatibleAdapter::set_y_offset(size_t, size_t) +{ + return false; +} + } diff --git a/Kernel/Graphics/VGACompatibleAdapter.h b/Kernel/Graphics/VGACompatibleAdapter.h index c1b6572e05..bc74be0e30 100644 --- a/Kernel/Graphics/VGACompatibleAdapter.h +++ b/Kernel/Graphics/VGACompatibleAdapter.h @@ -9,8 +9,8 @@ #include <AK/String.h> #include <AK/Types.h> #include <Kernel/Graphics/Console/Console.h> +#include <Kernel/Graphics/FramebufferDevice.h> #include <Kernel/Graphics/GraphicsDevice.h> -#include <Kernel/Graphics/RawFramebufferDevice.h> #include <Kernel/PCI/DeviceController.h> #include <Kernel/PhysicalAddress.h> @@ -25,6 +25,12 @@ public: virtual bool framebuffer_devices_initialized() const override { return !m_framebuffer_device.is_null(); } + virtual bool modesetting_capable() const override { return false; } + virtual bool double_framebuffering_capable() const override { return false; } + + virtual bool try_to_set_resolution(size_t output_port_index, size_t width, size_t height) override; + virtual bool set_y_offset(size_t output_port_index, size_t y) override; + protected: explicit VGACompatibleAdapter(PCI::Address); @@ -44,7 +50,7 @@ protected: size_t m_framebuffer_height { 0 }; size_t m_framebuffer_pitch { 0 }; - RefPtr<RawFramebufferDevice> m_framebuffer_device; + RefPtr<FramebufferDevice> m_framebuffer_device; RefPtr<Graphics::Console> m_framebuffer_console; }; diff --git a/Meta/CMake/all_the_debug_macros.cmake b/Meta/CMake/all_the_debug_macros.cmake index dc377d61f5..0377c69045 100644 --- a/Meta/CMake/all_the_debug_macros.cmake +++ b/Meta/CMake/all_the_debug_macros.cmake @@ -13,6 +13,7 @@ set(PAGE_FAULT_DEBUG ON) set(CONTEXT_SWITCH_DEBUG ON) set(SMP_DEBUG ON) set(BXVGA_DEBUG ON) +set(FRAMEBUFFER_DEVICE_DEBUG ON) set(PS2MOUSE_DEBUG ON) set(MOUSE_DEBUG ON) set(VMWARE_BACKDOOR_DEBUG ON) |