mirror of
https://github.com/RGBCube/serenity
synced 2025-07-24 22:37:34 +00:00
SharedGraphics: GraphicsBitmap::load_from_file() should be allowed to fail.
It's okay if it fails to load a bitmap in kernel space. Just return nullptr.
This commit is contained in:
parent
d4ba155711
commit
cf58b76210
1 changed files with 6 additions and 5 deletions
|
@ -48,6 +48,7 @@ RetainPtr<GraphicsBitmap> GraphicsBitmap::create_wrapper(const Size& size, RGBA3
|
||||||
|
|
||||||
RetainPtr<GraphicsBitmap> GraphicsBitmap::load_from_file(const String& path, const Size& size)
|
RetainPtr<GraphicsBitmap> GraphicsBitmap::load_from_file(const String& path, const Size& size)
|
||||||
{
|
{
|
||||||
|
RGBA32* mapped_data = nullptr;
|
||||||
#ifdef USERLAND
|
#ifdef USERLAND
|
||||||
int fd = open(path.characters(), O_RDONLY, 0644);
|
int fd = open(path.characters(), O_RDONLY, 0644);
|
||||||
if (fd < 0) {
|
if (fd < 0) {
|
||||||
|
@ -56,8 +57,8 @@ RetainPtr<GraphicsBitmap> GraphicsBitmap::load_from_file(const String& path, con
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto* mapped_file = (RGBA32*)mmap(nullptr, size.area() * 4, PROT_READ, MAP_SHARED, fd, 0);
|
mapped_data = (RGBA32*)mmap(nullptr, size.area() * 4, PROT_READ, MAP_SHARED, fd, 0);
|
||||||
if (mapped_file == MAP_FAILED) {
|
if (mapped_data == MAP_FAILED) {
|
||||||
int rc = close(fd);
|
int rc = close(fd);
|
||||||
ASSERT(rc == 0);
|
ASSERT(rc == 0);
|
||||||
return nullptr;
|
return nullptr;
|
||||||
|
@ -67,10 +68,10 @@ RetainPtr<GraphicsBitmap> GraphicsBitmap::load_from_file(const String& path, con
|
||||||
auto descriptor = VFS::the().open(path, error, 0, 0, *VFS::the().root_inode());
|
auto descriptor = VFS::the().open(path, error, 0, 0, *VFS::the().root_inode());
|
||||||
if (!descriptor) {
|
if (!descriptor) {
|
||||||
kprintf("Failed to load GraphicsBitmap from file (%s)\n", path.characters());
|
kprintf("Failed to load GraphicsBitmap from file (%s)\n", path.characters());
|
||||||
ASSERT_NOT_REACHED();
|
return nullptr;
|
||||||
}
|
}
|
||||||
auto* region = WSMessageLoop::the().server_process().allocate_file_backed_region(LinearAddress(), size.area() * 4, descriptor->inode(), ".rgb file", /*readable*/true, /*writable*/false);
|
auto* region = WSMessageLoop::the().server_process().allocate_file_backed_region(LinearAddress(), size.area() * 4, descriptor->inode(), ".rgb file", /*readable*/true, /*writable*/false);
|
||||||
auto* mapped_file = (RGBA32*)region->laddr().get();
|
mapped_data = (RGBA32*)region->laddr().get();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
@ -78,7 +79,7 @@ RetainPtr<GraphicsBitmap> GraphicsBitmap::load_from_file(const String& path, con
|
||||||
int rc = close(fd);
|
int rc = close(fd);
|
||||||
ASSERT(rc == 0);
|
ASSERT(rc == 0);
|
||||||
#endif
|
#endif
|
||||||
auto bitmap = create_wrapper(size, mapped_file);
|
auto bitmap = create_wrapper(size, mapped_data);
|
||||||
#ifdef KERNEL
|
#ifdef KERNEL
|
||||||
bitmap->m_server_region = region;
|
bitmap->m_server_region = region;
|
||||||
#else
|
#else
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue