RK3368 Recovery界面旋转方向调试
Platform: RK3368
OS: Android 6.0
Kernel: 3.10.0
文章目录
- RK3368 Recovery界面旋转方向调试
-
- 1. 打开recovery串口打印调试
- 2. 修改代码
- 3. 编译
1. 打开recovery串口打印调试
修改bootable/recovery/Android.mk文件,将日志打印重定向到串口,方便调试.
@@ -60,7 +60,7 @@ LOCAL_CFLAGS += -D_FILE_OFFSET_BITS=64
#SDCARD: save log to sdcard
#CACHE: save log to /cache/recovery/ dir
#UART: redirect log to uart output
-REDIRECT_LOG_TO := CACHE
+REDIRECT_LOG_TO := UART
LOCAL_C_INCLUDES := \
$(prebuilt_stdcxx_PATH)/gnu-libstdc++/include\
2. 修改代码
旋转UI代码参考了:Android O恢复出厂设置时,图标和屏的方向不一致;
修改当前设备的BoardConfig.mk,定义需要旋转的角度:
BOARD_RECOVERY_UI_ROTATION := 270
修改bootable/recovery/minui/Android.mk,添加以下代码:
+ifeq ($(strip $(BOARD_RECOVERY_UI_ROTATION)), 0)
+ LOCAL_CFLAGS += -DBOARD_RECOVERY_UI_ROTATION_0
+else
+ifeq ($(strip $(BOARD_RECOVERY_UI_ROTATION)), 90)
+ LOCAL_CFLAGS += -DBOARD_RECOVERY_UI_ROTATION_90
+else
+ifeq ($(strip $(BOARD_RECOVERY_UI_ROTATION)), 180)
+ LOCAL_CFLAGS += -DBOARD_RECOVERY_UI_ROTATION_180
+else
+ifeq ($(strip $(BOARD_RECOVERY_UI_ROTATION)), 270)
+ LOCAL_CFLAGS += -DBOARD_RECOVERY_UI_ROTATION_270
+else
+ LOCAL_CFLAGS += -DBOARD_RECOVERY_UI_ROTATION_0
+endif
+endif
+endif
+endif
+
bootable/recovery/minui/graphics_fbdev.cpp添加旋转方向代码:
static GRSurface *gr_rotate_draw = NULL;
#define swap(a, b) \
do \
{ \
typeof(a) __tmp = (a); \
(a) = (b); \
(b) = __tmp; \
} while (0)
static GRSurface *rotate_surface_init(GRSurface *surface)
{
static GRSurface *rotateSurface = (GRSurface *)malloc(sizeof(GRSurface));
if (rotateSurface == NULL)
{
return NULL;
}
memcpy(rotateSurface, surface, sizeof(GRSurface));
#if defined(BOARD_RECOVERY_UI_ROTATION_90) || defined(BOARD_RECOVERY_UI_ROTATION_270)
swap(rotateSurface->width, rotateSurface->height);
rotateSurface->row_bytes = rotateSurface->width * rotateSurface->pixel_bytes;
#endif
rotateSurface->data = (unsigned char *)malloc(rotateSurface->height * rotateSurface->row_bytes);
if (rotateSurface->data == NULL)
{
free(rotateSurface);
return NULL;
}
memset(rotateSurface->data, 0, rotateSurface->height * rotateSurface->row_bytes);
return rotateSurface;
}
static void rotate_surface_exit(GRSurface *surface)
{
if (surface)
{
if (surface->data)
free(surface->data);
free(surface);
}
surface = NULL;
}
static void rotate_surface_0(GRSurface *dst, GRSurface *src)
{
memcpy(dst->data, src->data, src->height * src->row_bytes);
}
static void rotate_surface_270(GRSurface *dst, GRSurface *src)
{
int v, w, h;
unsigned int *src_pixel;
unsigned int *dst_pixel;
for (h = 0, v = src->width - 1; h < dst->height; h++, v--)
{
for (w = 0; w < dst->width; w++)
{
dst_pixel = (unsigned int *)(dst->data + dst->row_bytes * h);
src_pixel = (unsigned int *)(src->data + src->row_bytes * w);
*(dst_pixel + w) = *(src_pixel + v);
}
}
}
static void rotate_surface_180(GRSurface *dst, GRSurface *src)
{
int v, w, k, h;
unsigned int *src_pixel;
unsigned int *dst_pixel;
for (h = 0, k = src->height - 1; h < dst->height && k >= 0; h++, k--)
{
dst_pixel = (unsigned int *)(dst->data + dst->row_bytes * h);
src_pixel = (unsigned int *)(src->data + src->row_bytes * k);
for (w = 0, v = src->width - 1; w < dst->width && v >= 0; w++, v--)
{
*(dst_pixel + w) = *(src_pixel + v);
}
}
}
static void rotate_surface_90(GRSurface *dst, GRSurface *src)
{
int w, k, h;
unsigned int *src_pixel;
unsigned int *dst_pixel;
for (h = 0; h < dst->height; h++)
{
for (w = 0, k = src->height - 1; w < dst->width; w++, k--)
{
dst_pixel = (unsigned int *)(dst->data + dst->row_bytes * h);
src_pixel = (unsigned int *)(src->data + src->row_bytes * k);
*(dst_pixel + w) = *(src_pixel + h);
}
}
}
修改open_fbdev, fbdev_flip, fbdev_exit:
minui_backend* open_fbdev() {
return &my_backend;
@@ -220,7 +298,9 @@ static GRSurface* fbdev_init(minui_backend* backend) {
fbdev_blank(backend, true);
fbdev_blank(backend, false);
- return gr_draw;
+ //return gr_draw;
+ gr_rotate_draw = rotate_surface_init(gr_draw);
+ return gr_rotate_draw;
}
static GRSurface* fbdev_flip(minui_backend* backend __unused) {
@@ -237,26 +317,46 @@ static GRSurface* fbdev_flip(minui_backend* backend __unused) {
ucfb_vaddr[idx + 2] = tmp;
}
#endif
+
+#ifdef BOARD_RECOVERY_UI_ROTATION_0
+ rotate_surface_0(gr_draw, gr_rotate_draw);
+#else
+#ifdef BOARD_RECOVERY_UI_ROTATION_90
+ rotate_surface_90(gr_draw, gr_rotate_draw);
+#else
+#ifdef BOARD_RECOVERY_UI_ROTATION_180
+ rotate_surface_180(gr_draw, gr_rotate_draw);
+#else
+#ifdef BOARD_RECOVERY_UI_ROTATION_270
+ rotate_surface_270(gr_draw, gr_rotate_draw);
+#else
+ rotate_surface_0(gr_draw, gr_rotate_draw);
+#endif
+#endif
+#endif
+#endif
+
// Change gr_draw to point to the buffer currently displayed,
// then flip the driver so we're displaying the other buffer
// instead.
gr_draw = gr_framebuffer + displayed_buffer;
-#ifdef BOARD_HAS_FLIPPED_SCREEN
- rk_rotate_surface_180( &gr_framebuffer[1-displayed_buffer]);
-#endif
+
set_displayed_framebuffer(1-displayed_buffer);
} else {
// Copy from the in-memory surface to the framebuffer.
memcpy(gr_framebuffer[0].data, gr_draw->data,
gr_draw->height * gr_draw->row_bytes);
}
- return gr_draw;
+ //return gr_draw;
+ return gr_rotate_draw;
}
static void fbdev_exit(minui_backend* backend __unused) {
close(fb_fd);
fb_fd = -1;
+ rotate_surface_exit(gr_rotate_draw);
+
if (!double_buffered && gr_draw) {
free(gr_draw->data);
free(gr_draw);
3. 编译
执行以下命令,可以单独编译recovery,但是需要重新刷入recovery.img进行测试验证.
$ source build/envsetup.sh
$ touch bootable/recovery/minui/*
$ make recoveryimage -j8