summaryrefslogtreecommitdiff
path: root/Kernel/Graphics/VirtIOGPU
diff options
context:
space:
mode:
authorLiav A <liavalb@gmail.com>2022-04-30 09:39:03 +0300
committerAndreas Kling <kling@serenityos.org>2022-05-05 20:55:57 +0200
commit41283a2de6f3861eb36648041462b10b7206493e (patch)
treea982eeba1589982a55c05043d473e104a65e9a55 /Kernel/Graphics/VirtIOGPU
parent728358c5996657e56a367e889723f39343176d46 (diff)
downloadserenity-41283a2de6f3861eb36648041462b10b7206493e.zip
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.
Diffstat (limited to 'Kernel/Graphics/VirtIOGPU')
-rw-r--r--Kernel/Graphics/VirtIOGPU/GPU3DDevice.cpp17
-rw-r--r--Kernel/Graphics/VirtIOGPU/GPU3DDevice.h11
-rw-r--r--Kernel/Graphics/VirtIOGPU/GraphicsAdapter.cpp2
3 files changed, 20 insertions, 10 deletions
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<Memor
{
}
-GPU3DDevice::GPU3DDevice(GraphicsAdapter& graphics_adapter)
- : CharacterDevice(28, 0)
- , m_graphics_adapter(graphics_adapter)
+NonnullRefPtr<GPU3DDevice> 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<VirtIOGPU::GPU3DDevice>(adapter, region_result.release_value()));
+ return device;
+}
+
+GPU3DDevice::GPU3DDevice(GraphicsAdapter& graphics_adapter, NonnullOwnPtr<Memory::Region> 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 <AK/DistinctNumeric.h>
#include <Kernel/Devices/CharacterDevice.h>
+#include <Kernel/Devices/DeviceManagement.h>
#include <Kernel/Graphics/VirtIOGPU/FramebufferDevice.h>
#include <Kernel/Graphics/VirtIOGPU/Protocol.h>
@@ -87,9 +88,13 @@ union ClearType {
};
class GPU3DDevice : public CharacterDevice {
+ friend class Kernel::DeviceManagement;
+
public:
- GPU3DDevice() = delete;
- explicit GPU3DDevice(GraphicsAdapter& graphics_adapter);
+ static NonnullRefPtr<GPU3DDevice> must_create(GraphicsAdapter&);
+
+private:
+ GPU3DDevice(GraphicsAdapter& graphics_adapter, NonnullOwnPtr<Memory::Region> transfer_buffer_region);
class PerContextState : public RefCounted<PerContextState> {
public:
@@ -129,7 +134,7 @@ private:
ContextID m_kernel_context_id;
HashMap<OpenFileDescription*, RefPtr<PerContextState>> m_context_state_lookup;
// Memory management for backing buffers
- OwnPtr<Memory::Region> m_transfer_buffer_region;
+ NonnullOwnPtr<Memory::Region> 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<VirtIOGPU::GPU3DDevice>(*this));
+ m_3d_device = VirtIOGPU::GPU3DDevice::must_create(*this);
}
}