This repository has been archived on 2025-02-26. You can view files and clone it, but cannot push or open issues or pull requests.
hilbert-os/applications/goldman/source/renderer.hpp
2024-07-29 21:26:17 -04:00

65 lines
1.5 KiB
C++

#pragma once
#include <daguerre/image.hpp>
#include "window.hpp"
#include <mutex>
#include <list>
class renderer {
daguerre::image<daguerre::hilbert_color> framebuffer;
daguerre::image<daguerre::hilbert_color> double_buffer;
daguerre::image<daguerre::hilbert_color> background;
daguerre::image<daguerre::hilbert_color> cursor;
daguerre::hilbert_color cursor_background;
int cursor_x;
int cursor_y;
//bottom to top
std::list<window *> windows;
std::mutex mut;
euler::syscall::stream_handle
dispatcher_handle_1, dispatcher_handle_2;
void do_render();
public:
renderer(
daguerre::image<daguerre::hilbert_color> &&framebuffer,
daguerre::image<daguerre::hilbert_color> &&background,
daguerre::hilbert_color background_color,
daguerre::image<daguerre::hilbert_color> &&cursor,
daguerre::hilbert_color cursor_background);
inline ~renderer() {
euler::syscall::close_stream(dispatcher_handle_1);
euler::syscall::close_stream(dispatcher_handle_2);
}
renderer(const renderer &) = delete;
renderer &operator =(const renderer &) = delete;
[[noreturn]] void render_thread_main();
inline void lock() { mut.lock(); }
inline void unlock() { mut.unlock(); }
inline void dispatch_render() {
uint8_t byte = 0;
euler::syscall::write_to_stream(dispatcher_handle_1, 1, &byte);
}
void bump_cursor(int x_offset, int y_offset);
void add_window(window *w);
void remove_window(window *w);
inline bool is_top(window *w) {
return windows.size() != 0 && w == windows.back();
}
};