1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-26 23:17:46 +00:00

Kernel: Add a simple shared memory API for two processes only.

And use this to implement shared bitmaps between WindowServer and clients.
This commit is contained in:
Andreas Kling 2019-02-16 12:13:43 +01:00
parent 4db78dabd3
commit 4ea28bf0a5
13 changed files with 240 additions and 48 deletions

View file

@ -118,7 +118,7 @@ struct WSAPI_ServerMessage {
WSAPI_Size size;
size_t bpp;
size_t pitch;
RGBA32* pixels;
int shared_buffer_id;
} backing;
};
};

View file

@ -42,13 +42,12 @@ WSClientConnection* WSClientConnection::ensure_for_client_id(int client_id)
WSClientConnection::WSClientConnection(int fd)
: m_fd(fd)
{
pid_t pid;
int rc = WSMessageLoop::the().server_process().sys$ioctl(m_fd, 413, (int)&pid);
int rc = WSMessageLoop::the().server_process().sys$ioctl(m_fd, 413, (int)&m_pid);
ASSERT(rc == 0);
{
InterruptDisabler disabler;
auto* process = Process::from_pid(pid);
auto* process = Process::from_pid(m_pid);
ASSERT(process);
m_process = process->make_weak_ptr();
m_client_id = (int)process;
@ -85,9 +84,12 @@ void WSClientConnection::post_message(const WSAPI_ServerMessage& message)
RetainPtr<GraphicsBitmap> WSClientConnection::create_bitmap(const Size& size)
{
if (!m_process)
return nullptr;
return GraphicsBitmap::create(*m_process, size);
RGBA32* buffer;
int shared_buffer_id = current->sys$create_shared_buffer(m_pid, size.area() * sizeof(RGBA32), (void**)&buffer);
ASSERT(shared_buffer_id >= 0);
ASSERT(buffer);
ASSERT(buffer != (void*)-1);
return GraphicsBitmap::create_with_shared_buffer(shared_buffer_id, size, buffer);
}
void WSClientConnection::on_message(WSMessage& message)
@ -369,7 +371,7 @@ void WSClientConnection::handle_request(WSAPIGetWindowBackingStoreRequest& reque
response.backing.bpp = sizeof(RGBA32);
response.backing.pitch = backing_store->pitch();
response.backing.size = backing_store->size();
response.backing.pixels = reinterpret_cast<RGBA32*>(backing_store->client_region()->laddr().as_ptr());
response.backing.shared_buffer_id = backing_store->shared_buffer_id();
WSMessageLoop::the().post_message_to_client(request.client_id(), response);
}

View file

@ -32,6 +32,7 @@ public:
WSMenuBar* app_menubar() { return m_app_menubar.ptr(); }
int fd() const { return m_fd; }
pid_t pid() const { return m_pid; }
private:
virtual void on_message(WSMessage&) override;
@ -61,6 +62,7 @@ private:
int m_client_id { 0 };
int m_fd { -1 };
pid_t m_pid { 0 };
HashMap<int, OwnPtr<WSWindow>> m_windows;
HashMap<int, OwnPtr<WSMenuBar>> m_menubars;