4

I am accessing /dev/fb0, the screen's frame buffer, in console mode, Debian 10, using a HP Envy Touchsmart laptop, using fwrite standard C function.

I read this page: https://techoverflow.net/2015/06/21/querying-framebuffer-resolution-in-linux/

It states that "cat /sys/class/graphics/fb0/virtual_size" should return fb0's dimensions.

It returns 1366 x 768 pixels. This is my actual screen resolution. So good so far.

But when I write into /dev/fb0, I actually need to write 1376 pixels before I start a new row.

Please note pixels are 32-bit packets, so it does not look like there is an underlying scanline alignment issue. We are talking about a difference of 10 times 4 bytes, i.e. 40 bytes, which is a lot.

Where does this discrepancy come from? How do I get the scanline width information without having to find out visually?

1 Answer 1

5

You can probably find the value in /sys/class/graphics/fb0/stride which is the length of the line in bytes according to the source. You need to divide by the bits_per_pixel divided by 8 to get the stride in pixels.

2
  • Brilliant! I ended up finding about fb.h and ioctl calls, but your answer is exactly what I needed. Thanks.
    – Winston
    Sep 4, 2019 at 14:40
  • Shouldn't this information be in the fb_var_screeninfo object returned by the ioctl? It's conveniently missing...
    – J-Cake
    Dec 17, 2021 at 3:17

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .