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