mirror of
https://github.com/RGBCube/serenity
synced 2025-07-08 15:07:35 +00:00
Make a SharedGraphics directory for classes shared between Kernel and LibGUI.
This commit is contained in:
parent
b75ee4aacb
commit
7e5b81fe48
31 changed files with 49 additions and 41 deletions
57
SharedGraphics/GraphicsBitmap.cpp
Normal file
57
SharedGraphics/GraphicsBitmap.cpp
Normal file
|
@ -0,0 +1,57 @@
|
|||
#include "GraphicsBitmap.h"
|
||||
#include <AK/kmalloc.h>
|
||||
|
||||
#ifdef KERNEL
|
||||
#include <Kernel/Process.h>
|
||||
#include <Kernel/MemoryManager.h>
|
||||
#include <WindowServer/WSEventLoop.h>
|
||||
#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)
|
||||
{
|
||||
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.copyRef(), 0, "GraphicsBitmap (client)", true, true);
|
||||
m_client_region->commit(process);
|
||||
|
||||
{
|
||||
auto& server = WSEventLoop::the().server_process();
|
||||
InterruptDisabler disabler;
|
||||
m_server_region = server.allocate_region_with_vmo(LinearAddress(), size_in_bytes, move(vmo), 0, "GraphicsBitmap (server)", true, true);
|
||||
}
|
||||
m_data = (RGBA32*)m_server_region->linearAddress.asPtr();
|
||||
}
|
||||
#endif
|
||||
|
||||
RetainPtr<GraphicsBitmap> GraphicsBitmap::create_wrapper(const Size& size, RGBA32* data)
|
||||
{
|
||||
return adopt(*new GraphicsBitmap(size, data));
|
||||
}
|
||||
|
||||
GraphicsBitmap::GraphicsBitmap(const Size& size, RGBA32* data)
|
||||
: m_size(size)
|
||||
, m_data(data)
|
||||
, m_pitch(size.width() * sizeof(RGBA32))
|
||||
{
|
||||
}
|
||||
|
||||
GraphicsBitmap::~GraphicsBitmap()
|
||||
{
|
||||
#ifdef KERNEL
|
||||
if (m_client_region)
|
||||
m_client_process->deallocate_region(*m_client_region);
|
||||
if (m_server_region)
|
||||
WSEventLoop::the().server_process().deallocate_region(*m_server_region);
|
||||
#endif
|
||||
m_data = nullptr;
|
||||
}
|
||||
|
Loading…
Add table
Add a link
Reference in a new issue