drm test



//Open
fd = drmOpen("imx-drm", NULL);

//Get resources
resources = drmModeGetResources(fd);
crtc_id = resources->crtcs[0];
connector_id = resources->connectors[0];

//Get modes
connector = drmModeGetConnector(fd, connector_id);
mode = connector->modes[0];
width = mode.hdisplay;
height = mode.vdisplay;

//Create buffer
struct drm_mode_create_dumb bo_create;
memset(&bo_create, 0, sizeof(bo_create));
bo_create.bpp = 32;
bo_create.width = width;
bo_create.height = height;
drmIoctl(fd, DRM_IOCTL_MODE_CREATE_DUMB, &bo_create);

//Fill buffer
struct drm_mode_map_dumb bo_map;
memset(&bo_map, 0, sizeof(bo_map));
bo_map.handle = bo_create.handle;
drmIoctl(fd, DRM_IOCTL_MODE_MAP_DUMB, &bo_map);

void *mem;
mem = mmap(0, bo_create.size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, bo_map.offset);
fill_pattern(DRM_FORMAT_ARGB8888, mem, width, height, bo_create.pitch);
munmap(mem, bo_create.size);

//Create frame buffer
uint32_t handles[4] = { bo_create.handle, };
uint32_t pitches[4] = { bo_create.pitch, };
uint32_t offsets[4] = { 0, };
uint32_t fb_id;
drmModeAddFB2(fd, width, height, DRM_FORMAT_ARGB8888, handles, pitches, offsets, &fb_id, 0);

//Set the mode
drmModeSetCrtc(fd, crtc_id, fb_id, 0, 0, &connector_id, 1, &mode);

//Get plane resources
drmModePlaneResPtr planes;
uint32_t plane_id;
planes = drmModeGetPlaneResources(fd);
plane_id = planes->planes[0];

//Set the plane
drmModeSetPlane(fd, plane_id, crtc_id, fb_id, 0, width / 4, height / 4, width / 2, height / 2, 0, 0, (width / 2) << 16, (height / 2) << 16);


//List plane properties
drmModeObjectPropertiesPtr properties;
properties = drmModeObjectGetProperties(fd, plane_id, DRM_MODE_OBJECT_PLANE);

//Find alpha property
drmModePropertyPtr property;
unsigned int i;
for (i = 0; i < properties->count_props; ++i) {
	property = drmModeGetProperty(fd, properties->props[i]);
	if (!strcmp(property->name, "alpha"))
		break;
}

//Turn global transparency on
drmModeObjectSetProperty(fd, plane_id, DRM_MODE_OBJECT_PLANE, property->prop_id, 128);

API:https://docs.nvidia.com/drive/nvvib_docs/NVIDIA%20DRIVE%20Linux%20SDK%20Development%20Guide/baggage/group__direct__rendering__manager.html#ga3f9326af9fc8eddc23dc6e263a2160a1

猜你喜欢

转载自blog.csdn.net/melody157398/article/details/82622452