mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 19:57:45 +00:00
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.
This commit is contained in:
parent
728358c599
commit
41283a2de6
3 changed files with 20 additions and 10 deletions
|
@ -21,12 +21,8 @@ GPU3DDevice::PerContextState::PerContextState(ContextID context_id, OwnPtr<Memor
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
GPU3DDevice::GPU3DDevice(GraphicsAdapter& graphics_adapter)
|
NonnullRefPtr<GPU3DDevice> GPU3DDevice::must_create(GraphicsAdapter& adapter)
|
||||||
: CharacterDevice(28, 0)
|
|
||||||
, m_graphics_adapter(graphics_adapter)
|
|
||||||
{
|
{
|
||||||
m_kernel_context_id = m_graphics_adapter.create_context();
|
|
||||||
|
|
||||||
// Setup memory transfer region
|
// Setup memory transfer region
|
||||||
auto region_result = MM.allocate_kernel_region(
|
auto region_result = MM.allocate_kernel_region(
|
||||||
NUM_TRANSFER_REGION_PAGES * PAGE_SIZE,
|
NUM_TRANSFER_REGION_PAGES * PAGE_SIZE,
|
||||||
|
@ -34,7 +30,16 @@ GPU3DDevice::GPU3DDevice(GraphicsAdapter& graphics_adapter)
|
||||||
Memory::Region::Access::ReadWrite,
|
Memory::Region::Access::ReadWrite,
|
||||||
AllocationStrategy::AllocateNow);
|
AllocationStrategy::AllocateNow);
|
||||||
VERIFY(!region_result.is_error());
|
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)
|
void GPU3DDevice::detach(OpenFileDescription& description)
|
||||||
|
|
|
@ -8,6 +8,7 @@
|
||||||
|
|
||||||
#include <AK/DistinctNumeric.h>
|
#include <AK/DistinctNumeric.h>
|
||||||
#include <Kernel/Devices/CharacterDevice.h>
|
#include <Kernel/Devices/CharacterDevice.h>
|
||||||
|
#include <Kernel/Devices/DeviceManagement.h>
|
||||||
#include <Kernel/Graphics/VirtIOGPU/FramebufferDevice.h>
|
#include <Kernel/Graphics/VirtIOGPU/FramebufferDevice.h>
|
||||||
#include <Kernel/Graphics/VirtIOGPU/Protocol.h>
|
#include <Kernel/Graphics/VirtIOGPU/Protocol.h>
|
||||||
|
|
||||||
|
@ -87,9 +88,13 @@ union ClearType {
|
||||||
};
|
};
|
||||||
|
|
||||||
class GPU3DDevice : public CharacterDevice {
|
class GPU3DDevice : public CharacterDevice {
|
||||||
|
friend class Kernel::DeviceManagement;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
GPU3DDevice() = delete;
|
static NonnullRefPtr<GPU3DDevice> must_create(GraphicsAdapter&);
|
||||||
explicit GPU3DDevice(GraphicsAdapter& graphics_adapter);
|
|
||||||
|
private:
|
||||||
|
GPU3DDevice(GraphicsAdapter& graphics_adapter, NonnullOwnPtr<Memory::Region> transfer_buffer_region);
|
||||||
|
|
||||||
class PerContextState : public RefCounted<PerContextState> {
|
class PerContextState : public RefCounted<PerContextState> {
|
||||||
public:
|
public:
|
||||||
|
@ -129,7 +134,7 @@ private:
|
||||||
ContextID m_kernel_context_id;
|
ContextID m_kernel_context_id;
|
||||||
HashMap<OpenFileDescription*, RefPtr<PerContextState>> m_context_state_lookup;
|
HashMap<OpenFileDescription*, RefPtr<PerContextState>> m_context_state_lookup;
|
||||||
// Memory management for backing buffers
|
// 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;
|
constexpr static size_t NUM_TRANSFER_REGION_PAGES = 256;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -465,7 +465,7 @@ void GraphicsAdapter::initialize_3d_device()
|
||||||
{
|
{
|
||||||
if (m_has_virgl_support) {
|
if (m_has_virgl_support) {
|
||||||
MutexLocker locker(m_operation_lock);
|
MutexLocker locker(m_operation_lock);
|
||||||
m_3d_device = MUST(DeviceManagement::try_create_device<VirtIOGPU::GPU3DDevice>(*this));
|
m_3d_device = VirtIOGPU::GPU3DDevice::must_create(*this);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue