Android recovery 模式下屏幕显示旋转
大家在网上搜索 Android屏幕旋转,成千上万的文章,但是没有几个是写recovery 模式的。难道你们只旋转正常模式下的屏幕方向,不管recovery模式,那升级的画面岂不是有问题。
很对人使用的是MTK平台,对与MTK平台,MTK已经帮你做好了,你只用修改一下配置就行了。
MTK平台我们可以在bootable/recovery/minui/mt_graphic_rotate.cpp 清晰的看到下面的代码:
#ifndef MTK_LCM_PHYSICAL_ROTATION
#define MTK_LCM_PHYSICAL_ROTATION "undefined"
#endif
static int rotate_config(GRSurface *gr_draw)
{
if (rotate_index<0)
{
if (gr_draw->pixel_bytes != 4) rotate_index=0; // support 4 bytes pixel only
else if (0 == strncmp(MTK_LCM_PHYSICAL_ROTATION, "90", 2)) rotate_index=1;
else if (0 == strncmp(MTK_LCM_PHYSICAL_ROTATION, "180", 3)) rotate_index=2;
else if (0 == strncmp(MTK_LCM_PHYSICAL_ROTATION, "270", 3)) rotate_index=3;
else rotate_index=0;
printf("[graphics] rotate_config %d %s\n", rotate_index, MTK_LCM_PHYSICAL_ROTATION);
}
return rotate_index;
}
已经很清楚了,只需要修改 MTK_LCM_PHYSICAL_ROTATION 这个宏就可以了。这是MTK已经改造过的recovery 。
那么其他一些平台 并没有想MTK平台这样,帮你改造好了。比如RK平台,我在RK的代码里只发现了,一个旋转180度的配置,那我要旋转270度怎么办。那就需要自己去看代码了。
recovery 模式 是直接操作 dev目录下的 fb ,如果对这种操作不熟悉的同学需要去补课,可能会看不懂我接下来说的。
在 bootable/recovery/minui/graphics_fbdev.c 我们可以看到下面的代码。
static gr_surface fbdev_init(minui_backend* backend) {
int fd;
void *bits;
int tmp = 0;
struct fb_fix_screeninfo fi;
fd = open("/dev/graphics/fb0", O_RDWR);
if (fd < 0) {
perror("cannot open fb0");
return NULL;
}
if (ioctl(fd, FBIOGET_FSCREENINFO, &fi) < 0) {
perror("failed to get fb0 info");
close(fd);
return NULL;
}
if (ioctl(fd, FBIOGET_VSCREENINFO, &vi) < 0) {
perror("failed to get fb0 info");
close(fd);
return NULL;
}
vi.red.offset = 0;
vi.red.length = 8;
vi.green.offset = 8;
vi.green.length = 8;
vi.blue.offset = 16;
vi.blue.length = 8;
vi.transp.offset = 24;
vi.transp.length = 8;
vi.bits_per_pixel = 32;
vi.nonstd = 2;
bits = mmap(0, fi.smem_len, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
if (bits == MAP_FAILED) {
perror("failed to mmap framebuffer");
close(fd);
return NULL;
}
memset(bits, 0, fi.smem_len);
gr_framebuffer[0].width = vi.xres;
gr_framebuffer[0].height = vi.yres;
gr_framebuffer[0].row_bytes = vi.xres * 4;
gr_framebuffer[0].pixel_bytes = vi.bits_per_pixel / 8;
gr_framebuffer[0].data = bits;
memset(gr_framebuffer[0].data, 0, gr_framebuffer[0].height * gr_framebuffer[0].row_bytes);
}
先过年,春节后再续