Full analysis of libdrm thirty-seven - full analysis of source code (34)

Continued from the previous article: Full analysis of libdrm thirty-six -- full analysis of source code (33)

This article refers to the following blog posts:

DRM driver development (VKMS)

Thank you very much!

This article begins to analyze the Userspace API drmModeSetCrtc() corresponding to DRM_IOCTL_MODE_SETCRTC. Post the source code of this function again, in xf86drmMode.c, as follows:

drm_public int drmModeSetCrtc(int fd, uint32_t crtcId, uint32_t bufferId,
		   uint32_t x, uint32_t y, uint32_t *connectors, int count,
		   drmModeModeInfoPtr mode)
{
	struct drm_mode_crtc crtc;

	memclear(crtc);
	crtc.x             = x;
	crtc.y             = y;
	crtc.crtc_id       = crtcId;
	crtc.fb_id         = bufferId;
	crtc.set_connectors_ptr = VOID2U64(connectors);
	crtc.count_connectors = count;
	if (mode) {
	  memcpy(&crtc.mode, mode, sizeof(struct drm_mode_modeinfo));
	  crtc.mode_valid = 1;
	}

	return DRM_IOCTL(fd, DRM_IOCTL_MODE_SETCRTC, &crtc);
}

The core structure struct drm_mode_crtc is defined in include/libdrm/drm_mode.h, as follows:

struct drm_mode_crtc {
	__u64 set_connectors_ptr;
	__u32 count_connectors;

	__u32 crtc_id; /**< Id */
	__u32 fb_id; /**< Id of framebuffer */

	__u32 x; /**< x Position on the framebuffer */
	__u32 y; /**< y Position on the framebuffer */

	__u32 gamma_size;
	__u32 mode_valid;
	struct drm_mode_modeinfo mode;
};

The code sample snippet called in actual use is as follows:

drmModeSetCrtc(fd, crtc_id, buf[0].fb_id,	
			0, 0, &conn_id, 1, &connector->modes[0]);	//初始化和设置crtc,对应显存立即刷新

Parameters of the drmModeSetCrtc function: fd is the file descriptor corresponding to the graphics card device; crtcId is the id of the crtc obtained when calling the drmModeGetResources function; bufferId is the id of the framebuffer obtained when calling the drmModeAddFB function; x and y correspond to the horizontal and vertical coordinates in the framebuffer respectively , connectors here is the id of the connector obtained when calling the drmModeGetResources function; count is the number of connectors, and 1 is passed in here, which means that there is 1 connector; mode is a member of the connector obtained by the drmModeGetConnector function, which represents the display mode .

The drmModeModeInfo structure is defined in xf86drmMode.h, the code is as follows:

typedef struct _drmModeModeInfo {
	uint32_t clock;
	uint16_t hdisplay, hsync_start, hsync_end, htotal, hskew;
	uint16_t vdisplay, vsync_start, vsync_end, vtotal, vscan;

	uint32_t vrefresh;

	uint32_t flags;
	uint32_t type;
	char name[DRM_DISPLAY_MODE_LEN];
} drmModeModeInfo, *drmModeModeInfoPtr;

The type of mode is drmModeModeInfoPtr, and the type of crtc.mode is struct drm_mode_modeinfo. Can crtc.mode be assigned a value through mode? Here again post the source code of struct drm_mode_modeinfo in include/libdrm/drm_mode.h, as follows:

/**
 * struct drm_mode_modeinfo - Display mode information.
 * @clock: pixel clock in kHz
 * @hdisplay: horizontal display size
 * @hsync_start: horizontal sync start
 * @hsync_end: horizontal sync end
 * @htotal: horizontal total size
 * @hskew: horizontal skew
 * @vdisplay: vertical display size
 * @vsync_start: vertical sync start
 * @vsync_end: vertical sync end
 * @vtotal: vertical total size
 * @vscan: vertical scan
 * @vrefresh: approximate vertical refresh rate in Hz
 * @flags: bitmask of misc. flags, see DRM_MODE_FLAG_* defines
 * @type: bitmask of type flags, see DRM_MODE_TYPE_* defines
 * @name: string describing the mode resolution
 *
 * This is the user-space API display mode information structure. For the
 * kernel version see struct drm_display_mode.
 */
struct drm_mode_modeinfo {
	__u32 clock;
	__u16 hdisplay;
	__u16 hsync_start;
	__u16 hsync_end;
	__u16 htotal;
	__u16 hskew;
	__u16 vdisplay;
	__u16 vsync_start;
	__u16 vsync_end;
	__u16 vtotal;
	__u16 vscan;

	__u32 vrefresh;

	__u32 flags;
	__u32 type;
	char name[DRM_DISPLAY_MODE_LEN];
};

It can be seen that there is a one-to-one relationship between the drmModeModeInfoPtr structure and the struct drm_mode_modeinfo structure, so they can be assigned.

According to the above analysis, the role of the drmModeSetCrtc function is to use the previous information to initialize the entire hardware pipeline (pipeline) and display the image.

So far, the drmModeSetCrtc function has been explained.

Guess you like

Origin blog.csdn.net/phmatthaus/article/details/132583505