| 1 |
// Copyright (C) 2016 The Qt Company Ltd. |
| 2 |
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only |
| 3 |
|
| 4 |
#include "qeglfsbrcmintegration.h" |
| 5 |
#include <bcm_host.h> |
| 6 |
|
| 7 |
QT_BEGIN_NAMESPACE |
| 8 |
|
| 9 |
static DISPMANX_DISPLAY_HANDLE_T dispman_display = 0; |
| 10 |
|
| 11 |
static EGLNativeWindowType createDispmanxLayer(const QPoint &pos, const QSize &size, int z, DISPMANX_FLAGS_ALPHA_T flags) |
| 12 |
{ |
| 13 |
VC_RECT_T dst_rect; |
| 14 |
dst_rect.x = pos.x(); |
| 15 |
dst_rect.y = pos.y(); |
| 16 |
dst_rect.width = size.width(); |
| 17 |
dst_rect.height = size.height(); |
| 18 |
|
| 19 |
VC_RECT_T src_rect; |
| 20 |
src_rect.x = 0; |
| 21 |
src_rect.y = 0; |
| 22 |
src_rect.width = size.width() << 16; |
| 23 |
src_rect.height = size.height() << 16; |
| 24 |
|
| 25 |
DISPMANX_UPDATE_HANDLE_T dispman_update = vc_dispmanx_update_start(0); |
| 26 |
|
| 27 |
VC_DISPMANX_ALPHA_T alpha; |
| 28 |
alpha.flags = flags; |
| 29 |
alpha.opacity = 0xFF; |
| 30 |
alpha.mask = 0; |
| 31 |
|
| 32 |
DISPMANX_ELEMENT_HANDLE_T dispman_element = vc_dispmanx_element_add( |
| 33 |
dispman_update, dispman_display, z, &dst_rect, 0, &src_rect, |
| 34 |
DISPMANX_PROTECTION_NONE, &alpha, (DISPMANX_CLAMP_T *)NULL, (DISPMANX_TRANSFORM_T)0); |
| 35 |
|
| 36 |
vc_dispmanx_update_submit_sync(dispman_update); |
| 37 |
|
| 38 |
EGL_DISPMANX_WINDOW_T *eglWindow = new EGL_DISPMANX_WINDOW_T; |
| 39 |
eglWindow->element = dispman_element; |
| 40 |
eglWindow->width = size.width(); |
| 41 |
eglWindow->height = size.height(); |
| 42 |
|
| 43 |
return eglWindow; |
| 44 |
} |
| 45 |
|
| 46 |
static void destroyDispmanxLayer(EGLNativeWindowType window) |
| 47 |
{ |
| 48 |
EGL_DISPMANX_WINDOW_T *eglWindow = static_cast<EGL_DISPMANX_WINDOW_T *>(window); |
| 49 |
DISPMANX_UPDATE_HANDLE_T dispman_update = vc_dispmanx_update_start(0); |
| 50 |
vc_dispmanx_element_remove(dispman_update, eglWindow->element); |
| 51 |
vc_dispmanx_update_submit_sync(dispman_update); |
| 52 |
delete eglWindow; |
| 53 |
} |
| 54 |
|
| 55 |
void QEglFSBrcmIntegration::platformInit() |
| 56 |
{ |
| 57 |
bcm_host_init(); |
| 58 |
} |
| 59 |
|
| 60 |
static int getDisplayId() |
| 61 |
{ |
| 62 |
// As defined in vc_dispmanx_types.h |
| 63 |
// DISPMANX_ID_MAIN_LCD 0 |
| 64 |
// DISPMANX_ID_AUX_LCD 1 |
| 65 |
// DISPMANX_ID_HDMI 2 |
| 66 |
// DISPMANX_ID_SDTV 3 |
| 67 |
// DISPMANX_ID_FORCE_LCD 4 |
| 68 |
// DISPMANX_ID_FORCE_TV 5 |
| 69 |
// DISPMANX_ID_FORCE_OTHER 6 /* non-default display */ |
| 70 |
static const int dispmanxId = qEnvironmentVariableIntValue("QT_QPA_EGLFS_DISPMANX_ID"); |
| 71 |
return (dispmanxId >= 0 && dispmanxId <= 6) ? dispmanxId : 0; |
| 72 |
} |
| 73 |
|
| 74 |
EGLNativeDisplayType QEglFSBrcmIntegration::platformDisplay() const |
| 75 |
{ |
| 76 |
dispman_display = vc_dispmanx_display_open(getDisplayId()); |
| 77 |
return EGL_DEFAULT_DISPLAY; |
| 78 |
} |
| 79 |
|
| 80 |
void QEglFSBrcmIntegration::platformDestroy() |
| 81 |
{ |
| 82 |
vc_dispmanx_display_close(dispman_display); |
| 83 |
} |
| 84 |
|
| 85 |
QSize QEglFSBrcmIntegration::screenSize() const |
| 86 |
{ |
| 87 |
uint32_t width, height; |
| 88 |
graphics_get_display_size(getDisplayId(), &width, &height); |
| 89 |
return QSize(width, height); |
| 90 |
} |
| 91 |
|
| 92 |
EGLNativeWindowType QEglFSBrcmIntegration::createNativeWindow(QPlatformWindow *window, const QSize &size, const QSurfaceFormat &format) |
| 93 |
{ |
| 94 |
Q_UNUSED(window); |
| 95 |
return createDispmanxLayer(QPoint(0, 0), size, 1, format.hasAlpha() ? DISPMANX_FLAGS_ALPHA_FROM_SOURCE : DISPMANX_FLAGS_ALPHA_FIXED_ALL_PIXELS); |
| 96 |
} |
| 97 |
|
| 98 |
void QEglFSBrcmIntegration::destroyNativeWindow(EGLNativeWindowType window) |
| 99 |
{ |
| 100 |
destroyDispmanxLayer(window); |
| 101 |
} |
| 102 |
|
| 103 |
bool QEglFSBrcmIntegration::hasCapability(QPlatformIntegration::Capability cap) const |
| 104 |
{ |
| 105 |
switch (cap) { |
| 106 |
case QPlatformIntegration::ThreadedPixmaps: |
| 107 |
case QPlatformIntegration::OpenGL: |
| 108 |
case QPlatformIntegration::ThreadedOpenGL: |
| 109 |
case QPlatformIntegration::BufferQueueingOpenGL: |
| 110 |
return true; |
| 111 |
default: |
| 112 |
return false; |
| 113 |
} |
| 114 |
} |
| 115 |
|
| 116 |
QT_END_NAMESPACE |