1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-24 20:17:41 +00:00

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
6 changed files with 47 additions and 58 deletions

View file

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

View file

@ -2,6 +2,10 @@
#include "WSMessageLoop.h" #include "WSMessageLoop.h"
#include "WSMessage.h" #include "WSMessage.h"
#include "WSWindowManager.h" #include "WSWindowManager.h"
#include <unistd.h>
#include <fcntl.h>
#include <sys/ioctl.h>
#include <sys/mman.h>
static WSScreen* s_the; static WSScreen* s_the;
@ -11,15 +15,29 @@ WSScreen& WSScreen::the()
return *s_the; return *s_the;
} }
WSScreen::WSScreen(RGBA32* framebuffer, unsigned width, unsigned height) WSScreen::WSScreen(unsigned width, unsigned height)
: m_framebuffer(framebuffer) : m_width(width)
, m_width(width)
, m_height(height) , m_height(height)
{ {
ASSERT(!s_the); ASSERT(!s_the);
s_the = this; s_the = this;
m_cursor_location = rect().center(); 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() WSScreen::~WSScreen()
@ -68,3 +86,9 @@ void WSScreen::on_receive_keyboard_data(KeyEvent kernel_event)
message->m_alt = kernel_event.alt(); message->m_alt = kernel_event.alt();
WSMessageLoop::the().post_message(&WSWindowManager::the(), move(message)); 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 { class WSScreen {
public: public:
WSScreen(RGBA32*, unsigned width, unsigned height); WSScreen(unsigned width, unsigned height);
~WSScreen(); ~WSScreen();
void set_resolution(int width, int height); void set_resolution(int width, int height);
@ -21,6 +21,8 @@ public:
Size size() const { return { width(), height() }; } Size size() const { return { width(), height() }; }
Rect rect() const { return { 0, 0, width(), height() }; } Rect rect() const { return { 0, 0, width(), height() }; }
void set_y_offset(int);
Point cursor_location() const { return m_cursor_location; } Point cursor_location() const { return m_cursor_location; }
bool left_mouse_button_pressed() const { return m_left_mouse_button_pressed; } bool left_mouse_button_pressed() const { return m_left_mouse_button_pressed; }
bool right_mouse_button_pressed() const { return m_right_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_mouse_data(int dx, int dy, bool left_button, bool right_button);
void on_receive_keyboard_data(KeyEvent); void on_receive_keyboard_data(KeyEvent);
protected:
WSScreen(unsigned width, unsigned height);
private: private:
RGBA32* m_framebuffer { nullptr }; RGBA32* m_framebuffer { nullptr };
int m_width { 0 }; int m_width { 0 };
int m_height { 0 }; int m_height { 0 };
int m_framebuffer_fd { -1 };
Point m_cursor_location; Point m_cursor_location;
bool m_left_mouse_button_pressed { false }; bool m_left_mouse_button_pressed { false };

View file

@ -11,7 +11,6 @@
#include "WSMenuBar.h" #include "WSMenuBar.h"
#include "WSMenuItem.h" #include "WSMenuItem.h"
#include <WindowServer/WSClientConnection.h> #include <WindowServer/WSClientConnection.h>
#include <sys/ioctl.h>
#include <unistd.h> #include <unistd.h>
#include <stdio.h> #include <stdio.h>
#include <time.h> #include <time.h>
@ -128,11 +127,8 @@ void WSWindowManager::flip_buffers()
{ {
swap(m_front_bitmap, m_back_bitmap); swap(m_front_bitmap, m_back_bitmap);
swap(m_front_painter, m_back_painter); 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 new_y_offset = m_buffers_are_flipped ? 0 : m_screen_rect.height(); WSScreen::the().set_y_offset(new_y_offset);
int rc = ioctl(m_framebuffer_fd, 1982, new_y_offset);
ASSERT(rc == 0);
}
m_buffers_are_flipped = !m_buffers_are_flipped; 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; } Color menu_selection_color() const { return m_menu_selection_color; }
int menubar_menu_margin() const; int menubar_menu_margin() const;
int framebuffer_fd() const { return m_framebuffer_fd; }
void set_framebuffer_fd(int fd) { m_framebuffer_fd = fd; }
private: private:
void process_mouse_event(WSMouseEvent&); void process_mouse_event(WSMouseEvent&);
void handle_menu_mouse_event(WSMenu&, WSMouseEvent&); void handle_menu_mouse_event(WSMenu&, WSMouseEvent&);
@ -149,6 +146,4 @@ private:
Color m_menu_selection_color; Color m_menu_selection_color;
WeakPtr<WSMenuBar> m_current_menubar; WeakPtr<WSMenuBar> m_current_menubar;
WeakPtr<WSMenu> m_current_menu; 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/WSScreen.h>
#include <WindowServer/WSWindowManager.h> #include <WindowServer/WSWindowManager.h>
#include <WindowServer/WSMessageLoop.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**) int main(int, char**)
{ {
dbgprintf("WindowServer starting...\n");
WSMessageLoop loop; WSMessageLoop loop;
WSScreen screen(1024, 768);
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);
WSWindowManager window_manager; WSWindowManager window_manager;
window_manager.set_framebuffer_fd(bxvga_fd);
dbgprintf("Entering WindowServer main loop.\n"); dbgprintf("Entering WindowServer main loop.\n");
WSMessageLoop::the().exec(); WSMessageLoop::the().exec();
ASSERT_NOT_REACHED(); ASSERT_NOT_REACHED();
} }