Toybrick

楼主: jefferyzhang

RK3399Pro入门教程(5)图形加速引擎RGA的使用

 

lily393

注册会员

积分
56
发表于 2020-11-26 16:31:33 | 显示全部楼层
jefferyzhang 发表于 2020-11-25 16:54
使用DMA内存的话,这速度不正常;
如果使用的是虚拟内存的话,那很正常。 ...

用的是这个
        src = wrapbuffer_virtualaddr(yuv_buf, SRC_WIDTH, SRC_HEIGHT, SRC_FORMAT);
        dst = wrapbuffer_virtualaddr(rgb_buf, DST_WIDTH, DST_HEIGHT, DST_FORMAT);

用dma内存的话我应该是调这个?
        src = wrapbuffer_fd(fd1, SRC_WIDTH, SRC_HEIGHT, SRC_FORMAT);
        dst = wrapbuffer_fd(fd2, DST_WIDTH, DST_HEIGHT, DST_FORMAT);
回复

使用道具 举报

seanx

中级会员

积分
349
发表于 2020-11-27 10:00:04 | 显示全部楼层
本帖最后由 seanx 于 2020-11-27 10:01 编辑

请问一下:
1. 如果送入 RGA 的图像是通过 imread 等方式获取的,无法确保宽高 16 对齐,这种情况要怎么处理?难道要先用 CPU 搬一遍吗?(这种情况报错“ioctl: RGA_BLIT_SYNC failed, return -1”)
2. 确认一下 16 对齐是对输入输出均有此要求吗,还是只要求输入即可?如果要求输出,那如何得到没有填充的输出?经测试,如果输入宽高是 16 对齐的,那么输出宽高似乎可以不用对齐(直接设置为 1920x1080 可以得到正确输出)
回复

使用道具 举报

jefferyzhang

版主

积分
13606
 楼主| 发表于 2020-11-27 22:41:16 | 显示全部楼层
seanx 发表于 2020-11-27 10:00
请问一下:
1. 如果送入 RGA 的图像是通过 imread 等方式获取的,无法确保宽高 16 对齐,这种情况要怎么处 ...

目前版本RGA不需要16对齐,mpp是需要对齐的
回复

使用道具 举报

xiayip

注册会员

积分
57
发表于 2020-11-30 23:26:36 | 显示全部楼层
你好, 请问会考虑利用RGA做图像去畸变吗, 谢谢
回复

使用道具 举报

xyyangkun

注册会员

积分
109
发表于 2021-3-16 09:50:14 | 显示全部楼层
你好,我想使用rga模块做两个视频的合成叠加,就是把一个视频叠加到另外一个视频中,视频是yuv422,如果视频最大是1080P60,rga模块是否可以达到每秒60帧的性能?
回复

使用道具 举报

jefferyzhang

版主

积分
13606
 楼主| 发表于 2021-3-16 10:06:43 | 显示全部楼层
xyyangkun 发表于 2021-3-16 09:50
你好,我想使用rga模块做两个视频的合成叠加,就是把一个视频叠加到另外一个视频中,视频是yuv422,如果视频 ...

理论上能
回复

使用道具 举报

xinzhiling111

中级会员

积分
403
发表于 2021-5-24 18:33:46 | 显示全部楼层
rga进行图像缩放的时候,宽度和高度必须同时都是放大或者缩小吗?是否可以宽度缩小,高度放大?实际测试中发现,1280*720图像转618*458的时候正常,但是1280*720图像转1246*924的时候图片部分花掉了,刚好是下面部分,以左上角为原点的话,像是超过720的部分花掉了。
回复

使用道具 举报

jefferyzhang

版主

积分
13606
 楼主| 发表于 2021-5-25 08:39:32 | 显示全部楼层
xinzhiling111 发表于 2021-5-24 18:33
rga进行图像缩放的时候,宽度和高度必须同时都是放大或者缩小吗?是否可以宽度缩小,高度放大?实际测试中 ...

可以。我暂时没遇到过这种问题。你用的是哪一套的rga封装?请用github rockchip-linux上那个最新的封装试下。
回复

使用道具 举报

miaozhihua

新手上路

积分
16
发表于 2021-6-29 21:17:09 | 显示全部楼层
各位大佬,我在github上下载最新代码,平台为3399+linux。我在sample中的rgaImdemo.cpp的基础上修改为通过drm申请mmap的fd方式,现在demo可以测试完成,速度比之前用malloc的也快了很多。但是demo跑完后系统桌面显示有些地方会出现花屏(花屏的现象是桌面某些地方会显示另外地方的内容,系统其他功能都正常,感觉是fb内容被破坏了),下面是我封装的创建drm mmap句柄的函数和执行到wrapbuffer_fd()函数调用为止的部分代码,帮忙看一下是否哪里有问题,十分感谢!
  1. <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;">
  2. <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>
  3. <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>
  4. <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>
复制代码


回复

使用道具 举报

miaozhihua

新手上路

积分
16
发表于 2021-6-29 21:21:40 | 显示全部楼层
上面帖子贴出来的代码网页显示异常,下面再贴一份:

int createDrmMap(int drm_fd, int bpp, int width, int height, struct fdmmap_s *map)
{
struct drm_mode_create_dumb arg;
struct drm_mode_map_dumb map_arg;
int ret;
memset(&arg, 0, sizeof(arg));
arg.bpp = bpp;
arg.width = width;
arg.height = height;
printf("bpp=%d, width=%d, height=%d\n", arg.bpp, arg.width, arg.height);
ret = drmIoctl(drm_fd, DRM_IOCTL_MODE_CREATE_DUMB, &arg);
if (ret) {
perror("failed to create dumb buffer");
return ret;
}
map->handle = arg.handle;
map->size = arg.size;
map->pitch = arg.pitch;
printf("bpp=%d, width=%d, height=%d, size=%d, pitch=%d\n", arg.bpp, arg.width, arg.height, arg.size, arg.pitch);

memset(&map_arg, 0, sizeof(map_arg));
map_arg.handle = map->handle;
ret = drmIoctl(drm_fd, DRM_IOCTL_MODE_MAP_DUMB, &map_arg);
if (ret)
return ret;
map->buf = (char *)mmap(0, map->size, PROT_READ | PROT_WRITE, MAP_SHARED, drm_fd, map_arg.offset);
if (map->buf == MAP_FAILED)
return -1;
drmPrimeHandleToFD(drm_fd, map->handle, 0, &map->fd);
printf("drm_fd=%d, map->fd=%d\n", drm_fd, map->fd);
return 0;
}
int main(int argc, char argv[])
{
        int drm_fd, ret;
    drm_fd = open("/dev/dri/card0", O_RDWR, 0);
    if( drm_fd <=0)
    {
        perror("open dri card0");
        return -1;
    }
if( createDrmMap(drm_fd, get_bpp_from_format(SRC_FORMAT), SRC_WIDTH, SRC_HEIGHT, &map_src)<0)
{
     printf("createDrmMap map_src error\n");
     return -1;
}
printf("map_src.size=%d\n", map_src.size);
if( createDrmMap(drm_fd, get_bpp_from_format(DST_FORMAT), DST_WIDTH, DST_HEIGHT, &map_dst)<0)
{
     printf("createDrmMap map_dst error\n");
     return -2;
}
printf("createDrmMap map_src/map_dst ok\n");

        ret = get_buf_from_file(map_src.buf, SRC_FORMAT, SRC_WIDTH, SRC_HEIGHT, 0);
        if (!ret)
            printf("open src file ok\n");
        else
            printf ("can not open file\n");
        if(MODE == MODE_BLEND || MODE == MODE_FILL) {
            ret = get_buf_from_file(map_dst.buf, DST_FORMAT, DST_WIDTH, DST_HEIGHT, 1);
            if (!ret)
                printf("open dst file\n");
            else
                printf ("can not open file\n");
        } else {
    printf("map_dst.size=%d, get_bpp_from_format(DST_FORMAT)=%d\n", map_dst.size, get_bpp_from_format(DST_FORMAT));
        memset(map_dst.buf,0x00,map_dst.size);
    //        memset(map_dst.buf,0x00,DST_WIDTH*DST_HEIGHT*get_bpp_from_format(DST_FORMAT));
        }
        printf("get_buf_from_file ok\n");
        src = wrapbuffer_fd(map_src.fd, SRC_WIDTH, SRC_HEIGHT, SRC_FORMAT);
        dst = wrapbuffer_fd(map_dst.fd, DST_WIDTH, DST_HEIGHT, DST_FORMAT);
                ......
}
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

产品中心 购买渠道 开源社区 Wiki教程 资料下载 关于Toybrick


快速回复 返回顶部 返回列表