1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 15:48:12 +00:00
serenity/Kernel/Graphics/VirtIOGPU/GraphicsAdapter.cpp
Liav A fb0ed2ae46 Kernel/Graphics: Force VirtIO Framebuffer to inherit FramebufferDevice
The distinction is not justified because a VirtIO Framebuffer device
acts much more like a regular FramebufferDevice than a pure BlockDevice.
2021-10-27 07:57:44 +03:00

60 lines
1.9 KiB
C++

/*
* Copyright (c) 2021, Sahan Fernando <sahan.h.fernando@gmail.com>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#include <Kernel/Bus/PCI/API.h>
#include <Kernel/Bus/PCI/IDs.h>
#include <Kernel/Graphics/Console/GenericFramebufferConsole.h>
#include <Kernel/Graphics/GraphicsManagement.h>
#include <Kernel/Graphics/VirtIOGPU/GPU.h>
#include <Kernel/Graphics/VirtIOGPU/GraphicsAdapter.h>
namespace Kernel::Graphics::VirtIOGPU {
NonnullRefPtr<GraphicsAdapter> GraphicsAdapter::initialize(PCI::DeviceIdentifier const& device_identifier)
{
VERIFY(device_identifier.hardware_id().vendor_id == PCI::VendorID::VirtIO);
return adopt_ref(*new GraphicsAdapter(device_identifier));
}
GraphicsAdapter::GraphicsAdapter(PCI::DeviceIdentifier const& device_identifier)
: PCI::Device(device_identifier.address())
{
m_gpu_device = adopt_ref(*new GPU(*this, device_identifier)).leak_ref();
m_gpu_device->initialize();
}
void GraphicsAdapter::initialize_framebuffer_devices()
{
dbgln_if(VIRTIO_DEBUG, "GPU: Initializing framebuffer devices");
VERIFY(!m_created_framebuffer_devices);
m_gpu_device->create_framebuffer_devices();
m_created_framebuffer_devices = true;
// FIXME: This is a very wrong way to do this...
GraphicsManagement::the().m_console = m_gpu_device->default_console();
}
void GraphicsAdapter::enable_consoles()
{
dbgln_if(VIRTIO_DEBUG, "GPU: Enabling consoles");
m_gpu_device->for_each_framebuffer([&](auto& framebuffer, auto& console) {
framebuffer.deactivate_writes();
console.enable();
return IterationDecision::Continue;
});
}
void GraphicsAdapter::disable_consoles()
{
dbgln_if(VIRTIO_DEBUG, "GPU: Disabling consoles");
m_gpu_device->for_each_framebuffer([&](auto& framebuffer, auto& console) {
console.disable();
framebuffer.activate_writes();
return IterationDecision::Continue;
});
}
}