IT

[EFL] EFL 윈도우를 가속하여 보자

타이젠 개발자, 윤진 2015. 6. 12. 00:08

이펙트가 전무한 평면적인 앱을 개발할 때는 성능에 민감하지 않아도 됩니다.

하지만, 사용자의 동작마다 유려한 반응이 연결되어 있다면,

성능에 민감하게 반응할 수밖에 없습니다.


부드러운 효과를 위해서는,

단위시간당 화면이 많이 갱신될수록 좋지요.

한 오브젝트가 1초에 60px을 움직일 때,

화면이 10번 갱신되는 것과 60번 갱신되는 것은 당연히 차이가 있겠지요.



EFL에서는 개발자가 윈도우 단위로 가속화 방식을 선택할 수 있게 하였습니다.

Elementary config에서 제공하는 함수 하나만으로 가속방식을 선택할 수 있지요.

먼저 elm_config.h에서 elm_config_accel_preference_set() 함수 선언을 살펴보시지요.


/**
 * @brief Set Elementary's acceleration preferences for new windows.
 *
 * @param[in] pref The preference desired as a normal C string
 *
 * @details  Note that it will take effect only to Elementary windows created after
 *           this is called. The @p pref string is a freeform C string that indicates
 *           what kind of acceleration is preferred. Here "acceleration" majorly
 *           means to rendering and which hardware unit application renders guis with.
 *           This may or may not be honored, but a best attempt will
 *           be made. Known strings are as follows:
 *
 * @li "gl", "opengl" - try use opengl.
 * @li "3d" - try and use a 3d acceleration unit.
 * @li "hw", "hardware", "accel" - try any acceleration unit (best possible)
 *
 * @note This takes precedence over engine preferences set with
 *       @ref elm_config_preferred_engine_set().
 *
 * @see elm_config_accel_preference_set()
 *
 * @since_tizen 2.3
 *
 * @see elm_win_add()
 * @see elm_config_accel_preference_override_set()
 *
 * @since 1.10
 */
EAPI void        elm_config_accel_preference_set(const char *pref);


가속방식으로 gl / opengl / 3d / hw / hardware / accel 등을 사용할 수 있습니다.

사용시 주의할 점이 하나 있습니다.

elm_config_accel_preference_set()은 elm_win_add()를 사용하기 전에 사용해야 합니다.

elm_win_add() 이후에 사용한다면 소용이 없습니다.

elm_win_add() 함수 내에서,

elm_config_accel_preference_set()에서 설정한 값을 참조하여 윈도우를 생성하기 때문입니다.


elementary 소스를 찾아보지요.

"git://review.tizen.org/framework/uifw/elementary"의 tizen_2.3 브랜치입니다.

elementary/src/lib/elm_win.c 파일에서 elm_win_add() 정의부를 찾아보세요.


EAPI Evas_Object *
elm_win_add(Evas_Object *parent,
            const char *name,
            Elm_Win_Type type)
{
   Evas *e;
   Evas_Object *obj;
   const Eina_List *l;
   const char *fontpath, *fallback = NULL;

   Elm_Win_Smart_Data tmp_sd;

   // 중략

   switch (type)
     {
      case ELM_WIN_DYNAMIC_BOX:
        // 중략
        break;
      case ELM_WIN_INLINED_IMAGE:
        // 중략
        break;
      case ELM_WIN_SOCKET_IMAGE:
        // 중략
        break;
      default:
        if (ENGINE_COMPARE(ELM_SOFTWARE_X11))
           // 중략
        else if (ENGINE_COMPARE(ELM_SOFTWARE_FB))
           // 중략
        else if (ENGINE_COMPARE(ELM_SOFTWARE_DIRECTFB))
           // 중략
        else if (ENGINE_COMPARE(ELM_SOFTWARE_16_X11))
           // 중략
        else if (ENGINE_COMPARE(ELM_SOFTWARE_8_X11))
           // 중략
        else if (ENGINE_COMPARE(ELM_OPENGL_X11))
           // 중략
        else if (ENGINE_COMPARE(ELM_SOFTWARE_WIN32))
           // 중략
        else if (ENGINE_COMPARE(ELM_SOFTWARE_16_WINCE))
           // 중략
        else if (ENGINE_COMPARE(ELM_SOFTWARE_PSL1GHT))
           // 중략
        else if (ENGINE_COMPARE(ELM_SOFTWARE_SDL))
           // 중략
        else if (ENGINE_COMPARE(ELM_SOFTWARE_16_SDL))
           // 중략
        else if (ENGINE_COMPARE(ELM_OPENGL_SDL))
           // 중략
        else if (ENGINE_COMPARE(ELM_OPENGL_COCOA))
           // 중략
        else if (ENGINE_COMPARE(ELM_BUFFER))
           // 중략
        else if (ENGINE_COMPARE(ELM_EWS))
           // 중략
        else if (ENGINE_COMPARE(ELM_WAYLAND_SHM))
           // 중략
        else if (ENGINE_COMPARE(ELM_WAYLAND_EGL))
           // 중략
        else if (!strncmp(ENGINE_GET(), "shot:", 5))
           // 중략
        break;
}


ELM_WIN_DYNAMIC_BOX, ELM_WIN_INLINED_IMAGE, ELM_WIN_SOCKET_IMAGE 타입의 윈도우를 생성하는 경우는 가속화 엔진을 사용하지 않습니다.

위의 타입은 엄밀히 얘기하면 윈도우가 아닙니다.

switch문 내의 default 케이스가 윈도우를 생성하는 부분입니다.

default 케이스 내의 if / else if / else 문으로 가속화를 위한 엔진을 고르지요.

ENGINE_COMPARE()를 통해,

- 사용자가 elm_config_accel_preference_set()에서 입력한 string과

- 내장되어 있는 엔진의 string을 비교하여,

그에 맞는 가속화 방법을 결정하게 되는 것입니다.


타이젠 오픈소스에 있는 모든 앱들을 대상으로 elm_config_accel_preference_set()을 사용하는 앱을 찾아보았습니다.

Tizen 2.3 기준으로 딱 하나의 앱이 나오네요.

git://review.tizen.org/apps/home/menu-screen


menu-screen 앱을 보면,

윈도우를 생성하기 직전에 가속방법을 설정하고 있습니다.

Emulator 환경에서는 opengl을 사용하고,

그 외의 환경에서는 vconf로 설정된 값을 사용하게 되어 있습니다.

menu-screen은 플랫폼의 첫 화면이니만큼,

성능에 신경을 쓸 수 밖에 없겠지요.


static menu_screen_error_e _create_canvas(char *name, char *title)
{
    char *buf;

    if (_is_emulator_on()) {
        elm_config_accel_preference_set("opengl");
    } else {
        buf = vconf_get_str(MENU_SCREEN_ENGINE);
        if (buf) {
            _D("ELM_ENGINE is set as [%s]", buf);
            elm_config_accel_preference_set(buf);
            free(buf);
        } else {
            _D("ELM_ENGINE is set as [gl]");
            elm_config_accel_preference_set("gl");
        }
    }   

    menu_screen_info.win = elm_win_add(NULL, name, ELM_WIN_BASIC);
    retv_if(NULL == menu_screen_info.win, MENU_SCREEN_ERROR_FAIL);

    if (title) {
        elm_win_title_set(menu_screen_info.win, title);
    }   
    elm_win_borderless_set(menu_screen_info.win, EINA_TRUE);
    elm_win_screen_size_get(menu_screen_info.win, NULL, NULL, &menu_screen_info.root_width, &menu_screen_info.root_height);
   // 생략
}


가속으로 CPU/메모리 사용이 증가하게 되면,

소모전류도 덩달이 늘어날 수 있습니다.

(하지만, 비례한다고 말할 수 있을지는 모르겠습니다)

상황에 맞게 사용하는게 좋겠지요.


끝_