Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
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
23
25{
26public:
28
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
43
45{
47
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
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
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) {
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
148 : ClientBuffer(buffer)
149 , m_integration(integration)
150{
151}
152
157
159{
161 return brcmBuffer->size();
162}
163
169
170
static BrcmBuffer * fromResource(struct ::wl_resource *resource)
Definition brcmbuffer.h:30
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
PFNEGLDESTROYIMAGEKHRPROC eglDestroyImageKHR
PFNEGLQUERYGLOBALIMAGEBRCMPROC eglQueryGlobalImageBRCM
PFNGLEGLIMAGETARGETTEXTURE2DOESPROC glEGLImageTargetTexture2DOES
PFNEGLCREATEIMAGEKHRPROC eglCreateImageKHR
static BrcmEglIntegrationPrivate * get(BrcmEglIntegration *integration)
BrcmEglIntegrationPrivate()=default
void brcm_bind_resource(Resource *resource) override
QtWayland::ClientBuffer * createBufferFor(wl_resource *buffer) override
void initializeHardware(struct ::wl_display *display) override
void brcm_create_buffer(Resource *resource, uint32_t id, int32_t width, int32_t height, wl_array *data) override
static QPlatformNativeInterface * platformNativeInterface()
\inmodule QtGui
bool create()
Creates the underlying OpenGL texture object.
void bind()
Binds this texture to the currently active texture unit ready for rendering.
The QPlatformNativeInterface class provides an abstraction for retrieving native resource handles.
virtual void * nativeResourceForIntegration(const QByteArray &resource)
T * data() const noexcept
Returns the value of the pointer referenced by this object.
\inmodule QtCore
Definition qsize.h:25
Origin
This enum type is used to specify the origin of a QWaylandSurface's buffer.
struct::wl_resource * m_buffer
struct wl_display * display
Definition linuxdmabuf.h:41
Combined button and popup list for selecting options.
Definition image.cpp:4
typedef EGLDisplay(EGLAPIENTRYP PFNEGLGETPLATFORMDISPLAYEXTPROC)(EGLenum platform
#define qWarning
Definition qlogging.h:166
GLint GLsizei GLsizei height
GLint GLsizei GLsizei GLenum GLenum GLsizei void * data
GLenum GLuint buffer
GLint GLsizei width
#define GL_CLAMP_TO_EDGE
Definition qopenglext.h:100
static QT_BEGIN_NAMESPACE void init(QTextBoundaryFinder::BoundaryType type, QStringView str, QCharAttributes *attributes)
#define Q_UNUSED(x)