Compare commits
3 Commits
21392e34cb
...
547aeb0170
Author | SHA1 | Date |
---|---|---|
Bananymous | 547aeb0170 | |
Bananymous | ebe465e81e | |
Bananymous | c10dffd719 |
|
@ -9,9 +9,6 @@
|
||||||
namespace Kernel
|
namespace Kernel
|
||||||
{
|
{
|
||||||
|
|
||||||
// Internally we hold 32 bpp buffer (top 8 bits not used)
|
|
||||||
static constexpr uint32_t bytes_per_pixel_internal = 4;
|
|
||||||
|
|
||||||
static uint32_t get_framebuffer_device_index()
|
static uint32_t get_framebuffer_device_index()
|
||||||
{
|
{
|
||||||
static uint32_t index = 0;
|
static uint32_t index = 0;
|
||||||
|
@ -75,7 +72,7 @@ namespace Kernel
|
||||||
m_video_buffer = TRY(VirtualRange::create_to_vaddr_range(
|
m_video_buffer = TRY(VirtualRange::create_to_vaddr_range(
|
||||||
PageTable::kernel(),
|
PageTable::kernel(),
|
||||||
KERNEL_OFFSET, UINTPTR_MAX,
|
KERNEL_OFFSET, UINTPTR_MAX,
|
||||||
BAN::Math::div_round_up<size_t>(m_width * m_height * bytes_per_pixel_internal, PAGE_SIZE) * PAGE_SIZE,
|
BAN::Math::div_round_up<size_t>(m_width * m_height * (BANAN_FB_BPP / 8), PAGE_SIZE) * PAGE_SIZE,
|
||||||
PageTable::Flags::ReadWrite | PageTable::Flags::Present,
|
PageTable::Flags::ReadWrite | PageTable::Flags::Present,
|
||||||
true
|
true
|
||||||
));
|
));
|
||||||
|
@ -94,15 +91,14 @@ namespace Kernel
|
||||||
auto& fb_info = buffer.as<framebuffer_info_t>();
|
auto& fb_info = buffer.as<framebuffer_info_t>();
|
||||||
fb_info.width = m_width;
|
fb_info.width = m_width;
|
||||||
fb_info.height = m_height;
|
fb_info.height = m_height;
|
||||||
fb_info.bpp = m_bpp;
|
|
||||||
|
|
||||||
return sizeof(framebuffer_info_t);
|
return sizeof(framebuffer_info_t);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((size_t)offset >= m_width * m_height * bytes_per_pixel_internal)
|
if ((size_t)offset >= m_width * m_height * (BANAN_FB_BPP / 8))
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
size_t bytes_to_copy = BAN::Math::min<size_t>(m_width * m_height * bytes_per_pixel_internal - offset, buffer.size());
|
size_t bytes_to_copy = BAN::Math::min<size_t>(m_width * m_height * (BANAN_FB_BPP / 8) - offset, buffer.size());
|
||||||
memcpy(buffer.data(), reinterpret_cast<void*>(m_video_buffer->vaddr() + offset), bytes_to_copy);
|
memcpy(buffer.data(), reinterpret_cast<void*>(m_video_buffer->vaddr() + offset), bytes_to_copy);
|
||||||
|
|
||||||
return bytes_to_copy;
|
return bytes_to_copy;
|
||||||
|
@ -112,14 +108,14 @@ namespace Kernel
|
||||||
{
|
{
|
||||||
if (offset < 0)
|
if (offset < 0)
|
||||||
return BAN::Error::from_errno(EINVAL);
|
return BAN::Error::from_errno(EINVAL);
|
||||||
if ((size_t)offset >= m_width * m_height * bytes_per_pixel_internal)
|
if ((size_t)offset >= m_width * m_height * (BANAN_FB_BPP / 8))
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
size_t bytes_to_copy = BAN::Math::min<size_t>(m_width * m_height * bytes_per_pixel_internal - offset, buffer.size());
|
size_t bytes_to_copy = BAN::Math::min<size_t>(m_width * m_height * (BANAN_FB_BPP / 8) - offset, buffer.size());
|
||||||
memcpy(reinterpret_cast<void*>(m_video_buffer->vaddr() + offset), buffer.data(), bytes_to_copy);
|
memcpy(reinterpret_cast<void*>(m_video_buffer->vaddr() + offset), buffer.data(), bytes_to_copy);
|
||||||
|
|
||||||
uint32_t first_pixel = offset / bytes_per_pixel_internal;
|
uint32_t first_pixel = offset / (BANAN_FB_BPP / 8);
|
||||||
uint32_t pixel_count = BAN::Math::div_round_up<uint32_t>(bytes_to_copy + (offset % bytes_per_pixel_internal), bytes_per_pixel_internal);
|
uint32_t pixel_count = BAN::Math::div_round_up<uint32_t>(bytes_to_copy + (offset % (BANAN_FB_BPP / 8)), (BANAN_FB_BPP / 8));
|
||||||
sync_pixels_linear(first_pixel, pixel_count);
|
sync_pixels_linear(first_pixel, pixel_count);
|
||||||
|
|
||||||
return bytes_to_copy;
|
return bytes_to_copy;
|
||||||
|
@ -129,8 +125,12 @@ namespace Kernel
|
||||||
{
|
{
|
||||||
if (x >= m_width || y >= m_height)
|
if (x >= m_width || y >= m_height)
|
||||||
return;
|
return;
|
||||||
auto* video_buffer_u32 = reinterpret_cast<uint32_t*>(m_video_buffer->vaddr());
|
auto* video_buffer_u8 = reinterpret_cast<uint8_t*>(m_video_buffer->vaddr());
|
||||||
video_buffer_u32[y * m_width + x] = rgb;
|
video_buffer_u8[(y * m_width + x) * (BANAN_FB_BPP / 8) + 0] = rgb >> 0;
|
||||||
|
video_buffer_u8[(y * m_width + x) * (BANAN_FB_BPP / 8) + 1] = rgb >> 8;
|
||||||
|
video_buffer_u8[(y * m_width + x) * (BANAN_FB_BPP / 8) + 2] = rgb >> 16;
|
||||||
|
if constexpr(BANAN_FB_BPP == 32)
|
||||||
|
video_buffer_u8[(y * m_width + x) * (BANAN_FB_BPP / 8) + 3] = rgb >> 24;
|
||||||
}
|
}
|
||||||
|
|
||||||
void FramebufferDevice::sync_pixels_full()
|
void FramebufferDevice::sync_pixels_full()
|
||||||
|
@ -143,9 +143,9 @@ namespace Kernel
|
||||||
uint32_t row = i / m_width;
|
uint32_t row = i / m_width;
|
||||||
uint32_t idx = i % m_width;
|
uint32_t idx = i % m_width;
|
||||||
|
|
||||||
video_memory_u8[(row * m_pitch) + (idx * m_bpp / 8) + 0] = video_buffer_u8[i * bytes_per_pixel_internal + 0];
|
video_memory_u8[(row * m_pitch) + (idx * m_bpp / 8) + 0] = video_buffer_u8[i * (BANAN_FB_BPP / 8) + 0];
|
||||||
video_memory_u8[(row * m_pitch) + (idx * m_bpp / 8) + 1] = video_buffer_u8[i * bytes_per_pixel_internal + 1];
|
video_memory_u8[(row * m_pitch) + (idx * m_bpp / 8) + 1] = video_buffer_u8[i * (BANAN_FB_BPP / 8) + 1];
|
||||||
video_memory_u8[(row * m_pitch) + (idx * m_bpp / 8) + 2] = video_buffer_u8[i * bytes_per_pixel_internal + 2];
|
video_memory_u8[(row * m_pitch) + (idx * m_bpp / 8) + 2] = video_buffer_u8[i * (BANAN_FB_BPP / 8) + 2];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -164,9 +164,9 @@ namespace Kernel
|
||||||
uint32_t row = (first_pixel + i) / m_width;
|
uint32_t row = (first_pixel + i) / m_width;
|
||||||
uint32_t idx = (first_pixel + i) % m_width;
|
uint32_t idx = (first_pixel + i) % m_width;
|
||||||
|
|
||||||
video_memory_u8[(row * m_pitch) + (idx * m_bpp / 8) + 0] = video_buffer_u8[(first_pixel + i) * bytes_per_pixel_internal + 0];
|
video_memory_u8[(row * m_pitch) + (idx * m_bpp / 8) + 0] = video_buffer_u8[(first_pixel + i) * (BANAN_FB_BPP / 8) + 0];
|
||||||
video_memory_u8[(row * m_pitch) + (idx * m_bpp / 8) + 1] = video_buffer_u8[(first_pixel + i) * bytes_per_pixel_internal + 1];
|
video_memory_u8[(row * m_pitch) + (idx * m_bpp / 8) + 1] = video_buffer_u8[(first_pixel + i) * (BANAN_FB_BPP / 8) + 1];
|
||||||
video_memory_u8[(row * m_pitch) + (idx * m_bpp / 8) + 2] = video_buffer_u8[(first_pixel + i) * bytes_per_pixel_internal + 2];
|
video_memory_u8[(row * m_pitch) + (idx * m_bpp / 8) + 2] = video_buffer_u8[(first_pixel + i) * (BANAN_FB_BPP / 8) + 2];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -186,9 +186,9 @@ namespace Kernel
|
||||||
{
|
{
|
||||||
for (uint32_t idx = top_right_x; idx < top_right_x + width; idx++)
|
for (uint32_t idx = top_right_x; idx < top_right_x + width; idx++)
|
||||||
{
|
{
|
||||||
video_memory_u8[(row * m_pitch) + (idx * m_bpp / 8) + 0] = video_buffer_u8[(row * m_width + idx) * bytes_per_pixel_internal + 0];
|
video_memory_u8[(row * m_pitch) + (idx * m_bpp / 8) + 0] = video_buffer_u8[(row * m_width + idx) * (BANAN_FB_BPP / 8) + 0];
|
||||||
video_memory_u8[(row * m_pitch) + (idx * m_bpp / 8) + 1] = video_buffer_u8[(row * m_width + idx) * bytes_per_pixel_internal + 1];
|
video_memory_u8[(row * m_pitch) + (idx * m_bpp / 8) + 1] = video_buffer_u8[(row * m_width + idx) * (BANAN_FB_BPP / 8) + 1];
|
||||||
video_memory_u8[(row * m_pitch) + (idx * m_bpp / 8) + 2] = video_buffer_u8[(row * m_width + idx) * bytes_per_pixel_internal + 2];
|
video_memory_u8[(row * m_pitch) + (idx * m_bpp / 8) + 2] = video_buffer_u8[(row * m_width + idx) * (BANAN_FB_BPP / 8) + 2];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -224,8 +224,8 @@ namespace Kernel
|
||||||
size = (vaddr - m_vaddr) + m_size;
|
size = (vaddr - m_vaddr) + m_size;
|
||||||
|
|
||||||
m_framebuffer->sync_pixels_linear(
|
m_framebuffer->sync_pixels_linear(
|
||||||
(vaddr - m_vaddr) / bytes_per_pixel_internal,
|
(vaddr - m_vaddr) / (BANAN_FB_BPP / 8),
|
||||||
BAN::Math::div_round_up<uint32_t>((vaddr % bytes_per_pixel_internal) + size, bytes_per_pixel_internal)
|
BAN::Math::div_round_up<uint32_t>((vaddr % (BANAN_FB_BPP / 8)) + size, (BANAN_FB_BPP / 8))
|
||||||
);
|
);
|
||||||
|
|
||||||
return {};
|
return {};
|
||||||
|
|
|
@ -43,7 +43,7 @@ namespace Kernel
|
||||||
[](BAN::RefPtr<TmpInode> inode)
|
[](BAN::RefPtr<TmpInode> inode)
|
||||||
{
|
{
|
||||||
if (inode->is_device())
|
if (inode->is_device())
|
||||||
reinterpret_cast<Device*>(inode.ptr())->update();
|
static_cast<Device*>(inode.ptr())->update();
|
||||||
return BAN::Iteration::Continue;
|
return BAN::Iteration::Continue;
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
@ -77,7 +77,7 @@ namespace Kernel
|
||||||
{
|
{
|
||||||
if (inode->is_device())
|
if (inode->is_device())
|
||||||
if (((Device*)inode.ptr())->is_storage_device())
|
if (((Device*)inode.ptr())->is_storage_device())
|
||||||
if (auto ret = reinterpret_cast<StorageDevice*>(inode.ptr())->sync_disk_cache(); ret.is_error())
|
if (auto ret = static_cast<StorageDevice*>(inode.ptr())->sync_disk_cache(); ret.is_error())
|
||||||
dwarnln("disk sync: {}", ret.error());
|
dwarnln("disk sync: {}", ret.error());
|
||||||
return BAN::Iteration::Continue;
|
return BAN::Iteration::Continue;
|
||||||
}
|
}
|
||||||
|
@ -119,13 +119,13 @@ namespace Kernel
|
||||||
void DevFileSystem::add_device(BAN::RefPtr<Device> device)
|
void DevFileSystem::add_device(BAN::RefPtr<Device> device)
|
||||||
{
|
{
|
||||||
ASSERT(!device->name().contains('/'));
|
ASSERT(!device->name().contains('/'));
|
||||||
MUST(reinterpret_cast<TmpDirectoryInode*>(root_inode().ptr())->link_inode(*device, device->name()));
|
MUST(static_cast<TmpDirectoryInode*>(root_inode().ptr())->link_inode(*device, device->name()));
|
||||||
}
|
}
|
||||||
|
|
||||||
void DevFileSystem::add_inode(BAN::StringView path, BAN::RefPtr<TmpInode> inode)
|
void DevFileSystem::add_inode(BAN::StringView path, BAN::RefPtr<TmpInode> inode)
|
||||||
{
|
{
|
||||||
ASSERT(!path.contains('/'));
|
ASSERT(!path.contains('/'));
|
||||||
MUST(reinterpret_cast<TmpDirectoryInode*>(root_inode().ptr())->link_inode(*inode, path));
|
MUST(static_cast<TmpDirectoryInode*>(root_inode().ptr())->link_inode(*inode, path));
|
||||||
}
|
}
|
||||||
|
|
||||||
void DevFileSystem::for_each_device(const BAN::Function<BAN::Iteration(Device*)>& callback)
|
void DevFileSystem::for_each_device(const BAN::Function<BAN::Iteration(Device*)>& callback)
|
||||||
|
@ -136,7 +136,7 @@ namespace Kernel
|
||||||
{
|
{
|
||||||
if (!inode->is_device())
|
if (!inode->is_device())
|
||||||
return BAN::Iteration::Continue;
|
return BAN::Iteration::Continue;
|
||||||
return callback(reinterpret_cast<Device*>(inode.ptr()));
|
return callback(static_cast<Device*>(inode.ptr()));
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
@ -31,7 +31,7 @@ namespace Kernel
|
||||||
{
|
{
|
||||||
auto path = BAN::String::formatted("{}", process.pid());
|
auto path = BAN::String::formatted("{}", process.pid());
|
||||||
auto inode = TRY(ProcPidInode::create_new(process, *this, 0555, process.credentials().ruid(), process.credentials().rgid()));
|
auto inode = TRY(ProcPidInode::create_new(process, *this, 0555, process.credentials().ruid(), process.credentials().rgid()));
|
||||||
TRY(reinterpret_cast<TmpDirectoryInode*>(root_inode().ptr())->link_inode(*inode, path));
|
TRY(static_cast<TmpDirectoryInode*>(root_inode().ptr())->link_inode(*inode, path));
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -40,7 +40,7 @@ namespace Kernel
|
||||||
auto path = BAN::String::formatted("{}", process.pid());
|
auto path = BAN::String::formatted("{}", process.pid());
|
||||||
|
|
||||||
auto inode = MUST(root_inode()->find_inode(path));
|
auto inode = MUST(root_inode()->find_inode(path));
|
||||||
reinterpret_cast<ProcPidInode*>(inode.ptr())->cleanup();
|
static_cast<ProcPidInode*>(inode.ptr())->cleanup();
|
||||||
|
|
||||||
if (auto ret = root_inode()->unlink(path); ret.is_error())
|
if (auto ret = root_inode()->unlink(path); ret.is_error())
|
||||||
dwarnln("{}", ret.error());
|
dwarnln("{}", ret.error());
|
||||||
|
|
|
@ -23,9 +23,9 @@ namespace Kernel
|
||||||
root = root.substring(5);
|
root = root.substring(5);
|
||||||
|
|
||||||
auto partition_inode = MUST(DevFileSystem::get().root_inode()->find_inode(root));
|
auto partition_inode = MUST(DevFileSystem::get().root_inode()->find_inode(root));
|
||||||
if (!partition_inode->is_device() || !reinterpret_cast<Device*>(partition_inode.ptr())->is_partition())
|
if (!partition_inode->is_device() || !static_cast<Device*>(partition_inode.ptr())->is_partition())
|
||||||
Kernel::panic("Specified root '/dev/{}' does not name a partition", root);
|
Kernel::panic("Specified root '/dev/{}' does not name a partition", root);
|
||||||
s_instance->m_root_fs = MUST(Ext2FS::create(reinterpret_cast<BlockDevice*>(partition_inode.ptr())));
|
s_instance->m_root_fs = MUST(Ext2FS::create(static_cast<BlockDevice*>(partition_inode.ptr())));
|
||||||
|
|
||||||
Credentials root_creds { 0, 0, 0, 0 };
|
Credentials root_creds { 0, 0, 0, 0 };
|
||||||
MUST(s_instance->mount(root_creds, &DevFileSystem::get(), "/dev"sv));
|
MUST(s_instance->mount(root_creds, &DevFileSystem::get(), "/dev"sv));
|
||||||
|
@ -48,11 +48,11 @@ namespace Kernel
|
||||||
if (!block_device_file.inode->is_device())
|
if (!block_device_file.inode->is_device())
|
||||||
return BAN::Error::from_errno(ENOTBLK);
|
return BAN::Error::from_errno(ENOTBLK);
|
||||||
|
|
||||||
auto* device = reinterpret_cast<Device*>(block_device_file.inode.ptr());
|
auto* device = static_cast<Device*>(block_device_file.inode.ptr());
|
||||||
if (!device->mode().ifblk())
|
if (!device->mode().ifblk())
|
||||||
return BAN::Error::from_errno(ENOTBLK);
|
return BAN::Error::from_errno(ENOTBLK);
|
||||||
|
|
||||||
auto* block_device = reinterpret_cast<BlockDevice*>(device);
|
auto* block_device = static_cast<BlockDevice*>(device);
|
||||||
auto* file_system = TRY(Ext2FS::create(block_device));
|
auto* file_system = TRY(Ext2FS::create(block_device));
|
||||||
return mount(credentials, file_system, target);
|
return mount(credentials, file_system, target);
|
||||||
}
|
}
|
||||||
|
|
|
@ -41,7 +41,7 @@ namespace Kernel
|
||||||
|
|
||||||
auto inode = inode_or_error.release_value();
|
auto inode = inode_or_error.release_value();
|
||||||
if (inode->mode().iflnk())
|
if (inode->mode().iflnk())
|
||||||
MUST(reinterpret_cast<TmpSymlinkInode*>(inode.ptr())->set_link_target(name()));
|
MUST(static_cast<TmpSymlinkInode&>(*inode.ptr()).set_link_target(name()));
|
||||||
}
|
}
|
||||||
|
|
||||||
BAN::ErrorOr<void> TTY::tty_ctrl(int command, int flags)
|
BAN::ErrorOr<void> TTY::tty_ctrl(int command, int flags)
|
||||||
|
|
|
@ -7,11 +7,12 @@ __BEGIN_DECLS
|
||||||
|
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
|
||||||
|
#define BANAN_FB_BPP 32
|
||||||
|
|
||||||
struct framebuffer_info_t
|
struct framebuffer_info_t
|
||||||
{
|
{
|
||||||
uint32_t width;
|
uint32_t width;
|
||||||
uint32_t height;
|
uint32_t height;
|
||||||
uint8_t bpp;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
__END_DECLS
|
__END_DECLS
|
||||||
|
|
|
@ -70,7 +70,7 @@ BAN::UniqPtr<Image> Image::load_from_file(BAN::StringView path)
|
||||||
case 0x3350:
|
case 0x3350:
|
||||||
case 0x3250:
|
case 0x3250:
|
||||||
case 0x3150:
|
case 0x3150:
|
||||||
if (auto res = Netbpm::create(addr, st.st_size); res.is_error())
|
if (auto res = load_netbpm(addr, st.st_size); res.is_error())
|
||||||
fprintf(stderr, "%s\n", strerror(res.error().get_error_code()));
|
fprintf(stderr, "%s\n", strerror(res.error().get_error_code()));
|
||||||
else
|
else
|
||||||
image = res.release_value();
|
image = res.release_value();
|
||||||
|
@ -103,14 +103,9 @@ bool Image::render_to_framebuffer()
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (fb_info.bpp != 24 && fb_info.bpp != 32)
|
ASSERT(BANAN_FB_BPP == 24 || BANAN_FB_BPP == 32);
|
||||||
{
|
|
||||||
fprintf(stderr, "unsupported framebuffer bpp\n");
|
|
||||||
close(fd);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
size_t mmap_size = fb_info.height * fb_info.width * fb_info.bpp / 8;
|
size_t mmap_size = fb_info.height * fb_info.width * BANAN_FB_BPP / 8;
|
||||||
|
|
||||||
void* mmap_addr = mmap(nullptr, mmap_size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
|
void* mmap_addr = mmap(nullptr, mmap_size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
|
||||||
if (mmap_addr == MAP_FAILED)
|
if (mmap_addr == MAP_FAILED)
|
||||||
|
@ -126,11 +121,11 @@ bool Image::render_to_framebuffer()
|
||||||
{
|
{
|
||||||
for (uint64_t x = 0; x < BAN::Math::min<uint64_t>(width(), fb_info.width); x++)
|
for (uint64_t x = 0; x < BAN::Math::min<uint64_t>(width(), fb_info.width); x++)
|
||||||
{
|
{
|
||||||
u8_fb[(y * fb_info.width + x) * fb_info.bpp / 8 + 0] = m_bitmap[y * width() + x].r;
|
u8_fb[(y * fb_info.width + x) * BANAN_FB_BPP / 8 + 0] = m_bitmap[y * width() + x].r;
|
||||||
u8_fb[(y * fb_info.width + x) * fb_info.bpp / 8 + 1] = m_bitmap[y * width() + x].g;
|
u8_fb[(y * fb_info.width + x) * BANAN_FB_BPP / 8 + 1] = m_bitmap[y * width() + x].g;
|
||||||
u8_fb[(y * fb_info.width + x) * fb_info.bpp / 8 + 2] = m_bitmap[y * width() + x].b;
|
u8_fb[(y * fb_info.width + x) * BANAN_FB_BPP / 8 + 2] = m_bitmap[y * width() + x].b;
|
||||||
if (fb_info.bpp == 32)
|
if constexpr(BANAN_FB_BPP == 32)
|
||||||
u8_fb[(y * fb_info.width + x) * fb_info.bpp / 8 + 3] = m_bitmap[y * width() + x].a;
|
u8_fb[(y * fb_info.width + x) * BANAN_FB_BPP / 8 + 3] = m_bitmap[y * width() + x].a;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -22,15 +22,17 @@ public:
|
||||||
|
|
||||||
bool render_to_framebuffer();
|
bool render_to_framebuffer();
|
||||||
|
|
||||||
protected:
|
private:
|
||||||
Image(uint64_t width, uint64_t height, BAN::Vector<Color>&& bitmap)
|
Image(uint64_t width, uint64_t height, BAN::Vector<Color>&& bitmap)
|
||||||
: m_width(width)
|
: m_width(width)
|
||||||
, m_height(height)
|
, m_height(height)
|
||||||
, m_bitmap(BAN::move(bitmap))
|
, m_bitmap(BAN::move(bitmap))
|
||||||
{ }
|
{ }
|
||||||
|
|
||||||
protected:
|
private:
|
||||||
const uint64_t m_width;
|
const uint64_t m_width;
|
||||||
const uint64_t m_height;
|
const uint64_t m_height;
|
||||||
const BAN::Vector<Color> m_bitmap;
|
const BAN::Vector<Color> m_bitmap;
|
||||||
|
|
||||||
|
friend class BAN::UniqPtr<Image>;
|
||||||
};
|
};
|
||||||
|
|
|
@ -29,7 +29,7 @@ BAN::Optional<uint64_t> parse_u64(const uint8_t*& data, size_t data_size)
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
BAN::ErrorOr<BAN::UniqPtr<Netbpm>> Netbpm::create(const void* mmap_addr, size_t size)
|
BAN::ErrorOr<BAN::UniqPtr<Image>> load_netbpm(const void* mmap_addr, size_t size)
|
||||||
{
|
{
|
||||||
if (size < 11)
|
if (size < 11)
|
||||||
{
|
{
|
||||||
|
@ -88,7 +88,7 @@ BAN::ErrorOr<BAN::UniqPtr<Netbpm>> Netbpm::create(const void* mmap_addr, size_t
|
||||||
|
|
||||||
printf("Netbpm image %llux%llu\n", *width, *height);
|
printf("Netbpm image %llux%llu\n", *width, *height);
|
||||||
|
|
||||||
BAN::Vector<Color> bitmap;
|
BAN::Vector<Image::Color> bitmap;
|
||||||
TRY(bitmap.resize(*width * *height));
|
TRY(bitmap.resize(*width * *height));
|
||||||
|
|
||||||
// Fill bitmap
|
// Fill bitmap
|
||||||
|
@ -104,5 +104,5 @@ BAN::ErrorOr<BAN::UniqPtr<Netbpm>> Netbpm::create(const void* mmap_addr, size_t
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return TRY(BAN::UniqPtr<Netbpm>::create(*width, *height, BAN::move(bitmap)));
|
return TRY(BAN::UniqPtr<Image>::create(*width, *height, BAN::move(bitmap)));
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,14 +1,3 @@
|
||||||
#include "Image.h"
|
#include "Image.h"
|
||||||
|
|
||||||
class Netbpm : public Image
|
BAN::ErrorOr<BAN::UniqPtr<Image>> load_netbpm(const void* mmap_addr, size_t size);
|
||||||
{
|
|
||||||
public:
|
|
||||||
static BAN::ErrorOr<BAN::UniqPtr<Netbpm>> create(const void* mmap_addr, size_t size);
|
|
||||||
|
|
||||||
private:
|
|
||||||
Netbpm(uint64_t width, uint64_t height, BAN::Vector<Color>&& bitmap)
|
|
||||||
: Image(width, height, BAN::move(bitmap))
|
|
||||||
{ }
|
|
||||||
|
|
||||||
friend class BAN::UniqPtr<Netbpm>;
|
|
||||||
};
|
|
||||||
|
|
|
@ -19,7 +19,7 @@ int main()
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t fb_size = fb_info.width * fb_info.height * fb_info.bpp / 8;
|
size_t fb_size = fb_info.width * fb_info.height * BANAN_FB_BPP / 8;
|
||||||
|
|
||||||
void* addr = mmap(nullptr, fb_size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
|
void* addr = mmap(nullptr, fb_size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
|
||||||
if (addr == MAP_FAILED)
|
if (addr == MAP_FAILED)
|
||||||
|
|
Loading…
Reference in New Issue