pitches

更新时间:2022-12-31 18:08:53 阅读: 评论:0


2022年12月31日发(作者:会议礼仪)

Linuxlibdrm库⼊门教程

DRM相关知识链接

DRM库提供的测试⼯具

modetest⽤法:

1、查看状态信息,输⼊命令:modetest则显⽰如下信息(省略属性信息)

Encoders:

idcrtctypepossiblecrtcspossibleclones

6059DSI0x000000010x00000000

Connectors:

idencoderstatusnamesize(mm)modencoders

6160connectedDSI-168x121160

modes:

namerefresh(Hz)hdisphsshhtotvdispvssvvtot)

720x4000flags:nhsync,nvsync;type:preferred

CRTCs:

idfbpossize

5966(0,0)(720x1280)

720x4000flags:nhsync,nvsync;type:preferred

Planes:

idcrtcfbCRTCx,yx,ygammasizepossiblecrtcs

5859660,00,000x00000001

formats:XR24AR24XB24AB24RG24BG24RG16BG16

Framebuffers:

idsizepitch

上⾯含义是:

1个connectors:id=61,最⼤分辨率为720x1280;

1个crtc:id=59,最⼤分辨率为720x1280;

1个plane:id=58,⽀持像素格式XR24AR24XB24AB24RG24BG24RG16BG16。

⽐如使⽤RG24(对应RGB888,具体可参见drm_fourcc.h)像素格式测试屏幕显⽰:

modetest-s61@59:720x1280@RG24

上述命令执⾏后的显⽰效果如下:

测试⽤例

运⾏命令:mydrmtest

运⾏效果:先显⽰⼀个⽩屏(1s),然后显⽰30帧竖直⿊⽩间隔图像(间隔1s)。如下图所⽰(⼿机翻拍导致不清晰)

代码说明:本⽰例基于RK1808,最⼤分辨率为720x1280,仅有⼀个Connector,⼀个Crtc,⼀个Plane。若针对多Plane平台,则

还需动态适配显⽰模式,图像格式,图层等。

/*

*Author:FrancisFan

*Date:2019-8-21

*/

#include

#include

#include

#include

#include

#include

#include

#include

#include

#include

#include

#include

#include"util/kms.h"

#include"drm_fourcc.h"

#include"buffers.h"

#include"libdrm_macros.h"

staticvoiddebug_save_file(void*ptr,intsize,char*path)

{

FILE*debug_file;

intret=0;

debug_file=fopen(path,"wb");

if(!debug_file){

printf("DEBUG:opendebugfile%sfailed!n",path);

return;

}

ret=fwrite(ptr,1,size,debug_file);

if(ret!=size)

printf("DEBUG:savedebugfile%sfailedn",path);

el

printf("DEBUG:savedebugfileas%sn",path);

fclo(debug_file);

}

/*Fillblackandwhiteverticalstripedata,like:

*White|Black|White|Black

*/

staticvoidfill_frame_rgb24_date(unsignedchar*ptr,intwidth,intheight,intlinesize)

{

unsignedchar*line_ptr=NULL;

unsignedchard_r=0,d_g=0,d_b=0;

if(!ptr||(linesize

printf("ERROR:%sinvalidargs!n",__func__);

return;

}

for(inti=0;i

line_ptr=ptr+i*linesize;

for(intj=0;j

if(j<(width/4)){

d_r=0;d_g=0;d_b=0;

}elif(j<(width/2)){

d_r=255;d_g=255;d_b=255;

}elif(j<(width*3/4)){

d_r=0;d_g=0;d_b=0;

}el{

d_r=255;d_g=255;d_b=255;

}

*line_ptr=d_r;

line_ptr++;

*line_ptr=d_g;

*line_ptr=d_g;

line_ptr++;

*line_ptr=d_b;

line_ptr++;

}

}

}

intmain(intargc,char*argv[])

{

intframe_cnt=30;

intwidth,height;

intret=0;

intdrm_fd=0;

intconnector_id,crtc_id,plane_id;

drmModeRes*res=NULL;

drmModeConnector*conn=NULL;

drmModeCrtc*crtc=NULL;

drmModePlaneRes*pres=NULL;

unsignedintfb_id;

if(argc==3){

width=atoi(argv[1]);

height=atoi(argv[2]);

printf("###InputResolution:%sx%s-->(%d,%d)n",argv[1],argv[2],width,height);

}el{

width=720;

height=1280;

printf("###DefaultResolution:720x1280n");

}

printf("###Initdrm...n");

drm_fd=util_open(NULL,NULL);

if(drm_fd<0){

printf("ERROR:drm_openfailed!n");

return-1;

}

/***********************************************************

*Getscreeninfos

***********************************************************/

if(drmSetClientCap(drm_fd,DRM_CLIENT_CAP_UNIVERSAL_PLANES,1)){

printf("ERROR:drmModeGetCrtcfailed!n");

gotoOUT;

}

res=drmModeGetResources(drm_fd);

if(!res){

printf("ERROR:drmModeGetResourcesfailed!n");

drmClo(drm_fd);

return-1;

}

printf("INFO:count_fbs:%d,count_crtcs:%d,count_encoders:%d,count_connectors:%dn",

res->count_fbs,res->count_crtcs,res->count_encoders,res->count_connectors);

/*Thistestforonly1connectorandonly1crtc*/

connector_id=res->connectors[0];

crtc_id=res->crtcs[0];

/*Justfortprintconnectoronly*/

conn=drmModeGetConnector(drm_fd,connector_id);

if(!conn){

printf("ERROR:drmModeGetConnectorfailed!n");

gotoOUT;

gotoOUT;

}

/*Getplaneinfos*/

pres=drmModeGetPlaneResources(drm_fd);

if(!pres){

printf("ERROR:drmModeGetPlaneResourcesfailed!n");

gotoOUT;

}

/*Thistestforonly1plane*/

plane_id=pres->planes[0];

printf("INFO:connector->name:%s-%un",util_lookup_connector_type_name(conn->connector_type),

conn->connector_type_id);

printf("INFO:connectorid=%d/crtcid=%d/planeid=%dn",

connector_id,crtc_id,plane_id);

/***********************************************************

*StartModeSetting

***********************************************************/

structbo*bo;

drmModeModeInfo*mode;

/*Maxplanes:4

*handles:dumbbufferhandle,createbylibdrmapi

*pitches:reallinesize,byBytes.

*offt:everyplaneofft.

*/

unsignedinthandles[4]={0};

unsignedintpitches[4]={0};

unsignedintoffts[4]={0};

uint64_tcap=0;

/*Supportdumbbuffer?*/

ret=drmGetCap(drm_fd,DRM_CAP_DUMB_BUFFER,&cap);

if(ret||cap==0){

fprintf(stderr,"ERROR:driverdoesn'tsupportthedumbbufferAPIn");

gotoOUT;

}

/*Createdumbbufferandmmapit*/

bo=bo_create(drm_fd,DRM_FORMAT_RGB888,width,height,handles,pitches,offts,UTIL_PATTERN_SMPTE);

if(bo==NULL){

printf("ERROR:bo_createfailed!n");

gotoOUT;

}

for(inti=0;i<4;i++)

printf("INFO:#%dhandles:%d,pitches:%d,offts:%dn",i,handles[i],pitches[i],offts[i]);

/*Filldate:fullscreeniswhite*/

memt(bo->ptr,255,height*pitches[0]);

/*Getframebuffid,thisidisudbydrmapitofindthebuffer.

*Formatthedisplaymemory,thenthedrmapiknowswhatformatto

*displaythememoryofthedrmapplication.

*/

ret=drmModeAddFB2(drm_fd,width,height,DRM_FORMAT_RGB888,handles,pitches,offts,&fb_id,0);

if(ret){

printf("ERROR:drmModeAddFB2failed!n");

gotoOUT;

}

/*stest,only1modesupport.*/

mode=&conn->modes[0];

printf("INFO:mode->mame:%s,%dx%d,Conn_id:%d,crtc_id:%dn",

mode->name,mode->hdisplay,mode->vdisplay,connector_id,crtc_id);

ret=drmModeSetCrtc(drm_fd,crtc_id,fb_id,0,0,(uint32_t*)&connector_id,1,mode);

if(ret){

printf("ERROR:drmModeSetCrtcfailed!n");

gotoOUT;

}

/*XXX:Actuallycheckifthisisneeded*/

drmModeDirtyFB(drm_fd,fb_id,NULL,0);

/*showmodetingeffect:fullscreenwhite*/

sleep(1);

/***********************************************************

*StartSetplane:showframetoplane

***********************************************************/

while(frame_cnt--){

fill_frame_rgb24_date(bo->ptr,width,height,pitches[0]);

//debug_save_file(bo->ptr,pitches[0]*height);

/*notesrccoords(last4args)areinQ16format*/

if(drmModeSetPlane(drm_fd,plane_id,crtc_id,fb_id,

0,0,0,width,height,0,0,width<<16,height<<16)){

printf("ERROR:drmModeSetPlanefailed!plane_id:%d,fb_id:%dn",plane_id,fb_id);

return-1;

}

sleep(1);

}

OUT:

if(bo){

if(bo->ptr)

drm_munmap(bo->ptr,bo->size);

bo->ptr=NULL;

bo_destroy(bo);

}

if(pres)

drmModeFreePlaneResources(pres);

if(conn)

drmModeFreeConnector(conn);

if(res)

drmModeFreeResources(res);

if(drm_fd)

drmClo(drm_fd);

return0;

}

本文发布于:2022-12-31 18:08:53,感谢您对本站的认可!

本文链接:http://www.wtabcd.cn/fanwen/fan/90/67001.html

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。

上一篇:pp2
下一篇:underlying
标签:pitches
相关文章
留言与评论(共有 0 条评论)
   
验证码:
Copyright ©2019-2022 Comsenz Inc.Powered by © 专利检索| 网站地图