mirror of
https://github.com/RGBCube/serenity
synced 2025-05-28 07:45:07 +00:00
Start working on a simple Launcher app.
Let GButton have an optional icon (GraphicsBitmap) that gets rendered in the middle of the button if present. Also add GraphicsBitmap::load_from_file() which allows mmap'ed RGBA32 files. I wrote a little program to take "raw" files from GIMP and swizzle them into the correct byte order.
This commit is contained in:
parent
71b9ec1ae0
commit
887b4a7a1a
29 changed files with 293 additions and 11 deletions
|
@ -1,5 +1,4 @@
|
|||
#include "GraphicsBitmap.h"
|
||||
#include <AK/kmalloc.h>
|
||||
|
||||
#ifdef KERNEL
|
||||
#include <Kernel/Process.h>
|
||||
|
@ -7,6 +6,14 @@
|
|||
#include <WindowServer/WSMessageLoop.h>
|
||||
#endif
|
||||
|
||||
#ifdef USERLAND
|
||||
#include <sys/mman.h>
|
||||
#include <unistd.h>
|
||||
#include <fcntl.h>
|
||||
#include <errno.h>
|
||||
#include <stdio.h>
|
||||
#endif
|
||||
|
||||
#ifdef KERNEL
|
||||
RetainPtr<GraphicsBitmap> GraphicsBitmap::create(Process& process, const Size& size)
|
||||
{
|
||||
|
@ -39,6 +46,49 @@ RetainPtr<GraphicsBitmap> GraphicsBitmap::create_wrapper(const Size& size, RGBA3
|
|||
return adopt(*new GraphicsBitmap(size, data));
|
||||
}
|
||||
|
||||
RetainPtr<GraphicsBitmap> GraphicsBitmap::load_from_file(const String& path, const Size& size)
|
||||
{
|
||||
#ifdef USERLAND
|
||||
int fd = open(path.characters(), O_RDONLY, 0644);
|
||||
if (fd < 0) {
|
||||
dbgprintf("open(%s) got fd=%d, failed: %s\n", path.characters(), fd, strerror(errno));
|
||||
perror("open");
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
auto* mapped_file = (RGBA32*)mmap(nullptr, size.area() * 4, PROT_READ, MAP_SHARED, fd, 0);
|
||||
if (mapped_file == MAP_FAILED) {
|
||||
int rc = close(fd);
|
||||
ASSERT(rc == 0);
|
||||
return nullptr;
|
||||
}
|
||||
#else
|
||||
int error;
|
||||
auto descriptor = VFS::the().open(path, error, 0, 0, *VFS::the().root_inode());
|
||||
if (!descriptor) {
|
||||
kprintf("Failed to load GraphicsBitmap from file (%s)\n", path.characters());
|
||||
ASSERT_NOT_REACHED();
|
||||
}
|
||||
auto* region = current->allocate_file_backed_region(LinearAddress(), size.area() * 4, descriptor->inode(), ".rgb file", /*readable*/true, /*writable*/false);
|
||||
region->page_in();
|
||||
auto* mapped_file = (RGBA32*)region->laddr().get();
|
||||
#endif
|
||||
|
||||
|
||||
#ifdef USERLAND
|
||||
int rc = close(fd);
|
||||
ASSERT(rc == 0);
|
||||
#endif
|
||||
auto bitmap = create_wrapper(size, mapped_file);
|
||||
#ifdef KERNEL
|
||||
bitmap->m_server_region = region;
|
||||
#else
|
||||
bitmap->m_mmaped = true;
|
||||
#endif
|
||||
|
||||
return bitmap;
|
||||
}
|
||||
|
||||
GraphicsBitmap::GraphicsBitmap(const Size& size, RGBA32* data)
|
||||
: m_size(size)
|
||||
, m_data(data)
|
||||
|
@ -53,6 +103,11 @@ GraphicsBitmap::~GraphicsBitmap()
|
|||
m_client_process->deallocate_region(*m_client_region);
|
||||
if (m_server_region)
|
||||
WSMessageLoop::the().server_process().deallocate_region(*m_server_region);
|
||||
#else
|
||||
if (m_mmaped) {
|
||||
int rc = munmap(m_data, m_size.area() * 4);
|
||||
ASSERT(rc == 0);
|
||||
}
|
||||
#endif
|
||||
m_data = nullptr;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue