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
5#include "brcmbuffer.h"
6#include <QtWaylandCompositor/qwaylandsurface.h>
7#include <qpa/qplatformnativeinterface.h>
8#include <QtGui/QGuiApplication>
9#include <QtGui/QOpenGLContext>
10#include <QOpenGLTexture>
11#include <qpa/qplatformscreen.h>
12#include <QtGui/QWindow>
13
14#include <EGL/egl.h>
15#include <EGL/eglext.h>
16
17#include <EGL/eglext_brcm.h>
18
19#include <GLES2/gl2.h>
20#include <GLES2/gl2ext.h>
21
22QT_BEGIN_NAMESPACE
23
24class BrcmEglIntegrationPrivate
25{
26public:
27 BrcmEglIntegrationPrivate() = default;
28
29 static BrcmEglIntegrationPrivate *get(BrcmEglIntegration *integration);
30
31 EGLDisplay egl_display = EGL_NO_DISPLAY;
32 bool valid = false;
33 PFNEGLQUERYGLOBALIMAGEBRCMPROC eglQueryGlobalImageBRCM;
34 PFNGLEGLIMAGETARGETTEXTURE2DOESPROC glEGLImageTargetTexture2DOES;
35 PFNEGLCREATEIMAGEKHRPROC eglCreateImageKHR;
36 PFNEGLDESTROYIMAGEKHRPROC eglDestroyImageKHR;
37};
38
39BrcmEglIntegration::BrcmEglIntegration()
40 : d_ptr(new BrcmEglIntegrationPrivate)
41{
42}
43
44void BrcmEglIntegration::initializeHardware(struct ::wl_display *display)
45{
46 Q_D(BrcmEglIntegration);
47
48 QPlatformNativeInterface *nativeInterface = QGuiApplication::platformNativeInterface();
49 if (nativeInterface) {
50 d->egl_display = nativeInterface->nativeResourceForIntegration("EglDisplay");
51 if (!d->egl_display)
52 qWarning("Failed to acquire EGL display from platform integration");
53
54 d->eglQueryGlobalImageBRCM = (PFNEGLQUERYGLOBALIMAGEBRCMPROC) eglGetProcAddress("eglQueryGlobalImageBRCM");
55
56 if (!d->eglQueryGlobalImageBRCM) {
57 qWarning("Failed to resolve eglQueryGlobalImageBRCM");
58 return;
59 }
60
61 d->glEGLImageTargetTexture2DOES = (PFNGLEGLIMAGETARGETTEXTURE2DOESPROC)eglGetProcAddress("glEGLImageTargetTexture2DOES");
62
63 if (!d->glEGLImageTargetTexture2DOES) {
64 qWarning("Failed to resolve glEGLImageTargetTexture2DOES");
65 return;
66 }
67
68 d->eglCreateImageKHR = (PFNEGLCREATEIMAGEKHRPROC)eglGetProcAddress("eglCreateImageKHR");
69
70 if (!d->eglCreateImageKHR) {
71 qWarning("Failed to resolve eglCreateImageKHR");
72 return;
73 }
74
75 d->eglDestroyImageKHR = (PFNEGLDESTROYIMAGEKHRPROC)eglGetProcAddress("eglDestroyImageKHR");
76
77 if (!d->eglDestroyImageKHR) {
78 qWarning("Failed to resolve eglDestroyImageKHR");
79 return;
80 }
81 d->valid = true;
82 init(display, 1);
83 }
84}
85
87{
88 if (wl_shm_buffer_get(buffer))
89 return nullptr;
90 return new BrcmEglClientBuffer(this, buffer);
91}
92
93BrcmEglIntegrationPrivate *BrcmEglIntegrationPrivate::get(BrcmEglIntegration *integration)
94{
95 return integration->d_ptr.data();
96}
97
99{
100 Q_UNUSED(plane);
101
102 auto d = BrcmEglIntegrationPrivate::get(m_integration);
103 if (!d->valid) {
104 qWarning("bindTextureToBuffer failed!");
105 return nullptr;
106 }
107
108 BrcmBuffer *brcmBuffer = BrcmBuffer::fromResource(m_buffer);
109
110 if (!d->eglQueryGlobalImageBRCM(brcmBuffer->handle(), brcmBuffer->handle() + 2)) {
111 qWarning("eglQueryGlobalImageBRCM failed!");
112 return nullptr;
113 }
114
115 EGLImageKHR image = d->eglCreateImageKHR(d->egl_display, EGL_NO_CONTEXT, EGL_NATIVE_PIXMAP_KHR, (EGLClientBuffer)brcmBuffer->handle(), NULL);
116 if (image == EGL_NO_IMAGE_KHR)
117 qWarning("eglCreateImageKHR() failed: %x\n", eglGetError());
118
119 if (!m_texture) {
120 m_texture = new QOpenGLTexture(QOpenGLTexture::Target2D);
121 m_texture->create();
122 }
123
124 m_texture->bind();
125
126 d->glEGLImageTargetTexture2DOES(GL_TEXTURE_2D, image);
127
128 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
129 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
130 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
131 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
132
133 d->eglDestroyImageKHR(d->egl_display, image);
134
135 return m_texture;
136}
137
139{
140}
141
142void BrcmEglIntegration::brcm_create_buffer(Resource *resource, uint32_t id, int32_t width, int32_t height, wl_array *data)
143{
144 new BrcmBuffer(resource->client(), id, QSize(width, height), static_cast<EGLint *>(data->data), data->size / sizeof(EGLint));
145}
146
149 , m_integration(integration)
150{
151}
152
154{
155 return QWaylandBufferRef::BufferFormatEgl_RGBA;
156}
157
159{
160 BrcmBuffer *brcmBuffer = BrcmBuffer::fromResource(m_buffer);
161 return brcmBuffer->size();
162}
163
165{
166 BrcmBuffer *brcmBuffer = BrcmBuffer::fromResource(m_buffer);
167 return brcmBuffer->isYInverted() ? QWaylandSurface::OriginTopLeft : QWaylandSurface::OriginBottomLeft;
168}
169
170
171QT_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