1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 08:48:11 +00:00
serenity/Kernel/Graphics/VirtIOGPU/VirtIOGraphicsAdapter.cpp
Liav A 053a832fac Kernel: Simplify graphics initialization somewhat
We use a switch-case statements to ensure we try to find the best
suitable driver for a specific graphics card. In case we don't find
such, we use the default statement to initialize the graphics card as a
generic VGA adapter, if the adapter is VGA compatible.

If we couldn't initialize the driver, we don't touch this adapter
anymore.

Also, GraphicsDevice should not be tied to a PCI::Address member, as it
can be theortically be used with other buses (e.g. ISA cards).
2021-07-03 16:28:49 +02:00

57 lines
1.7 KiB
C++

/*
* Copyright (c) 2021, Sahan Fernando <sahan.h.fernando@gmail.com>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#include <Kernel/Graphics/Console/GenericFramebufferConsole.h>
#include <Kernel/Graphics/GraphicsManagement.h>
#include <Kernel/Graphics/VirtIOGPU/VirtIOGPU.h>
#include <Kernel/Graphics/VirtIOGPU/VirtIOGraphicsAdapter.h>
namespace Kernel::Graphics {
NonnullRefPtr<VirtIOGraphicsAdapter> VirtIOGraphicsAdapter::initialize(PCI::Address base_address)
{
return adopt_ref(*new VirtIOGraphicsAdapter(base_address));
}
VirtIOGraphicsAdapter::VirtIOGraphicsAdapter(PCI::Address base_address)
: PCI::DeviceController(base_address)
{
m_gpu_device = adopt_ref(*new VirtIOGPU(base_address)).leak_ref();
}
void VirtIOGraphicsAdapter::initialize_framebuffer_devices()
{
dbgln_if(VIRTIO_DEBUG, "VirtIOGPU: 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 VirtIOGraphicsAdapter::enable_consoles()
{
dbgln_if(VIRTIO_DEBUG, "VirtIOGPU: Enabling consoles");
m_gpu_device->for_each_framebuffer([&](auto& framebuffer, auto& console) {
framebuffer.deactivate_writes();
framebuffer.clear_to_black();
console.enable();
return IterationDecision::Continue;
});
}
void VirtIOGraphicsAdapter::disable_consoles()
{
dbgln_if(VIRTIO_DEBUG, "VirtIOGPU: Disabling consoles");
m_gpu_device->for_each_framebuffer([&](auto& framebuffer, auto& console) {
console.disable();
framebuffer.activate_writes();
return IterationDecision::Continue;
});
}
}