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
|
/*
* vigs
*
* Copyright (c) 2000 - 2013 Samsung Electronics Co., Ltd. All rights reserved.
*
* Contact:
* Stanislav Vorobiov <s.vorobiov@samsung.com>
* Jinhyung Jo <jinhyung.jo@samsung.com>
* YeongKyoon Lee <yeongkyoon.lee@samsung.com>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
* Contributors:
* - S-Core Co., Ltd
*
*/
#include "vigs_qt5.h"
#include "config-host.h"
#include <QGuiApplication>
#include <QOpenGLContext>
#include <qpa/qplatformnativeinterface.h>
#include <stdio.h>
extern QApplication *qt5App;
extern QOpenGLContext *qt5GLContext;
extern QSurfaceFormat qt5GLFormat;
extern void qt5_register_capture_request_listener(void *listener,
void (*handler)(void *));
extern void qt5_unregister_capture_request_listener(void *listener);
extern void qt5_process_captured(bool captured, void *pixels,
int width, int height);
bool vigs_qt5_onscreen_enabled(void)
{
#ifndef CONFIG_DARWIN
/* Qt5 bug, QGLWidget has some problem on MacOS.
* (scrambled screen when resizing, invalid region masking) */
if (qt5App != NULL) {
return true;
}
#endif
return false;
}
void *vigs_qt5_display(void)
{
if (!qt5App) {
return NULL;
}
QPlatformNativeInterface *native =
QGuiApplication::platformNativeInterface();
return native->nativeResourceForScreen(QByteArray("display"),
QGuiApplication::primaryScreen());
}
void *vigs_qt5_gl_context_create(bool is_gl2)
{
if (!qt5App) {
fprintf(stderr, "QT5 not enabled!\n");
return NULL;
}
if (qt5GLContext) {
fprintf(stderr, "QT5 GL context already created!\n");
return NULL;
}
qt5GLContext = new QOpenGLContext();
QSurfaceFormat format;
format.setRedBufferSize(8);
format.setGreenBufferSize(8);
format.setBlueBufferSize(8);
format.setAlphaBufferSize(8);
format.setDepthBufferSize(24);
format.setStencilBufferSize(8);
if (!is_gl2) {
format.setMajorVersion(3);
#ifdef CONFIG_DARWIN
format.setMinorVersion(2);
format.setProfile(QSurfaceFormat::CoreProfile);
#else
format.setMinorVersion(1);
#endif
}
qt5GLContext->setScreen(QGuiApplication::primaryScreen());
qt5GLContext->setFormat(format);
if (!qt5GLContext->create()) {
fprintf(stderr, "Cannot create QT5 GL context!\n");
delete qt5GLContext;
qt5GLContext = NULL;
return NULL;
}
if (!is_gl2) {
if ((qt5GLContext->format().majorVersion() < 3) ||
((qt5GLContext->format().majorVersion() == 3) &&
(qt5GLContext->format().minorVersion() < 1))) {
fprintf(stderr, "Cannot create QT5 3.1 GL context!\n");
delete qt5GLContext;
qt5GLContext = NULL;
return NULL;
}
}
QPlatformNativeInterface *native =
QGuiApplication::platformNativeInterface();
void *ret = NULL;
#if defined(CONFIG_LINUX)
ret = native->nativeResourceForContext(QByteArray("glxcontext"), qt5GLContext);
#elif defined(CONFIG_WIN32)
ret = native->nativeResourceForContext(QByteArray("renderingContext"), qt5GLContext);
#elif defined(CONFIG_DARWIN)
ret = native->nativeResourceForContext(QByteArray("cglContextObj"), qt5GLContext);
#endif
if (!ret) {
fprintf(stderr, "Cannot get native QT5 GL context!\n");
delete qt5GLContext;
qt5GLContext = NULL;
}
qt5GLFormat = format;
return ret;
}
void vigs_qt5_register_capture_request_listener(void *listener,
void (*handler)(void *))
{
qt5_register_capture_request_listener(listener, handler);
}
void vigs_qt5_unregister_capture_request_listener(void *listener)
{
qt5_unregister_capture_request_listener(listener);
}
void vigs_qt5_process_captured(bool captured, void *pixels,
int width, int height)
{
qt5_process_captured(captured, pixels, width, height);
}
|