support fast software rendering on elvees board sandbox/richiefreedom/tizen_common_elvees_soft
authorAlexander Yashchenko <a.yashchenko@samsung.com>
Fri, 27 May 2016 15:10:12 +0000 (18:10 +0300)
committerSergei Rogachev <s.rogachev@samsung.com>
Thu, 16 Jun 2016 11:05:16 +0000 (14:05 +0300)
Some modifications to allow software renering on Elvees board.

After corresponding modification of libtbm-shm it is possible to remove memcopy
from the commit function.

Only for demonstration, very hacky and dirty.

Change-Id: I27e21ecf1da729f0166c603bb166dd31dbec561d
Signed-off-by: Alexander Yashchenko <a.yashchenko@samsung.com>
Signed-off-by: Sergei Rogachev <s.rogachev@samsung.com>
src/tdm_fbdev.c
src/tdm_fbdev.h
src/tdm_fbdev_display.c

index 6938c081ec1e624c912d4d7bc32613564616ed34..44e1dc623139c92a6352d064789fff5d6baba960 100644 (file)
@@ -66,52 +66,6 @@ _tdm_fbdev_init_internal(void)
     vinfo->transp.offset  = 0;
     vinfo->transp.length  = 0;
 
-    /*
-     * Almost all framebuffers support off screen rendering.
-     * The code bellow requests Framebuffer to allocate memory equals to three
-     * buffers each of which width*height size. While the first drawn
-     * framebuffer's area is displaying the second or the third is redrawing
-     * or compositing by some application. When timer was expired or vblank
-     * was received Framebufer's areas swap, thus the second or the third is
-     * displaying and first is redrawing or compositing. Simple representation
-     * of what was said bellow
-     *
-     *                    SWAP Event                SWAP Event
-     *                        |                         |
-     *    +-------------+     |     +-------------+     |      +-------------+
-     *    |             |     |     |             |     |      |  Redrawing  |
-     *    | Displaying  |     |     |   queued    |     |      |     or      |
-     *    |             |     |     |             |     |      | Compositing |
-     *    +-------------+     |     +-------------+     |      +-------------+
-     *    |  Redrawing  |     |     |             |     |      |             |
-     *    |     or      | +-------> | Displaying  | +--------> |   queued    |
-     *    | Compositing |     |     |             |     |      |             |
-     *    +-------------+     |     +-------------+     |      +-------------+
-     *    |             |     |     |  Redrawing  |     |      |             |
-     *    |   queued    |     |     |     or      |     |      | Displaying  |
-     *    |             |     |     | Compositing |     |      |             |
-     *    +-------------+     |     +-------------+     |      +-------------+
-     *                        |                         |
-     */
-    /*
-     * TODO: Implement off screen rendering
-     */
-    vinfo->yres_virtual = vinfo->yres * MAX_BUF;
-
-    ret = ioctl(fbdev_data->fbdev_fd, FBIOPAN_DISPLAY, vinfo);
-    if(ret < 0)
-    {
-        TDM_INFO("page flip not supported,  errno=%d", errno);
-        vinfo->yres_virtual = vinfo->yres;
-    }
-
-    ret = ioctl(fbdev_data->fbdev_fd, FBIOPAN_DISPLAY, vinfo);
-    if(ret < 0)
-    {
-        TDM_ERR("FBIOPAN_DISPLAY ioctl failed, errno=%d", errno);
-        goto close_1;
-    }
-
     ret = ioctl(fbdev_data->fbdev_fd, FBIOGET_FSCREENINFO, finfo);
     if (ret < 0)
     {
@@ -236,8 +190,8 @@ tdm_fbdev_init(tdm_display *dpy, tdm_error *error)
     memset(&fbdev_func_display, 0, sizeof(fbdev_func_display));
     fbdev_func_display.display_get_capabilitiy = fbdev_display_get_capabilitiy;
     fbdev_func_display.display_get_outputs = fbdev_display_get_outputs;
-    fbdev_func_display.display_get_fd = fbdev_display_get_fd;
-    fbdev_func_display.display_handle_events = fbdev_display_handle_events;
+    fbdev_func_display.display_get_fd = NULL;
+    fbdev_func_display.display_handle_events = NULL;
 
     memset(&fbdev_func_output, 0, sizeof(fbdev_func_output));
     fbdev_func_output.output_get_capability = fbdev_output_get_capability;
index a2c7d138934307dbf7875f6894589ec70250ec9d..49b7e6473e09bef1a48e641b7b88d42249a8eeb1 100644 (file)
@@ -22,7 +22,7 @@
 #include <tdm_log.h>
 #include <tdm_list.h>
 
-#define MAX_BUF 3
+#define MAX_BUF 1
 
 /* fbdev backend functions (display) */
 tdm_error    fbdev_display_get_capabilitiy(tdm_backend_data *bdata, tdm_caps_display *caps);
@@ -126,6 +126,9 @@ struct _tdm_fbdev_output_data
      */
     int is_vblank;
     int is_commit;
+
+    int sequence;
+
 };
 
 struct _tdm_fbdev_layer_data
index 32d834814315019b648cd59ca31b0fb346257a04..f077446fb5faf45ffda5eeed1330f9bd68333e6b 100644 (file)
@@ -91,6 +91,48 @@ _tdm_fbdev_layer_is_supproted_format()
 }
 */
 
+static inline uint32_t
+_get_refresh (struct fb_var_screeninfo *timing)
+{
+    uint32_t pixclock, hfreq, htotal, vtotal;
+
+    pixclock = PICOS2KHZ(timing->pixclock) * 1000;
+
+    htotal = timing->xres + timing->right_margin + timing->hsync_len + timing->left_margin;
+    vtotal = timing->yres + timing->lower_margin + timing->vsync_len + timing->upper_margin;
+
+    if (timing->vmode & FB_VMODE_INTERLACED) vtotal /= 2;
+    if (timing->vmode & FB_VMODE_DOUBLE) vtotal *= 2;
+
+    hfreq = pixclock / htotal;
+    return hfreq / vtotal;
+}
+
+/*
+ * Convert fb_var_screeninfo to tdm_output_mode
+ */
+static inline void
+_tdm_fbdev_display_to_tdm_mode(struct fb_var_screeninfo *timing, tdm_output_mode *mode)
+{
+
+    if (!timing->pixclock) return;
+
+    mode->clock = timing->pixclock / 1000;
+    mode->vrefresh = _get_refresh (timing);
+    mode->hdisplay = timing->xres;
+    mode->hsync_start = mode->hdisplay + timing->right_margin;
+    mode->hsync_end = mode->hsync_start + timing->hsync_len;
+    mode->htotal = mode->hsync_end + timing->left_margin;
+
+    mode->vdisplay = timing->yres;
+    mode->vsync_start = mode->vdisplay + timing->lower_margin;
+    mode->vsync_end = mode->vsync_start + timing->vsync_len;
+    mode->vtotal = mode->vsync_end + timing->upper_margin;
+
+    int interlaced = !!(timing->vmode & FB_VMODE_INTERLACED);
+    snprintf (mode->name, TDM_NAME_LEN, "%dx%d%s", mode->hdisplay, mode->vdisplay, interlaced ? "i" : "");
+}
+
 tdm_error
 tdm_fbdev_creat_output(tdm_fbdev_data *fbdev_data)
 {
@@ -138,6 +180,7 @@ tdm_fbdev_creat_output(tdm_fbdev_data *fbdev_data)
 
     output->is_vblank = DOWN;
     output->is_commit = DOWN;
+    output->sequence  = 1;
 
     /*
      * TODO: connector_type_id field relates to libdrm connector which framebuffer
@@ -156,11 +199,7 @@ tdm_fbdev_creat_output(tdm_fbdev_data *fbdev_data)
 
     for(i = 0; i < output->count_modes ; i++)
     {
-        output->output_modes[i].hdisplay = fbdev_data->vinfo->xres;
-        output->output_modes[i].vdisplay = fbdev_data->vinfo->yres;
-        output->output_modes[i].vrefresh = 60;
-        output->output_modes[i].flags = -1;
-        output->output_modes[i].type = -1;
+        _tdm_fbdev_display_to_tdm_mode(fbdev_data->vinfo, &output->output_modes[i]);
 
         sprintf(output->output_modes[i].name, "%dx%d",
                 fbdev_data->vinfo->xres,
@@ -233,7 +272,10 @@ void
 tdm_fbdev_destroy_layer(tdm_fbdev_data *fbdev_data)
 {
     tdm_fbdev_output_data *fbdev_output = fbdev_data->fbdev_output;
-    tdm_fbdev_layer_data *layer = fbdev_output->fbdev_layer;
+    tdm_fbdev_layer_data *layer;
+    if (!fbdev_output)
+           return;
+    layer = fbdev_output->fbdev_layer;
 
     if(layer != NULL)
         free(layer);
@@ -298,29 +340,6 @@ failed_get:
     return NULL;
 }
 
-tdm_error
-fbdev_display_get_fd(tdm_backend_data *bdata, int *fd)
-{
-    tdm_fbdev_data *fbdev_data = (tdm_fbdev_data *)bdata;
-    int file_fd;
-
-    RETURN_VAL_IF_FAIL(fbdev_data, TDM_ERROR_INVALID_PARAMETER);
-    RETURN_VAL_IF_FAIL(fd, TDM_ERROR_INVALID_PARAMETER);
-
-    /*
-     * Event-based applications use poll/select for pageflip or vsync events,
-     *  since farmebuffer does not produce such events we create common file.
-     *  Without this file application will be locked on poll/select or return
-     *  an error after timer expiring.
-     */
-    file_fd = open("/tmp/tdm_fbdev_select", O_RDWR | O_CREAT | O_TRUNC, ACCESSPERMS);
-    TDM_INFO("Open fake file: /tmp/tdm_fbdev_select %d", file_fd);
-
-    *fd = file_fd;
-
-    return TDM_ERROR_NONE;
-}
-
 tdm_error
 fbdev_display_handle_events(tdm_backend_data *bdata)
 {
@@ -544,7 +563,9 @@ fbdev_output_commit(tdm_output *output, int sync, void *user_data)
 {
     tdm_fbdev_output_data *fbdev_output = (tdm_fbdev_output_data *)output;
     tdm_fbdev_layer_data *fbdev_layer;
+#if 0
     tdm_fbdev_display_buffer *display_buffer;
+#endif
 
     RETURN_VAL_IF_FAIL(fbdev_output, TDM_ERROR_INVALID_PARAMETER);
 
@@ -557,19 +578,22 @@ fbdev_output_commit(tdm_output *output, int sync, void *user_data)
     fbdev_layer->display_buffer_changed = 0;
     fbdev_layer->info_changed = 0;
 
+#if 0
     display_buffer = fbdev_layer->display_buffer;
+#endif
 
     /*
-     * Display buffer's content to screen
+     * Disable copying to the buffer, everything is already rendered to SCANOUT.
      */
+#if 0
     memcpy(fbdev_output->mem, display_buffer->mem, display_buffer->size * sizeof(char) );
+#endif
 
-
-    /*
-     * Up fake flag to simulate page flip event
-     */
-    fbdev_output->is_commit = UP;
-    fbdev_output->user_data = user_data;
+    if (fbdev_output->commit_func)
+    {
+        TDM_ERR("trace");
+        fbdev_output->commit_func((tdm_output *)output, fbdev_output->sequence++, 0, 0, user_data);
+    }
 
     return TDM_ERROR_NONE;
 }
@@ -686,7 +710,7 @@ fbdev_output_get_mode(tdm_output *output, const tdm_output_mode **mode)
     tdm_fbdev_output_data *fbdev_output = (tdm_fbdev_output_data *)output;
 
     RETURN_VAL_IF_FAIL(fbdev_output, TDM_ERROR_INVALID_PARAMETER);
-    RETURN_VAL_IF_FAIL(*mode, TDM_ERROR_INVALID_PARAMETER);
+    RETURN_VAL_IF_FAIL(mode, TDM_ERROR_INVALID_PARAMETER);
 
     *mode = fbdev_output->current_mode;