1 /*
2 * GStreamer
3 * Copyright (C) 2014 Matthew Waters <ystreet00@gmail.com>
4 * Copyright (C) 2015 Freescale Semiconductor <b55597@freescale.com>
5 * Copyright (C) 2017 Sebastian Dröge <sebastian@centricular.com>
6 *
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Library General Public
9 * License as published by the Free Software Foundation; either
10 * version 2 of the License, or (at your option) any later version.
11 *
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Library General Public License for more details.
16 *
17 * You should have received a copy of the GNU Library General Public
18 * License along with this library; if not, write to the
19 * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
20 * Boston, MA 02110-1301, USA.
21 */
22
23 #ifdef HAVE_CONFIG_H
24 #include "config.h"
25 #endif
26
27 #include "gstgldisplay_viv_fb.h"
28
29 GST_DEBUG_CATEGORY_STATIC (gst_gl_display_debug);
30 #define GST_CAT_DEFAULT gst_gl_display_debug
31
32 G_DEFINE_TYPE (GstGLDisplayVivFB, gst_gl_display_viv_fb, GST_TYPE_GL_DISPLAY);
33
34 static void gst_gl_display_viv_fb_finalize (GObject * object);
35 static guintptr gst_gl_display_viv_fb_get_handle (GstGLDisplay * display);
36
37 static void
gst_gl_display_viv_fb_class_init(GstGLDisplayVivFBClass * klass)38 gst_gl_display_viv_fb_class_init (GstGLDisplayVivFBClass * klass)
39 {
40 GST_GL_DISPLAY_CLASS (klass)->get_handle =
41 GST_DEBUG_FUNCPTR (gst_gl_display_viv_fb_get_handle);
42
43 G_OBJECT_CLASS (klass)->finalize = gst_gl_display_viv_fb_finalize;
44 }
45
46 static void
gst_gl_display_viv_fb_init(GstGLDisplayVivFB * display_viv_fb)47 gst_gl_display_viv_fb_init (GstGLDisplayVivFB * display_viv_fb)
48 {
49 GstGLDisplay *display = (GstGLDisplay *) display_viv_fb;
50
51 display->type = GST_GL_DISPLAY_TYPE_VIV_FB;
52
53 display_viv_fb->disp_idx = 0;
54 display_viv_fb->display = NULL;
55 }
56
57 static void
gst_gl_display_viv_fb_finalize(GObject * object)58 gst_gl_display_viv_fb_finalize (GObject * object)
59 {
60 GstGLDisplayVivFB *display_viv_fb = GST_GL_DISPLAY_VIV_FB (object);
61
62 // We don't destroy the FB Display - it causes crashes in applications
63 // because Vivante doesn't seem to do any refcounting
64
65 G_OBJECT_CLASS (gst_gl_display_viv_fb_parent_class)->finalize (object);
66 }
67
68 /**
69 * gst_gl_display_viv_fb_new:
70 * @disp_idx: a display index
71 *
72 * Create a new #GstGLDisplayVivFB from the FB display index.
73 *
74 * Returns: (transfer full): a new #GstGLDisplayVivFB or %NULL
75 */
76 GstGLDisplayVivFB *
gst_gl_display_viv_fb_new(gint disp_idx)77 gst_gl_display_viv_fb_new (gint disp_idx)
78 {
79 GstGLDisplayVivFB *display;
80
81 GST_DEBUG_CATEGORY_GET (gst_gl_display_debug, "gldisplay");
82
83 GST_DEBUG ("creating Vivante FB EGL display %d", disp_idx);
84
85 display = g_object_new (GST_TYPE_GL_DISPLAY_VIV_FB, NULL);
86 gst_object_ref_sink (display);
87 display->disp_idx = disp_idx;
88 display->display = fbGetDisplayByIndex (display->disp_idx);
89 if (!display->display) {
90 GST_ERROR ("Failed to open Vivante FB display %d", disp_idx);
91 return NULL;
92 }
93
94 GST_DEBUG ("Created Vivante FB EGL display %p", (gpointer) display->display);
95
96 return display;
97 }
98
99 static guintptr
gst_gl_display_viv_fb_get_handle(GstGLDisplay * display)100 gst_gl_display_viv_fb_get_handle (GstGLDisplay * display)
101 {
102 return (guintptr) GST_GL_DISPLAY_VIV_FB (display)->display;
103 }
104