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
|
/*
* GStreamer
* Copyright (C) 2014 Sebastian Dröge <sebastian@centricular.com>
*
* This library is free software; you can redistribute it and/or
* modify it un der the terms of the GNU Library 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
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
* Boston, MA 02110-1301, USA.
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#import <OpenGLES/EAGL.h>
#import <QuartzCore/QuartzCore.h>
#import <UIKit/UIKit.h>
#include "gstglwindow_eagl.h"
#include "gstglcontext_eagl.h"
#define GST_GL_WINDOW_EAGL_GET_PRIVATE(o) \
(G_TYPE_INSTANCE_GET_PRIVATE((o), GST_GL_TYPE_WINDOW_EAGL, GstGLWindowEaglPrivate))
#define GST_CAT_DEFAULT gst_gl_window_eagl_debug
GST_DEBUG_CATEGORY_STATIC (GST_CAT_DEFAULT);
#define DEBUG_INIT \
GST_DEBUG_CATEGORY_GET (GST_CAT_DEFAULT, "glwindow");
#define gst_gl_window_eagl_parent_class parent_class
G_DEFINE_TYPE_WITH_CODE (GstGLWindowEagl, gst_gl_window_eagl,
GST_GL_TYPE_WINDOW, DEBUG_INIT);
static guintptr gst_gl_window_eagl_get_display (GstGLWindow * window);
static guintptr gst_gl_window_eagl_get_window_handle (GstGLWindow * window);
static void gst_gl_window_eagl_set_window_handle (GstGLWindow * window,
guintptr handle);
static void gst_gl_window_eagl_set_preferred_size (GstGLWindow * window,
gint width, gint height);
static void gst_gl_window_eagl_draw (GstGLWindow * window);
struct _GstGLWindowEaglPrivate
{
UIView *view;
gint window_width, window_height;
gint preferred_width, preferred_height;
};
static void
gst_gl_window_eagl_class_init (GstGLWindowEaglClass * klass)
{
GstGLWindowClass *window_class = (GstGLWindowClass *) klass;
g_type_class_add_private (klass, sizeof (GstGLWindowEaglPrivate));
window_class->get_display =
GST_DEBUG_FUNCPTR (gst_gl_window_eagl_get_display);
window_class->get_window_handle =
GST_DEBUG_FUNCPTR (gst_gl_window_eagl_get_window_handle);
window_class->set_window_handle =
GST_DEBUG_FUNCPTR (gst_gl_window_eagl_set_window_handle);
window_class->draw = GST_DEBUG_FUNCPTR (gst_gl_window_eagl_draw);
window_class->set_preferred_size =
GST_DEBUG_FUNCPTR (gst_gl_window_eagl_set_preferred_size);
}
static void
gst_gl_window_eagl_init (GstGLWindowEagl * window)
{
window->priv = GST_GL_WINDOW_EAGL_GET_PRIVATE (window);
}
/* Must be called in the gl thread */
GstGLWindowEagl *
gst_gl_window_eagl_new (GstGLDisplay * display)
{
/* there isn't an eagl display type */
return g_object_new (GST_GL_TYPE_WINDOW_EAGL, NULL);
}
static guintptr
gst_gl_window_eagl_get_display (GstGLWindow * window)
{
return 0;
}
static guintptr
gst_gl_window_eagl_get_window_handle (GstGLWindow * window)
{
return (guintptr) GST_GL_WINDOW_EAGL (window)->priv->view;
}
static void
gst_gl_window_eagl_set_window_handle (GstGLWindow * window, guintptr handle)
{
GstGLWindowEagl *window_eagl;
GstGLContext *context;
window_eagl = GST_GL_WINDOW_EAGL (window);
context = gst_gl_window_get_context (window);
window_eagl->priv->view = (UIView *) handle;
GST_INFO_OBJECT (context, "handle set, updating layer");
gst_gl_context_eagl_update_layer (context);
gst_object_unref (context);
}
static void
gst_gl_window_eagl_set_preferred_size (GstGLWindow * window, gint width, gint height)
{
GstGLWindowEagl *window_eagl = GST_GL_WINDOW_EAGL (window);
window_eagl->priv->preferred_width = width;
window_eagl->priv->preferred_height = height;
}
static void
draw_cb (gpointer data)
{
GstGLWindowEagl *window_eagl = data;
GstGLWindow *window = GST_GL_WINDOW (window_eagl);
GstGLContext *context = gst_gl_window_get_context (window);
GstGLContextEagl *eagl_context = GST_GL_CONTEXT_EAGL (context);
GstGLContextClass *context_class = GST_GL_CONTEXT_GET_CLASS (context);
if (window_eagl->priv->view) {
CGSize size;
CAEAGLLayer *eagl_layer;
eagl_layer = (CAEAGLLayer *)[window_eagl->priv->view layer];
size = eagl_layer.frame.size;
if (window->queue_resize || window_eagl->priv->window_width != size.width ||
window_eagl->priv->window_height != size.height) {
window_eagl->priv->window_width = size.width;
window_eagl->priv->window_height = size.height;
gst_gl_context_eagl_resize (eagl_context);
gst_gl_window_resize (window, window_eagl->priv->window_width,
window_eagl->priv->window_height);
}
}
gst_gl_context_eagl_prepare_draw (eagl_context);
if (window->draw)
window->draw (window->draw_data);
context_class->swap_buffers (context);
gst_gl_context_eagl_finish_draw (eagl_context);
gst_object_unref (context);
}
static void
gst_gl_window_eagl_draw (GstGLWindow * window)
{
gst_gl_window_send_message (window, (GstGLWindowCB) draw_cb, window);
}
|