Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
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
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
23QT_BEGIN_NAMESPACE
24
25class BrcmEglIntegrationPrivate
26{
27public:
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
40BrcmEglIntegration::BrcmEglIntegration()
41 : d_ptr(new BrcmEglIntegrationPrivate)
42{
43}
44
45void 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
88{
89 if (wl_shm_buffer_get(buffer))
90 return nullptr;
91 return new BrcmEglClientBuffer(this, buffer);
92}
93
94BrcmEglIntegrationPrivate *BrcmEglIntegrationPrivate::get(BrcmEglIntegration *integration)
95{
96 return integration->d_ptr.data();
97}
98
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
140{
141}
142
143void 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
150 , m_integration(integration)
151{
152}
153
155{
156 return QWaylandBufferRef::BufferFormatEgl_RGBA;
157}
158
160{
161 BrcmBuffer *brcmBuffer = BrcmBuffer::fromResource(m_buffer);
162 return brcmBuffer->size();
163}
164
166{
167 BrcmBuffer *brcmBuffer = BrcmBuffer::fromResource(m_buffer);
168 return brcmBuffer->isYInverted() ? QWaylandSurface::OriginTopLeft : QWaylandSurface::OriginBottomLeft;
169}
170
171
172QT_END_NAMESPACE
QWaylandBufferRef::BufferFormatEgl bufferFormatEgl() const override
QSize size() const override
BrcmEglClientBuffer(BrcmEglIntegration *integration, wl_resource *buffer)
QWaylandSurface::Origin origin() const override
QOpenGLTexture * toOpenGlTexture(int plane) override
void brcm_bind_resource(Resource *resource) override
QtWayland::ClientBuffer * createBufferFor(wl_resource *buffer) override
void brcm_create_buffer(Resource *resource, uint32_t id, int32_t width, int32_t height, wl_array *data) override
#define GL_CLAMP_TO_EDGE
Definition qopenglext.h:100