2019-01-09 04:06:04 +03:00
|
|
|
#include "GraphicsBitmap.h"
|
|
|
|
#include <AK/kmalloc.h>
|
2019-01-14 22:00:42 +03:00
|
|
|
|
|
|
|
#ifdef KERNEL
|
2019-01-16 18:03:50 +03:00
|
|
|
#include <Kernel/Process.h>
|
|
|
|
#include <Kernel/MemoryManager.h>
|
|
|
|
#include <WindowServer/WSEventLoop.h>
|
2019-01-14 22:00:42 +03:00
|
|
|
#endif
|
2019-01-13 02:27:25 +03:00
|
|
|
|
2019-01-14 22:00:42 +03:00
|
|
|
#ifdef KERNEL
|
2019-01-14 17:25:34 +03:00
|
|
|
RetainPtr<GraphicsBitmap> GraphicsBitmap::create(Process& process, const Size& size)
|
2019-01-09 04:06:04 +03:00
|
|
|
{
|
2019-01-14 17:25:34 +03:00
|
|
|
return adopt(*new GraphicsBitmap(process, size));
|
2019-01-09 04:06:04 +03:00
|
|
|
}
|
|
|
|
|
2019-01-14 17:25:34 +03:00
|
|
|
GraphicsBitmap::GraphicsBitmap(Process& process, const Size& size)
|
2019-01-09 04:06:04 +03:00
|
|
|
: m_size(size)
|
2019-01-12 23:29:05 +03:00
|
|
|
, m_pitch(size.width() * sizeof(RGBA32))
|
2019-01-14 17:25:34 +03:00
|
|
|
, m_client_process(&process)
|
2019-01-09 04:06:04 +03:00
|
|
|
{
|
2019-01-26 07:20:32 +03:00
|
|
|
InterruptDisabler disabler;
|
2019-01-14 17:25:34 +03:00
|
|
|
size_t size_in_bytes = size.width() * size.height() * sizeof(RGBA32);
|
|
|
|
auto vmo = VMObject::create_anonymous(size_in_bytes);
|
2019-01-17 04:58:34 +03:00
|
|
|
m_client_region = process.allocate_region_with_vmo(LinearAddress(), size_in_bytes, vmo.copyRef(), 0, "GraphicsBitmap (client)", true, true);
|
2019-01-21 07:18:28 +03:00
|
|
|
m_client_region->set_shared(true);
|
2019-01-22 07:01:00 +03:00
|
|
|
m_client_region->commit();
|
2019-01-26 07:20:32 +03:00
|
|
|
auto& server = WSEventLoop::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);
|
2019-01-14 17:25:34 +03:00
|
|
|
|
2019-01-24 20:09:46 +03:00
|
|
|
m_data = (RGBA32*)m_server_region->laddr().as_ptr();
|
2019-01-09 05:51:34 +03:00
|
|
|
}
|
2019-01-14 22:00:42 +03:00
|
|
|
#endif
|
|
|
|
|
|
|
|
RetainPtr<GraphicsBitmap> GraphicsBitmap::create_wrapper(const Size& size, RGBA32* data)
|
|
|
|
{
|
|
|
|
return adopt(*new GraphicsBitmap(size, data));
|
|
|
|
}
|
2019-01-09 05:51:34 +03:00
|
|
|
|
2019-01-10 07:36:32 +03:00
|
|
|
GraphicsBitmap::GraphicsBitmap(const Size& size, RGBA32* data)
|
2019-01-09 05:51:34 +03:00
|
|
|
: m_size(size)
|
2019-01-10 07:36:32 +03:00
|
|
|
, m_data(data)
|
2019-01-12 23:29:05 +03:00
|
|
|
, m_pitch(size.width() * sizeof(RGBA32))
|
2019-01-09 05:51:34 +03:00
|
|
|
{
|
2019-01-09 04:06:04 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
GraphicsBitmap::~GraphicsBitmap()
|
|
|
|
{
|
2019-01-14 22:00:42 +03:00
|
|
|
#ifdef KERNEL
|
2019-01-14 17:25:34 +03:00
|
|
|
if (m_client_region)
|
|
|
|
m_client_process->deallocate_region(*m_client_region);
|
|
|
|
if (m_server_region)
|
2019-01-16 18:03:50 +03:00
|
|
|
WSEventLoop::the().server_process().deallocate_region(*m_server_region);
|
2019-01-14 22:00:42 +03:00
|
|
|
#endif
|
2019-01-09 05:51:34 +03:00
|
|
|
m_data = nullptr;
|
2019-01-09 04:06:04 +03:00
|
|
|
}
|
|
|
|
|