From: dyamy-lee Date: Mon, 2 Nov 2020 06:27:29 +0000 (+0900) Subject: fota_gui_common : add rotation logic with using pixman - roate angle is fixed 0 X-Git-Tag: submit/tizen_6.0/20210611.044034~21 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=bb8f10c559948da5775c16fadb515dad06c1822d;p=profile%2Fcommon%2Fapps%2Fnative%2Ffirmware-update-system-ui.git fota_gui_common : add rotation logic with using pixman - roate angle is fixed 0 Change-Id: Ie971c8a18956bcbb33c87c6eb67dec8367c38fb3 --- diff --git a/fota_gui_common/CMakeLists.txt b/fota_gui_common/CMakeLists.txt index ed5c3ea..7587c0b 100644 --- a/fota_gui_common/CMakeLists.txt +++ b/fota_gui_common/CMakeLists.txt @@ -23,6 +23,7 @@ MESSAGE("Build type: ${CMAKE_BUILD_TYPE}") INCLUDE(FindPkgConfig) pkg_check_modules(gui_pkgs REQUIRED + pixman-1 libtbm libtdm libpng diff --git a/fota_gui_common/fota_gr_direct_ro_common.c b/fota_gui_common/fota_gr_direct_ro_common.c index 6ce3560..b96a5df 100644 --- a/fota_gui_common/fota_gr_direct_ro_common.c +++ b/fota_gui_common/fota_gr_direct_ro_common.c @@ -23,6 +23,7 @@ #include #include #include +#include #include "fota_gui_general.h" #include "fota_png.h" @@ -55,6 +56,8 @@ const int x_offset_main_bg_text_pos = 518; const int y_offset_main_bg_text_pos = 300; const int x_offset_prog_bar_img_pos = 240; const int y_offset_prog_bar_img_pos = 355; +int rotate_angle = 0; +int rollback_rotate_angle = 0; FbInfo s_fbi; tdm_if_disp s_disp; @@ -153,7 +156,7 @@ void fb_clear_screen(FbInfo *fbi, unsigned int color) /*----------------------------------------------------------------------------- _gr_direct_fill_rect ----------------------------------------------------------------------------*/ -static void _gr_direct_fill_rect(FbInfo *fbi, s32 x, s32 y, s32 w, s32 h, u32 color) +static void _gr_direct_fill_rect(tbm_surface_info_s *surface_info, s32 x, s32 y, s32 w, s32 h, u32 color) { unsigned int *fb_buf_int = NULL; unsigned int *fb_buf_cur = NULL; @@ -161,26 +164,26 @@ static void _gr_direct_fill_rect(FbInfo *fbi, s32 x, s32 y, s32 w, s32 h, u32 co s32 dy = 0; s32 wb = 0; - if (NULL == fbi) + if (NULL == surface_info) return; dx = w; dy = h; wb = w * sizeof(u32); - fb_buf_int = (unsigned int *)fbi->buf[FRONT_BUFFER]; - fb_buf_int += y * fbi->w + x; + fb_buf_int = (unsigned int *)surface_info->planes[0].ptr; + fb_buf_int += y * surface_info->width + x; fb_buf_cur = fb_buf_int; while (dx--) *fb_buf_cur++ = color; fb_buf_cur -= w; - fb_buf_cur += fbi->w; + fb_buf_cur += surface_info->width; dy--; while (dy--) { memcpy((void*)fb_buf_cur, (void*)fb_buf_int, wb); - fb_buf_cur += fbi->w; + fb_buf_cur += surface_info->width; } } @@ -216,10 +219,38 @@ static void _gr_direct_clear_screen(FbInfo *fbi, u32 color) } } +static void _gr_direct_clear_screen_init(tbm_surface_info_s *surface_info, u32 color) +{ + unsigned int *fb_buf_int = NULL; + unsigned int *fb_buf_cur = NULL; + s32 dx = 0; + s32 dy = 0; + s32 w = 0; + + if (NULL == surface_info) + return; + + dx = surface_info->width; + dy = surface_info->height; + w = surface_info->width * sizeof(u32); + + fb_buf_int = (unsigned int *)surface_info->planes[0].ptr; + fb_buf_cur = fb_buf_int; + + while (dx--) + *fb_buf_cur++ = color; + + dy--; + while (dy--) { + memcpy((void*)fb_buf_cur, (void*)fb_buf_int, w); + fb_buf_cur += surface_info->width; + } +} + /*----------------------------------------------------------------------------- _gr_direct_draw_text ----------------------------------------------------------------------------*/ -static void _gr_direct_draw_text(FbInfo *fbi, int percent) +static void _gr_direct_draw_text(tbm_surface_info_s *surface_info, int percent) { char img_name[MAX_PATH]; int img_x; @@ -241,7 +272,8 @@ static void _gr_direct_draw_text(FbInfo *fbi, int percent) if (read_png_file(img_name) < 0) return; - draw_png_img_xy(fbi, img_x, img_y); + //draw_png_img_xy(fbi, img_x, img_y); + draw_png_img_original(surface_info->planes[0].ptr, img_x, img_y, surface_info->width, surface_info->height, surface_info->planes[0].stride); release_png_res(); } @@ -255,7 +287,8 @@ static void _gr_direct_draw_text(FbInfo *fbi, int percent) if (read_png_file(img_name) < 0) return; - draw_png_img_xy(fbi, img_x, img_y); + //draw_png_img_xy(fbi, img_x, img_y); + draw_png_img_original(surface_info->planes[0].ptr, img_x, img_y, surface_info->width, surface_info->height, surface_info->planes[0].stride); release_png_res(); } @@ -266,7 +299,8 @@ static void _gr_direct_draw_text(FbInfo *fbi, int percent) if (read_png_file(img_name) < 0) return; - draw_png_img_xy(fbi, img_x, img_y); + //draw_png_img_xy(fbi, img_x, img_y); + draw_png_img_original(surface_info->planes[0].ptr, img_x, img_y, surface_info->width, surface_info->height, surface_info->planes[0].stride); release_png_res(); img_x += 13; @@ -275,14 +309,15 @@ static void _gr_direct_draw_text(FbInfo *fbi, int percent) if (read_png_file(img_name) < 0) return; - draw_png_img_xy(fbi, img_x, img_y); + //draw_png_img_xy(fbi, img_x, img_y); + draw_png_img_original(surface_info->planes[0].ptr, img_x, img_y, surface_info->width, surface_info->height, surface_info->planes[0].stride); release_png_res(); } /*----------------------------------------------------------------------------- _gr_direct_draw_prog_text ----------------------------------------------------------------------------*/ -static void _gr_direct_draw_prog_text(FbInfo *fbi, int percent) +static void _gr_direct_draw_prog_text(tbm_surface_info_s *surface_info, int percent) { if (percent <= 0) percent = 0; @@ -290,11 +325,11 @@ static void _gr_direct_draw_prog_text(FbInfo *fbi, int percent) if (percent > 100) percent = 100; - _gr_direct_fill_rect(fbi, 610, 395, 65, 41, COLOR_BLACK); - _gr_direct_draw_text(fbi, percent); + _gr_direct_fill_rect(surface_info, 610, 395, 65, 41, COLOR_BLACK); + _gr_direct_draw_text(surface_info, percent); } -static void _gr_direct_draw_main_prog_img(FbInfo *fbi, int percent) +static void _gr_direct_draw_main_prog_img(tbm_surface_info_s *surface_info, int percent) { int img_x = 0; int img_y = 0; @@ -305,14 +340,15 @@ static void _gr_direct_draw_main_prog_img(FbInfo *fbi, int percent) img_x = x_offset_prog_bar_img_pos; img_y = y_offset_prog_bar_img_pos; - draw_png_img_xy(fbi, img_x, img_y); + //draw_png_img_xy(fbi, img_x, img_y); + draw_png_img_original(surface_info->planes[0].ptr, img_x, img_y, surface_info->width, surface_info->height, surface_info->planes[0].stride); release_png_res(); } /*----------------------------------------------------------------------------- _gr_direct_draw_main_img ----------------------------------------------------------------------------*/ -static void _gr_direct_draw_main_img(FbInfo *fbi) +static void _gr_direct_draw_main_img(tbm_surface_info_s *surface_info) { int img_x = 0; int img_y = 0; @@ -323,7 +359,8 @@ static void _gr_direct_draw_main_img(FbInfo *fbi) img_x = 0; img_y = 0; - draw_png_img_xy(fbi, img_x, img_y); + //draw_png_img_xy(fbi, img_x, img_y); + draw_png_img_original(surface_info->planes[0].ptr, img_x, img_y, surface_info->width, surface_info->height, surface_info->planes[0].stride); release_png_res(); if (read_png_file(IMG_BASE MAIN_TEXT_NAME) < 0) @@ -332,34 +369,121 @@ static void _gr_direct_draw_main_img(FbInfo *fbi) img_x = x_offset_main_bg_text_pos; img_y = y_offset_main_bg_text_pos; - draw_png_img_xy(fbi, img_x, img_y); + //draw_png_img_xy(fbi, img_x, img_y); + draw_png_img_original(surface_info->planes[0].ptr, img_x, img_y, surface_info->width, surface_info->height, surface_info->planes[0].stride); release_png_res(); } + +void _copy_buffers_by_rotate(void *srcptr, int srcw, int srch, int srcstride, + void *dstptr, int dstw, int dsth, int dststride, + int sx, int sy, int sw, int sh, + int dx, int dy, int dw, int dh, int rotate) +{ + pixman_image_t *src_img = NULL, *dst_img = NULL; + pixman_op_t op; + + int buf_width; + + buf_width = srcstride/4; + src_img = pixman_image_create_bits(PIXMAN_a8r8g8b8, buf_width, srch, (uint32_t*)srcptr, srcstride); + if(!src_img) + { + LOG("No source image.\n"); + return; + } + + buf_width = dststride/4; + dst_img = pixman_image_create_bits(PIXMAN_a8r8g8b8, buf_width, dsth, (uint32_t*)dstptr, dststride); + + struct pixman_f_transform ft; + double scale_x, scale_y; + int rotate_step; + pixman_transform_t t; + pixman_f_transform_init_identity(&ft); + + rotate_step = (rotate + 360) / 90 % 4; + if (rotate_step > 0) { + int c = 0, s = 0, tx = 0, ty = 0; + switch (rotate_step) { + case 1: + c = 0, s = -1, tx = -dw; + break; + case 2: + c = -1, s = 0, tx = -dw, ty = -dh; + break; + case 3: + c = 0, s = 1, ty = -dh; + break; + } + pixman_f_transform_translate(&ft, NULL, tx, ty); + pixman_f_transform_rotate(&ft, NULL, c, s); + } + + if (rotate_step % 2 == 0) { + scale_x = (double)sw / dw; + scale_y = (double)sh / dh; + } else { + scale_x = (double)sw / dh; + scale_y = (double)sh / dw; + } + pixman_f_transform_scale(&ft, NULL, scale_x, scale_y); + pixman_f_transform_translate(&ft, NULL, sx, sy); + pixman_transform_from_pixman_f_transform(&t, &ft); + pixman_image_set_transform(src_img, &t); + + + op = PIXMAN_OP_SRC; + pixman_image_composite(op, src_img, NULL, dst_img, 0, 0, 0, 0, dx, dy, dw, dh); + + if (src_img) + pixman_image_unref(src_img); + if (dst_img) + pixman_image_unref(dst_img); +} + /*----------------------------------------------------------------------------- __init_screen ----------------------------------------------------------------------------*/ static void __init_screen(FbInfo *fbi) { - _gr_direct_clear_screen(fbi, COLOR_BLACK); + /* create tbm_surface for original image */ + tbm_surface_h tbm_surface_ori = NULL; + tbm_surface_info_s surface_info_ori; + tbm_surface_ori = tbm_surface_create(fbi->w, fbi->h, TBM_FORMAT_ARGB8888); // rotated width, height + if(!tbm_surface_ori){ + LOG("failed to tbm_surface_create\n"); + } + tbm_surface_map(tbm_surface_ori, TBM_SURF_OPTION_READ | TBM_SURF_OPTION_WRITE, &surface_info_ori); + + + _gr_direct_clear_screen_init(&surface_info_ori, COLOR_BLACK); + + _gr_direct_draw_main_img(&surface_info_ori); - //_gr_direct_draw_text_img(fbi); + _gr_direct_draw_main_prog_img(&surface_info_ori, 0); - _gr_direct_draw_main_img(fbi); + _gr_direct_draw_prog_text(&surface_info_ori, 0); - _gr_direct_draw_main_prog_img(fbi, 0); - _gr_direct_draw_prog_text(fbi, 0); + _copy_buffers_by_rotate(surface_info_ori.planes[0].ptr, surface_info_ori.width, surface_info_ori.height, surface_info_ori.planes[0].stride, + fbi->buf[0], fbi->w, fbi->h, fbi->w * RGB32_PITCH, + 0,0,surface_info_ori.width, surface_info_ori.height, + 0,0,fbi->w, fbi->h, rotate_angle); + tbm_surface_unmap(tbm_surface_ori); + tbm_surface_destroy(tbm_surface_ori); } -static void _gr_direct_progress_bar(FbInfo *fbi, int progress) +static void _gr_direct_progress_bar(tbm_surface_info_s *surface_info, int progress) { char img_name[MAX_PATH]; static int prog_pre = 0; int count = 0; int prog_cnt = 0; + int img_x = 0; + int img_y = 0; if (progress <= 0) return; @@ -369,6 +493,10 @@ static void _gr_direct_progress_bar(FbInfo *fbi, int progress) prog_cnt = progress; + + img_x = x_offset_prog_bar_img_pos; + img_y = y_offset_prog_bar_img_pos; + for (; prog_pre <= prog_cnt; prog_pre++) { LOG("prog_pre/prog_cnt : %d, %d \n", prog_pre , prog_cnt); @@ -379,7 +507,8 @@ static void _gr_direct_progress_bar(FbInfo *fbi, int progress) return; } - draw_png_img_xy(fbi, 240, 355); + //draw_png_img_xy(fbi, 240, 355); + draw_png_img_original(surface_info->planes[0].ptr, img_x, img_y, surface_info->width, surface_info->height, surface_info->planes[0].stride); release_png_res(); s_saved_percent = prog_pre; @@ -411,11 +540,34 @@ void fota_gr_direct_progress(void) LOG("fota_gr_direct_progress progress : %d \n", s_percent_to_draw); if (s_percent_to_draw > 0) { - _gr_direct_progress_bar(&s_fbi, s_percent_to_draw); - _gr_direct_draw_prog_text(&s_fbi, s_saved_percent); + /* create tbm_surface for original image */ + tbm_surface_h tbm_surface_ori = NULL; + tbm_surface_info_s surface_info_ori; + + tbm_surface_ori = tbm_surface_create(img_buf_width, img_buf_height, TBM_FORMAT_ARGB8888); // rotated width, height + if(!tbm_surface_ori){ + LOG("failed to tbm_surface_create\n"); + } + tbm_surface_map(tbm_surface_ori, TBM_SURF_OPTION_READ | TBM_SURF_OPTION_WRITE, &surface_info_ori); + // need to keep previous image + _copy_buffers_by_rotate(s_fbi.buf[0], s_fbi.w, s_fbi.h, s_fbi.w * RGB32_PITCH, + surface_info_ori.planes[0].ptr, surface_info_ori.width, surface_info_ori.height, surface_info_ori.planes[0].stride, + 0,0,s_fbi.w, s_fbi.h, + 0,0,surface_info_ori.width, surface_info_ori.height, rollback_step); + + _gr_direct_progress_bar(&surface_info_ori, s_percent_to_draw); + _gr_direct_draw_prog_text(&surface_info_ori, s_saved_percent); + + _copy_buffers_by_rotate(surface_info_ori.planes[0].ptr, surface_info_ori.width, surface_info_ori.height, surface_info_ori.planes[0].stride, + s_fbi.buf[0], s_fbi.w, s_fbi.h, s_fbi.w * RGB32_PITCH, + 0,0,surface_info_ori.width, surface_info_ori.height, + 0,0,s_fbi.w, s_fbi.h, rotate_step); + tbm_surface_unmap(tbm_surface_ori); + tbm_surface_destroy(tbm_surface_ori); } else if (s_percent_to_draw == 0) { s_saved_percent = 0; } + _gr_direct_update_screen(); } diff --git a/fota_gui_common/fota_png.c b/fota_gui_common/fota_png.c index 88f6e86..86ee2a1 100644 --- a/fota_gui_common/fota_png.c +++ b/fota_gui_common/fota_png.c @@ -381,6 +381,124 @@ void draw_png_img_xy(FbInfo *fbi, int x1, int y1) } + +/*----------------------------------------------------------------------------- + draw_png_img_original() + ----------------------------------------------------------------------------*/ +void draw_png_img_original(void *fbi, int x1, int y1, int fbi_w, int fbi_h, int fbi_stride) +{ + unsigned int *fb_buf_cur = NULL; + int bpp; + int x, y; + int end_width, end_height; + /* temp patch - lcd resoultion for qualcomm */ + + fb_buf_cur = (unsigned int *)fbi; + + /* check out range */ + if ((x1 > fbi_w ) || (y1 > fbi_h)) { + LOG("[draw_png_img_xy] output range exceeds frame buffer range \n"); + return; + } + if(x1 + png_img_width > fbi_w) + end_width = fbi_w- x1; + else + end_width = png_img_width; + if(y1 + png_img_height > fbi_h) + end_height = fbi_h - y1; + else + end_height = png_img_height; + + LOG("png_color_type = [%d]", png_color_type); + if (png_color_type == PNG_COLOR_TYPE_RGB) { + bpp = 3; + LOG("png color type is PNG_COLOR_TYPE_RGB, png_color_type = [%d]\n", png_color_type); + } else if (png_color_type == PNG_COLOR_TYPE_RGBA) { + bpp = 4; + LOG("png color type is PNG_COLOR_TYPE_RGBA, png_color_type = [%d]\n", png_color_type); + } else { + LOG("[draw_png_img_xy] png type does not match RGB or RGBA \n"); + + LOG("[draw_png_img_xy] png type does not match RGB or RGBA, png_color_type = [%d] \n", png_color_type); + return; + } + + /* temp patch - lcd resoultion for qualcomm */ + for (y = 0; y < png_img_height; y++) { + if(y > end_height) continue; + fb_buf_cur = (unsigned int *) (fbi + ((y1 + y) * fbi_stride)); + fb_buf_cur += x1; + png_byte *row = (png_byte *) row_pointers[y]; + for (x = 0; x < png_img_width; x++) { + if(x > end_width) continue; + if (bpp == 3) { + if (png_bit_depth == 8) { + (*fb_buf_cur) = ((*fb_buf_cur)&0xff000000) | + (row[0] << 16) | (row[1] << 8) | (row[2]); + row += bpp; + } else if (png_bit_depth == 16) { + (*fb_buf_cur) = ((*fb_buf_cur)&0xff000000) | + (row[0] << 16) | (row[2] << 8) | (row[4]); + row += bpp*2; + } + } else if (bpp == 4) { + if (png_bit_depth == 8) { + if (row[3] != 0) { + char r1, g1, b1, a1; + char r2, g2, b2, a2; + char r3, g3, b3, a3; + // background pixel + b1 = ((*fb_buf_cur)&0x000000ff); + g1 = ((*fb_buf_cur)&0x0000ff00)>>8; + r1 = ((*fb_buf_cur)&0x00ff0000)>>16; + a1 = ((*fb_buf_cur)&0xff000000)>>24; + // new pixel + r2 = row[0]; + g2 = row[1]; + b2 = row[2]; + a2 = row[3]; + // blended pixel + r3 = (r2 * a2 + r1 * (0xff - a2)) >> 8 ; + g3 = (g2 * a2 + g1 * (0xff - a2)) >> 8; + b3 = (b2 * a2 + b1 * (0xff - a2)) >> 8; + a3 = a1; + (*fb_buf_cur) = (a3 << 24) | + (r3 << 16) | (g3 << 8) | (b3); + } + row += bpp; + } else if (png_bit_depth == 16) { + if (row[6] != 0) { + short r1, g1, b1, a1; + short r2, g2, b2, a2; + char r3, g3, b3, a3; + // background pixel + b1 = ((*fb_buf_cur)&0x000000ff)<<8; + g1 = ((*fb_buf_cur)&0x0000ff00); + r1 = ((*fb_buf_cur)&0x00ff0000)>>8; + a1 = ((*fb_buf_cur)&0xff000000)>>16; + // new pixel + r2 = (row[0]<<8) + row[1]; + g2 = (row[2]<<8) + row[3]; + b2 = (row[4]<<8) + row[5]; + a2 = (row[6]<<8) + row[7]; + // blended pixel + r3 = (r2 * a2 + r1 * (0xffff - a2)) >> 24; + g3 = (g2 * a2 + g1 * (0xffff - a2)) >> 24; + b3 = (b2 * a2 + b1 * (0xffff - a2)) >> 24; + a3 = a1 >> 8; + (*fb_buf_cur) = (a3 << 24) | + (r3 << 16) | (g3 << 8) | (b3); + } + row += bpp*2; + } + } + fb_buf_cur++; + } + } + +} + + /*----------------------------------------------------------------------------- draw_png_mask_xy() - draw pixel only when alpha>0 of given png image diff --git a/fota_gui_common/fota_png.h b/fota_gui_common/fota_png.h index 4a8ce34..f4545e1 100644 --- a/fota_gui_common/fota_png.h +++ b/fota_gui_common/fota_png.h @@ -23,6 +23,7 @@ extern int read_png_file(char *file_name); extern void draw_png_img_xy(FbInfo *fbi, int x1, int y1); +extern void draw_png_img_original(void *fbi, int x1, int y1, int fbi_w, int fbi_h, int fbi_stride); extern void draw_png_img_clip_xy(FbInfo *fbi, int x1, int y1, int cx, int cy, int cw, int ch); extern void draw_png_mask_xy(FbInfo *fbi, int x1, int y1, char r, char g, char b); extern void release_png_res(void); diff --git a/packaging/firmware-update-system-ui.spec b/packaging/firmware-update-system-ui.spec index 44274e4..6c32c5e 100644 --- a/packaging/firmware-update-system-ui.spec +++ b/packaging/firmware-update-system-ui.spec @@ -9,6 +9,7 @@ Source0: %{name}-%{version}.tar.gz Source1001: %{name}.manifest BuildRequires: cmake +BuildRequires: pkgconfig(pixman-1) BuildRequires: pkgconfig(libtbm) BuildRequires: pkgconfig(libtdm) BuildRequires: pkgconfig(libpng)