]> git.proxmox.com Git - mirror_ubuntu-bionic-kernel.git/blob - Documentation/fb/api.txt
Merge branch 'next' into for-linus
[mirror_ubuntu-bionic-kernel.git] / Documentation / fb / api.txt
1 The Frame Buffer Device API
2 ---------------------------
3
4 Last revised: June 21, 2011
5
6
7 0. Introduction
8 ---------------
9
10 This document describes the frame buffer API used by applications to interact
11 with frame buffer devices. In-kernel APIs between device drivers and the frame
12 buffer core are not described.
13
14 Due to a lack of documentation in the original frame buffer API, drivers
15 behaviours differ in subtle (and not so subtle) ways. This document describes
16 the recommended API implementation, but applications should be prepared to
17 deal with different behaviours.
18
19
20 1. Capabilities
21 ---------------
22
23 Device and driver capabilities are reported in the fixed screen information
24 capabilities field.
25
26 struct fb_fix_screeninfo {
27 ...
28 __u16 capabilities; /* see FB_CAP_* */
29 ...
30 };
31
32 Application should use those capabilities to find out what features they can
33 expect from the device and driver.
34
35 - FB_CAP_FOURCC
36
37 The driver supports the four character code (FOURCC) based format setting API.
38 When supported, formats are configured using a FOURCC instead of manually
39 specifying color components layout.
40
41
42 2. Types and visuals
43 --------------------
44
45 Pixels are stored in memory in hardware-dependent formats. Applications need
46 to be aware of the pixel storage format in order to write image data to the
47 frame buffer memory in the format expected by the hardware.
48
49 Formats are described by frame buffer types and visuals. Some visuals require
50 additional information, which are stored in the variable screen information
51 bits_per_pixel, grayscale, red, green, blue and transp fields.
52
53 Visuals describe how color information is encoded and assembled to create
54 macropixels. Types describe how macropixels are stored in memory. The following
55 types and visuals are supported.
56
57 - FB_TYPE_PACKED_PIXELS
58
59 Macropixels are stored contiguously in a single plane. If the number of bits
60 per macropixel is not a multiple of 8, whether macropixels are padded to the
61 next multiple of 8 bits or packed together into bytes depends on the visual.
62
63 Padding at end of lines may be present and is then reported through the fixed
64 screen information line_length field.
65
66 - FB_TYPE_PLANES
67
68 Macropixels are split across multiple planes. The number of planes is equal to
69 the number of bits per macropixel, with plane i'th storing i'th bit from all
70 macropixels.
71
72 Planes are located contiguously in memory.
73
74 - FB_TYPE_INTERLEAVED_PLANES
75
76 Macropixels are split across multiple planes. The number of planes is equal to
77 the number of bits per macropixel, with plane i'th storing i'th bit from all
78 macropixels.
79
80 Planes are interleaved in memory. The interleave factor, defined as the
81 distance in bytes between the beginning of two consecutive interleaved blocks
82 belonging to different planes, is stored in the fixed screen information
83 type_aux field.
84
85 - FB_TYPE_FOURCC
86
87 Macropixels are stored in memory as described by the format FOURCC identifier
88 stored in the variable screen information grayscale field.
89
90 - FB_VISUAL_MONO01
91
92 Pixels are black or white and stored on a number of bits (typically one)
93 specified by the variable screen information bpp field.
94
95 Black pixels are represented by all bits set to 1 and white pixels by all bits
96 set to 0. When the number of bits per pixel is smaller than 8, several pixels
97 are packed together in a byte.
98
99 FB_VISUAL_MONO01 is currently used with FB_TYPE_PACKED_PIXELS only.
100
101 - FB_VISUAL_MONO10
102
103 Pixels are black or white and stored on a number of bits (typically one)
104 specified by the variable screen information bpp field.
105
106 Black pixels are represented by all bits set to 0 and white pixels by all bits
107 set to 1. When the number of bits per pixel is smaller than 8, several pixels
108 are packed together in a byte.
109
110 FB_VISUAL_MONO01 is currently used with FB_TYPE_PACKED_PIXELS only.
111
112 - FB_VISUAL_TRUECOLOR
113
114 Pixels are broken into red, green and blue components, and each component
115 indexes a read-only lookup table for the corresponding value. Lookup tables
116 are device-dependent, and provide linear or non-linear ramps.
117
118 Each component is stored in a macropixel according to the variable screen
119 information red, green, blue and transp fields.
120
121 - FB_VISUAL_PSEUDOCOLOR and FB_VISUAL_STATIC_PSEUDOCOLOR
122
123 Pixel values are encoded as indices into a colormap that stores red, green and
124 blue components. The colormap is read-only for FB_VISUAL_STATIC_PSEUDOCOLOR
125 and read-write for FB_VISUAL_PSEUDOCOLOR.
126
127 Each pixel value is stored in the number of bits reported by the variable
128 screen information bits_per_pixel field.
129
130 - FB_VISUAL_DIRECTCOLOR
131
132 Pixels are broken into red, green and blue components, and each component
133 indexes a programmable lookup table for the corresponding value.
134
135 Each component is stored in a macropixel according to the variable screen
136 information red, green, blue and transp fields.
137
138 - FB_VISUAL_FOURCC
139
140 Pixels are encoded and interpreted as described by the format FOURCC
141 identifier stored in the variable screen information grayscale field.
142
143
144 3. Screen information
145 ---------------------
146
147 Screen information are queried by applications using the FBIOGET_FSCREENINFO
148 and FBIOGET_VSCREENINFO ioctls. Those ioctls take a pointer to a
149 fb_fix_screeninfo and fb_var_screeninfo structure respectively.
150
151 struct fb_fix_screeninfo stores device independent unchangeable information
152 about the frame buffer device and the current format. Those information can't
153 be directly modified by applications, but can be changed by the driver when an
154 application modifies the format.
155
156 struct fb_fix_screeninfo {
157 char id[16]; /* identification string eg "TT Builtin" */
158 unsigned long smem_start; /* Start of frame buffer mem */
159 /* (physical address) */
160 __u32 smem_len; /* Length of frame buffer mem */
161 __u32 type; /* see FB_TYPE_* */
162 __u32 type_aux; /* Interleave for interleaved Planes */
163 __u32 visual; /* see FB_VISUAL_* */
164 __u16 xpanstep; /* zero if no hardware panning */
165 __u16 ypanstep; /* zero if no hardware panning */
166 __u16 ywrapstep; /* zero if no hardware ywrap */
167 __u32 line_length; /* length of a line in bytes */
168 unsigned long mmio_start; /* Start of Memory Mapped I/O */
169 /* (physical address) */
170 __u32 mmio_len; /* Length of Memory Mapped I/O */
171 __u32 accel; /* Indicate to driver which */
172 /* specific chip/card we have */
173 __u16 capabilities; /* see FB_CAP_* */
174 __u16 reserved[2]; /* Reserved for future compatibility */
175 };
176
177 struct fb_var_screeninfo stores device independent changeable information
178 about a frame buffer device, its current format and video mode, as well as
179 other miscellaneous parameters.
180
181 struct fb_var_screeninfo {
182 __u32 xres; /* visible resolution */
183 __u32 yres;
184 __u32 xres_virtual; /* virtual resolution */
185 __u32 yres_virtual;
186 __u32 xoffset; /* offset from virtual to visible */
187 __u32 yoffset; /* resolution */
188
189 __u32 bits_per_pixel; /* guess what */
190 __u32 grayscale; /* 0 = color, 1 = grayscale, */
191 /* >1 = FOURCC */
192 struct fb_bitfield red; /* bitfield in fb mem if true color, */
193 struct fb_bitfield green; /* else only length is significant */
194 struct fb_bitfield blue;
195 struct fb_bitfield transp; /* transparency */
196
197 __u32 nonstd; /* != 0 Non standard pixel format */
198
199 __u32 activate; /* see FB_ACTIVATE_* */
200
201 __u32 height; /* height of picture in mm */
202 __u32 width; /* width of picture in mm */
203
204 __u32 accel_flags; /* (OBSOLETE) see fb_info.flags */
205
206 /* Timing: All values in pixclocks, except pixclock (of course) */
207 __u32 pixclock; /* pixel clock in ps (pico seconds) */
208 __u32 left_margin; /* time from sync to picture */
209 __u32 right_margin; /* time from picture to sync */
210 __u32 upper_margin; /* time from sync to picture */
211 __u32 lower_margin;
212 __u32 hsync_len; /* length of horizontal sync */
213 __u32 vsync_len; /* length of vertical sync */
214 __u32 sync; /* see FB_SYNC_* */
215 __u32 vmode; /* see FB_VMODE_* */
216 __u32 rotate; /* angle we rotate counter clockwise */
217 __u32 colorspace; /* colorspace for FOURCC-based modes */
218 __u32 reserved[4]; /* Reserved for future compatibility */
219 };
220
221 To modify variable information, applications call the FBIOPUT_VSCREENINFO
222 ioctl with a pointer to a fb_var_screeninfo structure. If the call is
223 successful, the driver will update the fixed screen information accordingly.
224
225 Instead of filling the complete fb_var_screeninfo structure manually,
226 applications should call the FBIOGET_VSCREENINFO ioctl and modify only the
227 fields they care about.
228
229
230 4. Format configuration
231 -----------------------
232
233 Frame buffer devices offer two ways to configure the frame buffer format: the
234 legacy API and the FOURCC-based API.
235
236
237 The legacy API has been the only frame buffer format configuration API for a
238 long time and is thus widely used by application. It is the recommended API
239 for applications when using RGB and grayscale formats, as well as legacy
240 non-standard formats.
241
242 To select a format, applications set the fb_var_screeninfo bits_per_pixel field
243 to the desired frame buffer depth. Values up to 8 will usually map to
244 monochrome, grayscale or pseudocolor visuals, although this is not required.
245
246 - For grayscale formats, applications set the grayscale field to one. The red,
247 blue, green and transp fields must be set to 0 by applications and ignored by
248 drivers. Drivers must fill the red, blue and green offsets to 0 and lengths
249 to the bits_per_pixel value.
250
251 - For pseudocolor formats, applications set the grayscale field to zero. The
252 red, blue, green and transp fields must be set to 0 by applications and
253 ignored by drivers. Drivers must fill the red, blue and green offsets to 0
254 and lengths to the bits_per_pixel value.
255
256 - For truecolor and directcolor formats, applications set the grayscale field
257 to zero, and the red, blue, green and transp fields to describe the layout of
258 color components in memory.
259
260 struct fb_bitfield {
261 __u32 offset; /* beginning of bitfield */
262 __u32 length; /* length of bitfield */
263 __u32 msb_right; /* != 0 : Most significant bit is */
264 /* right */
265 };
266
267 Pixel values are bits_per_pixel wide and are split in non-overlapping red,
268 green, blue and alpha (transparency) components. Location and size of each
269 component in the pixel value are described by the fb_bitfield offset and
270 length fields. Offset are computed from the right.
271
272 Pixels are always stored in an integer number of bytes. If the number of
273 bits per pixel is not a multiple of 8, pixel values are padded to the next
274 multiple of 8 bits.
275
276 Upon successful format configuration, drivers update the fb_fix_screeninfo
277 type, visual and line_length fields depending on the selected format.
278
279
280 The FOURCC-based API replaces format descriptions by four character codes
281 (FOURCC). FOURCCs are abstract identifiers that uniquely define a format
282 without explicitly describing it. This is the only API that supports YUV
283 formats. Drivers are also encouraged to implement the FOURCC-based API for RGB
284 and grayscale formats.
285
286 Drivers that support the FOURCC-based API report this capability by setting
287 the FB_CAP_FOURCC bit in the fb_fix_screeninfo capabilities field.
288
289 FOURCC definitions are located in the linux/videodev2.h header. However, and
290 despite starting with the V4L2_PIX_FMT_prefix, they are not restricted to V4L2
291 and don't require usage of the V4L2 subsystem. FOURCC documentation is
292 available in Documentation/DocBook/v4l/pixfmt.xml.
293
294 To select a format, applications set the grayscale field to the desired FOURCC.
295 For YUV formats, they should also select the appropriate colorspace by setting
296 the colorspace field to one of the colorspaces listed in linux/videodev2.h and
297 documented in Documentation/DocBook/v4l/colorspaces.xml.
298
299 The red, green, blue and transp fields are not used with the FOURCC-based API.
300 For forward compatibility reasons applications must zero those fields, and
301 drivers must ignore them. Values other than 0 may get a meaning in future
302 extensions.
303
304 Upon successful format configuration, drivers update the fb_fix_screeninfo
305 type, visual and line_length fields depending on the selected format. The type
306 and visual fields are set to FB_TYPE_FOURCC and FB_VISUAL_FOURCC respectively.