요약·해설과 원문, 전문 번역을 서로 분리했습니다. API 이름, symbol, source path는 원문 표기를 사용합니다.
1. 요약·해설
원문의 핵심 논리와 kernel programming 관점의 보충 설명입니다. 아래의 전문 번역과는 별도로 작성했습니다.
2. 영어 원문 전체
번역 기준이 된 Linux v6.18.37 원문입니다. 줄 번호는 이 버전의 파일 좌표입니다.
원문 전체 펼치기
===========================
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.
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.
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.
- 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.
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 */
};
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.
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.
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.
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 동작에도 대응할 수 있어야 합니다.
이 문서가 다루는 범위와 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-42Device와 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을 구성합니다.
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-90Pixel은 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에 배치합니다.
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하고 해석합니다.
- 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-177Application은 `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를 위해 남겨 둡니다.
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만 수정해야 합니다.
기존 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-280Frame 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`를 갱신합니다.
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-307FOURCC 기반 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`로 설정합니다.
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.
요약·해설
api.rst:1-307Frame 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를 사용합니다.