فهرست منبع

Hook everything up to run the GUI on top of the kernel.

Okay things kinda sorta work. Both Bochs and QEMU now boot into GUI mode.
There's a ton of stuff that doesn't make sense and so many things to rework.

Still it's quite cool to have made it this far. :^)
Andreas Kling 6 سال پیش
والد
کامیت
f6d2c3ed87

+ 16 - 1
Kernel/Makefile

@@ -43,7 +43,22 @@ VFS_OBJS = \
 
 
 WIDGETS_OBJS = \
 WIDGETS_OBJS = \
     ../Widgets/Window.o \
     ../Widgets/Window.o \
-    ../Widgets/Painter.o
+    ../Widgets/Painter.o \
+    ../Widgets/WindowManager.o \
+    ../Widgets/FrameBuffer.o \
+    ../Widgets/GraphicsBitmap.o \
+    ../Widgets/Object.o \
+    ../Widgets/Rect.o \
+    ../Widgets/Widget.o \
+    ../Widgets/Font.o \
+    ../Widgets/Color.o \
+    ../Widgets/CharacterBitmap.o \
+    ../Widgets/EventLoop.o \
+    ../Widgets/RootWidget.o \
+    ../Widgets/Label.o \
+    ../Widgets/Button.o \
+    ../Widgets/MsgBox.o \
+    ../Widgets/AbstractScreen.o
 
 
 AK_OBJS = \
 AK_OBJS = \
     ../AK/String.o \
     ../AK/String.o \

+ 23 - 2
Kernel/WindowComposer.cpp

@@ -1,12 +1,33 @@
 #include "WindowComposer.h"
 #include "WindowComposer.h"
 #include "Process.h"
 #include "Process.h"
+#include <Widgets/Font.h>
+#include <Widgets/FrameBuffer.h>
+#include <Widgets/WindowManager.h>
+#include <Widgets/RootWidget.h>
+#include <Widgets/EventLoop.h>
+#include <Widgets/MsgBox.h>
 
 
 void WindowComposer_main()
 void WindowComposer_main()
 {
 {
+    Font::initialize();
+    FrameBuffer::initialize();
+    EventLoop::initialize();
+    WindowManager::initialize();
+
     auto info = current->get_display_info();
     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);
+    RootWidget rw;
+    EventLoop loop;
+
+    WindowManager::the().setRootWidget(&rw);
+
+    MsgBox(nullptr, "Serenity Operating System");
+
     dbgprintf("Entering WindowComposer main loop.\n");
     dbgprintf("Entering WindowComposer main loop.\n");
-    for (;;) {
+    loop.exec();
 
 
-    }
+    ASSERT_NOT_REACHED();
 }
 }

+ 1 - 2
Widgets/Button.cpp

@@ -1,6 +1,5 @@
 #include "Button.h"
 #include "Button.h"
 #include "Painter.h"
 #include "Painter.h"
-#include <cstdio>
 
 
 Button::Button(Widget* parent)
 Button::Button(Widget* parent)
     : Widget(parent)
     : Widget(parent)
@@ -15,7 +14,7 @@ void Button::setCaption(String&& caption)
 {
 {
     if (caption == m_caption)
     if (caption == m_caption)
         return;
         return;
-    m_caption = std::move(caption);
+    m_caption = move(caption);
     update();
     update();
 }
 }
 
 

+ 2 - 2
Widgets/Color.cpp

@@ -6,7 +6,7 @@ Color::Color(byte r, byte g, byte b)
 #ifdef USE_SDL
 #ifdef USE_SDL
     m_value = SDL_MapRGB(FrameBuffer::the().surface()->format, r, g, b);
     m_value = SDL_MapRGB(FrameBuffer::the().surface()->format, r, g, b);
 #else
 #else
-#error FIXME: Implement
+    m_value = (r << 16) | (g << 8) | b;
 #endif
 #endif
 }
 }
 
 
@@ -33,6 +33,6 @@ Color::Color(NamedColor named)
 #ifdef USE_SDL
 #ifdef USE_SDL
     m_value = SDL_MapRGB(FrameBuffer::the().surface()->format, rgb.r, rgb.g, rgb.g);
     m_value = SDL_MapRGB(FrameBuffer::the().surface()->format, rgb.r, rgb.g, rgb.g);
 #else
 #else
-#error FIXME: Implement
+    m_value = (rgb.r << 16) | (rgb.g << 8) | rgb.b;
 #endif
 #endif
 }
 }

+ 15 - 3
Widgets/EventLoop.cpp

@@ -5,6 +5,11 @@
 
 
 static EventLoop* s_mainEventLoop;
 static EventLoop* s_mainEventLoop;
 
 
+void EventLoop::initialize()
+{
+    s_mainEventLoop = nullptr;
+}
+
 EventLoop::EventLoop()
 EventLoop::EventLoop()
 {
 {
     if (!s_mainEventLoop)
     if (!s_mainEventLoop)
@@ -26,7 +31,7 @@ int EventLoop::exec()
     for (;;) {
     for (;;) {
         if (m_queuedEvents.is_empty())
         if (m_queuedEvents.is_empty())
             waitForEvent();
             waitForEvent();
-        auto events = std::move(m_queuedEvents);
+        auto events = move(m_queuedEvents);
         for (auto& queuedEvent : events) {
         for (auto& queuedEvent : events) {
             auto* receiver = queuedEvent.receiver;
             auto* receiver = queuedEvent.receiver;
             auto& event = *queuedEvent.event;
             auto& event = *queuedEvent.event;
@@ -48,8 +53,15 @@ int EventLoop::exec()
 
 
 void EventLoop::postEvent(Object* receiver, OwnPtr<Event>&& event)
 void EventLoop::postEvent(Object* receiver, OwnPtr<Event>&& event)
 {
 {
-    m_queuedEvents.append({ receiver, std::move(event) });
+    printf("EventLoop::postEvent: {%u} << receiver=%p, event=%p\n", m_queuedEvents.size(), receiver, event.ptr());
+    m_queuedEvents.append({ receiver, move(event) });
+}
+
+#ifdef SERENITY
+void EventLoop::waitForEvent()
+{
 }
 }
+#endif
 
 
 #ifdef USE_SDL
 #ifdef USE_SDL
 static inline MouseButton toMouseButton(byte sdlButton)
 static inline MouseButton toMouseButton(byte sdlButton)
@@ -119,7 +131,7 @@ void EventLoop::handleKeyEvent(Event::Type type, const SDL_KeyboardEvent& sdlKey
     keyEvent->m_ctrl = sdlKey.keysym.mod & KMOD_CTRL;
     keyEvent->m_ctrl = sdlKey.keysym.mod & KMOD_CTRL;
     keyEvent->m_alt = sdlKey.keysym.mod & KMOD_ALT;
     keyEvent->m_alt = sdlKey.keysym.mod & KMOD_ALT;
 
 
-    postEvent(&WindowManager::the(), std::move(keyEvent));
+    postEvent(&WindowManager::the(), move(keyEvent));
 }
 }
 
 
 void EventLoop::waitForEvent()
 void EventLoop::waitForEvent()

+ 2 - 0
Widgets/EventLoop.h

@@ -21,6 +21,8 @@ public:
 
 
     static EventLoop& main();
     static EventLoop& main();
 
 
+    static void initialize();
+
 private:
 private:
     void waitForEvent();
     void waitForEvent();
 
 

+ 10 - 3
Widgets/Font.cpp

@@ -1,12 +1,19 @@
 #include "Font.h"
 #include "Font.h"
 #include "Peanut8x10.h"
 #include "Peanut8x10.h"
 #include <AK/RetainPtr.h>
 #include <AK/RetainPtr.h>
-#include <cstdio>
+
+static Font* s_default_font;
+
+void Font::initialize()
+{
+    s_default_font = nullptr;
+}
 
 
 Font& Font::defaultFont()
 Font& Font::defaultFont()
 {
 {
-    static auto* f = adopt(*new Font(Peanut8x10::glyphs, Peanut8x10::glyphWidth, Peanut8x10::glyphHeight, Peanut8x10::firstGlyph, Peanut8x10::lastGlyph)).leakRef();
-    return *f;
+    if (!s_default_font)
+        s_default_font = adopt(*new Font(Peanut8x10::glyphs, Peanut8x10::glyphWidth, Peanut8x10::glyphHeight, Peanut8x10::firstGlyph, Peanut8x10::lastGlyph)).leakRef();
+    return *s_default_font;
 }
 }
 
 
 Font::Font(const char* const* glyphs, byte glyphWidth, byte glyphHeight, byte firstGlyph, byte lastGlyph)
 Font::Font(const char* const* glyphs, byte glyphWidth, byte glyphHeight, byte firstGlyph, byte lastGlyph)

+ 2 - 0
Widgets/Font.h

@@ -16,6 +16,8 @@ public:
     byte glyphWidth() const { return m_glyphWidth; }
     byte glyphWidth() const { return m_glyphWidth; }
     byte glyphHeight() const { return m_glyphHeight; }
     byte glyphHeight() const { return m_glyphHeight; }
 
 
+    static void initialize();
+
 private:
 private:
     Font(const char* const* glyphs, byte glyphWidth, byte glyphHeight, byte firstGlyph, byte lastGlyph);
     Font(const char* const* glyphs, byte glyphWidth, byte glyphHeight, byte firstGlyph, byte lastGlyph);
 
 

+ 21 - 1
Widgets/FrameBuffer.cpp

@@ -2,7 +2,12 @@
 #include "GraphicsBitmap.h"
 #include "GraphicsBitmap.h"
 #include <AK/Assertions.h>
 #include <AK/Assertions.h>
 
 
-FrameBuffer* s_the = nullptr;
+FrameBuffer* s_the;
+
+void FrameBuffer::initialize()
+{
+    s_the = nullptr;
+}
 
 
 FrameBuffer& FrameBuffer::the()
 FrameBuffer& FrameBuffer::the()
 {
 {
@@ -20,6 +25,17 @@ FrameBuffer::FrameBuffer(unsigned width, unsigned height)
 #endif
 #endif
 }
 }
 
 
+FrameBuffer::FrameBuffer(RGBA32* data, unsigned width, unsigned height)
+    : AbstractScreen(width, height)
+#ifdef SERENITY
+    , m_data(data)
+#endif
+{
+    ASSERT(!s_the);
+    s_the = this;
+}
+
+
 FrameBuffer::~FrameBuffer()
 FrameBuffer::~FrameBuffer()
 {
 {
 #ifdef USE_SDL
 #ifdef USE_SDL
@@ -68,6 +84,10 @@ RGBA32* FrameBuffer::scanline(int y)
 #ifdef USE_SDL
 #ifdef USE_SDL
     return reinterpret_cast<RGBA32*>(((byte*)m_surface->pixels) + (y * m_surface->pitch));
     return reinterpret_cast<RGBA32*>(((byte*)m_surface->pixels) + (y * m_surface->pitch));
 #endif
 #endif
+#ifdef SERENITY
+    unsigned pitch = sizeof(RGBA32) * width();
+    return reinterpret_cast<RGBA32*>(((byte*)m_data) + (y * pitch));
+#endif
 }
 }
 
 
 void FrameBuffer::blit(const Point& position, GraphicsBitmap& bitmap)
 void FrameBuffer::blit(const Point& position, GraphicsBitmap& bitmap)

+ 6 - 0
Widgets/FrameBuffer.h

@@ -12,6 +12,7 @@ class GraphicsBitmap;
 class FrameBuffer final : public AbstractScreen {
 class FrameBuffer final : public AbstractScreen {
 public:
 public:
     FrameBuffer(unsigned width, unsigned height);
     FrameBuffer(unsigned width, unsigned height);
+    FrameBuffer(RGBA32*, unsigned width, unsigned height);
     virtual ~FrameBuffer() override;
     virtual ~FrameBuffer() override;
 
 
     void show();
     void show();
@@ -27,11 +28,16 @@ public:
     void blit(const Point&, GraphicsBitmap&);
     void blit(const Point&, GraphicsBitmap&);
     void flush();
     void flush();
 
 
+    static void initialize();
+
 private:
 private:
 #ifdef USE_SDL
 #ifdef USE_SDL
     void initializeSDL();
     void initializeSDL();
     SDL_Window* m_window { nullptr };
     SDL_Window* m_window { nullptr };
     SDL_Surface* m_surface { nullptr };
     SDL_Surface* m_surface { nullptr };
 #endif
 #endif
+#ifdef SERENITY
+    RGBA32* m_data { nullptr };
+#endif
 };
 };
 
 

+ 1 - 2
Widgets/Label.cpp

@@ -1,6 +1,5 @@
 #include "Label.h"
 #include "Label.h"
 #include "Painter.h"
 #include "Painter.h"
-#include <cstdio>
 
 
 Label::Label(Widget* parent)
 Label::Label(Widget* parent)
     : Widget(parent)
     : Widget(parent)
@@ -15,7 +14,7 @@ void Label::setText(String&& text)
 {
 {
     if (text == m_text)
     if (text == m_text)
         return;
         return;
-    m_text = std::move(text);
+    m_text = move(text);
     update();
     update();
 }
 }
 
 

+ 1 - 1
Widgets/MsgBox.cpp

@@ -47,7 +47,7 @@ void MsgBox(Window* owner, String&& text)
         textWidth,
         textWidth,
         textHeight
         textHeight
     });
     });
-    label->setText(std::move(text));
+    label->setText(move(text));
     auto* button = new Button(widget);
     auto* button = new Button(widget);
     button->setCaption("OK");
     button->setCaption("OK");
     button->setWindowRelativeRect(buttonRect);
     button->setWindowRelativeRect(buttonRect);

+ 3 - 1
Widgets/Object.cpp

@@ -18,7 +18,7 @@ Object::~Object()
 {
 {
     if (m_parent)
     if (m_parent)
         m_parent->removeChild(*this);
         m_parent->removeChild(*this);
-    auto childrenToDelete = std::move(m_children);
+    auto childrenToDelete = move(m_children);
     for (auto* child : childrenToDelete)
     for (auto* child : childrenToDelete)
         delete child;
         delete child;
 }
 }
@@ -81,7 +81,9 @@ void Object::stopTimer()
 {
 {
     if (!m_timerID)
     if (!m_timerID)
         return;
         return;
+#ifdef USE_SDL
     SDL_RemoveTimer(m_timerID);
     SDL_RemoveTimer(m_timerID);
+#endif
     m_timerID = 0;
     m_timerID = 0;
 }
 }
 
 

+ 0 - 1
Widgets/RootWidget.cpp

@@ -4,7 +4,6 @@
 #include "Painter.h"
 #include "Painter.h"
 #include "WindowManager.h"
 #include "WindowManager.h"
 #include "FrameBuffer.h"
 #include "FrameBuffer.h"
-#include <cstdio>
 
 
 RootWidget::RootWidget()
 RootWidget::RootWidget()
 {
 {

+ 1 - 1
Widgets/Widget.cpp

@@ -159,7 +159,7 @@ void Widget::setFont(RetainPtr<Font>&& font)
     if (!font)
     if (!font)
         m_font = Font::defaultFont();
         m_font = Font::defaultFont();
     else
     else
-        m_font = std::move(font);
+        m_font = move(font);
 }
 }
 
 
 GraphicsBitmap* Widget::backing()
 GraphicsBitmap* Widget::backing()

+ 10 - 2
Widgets/WindowManager.cpp

@@ -47,10 +47,18 @@ static inline Rect outerRectForWindow(const Window& window)
     return rect;
     return rect;
 }
 }
 
 
+static WindowManager* s_the_window_manager;
+
 WindowManager& WindowManager::the()
 WindowManager& WindowManager::the()
 {
 {
-    static WindowManager* s_the = new WindowManager;
-    return *s_the;
+    if (!s_the_window_manager)
+        s_the_window_manager = new WindowManager;
+    return *s_the_window_manager;
+}
+
+void WindowManager::initialize()
+{
+    s_the_window_manager = nullptr;
 }
 }
 
 
 WindowManager::WindowManager()
 WindowManager::WindowManager()

+ 2 - 0
Widgets/WindowManager.h

@@ -34,6 +34,8 @@ public:
     void repaint();
     void repaint();
     void move_to_front(Window&);
     void move_to_front(Window&);
 
 
+    static void initialize();
+
 private:
 private:
     WindowManager();
     WindowManager();
     ~WindowManager();
     ~WindowManager();