高通Android平台-应用空间操作framebuffer dump LCD总结

xiaoxiao2021-02-28  149

高通Android平台 dump LCD总结

转载请注明出处,谢谢!http://blog.csdn.net/eliot_shao/article/details/74926010

1、问题背景

项目终于到一个比较奇葩的客户,希望可以中断Android系统界面,显示发送过来的图片。

想在高通msm8937平台,720x1280 HD 显示屏上dump点东西,做个实验,搜索HAL,gralloc里面的东西,得到大致的思路。

2、思路整理

打开文件LA.UM.5.6\hardware\qcom\display\libgralloc\framebuffer.cpp 函数:int mapFrameBufferLocked(framebuffer_device_t *dev)

int mapFrameBufferLocked(framebuffer_device_t *dev) { private_module_t* module = reinterpret_cast<private_module_t*>(dev->common.module); fb_context_t *ctx = reinterpret_cast<fb_context_t*>(dev); // already initialized... if (module->framebuffer) { return 0; } char const * const device_template[] = { "/dev/graphics/fb%u", "/dev/fb%u", 0 }; int fd = -1; int i=0; char name[64]; char property[PROPERTY_VALUE_MAX]; while ((fd==-1) && device_template[i]) { snprintf(name, 64, device_template[i], 0); fd = open(name, O_RDWR, 0); i++; } if (fd < 0) return -errno; struct fb_fix_screeninfo finfo; if (ioctl(fd, FBIOGET_FSCREENINFO, &finfo) == -1) { close(fd); return -errno; } struct fb_var_screeninfo info; if (ioctl(fd, FBIOGET_VSCREENINFO, &info) == -1) { close(fd); return -errno; } info.reserved[0] = 0; info.reserved[1] = 0; info.reserved[2] = 0; info.xoffset = 0; info.yoffset = 0; info.activate = FB_ACTIVATE_NOW; /* Interpretation of offset for color fields: All offsets are from the * right, inside a "pixel" value, which is exactly 'bits_per_pixel' wide * (means: you can use the offset as right argument to <<). A pixel * afterwards is a bit stream and is written to video memory as that * unmodified. This implies big-endian byte order if bits_per_pixel is * greater than 8. */ if(info.bits_per_pixel == 32) { /* * Explicitly request RGBA_8888 */ info.bits_per_pixel = 32; info.red.offset = 24; info.red.length = 8; info.green.offset = 16; info.green.length = 8; info.blue.offset = 8; info.blue.length = 8; info.transp.offset = 0; info.transp.length = 8; /* Note: the GL driver does not have a r=8 g=8 b=8 a=0 config, so if we * do not use the MDP for composition (i.e. hw composition == 0), ask * for RGBA instead of RGBX. */ if (property_get("debug.sf.hw", property, NULL) > 0 && atoi(property) == 0) module->fbFormat = HAL_PIXEL_FORMAT_RGBX_8888; else if(property_get("debug.composition.type", property, NULL) > 0 && (strncmp(property, "mdp", 3) == 0)) module->fbFormat = HAL_PIXEL_FORMAT_RGBX_8888; else module->fbFormat = HAL_PIXEL_FORMAT_RGBA_8888; } else { /* * Explicitly request 5/6/5 */ info.bits_per_pixel = 16; info.red.offset = 11; info.red.length = 5; info.green.offset = 5; info.green.length = 6; info.blue.offset = 0; info.blue.length = 5; info.transp.offset = 0; info.transp.length = 0; module->fbFormat = HAL_PIXEL_FORMAT_RGB_565; } //adreno needs 4k aligned offsets. Max hole size is 4096-1 unsigned int size = roundUpToPageSize(info.yres * info.xres * (info.bits_per_pixel/8)); /* * Request NUM_BUFFERS screens (at least 2 for page flipping) */ int numberOfBuffers = (int)(finfo.smem_len/size); ALOGV("num supported framebuffers in kernel = %d", numberOfBuffers); if (property_get("debug.gr.numframebuffers", property, NULL) > 0) { int num = atoi(property); if ((num >= NUM_FRAMEBUFFERS_MIN) && (num <= NUM_FRAMEBUFFERS_MAX)) { numberOfBuffers = num; } } if (numberOfBuffers > NUM_FRAMEBUFFERS_MAX) numberOfBuffers = NUM_FRAMEBUFFERS_MAX; ALOGV("We support %d buffers", numberOfBuffers); //consider the included hole by 4k alignment uint32_t line_length = (info.xres * info.bits_per_pixel / 8); info.yres_virtual = (uint32_t) ((size * numberOfBuffers) / line_length); uint32_t flags = PAGE_FLIP; if (info.yres_virtual < ((size * 2) / line_length) ) { // we need at least 2 for page-flipping info.yres_virtual = (int)(size / line_length); flags &= ~PAGE_FLIP; ALOGW("page flipping not supported (yres_virtual=%d, requested=%d)", info.yres_virtual, info.yres*2); } if (ioctl(fd, FBIOGET_VSCREENINFO, &info) == -1) { close(fd); return -errno; } if (int(info.width) <= 0 || int(info.height) <= 0) { // the driver doesn't return that information // default to 160 dpi info.width = (uint32_t)(((float)(info.xres) * 25.4f)/160.0f + 0.5f); info.height = (uint32_t)(((float)(info.yres) * 25.4f)/160.0f + 0.5f); } float xdpi = ((float)(info.xres) * 25.4f) / (float)info.width; float ydpi = ((float)(info.yres) * 25.4f) / (float)info.height; #ifdef MSMFB_METADATA_GET struct msmfb_metadata metadata; memset(&metadata, 0 , sizeof(metadata)); metadata.op = metadata_op_frame_rate; if (ioctl(fd, MSMFB_METADATA_GET, &metadata) == -1) { ALOGE("Error retrieving panel frame rate"); close(fd); return -errno; } float fps = (float)metadata.data.panel_frame_rate; #else //XXX: Remove reserved field usage on all baselines //The reserved[3] field is used to store FPS by the driver. float fps = info.reserved[3] & 0xFF; #endif ALOGI("using (fd=%d)\n" "id = %s\n" "xres = %d px\n" "yres = %d px\n" "xres_virtual = %d px\n" "yres_virtual = %d px\n" "bpp = %d\n" "r = %2u:%u\n" "g = %2u:%u\n" "b = %2u:%u\n", fd, finfo.id, info.xres, info.yres, info.xres_virtual, info.yres_virtual, info.bits_per_pixel, info.red.offset, info.red.length, info.green.offset, info.green.length, info.blue.offset, info.blue.length ); ALOGI("width = %d mm (%f dpi)\n" "height = %d mm (%f dpi)\n" "refresh rate = %.2f Hz\n", info.width, xdpi, info.height, ydpi, fps ); if (ioctl(fd, FBIOGET_FSCREENINFO, &finfo) == -1) { close(fd); return -errno; } if (finfo.smem_len <= 0) { close(fd); return -errno; } module->flags = flags; module->info = info; module->finfo = finfo; module->xdpi = xdpi; module->ydpi = ydpi; module->fps = fps; module->swapInterval = 1; CALC_INIT(); /* * map the framebuffer */ module->numBuffers = info.yres_virtual / info.yres; module->bufferMask = 0; //adreno needs page aligned offsets. Align the fbsize to pagesize. unsigned int fbSize = roundUpToPageSize(finfo.line_length * info.yres)* module->numBuffers; void* vaddr = mmap(0, fbSize, PROT_READ|PROT_WRITE, MAP_SHARED, fd, 0); if (vaddr == MAP_FAILED) { ALOGE("Error mapping the framebuffer (%s)", strerror(errno)); close(fd); return -errno; } //store the framebuffer fd in the ctx ctx->fbFd = fd; #ifdef MSMFB_METADATA_GET memset(&metadata, 0 , sizeof(metadata)); metadata.op = metadata_op_get_ion_fd; // get the ION fd for the framebuffer, as GPU needs ION fd if (ioctl(fd, MSMFB_METADATA_GET, &metadata) == -1) { ALOGE("Error getting ION fd (%s)", strerror(errno)); close(fd); return -errno; } if(metadata.data.fbmem_ionfd < 0) { ALOGE("Error: Ioctl returned invalid ION fd = %d", metadata.data.fbmem_ionfd); close(fd); return -errno; } fd = metadata.data.fbmem_ionfd; #endif // Create framebuffer handle using the ION fd module->framebuffer = new private_handle_t(fd, fbSize, private_handle_t::PRIV_FLAGS_USES_ION, BUFFER_TYPE_UI, module->fbFormat, info.xres, info.yres); module->framebuffer->base = uint64_t(vaddr); memset(vaddr, 0, fbSize); //Enable vsync int enable = 1; ioctl(ctx->fbFd, MSMFB_OVERLAY_VSYNC_CTRL, &enable); return 0; }

主要操作步骤: fd = open(name, O_RDWR, 0);//打开 ioctl(fd, FBIOGET_FSCREENINFO, &finfo)//获取信息 ioctl(fd, FBIOGET_VSCREENINFO, &info)//获取信息 void* vaddr = mmap(0, fbSize, PROT_READ|PROT_WRITE, MAP_SHARED, fd, 0);//映射framebuffer到用户空间 //把图放在该内存空间 ioctl(fd, MSMFB_METADATA_GET, &metadata)//// get the ION fd for the framebuffer, as GPU needs ION fd  ioctl(ctx->fbFd, MSMFB_OVERLAY_VSYNC_CTRL, &enable);//Enable vsync

到网上找了一个例子,参考网址:http://blog.csdn.net/jiangdou88/article/details/9906053 [ 

framebuffer实验:编写应用程序测试lcd驱动

]

把里面的例子复制出来编译,运行发现并不能出现色块。

可能高通硬件上使用了MDP有关,MDP是一个简单的图形处理器。surfaceflinger会将一些复制的图形处理交给GPU,简单的交给MDP处理,两个硬件处理之后的结果都是放到framebuffer中。

在LA.UM.5.6\vendor\qcom\proprietary\kernel-tests\fbtest 中发现高通一个官方的FB dump LCD的历程。

参照http://blog.csdn.net/eliot_shao/article/details/56669284 [高通Android平台下关于display部分的几个关键问题]中的说法

5. Framebuffer中的数据是如何被送到LCD显示的?

   图中的Gralloc完成的。

Gralloc有2个功能:

1)一个是和copybit相同的,里面有MDP PPP的接口(目前没有使用)

2)另一个则是刷屏(整屏刷)的接口,即将framebuffer中的数据送到lcd上,调用的是MDP DMA的接口

简单的修改了一下fbtest.c,编译运行,它是可以正常测试LCD的。

3、资源整合,成功dump

下面是最终实现的一个小程序,dump两个图案到屏上。并附上效果图。

panel_test.c

#include <unistd.h> #include <stdio.h> #include <fcntl.h> #include <linux/fb.h> #include <sys/mman.h> #include <stdlib.h> #include "yellow_face.zif" int main() { int fbfd = 0; struct fb_var_screeninfo vinfo; struct fb_fix_screeninfo finfo; struct fb_cmap cmapinfo; long int screensize = 0; char *fbp = 0; int x = 0, y = 0; long int location = 0; int b,g,r; // Open the file for reading and writing fbfd = open("/dev/graphics/fb0", O_RDWR,0); // 打开Frame Buffer设备 if (fbfd < 0) { printf("Error: cannot open framebuffer device.%x\n",fbfd); exit(1); } printf("The framebuffer device was opened successfully.\n"); // Get fixed screen information if (ioctl(fbfd, FBIOGET_FSCREENINFO, &finfo)) { // 获取设备固有信息 printf("Error reading fixed information.\n"); exit(2); } printf("\ntype:0x%x\n", finfo.type ); // FrameBuffer 类型,如0为象素 printf("visual:%d\n", finfo.visual ); // 视觉类型:如真彩2,伪彩3 printf("line_length:%d\n", finfo.line_length ); // 每行长度 printf("\nsmem_start:0x%lx,smem_len:%u\n", finfo.smem_start, finfo.smem_len ); // 映象RAM的参数 printf("mmio_start:0x%lx ,mmio_len:%u\n", finfo.mmio_start, finfo.mmio_len ); // Get variable screen information if (ioctl(fbfd, FBIOGET_VSCREENINFO, &vinfo)) { // 获取设备可变信息 printf("Error reading variable information.\n"); exit(3); } printf("%dx%d,
转载请注明原文地址: https://www.6miu.com/read-29452.html

最新回复(0)