display: added blank guide image
authorGiWoong Kim <giwoong.kim@samsung.com>
Fri, 9 Aug 2013 11:07:55 +0000 (20:07 +0900)
committerGiWoong Kim <giwoong.kim@samsung.com>
Mon, 12 Aug 2013 13:03:42 +0000 (22:03 +0900)
Change-Id: I0f558f0e26f717d80c4d2641ac50c80c04e69dc5
Signed-off-by: GiWoong Kim <giwoong.kim@samsung.com>
tizen/src/Makefile
tizen/src/Makefile.tizen
tizen/src/hw/maru_brightness.c [changed mode: 0644->0755]
tizen/src/maru_sdl.c
tizen/src/osutil-linux.c [changed mode: 0644->0755]
tizen/src/osutil-win32.c [changed mode: 0644->0755]
tizen/src/skin/client/resource/images/blank-guide.png [new file with mode: 0755]

index 7c363ab..eb1eef2 100644 (file)
@@ -78,6 +78,7 @@ install: all
        mkdir -p $(EMUL_DIR)/bin
        mkdir -p $(EMUL_DIR)/etc
        mkdir -p $(EMUL_DIR)/data
+       mkdir -p $(EMUL_DIR)/images
 ifndef CONFIG_DARWIN
        @for target in $(TARGET_DIRS); do \
        case "$$target" in \
@@ -141,10 +142,12 @@ ifndef CONFIG_DARWIN
        cp ../../qemu-img $(EMUL_DIR)/bin
        cp skin/client/lib/swt.jar $(EMUL_DIR)/bin/swt.jar
        cp -dpr skin/client/skins $(EMUL_DIR)
+       cp -dpr skin/client/resource/images/blank-guide.png $(EMUL_DIR)/images/blank-guide.png
 else
        cp ../../qemu-img $(EMUL_DIR)/bin
        cp skin/client/lib/swt.jar $(EMUL_DIR)/bin/swt.jar
        cp -pPR skin/client/skins $(EMUL_DIR)
+       cp -pPR skin/client/resource/images/blank-guide.png $(EMUL_DIR)/images/blank-guide.png
 endif
 
 ifdef CONFIG_USE_SHM
@@ -191,6 +194,7 @@ skin_client_dibs:
 install_dibs: all_dibs
        mkdir -p $(DIBS_COMMON_DIR)/bin
        mkdir -p $(DIBS_COMMON_DIR)/etc
+       mkdir -p $(DIBS_COMMON_DIR)/images
        mkdir -p $(DIBS_X86_DIR)/bin
        mkdir -p $(DIBS_X86_DIR)/data
        mkdir -p $(DIBS_X86_DIR)/etc
@@ -259,9 +263,11 @@ endif
 ifndef CONFIG_DARWIN
        cp ../../qemu-img $(DIBS_COMMON_DIR)/bin
        cp -dpr skin/client/skins $(DIBS_COMMON_DIR)
+       cp -dpr skin/client/resource/images/blank-guide.png $(EMUL_DIR)/images/blank-guide.png
 else
        cp ../../qemu-img $(DIBS_COMMON_DIR)/bin
        cp -pPR skin/client/skins $(DIBS_COMMON_DIR)
+       cp -pPR skin/client/resource/images/blank-guide.png $(EMUL_DIR)/images/blank-guide.png
 endif
 
 ifdef CONFIG_USE_SHM
index d441b90..45ede2c 100644 (file)
@@ -23,10 +23,10 @@ CFLAGS += -g -O0
 endif
 
 ifdef CONFIG_WIN32
-LIBS += -lavformat -lavcodec -lavutil -lm -lcurl -lopengl32 -lglu32 -lgdi32
+LIBS += -lavformat -lavcodec -lavutil -lm -lcurl -lopengl32 -lglu32 -lgdi32 -lpng -lz
 endif
 ifdef CONFIG_LINUX
-LIBS += -lavformat -lavcodec -lavutil -lm -lcurl -lGL -lXcomposite -lXext
+LIBS += -lavformat -lavcodec -lavutil -lm -lcurl -lGL -lXcomposite -lXext -lpng
 endif
 ifdef CONFIG_DARWIN
 # FIXME: disabled codec on Mac now
old mode 100644 (file)
new mode 100755 (executable)
index 6a4215a..b694301
@@ -178,9 +178,9 @@ static void brightness_exitfn(PCIDevice *dev)
 static void maru_brightness_bh(void *opaque)
 {
     if (brightness_off == 0) {
-        notify_brightness(TRUE);
+        notify_brightness(true);
     } else {
-        notify_brightness(FALSE);
+        notify_brightness(false);
     }
 }
 
index 4e300c1..873b3b6 100644 (file)
 
 #include <pthread.h>
 #include <math.h>
+#include <png.h>
 #include "ui/console.h"
 #include "maru_sdl.h"
 #include "maru_display.h"
 #include "emul_state.h"
+#include "emulator.h"
 #include "maru_finger.h"
 #include "hw/maru_pm.h"
 #include "hw/maru_brightness.h"
@@ -50,6 +52,7 @@ static SDL_Surface *surface_screen;
 static SDL_Surface *surface_qemu;
 static SDL_Surface *scaled_screen;
 static SDL_Surface *rotated_screen;
+static SDL_Surface *surface_guide; /* blank guide image */
 
 static double current_scale_factor = 1.0;
 static double current_screen_degree;
@@ -60,6 +63,10 @@ static int sdl_initialized;
 static int sdl_alteration;
 
 static int sdl_skip_update;
+static int blank_cnt;
+#define MAX_BLANK_FRAME_CNT 100
+#define BLANK_GUIDE_IMAGE_PATH "../images/"
+#define BLANK_GUIDE_IMAGE_NAME "blank-guide.png"
 
 #if 0
 static int sdl_opengl = 0; //0 : just SDL surface, 1 : using SDL with OpenGL
@@ -285,6 +292,193 @@ static int maru_sdl_poll_event(SDL_Event *ev)
 
     return ret;
 }
+
+static png_bytep read_png_file(const char *file_name,
+    unsigned int *width_out, unsigned int *height_out)
+{
+#define PNG_HEADER_SIZE 8
+
+    FILE *fp = NULL;
+    png_byte header[PNG_HEADER_SIZE] = { 0, };
+    png_structp png_ptr = NULL;
+
+    png_infop info_ptr = NULL;
+    png_uint_32 width = 0;
+    png_uint_32 height = 0;
+    png_byte channels = 0;
+    unsigned int stride = 0;
+    int bit_depth = 0;
+    int color_type = 0;
+    int i = 0;
+
+    png_bytep pixel_data = NULL;
+    png_bytepp row_ptr_data = NULL;
+
+    if (file_name == NULL) {
+        ERR("file name is empty\n");
+        return NULL;
+    }
+
+    fp = fopen(file_name, "rb");
+    if (fp == NULL) {
+        ERR("file %s could not be opened\n", file_name);
+        return NULL;
+    }
+
+    if (fread(header, sizeof(png_byte), PNG_HEADER_SIZE, fp) != PNG_HEADER_SIZE) {
+        ERR("failed to read header from png file\n");
+        fclose(fp);
+        return NULL;
+    }
+
+    if (png_sig_cmp(header, 0, PNG_HEADER_SIZE) != 0) {
+        ERR("file %s is not recognized as a PNG image\n", file_name);
+        fclose(fp);
+        return NULL;
+    }
+
+    png_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
+    if (png_ptr == NULL) {
+        ERR("failed to allocate png read struct\n");
+        fclose(fp);
+        return NULL;
+    }
+
+    info_ptr = png_create_info_struct(png_ptr);
+    if (info_ptr == NULL) {
+        ERR("failed to allocate png info struct\n");
+        png_destroy_read_struct(&png_ptr, &info_ptr, NULL);
+        fclose(fp);
+        return NULL;
+    }
+
+    if (setjmp(png_jmpbuf(png_ptr)) != 0) {
+        ERR("error during init_io\n");
+        png_destroy_read_struct(&png_ptr, &info_ptr, NULL);
+        png_destroy_info_struct(png_ptr, &info_ptr);
+        fclose(fp);
+        return NULL;
+    }
+
+    png_init_io(png_ptr, fp);
+    png_set_sig_bytes(png_ptr, PNG_HEADER_SIZE);
+
+    /* read the PNG image information */
+    png_read_info(png_ptr, info_ptr);
+    png_get_IHDR(png_ptr, info_ptr,
+        &width, &height, &bit_depth, &color_type,
+        NULL, NULL, NULL);
+
+    channels = png_get_channels(png_ptr, info_ptr);
+    stride = width * bit_depth * channels / 8;
+
+    pixel_data = (png_bytep) g_malloc0(stride * height);
+    if (pixel_data == NULL) {
+        ERR("could not allocate data buffer for pixels\n");
+
+        png_destroy_read_struct(&png_ptr, &info_ptr, NULL);
+        png_destroy_info_struct(png_ptr, &info_ptr);
+        fclose(fp);
+        return NULL;
+    }
+
+    row_ptr_data = (png_bytepp) g_malloc0(sizeof(png_bytep) * height);
+    if (row_ptr_data == NULL) {
+        ERR("could not allocate data buffer for row_ptr\n");
+
+        g_free(pixel_data);
+        png_destroy_read_struct(&png_ptr, &info_ptr, NULL);
+        png_destroy_info_struct(png_ptr, &info_ptr);
+        fclose(fp);
+        return NULL;
+    }
+
+    switch(color_type) {
+        case PNG_COLOR_TYPE_PALETTE :
+            png_set_palette_to_rgb(png_ptr);
+            break;
+        case PNG_COLOR_TYPE_RGB :
+            if (png_get_valid(png_ptr, info_ptr, PNG_INFO_tRNS)) {
+                /* transparency data for image */
+                png_set_tRNS_to_alpha(png_ptr);
+            } else {
+                png_set_filter(png_ptr, 0xff, PNG_FILLER_AFTER);
+            }
+            break;
+        case PNG_COLOR_TYPE_RGB_ALPHA :
+            break;
+        default :
+            INFO("png file has an unsupported color type\n");
+            break;
+    }
+
+    for (i = 0; i < height; i++) {
+        row_ptr_data[i] = pixel_data + (stride * i);
+    }
+
+    /* read the entire image into memory */
+    png_read_image(png_ptr, row_ptr_data);
+
+    /* image information */
+    INFO("=== blank guide image was loaded ===============\n");
+    INFO("file path : %s\n", file_name);
+    INFO("width : %d, height : %d, stride : %d\n",
+        width, height, stride);
+    INFO("color type : %d, channels : %d, bit depth : %d\n",
+        color_type, channels, bit_depth);
+    INFO("================================================\n");
+
+    if (width_out != NULL) {
+        *width_out = (unsigned int) width;
+    }
+    if (height_out != NULL) {
+        *height_out = (unsigned int) height;
+    }
+
+    g_free(row_ptr_data);
+    png_destroy_read_struct(&png_ptr, &info_ptr, NULL);
+    png_destroy_info_struct(png_ptr, &info_ptr);
+    fclose(fp);
+
+    return pixel_data;
+}
+
+static SDL_Surface *get_blank_guide_image(void)
+{
+    unsigned int width = 0;
+    unsigned int height = 0;
+    char *guide_image_path = NULL;
+    int path_len = 0;
+    void *guide_image_data = NULL;
+
+    path_len = strlen(get_bin_path()) +
+        strlen(BLANK_GUIDE_IMAGE_PATH) + strlen(BLANK_GUIDE_IMAGE_NAME) + 1;
+    guide_image_path = g_malloc0(sizeof(char) * path_len);
+    snprintf(guide_image_path, path_len, "%s%s%s",
+        get_bin_path(), BLANK_GUIDE_IMAGE_PATH, BLANK_GUIDE_IMAGE_NAME);
+
+    if (surface_guide == NULL) {
+        /* load png image */
+        guide_image_data = (void *) read_png_file(
+            guide_image_path, &width, &height);
+        if (guide_image_data != NULL) {
+            surface_guide = SDL_CreateRGBSurfaceFrom(
+                guide_image_data, width, height,
+                get_emul_sdl_bpp(), width * 4,
+                dpy_surface->pf.bmask,
+                dpy_surface->pf.gmask,
+                dpy_surface->pf.rmask,
+                dpy_surface->pf.amask);
+        } else {
+            ERR("failed to draw a blank guide image\n");
+        }
+    }
+
+    g_free(guide_image_path);
+
+    return surface_guide;
+}
+
 static void qemu_ds_sdl_refresh(DisplayChangeListener *dcl)
 {
     SDL_Event ev1, *ev = &ev1;
@@ -311,10 +505,33 @@ static void qemu_ds_sdl_refresh(DisplayChangeListener *dcl)
         }
     }
 
-    /* If the LCD is turned off,
-       the screen does not update until the LCD is turned on */
+    /* If the display is turned off,
+       the screen does not update until the display is turned on */
     if (sdl_skip_update && brightness_off) {
+        if (blank_cnt > MAX_BLANK_FRAME_CNT) {
+            /* do nothing */
+            return;
+        } else if (blank_cnt == MAX_BLANK_FRAME_CNT) {
+            /* draw guide image */
+            INFO("draw a blank guide image\n");
+
+            SDL_Surface *guide = get_blank_guide_image();
+            if (guide != NULL) {
+                SDL_BlitSurface(guide, NULL, surface_screen, NULL);
+                SDL_UpdateRect(surface_screen, 0, 0, 0, 0);
+            }
+        } else if (blank_cnt == 0) {
+            INFO("skipping of the display updating is started\n");
+        }
+
+        blank_cnt++;
+
         return;
+    } else {
+        if (blank_cnt != 0) {
+            INFO("skipping of the display updating is ended\n");
+            blank_cnt = 0;
+        }
     }
 
     graphic_hw_update(NULL);
@@ -713,6 +930,11 @@ void maruskin_sdl_quit(void)
 {
     INFO("maru sdl quit\n");
 
+    if (surface_guide != NULL) {
+        g_free(surface_guide->pixels);
+        SDL_FreeSurface(surface_guide);
+    }
+
     /* remove multi-touch finger points */
     cleanup_multi_touch_state();
 
old mode 100644 (file)
new mode 100755 (executable)
index fba3ba8..855ff01
@@ -34,6 +34,7 @@
   @brief    Collection of utilities for linux
  */
 
+#include <png.h>
 #include "maru_common.h"
 #include "osutil.h"
 #include "emulator.h"
@@ -165,6 +166,8 @@ void print_system_info_os(void)
 {
     INFO("* Linux\n");
 
+    INFO("* LibPNG Version : %s\n", PNG_LIBPNG_VER_STRING);
+
     /* depends on building */
     INFO("* QEMU build machine linux kernel version : (%d, %d, %d)\n",
         LINUX_VERSION_CODE >> 16,
old mode 100644 (file)
new mode 100755 (executable)
index ad5ef10..a2117b3
@@ -34,6 +34,7 @@
   @brief    Collection of utilities for win32
  */
 
+#include <png.h>
 #include "maru_common.h"
 #include "osutil.h"
 #include "emulator.h"
@@ -144,6 +145,8 @@ void print_system_info_os(void)
 {
     INFO("* Windows\n");
 
+    INFO("* LibPNG Version : %s\n", PNG_LIBPNG_VER_STRING);
+
     /* Retrieves information about the current os */
     OSVERSIONINFO osvi;
     ZeroMemory(&osvi, sizeof(OSVERSIONINFO));
diff --git a/tizen/src/skin/client/resource/images/blank-guide.png b/tizen/src/skin/client/resource/images/blank-guide.png
new file mode 100755 (executable)
index 0000000..c90a1b7
Binary files /dev/null and b/tizen/src/skin/client/resource/images/blank-guide.png differ