tdm: add pepper_tdm_output_create_gl_renderer function 82/263882/1
authorSooChan Lim <sc1.lim@samsung.com>
Mon, 13 Sep 2021 05:45:18 +0000 (14:45 +0900)
committerSooChan Lim <sc1.lim@samsung.com>
Mon, 13 Sep 2021 06:22:51 +0000 (15:22 +0900)
This function provides pepper_tdm_renderer which contains
built-in gl renderer.

Change-Id: I94215569ed8eb35eac4e9e86089a1f7353987749

src/lib/tdm/Makefile.am
src/lib/tdm/pepper-tdm.h
src/lib/tdm/tdm-renderer-gl.c [new file with mode: 0644]

index 597927e..e6b9768 100644 (file)
@@ -13,4 +13,5 @@ libpepper_tdm_la_SOURCES =  tdm-internal.h        \
                             tdm-output.c          \
                             tdm-hwc.c             \
                             tdm-renderer.c        \
-                            tdm-renderer-pixman.c
+                            tdm-renderer-pixman.c \
+                            tdm-renderer-gl.c
index d407b8f..b68a075 100644 (file)
@@ -103,6 +103,9 @@ pepper_tdm_output_create_renderer(pepper_tdm_output_t *output,
 PEPPER_API pepper_tdm_renderer_t *
 pepper_tdm_output_create_pixman_renderer(pepper_tdm_output_t *output);
 
+PEPPER_API pepper_tdm_renderer_t *
+pepper_tdm_output_create_gl_renderer(pepper_tdm_output_t *output);
+
 PEPPER_API void
 pepper_tdm_renderer_destroy(pepper_tdm_renderer_t *renderer);
 
diff --git a/src/lib/tdm/tdm-renderer-gl.c b/src/lib/tdm/tdm-renderer-gl.c
new file mode 100644 (file)
index 0000000..4a3ddb9
--- /dev/null
@@ -0,0 +1,180 @@
+/*
+* Copyright © 2021 Samsung Electronics co., Ltd. All Rights Reserved.
+*
+* Permission is hereby granted, free of charge, to any person obtaining a
+* copy of this software and associated documentation files (the "Software"),
+* to deal in the Software without restriction, including without limitation
+* the rights to use, copy, modify, merge, publish, distribute, sublicense,
+* and/or sell copies of the Software, and to permit persons to whom the
+* Software is furnished to do so, subject to the following conditions:
+*
+* The above copyright notice and this permission notice (including the next
+* paragraph) shall be included in all copies or substantial portions of the
+* Software.
+*
+* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+* DEALINGS IN THE SOFTWARE.
+*/
+
+#include "tdm-internal.h"
+#include <pepper-gl-renderer.h>
+
+typedef struct pepper_tdm_renderer_gl_data  pepper_tdm_renderer_gl_data_t;
+
+struct pepper_tdm_renderer_gl_data {
+       pepper_renderer_t        *renderer;
+       pepper_render_target_t   *target;
+       tbm_surface_queue_h       tsurface_queue;
+       tbm_bufmgr                bufmgr;
+
+       pepper_compositor_t      *compositor;
+       pepper_tdm_output_t      *output;
+};
+
+static void
+pepper_tdm_renderer_gl_destroy_impl(void *renderer_data)
+{
+       PEPPER_INFO("\n");
+
+       pepper_tdm_renderer_gl_data_t *gl_data = renderer_data;
+
+       if (gl_data->target)
+               pepper_render_target_destroy(gl_data->target);
+
+       if (gl_data->renderer)
+               pepper_renderer_destroy(gl_data->renderer);
+
+       free(gl_data);
+}
+
+static pepper_bool_t
+pepper_tdm_renderer_gl_setup_impl(void *renderer_data)
+{
+       PEPPER_INFO("\n");
+
+       pepper_tdm_renderer_gl_data_t *gl_data = renderer_data;
+       uint32_t native_visual_id = TBM_FORMAT_XRGB8888;
+       int w, h;
+
+       gl_data->renderer = pepper_gl_renderer_create(gl_data->compositor,
+                                                                                               gl_data->bufmgr, "tbm");
+       PEPPER_CHECK(gl_data->renderer, return PEPPER_FALSE,
+                               "pepper_gl_renderer_create() failed.\n");
+
+       w = tbm_surface_queue_get_width(gl_data->tsurface_queue);
+       h = tbm_surface_queue_get_height(gl_data->tsurface_queue);
+
+       gl_data->target = pepper_gl_renderer_create_target(gl_data->renderer,
+                                                                                                       gl_data->tsurface_queue,
+                                                                                                       PEPPER_FORMAT_XRGB8888,
+                                                                                                       &native_visual_id,
+                                                                                                       w, h);
+       PEPPER_CHECK(gl_data->target, goto error,
+                                        "pepper_gl_renderer_create_target() failed.\n");
+
+       pepper_renderer_set_target(gl_data->renderer, gl_data->target);
+
+       return PEPPER_TRUE;
+
+error:
+       pepper_tdm_renderer_gl_destroy_impl((void *)gl_data);
+
+       return PEPPER_FALSE;
+}
+
+static pepper_bool_t
+pepper_tdm_renderer_gl_attach_surface_impl(void *renderer_data,
+                                                                               pepper_surface_t *surface,
+                                                                               int *w, int *h)
+{
+       PEPPER_INFO("\n");
+
+       pepper_tdm_renderer_gl_data_t *gl_data = renderer_data;
+
+       pepper_renderer_attach_surface(gl_data->renderer, surface, w, h);
+
+       return PEPPER_TRUE;
+}
+
+static pepper_bool_t
+pepper_tdm_renderer_gl_flush_surface_damage_impl(void *renderer_data,
+                                                                                       pepper_surface_t *surface)
+{
+       PEPPER_INFO("\n");
+
+       pepper_tdm_renderer_gl_data_t *gl_data = renderer_data;
+
+       pepper_renderer_flush_surface_damage(gl_data->renderer, surface);
+
+       return PEPPER_TRUE;
+}
+
+static pepper_bool_t
+pepper_tdm_renderer_gl_render_once_impl(void *renderer_data,
+                                                                       const pepper_list_t *render_list,
+                                                                       pepper_region_t *damage)
+{
+       PEPPER_INFO("\n");
+
+       pepper_tdm_renderer_gl_data_t *gl_data =  renderer_data;
+       pepper_output_t *output = pepper_tdm_output_get_pepper_output(gl_data->output);
+
+       pepper_renderer_repaint_output(gl_data->renderer, output, render_list,
+                                                                       damage);
+
+       return PEPPER_TRUE;
+}
+
+static const pepper_tdm_renderer_iface_t tdm_renderer_gl_iface = {
+       pepper_tdm_renderer_gl_destroy_impl,
+       pepper_tdm_renderer_gl_setup_impl,
+       pepper_tdm_renderer_gl_attach_surface_impl,
+       pepper_tdm_renderer_gl_flush_surface_damage_impl,
+       pepper_tdm_renderer_gl_render_once_impl,
+};
+
+PEPPER_API pepper_tdm_renderer_t *
+pepper_tdm_output_create_gl_renderer(pepper_tdm_output_t *output)
+{
+       pepper_tdm_renderer_t         *renderer;
+       pepper_tdm_renderer_gl_data_t *gl_data = NULL;
+       tbm_surface_queue_h            tsurface_queue;
+
+       PEPPER_CHECK(!output->renderer, return PEPPER_FALSE,
+                               "renderer:%p already assigned.\n");
+
+       tsurface_queue = pepper_tdm_output_get_display_buffer_queue(output);
+       PEPPER_CHECK(tsurface_queue, return PEPPER_FALSE,
+                               "pepper_tdm_output_get_display_buffer_queue() failed.\n");
+
+       gl_data = calloc(1, sizeof(pepper_tdm_renderer_gl_data_t));
+       PEPPER_CHECK(tsurface_queue, return PEPPER_FALSE,
+                               "fail to allocate pepper_tdm_renderer_gl_data_t.\n");
+
+       gl_data->tsurface_queue = tsurface_queue;
+       gl_data->bufmgr = output->tdm->bufmgr;
+       gl_data->compositor = output->tdm->compositor;
+       gl_data->output = output;
+
+       renderer = pepper_tdm_output_create_renderer(output,
+                                                                                       &tdm_renderer_gl_iface,
+                                                                                       tsurface_queue,
+                                                                                       (void *)gl_data);
+       PEPPER_CHECK(renderer, goto error,
+                               "pepper_tdm_output_create_renderer() failed.\n");
+
+       output->render_type = TDM_RENDER_TYPE_PIXMAN;
+
+       return renderer;
+
+error:
+       if (gl_data)
+               free(gl_data);
+
+       return NULL;
+}