Documentation/fb/api.rst GitHub 원문 ↗

Linux 6.18.37 · Frame Buffer

The Frame Buffer Device API

Frame buffer type·visual, fixed/variable screen information, legacy와 FOURCC format 설정 API의 한국어 전문 번역입니다.

Source pathDocumentation/fb/api.rst
Source versionLinux v6.18.37
TranslationDUJINLABS 전문 번역 + 해설

요약·해설과 원문, 전문 번역을 서로 분리했습니다. API 이름, symbol, source path는 원문 표기를 사용합니다.

1. 요약·해설

원문의 핵심 논리와 kernel programming 관점의 보충 설명입니다. 아래의 전문 번역과는 별도로 작성했습니다.

요약·해설

api.rst:1-307

Frame Buffer Device API는 application이 fixed/variable screen information을 조회하고 pixel format을 설정하는 userspace contract입니다. Type은 macropixel의 memory layout을, visual은 color encoding 방식을 나타냅니다.

Mode 변경은 기존 `fb_var_screeninfo`를 읽고 필요한 field만 수정한 뒤 `FBIOPUT_VSCREENINFO`로 적용합니다. RGB·grayscale에는 legacy API를 쓸 수 있고, YUV 및 명시적 format identifier에는 `FB_CAP_FOURCC`를 확인한 뒤 FOURCC API를 사용합니다.

Frame buffer API 핵심 선택
질문확인할 값결과
어떻게 저장되는가?`fb_fix_screeninfo.type`Packed, planar, interleaved, FOURCC
색을 어떻게 해석하는가?`fb_fix_screeninfo.visual`Mono, true/direct color, pseudocolor, FOURCC
현재 mode는 무엇인가?`FBIOGET_VSCREENINFO`Resolution, bpp, component, timing
FOURCC를 지원하는가?`FB_CAP_FOURCC`YUV/RGB/grayscale FOURCC mode 사용 가능

2. 영어 원문 전체

번역 기준이 된 Linux v6.18.37 원문입니다. 줄 번호는 이 버전의 파일 좌표입니다.

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

3. 한국어 전문 번역

영어 원문의 문단 순서와 의미를 유지한 전체 번역입니다. 코드, 함수명, symbol과 URL은 원문 표기를 유지합니다.

Frame Buffer Device API 소개

1-20

이 문서는 application이 frame buffer device와 상호 작용할 때 사용하는 frame buffer API를 설명합니다. Device driver와 frame buffer core 사이에서 쓰는 in-kernel API는 다루지 않습니다.

최종 개정일은 2011년 6월 21일입니다.

초기 frame buffer API의 문서가 충분하지 않았기 때문에 driver 동작에는 미묘하거나 상당한 차이가 존재합니다. 여기서는 권장 API 구현을 설명하지만, application은 서로 다른 driver 동작에도 대응할 수 있어야 합니다.

Frame buffer userspace 경계
Application calls frame buffer userspace APIFrame buffer device reports its format and capabilitiesApplication adapts to driver-specific behaviorIn-kernel driver/core APIs remain out of scope

이 문서가 다루는 범위와 application이 고려해야 할 호환성 조건입니다.

===========================
The Frame Buffer Device API
===========================

Last revised: June 21, 2011


0. Introduction
---------------

This document describes the frame buffer API used by applications to interact
with frame buffer devices. In-kernel APIs between device drivers and the frame
buffer core are not described.

Due to a lack of documentation in the original frame buffer API, drivers
behaviours differ in subtle (and not so subtle) ways. This document describes
the recommended API implementation, but applications should be prepared to
deal with different behaviours.

Device와 driver capability

21-42

Device와 driver의 capability는 fixed screen information의 `capabilities` field에 보고됩니다. Application은 이 값을 검사해 device와 driver에서 기대할 수 있는 기능을 판단해야 합니다.

`FB_CAP_FOURCC`가 설정되어 있으면 driver가 four character code(FOURCC) 기반 format 설정 API를 지원합니다. 이 경우 color component의 memory layout을 application이 직접 지정하는 대신 FOURCC로 format을 구성합니다.

Capability 확인
Field 또는 bit의미Application 동작
`fb_fix_screeninfo.capabilities`Device/driver 기능 bitmask지원 기능을 사용하기 전에 검사
`FB_CAP_FOURCC`FOURCC 기반 format 설정 지원Component layout 대신 FOURCC 지정

1. Capabilities
---------------

Device and driver capabilities are reported in the fixed screen information
capabilities field::

  struct fb_fix_screeninfo {
        ...
        __u16 capabilities;                /* see FB_CAP_*                        */
        ...
  };

Application should use those capabilities to find out what features they can
expect from the device and driver.

- FB_CAP_FOURCC

The driver supports the four character code (FOURCC) based format setting API.
When supported, formats are configured using a FOURCC instead of manually
specifying color components layout.

Pixel 저장 type과 macropixel 배치

43-90

Pixel은 hardware에 따라 다른 format으로 memory에 저장되므로, application은 hardware가 기대하는 형식으로 image data를 쓰기 위해 pixel storage format을 알아야 합니다.

Format은 frame buffer type과 visual로 기술합니다. 일부 visual에는 variable screen information의 `bits_per_pixel`, `grayscale`, `red`, `green`, `blue`, `transp` field가 제공하는 추가 정보가 필요합니다.

Visual은 color information을 encoding하고 조합해 macropixel을 만드는 방법을 나타내고, type은 macropixel을 memory에 저장하는 방법을 나타냅니다.

`FB_TYPE_PACKED_PIXELS`에서는 macropixel을 단일 plane에 연속 저장합니다. Macropixel bit 수가 8의 배수가 아닐 때 다음 8-bit 경계까지 padding할지 byte 안에 연속 packing할지는 visual에 따라 달라집니다. Line 끝 padding이 있으면 `fb_fix_screeninfo.line_length`로 보고합니다.

`FB_TYPE_PLANES`에서는 macropixel을 bit 수와 같은 개수의 plane으로 나누고, i번째 plane에 모든 macropixel의 i번째 bit를 저장합니다. Plane들은 memory에 연속 배치됩니다.

`FB_TYPE_INTERLEAVED_PLANES`도 각 bit를 별도 plane에 저장하지만 plane block을 memory에서 interleave합니다. 서로 다른 plane에 속한 연속 interleaved block 시작점 사이의 byte 거리는 `fb_fix_screeninfo.type_aux`에 저장됩니다.

`FB_TYPE_FOURCC`에서는 `fb_var_screeninfo.grayscale`에 저장된 format FOURCC identifier가 설명하는 방식대로 macropixel을 memory에 배치합니다.

Frame buffer type 비교
TypeMemory layout추가 정보
`FB_TYPE_PACKED_PIXELS`단일 plane에 macropixel 연속 저장Line padding은 `line_length`
`FB_TYPE_PLANES`Bit별 plane을 연속 저장Plane 수는 bits per macropixel
`FB_TYPE_INTERLEAVED_PLANES`Bit별 plane block을 interleave간격은 `type_aux`
`FB_TYPE_FOURCC`FOURCC가 정의한 layoutIdentifier는 `grayscale`

2. Types and visuals
--------------------

Pixels are stored in memory in hardware-dependent formats. Applications need
to be aware of the pixel storage format in order to write image data to the
frame buffer memory in the format expected by the hardware.

Formats are described by frame buffer types and visuals. Some visuals require
additional information, which are stored in the variable screen information
bits_per_pixel, grayscale, red, green, blue and transp fields.

Visuals describe how color information is encoded and assembled to create
macropixels. Types describe how macropixels are stored in memory. The following
types and visuals are supported.

- FB_TYPE_PACKED_PIXELS

Macropixels are stored contiguously in a single plane. If the number of bits
per macropixel is not a multiple of 8, whether macropixels are padded to the
next multiple of 8 bits or packed together into bytes depends on the visual.

Padding at end of lines may be present and is then reported through the fixed
screen information line_length field.

- FB_TYPE_PLANES

Macropixels are split across multiple planes. The number of planes is equal to
the number of bits per macropixel, with plane i'th storing i'th bit from all
macropixels.

Planes are located contiguously in memory.

- FB_TYPE_INTERLEAVED_PLANES

Macropixels are split across multiple planes. The number of planes is equal to
the number of bits per macropixel, with plane i'th storing i'th bit from all
macropixels.

Planes are interleaved in memory. The interleave factor, defined as the
distance in bytes between the beginning of two consecutive interleaved blocks
belonging to different planes, is stored in the fixed screen information
type_aux field.

- FB_TYPE_FOURCC

Macropixels are stored in memory as described by the format FOURCC identifier
stored in the variable screen information grayscale field.

Color encoding visual

91-144

`FB_VISUAL_MONO01`은 보통 1 bit인 `bpp`만큼의 bit로 black/white pixel을 저장합니다. 모든 bit가 1이면 black, 모두 0이면 white입니다. 8 bit보다 작으면 여러 pixel을 한 byte에 packing하며 현재 `FB_TYPE_PACKED_PIXELS`와 함께 사용합니다.

`FB_VISUAL_MONO10`은 bit 의미가 반대입니다. 모든 bit가 0이면 black, 모두 1이면 white이며, 8 bit보다 작은 경우 여러 pixel을 byte에 packing합니다. 원문 마지막 문장은 이 항목에서도 `FB_VISUAL_MONO01`이라고 표기하므로 해당 symbol을 그대로 보존합니다.

`FB_VISUAL_TRUECOLOR`는 pixel을 red, green, blue component로 나누고 각 component가 대응 값을 위한 read-only lookup table을 index합니다. Lookup table은 device에 따라 linear 또는 non-linear ramp를 제공합니다. 각 component의 macropixel 내 위치는 `red`, `green`, `blue`, `transp` field가 정합니다.

`FB_VISUAL_PSEUDOCOLOR`와 `FB_VISUAL_STATIC_PSEUDOCOLOR`는 pixel 값을 red, green, blue component를 보관하는 colormap index로 해석합니다. Static variant의 colormap은 read-only이고 일반 pseudocolor는 read-write입니다. Pixel 값의 폭은 `bits_per_pixel`입니다.

`FB_VISUAL_DIRECTCOLOR`는 pixel을 red, green, blue component로 나누고 각 component가 programmable lookup table을 index합니다. Component layout은 `red`, `green`, `blue`, `transp` field를 따릅니다.

`FB_VISUAL_FOURCC`에서는 `grayscale` field의 format FOURCC identifier가 정의하는 방식으로 pixel을 encoding하고 해석합니다.

Visual별 color 해석
VisualPixel 해석Table 또는 polarity
`FB_VISUAL_MONO01`Black/white1=black, 0=white
`FB_VISUAL_MONO10`Black/white0=black, 1=white
`FB_VISUAL_TRUECOLOR`RGB componentDevice-dependent read-only LUT
`FB_VISUAL_PSEUDOCOLOR`Colormap indexRead-write colormap
`FB_VISUAL_STATIC_PSEUDOCOLOR`Colormap indexRead-only colormap
`FB_VISUAL_DIRECTCOLOR`RGB componentProgrammable LUT
`FB_VISUAL_FOURCC`FOURCC format`grayscale`의 identifier

- FB_VISUAL_MONO01

Pixels are black or white and stored on a number of bits (typically one)
specified by the variable screen information bpp field.

Black pixels are represented by all bits set to 1 and white pixels by all bits
set to 0. When the number of bits per pixel is smaller than 8, several pixels
are packed together in a byte.

FB_VISUAL_MONO01 is currently used with FB_TYPE_PACKED_PIXELS only.

- FB_VISUAL_MONO10

Pixels are black or white and stored on a number of bits (typically one)
specified by the variable screen information bpp field.

Black pixels are represented by all bits set to 0 and white pixels by all bits
set to 1. When the number of bits per pixel is smaller than 8, several pixels
are packed together in a byte.

FB_VISUAL_MONO01 is currently used with FB_TYPE_PACKED_PIXELS only.

- FB_VISUAL_TRUECOLOR

Pixels are broken into red, green and blue components, and each component
indexes a read-only lookup table for the corresponding value. Lookup tables
are device-dependent, and provide linear or non-linear ramps.

Each component is stored in a macropixel according to the variable screen
information red, green, blue and transp fields.

- FB_VISUAL_PSEUDOCOLOR and FB_VISUAL_STATIC_PSEUDOCOLOR

Pixel values are encoded as indices into a colormap that stores red, green and
blue components. The colormap is read-only for FB_VISUAL_STATIC_PSEUDOCOLOR
and read-write for FB_VISUAL_PSEUDOCOLOR.

Each pixel value is stored in the number of bits reported by the variable
screen information bits_per_pixel field.

- FB_VISUAL_DIRECTCOLOR

Pixels are broken into red, green and blue components, and each component
indexes a programmable lookup table for the corresponding value.

Each component is stored in a macropixel according to the variable screen
information red, green, blue and transp fields.

- FB_VISUAL_FOURCC

Pixels are encoded and  interpreted as described by the format FOURCC
identifier stored in the variable screen information grayscale field.

Fixed screen information 조회

145-177

Application은 `FBIOGET_FSCREENINFO`와 `FBIOGET_VSCREENINFO` ioctl로 screen information을 조회합니다. 두 ioctl은 각각 `fb_fix_screeninfo`와 `fb_var_screeninfo` structure pointer를 받습니다.

`struct fb_fix_screeninfo`는 frame buffer device와 현재 format에 관한 device-independent 불변 정보를 저장합니다. Application이 직접 바꿀 수는 없지만, application이 format을 변경하면 driver가 이 정보를 갱신할 수 있습니다.

`id`는 식별 문자열, `smem_start`와 `smem_len`은 frame buffer memory의 physical start address와 길이입니다. `type`, `type_aux`, `visual`은 pixel 저장 및 해석 방식을 나타냅니다.

`xpanstep`, `ypanstep`, `ywrapstep`은 hardware panning/wrap step이며 지원하지 않으면 0입니다. `line_length`는 한 line의 byte 길이입니다.

`mmio_start`와 `mmio_len`은 memory-mapped I/O의 physical start address와 길이입니다. `accel`은 특정 chip/card를 driver에 알리고, `capabilities`는 `FB_CAP_*` 기능을 보고하며, `reserved`는 future compatibility를 위해 남겨 둡니다.

fb_fix_screeninfo field group
그룹Field내용
식별·memory`id`, `smem_start`, `smem_len`Device ID와 frame buffer physical memory
Format`type`, `type_aux`, `visual`Macropixel layout과 color 해석
Panning·line`xpanstep`, `ypanstep`, `ywrapstep`, `line_length`이동 단위와 stride
MMIO·hardware`mmio_start`, `mmio_len`, `accel`Register mapping과 chip/card
확장`capabilities`, `reserved`기능 bit와 future compatibility

3. Screen information
---------------------

Screen information are queried by applications using the FBIOGET_FSCREENINFO
and FBIOGET_VSCREENINFO ioctls. Those ioctls take a pointer to a
fb_fix_screeninfo and fb_var_screeninfo structure respectively.

struct fb_fix_screeninfo stores device independent unchangeable information
about the frame buffer device and the current format. Those information can't
be directly modified by applications, but can be changed by the driver when an
application modifies the format::

  struct fb_fix_screeninfo {
        char id[16];                        /* identification string eg "TT Builtin" */
        unsigned long smem_start;        /* Start of frame buffer mem */
                                        /* (physical address) */
        __u32 smem_len;                        /* Length of frame buffer mem */
        __u32 type;                        /* see FB_TYPE_*                */
        __u32 type_aux;                        /* Interleave for interleaved Planes */
        __u32 visual;                        /* see FB_VISUAL_*                */
        __u16 xpanstep;                        /* zero if no hardware panning  */
        __u16 ypanstep;                        /* zero if no hardware panning  */
        __u16 ywrapstep;                /* zero if no hardware ywrap    */
        __u32 line_length;                /* length of a line in bytes    */
        unsigned long mmio_start;        /* Start of Memory Mapped I/O   */
                                        /* (physical address) */
        __u32 mmio_len;                        /* Length of Memory Mapped I/O  */
        __u32 accel;                        /* Indicate to driver which        */
                                        /*  specific chip/card we have        */
        __u16 capabilities;                /* see FB_CAP_*                        */
        __u16 reserved[2];                /* Reserved for future compatibility */
  };

Variable screen information과 변경 절차

178-230

`struct fb_var_screeninfo`는 frame buffer device의 device-independent 가변 정보, 현재 format과 video mode, 기타 parameter를 저장합니다.

`xres`, `yres`는 visible resolution이고 `xres_virtual`, `yres_virtual`은 virtual resolution입니다. `xoffset`, `yoffset`은 virtual 화면에서 visible 화면이 시작하는 위치입니다.

`bits_per_pixel`은 pixel depth입니다. `grayscale`은 0이면 color, 1이면 grayscale, 1보다 크면 FOURCC를 의미합니다. `red`, `green`, `blue`, `transp`는 true color일 때 frame buffer memory의 component bitfield이며, 다른 mode에서는 길이만 중요합니다.

`nonstd`가 0이 아니면 non-standard pixel format이고, `activate`는 `FB_ACTIVATE_*` 동작을 선택합니다. `height`와 `width`는 mm 단위 picture 크기이며 `accel_flags`는 obsolete field입니다.

Timing field 중 `pixclock`은 picosecond 단위 pixel clock이고, margin은 sync와 picture 사이 시간, `hsync_len`과 `vsync_len`은 horizontal/vertical sync 길이입니다. `sync`, `vmode`, `rotate`, `colorspace`는 각각 sync flag, video mode, counter-clockwise rotation angle, FOURCC mode colorspace를 지정합니다.

Variable information을 바꾸려면 `fb_var_screeninfo` pointer로 `FBIOPUT_VSCREENINFO`를 호출합니다. 성공하면 driver가 fixed screen information도 맞게 갱신합니다.

전체 structure를 처음부터 채우기보다는 먼저 `FBIOGET_VSCREENINFO`를 호출하고 application이 필요한 field만 수정해야 합니다.

Variable screen information 변경
Call `FBIOGET_VSCREENINFO`Modify only required `fb_var_screeninfo` fieldsCall `FBIOPUT_VSCREENINFO`Driver validates and applies modeDriver updates fixed screen information

기존 driver 값을 기준으로 필요한 field만 수정해야 호환성을 유지할 수 있습니다.

struct fb_var_screeninfo stores device independent changeable information
about a frame buffer device, its current format and video mode, as well as
other miscellaneous parameters::

  struct fb_var_screeninfo {
        __u32 xres;                        /* visible resolution                */
        __u32 yres;
        __u32 xres_virtual;                /* virtual resolution                */
        __u32 yres_virtual;
        __u32 xoffset;                        /* offset from virtual to visible */
        __u32 yoffset;                        /* resolution                        */

        __u32 bits_per_pixel;                /* guess what                        */
        __u32 grayscale;                /* 0 = color, 1 = grayscale,        */
                                        /* >1 = FOURCC                        */
        struct fb_bitfield red;                /* bitfield in fb mem if true color, */
        struct fb_bitfield green;        /* else only length is significant */
        struct fb_bitfield blue;
        struct fb_bitfield transp;        /* transparency                        */

        __u32 nonstd;                        /* != 0 Non standard pixel format */

        __u32 activate;                        /* see FB_ACTIVATE_*                */

        __u32 height;                        /* height of picture in mm    */
        __u32 width;                        /* width of picture in mm     */

        __u32 accel_flags;                /* (OBSOLETE) see fb_info.flags */

        /* Timing: All values in pixclocks, except pixclock (of course) */
        __u32 pixclock;                        /* pixel clock in ps (pico seconds) */
        __u32 left_margin;                /* time from sync to picture        */
        __u32 right_margin;                /* time from picture to sync        */
        __u32 upper_margin;                /* time from sync to picture        */
        __u32 lower_margin;
        __u32 hsync_len;                /* length of horizontal sync        */
        __u32 vsync_len;                /* length of vertical sync        */
        __u32 sync;                        /* see FB_SYNC_*                */
        __u32 vmode;                        /* see FB_VMODE_*                */
        __u32 rotate;                        /* angle we rotate counter clockwise */
        __u32 colorspace;                /* colorspace for FOURCC-based modes */
        __u32 reserved[4];                /* Reserved for future compatibility */
  };

To modify variable information, applications call the FBIOPUT_VSCREENINFO
ioctl with a pointer to a fb_var_screeninfo structure. If the call is
successful, the driver will update the fixed screen information accordingly.

Instead of filling the complete fb_var_screeninfo structure manually,
applications should call the FBIOGET_VSCREENINFO ioctl and modify only the
fields they care about.

Legacy format 설정 API

231-280

Frame buffer device는 legacy API와 FOURCC 기반 API 두 방식으로 frame buffer format을 설정합니다.

Legacy API는 오랫동안 유일한 format 설정 API였기 때문에 널리 사용됩니다. RGB, grayscale, legacy non-standard format을 쓰는 application에는 이 API가 권장됩니다.

Format을 선택할 때 application은 `fb_var_screeninfo.bits_per_pixel`을 원하는 frame buffer depth로 설정합니다. 8 이하의 값은 보통 monochrome, grayscale 또는 pseudocolor visual에 대응하지만 필수 규칙은 아닙니다.

Grayscale format에서는 `grayscale=1`로 설정하고 application은 `red`, `blue`, `green`, `transp`를 0으로 만들어야 하며 driver는 이를 무시해야 합니다. Driver는 red/blue/green offset을 0으로, length를 `bits_per_pixel` 값으로 채웁니다.

Pseudocolor format에서는 `grayscale=0`으로 설정합니다. Component field에 적용하는 application/driver 규칙과 driver가 반환할 offset 및 length는 grayscale format과 같습니다.

Truecolor와 directcolor에서는 `grayscale=0`으로 두고 `red`, `blue`, `green`, `transp`가 memory의 color component layout을 기술하도록 설정합니다. `struct fb_bitfield`의 `offset`은 bitfield 시작점, `length`는 길이, `msb_right`는 most significant bit가 오른쪽에 있는지를 나타냅니다.

Pixel 값의 폭은 `bits_per_pixel`이며 겹치지 않는 red, green, blue, alpha(transparency) component로 나뉩니다. 각 component의 위치와 크기는 `fb_bitfield.offset`과 `fb_bitfield.length`로 나타내고 offset은 오른쪽부터 계산합니다.

Pixel은 항상 정수 개수의 byte로 저장합니다. Bits per pixel이 8의 배수가 아니면 다음 8-bit 배수까지 padding합니다.

Format 설정이 성공하면 driver는 선택한 format에 맞춰 `fb_fix_screeninfo.type`, `visual`, `line_length`를 갱신합니다.

Legacy format field 규칙
Format`grayscale`Component field 규칙
Grayscale1Application은 0, driver는 offset 0/length bpp 반환
Pseudocolor0Application은 0, driver는 offset 0/length bpp 반환
Truecolor0`fb_bitfield`로 RGB/transparency layout 지정
Directcolor0`fb_bitfield`로 RGB/transparency layout 지정

4. Format configuration
-----------------------

Frame buffer devices offer two ways to configure the frame buffer format: the
legacy API and the FOURCC-based API.


The legacy API has been the only frame buffer format configuration API for a
long time and is thus widely used by application. It is the recommended API
for applications when using RGB and grayscale formats, as well as legacy
non-standard formats.

To select a format, applications set the fb_var_screeninfo bits_per_pixel field
to the desired frame buffer depth. Values up to 8 will usually map to
monochrome, grayscale or pseudocolor visuals, although this is not required.

- For grayscale formats, applications set the grayscale field to one. The red,
  blue, green and transp fields must be set to 0 by applications and ignored by
  drivers. Drivers must fill the red, blue and green offsets to 0 and lengths
  to the bits_per_pixel value.

- For pseudocolor formats, applications set the grayscale field to zero. The
  red, blue, green and transp fields must be set to 0 by applications and
  ignored by drivers. Drivers must fill the red, blue and green offsets to 0
  and lengths to the bits_per_pixel value.

- For truecolor and directcolor formats, applications set the grayscale field
  to zero, and the red, blue, green and transp fields to describe the layout of
  color components in memory::

    struct fb_bitfield {
        __u32 offset;                        /* beginning of bitfield        */
        __u32 length;                        /* length of bitfield                */
        __u32 msb_right;                /* != 0 : Most significant bit is */
                                        /* right */
    };

  Pixel values are bits_per_pixel wide and are split in non-overlapping red,
  green, blue and alpha (transparency) components. Location and size of each
  component in the pixel value are described by the fb_bitfield offset and
  length fields. Offset are computed from the right.

  Pixels are always stored in an integer number of bytes. If the number of
  bits per pixel is not a multiple of 8, pixel values are padded to the next
  multiple of 8 bits.

Upon successful format configuration, drivers update the fb_fix_screeninfo
type, visual and line_length fields depending on the selected format.

FOURCC 기반 format 설정 API

281-307

FOURCC 기반 API는 명시적인 layout 설명을 four character code로 대체합니다. FOURCC는 format을 고유하게 정의하는 추상 identifier이며 YUV format을 지원하는 유일한 API입니다. Driver는 RGB와 grayscale format에도 이 API를 구현하는 것이 권장됩니다.

FOURCC API를 지원하는 driver는 `fb_fix_screeninfo.capabilities`의 `FB_CAP_FOURCC` bit를 설정합니다.

FOURCC 정의는 `linux/videodev2.h`에 있습니다. 이름이 `V4L2_PIX_FMT_` prefix로 시작하더라도 V4L2에 한정되거나 V4L2 subsystem 사용을 요구하지 않습니다. Format 문서는 `Documentation/userspace-api/media/v4l/pixfmt.rst`에 있습니다.

Application은 원하는 FOURCC를 `grayscale` field에 설정해 format을 선택합니다. YUV format에서는 `linux/videodev2.h`에 열거되고 `Documentation/userspace-api/media/v4l/colorspaces.rst`에 문서화된 colorspace 중 하나를 `colorspace` field에 함께 설정해야 합니다.

FOURCC API에서는 `red`, `green`, `blue`, `transp`를 사용하지 않습니다. Forward compatibility를 위해 application은 이 field를 0으로 만들고 driver는 무시해야 합니다. 0이 아닌 값은 향후 extension에서 의미가 생길 수 있습니다.

설정이 성공하면 driver는 format에 맞게 `type`, `visual`, `line_length`를 갱신합니다. 이때 `type`은 `FB_TYPE_FOURCC`, `visual`은 `FB_VISUAL_FOURCC`로 설정합니다.

FOURCC mode 선택
Check `FB_CAP_FOURCC`Choose FOURCC from `linux/videodev2.h`Set `grayscale` to the FOURCCSet YUV `colorspace` when neededZero `red`, `green`, `blue`, `transp`Apply mode and read back `FB_TYPE_FOURCC`/`FB_VISUAL_FOURCC`

Capability 확인부터 fixed screen information 갱신까지의 절차입니다.

The FOURCC-based API replaces format descriptions by four character codes
(FOURCC). FOURCCs are abstract identifiers that uniquely define a format
without explicitly describing it. This is the only API that supports YUV
formats. Drivers are also encouraged to implement the FOURCC-based API for RGB
and grayscale formats.

Drivers that support the FOURCC-based API report this capability by setting
the FB_CAP_FOURCC bit in the fb_fix_screeninfo capabilities field.

FOURCC definitions are located in the linux/videodev2.h header. However, and
despite starting with the V4L2_PIX_FMT_prefix, they are not restricted to V4L2
and don't require usage of the V4L2 subsystem. FOURCC documentation is
available in Documentation/userspace-api/media/v4l/pixfmt.rst.

To select a format, applications set the grayscale field to the desired FOURCC.
For YUV formats, they should also select the appropriate colorspace by setting
the colorspace field to one of the colorspaces listed in linux/videodev2.h and
documented in Documentation/userspace-api/media/v4l/colorspaces.rst.

The red, green, blue and transp fields are not used with the FOURCC-based API.
For forward compatibility reasons applications must zero those fields, and
drivers must ignore them. Values other than 0 may get a meaning in future
extensions.

Upon successful format configuration, drivers update the fb_fix_screeninfo
type, visual and line_length fields depending on the selected format. The type
and visual fields are set to FB_TYPE_FOURCC and FB_VISUAL_FOURCC respectively.