mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 06:07:34 +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:
parent
4db78dabd3
commit
4ea28bf0a5
13 changed files with 240 additions and 48 deletions
|
@ -15,31 +15,6 @@
|
|||
#endif
|
||||
|
||||
#ifdef KERNEL
|
||||
RetainPtr<GraphicsBitmap> GraphicsBitmap::create(Process& process, const Size& size)
|
||||
{
|
||||
return adopt(*new GraphicsBitmap(process, size));
|
||||
}
|
||||
|
||||
GraphicsBitmap::GraphicsBitmap(Process& process, const Size& size)
|
||||
: m_size(size)
|
||||
, m_pitch(size.width() * sizeof(RGBA32))
|
||||
, m_client_process(process.make_weak_ptr())
|
||||
{
|
||||
InterruptDisabler disabler;
|
||||
size_t size_in_bytes = size.width() * size.height() * sizeof(RGBA32);
|
||||
auto vmo = VMObject::create_anonymous(size_in_bytes);
|
||||
m_client_region = process.allocate_region_with_vmo(LinearAddress(), size_in_bytes, vmo.copy_ref(), 0, "GraphicsBitmap (client)", true, true);
|
||||
m_client_region->set_shared(true);
|
||||
m_client_region->set_is_bitmap(true);
|
||||
m_client_region->commit();
|
||||
auto& server = WSMessageLoop::the().server_process();
|
||||
m_server_region = server.allocate_region_with_vmo(LinearAddress(), size_in_bytes, move(vmo), 0, "GraphicsBitmap (server)", true, false);
|
||||
m_server_region->set_shared(true);
|
||||
m_server_region->set_is_bitmap(true);
|
||||
|
||||
m_data = (RGBA32*)m_server_region->laddr().as_ptr();
|
||||
}
|
||||
|
||||
RetainPtr<GraphicsBitmap> GraphicsBitmap::create_kernel_only(const Size& size)
|
||||
{
|
||||
return adopt(*new GraphicsBitmap(size));
|
||||
|
@ -115,11 +90,32 @@ GraphicsBitmap::GraphicsBitmap(const Size& size, RGBA32* data)
|
|||
{
|
||||
}
|
||||
|
||||
RetainPtr<GraphicsBitmap> GraphicsBitmap::create_with_shared_buffer(int shared_buffer_id, const Size& size, RGBA32* data)
|
||||
{
|
||||
if (!data) {
|
||||
#ifdef KERNEL
|
||||
void* shared_buffer = current->sys$get_shared_buffer(shared_buffer_id);
|
||||
#else
|
||||
void* shared_buffer = get_shared_buffer(shared_buffer_id);
|
||||
#endif
|
||||
if (!shared_buffer || shared_buffer == (void*)-1)
|
||||
return nullptr;
|
||||
data = (RGBA32*)shared_buffer;
|
||||
}
|
||||
return adopt(*new GraphicsBitmap(shared_buffer_id, size, data));
|
||||
}
|
||||
|
||||
GraphicsBitmap::GraphicsBitmap(int shared_buffer_id, const Size& size, RGBA32* data)
|
||||
: m_size(size)
|
||||
, m_data(data)
|
||||
, m_pitch(size.width() * sizeof(RGBA32))
|
||||
, m_shared_buffer_id(shared_buffer_id)
|
||||
{
|
||||
}
|
||||
|
||||
GraphicsBitmap::~GraphicsBitmap()
|
||||
{
|
||||
#ifdef KERNEL
|
||||
if (m_client_region && m_client_process)
|
||||
m_client_process->deallocate_region(*m_client_region);
|
||||
if (m_server_region)
|
||||
WSMessageLoop::the().server_process().deallocate_region(*m_server_region);
|
||||
#else
|
||||
|
@ -128,6 +124,15 @@ GraphicsBitmap::~GraphicsBitmap()
|
|||
ASSERT(rc == 0);
|
||||
}
|
||||
#endif
|
||||
if (m_shared_buffer_id != -1) {
|
||||
int rc;
|
||||
#ifdef KERNEL
|
||||
rc = current->sys$release_shared_buffer(m_shared_buffer_id);
|
||||
#else
|
||||
rc = release_shared_buffer(m_shared_buffer_id);
|
||||
#endif
|
||||
ASSERT(rc == 0);
|
||||
}
|
||||
m_data = nullptr;
|
||||
}
|
||||
|
||||
|
|
|
@ -7,18 +7,16 @@
|
|||
#include <AK/RetainPtr.h>
|
||||
#include <AK/AKString.h>
|
||||
|
||||
#ifdef KERNEL
|
||||
#include "Process.h"
|
||||
#endif
|
||||
class Region;
|
||||
|
||||
class GraphicsBitmap : public Retainable<GraphicsBitmap> {
|
||||
public:
|
||||
#ifdef KERNEL
|
||||
static RetainPtr<GraphicsBitmap> create(Process&, const Size&);
|
||||
static RetainPtr<GraphicsBitmap> create_kernel_only(const Size&);
|
||||
#endif
|
||||
static RetainPtr<GraphicsBitmap> create_wrapper(const Size&, RGBA32*);
|
||||
static RetainPtr<GraphicsBitmap> load_from_file(const String& path, const Size&);
|
||||
static RetainPtr<GraphicsBitmap> create_with_shared_buffer(int shared_buffer_id, const Size&, RGBA32* buffer = nullptr);
|
||||
~GraphicsBitmap();
|
||||
|
||||
RGBA32* scanline(int y);
|
||||
|
@ -31,16 +29,17 @@ public:
|
|||
size_t pitch() const { return m_pitch; }
|
||||
|
||||
#ifdef KERNEL
|
||||
Region* client_region() { return m_client_region; }
|
||||
Region* server_region() { return m_server_region; }
|
||||
#endif
|
||||
|
||||
int shared_buffer_id() const { return m_shared_buffer_id; }
|
||||
|
||||
private:
|
||||
#ifdef KERNEL
|
||||
GraphicsBitmap(Process&, const Size&);
|
||||
GraphicsBitmap(const Size&);
|
||||
#endif
|
||||
GraphicsBitmap(const Size&, RGBA32*);
|
||||
GraphicsBitmap(int shared_buffer_id, const Size&, RGBA32*);
|
||||
|
||||
Size m_size;
|
||||
RGBA32* m_data { nullptr };
|
||||
|
@ -50,9 +49,9 @@ private:
|
|||
bool m_mmaped { false };
|
||||
#endif
|
||||
|
||||
int m_shared_buffer_id { -1 };
|
||||
|
||||
#ifdef KERNEL
|
||||
WeakPtr<Process> m_client_process;
|
||||
Region* m_client_region { nullptr };
|
||||
Region* m_server_region { nullptr };
|
||||
#endif
|
||||
};
|
||||
|
|
|
@ -32,7 +32,7 @@ Painter::Painter(GWidget& widget)
|
|||
auto response = GEventLoop::main().sync_request(request, WSAPI_ServerMessage::DidGetWindowBackingStore);
|
||||
m_backing_store_id = response.backing.backing_store_id;
|
||||
|
||||
m_target = GraphicsBitmap::create_wrapper(response.backing.size, response.backing.pixels);
|
||||
m_target = GraphicsBitmap::create_with_shared_buffer(response.backing.shared_buffer_id, response.backing.size);
|
||||
ASSERT(m_target);
|
||||
m_window = widget.window();
|
||||
m_translation.move_by(widget.window_relative_rect().location());
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue