1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 20:47:45 +00:00

Kernel: Add ioctls to BochsVGADevice for mode setting and page flipping.

Use these in WindowServer instead of poking at the BochsVGADevice directly.
This commit is contained in:
Andreas Kling 2019-02-16 10:24:55 +01:00
parent 799177feda
commit 468113422f
6 changed files with 50 additions and 16 deletions

View file

@ -3,6 +3,7 @@
#include <Kernel/PCI.h> #include <Kernel/PCI.h>
#include <Kernel/MemoryManager.h> #include <Kernel/MemoryManager.h>
#include <Kernel/Process.h> #include <Kernel/Process.h>
#include <LibC/errno_numbers.h>
#define VBE_DISPI_IOPORT_INDEX 0x01CE #define VBE_DISPI_IOPORT_INDEX 0x01CE
#define VBE_DISPI_IOPORT_DATA 0x01CF #define VBE_DISPI_IOPORT_DATA 0x01CF
@ -21,6 +22,13 @@
#define VBE_DISPI_ENABLED 0x01 #define VBE_DISPI_ENABLED 0x01
#define VBE_DISPI_LFB_ENABLED 0x40 #define VBE_DISPI_LFB_ENABLED 0x40
#define BXVGA_DEV_IOCTL_SET_Y_OFFSET 1982
#define BXVGA_DEV_IOCTL_SET_RESOLUTION 1985
struct BXVGAResolution {
int width;
int height;
};
static BochsVGADevice* s_the; static BochsVGADevice* s_the;
BochsVGADevice& BochsVGADevice::the() BochsVGADevice& BochsVGADevice::the()
@ -87,6 +95,24 @@ dword BochsVGADevice::find_framebuffer_address()
return framebuffer_address; return framebuffer_address;
} }
int BochsVGADevice::ioctl(Process& process, unsigned int request, unsigned int arg)
{
switch (request) {
case BXVGA_DEV_IOCTL_SET_Y_OFFSET:
set_y_offset(arg);
return 0;
case BXVGA_DEV_IOCTL_SET_RESOLUTION: {
auto* resolution = (const BXVGAResolution*)arg;
if (!process.validate_read_typed(resolution))
return -EFAULT;
set_resolution(resolution->width, resolution->height);
return 0;
}
default:
return -EINVAL;
};
}
bool BochsVGADevice::can_read(Process&) const bool BochsVGADevice::can_read(Process&) const
{ {
ASSERT_NOT_REACHED(); ASSERT_NOT_REACHED();

View file

@ -17,7 +17,7 @@ public:
void set_resolution(int width, int height); void set_resolution(int width, int height);
void set_y_offset(int); void set_y_offset(int);
virtual int ioctl(Process&, unsigned request, unsigned arg) override;
virtual Region* mmap(Process&, LinearAddress preferred_laddr, size_t offset, size_t) override; virtual Region* mmap(Process&, LinearAddress preferred_laddr, size_t offset, size_t) override;
size_t framebuffer_size_in_bytes() const { return m_framebuffer_size.area() * sizeof(dword) * 2; } size_t framebuffer_size_in_bytes() const { return m_framebuffer_size.area() * sizeof(dword) * 2; }

View file

@ -1786,9 +1786,9 @@ int Process::sys$ioctl(int fd, unsigned request, unsigned arg)
*pid = descriptor->socket()->origin_pid(); *pid = descriptor->socket()->origin_pid();
return 0; return 0;
} }
if (!descriptor->is_character_device()) if (!descriptor->is_device())
return -ENOTTY; return -ENOTTY;
return descriptor->character_device()->ioctl(*this, request, arg); return descriptor->device()->ioctl(*this, request, arg);
} }
int Process::sys$getdtablesize() int Process::sys$getdtablesize()

View file

@ -9,7 +9,6 @@
#include <SharedGraphics/Painter.h> #include <SharedGraphics/Painter.h>
#include <SharedGraphics/CharacterBitmap.h> #include <SharedGraphics/CharacterBitmap.h>
#include <AK/StdLibExtras.h> #include <AK/StdLibExtras.h>
#include <Kernel/BochsVGADevice.h>
#include <LibC/errno_numbers.h> #include <LibC/errno_numbers.h>
#include "WSMenu.h" #include "WSMenu.h"
#include "WSMenuBar.h" #include "WSMenuBar.h"
@ -126,10 +125,11 @@ 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_buffers_are_flipped) if (m_framebuffer_fd != -1) {
BochsVGADevice::the().set_y_offset(0); int new_y_offset = m_buffers_are_flipped ? 0 : m_screen_rect.height();
else int rc = current->sys$ioctl(m_framebuffer_fd, 1982, new_y_offset);
BochsVGADevice::the().set_y_offset(m_screen_rect.height()); ASSERT(rc == 0);
}
m_buffers_are_flipped = !m_buffers_are_flipped; m_buffers_are_flipped = !m_buffers_are_flipped;
} }

View file

@ -63,8 +63,8 @@ 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 api$menu_add_separator(int menu_id); int framebuffer_fd() const { return m_framebuffer_fd; }
int api$menu_add_item(int menu_id, unsigned identifier, String&& text); void set_framebuffer_fd(int fd) { m_framebuffer_fd = fd; }
private: private:
WSWindowManager(); WSWindowManager();
@ -151,4 +151,6 @@ 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

@ -12,27 +12,33 @@ void WindowServer_main()
{ {
WSMessageLoop::the().set_server_process(*current); WSMessageLoop::the().set_server_process(*current);
current->set_priority(Process::HighPriority); current->set_priority(Process::HighPriority);
auto info = current->set_video_resolution(1024, 768);
dbgprintf("Screen is %ux%ux%ubpp\n", info.width, info.height, info.bpp);
int bxvga_fd = current->sys$open("/dev/bxvga", O_RDWR); int bxvga_fd = current->sys$open("/dev/bxvga", O_RDWR);
ASSERT(bxvga_fd >= 0); ASSERT(bxvga_fd >= 0);
struct BXVGAResolution {
int width;
int height;
};
BXVGAResolution resolution { 1024, 768 };
int rc = current->sys$ioctl(bxvga_fd, 1985, (int)&resolution);
ASSERT(rc == 0);
Syscall::SC_mmap_params params; Syscall::SC_mmap_params params;
memset(&params, 0, sizeof(params)); memset(&params, 0, sizeof(params));
params.fd = bxvga_fd; params.fd = bxvga_fd;
params.prot = PROT_READ | PROT_WRITE; params.prot = PROT_READ | PROT_WRITE;
params.flags = MAP_SHARED; params.flags = MAP_SHARED;
params.size = info.width * info.height * sizeof(RGBA32) * 2; params.size = resolution.width * resolution.height * sizeof(RGBA32) * 2;
params.offset = 0; params.offset = 0;
kprintf("Calling sys$mmap in WS\n"); kprintf("Calling sys$mmap in WS\n");
void* framebuffer = current->sys$mmap(&params); void* framebuffer = current->sys$mmap(&params);
ASSERT(framebuffer && framebuffer != (void*)-1); ASSERT(framebuffer && framebuffer != (void*)-1);
WSScreen screen((dword*)framebuffer, info.width, info.height); WSScreen screen((dword*)framebuffer, resolution.width, resolution.height);
WSWindowManager::the(); WSWindowManager::the().set_framebuffer_fd(bxvga_fd);
dbgprintf("Entering WindowServer main loop.\n"); dbgprintf("Entering WindowServer main loop.\n");
WSMessageLoop::the().exec(); WSMessageLoop::the().exec();