6#include <QtWaylandClient/private/qwaylandbuffer_p.h>
7#include <QtWaylandClient/private/qwaylandscreen_p.h>
10#include <QtGui/private/qeglconvenience_p.h>
12#include <QtGui/QWindow>
13#include <qpa/qwindowsysteminterface.h>
15#include <EGL/eglext_brcm.h>
17#include "wayland-brcm-client-protocol.h"
31 struct wl_event_queue *eventQueue)
34 , m_eventQueue(eventQueue)
36 wl_array_init(&m_array);
37 m_data =
static_cast<EGLint *>(wl_array_add(&m_array, count *
sizeof(EGLint)));
39 for (
int i = 0; i < count; ++i)
42 mBuffer = qt_brcm_create_buffer(brcm, size.width(), size.height(), &m_array);
43 wl_proxy_set_queue(
reinterpret_cast<
struct wl_proxy*>(mBuffer), m_eventQueue);
45 static const struct wl_buffer_listener buffer_listener = {
46 QWaylandBrcmBuffer::buffer_release
49 wl_buffer_add_listener(mBuffer, &buffer_listener,
this);
54 wl_array_release(&m_array);
55 wl_buffer_destroy(mBuffer);
71 wl_display_dispatch_queue(m_display->wl_display(), m_eventQueue);
84 bool m_released =
true;
86 EGLint *m_data =
nullptr;
87 QWaylandDisplay *m_display =
nullptr;
88 struct wl_event_queue *m_eventQueue =
nullptr;
92 : QWaylandWindow(window, display)
93 , m_eglIntegration(
static_cast<QWaylandBrcmEglIntegration *>(mDisplay->clientBufferIntegration()))
94 , m_format(window->format())
95 , m_eventQueue(wl_display_create_queue(mDisplay->wl_display()))
101 destroyEglSurfaces();
106 return QWaylandWindow::Egl;
111 destroyEglSurfaces();
112 QWaylandWindow::setGeometry(rect);
122 for (
int i = 0; i < m_count; ++i) {
123 if (m_eglSurfaces[i]) {
124 eglDestroySurface(m_eglIntegration
->eglDisplay(), m_eglSurfaces[i]);
125 m_eglSurfaces[i] = 0;
138 QSurfaceFormat format = f;
139 format.setRedBufferSize(8);
140 format.setGreenBufferSize(8);
141 format.setBlueBufferSize(8);
142 format.setAlphaBufferSize(8);
148 QSize size(geometry().size());
150 m_count = window()->format().swapBehavior() == QSurfaceFormat::TripleBuffer ? 3 : 2;
152 EGLConfig eglConfig = q_configFromGLFormat(m_eglIntegration->eglDisplay(), brcmFixFormat(window()->format()),
true, EGL_PIXMAP_BIT);
154 m_format = q_glFormatFromConfig(m_eglIntegration->eglDisplay(), eglConfig);
156 EGLint pixel_format = EGL_PIXEL_FORMAT_ARGB_8888_BRCM;
159 eglGetConfigAttrib(m_eglIntegration
->eglDisplay(), eglConfig, EGL_RENDERABLE_TYPE, &rt);
161 if (rt & EGL_OPENGL_ES_BIT) {
162 pixel_format |= EGL_PIXEL_FORMAT_RENDER_GLES_BRCM;
163 pixel_format |= EGL_PIXEL_FORMAT_GLES_TEXTURE_BRCM;
166 if (rt & EGL_OPENGL_ES2_BIT) {
167 pixel_format |= EGL_PIXEL_FORMAT_RENDER_GLES2_BRCM;
168 pixel_format |= EGL_PIXEL_FORMAT_GLES2_TEXTURE_BRCM;
171 if (rt & EGL_OPENVG_BIT) {
172 pixel_format |= EGL_PIXEL_FORMAT_RENDER_VG_BRCM;
173 pixel_format |= EGL_PIXEL_FORMAT_VG_IMAGE_BRCM;
176 if (rt & EGL_OPENGL_BIT) {
177 pixel_format |= EGL_PIXEL_FORMAT_RENDER_GL_BRCM;
180 memset(m_globalImages, 0, 5 * m_count *
sizeof(EGLint));
181 for (
int i = 0; i < m_count; ++i) {
182 m_eglIntegration->eglCreateGlobalImageBRCM(size.width(), size.height(), pixel_format,
183 0, size.width() * 4, &m_globalImages[5*i]);
185 m_globalImages[5*i+2] = size.width();
186 m_globalImages[5*i+3] = size.height();
187 m_globalImages[5*i+4] = pixel_format;
190 EGL_VG_COLORSPACE, EGL_VG_COLORSPACE_sRGB,
191 EGL_VG_ALPHA_FORMAT, pixel_format & EGL_PIXEL_FORMAT_ARGB_8888_PRE_BRCM ? EGL_VG_ALPHA_FORMAT_PRE : EGL_VG_ALPHA_FORMAT_NONPRE,
195 m_eglSurfaces[i] = eglCreatePixmapSurface(m_eglIntegration
->eglDisplay(), eglConfig, (EGLNativePixmapType)&m_globalImages[5*i], attrs);
196 if (m_eglSurfaces[i] == EGL_NO_SURFACE)
197 qFatal(
"eglCreatePixmapSurface failed: %x, global image id: %d %d\n", eglGetError(), m_globalImages[5*i], m_globalImages[5*i+1]);
198 m_buffers[i] =
new QWaylandBrcmBuffer(mDisplay, m_eglIntegration->waylandBrcm(), size, &m_globalImages[5*i], 5, m_eventQueue);
204 if (m_eglIntegration->eglFlushBRCM) {
205 m_eglIntegration->eglFlushBRCM();
215 commit(m_buffers[m_current], QRegion(0, 0, geometry().size().width(), geometry().size().height()));
217 m_current = (m_current + 1) % m_count;
225 return eglMakeCurrent(m_eglIntegration
->eglDisplay(), m_eglSurfaces[m_current], m_eglSurfaces[m_current], context);
QWaylandBrcmBuffer(QWaylandDisplay *display, struct qt_brcm *brcm, const QSize &size, EGLint *data, int count, struct wl_event_queue *eventQueue)
static void buffer_release(void *data, wl_buffer *buffer)
EGLDisplay eglDisplay() const
WindowType windowType() const override
bool makeCurrent(EGLContext context)
void setGeometry(const QRect &rect) override
This function is called by Qt whenever a window is moved or resized using the QWindow API.
QSurfaceFormat format() const override
Returns the actual surface format of the window.
QSurfaceFormat brcmFixFormat(const QSurfaceFormat &f)