generated from Projetos/RaspberryPi_app
63 lines
1.9 KiB
C++
63 lines
1.9 KiB
C++
// linux_fb_display.h — GfxCanvas subclass for Linux framebuffer devices.
|
|
//
|
|
// Supports XRGB8888 (32 bpp), RGB565 (16 bpp), 8-bit grayscale, and 1 bpp (SSD1306).
|
|
// 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; }
|
|
|
|
// Copy the internal shadow buffer to the framebuffer, triggering a display refresh.
|
|
void update();
|
|
|
|
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; // mmap'd framebuffer
|
|
uint8_t* shadow_ = nullptr; // internal draw target
|
|
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
|