2019-01-08 20:06:04 -05:00
|
|
|
#include "GraphicsBitmap.h"
|
2019-01-12 19:59:38 -05:00
|
|
|
#include "EventLoop.h"
|
2019-01-08 20:06:04 -05:00
|
|
|
#include <AK/kmalloc.h>
|
2019-01-12 18:27:25 -05:00
|
|
|
#include "Process.h"
|
|
|
|
#include "MemoryManager.h"
|
|
|
|
|
2019-01-14 09:25:34 -05:00
|
|
|
RetainPtr<GraphicsBitmap> GraphicsBitmap::create(Process& process, const Size& size)
|
2019-01-08 20:06:04 -05:00
|
|
|
{
|
2019-01-14 09:25:34 -05:00
|
|
|
return adopt(*new GraphicsBitmap(process, size));
|
2019-01-08 20:06:04 -05:00
|
|
|
}
|
|
|
|
|
2019-01-09 23:36:32 -05:00
|
|
|
RetainPtr<GraphicsBitmap> GraphicsBitmap::create_wrapper(const Size& size, RGBA32* data)
|
2019-01-08 21:51:34 -05:00
|
|
|
{
|
|
|
|
return adopt(*new GraphicsBitmap(size, data));
|
|
|
|
}
|
|
|
|
|
2019-01-14 09:25:34 -05:00
|
|
|
GraphicsBitmap::GraphicsBitmap(Process& process, const Size& size)
|
2019-01-08 20:06:04 -05:00
|
|
|
: m_size(size)
|
2019-01-12 15:29:05 -05:00
|
|
|
, m_pitch(size.width() * sizeof(RGBA32))
|
2019-01-14 09:25:34 -05:00
|
|
|
, m_client_process(&process)
|
2019-01-08 20:06:04 -05:00
|
|
|
{
|
2019-01-14 09:25:34 -05:00
|
|
|
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 (shared)", true, true);
|
|
|
|
m_client_region->commit(process);
|
|
|
|
|
|
|
|
{
|
|
|
|
auto& server = EventLoop::main().server_process();
|
|
|
|
ProcessInspectionHandle composer_handle(server);
|
|
|
|
m_server_region = server.allocate_region_with_vmo(LinearAddress(), size_in_bytes, move(vmo), 0, "GraphicsBitmap (shared)", true, true);
|
|
|
|
|
|
|
|
process.dumpRegions();
|
|
|
|
server.dumpRegions();
|
|
|
|
}
|
|
|
|
m_data = (RGBA32*)m_server_region->linearAddress.asPtr();
|
2019-01-08 21:51:34 -05:00
|
|
|
}
|
|
|
|
|
2019-01-09 23:36:32 -05:00
|
|
|
GraphicsBitmap::GraphicsBitmap(const Size& size, RGBA32* data)
|
2019-01-08 21:51:34 -05:00
|
|
|
: m_size(size)
|
2019-01-09 23:36:32 -05:00
|
|
|
, m_data(data)
|
2019-01-12 15:29:05 -05:00
|
|
|
, m_pitch(size.width() * sizeof(RGBA32))
|
2019-01-08 21:51:34 -05:00
|
|
|
{
|
2019-01-08 20:06:04 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
GraphicsBitmap::~GraphicsBitmap()
|
|
|
|
{
|
2019-01-14 09:25:34 -05:00
|
|
|
if (m_client_region)
|
|
|
|
m_client_process->deallocate_region(*m_client_region);
|
|
|
|
if (m_server_region)
|
|
|
|
EventLoop::main().server_process().deallocate_region(*m_server_region);
|
2019-01-08 21:51:34 -05:00
|
|
|
m_data = nullptr;
|
2019-01-08 20:06:04 -05:00
|
|
|
}
|
|
|
|
|
2019-01-09 23:36:32 -05:00
|
|
|
RGBA32* GraphicsBitmap::scanline(int y)
|
2019-01-08 20:06:04 -05:00
|
|
|
{
|
2019-01-12 15:29:05 -05:00
|
|
|
return reinterpret_cast<RGBA32*>((((byte*)m_data) + (y * m_pitch)));
|
2019-01-08 20:06:04 -05:00
|
|
|
}
|
|
|
|
|
2019-01-12 00:39:34 -05:00
|
|
|
const RGBA32* GraphicsBitmap::scanline(int y) const
|
|
|
|
{
|
2019-01-12 15:29:05 -05:00
|
|
|
return reinterpret_cast<const RGBA32*>((((const byte*)m_data) + (y * m_pitch)));
|
2019-01-12 00:39:34 -05:00
|
|
|
}
|