[Title] optimize a maru_rotozoom
authorgiwoong.kim <giwoong.kim@samsung.com>
Tue, 7 Aug 2012 12:21:53 +0000 (21:21 +0900)
committergiwoong.kim <giwoong.kim@samsung.com>
Tue, 7 Aug 2012 12:28:43 +0000 (21:28 +0900)
[Type] feature
[Module] Emulator / skin
[Priority] major
[Jira#]
[Redmine#]
[Problem]
[Cause]
[Solution]
[TestCase]

tizen/src/maru_sdl.c
tizen/src/maru_sdl_rotozoom.h

index f7ed3854b9dc9dcadbf038b92510d685a64abe59..d2e4eb4f36b91933d9b2ac2d2efc7e51a5fb5ce6 100644 (file)
@@ -47,6 +47,7 @@ DisplaySurface* qemu_display_surface = NULL;
 
 SDL_Surface *surface_screen;
 SDL_Surface *surface_qemu;
+SDL_Surface *processing_screen = NULL;
 GLuint texture;
 
 static double current_scale_factor = 1.0;
@@ -184,7 +185,8 @@ static void _sdl_init(void)
         h = temp;
     }
 
-    /*if (capability_check_gl != 0) {
+#if 0
+    if (capability_check_gl != 0) {
         ERR("GL check returned non-zero\n");
         surface_screen = NULL;
     } else {
@@ -194,17 +196,26 @@ static void _sdl_init(void)
     if (surface_screen == NULL) {
         sdl_opengl = 0;
         INFO("No OpenGL support on this system!??\n");
-        ERR("%s\n", SDL_GetError());*/
+        ERR("%s\n", SDL_GetError());
+#endif
 
         surface_screen = SDL_SetVideoMode(w, h, get_emul_sdl_bpp(), SDL_FLAGS);
         if (surface_screen == NULL) {
             ERR("Could not open SDL display (%dx%dx%d): %s\n", w, h, get_emul_sdl_bpp(), SDL_GetError());
             return;
         }
-    /*} else {
+#if 0
+    } else {
         sdl_opengl = 1;
         INFO("OpenGL is supported on this system.\n");
-    }*/
+    }
+#endif
+
+    /* create buffer for image processing */
+    SDL_FreeSurface(processing_screen);
+    processing_screen = SDL_CreateRGBSurface(SDL_SWSURFACE, w, h, get_emul_sdl_bpp(),
+        surface_qemu->format->Rmask, surface_qemu->format->Gmask,
+        surface_qemu->format->Bmask, surface_qemu->format->Amask);
 
     if (sdl_opengl == 1) {
         /* Set the OpenGL state */
@@ -347,26 +358,33 @@ static void qemu_update(void)
         }
         else
         { //sdl surface
-            SDL_Surface *processing_screen = NULL;
-
-            if (current_scale_factor < 0.5) {
+            if (current_scale_factor < 0.5)
+            {
+                /* process by sdl_gfx */
                 // workaround
                 // set color key 'magenta'
                 surface_qemu->format->colorkey = 0xFF00FF;
 
+                SDL_Surface *temp_surface = NULL;
+
+                temp_surface = rotozoomSurface(
+                    surface_qemu, current_screen_degree, current_scale_factor, 1);
+                SDL_BlitSurface(temp_surface, NULL, surface_screen, NULL);
+
+                SDL_FreeSurface(temp_surface);
+            }
+            else if (current_scale_factor != 1.0 || current_screen_degree != 0.0)
+            {
                 //image processing
-                processing_screen = rotozoomSurface(surface_qemu, current_screen_degree, current_scale_factor, 1);
-                SDL_BlitSurface(processing_screen, NULL, surface_screen, NULL);
-            } else if (current_scale_factor != 1.0 || current_screen_degree != 0.0) {
-                //image processing
-                processing_screen = maru_rotozoom(surface_qemu, (int)current_screen_degree, current_scale_factor);
+                processing_screen = maru_rotozoom(
+                    surface_qemu, processing_screen, (int)current_screen_degree);
                 SDL_BlitSurface(processing_screen, NULL, surface_screen, NULL);
-            } else { //as-is
+            }
+            else //as-is
+            {
                 SDL_BlitSurface(surface_qemu, NULL, surface_screen, NULL);
             }
 
-            SDL_FreeSurface(processing_screen);
-
             /* draw multi-touch finger points */
             MultiTouchState *mts = get_emul_multi_touch_state();
             if (mts->multitouch_enable != 0 && mts->finger_point_surface != NULL) {
@@ -468,6 +486,7 @@ void maruskin_sdl_quit(void)
         glDeleteTextures(1, &texture);
     }
 
+    SDL_FreeSurface(processing_screen);
     SDL_Quit();
 }
 
index 4faf2c413d22a9a90a29f95a5f145750769ce780..de362cae9c3669db5decb71a51f05cbd7b8bc368 100644 (file)
@@ -39,7 +39,8 @@
 #define G_CHANNEL_MASK 0x0000ff00
 #define B_CHANNEL_MASK 0x000000ff
 
-SDL_Surface *maru_rotozoom(SDL_Surface *rz_src, int angle, double zoom);
+SDL_Surface *maru_rotozoom(SDL_Surface *rz_src, SDL_Surface *rz_dst, int angle);
+
 
 static void interpolate_pixel_cpy(unsigned int *dst, unsigned int *src_addr, unsigned int src_w, unsigned int src_h, int x, int y)
 {
@@ -122,40 +123,39 @@ static void interpolate_pixel_cpy(unsigned int *dst, unsigned int *src_addr, uns
         ((sum_g / 4) & G_CHANNEL_MASK) | ((sum_b / 4) & B_CHANNEL_MASK);
 }
 
-//TODO: optimization
-SDL_Surface *maru_rotozoom(SDL_Surface *rz_src, int angle, double zoom)
+SDL_Surface *maru_rotozoom(SDL_Surface *rz_src, SDL_Surface *rz_dst, int angle)
 {
 #define PRECISION 4096
 #define SHIFT 12
 
     int i, j;
-    SDL_Surface *rz_dst;
-    unsigned int dst_width = (unsigned int)(rz_src->w * zoom);
-    unsigned int dst_height = (unsigned int)(rz_src->h * zoom);
+    unsigned int dst_width = 0;
+    unsigned int dst_height = 0;
+
+    unsigned int sx = 0;
+    unsigned int sy = 0;
+    unsigned int row_index = 0;
+    unsigned int col_index = 0;
+
+    unsigned int *out = NULL;
+    unsigned int *row = NULL;
 
     switch(angle) {
         case 90:
         case 270:
-            rz_dst = SDL_CreateRGBSurface(SDL_SWSURFACE, dst_height, dst_width, 32,
-                rz_src->format->Rmask, rz_src->format->Gmask,
-                rz_src->format->Bmask, rz_src->format->Amask);
+            dst_width = rz_dst->h;
+            dst_height = rz_dst->w;
             break;
         case 0:
         case 180:
         default:
-            rz_dst = SDL_CreateRGBSurface(SDL_SWSURFACE, dst_width, dst_height, 32,
-                rz_src->format->Rmask, rz_src->format->Gmask,
-                rz_src->format->Bmask, rz_src->format->Amask);
+            dst_width = rz_dst->w;
+            dst_height = rz_dst->h;
             break;
-    } //TODO: exile 
-
-    unsigned int sx = (rz_src->w) * PRECISION / dst_width;
-    unsigned int sy = (rz_src->h) * PRECISION / dst_height; //TODO: exile 
-    unsigned int row_index = 0;
-    unsigned int col_index = 0;
+    }
 
-    unsigned int *out = NULL;
-    unsigned int *row = NULL;
+    sx = (rz_src->w) * PRECISION / dst_width;
+    sy = (rz_src->h) * PRECISION / dst_height;
 
     SDL_LockSurface(rz_src);