Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Toggle main menu visibility
Loading...
Searching...
No Matches
brcmeglintegration.cpp
Go to the documentation of this file.
1
// Copyright (C) 2017 The Qt Company Ltd.
2
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
3
// Qt-Security score:critical reason:network-protocol
4
5
#
include
"brcmeglintegration.h"
6
#
include
"brcmbuffer.h"
7
#
include
<
QtWaylandCompositor
/
qwaylandsurface
.
h
>
8
#
include
<
qpa
/
qplatformnativeinterface
.
h
>
9
#
include
<
QtGui
/
QGuiApplication
>
10
#
include
<
QtGui
/
QOpenGLContext
>
11
#
include
<
QOpenGLTexture
>
12
#
include
<
qpa
/
qplatformscreen
.
h
>
13
#
include
<
QtGui
/
QWindow
>
14
15
#
include
<
EGL
/
egl
.
h
>
16
#
include
<
EGL
/
eglext
.
h
>
17
18
#
include
<
EGL
/
eglext_brcm
.
h
>
19
20
#
include
<
GLES2
/
gl2
.
h
>
21
#
include
<
GLES2
/
gl2ext
.
h
>
22
23
QT_BEGIN_NAMESPACE
24
25
class
BrcmEglIntegrationPrivate
26
{
27
public
:
28
BrcmEglIntegrationPrivate() =
default
;
29
30
static
BrcmEglIntegrationPrivate *get(BrcmEglIntegration *integration);
31
32
EGLDisplay egl_display = EGL_NO_DISPLAY;
33
bool
valid =
false
;
34
PFNEGLQUERYGLOBALIMAGEBRCMPROC eglQueryGlobalImageBRCM;
35
PFNGLEGLIMAGETARGETTEXTURE2DOESPROC glEGLImageTargetTexture2DOES;
36
PFNEGLCREATEIMAGEKHRPROC eglCreateImageKHR;
37
PFNEGLDESTROYIMAGEKHRPROC eglDestroyImageKHR;
38
};
39
40
BrcmEglIntegration
::BrcmEglIntegration()
41
: d_ptr(
new
BrcmEglIntegrationPrivate)
42
{
43
}
44
45
void
BrcmEglIntegration
::initializeHardware(
struct
::wl_display *display)
46
{
47
Q_D(BrcmEglIntegration);
48
49
QPlatformNativeInterface *nativeInterface = QGuiApplication::platformNativeInterface();
50
if
(nativeInterface) {
51
d->egl_display = nativeInterface->nativeResourceForIntegration(
"EglDisplay"
);
52
if
(!d->egl_display)
53
qWarning(
"Failed to acquire EGL display from platform integration"
);
54
55
d->eglQueryGlobalImageBRCM = (PFNEGLQUERYGLOBALIMAGEBRCMPROC) eglGetProcAddress(
"eglQueryGlobalImageBRCM"
);
56
57
if
(!d->eglQueryGlobalImageBRCM) {
58
qWarning(
"Failed to resolve eglQueryGlobalImageBRCM"
);
59
return
;
60
}
61
62
d->glEGLImageTargetTexture2DOES = (PFNGLEGLIMAGETARGETTEXTURE2DOESPROC)eglGetProcAddress(
"glEGLImageTargetTexture2DOES"
);
63
64
if
(!d->glEGLImageTargetTexture2DOES) {
65
qWarning(
"Failed to resolve glEGLImageTargetTexture2DOES"
);
66
return
;
67
}
68
69
d->eglCreateImageKHR = (PFNEGLCREATEIMAGEKHRPROC)eglGetProcAddress(
"eglCreateImageKHR"
);
70
71
if
(!d->eglCreateImageKHR) {
72
qWarning(
"Failed to resolve eglCreateImageKHR"
);
73
return
;
74
}
75
76
d->eglDestroyImageKHR = (PFNEGLDESTROYIMAGEKHRPROC)eglGetProcAddress(
"eglDestroyImageKHR"
);
77
78
if
(!d->eglDestroyImageKHR) {
79
qWarning(
"Failed to resolve eglDestroyImageKHR"
);
80
return
;
81
}
82
d->valid =
true
;
83
init(display, 1);
84
}
85
}
86
87
QtWayland
::
ClientBuffer
*
BrcmEglIntegration
::
createBufferFor
(wl_resource *buffer)
88
{
89
if
(wl_shm_buffer_get(buffer))
90
return
nullptr
;
91
return
new
BrcmEglClientBuffer
(
this
, buffer);
92
}
93
94
BrcmEglIntegrationPrivate *BrcmEglIntegrationPrivate::get(
BrcmEglIntegration
*integration)
95
{
96
return
integration->d_ptr.data();
97
}
98
99
QOpenGLTexture
*
BrcmEglClientBuffer
::
toOpenGlTexture
(
int
plane)
100
{
101
Q_UNUSED(plane);
102
103
auto
d = BrcmEglIntegrationPrivate::get(m_integration);
104
if
(!d->valid) {
105
qWarning(
"bindTextureToBuffer failed!"
);
106
return
nullptr
;
107
}
108
109
BrcmBuffer *brcmBuffer = BrcmBuffer::fromResource(m_buffer);
110
111
if
(!d->eglQueryGlobalImageBRCM(brcmBuffer->handle(), brcmBuffer->handle() + 2)) {
112
qWarning(
"eglQueryGlobalImageBRCM failed!"
);
113
return
nullptr
;
114
}
115
116
EGLImageKHR image = d->eglCreateImageKHR(d->egl_display, EGL_NO_CONTEXT, EGL_NATIVE_PIXMAP_KHR, (EGLClientBuffer)brcmBuffer->handle(), NULL);
117
if
(image == EGL_NO_IMAGE_KHR)
118
qWarning(
"eglCreateImageKHR() failed: %x\n"
, eglGetError());
119
120
if
(!m_texture) {
121
m_texture =
new
QOpenGLTexture(QOpenGLTexture::Target2D);
122
m_texture->create();
123
}
124
125
m_texture->bind();
126
127
d->glEGLImageTargetTexture2DOES(GL_TEXTURE_2D, image);
128
129
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
130
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
131
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S,
GL_CLAMP_TO_EDGE
);
132
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T,
GL_CLAMP_TO_EDGE
);
133
134
d->eglDestroyImageKHR(d->egl_display, image);
135
136
return
m_texture;
137
}
138
139
void
BrcmEglIntegration
::
brcm_bind_resource
(Resource *)
140
{
141
}
142
143
void
BrcmEglIntegration
::
brcm_create_buffer
(Resource *resource, uint32_t id, int32_t width, int32_t height, wl_array *data)
144
{
145
new
BrcmBuffer(resource->client(), id, QSize(width, height),
static_cast
<EGLint *>(data->data), data->size /
sizeof
(EGLint));
146
}
147
148
BrcmEglClientBuffer
::
BrcmEglClientBuffer
(
BrcmEglIntegration
*integration, wl_resource *buffer)
149
:
ClientBuffer
(
buffer
)
150
, m_integration(integration)
151
{
152
}
153
154
QWaylandBufferRef
::
BufferFormatEgl
BrcmEglClientBuffer
::
bufferFormatEgl
()
const
155
{
156
return
QWaylandBufferRef::BufferFormatEgl_RGBA;
157
}
158
159
QSize
BrcmEglClientBuffer
::
size
()
const
160
{
161
BrcmBuffer *brcmBuffer = BrcmBuffer::fromResource(m_buffer);
162
return
brcmBuffer->size();
163
}
164
165
QWaylandSurface
::
Origin
BrcmEglClientBuffer
::
origin
()
const
166
{
167
BrcmBuffer *brcmBuffer = BrcmBuffer::fromResource(m_buffer);
168
return
brcmBuffer->isYInverted() ? QWaylandSurface::OriginTopLeft : QWaylandSurface::OriginBottomLeft;
169
}
170
171
172
QT_END_NAMESPACE
BrcmEglClientBuffer
Definition
brcmeglintegration.h:38
BrcmEglClientBuffer::bufferFormatEgl
QWaylandBufferRef::BufferFormatEgl bufferFormatEgl() const override
Definition
brcmeglintegration.cpp:154
BrcmEglClientBuffer::size
QSize size() const override
Definition
brcmeglintegration.cpp:159
BrcmEglClientBuffer::BrcmEglClientBuffer
BrcmEglClientBuffer(BrcmEglIntegration *integration, wl_resource *buffer)
Definition
brcmeglintegration.cpp:148
BrcmEglClientBuffer::origin
QWaylandSurface::Origin origin() const override
Definition
brcmeglintegration.cpp:165
BrcmEglClientBuffer::toOpenGlTexture
QOpenGLTexture * toOpenGlTexture(int plane) override
Definition
brcmeglintegration.cpp:99
BrcmEglIntegration
Definition
brcmeglintegration.h:20
BrcmEglIntegration::brcm_bind_resource
void brcm_bind_resource(Resource *resource) override
Definition
brcmeglintegration.cpp:139
BrcmEglIntegration::createBufferFor
QtWayland::ClientBuffer * createBufferFor(wl_resource *buffer) override
Definition
brcmeglintegration.cpp:87
BrcmEglIntegration::brcm_create_buffer
void brcm_create_buffer(Resource *resource, uint32_t id, int32_t width, int32_t height, wl_array *data) override
Definition
brcmeglintegration.cpp:143
GL_CLAMP_TO_EDGE
#define GL_CLAMP_TO_EDGE
Definition
qopenglext.h:100
qtwayland
src
hardwareintegration
compositor
brcm-egl
brcmeglintegration.cpp
Generated on
for Qt by
1.18.0