WindowServer: Move video mode setup to WSScreen.

This commit is contained in:
Andreas Kling 2019-02-17 01:43:01 +01:00
parent 809266a9fb
commit 82768e7ac5
Notes: sideshowbarker 2024-07-19 15:41:32 +09:00
6 changed files with 47 additions and 58 deletions

View File

@ -1,18 +1,18 @@
#include "WSMessageLoop.h"
#include "WSMessage.h"
#include "WSMessageReceiver.h"
#include "WSWindowManager.h"
#include "WSScreen.h"
#include <WindowServer/WSMessageLoop.h>
#include <WindowServer/WSMessage.h>
#include <WindowServer/WSMessageReceiver.h>
#include <WindowServer/WSWindowManager.h>
#include <WindowServer/WSScreen.h>
#include <WindowServer/WSClientConnection.h>
#include <Kernel/KeyCode.h>
#include <WindowServer/WSAPITypes.h>
#include <unistd.h>
#include <time.h>
#include <sys/socket.h>
#include <sys/select.h>
#include <fcntl.h>
#include <stdio.h>
#include <errno.h>
#include <Kernel/KeyCode.h>
#include <LibC/sys/socket.h>
#include <LibC/sys/select.h>
#include <LibC/unistd.h>
#include <LibC/time.h>
#include <LibC/fcntl.h>
#include <LibC/stdio.h>
#include <LibC/errno.h>
//#define WSEVENTLOOP_DEBUG

View File

@ -2,6 +2,10 @@
#include "WSMessageLoop.h"
#include "WSMessage.h"
#include "WSWindowManager.h"
#include <unistd.h>
#include <fcntl.h>
#include <sys/ioctl.h>
#include <sys/mman.h>
static WSScreen* s_the;
@ -11,15 +15,29 @@ WSScreen& WSScreen::the()
return *s_the;
}
WSScreen::WSScreen(RGBA32* framebuffer, unsigned width, unsigned height)
: m_framebuffer(framebuffer)
, m_width(width)
WSScreen::WSScreen(unsigned width, unsigned height)
: m_width(width)
, m_height(height)
{
ASSERT(!s_the);
s_the = this;
m_cursor_location = rect().center();
m_framebuffer_fd = open("/dev/bxvga", O_RDWR);
ASSERT(m_framebuffer_fd >= 0);
struct BXVGAResolution {
int width;
int height;
};
BXVGAResolution resolution { (int)width, (int)height};
int rc = ioctl(m_framebuffer_fd, 1985, (int)&resolution);
ASSERT(rc == 0);
size_t framebuffer_size_in_bytes = resolution.width * resolution.height * sizeof(RGBA32) * 2;
m_framebuffer = (RGBA32*)mmap(nullptr, framebuffer_size_in_bytes, PROT_READ | PROT_WRITE, MAP_SHARED, m_framebuffer_fd, 0);
ASSERT(m_framebuffer && m_framebuffer != (void*)-1);
}
WSScreen::~WSScreen()
@ -68,3 +86,9 @@ void WSScreen::on_receive_keyboard_data(KeyEvent kernel_event)
message->m_alt = kernel_event.alt();
WSMessageLoop::the().post_message(&WSWindowManager::the(), move(message));
}
void WSScreen::set_y_offset(int offset)
{
int rc = ioctl(m_framebuffer_fd, 1982, offset);
ASSERT(rc == 0);
}

View File

@ -7,7 +7,7 @@
class WSScreen {
public:
WSScreen(RGBA32*, unsigned width, unsigned height);
WSScreen(unsigned width, unsigned height);
~WSScreen();
void set_resolution(int width, int height);
@ -21,6 +21,8 @@ public:
Size size() const { return { width(), height() }; }
Rect rect() const { return { 0, 0, width(), height() }; }
void set_y_offset(int);
Point cursor_location() const { return m_cursor_location; }
bool left_mouse_button_pressed() const { return m_left_mouse_button_pressed; }
bool right_mouse_button_pressed() const { return m_right_mouse_button_pressed; }
@ -28,14 +30,12 @@ public:
void on_receive_mouse_data(int dx, int dy, bool left_button, bool right_button);
void on_receive_keyboard_data(KeyEvent);
protected:
WSScreen(unsigned width, unsigned height);
private:
RGBA32* m_framebuffer { nullptr };
int m_width { 0 };
int m_height { 0 };
int m_framebuffer_fd { -1 };
Point m_cursor_location;
bool m_left_mouse_button_pressed { false };

View File

@ -11,7 +11,6 @@
#include "WSMenuBar.h"
#include "WSMenuItem.h"
#include <WindowServer/WSClientConnection.h>
#include <sys/ioctl.h>
#include <unistd.h>
#include <stdio.h>
#include <time.h>
@ -128,11 +127,8 @@ void WSWindowManager::flip_buffers()
{
swap(m_front_bitmap, m_back_bitmap);
swap(m_front_painter, m_back_painter);
if (m_framebuffer_fd != -1) {
int new_y_offset = m_buffers_are_flipped ? 0 : m_screen_rect.height();
int rc = ioctl(m_framebuffer_fd, 1982, new_y_offset);
ASSERT(rc == 0);
}
int new_y_offset = m_buffers_are_flipped ? 0 : m_screen_rect.height();
WSScreen::the().set_y_offset(new_y_offset);
m_buffers_are_flipped = !m_buffers_are_flipped;
}

View File

@ -66,9 +66,6 @@ public:
Color menu_selection_color() const { return m_menu_selection_color; }
int menubar_menu_margin() const;
int framebuffer_fd() const { return m_framebuffer_fd; }
void set_framebuffer_fd(int fd) { m_framebuffer_fd = fd; }
private:
void process_mouse_event(WSMouseEvent&);
void handle_menu_mouse_event(WSMenu&, WSMouseEvent&);
@ -149,6 +146,4 @@ private:
Color m_menu_selection_color;
WeakPtr<WSMenuBar> m_current_menubar;
WeakPtr<WSMenu> m_current_menu;
int m_framebuffer_fd { -1 };
};

View File

@ -1,40 +1,14 @@
#include <SharedGraphics/Font.h>
#include <WindowServer/WSScreen.h>
#include <WindowServer/WSWindowManager.h>
#include <WindowServer/WSMessageLoop.h>
#include <WindowServer/WSWindow.h>
#include <unistd.h>
#include <fcntl.h>
#include <sys/ioctl.h>
#include <sys/mman.h>
int main(int, char**)
{
dbgprintf("WindowServer starting...\n");
WSMessageLoop loop;
int bxvga_fd = open("/dev/bxvga", O_RDWR);
ASSERT(bxvga_fd >= 0);
struct BXVGAResolution {
int width;
int height;
};
BXVGAResolution resolution { 1024, 768 };
int rc = ioctl(bxvga_fd, 1985, (int)&resolution);
ASSERT(rc == 0);
size_t framebuffer_size_in_bytes = resolution.width * resolution.height * sizeof(RGBA32) * 2;
void* framebuffer = mmap(nullptr, framebuffer_size_in_bytes, PROT_READ | PROT_WRITE, MAP_SHARED, bxvga_fd, 0);
ASSERT(framebuffer && framebuffer != (void*)-1);
WSScreen screen((dword*)framebuffer, resolution.width, resolution.height);
WSScreen screen(1024, 768);
WSWindowManager window_manager;
window_manager.set_framebuffer_fd(bxvga_fd);
dbgprintf("Entering WindowServer main loop.\n");
WSMessageLoop::the().exec();
ASSERT_NOT_REACHED();
}