0001 ===========================
0002 The Frame Buffer Device API
0003 ===========================
0004
0005 Last revised: June 21, 2011
0006
0007
0008 0. Introduction
0009 ---------------
0010
0011 This document describes the frame buffer API used by applications to interact
0012 with frame buffer devices. In-kernel APIs between device drivers and the frame
0013 buffer core are not described.
0014
0015 Due to a lack of documentation in the original frame buffer API, drivers
0016 behaviours differ in subtle (and not so subtle) ways. This document describes
0017 the recommended API implementation, but applications should be prepared to
0018 deal with different behaviours.
0019
0020
0021 1. Capabilities
0022 ---------------
0023
0024 Device and driver capabilities are reported in the fixed screen information
0025 capabilities field::
0026
0027 struct fb_fix_screeninfo {
0028 ...
0029 __u16 capabilities; /* see FB_CAP_* */
0030 ...
0031 };
0032
0033 Application should use those capabilities to find out what features they can
0034 expect from the device and driver.
0035
0036 - FB_CAP_FOURCC
0037
0038 The driver supports the four character code (FOURCC) based format setting API.
0039 When supported, formats are configured using a FOURCC instead of manually
0040 specifying color components layout.
0041
0042
0043 2. Types and visuals
0044 --------------------
0045
0046 Pixels are stored in memory in hardware-dependent formats. Applications need
0047 to be aware of the pixel storage format in order to write image data to the
0048 frame buffer memory in the format expected by the hardware.
0049
0050 Formats are described by frame buffer types and visuals. Some visuals require
0051 additional information, which are stored in the variable screen information
0052 bits_per_pixel, grayscale, red, green, blue and transp fields.
0053
0054 Visuals describe how color information is encoded and assembled to create
0055 macropixels. Types describe how macropixels are stored in memory. The following
0056 types and visuals are supported.
0057
0058 - FB_TYPE_PACKED_PIXELS
0059
0060 Macropixels are stored contiguously in a single plane. If the number of bits
0061 per macropixel is not a multiple of 8, whether macropixels are padded to the
0062 next multiple of 8 bits or packed together into bytes depends on the visual.
0063
0064 Padding at end of lines may be present and is then reported through the fixed
0065 screen information line_length field.
0066
0067 - FB_TYPE_PLANES
0068
0069 Macropixels are split across multiple planes. The number of planes is equal to
0070 the number of bits per macropixel, with plane i'th storing i'th bit from all
0071 macropixels.
0072
0073 Planes are located contiguously in memory.
0074
0075 - FB_TYPE_INTERLEAVED_PLANES
0076
0077 Macropixels are split across multiple planes. The number of planes is equal to
0078 the number of bits per macropixel, with plane i'th storing i'th bit from all
0079 macropixels.
0080
0081 Planes are interleaved in memory. The interleave factor, defined as the
0082 distance in bytes between the beginning of two consecutive interleaved blocks
0083 belonging to different planes, is stored in the fixed screen information
0084 type_aux field.
0085
0086 - FB_TYPE_FOURCC
0087
0088 Macropixels are stored in memory as described by the format FOURCC identifier
0089 stored in the variable screen information grayscale field.
0090
0091 - FB_VISUAL_MONO01
0092
0093 Pixels are black or white and stored on a number of bits (typically one)
0094 specified by the variable screen information bpp field.
0095
0096 Black pixels are represented by all bits set to 1 and white pixels by all bits
0097 set to 0. When the number of bits per pixel is smaller than 8, several pixels
0098 are packed together in a byte.
0099
0100 FB_VISUAL_MONO01 is currently used with FB_TYPE_PACKED_PIXELS only.
0101
0102 - FB_VISUAL_MONO10
0103
0104 Pixels are black or white and stored on a number of bits (typically one)
0105 specified by the variable screen information bpp field.
0106
0107 Black pixels are represented by all bits set to 0 and white pixels by all bits
0108 set to 1. When the number of bits per pixel is smaller than 8, several pixels
0109 are packed together in a byte.
0110
0111 FB_VISUAL_MONO01 is currently used with FB_TYPE_PACKED_PIXELS only.
0112
0113 - FB_VISUAL_TRUECOLOR
0114
0115 Pixels are broken into red, green and blue components, and each component
0116 indexes a read-only lookup table for the corresponding value. Lookup tables
0117 are device-dependent, and provide linear or non-linear ramps.
0118
0119 Each component is stored in a macropixel according to the variable screen
0120 information red, green, blue and transp fields.
0121
0122 - FB_VISUAL_PSEUDOCOLOR and FB_VISUAL_STATIC_PSEUDOCOLOR
0123
0124 Pixel values are encoded as indices into a colormap that stores red, green and
0125 blue components. The colormap is read-only for FB_VISUAL_STATIC_PSEUDOCOLOR
0126 and read-write for FB_VISUAL_PSEUDOCOLOR.
0127
0128 Each pixel value is stored in the number of bits reported by the variable
0129 screen information bits_per_pixel field.
0130
0131 - FB_VISUAL_DIRECTCOLOR
0132
0133 Pixels are broken into red, green and blue components, and each component
0134 indexes a programmable lookup table for the corresponding value.
0135
0136 Each component is stored in a macropixel according to the variable screen
0137 information red, green, blue and transp fields.
0138
0139 - FB_VISUAL_FOURCC
0140
0141 Pixels are encoded and interpreted as described by the format FOURCC
0142 identifier stored in the variable screen information grayscale field.
0143
0144
0145 3. Screen information
0146 ---------------------
0147
0148 Screen information are queried by applications using the FBIOGET_FSCREENINFO
0149 and FBIOGET_VSCREENINFO ioctls. Those ioctls take a pointer to a
0150 fb_fix_screeninfo and fb_var_screeninfo structure respectively.
0151
0152 struct fb_fix_screeninfo stores device independent unchangeable information
0153 about the frame buffer device and the current format. Those information can't
0154 be directly modified by applications, but can be changed by the driver when an
0155 application modifies the format::
0156
0157 struct fb_fix_screeninfo {
0158 char id[16]; /* identification string eg "TT Builtin" */
0159 unsigned long smem_start; /* Start of frame buffer mem */
0160 /* (physical address) */
0161 __u32 smem_len; /* Length of frame buffer mem */
0162 __u32 type; /* see FB_TYPE_* */
0163 __u32 type_aux; /* Interleave for interleaved Planes */
0164 __u32 visual; /* see FB_VISUAL_* */
0165 __u16 xpanstep; /* zero if no hardware panning */
0166 __u16 ypanstep; /* zero if no hardware panning */
0167 __u16 ywrapstep; /* zero if no hardware ywrap */
0168 __u32 line_length; /* length of a line in bytes */
0169 unsigned long mmio_start; /* Start of Memory Mapped I/O */
0170 /* (physical address) */
0171 __u32 mmio_len; /* Length of Memory Mapped I/O */
0172 __u32 accel; /* Indicate to driver which */
0173 /* specific chip/card we have */
0174 __u16 capabilities; /* see FB_CAP_* */
0175 __u16 reserved[2]; /* Reserved for future compatibility */
0176 };
0177
0178 struct fb_var_screeninfo stores device independent changeable information
0179 about a frame buffer device, its current format and video mode, as well as
0180 other miscellaneous parameters::
0181
0182 struct fb_var_screeninfo {
0183 __u32 xres; /* visible resolution */
0184 __u32 yres;
0185 __u32 xres_virtual; /* virtual resolution */
0186 __u32 yres_virtual;
0187 __u32 xoffset; /* offset from virtual to visible */
0188 __u32 yoffset; /* resolution */
0189
0190 __u32 bits_per_pixel; /* guess what */
0191 __u32 grayscale; /* 0 = color, 1 = grayscale, */
0192 /* >1 = FOURCC */
0193 struct fb_bitfield red; /* bitfield in fb mem if true color, */
0194 struct fb_bitfield green; /* else only length is significant */
0195 struct fb_bitfield blue;
0196 struct fb_bitfield transp; /* transparency */
0197
0198 __u32 nonstd; /* != 0 Non standard pixel format */
0199
0200 __u32 activate; /* see FB_ACTIVATE_* */
0201
0202 __u32 height; /* height of picture in mm */
0203 __u32 width; /* width of picture in mm */
0204
0205 __u32 accel_flags; /* (OBSOLETE) see fb_info.flags */
0206
0207 /* Timing: All values in pixclocks, except pixclock (of course) */
0208 __u32 pixclock; /* pixel clock in ps (pico seconds) */
0209 __u32 left_margin; /* time from sync to picture */
0210 __u32 right_margin; /* time from picture to sync */
0211 __u32 upper_margin; /* time from sync to picture */
0212 __u32 lower_margin;
0213 __u32 hsync_len; /* length of horizontal sync */
0214 __u32 vsync_len; /* length of vertical sync */
0215 __u32 sync; /* see FB_SYNC_* */
0216 __u32 vmode; /* see FB_VMODE_* */
0217 __u32 rotate; /* angle we rotate counter clockwise */
0218 __u32 colorspace; /* colorspace for FOURCC-based modes */
0219 __u32 reserved[4]; /* Reserved for future compatibility */
0220 };
0221
0222 To modify variable information, applications call the FBIOPUT_VSCREENINFO
0223 ioctl with a pointer to a fb_var_screeninfo structure. If the call is
0224 successful, the driver will update the fixed screen information accordingly.
0225
0226 Instead of filling the complete fb_var_screeninfo structure manually,
0227 applications should call the FBIOGET_VSCREENINFO ioctl and modify only the
0228 fields they care about.
0229
0230
0231 4. Format configuration
0232 -----------------------
0233
0234 Frame buffer devices offer two ways to configure the frame buffer format: the
0235 legacy API and the FOURCC-based API.
0236
0237
0238 The legacy API has been the only frame buffer format configuration API for a
0239 long time and is thus widely used by application. It is the recommended API
0240 for applications when using RGB and grayscale formats, as well as legacy
0241 non-standard formats.
0242
0243 To select a format, applications set the fb_var_screeninfo bits_per_pixel field
0244 to the desired frame buffer depth. Values up to 8 will usually map to
0245 monochrome, grayscale or pseudocolor visuals, although this is not required.
0246
0247 - For grayscale formats, applications set the grayscale field to one. The red,
0248 blue, green and transp fields must be set to 0 by applications and ignored by
0249 drivers. Drivers must fill the red, blue and green offsets to 0 and lengths
0250 to the bits_per_pixel value.
0251
0252 - For pseudocolor formats, applications set the grayscale field to zero. The
0253 red, blue, green and transp fields must be set to 0 by applications and
0254 ignored by drivers. Drivers must fill the red, blue and green offsets to 0
0255 and lengths to the bits_per_pixel value.
0256
0257 - For truecolor and directcolor formats, applications set the grayscale field
0258 to zero, and the red, blue, green and transp fields to describe the layout of
0259 color components in memory::
0260
0261 struct fb_bitfield {
0262 __u32 offset; /* beginning of bitfield */
0263 __u32 length; /* length of bitfield */
0264 __u32 msb_right; /* != 0 : Most significant bit is */
0265 /* right */
0266 };
0267
0268 Pixel values are bits_per_pixel wide and are split in non-overlapping red,
0269 green, blue and alpha (transparency) components. Location and size of each
0270 component in the pixel value are described by the fb_bitfield offset and
0271 length fields. Offset are computed from the right.
0272
0273 Pixels are always stored in an integer number of bytes. If the number of
0274 bits per pixel is not a multiple of 8, pixel values are padded to the next
0275 multiple of 8 bits.
0276
0277 Upon successful format configuration, drivers update the fb_fix_screeninfo
0278 type, visual and line_length fields depending on the selected format.
0279
0280
0281 The FOURCC-based API replaces format descriptions by four character codes
0282 (FOURCC). FOURCCs are abstract identifiers that uniquely define a format
0283 without explicitly describing it. This is the only API that supports YUV
0284 formats. Drivers are also encouraged to implement the FOURCC-based API for RGB
0285 and grayscale formats.
0286
0287 Drivers that support the FOURCC-based API report this capability by setting
0288 the FB_CAP_FOURCC bit in the fb_fix_screeninfo capabilities field.
0289
0290 FOURCC definitions are located in the linux/videodev2.h header. However, and
0291 despite starting with the V4L2_PIX_FMT_prefix, they are not restricted to V4L2
0292 and don't require usage of the V4L2 subsystem. FOURCC documentation is
0293 available in Documentation/userspace-api/media/v4l/pixfmt.rst.
0294
0295 To select a format, applications set the grayscale field to the desired FOURCC.
0296 For YUV formats, they should also select the appropriate colorspace by setting
0297 the colorspace field to one of the colorspaces listed in linux/videodev2.h and
0298 documented in Documentation/userspace-api/media/v4l/colorspaces.rst.
0299
0300 The red, green, blue and transp fields are not used with the FOURCC-based API.
0301 For forward compatibility reasons applications must zero those fields, and
0302 drivers must ignore them. Values other than 0 may get a meaning in future
0303 extensions.
0304
0305 Upon successful format configuration, drivers update the fb_fix_screeninfo
0306 type, visual and line_length fields depending on the selected format. The type
0307 and visual fields are set to FB_TYPE_FOURCC and FB_VISUAL_FOURCC respectively.