25 #include <sys/ioctl.h> 30 #include "pedigree/native/graphics/Graphics.h" 32 #include "pedigree_fb.h" 34 Framebuffer::Framebuffer()
35 : m_pFramebuffer(0), m_FramebufferSize(0), m_Format(), m_Width(0),
36 m_Height(0), m_Fb(-1), m_bStoredMode(false), m_StoredMode()
40 Framebuffer::~Framebuffer()
44 munmap(m_pFramebuffer, m_FramebufferSize);
46 m_FramebufferSize = 0;
59 m_Fb =
open(
"/dev/fb", O_RDWR);
62 klog(LOG_INFO,
"libfb: no framebuffer device");
63 fprintf(stderr,
"libfb: couldn't open framebuffer device");
77 int result = ioctl(m_Fb, PEDIGREE_FB_GETMODE, ¤t_mode);
81 m_StoredMode = current_mode;
93 ioctl(m_Fb, PEDIGREE_FB_SETMODE, &old_mode);
95 m_bStoredMode =
false;
106 int result = ioctl(m_Fb, PEDIGREE_FB_SETMODE, &mode);
113 klog(LOG_INFO,
"libfb: can't set the desired mode");
116 "libfb: could not set desired mode (%ux%u) in any colour depth.\n",
117 mode.width, mode.height);
122 result = ioctl(m_Fb, PEDIGREE_FB_GETMODE, &set_mode);
125 klog(LOG_INFO,
"libfb: can't get mode info");
128 "libfb: could not get mode information after setting mode.\n");
131 memset(&mode, 0,
sizeof(mode));
132 ioctl(m_Fb, PEDIGREE_FB_SETMODE, &mode);
136 m_Width = set_mode.width;
137 m_Height = set_mode.height;
139 m_Format = CAIRO_FORMAT_ARGB32;
140 if (set_mode.format == PedigreeGraphics::Bits24_Rgb)
142 if (set_mode.bytes_per_pixel != 4)
145 stderr,
"libfb: error: incompatible framebuffer format (bytes " 150 else if (set_mode.format == PedigreeGraphics::Bits16_Rgb565)
152 m_Format = CAIRO_FORMAT_RGB16_565;
154 else if (set_mode.format > PedigreeGraphics::Bits32_Rgb)
157 stderr,
"libfb: error: incompatible framebuffer format (possibly " 158 "BGR or similar)\n");
162 int stride = cairo_format_stride_for_width(m_Format, set_mode.width);
165 klog(LOG_INFO,
"Mapping /dev/fb in (sz=%x)...", stride * set_mode.height);
166 m_pFramebuffer = mmap(
167 0, stride * set_mode.height, PROT_READ | PROT_WRITE, MAP_SHARED, m_Fb,
169 klog(LOG_INFO,
"Got %p...", m_pFramebuffer);
171 if (m_pFramebuffer == MAP_FAILED)
173 klog(LOG_CRIT,
"libfb: couldn't map framebuffer into address space");
178 klog(LOG_INFO,
"libfb: mapped framebuffer at %p", m_pFramebuffer);
181 m_FramebufferSize = stride * set_mode.height;
190 ioctl(m_Fb, PEDIGREE_FB_REDRAW, &fbdirty);
int enterMode(size_t desiredW, size_t desiredH, size_t desiredBpp)
All zeroes = 'revert to text mode'.
void flush(size_t x, size_t y, size_t w, size_t h)