Files
GfxCanvas/linux_fb_display.h

59 lines
1.7 KiB
C++

// linux_fb_display.h — GfxCanvas subclass for Linux framebuffer devices.
//
// Supports XRGB8888 (32 bpp), RGB565 (16 bpp), and 8-bit grayscale.
// Uses mmap for zero-copy access to the kernel framebuffer.
#ifndef LINUX_FB_DISPLAY_H
#define LINUX_FB_DISPLAY_H
#include "gfx_canvas.h"
#include <cstdint>
#include <linux/fb.h>
namespace gfx {
class LinuxFBDisplay : public GfxCanvas {
public:
// Construct with the physical panel dimensions.
LinuxFBDisplay(int16_t width, int16_t height);
~LinuxFBDisplay() override;
// Open the framebuffer device. Returns true on success.
[[nodiscard]] bool open(const char* device);
// Release the mmap and close the file descriptor.
void close();
// Is the framebuffer currently open and mapped?
bool isOpen() const { return buf_ != nullptr; }
protected:
// Mandatory HAL: single pixel write.
void drawPixelImpl(int16_t x, int16_t y, Color color) override;
// Accelerated HAL overrides.
void drawHLineImpl(int16_t x, int16_t y, int16_t w, Color color) override;
void drawVLineImpl(int16_t x, int16_t y, int16_t h, Color color) override;
void fillRectImpl(int16_t x, int16_t y,
int16_t w, int16_t h, Color color) override;
private:
int fd_ = -1;
uint8_t* buf_ = nullptr;
size_t map_size_ = 0;
uint32_t bpp_ = 0;
uint32_t line_len_ = 0;
fb_var_screeninfo vinfo_{};
fb_fix_screeninfo finfo_{};
// Convert XRGB8888 color to the native pixel value for this fb.
// Returns the value and its byte width.
void writePixel(uint8_t* dst, Color color) const;
};
} // namespace gfx
#endif // LINUX_FB_DISPLAY_H