summaryrefslogtreecommitdiff
path: root/clutter-gst/clutter-gst-types.c
blob: a4ec6f43732bfaffc054d2639689269add5edd3e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
/*
 * Clutter-GStreamer.
 *
 * GStreamer integration library for Clutter.
 *
 * clutter-gst-types.c - Some basic types.
 *
 * Authored by Lionel Landwerlin <lionel.g.landwerlin@linux.intel.com>
 *
 * Copyright (C) 2013 Intel Corporation
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the
 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
 * Boston, MA 02111-1307, USA.
 */

#include "clutter-gst-types.h"

ClutterGstFrame *
clutter_gst_frame_new (void)
{
  return g_slice_new0 (ClutterGstFrame);
}

static gpointer
clutter_gst_frame_copy (gpointer data)
{
  if (G_LIKELY (data))
    {
      ClutterGstFrame *frame = g_slice_dup (ClutterGstFrame, data);

      if (frame->pipeline != COGL_INVALID_HANDLE)
        frame->pipeline = cogl_pipeline_copy (frame->pipeline);

      return frame;
    }

  return NULL;
}

static void
clutter_gst_frame_free (gpointer data)
{
  if (G_LIKELY (data))
    {
      ClutterGstFrame *frame = (ClutterGstFrame *) data;

      if (frame->pipeline != COGL_INVALID_HANDLE)
        {
          cogl_object_unref (frame->pipeline);
          frame->pipeline = COGL_INVALID_HANDLE;
        }
      g_slice_free (ClutterGstFrame, frame);
    }
}

G_DEFINE_BOXED_TYPE (ClutterGstFrame,
                     clutter_gst_frame,
                     clutter_gst_frame_copy,
                     clutter_gst_frame_free);


ClutterGstOverlay *
clutter_gst_overlay_new (void)
{
  return g_slice_new0 (ClutterGstOverlay);
}

static gpointer
clutter_gst_overlay_copy (gpointer data)
{
  if (G_LIKELY (data))
    {
      ClutterGstOverlay *overlay = g_slice_dup (ClutterGstOverlay, data);

      if (overlay->pipeline != COGL_INVALID_HANDLE)
        overlay->pipeline = cogl_object_ref (overlay->pipeline);

      return overlay;
    }

  return NULL;
}

static void
clutter_gst_overlay_free (gpointer data)
{
  if (G_LIKELY (data))
    {
      ClutterGstOverlay *overlay = (ClutterGstOverlay *) data;

      if (overlay->pipeline != COGL_INVALID_HANDLE)
        {
          cogl_object_unref (overlay->pipeline);
          overlay->pipeline = COGL_INVALID_HANDLE;
        }
      g_slice_free (ClutterGstOverlay, overlay);
    }
}

G_DEFINE_BOXED_TYPE (ClutterGstOverlay,
                     clutter_gst_overlay,
                     clutter_gst_overlay_copy,
                     clutter_gst_overlay_free);

ClutterGstOverlays *
clutter_gst_overlays_new (void)
{
  ClutterGstOverlays *overlays = g_slice_new0 (ClutterGstOverlays);

  overlays->overlays = g_ptr_array_new_with_free_func (clutter_gst_overlay_free);

  return overlays;
}

static gpointer
clutter_gst_overlays_copy (gpointer data)
{
  if (G_LIKELY (data))
    {
      ClutterGstOverlays *overlays = clutter_gst_overlays_new ();
      GPtrArray *src_overlays = ((ClutterGstOverlays *) data)->overlays;
      guint i;

      for (i = 0; i < src_overlays->len; i++)
        g_ptr_array_add (overlays->overlays,
                         clutter_gst_overlay_copy (g_ptr_array_index (src_overlays,
                                                                      i)));
      return overlays;
    }

  return NULL;
}

static void
clutter_gst_overlays_free (gpointer data)
{
  if (G_LIKELY (data))
    {
      ClutterGstOverlays *overlays = (ClutterGstOverlays *) data;

      g_ptr_array_unref (overlays->overlays);

      g_slice_free (ClutterGstOverlays, overlays);
    }
}

G_DEFINE_BOXED_TYPE (ClutterGstOverlays,
                     clutter_gst_overlays,
                     clutter_gst_overlays_copy,
                     clutter_gst_overlays_free);

static ClutterGstBox *
clutter_gst_box_copy (const ClutterGstBox *box)
{
  if (G_LIKELY (box != NULL))
    return g_slice_dup (ClutterGstBox, box);

  return NULL;
}

static void
clutter_gst_box_free (ClutterGstBox *box)
{
  if (G_LIKELY (box != NULL))
    g_slice_free (ClutterGstBox, box);
}

G_DEFINE_BOXED_TYPE (ClutterGstBox,
                     clutter_gst_box,
                     clutter_gst_box_copy,
                     clutter_gst_box_free);

/**
 * clutter_gst_box_get_width:
 * @box: a #ClutterGstBox
 *
 * Retrieves the width of the @box
 *
 * Return value: the width of the box
 *
 * Since: 3.0
 */
gfloat
clutter_gst_box_get_width (const ClutterGstBox *box)
{
  g_return_val_if_fail (box != NULL, 0.);

  return box->x2 - box->x1;
}

/**
 * clutter_gst_box_get_height:
 * @box: a #ClutterGstBox
 *
 * Retrieves the height of the @box
 *
 * Return value: the height of the box
 *
 * Since: 3.0
 */
gfloat
clutter_gst_box_get_height (const ClutterGstBox *box)
{
  g_return_val_if_fail (box != NULL, 0.);

  return box->y2 - box->y1;
}