dri2videosink: refcount dri2window
[gstreamer-omap:gst-plugins-bad.git] / sys / dri2 / gstdri2bufferpool.c
1 /*
2  * GStreamer
3  *
4  * Copyright (C) 2012 Texas Instruments
5  * Copyright (C) 2012 Collabora Ltd
6  *
7  * Authors:
8  *  Alessandro Decina <alessandro.decina@collabora.co.uk>
9  *  Rob Clark <rob.clark@linaro.org>
10  *
11  * This library is free software; you can redistribute it and/or
12  * modify it under the terms of the GNU Lesser General Public
13  * License as published by the Free Software Foundation
14  * version 2.1 of the License.
15  *
16  * This library is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19  * Lesser General Public License for more details.
20  *
21  * You should have received a copy of the GNU Lesser General Public
22  * License along with this library; if not, write to the Free Software
23  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
24  */
25
26 #ifdef HAVE_CONFIG_H
27 #include "config.h"
28 #endif
29
30 #include "gstdri2bufferpool.h"
31
32 /*
33  * GstDRI2BufferPool:
34  */
35
36 static GstMiniObjectClass * gst_dri2bufferpool_parent_class = NULL;
37
38 G_DEFINE_TYPE (GstDRI2BufferPool, gst_dri2_buffer_pool,
39     GST_TYPE_DRM_BUFFER_POOL);
40
41 GstDRI2BufferPool *
42 gst_dri2_buffer_pool_new (GstDRI2Window * xwindow,
43     int fd, GstCaps * caps, guint size)
44 {
45   GstDRI2BufferPool *self = (GstDRI2BufferPool *)
46       gst_mini_object_new (GST_TYPE_DRI2_BUFFER_POOL);
47
48   gst_drm_buffer_pool_initialize (GST_DRM_BUFFER_POOL (self),
49       xwindow->dcontext->elem, fd, caps, size);
50
51   gst_mini_object_ref (GST_MINI_OBJECT (xwindow));
52   self->xwindow = xwindow;
53
54   return self;
55 }
56
57 static GstDRMBuffer *
58 gst_dri2_buffer_alloc (GstDRMBufferPool * pool)
59 {
60   GstDRI2BufferPool *dri2pool = GST_DRI2_BUFFER_POOL (pool);
61   GstDRI2Buffer *self = (GstDRI2Buffer *)
62       gst_mini_object_new (GST_TYPE_DRI2_BUFFER);
63   struct omap_bo *bo;
64
65   gst_mini_object_ref (GST_MINI_OBJECT (pool));
66
67   self->dri2buf = gst_dri2window_get_dri2buffer (dri2pool->xwindow,
68       pool->width, pool->height, pool->fourcc);
69
70   /* we can't really properly support multi-planar w/ separate buffers
71    * in gst0.10..  we need a way to indicate this to the server!
72    */
73   g_warn_if_fail (self->dri2buf->names[1] == 0);
74
75   bo = omap_bo_from_name (pool->dev, self->dri2buf->names[0]);
76   gst_drm_buffer_initialize (GST_DRM_BUFFER (self), pool, bo);
77
78   return GST_DRM_BUFFER (self);
79 }
80
81 static void
82 gst_dri2_buffer_cleanup (GstDRMBufferPool * pool, GstDRMBuffer * buf)
83 {
84   gst_dri2window_free_dri2buffer (
85       GST_DRI2_BUFFER_POOL (pool)->xwindow,
86       GST_DRI2_BUFFER (buf)->dri2buf);
87   gst_mini_object_unref (GST_MINI_OBJECT (pool));
88 }
89
90 static void
91 gst_dri2_buffer_pool_finalize (GstDRMBufferPool * pool)
92 {
93   gst_mini_object_unref (GST_MINI_OBJECT (GST_DRI2_BUFFER_POOL(pool)->xwindow));
94   GST_MINI_OBJECT_CLASS (gst_dri2bufferpool_parent_class)->finalize (GST_MINI_OBJECT
95       (pool));
96 }
97
98 static void
99 gst_dri2_buffer_pool_class_init (GstDRI2BufferPoolClass * klass)
100 {
101   GST_DRM_BUFFER_POOL_CLASS (klass)->buffer_alloc =
102       GST_DEBUG_FUNCPTR (gst_dri2_buffer_alloc);
103   GST_DRM_BUFFER_POOL_CLASS (klass)->buffer_cleanup =
104       GST_DEBUG_FUNCPTR (gst_dri2_buffer_cleanup);
105   GST_MINI_OBJECT_CLASS (klass)->finalize =
106       (GstMiniObjectFinalizeFunction) GST_DEBUG_FUNCPTR (gst_dri2_buffer_pool_finalize);
107   gst_dri2bufferpool_parent_class = g_type_class_peek_parent (klass);
108 }
109
110 static void
111 gst_dri2_buffer_pool_init (GstDRI2BufferPool * self)
112 {
113 }
114
115 /*
116  * GstDRI2Buffer:
117  */
118
119
120 G_DEFINE_TYPE (GstDRI2Buffer, gst_dri2_buffer, GST_TYPE_DRM_BUFFER);
121
122 static void
123 gst_dri2_buffer_class_init (GstDRI2BufferClass * klass)
124 {
125 }
126
127 static void
128 gst_dri2_buffer_init (GstDRI2Buffer * buffer)
129 {
130 }