1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 17:37:34 +00:00

WindowServer: Convert entire API to be message-based.

One big step towards userspace WindowServer. :^)
This commit is contained in:
Andreas Kling 2019-02-14 01:21:32 +01:00
parent ef4e9860fd
commit f529b845ec
25 changed files with 508 additions and 625 deletions

View file

@ -76,11 +76,21 @@ struct GUI_ServerMessage {
DidSetApplicationMenubar,
DidAddMenuItem,
DidAddMenuSeparator,
DidCreateWindow,
DidDestroyWindow,
DidGetWindowTitle,
DidGetWindowRect,
DidGetWindowBackingStore,
};
Type type { Invalid };
int window_id { -1 };
size_t text_length;
char text[256];
union {
struct {
GUI_Rect rect;
} window;
struct {
GUI_Rect rect;
} paint;
@ -102,6 +112,13 @@ struct GUI_ServerMessage {
int menu_id;
unsigned identifier;
} menu;
struct {
void* backing_store_id;
GUI_Size size;
size_t bpp;
size_t pitch;
RGBA32* pixels;
} backing;
};
};
@ -116,18 +133,36 @@ struct GUI_ClientMessage {
SetApplicationMenubar,
AddMenuItem,
AddMenuSeparator,
CreateWindow,
DestroyWindow,
SetWindowTitle,
GetWindowTitle,
SetWindowRect,
GetWindowRect,
InvalidateRect,
DidFinishPainting,
GetWindowBackingStore,
ReleaseWindowBackingStore,
SetGlobalCursorTracking,
};
Type type { Invalid };
int window_id { -1 };
size_t text_length;
char text[256];
int value { 0 };
union {
struct {
int menubar_id;
int menu_id;
unsigned identifier;
unsigned text_length;
char text[256];
} menu;
struct {
GUI_Rect rect;
} window;
struct {
void* backing_store_id;
} backing;
};
};

View file

@ -2133,7 +2133,6 @@ void Process::finalize()
{
ASSERT(current == g_finalizer);
destroy_all_menus();
destroy_all_windows();
m_fds.clear();
m_tty = nullptr;

View file

@ -219,24 +219,10 @@ public:
int sys$read_tsc(dword* lsw, dword* msw);
int sys$chmod(const char* pathname, mode_t);
int gui$create_window(const GUI_WindowParameters*);
int gui$destroy_window(int window_id);
int gui$get_window_backing_store(int window_id, GUI_WindowBackingStoreInfo*);
int gui$release_window_backing_store(void* backing_store_id);
int gui$invalidate_window(int window_id, const GUI_Rect*);
int gui$notify_paint_finished(int window_id, const GUI_Rect*);
int gui$get_window_title(int window_id, char* buffer, size_t size);
int gui$set_window_title(int window_id, const char* title, size_t size);
int gui$get_window_rect(int window_id, GUI_Rect*);
int gui$set_window_rect(int window_id, const GUI_Rect*);
int gui$set_global_cursor_tracking_enabled(int window_id, bool enabled);
DisplayInfo set_video_resolution(int width, int height);
static void initialize();
static void initialize_gui_statics();
int make_window_id();
void destroy_all_menus();
void destroy_all_windows();
void crash() NORETURN;
@ -408,12 +394,8 @@ private:
RetainPtr<Region> m_display_framebuffer_region;
HashMap<int, OwnPtr<WSWindow>> m_windows;
Vector<RetainPtr<GraphicsBitmap>> m_retained_backing_stores;
Vector<GUI_ServerMessage> m_gui_events;
Lock m_gui_events_lock;
int m_next_window_id { 1 };
dword m_wakeup_requested { false };
bool m_has_used_fpu { false };

View file

@ -16,262 +16,11 @@ void Process::initialize_gui_statics()
new WSMessageLoop;
}
int Process::make_window_id()
{
int new_id = m_next_window_id++;
while (!new_id || m_windows.contains(new_id)) {
new_id = m_next_window_id++;
if (new_id < 0)
new_id = 1;
}
return new_id;
}
static void wait_for_gui_server()
{
// FIXME: Time out after a while and return an error.
while (!WSMessageLoop::the().running())
sleep(10);
}
int Process::gui$create_window(const GUI_WindowParameters* user_params)
{
wait_for_gui_server();
if (!validate_read_typed(user_params))
return -EFAULT;
auto params = *user_params;
Rect rect = params.rect;
if (rect.is_empty())
return -EINVAL;
ProcessPagingScope scope(WSMessageLoop::the().server_process());
int window_id = make_window_id();
if (!window_id)
return -ENOMEM;
auto window = make<WSWindow>(*this, window_id);
if (!window)
return -ENOMEM;
window->set_title(params.title);
window->set_rect(rect);
m_windows.set(window_id, move(window));
#ifdef LOG_GUI_SYSCALLS
dbgprintf("%s<%u> gui$create_window: %d with rect {%d,%d %dx%d}\n", name().characters(), pid(), window_id, rect.x(), rect.y(), rect.width(), rect.height());
#endif
return window_id;
}
int Process::gui$destroy_window(int window_id)
{
#ifdef LOG_GUI_SYSCALLS
dbgprintf("%s<%u> gui$destroy_window (window_id=%d)\n", name().characters(), pid(), window_id);
#endif
if (window_id < 0)
return -EINVAL;
auto it = m_windows.find(window_id);
if (it == m_windows.end())
return -EBADWINDOW;
auto message = make<WSMessage>(WSMessage::WM_DestroyWindow);
WSMessageLoop::the().post_message((*it).value.leak_ptr(), move(message));
m_windows.remove(window_id);
return 0;
}
int Process::gui$get_window_backing_store(int window_id, GUI_WindowBackingStoreInfo* info)
{
#ifdef LOG_GUI_SYSCALLS
dbgprintf("%s<%u> gui$get_window_backing_store (window_id=%d, info=%p)\n", name().characters(), pid(), window_id, info);
#endif
if (!validate_write_typed(info))
return -EFAULT;
if (window_id < 0)
return -EINVAL;
auto it = m_windows.find(window_id);
if (it == m_windows.end())
return -EBADWINDOW;
auto& window = *(*it).value;
WSWindowLocker locker(window);
auto* backing_store = window.backing();
#ifdef BACKING_STORE_DEBUG
dbgprintf("%s<%u> +++ %p[%d] (%dx%d)\n", name().characters(), pid(), backing_store, backing_store->width(), backing_store->height());
#endif
m_retained_backing_stores.append(backing_store);
info->backing_store_id = backing_store;
info->bpp = sizeof(RGBA32);
info->pitch = backing_store->pitch();
info->size = backing_store->size();
info->pixels = reinterpret_cast<RGBA32*>(backing_store->client_region()->laddr().as_ptr());
return 0;
}
int Process::gui$release_window_backing_store(void* backing_store_id)
{
for (size_t i = 0; i < m_retained_backing_stores.size(); ++i) {
if (m_retained_backing_stores[i].ptr() == backing_store_id) {
#ifdef BACKING_STORE_DEBUG
auto* backing_store = m_retained_backing_stores[i].ptr();
dbgprintf("%s<%u> --- %p (%dx%d)\n", name().characters(), pid(), backing_store, backing_store->width(), backing_store->height());
#endif
m_retained_backing_stores.remove(i);
return 0;
}
}
return -EBADBACKING;
}
int Process::gui$invalidate_window(int window_id, const GUI_Rect* a_rect)
{
if (window_id < 0)
return -EINVAL;
if (a_rect && !validate_read_typed(a_rect))
return -EFAULT;
auto it = m_windows.find(window_id);
if (it == m_windows.end())
return -EBADWINDOW;
#ifdef LOG_GUI_SYSCALLS
if (!a_rect)
dbgprintf("%s<%u> gui$invalidate_window (window_id=%d, rect=(entire))\n", name().characters(), pid(), window_id);
else
dbgprintf("%s<%u> gui$invalidate_window (window_id=%d, rect={%d,%d %dx%d})\n", name().characters(), pid(), window_id, a_rect->location.x, a_rect->location.y, a_rect->size.width, a_rect->size.height);
#endif
auto& window = *(*it).value;
Rect rect;
if (a_rect)
rect = *a_rect;
WSMessageLoop::the().post_message(&window, make<WSClientWantsToPaintMessage>(rect));
WSMessageLoop::the().server_process().request_wakeup();
return 0;
}
int Process::gui$notify_paint_finished(int window_id, const GUI_Rect* a_rect)
{
if (window_id < 0)
return -EINVAL;
if (a_rect && !validate_read_typed(a_rect))
return -EFAULT;
auto it = m_windows.find(window_id);
if (it == m_windows.end())
return -EBADWINDOW;
#ifdef LOG_GUI_SYSCALLS
if (!a_rect)
dbgprintf("%s<%u> gui$notify_paint_finished (window_id=%d, rect=(entire))\n", name().characters(), pid(), window_id);
else
dbgprintf("%s<%u> gui$notify_paint_finished (window_id=%d, rect={%d,%d %dx%d})\n", name().characters(), pid(), window_id, a_rect->location.x, a_rect->location.y, a_rect->size.width, a_rect->size.height);
#endif
auto& window = *(*it).value;
Rect rect;
if (a_rect)
rect = *a_rect;
WSMessageLoop::the().post_message(&window, make<WSClientFinishedPaintMessage>(rect));
WSMessageLoop::the().server_process().request_wakeup();
return 0;
}
int Process::gui$get_window_title(int window_id, char* buffer, size_t size)
{
if (window_id < 0)
return -EINVAL;
if (!validate_write(buffer, size))
return -EFAULT;
auto it = m_windows.find(window_id);
if (it == m_windows.end())
return -EBADWINDOW;
auto& window = *(*it).value;
String title;
{
WSWindowLocker locker(window);
title = window.title();
}
if (title.length() > size)
return -ERANGE;
memcpy(buffer, title.characters(), title.length());
return title.length();
}
int Process::gui$set_window_title(int window_id, const char* title, size_t size)
{
if (window_id < 0)
return -EINVAL;
if (!validate_read(title, size))
return -EFAULT;
auto it = m_windows.find(window_id);
if (it == m_windows.end())
return -EBADWINDOW;
auto& window = *(*it).value;
String new_title(title, size);
WSMessageLoop::the().post_message(&window, make<WSSetWindowTitleMessage>(move(new_title)));
WSMessageLoop::the().server_process().request_wakeup();
return 0;
}
int Process::gui$get_window_rect(int window_id, GUI_Rect* rect)
{
if (window_id < 0)
return -EINVAL;
if (!validate_write_typed(rect))
return -EFAULT;
auto it = m_windows.find(window_id);
if (it == m_windows.end())
return -EBADWINDOW;
auto& window = *(*it).value;
{
WSWindowLocker locker(window);
*rect = window.rect();
}
return 0;
}
int Process::gui$set_window_rect(int window_id, const GUI_Rect* rect)
{
if (window_id < 0)
return -EINVAL;
if (!validate_read_typed(rect))
return -EFAULT;
auto it = m_windows.find(window_id);
if (it == m_windows.end())
return -EBADWINDOW;
auto& window = *(*it).value;
Rect new_rect = *rect;
WSMessageLoop::the().post_message(&window, make<WSSetWindowRectMessage>(new_rect));
WSMessageLoop::the().server_process().request_wakeup();
return 0;
}
int Process::gui$set_global_cursor_tracking_enabled(int window_id, bool enabled)
{
if (window_id < 0)
return -EINVAL;
auto it = m_windows.find(window_id);
if (it == m_windows.end())
return -EBADWINDOW;
auto& window = *(*it).value;
WSWindowLocker locker(window);
window.set_global_cursor_tracking_enabled(enabled);
return 0;
}
void Process::destroy_all_menus()
void Process::destroy_all_windows()
{
if (!WSMessageLoop::the().running())
return;
WSWindowManager::the().destroy_all_menus(*this);
}
void Process::destroy_all_windows()
{
for (auto& it : m_windows) {
auto message = make<WSMessage>(WSMessage::WM_DestroyWindow);
it.value->notify_process_died(Badge<Process>());
WSMessageLoop::the().post_message(it.value.leak_ptr(), move(message));
}
m_windows.clear();
WSMessageLoop::the().notify_client_died(gui_client_id());
}
DisplayInfo Process::set_video_resolution(int width, int height)

View file

@ -195,30 +195,8 @@ static dword handle(RegisterDump& regs, dword function, dword arg1, dword arg2,
return sync();
case Syscall::SC_unlink:
return current->sys$unlink((const char*)arg1);
case Syscall::SC_gui_create_window:
return current->gui$create_window((const GUI_WindowParameters*)arg1);
case Syscall::SC_gui_destroy_window:
return current->gui$destroy_window((int)arg1);
case Syscall::SC_gui_get_window_backing_store:
return current->gui$get_window_backing_store((int)arg1, (GUI_WindowBackingStoreInfo*)arg2);
case Syscall::SC_gui_release_window_backing_store:
return current->gui$release_window_backing_store((void*)arg1);
case Syscall::SC_gui_invalidate_window:
return current->gui$invalidate_window((int)arg1, (const GUI_Rect*)arg2);
case Syscall::SC_gui_set_window_title:
return current->gui$set_window_title((int)arg1, (const char*)arg2, (size_t)arg3);
case Syscall::SC_gui_get_window_title:
return current->gui$get_window_title((int)arg1, (char*)arg2, (size_t)arg3);
case Syscall::SC_gui_set_window_rect:
return current->gui$set_window_rect((int)arg1, (const GUI_Rect*)arg2);
case Syscall::SC_gui_get_window_rect:
return current->gui$get_window_rect((int)arg1, (GUI_Rect*)arg2);
case Syscall::SC_read_tsc:
return current->sys$read_tsc((dword*)arg1, (dword*)arg2);
case Syscall::SC_gui_notify_paint_finished:
return current->gui$notify_paint_finished((int)arg1, (const GUI_Rect*)arg2);
case Syscall::SC_gui_set_global_cursor_tracking_enabled:
return current->gui$set_global_cursor_tracking_enabled((int)arg1, (bool)arg2);
case Syscall::SC_rmdir:
return current->sys$rmdir((const char*)arg1);
case Syscall::SC_chmod:

View file

@ -71,17 +71,6 @@
__ENUMERATE_SYSCALL(unlink) \
__ENUMERATE_SYSCALL(poll) \
__ENUMERATE_SYSCALL(read_tsc) \
__ENUMERATE_SYSCALL(gui_create_window) \
__ENUMERATE_SYSCALL(gui_destroy_window) \
__ENUMERATE_SYSCALL(gui_get_window_backing_store) \
__ENUMERATE_SYSCALL(gui_release_window_backing_store) \
__ENUMERATE_SYSCALL(gui_invalidate_window) \
__ENUMERATE_SYSCALL(gui_get_window_title) \
__ENUMERATE_SYSCALL(gui_set_window_title) \
__ENUMERATE_SYSCALL(gui_get_window_rect) \
__ENUMERATE_SYSCALL(gui_set_window_rect) \
__ENUMERATE_SYSCALL(gui_notify_paint_finished) \
__ENUMERATE_SYSCALL(gui_set_global_cursor_tracking_enabled) \
__ENUMERATE_SYSCALL(rmdir) \
__ENUMERATE_SYSCALL(chmod) \
__ENUMERATE_SYSCALL(usleep) \

View file

@ -57,7 +57,6 @@ cp -v ../Userland/more mnt/bin/more
cp -v ../Userland/rm mnt/bin/rm
cp -v ../Userland/rmdir mnt/bin/rmdir
cp -v ../Userland/cp mnt/bin/cp
cp -v ../Userland/guitest mnt/bin/guitest
cp -v ../Userland/guitest2 mnt/bin/guitest2
cp -v ../Userland/sysctl mnt/bin/sysctl
cp -v ../Userland/pape mnt/bin/pape