VGACompatibleAdapter.cpp 3.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. /*
  2. * Copyright (c) 2021, Liav A. <liavalb@hotmail.co.il>
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #include <Kernel/Graphics/Console/ContiguousFramebufferConsole.h>
  7. #include <Kernel/Graphics/Console/TextModeConsole.h>
  8. #include <Kernel/Graphics/GraphicsManagement.h>
  9. #include <Kernel/Graphics/VGACompatibleAdapter.h>
  10. #include <Kernel/Sections.h>
  11. namespace Kernel {
  12. UNMAP_AFTER_INIT NonnullRefPtr<VGACompatibleAdapter> VGACompatibleAdapter::initialize_with_preset_resolution(PCI::DeviceIdentifier const& pci_device_identifier, PhysicalAddress m_framebuffer_address, size_t framebuffer_width, size_t framebuffer_height, size_t framebuffer_pitch)
  13. {
  14. return adopt_ref(*new VGACompatibleAdapter(pci_device_identifier.address(), m_framebuffer_address, framebuffer_width, framebuffer_height, framebuffer_pitch));
  15. }
  16. UNMAP_AFTER_INIT NonnullRefPtr<VGACompatibleAdapter> VGACompatibleAdapter::initialize(PCI::DeviceIdentifier const& pci_device_identifier)
  17. {
  18. return adopt_ref(*new VGACompatibleAdapter(pci_device_identifier.address()));
  19. }
  20. UNMAP_AFTER_INIT void VGACompatibleAdapter::initialize_framebuffer_devices()
  21. {
  22. // We might not have any pre-set framebuffer, so if that's the case - don't try to initialize one.
  23. if (m_framebuffer_address.is_null())
  24. return;
  25. VERIFY(m_framebuffer_width);
  26. VERIFY(m_framebuffer_width != 0);
  27. VERIFY(m_framebuffer_height != 0);
  28. VERIFY(m_framebuffer_pitch != 0);
  29. m_framebuffer_device = FramebufferDevice::create(*this, 0, m_framebuffer_address, m_framebuffer_width, m_framebuffer_height, m_framebuffer_pitch);
  30. // FIXME: Would be nice to be able to return KResult here.
  31. VERIFY(!m_framebuffer_device->initialize().is_error());
  32. }
  33. UNMAP_AFTER_INIT VGACompatibleAdapter::VGACompatibleAdapter(PCI::Address address)
  34. : PCI::Device(address)
  35. {
  36. m_framebuffer_console = Graphics::TextModeConsole::initialize(*this);
  37. // FIXME: This is a very wrong way to do this...
  38. GraphicsManagement::the().m_console = m_framebuffer_console;
  39. }
  40. UNMAP_AFTER_INIT VGACompatibleAdapter::VGACompatibleAdapter(PCI::Address address, PhysicalAddress framebuffer_address, size_t framebuffer_width, size_t framebuffer_height, size_t framebuffer_pitch)
  41. : PCI::Device(address)
  42. , m_framebuffer_address(framebuffer_address)
  43. , m_framebuffer_width(framebuffer_width)
  44. , m_framebuffer_height(framebuffer_height)
  45. , m_framebuffer_pitch(framebuffer_pitch)
  46. {
  47. m_framebuffer_console = Graphics::ContiguousFramebufferConsole::initialize(framebuffer_address, framebuffer_width, framebuffer_height, framebuffer_pitch);
  48. // FIXME: This is a very wrong way to do this...
  49. GraphicsManagement::the().m_console = m_framebuffer_console;
  50. }
  51. void VGACompatibleAdapter::enable_consoles()
  52. {
  53. VERIFY(m_framebuffer_console);
  54. if (m_framebuffer_device)
  55. m_framebuffer_device->deactivate_writes();
  56. m_framebuffer_console->enable();
  57. }
  58. void VGACompatibleAdapter::disable_consoles()
  59. {
  60. VERIFY(m_framebuffer_device);
  61. VERIFY(m_framebuffer_console);
  62. m_framebuffer_console->disable();
  63. m_framebuffer_device->activate_writes();
  64. }
  65. bool VGACompatibleAdapter::try_to_set_resolution(size_t, size_t, size_t)
  66. {
  67. return false;
  68. }
  69. bool VGACompatibleAdapter::set_y_offset(size_t, size_t)
  70. {
  71. return false;
  72. }
  73. }