Try to allocate canvas using stride option.
authorSung-jae Park <nicesj.park@samsung.com>
Sat, 14 Jun 2014 05:09:29 +0000 (14:09 +0900)
committerSung-jae Park <nicesj.park@samsung.com>
Sat, 14 Jun 2014 05:38:41 +0000 (14:38 +0900)
and then try to allocate canvas using original way.

Change-Id: I33076264830664d461d4232ca93cc1f784218576

CMakeLists.txt
include/livebox_internal.h [new file with mode: 0644]
packaging/liblivebox.spec
src/livebox.c
src/virtual_window.c

index 4fcfb41..ce79457 100644 (file)
@@ -64,7 +64,6 @@ ADD_DEFINITIONS("-DNDEBUG")
 ADD_DEFINITIONS("-D_USE_ECORE_TIME_GET")
 ADD_DEFINITIONS("-DMASTER_PKGNAME=\"data-provider-master\"")
 ADD_DEFINITIONS("-DSLAVE_PKGNAME=\"com.samsung.data-provider-slave\"")
-ADD_DEFINITIONS("-DAUTO_ALIGN=1")
 
 SET (BUILD_SOURCE
        ${BUILD_SOURCE}
diff --git a/include/livebox_internal.h b/include/livebox_internal.h
new file mode 100644 (file)
index 0000000..4edab0f
--- /dev/null
@@ -0,0 +1,17 @@
+/*
+ * Copyright 2013  Samsung Electronics Co., Ltd
+ *
+ * Licensed under the Flora License, Version 1.1 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://floralicense.org/license/
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+extern int livebox_conf_auto_align(void);
index 0446d20..c1a3548 100644 (file)
@@ -2,7 +2,7 @@
 
 Name: liblivebox
 Summary: Livebox development library
-Version: 0.8.0
+Version: 0.8.1
 Release: 1
 Group: HomeTF/Livebox
 License: Flora
index 95b4075..50e91c7 100644 (file)
@@ -109,6 +109,7 @@ struct conf {
        int com_core_thread;
        int use_xmonitor;
        int premultiplied;
+       int auto_align;
 };
 
 /*!
@@ -886,6 +887,28 @@ PUBLIC int livebox_request_update(const char *filename)
        return ret;
 }
 
+int livebox_conf_auto_align(void)
+{
+       if (!s_info.conf) {
+               struct conf *(*livebox_conf_get_conf)(void);
+               livebox_conf_get_conf = dlsym(RTLD_DEFAULT, "livebox_conf_get_conf");
+               if (!livebox_conf_get_conf) {
+                       ErrPrint("g_conf is not found\n");
+                       return 1;
+               }
+
+               s_info.conf = livebox_conf_get_conf();
+               if (!s_info.conf) {
+                       ErrPrint("g_conf is not found\n");
+                       return 1;
+               }
+
+               DbgPrint("Auto align: %d\n", s_info.conf->auto_align);
+       }
+
+       return s_info.conf->auto_align;
+}
+
 PUBLIC int livebox_conf_premultiplied_alpha(void)
 {
        if (!s_info.conf) {
index 38c4185..f9ed5c9 100644 (file)
@@ -1,8 +1,27 @@
+/*
+ * Copyright 2013  Samsung Electronics Co., Ltd
+ *
+ * Licensed under the Flora License, Version 1.1 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://floralicense.org/license/
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#define _GNU_SOURCE
+
 #include <Elementary.h>
 #include <string.h>
 #include <Ecore_Evas.h>
 #include <Ecore_X.h>
 #include <Evas.h>
+#include <dlfcn.h>
 
 #include <X11/Xlib.h>
 
 #include <livebox-service.h>
 
 #include "livebox.h"
+#include "livebox_internal.h"
 #include "debug.h"
 
 #define IS_PD 1
 
 #define PUBLIC __attribute__((visibility("default")))
 
+static struct static_info {
+       Ecore_Evas *(*alloc_canvas)(int w, int h, void *(*a)(void *data, int size), void (*f)(void *data, void *ptr), void *data);
+       Ecore_Evas *(*alloc_canvas_with_stride)(int w, int h, void *(*a)(void *data, int size, int *stride, int *bpp), void (*f)(void *data, void *ptr), void *data);
+} s_info = {
+       .alloc_canvas = NULL,
+       .alloc_canvas_with_stride = NULL,
+};
+
 /*!
  * \brief
  * Abstracted Data Type of Virtual Window
@@ -343,7 +371,6 @@ static int event_handler_cb(struct livebox_buffer *handler, struct buffer_event_
        return ret;
 }
 
-#if AUTO_ALIGN
 static void *alloc_fb(void *data, int size)
 {
        struct info *info = data;
@@ -358,7 +385,7 @@ static void *alloc_fb(void *data, int size)
         * Acquire a buffer for canvas.
         */
        info->handle = livebox_acquire_buffer_NEW(info->id, info->is_pd,
-                                       info->w, info->h, sizeof(int), AUTO_ALIGN, /* 0 == auto_align off */
+                                       info->w, info->h, sizeof(int), (livebox_conf_auto_align() || !s_info.alloc_canvas_with_stride),
                                        event_handler_cb, info);
 
        /*!
@@ -386,60 +413,28 @@ static void *alloc_fb(void *data, int size)
        info->is_hw = 0;
        return buffer;
 }
-#else
-static void *alloc_fb(void *data, int size, int *stride, int *bpp)
+
+static void *alloc_stride_fb(void *data, int size, int *stride, int *bpp)
 {
-       struct info *info = data;
        void *buffer;
-       int _stride;
-       int _bpp;
-
-       if (info->ee) {
-               ecore_evas_geometry_get(info->ee, NULL, NULL, &info->w, &info->h);
-               LOGD("Size of ee is updated: %dx%d (info: %p)\n", info->w, info->h, info);
-       }
 
-       /*!
-        * Acquire a buffer for canvas.
-        */
-       info->handle = livebox_acquire_buffer_NEW(info->id, info->is_pd,
-                                       info->w, info->h, sizeof(int), AUTO_ALIGN, /* 0 == auto_align off */
-                                       event_handler_cb, info);
-
-       *bpp = sizeof(int);
-       _stride = livebox_buffer_stride(info->handle);
-       if (_stride < 0) {
-               _stride = info->w * *bpp;
-       }
-       *stride = _stride;
-       DbgPrint("bpp: %d, stride: %d\n", *bpp, *stride);
+       buffer = alloc_fb(data, size);
+       if (buffer) {
+               struct info *info = data;
+               int _stride;
 
-       /*!
-        * If it supports the H/W accelerated buffer,
-        * Use it.
-        */
-       if (livebox_support_hw_buffer(info->handle)) {
-               if (livebox_create_hw_buffer(info->handle) == 0) {
-                       buffer = livebox_buffer_hw_buffer(info->handle);
-                       if (buffer) {
-                               LOGD("HW Accelerated buffer is created %p, (%dx%d)\n", info, info->w, info->h);
-                               info->is_hw = 1;
-                               return buffer;
-                       }
+               *bpp = sizeof(int);
+               _stride = livebox_buffer_stride(info->handle);
+               if (_stride < 0) {
+                       _stride = info->w * *bpp;
                }
 
-               LOGE("Failed to allocate HW Accelerated buffer\n");
+               *stride = _stride;
+               DbgPrint("bpp: %d, stride: %d\n", *bpp, *stride);
        }
 
-       /*!
-        * Or use the buffer of a S/W backend.
-        */
-       buffer = livebox_ref_buffer(info->handle);
-       LOGD("SW buffer is created (%dx%d)\n", info->w, info->h);
-       info->is_hw = 0;
        return buffer;
 }
-#endif
 
 static void free_fb(void *data, void *ptr)
 {
@@ -544,6 +539,23 @@ PUBLIC Evas_Object *livebox_get_evas_object(const char *id, int is_pd)
        struct info *info;
        Evas_Object *rect;
 
+       if (!s_info.alloc_canvas && !s_info.alloc_canvas_with_stride) {
+               s_info.alloc_canvas_with_stride = dlsym(RTLD_DEFAULT, "ecore_evas_buffer_allocfunc_with_stride_new");
+               if (!s_info.alloc_canvas_with_stride) {
+                       DbgPrint("allocfunc_with_stirde_new is not found\n");
+               }
+
+               s_info.alloc_canvas = dlsym(RTLD_DEFAULT, "ecore_evas_buffer_allocfunc_new");
+               if (!s_info.alloc_canvas) {
+                       ErrPrint("allocfunc_new is not found\n");
+               }
+
+               if (!s_info.alloc_canvas_with_stride && !s_info.alloc_canvas) {
+                       ErrPrint("No way to allocate canvas\n");
+                       return NULL;
+               }
+       }
+
        if (!id) {
                ErrPrint("Invalid parameter\n");
                return NULL;
@@ -570,17 +582,18 @@ PUBLIC Evas_Object *livebox_get_evas_object(const char *id, int is_pd)
        info->w = 1;
        info->h = 1;
 
-#if AUTO_ALIGN
-       info->ee = ecore_evas_buffer_allocfunc_new(1, 1, alloc_fb, free_fb, info);
-#else
-       info->ee = ecore_evas_buffer_allocfunc_with_stride_new(1, 1, alloc_fb, free_fb, info);
+       if (!livebox_conf_auto_align() && s_info.alloc_canvas_with_stride) {
+               info->ee = s_info.alloc_canvas_with_stride(1, 1, alloc_stride_fb, free_fb, info);
+       } else {
+               info->ee = s_info.alloc_canvas(1, 1, alloc_fb, free_fb, info);
+       }
+
        if (!info->ee) {
                ErrPrint("Failed to create ecore_evas (%dx%d)\n", 1, 1);
                free(info->id);
                free(info);
                return NULL;
        }
-#endif
 
        info->e = ecore_evas_get(info->ee);
        if (!info->e) {