|
各位大佬,我在github上下载最新代码,平台为3399+linux。我在sample中的rgaImdemo.cpp的基础上修改为通过drm申请mmap的fd方式,现在demo可以测试完成,速度比之前用malloc的也快了很多。但是demo跑完后系统桌面显示有些地方会出现花屏(花屏的现象是桌面某些地方会显示另外地方的内容,系统其他功能都正常,感觉是fb内容被破坏了),下面是我封装的创建drm mmap句柄的函数和执行到wrapbuffer_fd()函数调用为止的部分代码,帮忙看一下是否哪里有问题,十分感谢!
- <div style="color: #d4d4d4;background-color: #1e1e1e;font-family: 'Droid Sans Mono', 'monospace', monospace, 'Droid Sans Fallback';font-weight: normal;font-size: 18px;line-height: 24px;white-space: pre;">
- <div><span style="color: #569cd6;">int</span><span style="color: #d4d4d4;"> </span><span style="color: #dcdcaa;">createDrmMap</span><span style="color: #d4d4d4;">(</span><span style="color: #569cd6;">int</span><span style="color: #d4d4d4;"> </span><span style="color: #9cdcfe;">drm_fd</span><span style="color: #d4d4d4;">, </span><span style="color: #569cd6;">int</span><span style="color: #d4d4d4;"> </span><span style="color: #9cdcfe;">bpp</span><span style="color: #d4d4d4;">, </span><span style="color: #569cd6;">int</span><span style="color: #d4d4d4;"> </span><span style="color: #9cdcfe;">width</span><span style="color: #d4d4d4;">, </span><span style="color: #569cd6;">int</span><span style="color: #d4d4d4;"> </span><span style="color: #9cdcfe;">height</span><span style="color: #d4d4d4;">, </span><span style="color: #569cd6;">struct</span><span style="color: #d4d4d4;"> </span><span style="color: #4ec9b0;">fdmmap_s</span><span style="color: #d4d4d4;"> </span><span style="color: #569cd6;">*</span><span style="color: #9cdcfe;">map</span><span style="color: #d4d4d4;">)</span></div><div><span style="color: #d4d4d4;">{</span></div><div><span style="color: #569cd6;">struct</span><span style="color: #d4d4d4;"> </span><span style="color: #4ec9b0;">drm_mode_create_dumb</span><span style="color: #d4d4d4;"> </span><span style="color: #9cdcfe;">arg</span><span style="color: #d4d4d4;">;</span></div><div><span style="color: #569cd6;">struct</span><span style="color: #d4d4d4;"> </span><span style="color: #4ec9b0;">drm_mode_map_dumb</span><span style="color: #d4d4d4;"> </span><span style="color: #9cdcfe;">map_arg</span><span style="color: #d4d4d4;">;</span></div><div><span style="color: #569cd6;">int</span><span style="color: #d4d4d4;"> ret;</span></div><div><span style="color: #dcdcaa;">memset</span><span style="color: #d4d4d4;">(&arg, </span><span style="color: #b5cea8;">0</span><span style="color: #d4d4d4;">, </span><span style="color: #569cd6;">sizeof</span><span style="color: #d4d4d4;">(arg));</span></div><div><span style="color: #9cdcfe;">arg</span><span style="color: #d4d4d4;">.</span><span style="color: #9cdcfe;">bpp</span><span style="color: #d4d4d4;"> = bpp;</span></div><div><span style="color: #9cdcfe;">arg</span><span style="color: #d4d4d4;">.</span><span style="color: #9cdcfe;">width</span><span style="color: #d4d4d4;"> = width;</span></div><div><span style="color: #9cdcfe;">arg</span><span style="color: #d4d4d4;">.</span><span style="color: #9cdcfe;">height</span><span style="color: #d4d4d4;"> = height;</span></div><div><span style="color: #dcdcaa;">printf</span><span style="color: #d4d4d4;">(</span><span style="color: #ce9178;">"bpp=%d, width=%d, height=%d</span><span style="color: #d7ba7d;">\n</span><span style="color: #ce9178;">"</span><span style="color: #d4d4d4;">, </span><span style="color: #9cdcfe;">arg</span><span style="color: #d4d4d4;">.</span><span style="color: #9cdcfe;">bpp</span><span style="color: #d4d4d4;">, </span><span style="color: #9cdcfe;">arg</span><span style="color: #d4d4d4;">.</span><span style="color: #9cdcfe;">width</span><span style="color: #d4d4d4;">, </span><span style="color: #9cdcfe;">arg</span><span style="color: #d4d4d4;">.</span><span style="color: #9cdcfe;">height</span><span style="color: #d4d4d4;">);</span></div><div><span style="color: #d4d4d4;">ret = </span><span style="color: #dcdcaa;">drmIoctl</span><span style="color: #d4d4d4;">(drm_fd, DRM_IOCTL_MODE_CREATE_DUMB, &arg);</span></div><div><span style="color: #c586c0;">if</span><span style="color: #d4d4d4;"> (ret) {</span></div><div><span style="color: #dcdcaa;">perror</span><span style="color: #d4d4d4;">(</span><span style="color: #ce9178;">"failed to create dumb buffer"</span><span style="color: #d4d4d4;">);</span></div><div><span style="color: #c586c0;">return</span><span style="color: #d4d4d4;"> ret;</span></div><div><span style="color: #d4d4d4;">}</span></div><div><span style="color: #9cdcfe;">map</span><span style="color: #d4d4d4;">-></span><span style="color: #9cdcfe;">handle</span><span style="color: #d4d4d4;"> = </span><span style="color: #9cdcfe;">arg</span><span style="color: #d4d4d4;">.</span><span style="color: #9cdcfe;">handle</span><span style="color: #d4d4d4;">;</span></div><div><span style="color: #9cdcfe;">map</span><span style="color: #d4d4d4;">-></span><span style="color: #9cdcfe;">size</span><span style="color: #d4d4d4;"> = </span><span style="color: #9cdcfe;">arg</span><span style="color: #d4d4d4;">.</span><span style="color: #9cdcfe;">size</span><span style="color: #d4d4d4;">;</span></div><div><span style="color: #9cdcfe;">map</span><span style="color: #d4d4d4;">-></span><span style="color: #9cdcfe;">pitch</span><span style="color: #d4d4d4;"> = </span><span style="color: #9cdcfe;">arg</span><span style="color: #d4d4d4;">.</span><span style="color: #9cdcfe;">pitch</span><span style="color: #d4d4d4;">;</span></div><div><span style="color: #dcdcaa;">printf</span><span style="color: #d4d4d4;">(</span><span style="color: #ce9178;">"bpp=%d, width=%d, height=%d, size=%d, pitch=%d</span><span style="color: #d7ba7d;">\n</span><span style="color: #ce9178;">"</span><span style="color: #d4d4d4;">, </span><span style="color: #9cdcfe;">arg</span><span style="color: #d4d4d4;">.</span><span style="color: #9cdcfe;">bpp</span><span style="color: #d4d4d4;">, </span><span style="color: #9cdcfe;">arg</span><span style="color: #d4d4d4;">.</span><span style="color: #9cdcfe;">width</span><span style="color: #d4d4d4;">, </span><span style="color: #9cdcfe;">arg</span><span style="color: #d4d4d4;">.</span><span style="color: #9cdcfe;">height</span><span style="color: #d4d4d4;">, </span><span style="color: #9cdcfe;">arg</span><span style="color: #d4d4d4;">.</span><span style="color: #9cdcfe;">size</span><span style="color: #d4d4d4;">, </span><span style="color: #9cdcfe;">arg</span><span style="color: #d4d4d4;">.</span><span style="color: #9cdcfe;">pitch</span><span style="color: #d4d4d4;">);</span></div>
- <div><span style="color: #dcdcaa;">memset</span><span style="color: #d4d4d4;">(&map_arg, </span><span style="color: #b5cea8;">0</span><span style="color: #d4d4d4;">, </span><span style="color: #569cd6;">sizeof</span><span style="color: #d4d4d4;">(map_arg));</span></div><div><span style="color: #9cdcfe;">map_arg</span><span style="color: #d4d4d4;">.</span><span style="color: #9cdcfe;">handle</span><span style="color: #d4d4d4;"> = </span><span style="color: #9cdcfe;">map</span><span style="color: #d4d4d4;">-></span><span style="color: #9cdcfe;">handle</span><span style="color: #d4d4d4;">;</span></div><div><span style="color: #d4d4d4;">ret = </span><span style="color: #dcdcaa;">drmIoctl</span><span style="color: #d4d4d4;">(drm_fd, DRM_IOCTL_MODE_MAP_DUMB, &map_arg);</span></div><div><span style="color: #c586c0;">if</span><span style="color: #d4d4d4;"> (ret)</span></div><div><span style="color: #c586c0;">return</span><span style="color: #d4d4d4;"> ret;</span></div><div><span style="color: #9cdcfe;">map</span><span style="color: #d4d4d4;">-></span><span style="color: #9cdcfe;">buf</span><span style="color: #d4d4d4;"> = (</span><span style="color: #569cd6;">char</span><span style="color: #d4d4d4;"> *)</span><span style="color: #dcdcaa;">mmap</span><span style="color: #d4d4d4;">(</span><span style="color: #b5cea8;">0</span><span style="color: #d4d4d4;">, </span><span style="color: #9cdcfe;">map</span><span style="color: #d4d4d4;">-></span><span style="color: #9cdcfe;">size</span><span style="color: #d4d4d4;">, PROT_READ | PROT_WRITE, MAP_SHARED, drm_fd, </span><span style="color: #9cdcfe;">map_arg</span><span style="color: #d4d4d4;">.</span><span style="color: #9cdcfe;">offset</span><span style="color: #d4d4d4;">);</span></div><div><span style="color: #c586c0;">if</span><span style="color: #d4d4d4;"> (</span><span style="color: #9cdcfe;">map</span><span style="color: #d4d4d4;">-></span><span style="color: #9cdcfe;">buf</span><span style="color: #d4d4d4;"> == MAP_FAILED)</span></div><div><span style="color: #c586c0;">return</span><span style="color: #d4d4d4;"> -</span><span style="color: #b5cea8;">1</span><span style="color: #d4d4d4;">;</span></div><div><span style="color: #dcdcaa;">drmPrimeHandleToFD</span><span style="color: #d4d4d4;">(drm_fd, </span><span style="color: #9cdcfe;">map</span><span style="color: #d4d4d4;">-></span><span style="color: #9cdcfe;">handle</span><span style="color: #d4d4d4;">, </span><span style="color: #b5cea8;">0</span><span style="color: #d4d4d4;">, &</span><span style="color: #9cdcfe;">map</span><span style="color: #d4d4d4;">-></span><span style="color: #9cdcfe;">fd</span><span style="color: #d4d4d4;">);</span></div><div><span style="color: #dcdcaa;">printf</span><span style="color: #d4d4d4;">(</span><span style="color: #ce9178;">"drm_fd=%d, map->fd=%d</span><span style="color: #d7ba7d;">\n</span><span style="color: #ce9178;">"</span><span style="color: #d4d4d4;">, drm_fd, </span><span style="color: #9cdcfe;">map</span><span style="color: #d4d4d4;">-></span><span style="color: #9cdcfe;">fd</span><span style="color: #d4d4d4;">);</span></div><div><span style="color: #c586c0;">return</span><span style="color: #d4d4d4;"> </span><span style="color: #b5cea8;">0</span><span style="color: #d4d4d4;">;</span></div><div><span style="color: #d4d4d4;">}</span></div><div><span style="color: #569cd6;">int</span><span style="color: #d4d4d4;"> </span><span style="color: #dcdcaa;">main</span><span style="color: #d4d4d4;">(</span><span style="color: #569cd6;">int</span><span style="color: #d4d4d4;"> </span><span style="color: #9cdcfe;">argc</span><span style="color: #d4d4d4;">, </span><span style="color: #569cd6;">char</span><span style="color: #d4d4d4;"> </span><span style="color: #9cdcfe;">argv</span><span style="color: #d4d4d4;">[])</span></div><div><span style="color: #d4d4d4;">{</span></div><div><span style="color: #d4d4d4;"> </span><span style="color: #569cd6;">int</span><span style="color: #d4d4d4;"> drm_fd, ret;</span></div><div><span style="color: #d4d4d4;"> drm_fd = </span><span style="color: #dcdcaa;">open</span><span style="color: #d4d4d4;">(</span><span style="color: #ce9178;">"/dev/dri/card0"</span><span style="color: #d4d4d4;">, O_RDWR, </span><span style="color: #b5cea8;">0</span><span style="color: #d4d4d4;">);</span></div><div><span style="color: #d4d4d4;"> </span><span style="color: #c586c0;">if</span><span style="color: #d4d4d4;">( drm_fd <=</span><span style="color: #b5cea8;">0</span><span style="color: #d4d4d4;">)</span></div><div><span style="color: #d4d4d4;"> {</span></div><div><span style="color: #d4d4d4;"> </span><span style="color: #dcdcaa;">perror</span><span style="color: #d4d4d4;">(</span><span style="color: #ce9178;">"open dri card0"</span><span style="color: #d4d4d4;">);</span></div><div><span style="color: #d4d4d4;"> </span><span style="color: #c586c0;">return</span><span style="color: #d4d4d4;"> -</span><span style="color: #b5cea8;">1</span><span style="color: #d4d4d4;">;</span></div><div><span style="color: #d4d4d4;"> }</span></div><div><span style="color: #d4d4d4;"> </span><span style="color: #c586c0;">if</span><span style="color: #d4d4d4;">( </span><span style="color: #dcdcaa;">createDrmMap</span><span style="color: #d4d4d4;">(drm_fd, </span><span style="color: #dcdcaa;">get_bpp_from_format</span><span style="color: #d4d4d4;">(SRC_FORMAT), SRC_WIDTH, SRC_HEIGHT, &map_src)<</span><span style="color: #b5cea8;">0</span><span style="color: #d4d4d4;">)</span></div><div><span style="color: #d4d4d4;"> {</span></div><div><span style="color: #d4d4d4;"> </span><span style="color: #dcdcaa;">printf</span><span style="color: #d4d4d4;">(</span><span style="color: #ce9178;">"createDrmMap map_src error</span><span style="color: #d7ba7d;">\n</span><span style="color: #ce9178;">"</span><span style="color: #d4d4d4;">);</span></div><div><span style="color: #d4d4d4;"> </span><span style="color: #c586c0;">return</span><span style="color: #d4d4d4;"> -</span><span style="color: #b5cea8;">1</span><span style="color: #d4d4d4;">;</span></div><div><span style="color: #d4d4d4;"> }</span></div><div><span style="color: #d4d4d4;"> </span><span style="color: #dcdcaa;">printf</span><span style="color: #d4d4d4;">(</span><span style="color: #ce9178;">"map_src.size=%d</span><span style="color: #d7ba7d;">\n</span><span style="color: #ce9178;">"</span><span style="color: #d4d4d4;">, </span><span style="color: #9cdcfe;">map_src</span><span style="color: #d4d4d4;">.</span><span style="color: #9cdcfe;">size</span><span style="color: #d4d4d4;">);</span></div><div><span style="color: #d4d4d4;"> </span><span style="color: #c586c0;">if</span><span style="color: #d4d4d4;">( </span><span style="color: #dcdcaa;">createDrmMap</span><span style="color: #d4d4d4;">(drm_fd, </span><span style="color: #dcdcaa;">get_bpp_from_format</span><span style="color: #d4d4d4;">(DST_FORMAT), DST_WIDTH, DST_HEIGHT, &map_dst)<</span><span style="color: #b5cea8;">0</span><span style="color: #d4d4d4;">)</span></div><div><span style="color: #d4d4d4;"> {</span></div><div><span style="color: #d4d4d4;"> </span><span style="color: #dcdcaa;">printf</span><span style="color: #d4d4d4;">(</span><span style="color: #ce9178;">"createDrmMap map_dst error</span><span style="color: #d7ba7d;">\n</span><span style="color: #ce9178;">"</span><span style="color: #d4d4d4;">);</span></div><div><span style="color: #d4d4d4;"> </span><span style="color: #c586c0;">return</span><span style="color: #d4d4d4;"> -</span><span style="color: #b5cea8;">2</span><span style="color: #d4d4d4;">;</span></div><div><span style="color: #d4d4d4;"> }</span></div><div><span style="color: #dcdcaa;">printf</span><span style="color: #d4d4d4;">(</span><span style="color: #ce9178;">"createDrmMap map_src/map_dst ok</span><span style="color: #d7ba7d;">\n</span><span style="color: #ce9178;">"</span><span style="color: #d4d4d4;">);</span></div>
- <div><span style="color: #d4d4d4;"> ret = </span><span style="color: #dcdcaa;">get_buf_from_file</span><span style="color: #d4d4d4;">(</span><span style="color: #9cdcfe;">map_src</span><span style="color: #d4d4d4;">.</span><span style="color: #9cdcfe;">buf</span><span style="color: #d4d4d4;">, SRC_FORMAT, SRC_WIDTH, SRC_HEIGHT, </span><span style="color: #b5cea8;">0</span><span style="color: #d4d4d4;">);</span></div><div><span style="color: #d4d4d4;"> </span><span style="color: #c586c0;">if</span><span style="color: #d4d4d4;"> (!ret)</span></div><div><span style="color: #d4d4d4;"> </span><span style="color: #dcdcaa;">printf</span><span style="color: #d4d4d4;">(</span><span style="color: #ce9178;">"open src file ok</span><span style="color: #d7ba7d;">\n</span><span style="color: #ce9178;">"</span><span style="color: #d4d4d4;">);</span></div><div><span style="color: #d4d4d4;"> </span><span style="color: #c586c0;">else</span></div><div><span style="color: #d4d4d4;"> </span><span style="color: #dcdcaa;">printf</span><span style="color: #d4d4d4;"> (</span><span style="color: #ce9178;">"can not open file</span><span style="color: #d7ba7d;">\n</span><span style="color: #ce9178;">"</span><span style="color: #d4d4d4;">);</span></div><div><span style="color: #d4d4d4;"> </span><span style="color: #c586c0;">if</span><span style="color: #d4d4d4;">(MODE == MODE_BLEND || MODE == MODE_FILL) {</span></div><div><span style="color: #d4d4d4;"> ret = </span><span style="color: #dcdcaa;">get_buf_from_file</span><span style="color: #d4d4d4;">(</span><span style="color: #9cdcfe;">map_dst</span><span style="color: #d4d4d4;">.</span><span style="color: #9cdcfe;">buf</span><span style="color: #d4d4d4;">, DST_FORMAT, DST_WIDTH, DST_HEIGHT, </span><span style="color: #b5cea8;">1</span><span style="color: #d4d4d4;">);</span></div><div><span style="color: #d4d4d4;"> </span><span style="color: #c586c0;">if</span><span style="color: #d4d4d4;"> (!ret)</span></div><div><span style="color: #d4d4d4;"> </span><span style="color: #dcdcaa;">printf</span><span style="color: #d4d4d4;">(</span><span style="color: #ce9178;">"open dst file</span><span style="color: #d7ba7d;">\n</span><span style="color: #ce9178;">"</span><span style="color: #d4d4d4;">);</span></div><div><span style="color: #d4d4d4;"> </span><span style="color: #c586c0;">else</span></div><div><span style="color: #d4d4d4;"> </span><span style="color: #dcdcaa;">printf</span><span style="color: #d4d4d4;"> (</span><span style="color: #ce9178;">"can not open file</span><span style="color: #d7ba7d;">\n</span><span style="color: #ce9178;">"</span><span style="color: #d4d4d4;">);</span></div><div><span style="color: #d4d4d4;"> } </span><span style="color: #c586c0;">else</span><span style="color: #d4d4d4;"> {</span></div><div><span style="color: #d4d4d4;"> </span><span style="color: #dcdcaa;">printf</span><span style="color: #d4d4d4;">(</span><span style="color: #ce9178;">"map_dst.size=%d, get_bpp_from_format(DST_FORMAT)=%d</span><span style="color: #d7ba7d;">\n</span><span style="color: #ce9178;">"</span><span style="color: #d4d4d4;">, </span><span style="color: #9cdcfe;">map_dst</span><span style="color: #d4d4d4;">.</span><span style="color: #9cdcfe;">size</span><span style="color: #d4d4d4;">, </span><span style="color: #dcdcaa;">get_bpp_from_format</span><span style="color: #d4d4d4;">(DST_FORMAT));</span></div><div><span style="color: #d4d4d4;"> </span><span style="color: #dcdcaa;">memset</span><span style="color: #d4d4d4;">(</span><span style="color: #9cdcfe;">map_dst</span><span style="color: #d4d4d4;">.</span><span style="color: #9cdcfe;">buf</span><span style="color: #d4d4d4;">,</span><span style="color: #b5cea8;">0x00</span><span style="color: #d4d4d4;">,</span><span style="color: #9cdcfe;">map_dst</span><span style="color: #d4d4d4;">.</span><span style="color: #9cdcfe;">size</span><span style="color: #d4d4d4;">);</span></div><div><span style="color: #6a9955;"> // memset(map_dst.buf,0x00,DST_WIDTH*DST_HEIGHT*get_bpp_from_format(DST_FORMAT));</span></div><div><span style="color: #d4d4d4;"> }</span></div><div><span style="color: #d4d4d4;"> </span><span style="color: #dcdcaa;">printf</span><span style="color: #d4d4d4;">(</span><span style="color: #ce9178;">"get_buf_from_file ok</span><span style="color: #d7ba7d;">\n</span><span style="color: #ce9178;">"</span><span style="color: #d4d4d4;">);</span></div><div><span style="color: #d4d4d4;"> src = </span><span style="color: #dcdcaa;">wrapbuffer_fd</span><span style="color: #d4d4d4;">(</span><span style="color: #9cdcfe;">map_src</span><span style="color: #d4d4d4;">.</span><span style="color: #9cdcfe;">fd</span><span style="color: #d4d4d4;">, SRC_WIDTH, SRC_HEIGHT, SRC_FORMAT);</span></div><div><span style="color: #d4d4d4;"> dst = </span><span style="color: #dcdcaa;">wrapbuffer_fd</span><span style="color: #d4d4d4;">(</span><span style="color: #9cdcfe;">map_dst</span><span style="color: #d4d4d4;">.</span><span style="color: #9cdcfe;">fd</span><span style="color: #d4d4d4;">, DST_WIDTH, DST_HEIGHT, DST_FORMAT);</span></div><div><span style="color: #d4d4d4;"> ......</span></div><div><span style="color: #d4d4d4;">}</span></div></div>
|
|