1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 11:28:12 +00:00

WindowServer: Detect framebuffer capabilities and settings

The main changes are twofold:

* Buffer flipping is now controlled by the m_screen_can_set_buffer flag
  in WSCompositor. This flag, in turn, is impacted by m_can_set_buffer
  flag, in WSScreen. m_can_set_buffer is set in the WSScreen constructor
  by checking the return value of fb_set_buffer. If the framebuffer
  supports this operation, it will succeed, and we record this fact. This
  information is then used by WSCompositor to set its own
  m_screen_can_set_buffer flag.

* WSScreen now only requests a resolution change of the framebuffer. The
  driver itself is ultimately responsible for what resolution or mode is
  actually set, so WSScreen has to read the response from that request,
  and has no choice but to accept the answer. This allows the driver to
  choose a "close enough" value to what was requested, or simply ignore
  it.

The result of this is that there is no special configuration necessary
for WindowServer to work with reduced-capability framebuffer devices.
This commit is contained in:
Conrad Pankoff 2019-08-18 14:32:14 +10:00 committed by Andreas Kling
parent 3932dfbb04
commit 23b6ef29dd
4 changed files with 68 additions and 51 deletions

View file

@ -3,8 +3,8 @@
#include "WSEvent.h"
#include "WSEventLoop.h"
#include "WSWindowManager.h"
#include <Kernel/FB.h>
#include <fcntl.h>
#include <sys/ioctl.h>
#include <sys/mman.h>
#include <unistd.h>
@ -16,9 +16,7 @@ WSScreen& WSScreen::the()
return *s_the;
}
WSScreen::WSScreen(unsigned width, unsigned height)
: m_width(width)
, m_height(height)
WSScreen::WSScreen(unsigned desired_width, unsigned desired_height)
{
ASSERT(!s_the);
s_the = this;
@ -26,7 +24,11 @@ WSScreen::WSScreen(unsigned width, unsigned height)
m_framebuffer_fd = open("/dev/fb0", O_RDWR);
ASSERT(m_framebuffer_fd >= 0);
set_resolution(width, height);
if (fb_set_buffer(m_framebuffer_fd, 0) == 0) {
m_can_set_buffer = true;
}
set_resolution(desired_width, desired_height);
}
WSScreen::~WSScreen()
@ -35,30 +37,40 @@ WSScreen::~WSScreen()
void WSScreen::set_resolution(int width, int height)
{
struct BXVGAResolution {
int width;
int height;
};
BXVGAResolution resolution { (int)width, (int)height };
int rc = ioctl(m_framebuffer_fd, 1985, (int)&resolution);
FBResolution resolution { 0, (int)width, (int)height };
int rc = fb_set_resolution(m_framebuffer_fd, &resolution);
ASSERT(rc == 0);
on_change_resolution(resolution.pitch, resolution.width, resolution.height);
}
void WSScreen::on_change_resolution(int pitch, int width, int height)
{
if (m_framebuffer) {
size_t previous_size_in_bytes = m_width * m_height * sizeof(RGBA32) * 2;
size_t previous_size_in_bytes = m_size_in_bytes;
int rc = munmap(m_framebuffer, previous_size_in_bytes);
ASSERT(rc == 0);
}
size_t framebuffer_size_in_bytes = width * height * sizeof(RGBA32) * 2;
m_framebuffer = (RGBA32*)mmap(nullptr, framebuffer_size_in_bytes, PROT_READ | PROT_WRITE, MAP_SHARED, m_framebuffer_fd, 0);
int rc = fb_get_size_in_bytes(m_framebuffer_fd, &m_size_in_bytes);
ASSERT(rc == 0);
m_framebuffer = (RGBA32*)mmap(nullptr, m_size_in_bytes, PROT_READ | PROT_WRITE, MAP_SHARED, m_framebuffer_fd, 0);
ASSERT(m_framebuffer && m_framebuffer != (void*)-1);
m_pitch = pitch;
m_width = width;
m_height = height;
m_cursor_location.constrain(rect());
}
void WSScreen::set_buffer(int index)
{
ASSERT(m_can_set_buffer);
int rc = fb_set_buffer(m_framebuffer_fd, index);
ASSERT(rc == 0);
}
void WSScreen::on_receive_mouse_data(int dx, int dy, int dz, unsigned buttons)
{
auto prev_location = m_cursor_location;
@ -96,9 +108,3 @@ void WSScreen::on_receive_keyboard_data(KeyEvent kernel_event)
auto message = make<WSKeyEvent>(kernel_event.is_press() ? WSEvent::KeyDown : WSEvent::KeyUp, kernel_event.key, kernel_event.character, kernel_event.modifiers());
CEventLoop::current().post_event(WSWindowManager::the(), move(message));
}
void WSScreen::set_y_offset(int offset)
{
int rc = ioctl(m_framebuffer_fd, 1982, offset);
ASSERT(rc == 0);
}