From 41283a2de6f3861eb36648041462b10b7206493e Mon Sep 17 00:00:00 2001 From: Liav A Date: Sat, 30 Apr 2022 09:39:03 +0300 Subject: Kernel/Graphics: Use VirtIO GPU3DDevice constructor indirectly We shouldn't expose the VirtIO GPU3DDevice constructor as public method, so instead, let's use the usual pattern of a static construction method that uses the constructor within the method. --- Kernel/Graphics/VirtIOGPU/GPU3DDevice.cpp | 17 +++++++++++------ Kernel/Graphics/VirtIOGPU/GPU3DDevice.h | 11 ++++++++--- Kernel/Graphics/VirtIOGPU/GraphicsAdapter.cpp | 2 +- 3 files changed, 20 insertions(+), 10 deletions(-) (limited to 'Kernel/Graphics/VirtIOGPU') diff --git a/Kernel/Graphics/VirtIOGPU/GPU3DDevice.cpp b/Kernel/Graphics/VirtIOGPU/GPU3DDevice.cpp index c7740995bf..00caaa725b 100644 --- a/Kernel/Graphics/VirtIOGPU/GPU3DDevice.cpp +++ b/Kernel/Graphics/VirtIOGPU/GPU3DDevice.cpp @@ -21,12 +21,8 @@ GPU3DDevice::PerContextState::PerContextState(ContextID context_id, OwnPtr GPU3DDevice::must_create(GraphicsAdapter& adapter) { - m_kernel_context_id = m_graphics_adapter.create_context(); - // Setup memory transfer region auto region_result = MM.allocate_kernel_region( NUM_TRANSFER_REGION_PAGES * PAGE_SIZE, @@ -34,7 +30,16 @@ GPU3DDevice::GPU3DDevice(GraphicsAdapter& graphics_adapter) Memory::Region::Access::ReadWrite, AllocationStrategy::AllocateNow); VERIFY(!region_result.is_error()); - m_transfer_buffer_region = region_result.release_value(); + auto device = MUST(DeviceManagement::try_create_device(adapter, region_result.release_value())); + return device; +} + +GPU3DDevice::GPU3DDevice(GraphicsAdapter& graphics_adapter, NonnullOwnPtr transfer_buffer_region) + : CharacterDevice(28, 0) + , m_graphics_adapter(graphics_adapter) + , m_transfer_buffer_region(move(transfer_buffer_region)) +{ + m_kernel_context_id = m_graphics_adapter.create_context(); } void GPU3DDevice::detach(OpenFileDescription& description) diff --git a/Kernel/Graphics/VirtIOGPU/GPU3DDevice.h b/Kernel/Graphics/VirtIOGPU/GPU3DDevice.h index de72726084..5ad653f085 100644 --- a/Kernel/Graphics/VirtIOGPU/GPU3DDevice.h +++ b/Kernel/Graphics/VirtIOGPU/GPU3DDevice.h @@ -8,6 +8,7 @@ #include #include +#include #include #include @@ -87,9 +88,13 @@ union ClearType { }; class GPU3DDevice : public CharacterDevice { + friend class Kernel::DeviceManagement; + public: - GPU3DDevice() = delete; - explicit GPU3DDevice(GraphicsAdapter& graphics_adapter); + static NonnullRefPtr must_create(GraphicsAdapter&); + +private: + GPU3DDevice(GraphicsAdapter& graphics_adapter, NonnullOwnPtr transfer_buffer_region); class PerContextState : public RefCounted { public: @@ -129,7 +134,7 @@ private: ContextID m_kernel_context_id; HashMap> m_context_state_lookup; // Memory management for backing buffers - OwnPtr m_transfer_buffer_region; + NonnullOwnPtr m_transfer_buffer_region; constexpr static size_t NUM_TRANSFER_REGION_PAGES = 256; }; diff --git a/Kernel/Graphics/VirtIOGPU/GraphicsAdapter.cpp b/Kernel/Graphics/VirtIOGPU/GraphicsAdapter.cpp index 23376d31f5..485c18c04b 100644 --- a/Kernel/Graphics/VirtIOGPU/GraphicsAdapter.cpp +++ b/Kernel/Graphics/VirtIOGPU/GraphicsAdapter.cpp @@ -465,7 +465,7 @@ void GraphicsAdapter::initialize_3d_device() { if (m_has_virgl_support) { MutexLocker locker(m_operation_lock); - m_3d_device = MUST(DeviceManagement::try_create_device(*this)); + m_3d_device = VirtIOGPU::GPU3DDevice::must_create(*this); } } -- cgit v1.2.3