VGACompatibleAdapter.cpp 3.1 KB

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