当前位置:网站首页>[Wayland] Wayland introduction and customized guidance

[Wayland] Wayland introduction and customized guidance

2022-06-12 10:09:00 Lindo

Wayland And Weston brief introduction

  • For some reason . Porting and customizing a set based on Wayland Of Compositor.
  • Wayland And Weston, It's two complementary concepts . Here is a brief summary :
  1. wayland It's a set for “ Show ” Agreement for services , be based on C/S structure . It customizes a set of standard interfaces 、 Basic communication mode .
  2. wayland It provides the realization of communication mode (socket+epoll), And provides “ Interface ” Description language of , And tools to convert the language into code (scanner)
  3. Weston Is based on Wayland agreement , And implemented Compositor Functional , An official set of Wayland compositor Realization ( Can be understood as based on wayland Agreed compositor
  • Some concepts on the Internet are vague . In short ,wayland Customized a set of protocols , This protocol implements a set of “ Display server ”.Weston Namely wayland Official , This set of display server Reference implementation .

Architecture diagram

 Insert picture description here

wayland

  • Wayland Provides Protocol How to define .Wayland In the source code of protocol Under the folder , Defined Wayland The core agreement of .
  • Such as wl_display: Used to get display Global object .
<interface name="wl_display" version="1">
    <description summary="core global object">
      The core global object.  This is a special singleton object.  It
      is used for internal Wayland protocol features.
    </description>
    .....
</interface>
  • be based on wayland Of Compositor Realization , At least to achieve wayland Stipulated core agreement . Specific core agreements , To participate in wayland Official website (https://wayland.freedesktop.org/docs/html/ch04.html#sect-Protocol-Interfaces)
  • wayland Source code , Except for the agreement . The remaining main contents , Is to achieve an efficient Server+Client Communication mode .
  • Server End , Mainly used epoll+socket monitor Client End event , And deserialize the received message .
// epoll
int
wl_os_epoll_create_cloexec(void)
{
    
	int fd;

#ifdef EPOLL_CLOEXEC
	fd = epoll_create1(EPOLL_CLOEXEC);
	if (fd >= 0)
		return fd;
	if (errno != EINVAL)
		return -1;
#endif

	fd = epoll_create(1);
	return set_cloexec_or_close(fd);
}

// socket
int
wl_os_socket_cloexec(int domain, int type, int protocol)
{
    
	int fd;

	fd = socket(domain, type | SOCK_CLOEXEC, protocol);
	if (fd >= 0)
		return fd;
	if (errno != EINVAL)
		return -1;

	fd = socket(domain, type, protocol);
	return set_cloexec_or_close(fd);
}
  • Client End :wayland-client Provides the implemented serialization interface . Specific communications 、 Serialization implementation is not described in detail here .
WL_EXPORT void
wl_proxy_marshal(struct wl_proxy *proxy, uint32_t opcode, ...)
{
    
	union wl_argument args[WL_CLOSURE_MAX_ARGS];
	va_list ap;

	va_start(ap, opcode);
	wl_argument_from_va_list(proxy->object.interface->methods[opcode].signature,
				 args, WL_CLOSURE_MAX_ARGS, ap);
	va_end(ap);

	wl_proxy_marshal_array_constructor(proxy, opcode, args, NULL);
}
  • summary : Official Wayland Source code , It mainly includes the definition of the agreement 、 Protocol to code generation tool , And a set of well implemented communication model .

Weston

  • Weston Is based on wayland agreement , Realized Compositor.
  • Weston The entrance of is in ( Here we use 2.0.0 For example ): weston2.0.0./compositor/main.c
int main(int argc, char *argv[])
{
    
	//  Create a global Display, And finally call to wl_os_epoll_create_cloexec
	display = wl_display_create();
	//  establish Compositor
	ec = weston_compositor_create(display, &user_data);
	//  establish Shell
	if (wet_load_shell(ec, shell, &argc, argv) < 0)
		goto out;
	// while loop 
	wl_display_run(display);
}
  • Weston There are four main parts in :Shell、Compositor、Render、Input.
  1. Shell: Window manager , Picture level 、 Window information 、 Window life cycle 、Focus Windows, and so on, tend to be handled in the business layer . default shell by desktop-shell, Other shell Realization ( Such as ivi-shell)
  2. Compositor: Responsible for the composition of the picture , Use DRM Connect output, Output the screen to the actual display device .
  3. Render: Responsible for rendering , such as gl-render, Do some texture mapping .
  4. Input:libinput modular , And evdev、uvdev Module interaction , Receive... From the underlying device node touch、key Equal input .

Migration and customization

At present, many systems in China adopt Wayland As a display server , Transplantation and customization generally have the following aspects :

  1. Compile and migrate : Compile and migrate based on the compiler adopted by the project .
  2. System docking and native debugging : Mode native code , In fact, it is the original Sample Run .
  3. Shell customized 、 Protocol extension : According to business needs , Choose one Shell, And then customize on the basis of it Shell, Extend native protocols .
  4. Optimize : Display performance 、Input performance 、 Log optimization 、Debug Tool development, etc .
原网站

版权声明
本文为[Lindo]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/03/202203010528238951.html