| 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 <QDebug> |
| 5 |
#include <QtGui/private/qeglconvenience_p.h> |
| 6 |
#include <EGL/egl.h> |
| 7 |
#include "INTEGRITY.h" |
| 8 |
#include "qeglfsrcarintegration.h" |
| 9 |
|
| 10 |
#define RCAR_DEFAULT_DISPLAY 1 |
| 11 |
#define RCAR_DEFAULT_WM_LAYER 2 |
| 12 |
|
| 13 |
extern "C" unsigned long PVRGrfxServerInit(void); |
| 14 |
|
| 15 |
QT_BEGIN_NAMESPACE |
| 16 |
|
| 17 |
void QEglFSRcarIntegration::platformInit() |
| 18 |
{ |
| 19 |
bool ok; |
| 20 |
|
| 21 |
QEglFSDeviceIntegration::platformInit(); |
| 22 |
|
| 23 |
PVRGrfxServerInit(); |
| 24 |
|
| 25 |
mScreenSize = q_screenSizeFromFb(0); |
| 26 |
mNativeDisplay = (NativeDisplayType)EGL_DEFAULT_DISPLAY; |
| 27 |
|
| 28 |
mNativeDisplayID = qEnvironmentVariableIntValue("QT_QPA_WM_DISP_ID", &ok); |
| 29 |
if (!ok) |
| 30 |
mNativeDisplayID = RCAR_DEFAULT_DISPLAY; |
| 31 |
|
| 32 |
r_wm_Error_t wm_err = R_WM_DevInit(mNativeDisplayID); |
| 33 |
if (wm_err != R_WM_ERR_OK) |
| 34 |
qFatal("Failed to init WM Dev: %d, error: %d", mNativeDisplayID, wm_err); |
| 35 |
wm_err = R_WM_ScreenBgColorSet(mNativeDisplayID, 0x20, 0x20, 0x20); // Grey |
| 36 |
if (wm_err != R_WM_ERR_OK) |
| 37 |
qFatal("Failed to set screen background: %d", wm_err); |
| 38 |
wm_err = R_WM_ScreenEnable(mNativeDisplayID); |
| 39 |
if (wm_err != R_WM_ERR_OK) |
| 40 |
qFatal("Failed to enable screen: %d", wm_err); |
| 41 |
} |
| 42 |
|
| 43 |
QSize QEglFSRcarIntegration::screenSize() const |
| 44 |
{ |
| 45 |
return mScreenSize; |
| 46 |
} |
| 47 |
|
| 48 |
EGLNativeDisplayType QEglFSRcarIntegration::platformDisplay() const |
| 49 |
{ |
| 50 |
return mNativeDisplay; |
| 51 |
} |
| 52 |
|
| 53 |
static r_wm_WinColorFmt_t getWMColorFormat(const QSurfaceFormat &format) |
| 54 |
{ |
| 55 |
const int a = format.alphaBufferSize(); |
| 56 |
const int r = format.redBufferSize(); |
| 57 |
const int g = format.greenBufferSize(); |
| 58 |
const int b = format.blueBufferSize(); |
| 59 |
|
| 60 |
switch (r) { |
| 61 |
case 4: |
| 62 |
if (g == 4 && b == 4 && a == 4) |
| 63 |
return R_WM_COLORFMT_ARGB4444; |
| 64 |
break; |
| 65 |
case 5: |
| 66 |
if (g == 6 && b == 5 && a == 0) |
| 67 |
return R_WM_COLORFMT_RGB565; |
| 68 |
else if (g == 5 && b == 5 && a == 1) |
| 69 |
return R_WM_COLORFMT_ARGB1555; |
| 70 |
break; |
| 71 |
case 8: |
| 72 |
if (g == 8 && b == 8 && a == 0) |
| 73 |
return R_WM_COLORFMT_RGB0888; |
| 74 |
else if (g == 8 && b == 8 && a == 8) |
| 75 |
return R_WM_COLORFMT_ARGB8888; |
| 76 |
break; |
| 77 |
} |
| 78 |
|
| 79 |
qFatal("Unsupported color format: R:%d G:%d B:%d A:%d", r, g, b, a); |
| 80 |
return R_WM_COLORFMT_LAST; |
| 81 |
} |
| 82 |
|
| 83 |
EGLNativeWindowType QEglFSRcarIntegration::createNativeWindow(QPlatformWindow *window, const QSize &size, const QSurfaceFormat &format) |
| 84 |
{ |
| 85 |
bool ok; |
| 86 |
|
| 87 |
mNativeWindow = (EGLNativeWindowTypeREL*)malloc(sizeof(EGLNativeWindowTypeREL)); |
| 88 |
memset(mNativeWindow, 0, sizeof(EGLNativeWindowTypeREL)); |
| 89 |
|
| 90 |
mNativeWindow->ColorFmt = getWMColorFormat(format); |
| 91 |
mNativeWindow->PosX = 0; |
| 92 |
mNativeWindow->PosY = 0; |
| 93 |
mNativeWindow->PosZ = qEnvironmentVariableIntValue("QT_QPA_WM_LAYER", &ok); |
| 94 |
if (!ok) |
| 95 |
mNativeWindow->PosZ = RCAR_DEFAULT_WM_LAYER; |
| 96 |
mNativeWindow->Pitch = size.width(); |
| 97 |
mNativeWindow->Width = size.width(); |
| 98 |
mNativeWindow->Height = size.height(); |
| 99 |
mNativeWindow->Alpha = format.alphaBufferSize(); |
| 100 |
|
| 101 |
if (format.swapBehavior() == QSurfaceFormat::DefaultSwapBehavior) |
| 102 |
mNativeWindow->Surface.BufNum = 3; |
| 103 |
else |
| 104 |
mNativeWindow->Surface.BufNum = format.swapBehavior(); |
| 105 |
|
| 106 |
mNativeWindow->Surface.Type = R_WM_SURFACE_FB; |
| 107 |
mNativeWindow->Surface.BufMode = R_WM_WINBUF_ALLOC_INTERNAL; |
| 108 |
|
| 109 |
r_wm_Error_t wm_err = R_WM_WindowCreate(mNativeDisplayID, mNativeWindow); |
| 110 |
if (wm_err != R_WM_ERR_OK) |
| 111 |
qFatal("Failed to create window layer: %d", wm_err); |
| 112 |
wm_err = R_WM_DevEventRegister(mNativeDisplayID, R_WM_EVENT_VBLANK, 0); |
| 113 |
if (wm_err != R_WM_ERR_OK) |
| 114 |
qFatal("Failed to Register vsync event: %d", wm_err); |
| 115 |
wm_err = R_WM_WindowEnable(mNativeDisplayID, mNativeWindow); |
| 116 |
if (wm_err != R_WM_ERR_OK) |
| 117 |
qFatal("Failed to Enable window surface: %d", wm_err); |
| 118 |
|
| 119 |
return static_cast<EGLNativeWindowType>(mNativeWindow); |
| 120 |
} |
| 121 |
|
| 122 |
void QEglFSRcarIntegration::destroyNativeWindow(EGLNativeWindowType window) |
| 123 |
{ |
| 124 |
R_WM_WindowDisable(mNativeDisplayID, mNativeWindow); |
| 125 |
usleep(100000); //Needed to allow Window Manager make the window transparent |
| 126 |
R_WM_WindowDelete(mNativeDisplayID, mNativeWindow); |
| 127 |
R_WM_DevDeinit(mNativeDisplayID); |
| 128 |
free(mNativeWindow); |
| 129 |
} |
| 130 |
|
| 131 |
QT_END_NAMESPACE |