Added TI patches, generated from commit 04f9d72 of the following tree:
[ubuntu-omap:gst-plugins-bad1-0.git] / debian / patches / 0052-dri2-Implement-a-wrapper-around-DRI2Buffer.patch
1 From a8f7fdcb2bfc63246471bd7189674b663786ed04 Mon Sep 17 00:00:00 2001
2 From: Thibault Saunier <thibault.saunier@collabora.com>
3 Date: Tue, 13 Nov 2012 17:14:10 -0300
4 Subject: [PATCH 052/100] dri2: Implement a wrapper around DRI2Buffer
5
6 This way we can just
7 ---
8  sys/dri2/gstdri2bufferpool.c |   32 ++++++++++++++++++++----
9  sys/dri2/gstdri2bufferpool.h |    2 +-
10  sys/dri2/gstdri2util.c       |   56 ++++++++++++++++++++++++++++++++++++------
11  sys/dri2/gstdri2util.h       |   34 +++++++++++++++++++------
12  4 files changed, 104 insertions(+), 20 deletions(-)
13
14 diff --git a/sys/dri2/gstdri2bufferpool.c b/sys/dri2/gstdri2bufferpool.c
15 index 487d3ff..32e8fff 100755
16 --- a/sys/dri2/gstdri2bufferpool.c
17 +++ b/sys/dri2/gstdri2bufferpool.c
18 @@ -76,7 +76,7 @@ gst_dri2_pool_alloc_buffer (GstBufferPool * pool, GstBuffer ** buffer,
19    }
20  
21    GST_DEBUG_OBJECT (pool, "Allocating new buffer");
22 -  dri2meta->dri2buf = gst_dri2window_get_dri2buffer (dri2pool->xwindow,
23 +  dri2meta->gstdri2buf = gst_dri2_buffer_new (dri2pool->xwindow,
24        info->width, info->height,
25        gst_video_format_to_fourcc (info->finfo->format));
26    dri2meta->xwindow = gst_dri2window_ref (dri2pool->xwindow);
27 @@ -84,10 +84,10 @@ gst_dri2_pool_alloc_buffer (GstBufferPool * pool, GstBuffer ** buffer,
28    /* we can't really properly support multi-planar w/ separate buffers
29     * in gst0.10..  we need a way to indicate this to the server!
30     */
31 -  g_warn_if_fail (dri2meta->dri2buf->names[1] == 0);
32 +  g_warn_if_fail (dri2meta->gstdri2buf->dri2buf->names[1] == 0);
33  
34    bo = omap_bo_from_name (GST_DRM_BUFFER_POOL (pool)->dev,
35 -      dri2meta->dri2buf->names[0]);
36 +      dri2meta->gstdri2buf->dri2buf->names[0]);
37    gst_buffer_add_drm_meta (*buffer, pool, bo);
38  
39    return gst_drm_buffer_pool_finnish_alloc (pool, buffer, params);
40 @@ -125,7 +125,7 @@ gst_dri2_buffer_pool_init (GstDRI2BufferPool * self)
41  static void
42  gst_dri2_meta_free (GstDRI2Meta * meta, GstBuffer * buf)
43  {
44 -  gst_dri2window_free_dri2buffer (meta->xwindow, meta->dri2buf);
45 +  gst_dri2_buffer_unref (meta->gstdri2buf);
46    gst_dri2window_unref (meta->xwindow);
47  
48    return;
49 @@ -145,6 +145,28 @@ gst_dri2_meta_api_get_type (void)
50    return type;
51  }
52  
53 +static gboolean
54 +gst_dri2_meta_transform (GstBuffer * dest, GstMeta * meta,
55 +    GstBuffer * buffer, GQuark type, gpointer data)
56 +{
57 +
58 +  if (GST_META_TRANSFORM_IS_COPY (type)) {
59 +    GstDRI2Meta *new_meta, *dri2meta = (GstDRI2Meta *) meta;
60 +    GST_DEBUG ("Copying DRI2Meta meta %p from %p to %p", meta, buffer, dest);
61 +
62 +    new_meta = (GstDRI2Meta *) gst_buffer_add_meta (dest, GST_DRI2_META_INFO,
63 +      NULL);
64 +
65 +    if (new_meta == NULL)
66 +      return FALSE;
67 +
68 +    new_meta->gstdri2buf = gst_dri2_buffer_ref (dri2meta->gstdri2buf);
69 +    new_meta->xwindow = gst_dri2window_ref (dri2meta->xwindow);
70 +  }
71 +
72 +  return TRUE;
73 +}
74 +
75  const GstMetaInfo *
76  gst_dri2_meta_get_info (void)
77  {
78 @@ -152,7 +174,7 @@ gst_dri2_meta_get_info (void)
79  
80    if (dri2_meta_info == NULL) {
81      dri2_meta_info = gst_meta_register (GST_DRI2_META_API_TYPE, "GstDRI2Meta", sizeof (GstDRI2Meta), NULL,      /* No init needed */
82 -        (GstMetaFreeFunction) gst_dri2_meta_free, NULL);
83 +        (GstMetaFreeFunction) gst_dri2_meta_free, (GstMetaTransformFunction) gst_dri2_meta_transform);
84    }
85    return dri2_meta_info;
86  }
87 diff --git a/sys/dri2/gstdri2bufferpool.h b/sys/dri2/gstdri2bufferpool.h
88 index 70d1306..27a7cdd 100644
89 --- a/sys/dri2/gstdri2bufferpool.h
90 +++ b/sys/dri2/gstdri2bufferpool.h
91 @@ -75,7 +75,7 @@ typedef struct _GstDRI2Meta GstDRI2Meta;
92  struct _GstDRI2Meta {
93    GstMeta parent;
94  
95 -  DRI2Buffer *dri2buf;
96 +  GstDRI2Buffer *gstdri2buf;
97  
98    GstDRI2Window *xwindow;
99    /* FIXME Do we need that? */
100 diff --git a/sys/dri2/gstdri2util.c b/sys/dri2/gstdri2util.c
101 index 50b762e..96b8d84 100644
102 --- a/sys/dri2/gstdri2util.c
103 +++ b/sys/dri2/gstdri2util.c
104 @@ -591,7 +591,7 @@ gst_dri2window_buffer_show (GstDRI2Window * xwindow, GstBuffer * buf)
105  
106    GST_DRI2CONTEXT_LOCK_X (dcontext);
107    DRI2SwapBuffersVid (dcontext->x_display, xwindow->window, 0, 0, 0,
108 -      &count, dri2meta->dri2buf->attachment, &b);
109 +      &count, dri2meta->gstdri2buf->dri2buf->attachment, &b);
110  
111    /* TODO: probably should wait for DRI2_BufferSwapComplete instead..
112     * although that probably depends on someone making an x11 call to
113 @@ -618,11 +618,11 @@ gst_dri2window_buffer_prepare (GstDRI2Window * xwindow, GstBuffer * buf)
114    GstElement *sink = xwindow->dcontext->elem;
115  
116    if (ok_buffer (xwindow, buf)) {
117 -    GST_DEBUG_OBJECT (sink, "Buffer %" GST_PTR_FORMAT " is OK, using it", buf);
118 +    GST_DEBUG_OBJECT (sink, "Buffer %p is OK, using it", buf);
119      return gst_buffer_ref (buf);
120    }
121  
122 -  GST_WARNING_OBJECT (sink, "Not our buffer, making a copy");
123 +  GST_WARNING_OBJECT (sink, "%p: Not our buffer, making a copy", buf);
124    /* DRI2 on OMAP has a 32 quantization step for strides, so we copy
125       the buffer into another buffer with a size that's to its liking */
126    format = xwindow->info.finfo->format;
127 @@ -802,8 +802,8 @@ get_buffer (GstDRI2Window * xwindow, guint attach, gint width, gint height,
128    return dri2buf;
129  }
130  
131 -DRI2Buffer *
132 -gst_dri2window_get_dri2buffer (GstDRI2Window * xwindow, gint width, gint height,
133 +static DRI2Buffer *
134 +gst_dri2window_get_dri2_buffer (GstDRI2Window * xwindow, gint width, gint height,
135      guint32 format)
136  {
137    GstDRI2Context *dcontext = xwindow->dcontext;
138 @@ -814,6 +814,7 @@ gst_dri2window_get_dri2buffer (GstDRI2Window * xwindow, gint width, gint height,
139     */
140    for (idx = 0; idx < G_N_ELEMENTS (xwindow->dri2bufs); idx++) {
141      if (!xwindow->dri2bufs[idx]) {
142 +      GST_DEBUG ("Getting dri2buffer idx: %i", idx);
143        xwindow->dri2bufs[idx] = get_buffer (xwindow, idx + 1,
144            width, height, format);
145        g_warn_if_fail ((xwindow->dri2bufs[idx]->attachment - 1) == idx);
146 @@ -826,8 +827,8 @@ gst_dri2window_get_dri2buffer (GstDRI2Window * xwindow, gint width, gint height,
147    return NULL;
148  }
149  
150 -void
151 -gst_dri2window_free_dri2buffer (GstDRI2Window * xwindow, DRI2Buffer * dri2buf)
152 +static void
153 +gst_dri2window_free_dri2_buffer (GstDRI2Window * xwindow, DRI2Buffer * dri2buf)
154  {
155    int idx = dri2buf->attachment - 1;
156  
157 @@ -838,3 +839,44 @@ gst_dri2window_free_dri2buffer (GstDRI2Window * xwindow, DRI2Buffer * dri2buf)
158    free (xwindow->dri2bufs[idx]);
159    xwindow->dri2bufs[idx] = NULL;
160  }
161 +
162 +/*
163 + * GstDRI2Buffer
164 + */
165 +
166 +GType _gst_dri2_buffer_type = 0;
167 +
168 +GST_DEFINE_MINI_OBJECT_TYPE (GstDRI2Buffer, gst_dri2_buffer);
169 +
170 +static void
171 +gst_dri2_buffer_finalize (GstDRI2Buffer * buffer)
172 +{
173 +  gst_dri2window_free_dri2_buffer (buffer->window, buffer->dri2buf);
174 +  gst_dri2window_unref (buffer->window);
175 +
176 +}
177 +
178 +GstDRI2Buffer *
179 +gst_dri2_buffer_new (GstDRI2Window * window, gint width, gint height,
180 +    guint32 format)
181 +{
182 +  DRI2Buffer *dri2buf;
183 +  GstDRI2Buffer *buffer;
184 +
185 +  g_return_val_if_fail (GST_IS_DRI2WINDOW (window), NULL);
186 +
187 +  dri2buf = gst_dri2window_get_dri2_buffer (window, width, height, format);
188 +
189 +  if (dri2buf == NULL)
190 +    return NULL;
191 +
192 +  buffer = g_slice_new (GstDRI2Buffer);
193 +  gst_mini_object_init (GST_MINI_OBJECT_CAST (buffer),
194 +      0, _gst_dri2_buffer_type, NULL, NULL,
195 +      (GstMiniObjectFreeFunction) gst_dri2_buffer_finalize);
196 +
197 +  buffer->window  = gst_dri2window_ref (window);
198 +  buffer->dri2buf = dri2buf;
199 +
200 +  return buffer;
201 +}
202 diff --git a/sys/dri2/gstdri2util.h b/sys/dri2/gstdri2util.h
203 index de2b9ce..669d3b7 100644
204 --- a/sys/dri2/gstdri2util.h
205 +++ b/sys/dri2/gstdri2util.h
206 @@ -50,6 +50,7 @@ GST_DEBUG_CATEGORY_EXTERN (gst_debug_dri2);
207  
208  typedef struct _GstDRI2Context GstDRI2Context;
209  typedef struct _GstDRI2Window GstDRI2Window;
210 +typedef struct _GstDRI2Buffer GstDRI2Buffer;
211  
212  /*
213   * GstDRI2DrawContext
214 @@ -150,12 +151,31 @@ GstFlowReturn   gst_dri2window_buffer_alloc    (GstDRI2Window * xwindow,
215  gboolean        gst_dri2window_create_pool     (GstDRI2Window * xwindow,
216                                                  GstVideoInfo *info,
217                                                  GstCaps * caps);
218 -/* used by GstDRI2BufferPool: */
219 -DRI2Buffer * gst_dri2window_get_dri2buffer     (GstDRI2Window * xwindow,
220 -                                                gint width,
221 -                                                gint height,
222 -                                                guint32 format);
223 -void gst_dri2window_free_dri2buffer            (GstDRI2Window * xwindow,
224 -                                                DRI2Buffer * dri2buf);
225 +
226 +
227 +/**
228 + * GstDRI2Buffer: Wrapper around DRI2Buffer to have refcounting
229 + **/
230 +GST_EXPORT GType _gst_dri2_buffer_type;
231 +
232 +#define GST_TYPE_DRI2BUFFER                    (_gst_dri2_buffer_type)
233 +#define GST_IS_DRI2BUFFER(obj)                 (GST_IS_MINI_OBJECT_TYPE(obj, GST_TYPE_DRI2BUFFER))
234 +#define GST_DRI2BUFFER(obj)                    ((GstDRI2Buffer*)(obj))
235 +
236 +#define gst_dri2_buffer_ref(obj)               (GST_DRI2BUFFER (gst_mini_object_ref (GST_MINI_OBJECT (obj))));
237 +#define gst_dri2_buffer_unref(obj)             (gst_mini_object_unref (GST_MINI_OBJECT (obj)));
238 +
239 +struct _GstDRI2Buffer
240 +{
241 +  GstMiniObject parent;
242 +  DRI2Buffer *dri2buf;
243 +  GstDRI2Window *window;
244 +};
245 +
246 +GType           gst_dri2_buffer_get_type         (void);
247 +GstDRI2Buffer * gst_dri2_buffer_new              (GstDRI2Window * window,
248 +                                                  gint width,
249 +                                                  gint height,
250 +                                                  guint32 format);
251  
252  #endif /* __GSTDRI2UTIL_H__ */
253 -- 
254 1.7.9.5
255