summaryrefslogtreecommitdiff
path: root/Kernel
diff options
context:
space:
mode:
authorAndreas Kling <awesomekling@gmail.com>2019-01-16 16:03:50 +0100
committerAndreas Kling <awesomekling@gmail.com>2019-01-16 16:03:50 +0100
commitf7ca6d254d452e3524aaeaa1334ac041be3a1279 (patch)
tree165f54aa32eafbfd79003eb686770370f585c14d /Kernel
parente655aebd70bb7d248c2f7be4a12d695ceec707a5 (diff)
downloadserenity-f7ca6d254d452e3524aaeaa1334ac041be3a1279.zip
Tear out or duplicate what's unique for WindowServer from Widgets.
This turned into a huge refactoring that somehow also includes making locks recursive/reentrant.
Diffstat (limited to 'Kernel')
-rw-r--r--Kernel/GUIEventDevice.cpp38
-rw-r--r--Kernel/GUIEventDevice.h16
-rw-r--r--Kernel/Makefile25
-rw-r--r--Kernel/Process.cpp2
-rw-r--r--Kernel/Process.h7
-rw-r--r--Kernel/ProcessGUI.cpp32
-rw-r--r--Kernel/Scheduler.cpp2
-rw-r--r--Kernel/WindowServer.cpp22
-rw-r--r--Kernel/i386.h1
-rw-r--r--Kernel/init.cpp2
10 files changed, 87 insertions, 60 deletions
diff --git a/Kernel/GUIEventDevice.cpp b/Kernel/GUIEventDevice.cpp
new file mode 100644
index 0000000000..20ba6c917b
--- /dev/null
+++ b/Kernel/GUIEventDevice.cpp
@@ -0,0 +1,38 @@
+#include "GUIEventDevice.h"
+#include <Kernel/Process.h>
+#include <AK/Lock.h>
+#include <LibC/errno_numbers.h>
+
+//#define GUIEVENTDEVICE_DEBUG
+
+GUIEventDevice::GUIEventDevice()
+ : CharacterDevice(66, 1)
+{
+}
+
+GUIEventDevice::~GUIEventDevice()
+{
+}
+
+bool GUIEventDevice::can_read(Process& process) const
+{
+ return !process.gui_events().is_empty();
+}
+
+ssize_t GUIEventDevice::read(Process& process, byte* buffer, size_t size)
+{
+#ifdef GUIEVENTDEVICE_DEBUG
+ dbgprintf("GUIEventDevice::read(): %s<%u>, size=%u, sizeof(GUI_Event)=%u\n", process.name().characters(), process.pid(), size, sizeof(GUI_Event));
+#endif
+ if (process.gui_events().is_empty())
+ return 0;
+ LOCKER(process.gui_events_lock());
+ ASSERT(size == sizeof(GUI_Event));
+ *reinterpret_cast<GUI_Event*>(buffer) = process.gui_events().take_first();
+ return size;
+}
+
+ssize_t GUIEventDevice::write(Process&, const byte*, size_t)
+{
+ return -EINVAL;
+}
diff --git a/Kernel/GUIEventDevice.h b/Kernel/GUIEventDevice.h
new file mode 100644
index 0000000000..e98b208f05
--- /dev/null
+++ b/Kernel/GUIEventDevice.h
@@ -0,0 +1,16 @@
+#pragma once
+
+#include <VirtualFileSystem/CharacterDevice.h>
+
+class GUIEventDevice final : public CharacterDevice {
+public:
+ GUIEventDevice();
+ virtual ~GUIEventDevice() override;
+
+private:
+ // ^CharacterDevice
+ virtual ssize_t read(Process&, byte* buffer, size_t bufferSize) override;
+ virtual ssize_t write(Process&, const byte* buffer, size_t bufferSize) override;
+ virtual bool can_read(Process&) const override;
+ virtual bool can_write(Process&) const override { return true; }
+};
diff --git a/Kernel/Makefile b/Kernel/Makefile
index 149cffa46c..580a921618 100644
--- a/Kernel/Makefile
+++ b/Kernel/Makefile
@@ -30,7 +30,7 @@ KERNEL_OBJS = \
ELFLoader.o \
KSyms.o \
PS2MouseDevice.o \
- WindowServer.o
+ GUIEventDevice.o
VFS_OBJS = \
../VirtualFileSystem/DiskDevice.o \
@@ -46,21 +46,20 @@ VFS_OBJS = \
../VirtualFileSystem/FileDescriptor.o \
../VirtualFileSystem/SyntheticFileSystem.o
-WIDGETS_OBJS = \
- ../Widgets/Window.o \
- ../Widgets/Painter.o \
- ../Widgets/WindowManager.o \
- ../Widgets/FrameBuffer.o \
- ../Widgets/GraphicsBitmap.o \
- ../Widgets/Object.o \
+WINDOWSERVER_OBJS = \
../Widgets/Rect.o \
- ../Widgets/Widget.o \
+ ../Widgets/Painter.o \
../Widgets/Font.o \
../Widgets/Color.o \
../Widgets/CharacterBitmap.o \
- ../Widgets/EventLoop.o \
- ../Widgets/AbstractScreen.o \
- ../Widgets/GUIEventDevice.o \
+ ../Widgets/GraphicsBitmap.o \
+ ../WindowServer/WSEventReceiver.o \
+ ../WindowServer/WSEventLoop.o \
+ ../WindowServer/WSWindow.o \
+ ../WindowServer/WSWindowManager.o \
+ ../WindowServer/WSFrameBuffer.o \
+ ../WindowServer/WSScreen.o \
+ ../WindowServer/main.o
AK_OBJS = \
../AK/String.o \
@@ -68,7 +67,7 @@ AK_OBJS = \
../AK/StringBuilder.o \
../AK/FileSystemPath.o
-OBJS = $(KERNEL_OBJS) $(VFS_OBJS) $(AK_OBJS) $(WIDGETS_OBJS)
+OBJS = $(KERNEL_OBJS) $(VFS_OBJS) $(AK_OBJS) $(WINDOWSERVER_OBJS)
NASM = nasm
KERNEL = kernel
diff --git a/Kernel/Process.cpp b/Kernel/Process.cpp
index 8b7bd457ac..eee7fc70a7 100644
--- a/Kernel/Process.cpp
+++ b/Kernel/Process.cpp
@@ -18,7 +18,7 @@
#include "Scheduler.h"
#include "FIFO.h"
#include "KSyms.h"
-#include <Widgets/Window.h>
+#include <WindowServer/WSWindow.h>
#include "MasterPTY.h"
//#define DEBUG_IO
diff --git a/Kernel/Process.h b/Kernel/Process.h
index 4e96a5328c..e79b37fa81 100644
--- a/Kernel/Process.h
+++ b/Kernel/Process.h
@@ -19,8 +19,7 @@ class PageDirectory;
class Region;
class VMObject;
class Zone;
-class Window;
-class Widget;
+class WSWindow;
#define COOL_GLOBALS
#ifdef COOL_GLOBALS
@@ -47,7 +46,7 @@ struct DisplayInfo {
class Process : public InlineLinkedListNode<Process> {
friend class InlineLinkedListNode<Process>;
- friend class WindowManager; // FIXME: Make a better API for allocate_region().
+ friend class WSWindowManager; // FIXME: Make a better API for allocate_region().
friend class GraphicsBitmap; // FIXME: Make a better API for allocate_region().
public:
static Process* create_kernel_process(String&& name, void (*entry)());
@@ -353,7 +352,7 @@ private:
RetainPtr<Region> m_display_framebuffer_region;
- HashMap<int, OwnPtr<Window>> m_windows;
+ HashMap<int, OwnPtr<WSWindow>> m_windows;
Vector<GUI_Event> m_gui_events;
SpinLock m_gui_events_lock;
diff --git a/Kernel/ProcessGUI.cpp b/Kernel/ProcessGUI.cpp
index 6801a9e86b..ff3ff76fc7 100644
--- a/Kernel/ProcessGUI.cpp
+++ b/Kernel/ProcessGUI.cpp
@@ -1,25 +1,22 @@
#include "Process.h"
#include "MemoryManager.h"
#include <LibC/errno_numbers.h>
-#include <Widgets/AbstractScreen.h>
-#include <Widgets/FrameBuffer.h>
-#include <Widgets/EventLoop.h>
#include <Widgets/Font.h>
-#include <Widgets/Button.h>
-#include <Widgets/Label.h>
-#include <Widgets/Widget.h>
-#include <Widgets/Window.h>
-#include <Widgets/WindowManager.h>
+#include <WindowServer/WSScreen.h>
+#include <WindowServer/WSFrameBuffer.h>
+#include <WindowServer/WSEventLoop.h>
+#include <WindowServer/WSWindow.h>
+#include <WindowServer/WSWindowManager.h>
void Process::initialize_gui_statics()
{
Font::initialize();
- FrameBuffer::initialize();
- EventLoop::initialize();
- WindowManager::initialize();
- AbstractScreen::initialize();
+ WSFrameBuffer::initialize();
+ WSEventLoop::initialize();
+ WSWindowManager::initialize();
+ WSScreen::initialize();
- new EventLoop;
+ new WSEventLoop;
}
int Process::make_window_id()
@@ -36,7 +33,7 @@ int Process::make_window_id()
static void wait_for_gui_server()
{
// FIXME: Time out after a while and return an error.
- while (!EventLoop::main().running())
+ while (!WSEventLoop::the().running())
sleep(10);
}
@@ -53,13 +50,13 @@ int Process::gui$create_window(const GUI_CreateWindowParameters* user_params)
if (rect.is_empty())
return -EINVAL;
- ProcessPagingScope scope(EventLoop::main().server_process());
+ ProcessPagingScope scope(WSEventLoop::the().server_process());
int window_id = make_window_id();
if (!window_id)
return -ENOMEM;
- auto window = make<Window>(*this, window_id);
+ auto window = make<WSWindow>(*this, window_id);
if (!window)
return -ENOMEM;
@@ -113,7 +110,6 @@ int Process::gui$invalidate_window(int window_id)
auto& window = *(*it).value;
// FIXME: This should queue up a message that the window server process can read.
// Poking into its data structures is not good.
- InterruptDisabler disabler;
- WindowManager::the().invalidate(window);
+ WSEventLoop::the().post_event(&window, make<WSEvent>(WSEvent::WM_Invalidate));
return 0;
}
diff --git a/Kernel/Scheduler.cpp b/Kernel/Scheduler.cpp
index 7bd8ee4d91..f8f546db1c 100644
--- a/Kernel/Scheduler.cpp
+++ b/Kernel/Scheduler.cpp
@@ -133,7 +133,7 @@ bool Scheduler::pick_next()
for (auto* process = g_processes->head(); process; process = process->next()) {
//if (process->state() == Process::BlockedWait || process->state() == Process::BlockedSleep)
// continue;
- dbgprintf("% 12s %s(%u) @ %w:%x\n", toString(process->state()), process->name().characters(), process->pid(), process->tss().cs, process->tss().eip);
+ dbgprintf("[K%x] % 12s %s(%u) @ %w:%x\n", process, toString(process->state()), process->name().characters(), process->pid(), process->tss().cs, process->tss().eip);
}
#endif
diff --git a/Kernel/WindowServer.cpp b/Kernel/WindowServer.cpp
deleted file mode 100644
index 674562ad7f..0000000000
--- a/Kernel/WindowServer.cpp
+++ /dev/null
@@ -1,22 +0,0 @@
-#include "Process.h"
-#include <Widgets/Font.h>
-#include <Widgets/FrameBuffer.h>
-#include <Widgets/WindowManager.h>
-#include <Widgets/EventLoop.h>
-#include <Widgets/Window.h>
-
-void WindowServer_main()
-{
- auto info = current->get_display_info();
-
- dbgprintf("Screen is %ux%ux%ubpp\n", info.width, info.height, info.bpp);
-
- FrameBuffer framebuffer((dword*)info.framebuffer, info.width, info.height);
-
- WindowManager::the();
-
- dbgprintf("Entering WindowServer main loop.\n");
- EventLoop::main().exec();
-
- ASSERT_NOT_REACHED();
-}
diff --git a/Kernel/i386.h b/Kernel/i386.h
index eae96cbd5c..d48c7b481e 100644
--- a/Kernel/i386.h
+++ b/Kernel/i386.h
@@ -81,6 +81,7 @@ void write_gdt_entry(word selector, Descriptor&);
#define cli() asm volatile("cli")
#define sti() asm volatile("sti")
+#define memory_barrier() asm volatile ("" ::: "memory")
static inline dword cpu_flags()
{
diff --git a/Kernel/init.cpp b/Kernel/init.cpp
index 52a942ac8d..1a6ce48bb8 100644
--- a/Kernel/init.cpp
+++ b/Kernel/init.cpp
@@ -15,7 +15,7 @@
#include <VirtualFileSystem/RandomDevice.h>
#include <VirtualFileSystem/Ext2FileSystem.h>
#include <VirtualFileSystem/VirtualFileSystem.h>
-#include <Widgets/GUIEventDevice.h>
+#include "GUIEventDevice.h"
#include "MemoryManager.h"
#include "ProcFileSystem.h"
#include "RTC.h"