Skip to content

Gui improvements#18

Merged
antpln merged 5 commits intomainfrom
gui-improvements
Oct 20, 2025
Merged

Gui improvements#18
antpln merged 5 commits intomainfrom
gui-improvements

Conversation

@antpln
Copy link
Copy Markdown
Owner

@antpln antpln commented Oct 20, 2025

Framebuffer Double Buffering Core Implementation

  • Introduced the BufferTarget enum to distinguish between draw and display buffers, and added functions for double buffering management such as present(), double_buffering_enabled(), and internal buffer handling logic in framebuffer.cpp and framebuffer.h.

Framebuffer Drawing APIs Update

  • Updated fill_rect, draw_mono_bitmap, and peek_pixel to accept a BufferTarget parameter, enabling drawing to either the draw or display buffer. Internal drawing logic was refactored for efficiency and correctness with double buffering.

Integration with GUI and Terminal Components

  • Modified GUI and terminal rendering functions to use the new double buffering APIs and call present() appropriately after drawing operations, ensuring rendered output is displayed only after all drawing is complete.
    Initialization and Debug Logging

  • Enhanced initialization routines to attempt enabling double buffering if supported, and added debug logging to report framebuffer status and double buffering availability at boot.
    Internal Refactoring and Robustness

  • Refactored internal framebuffer code for buffer management, memory access, and color storage, improving robustness and maintainability. Added safety checks for buffer boundaries and drawing operations.

Copilot AI review requested due to automatic review settings October 20, 2025 22:03
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR implements double buffering support for the framebuffer system to eliminate visual artifacts during rendering. The implementation adds buffer management infrastructure, updates drawing APIs to support targeting specific buffers, and integrates present() calls throughout the GUI rendering pipeline to synchronize buffer swaps.

Key changes:

  • Added BufferTarget enum and double buffering functions (present(), double_buffering_enabled()) to the framebuffer API
  • Updated all drawing functions to accept BufferTarget parameters with default values favoring the draw buffer
  • Enhanced window system to support resizable windows with proper dimension tracking and validation

Reviewed Changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
include/kernel/framebuffer.h Introduced BufferTarget enum and updated function signatures for buffer-aware drawing
src/kernel/framebuffer.cpp Core double buffering implementation with buffer management, swap logic, and optimized drawing routines
src/kernel/vga.cpp Integrated present() calls in terminal rendering and updated cursor drawing to use Display buffer
src/kernel/gui.cpp Updated mouse cursor and boot screen rendering to call present() after drawing operations
src/kernel/kernel.cpp Added debug logging for framebuffer initialization status and double buffering availability
src/kernel/terminal_windows.cpp Implemented window resizing functionality with per-window dimension tracking and proper frame clamping
src/kernel/debug.cpp Added present() call after panic screen rendering

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

Comment on lines 768 to +770
void ensure_geometry(Terminal &terminal)
{
(void)terminal;
Copy link

Copilot AI Oct 20, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The terminal parameter is explicitly marked as unused but this function was previously using it. Since geometry calculations for windows no longer depend on a specific terminal instance, consider removing the parameter entirely from ensure_geometry() and updating all call sites to improve API clarity.

Suggested change
void ensure_geometry(Terminal &terminal)
{
(void)terminal;
void ensure_geometry()
{

Copilot uses AI. Check for mistakes.
Comment on lines +673 to +685
if (g_bytes_per_pixel == 4)
{
uint8_t *row_ptr = base + (y + row) * row_stride + x * g_bytes_per_pixel;
for (uint32_t col = 0; col < width; ++col)
for (uint32_t row = 0; row < height; ++row)
{
uint8_t *pixel = row_ptr + col * g_bytes_per_pixel;
switch (g_bytes_per_pixel)
uint8_t *row_base = base + (y + row) * row_stride + x * pixel_stride;
uint32_t *dst = reinterpret_cast<uint32_t *>(row_base);
for (uint32_t col = 0; col < width; ++col)
{
case 4:
{
uint32_t value = color;
memcpy(pixel, &value, sizeof(uint32_t));
break;
}
case 3:
{
pixel[0] = static_cast<uint8_t>(color & 0xFF);
pixel[1] = static_cast<uint8_t>((color >> 8) & 0xFF);
pixel[2] = static_cast<uint8_t>((color >> 16) & 0xFF);
break;
}
case 2:
{
uint16_t value = static_cast<uint16_t>(color & 0xFFFF);
memcpy(pixel, &value, sizeof(uint16_t));
break;
}
default:
break;
dst[col] = color;
}
}
return;
}
Copy link

Copilot AI Oct 20, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The fast path for 4-byte pixels uses pointer arithmetic that could cause unaligned memory access if row_base is not 4-byte aligned. Consider adding an alignment check or using memset for single-color fills: for (uint32_t row = 0; row < height; ++row) { uint32_t *dst = reinterpret_cast<uint32_t *>(base + (y + row) * row_stride + x * pixel_stride); if (reinterpret_cast<uintptr_t>(dst) % 4 == 0) { /* fast path */ } else { /* fallback */ } }

Copilot uses AI. Check for mistakes.
@antpln antpln merged commit 874012f into main Oct 20, 2025
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants