1 /****************************************************************************
2 **
3 ** Copyright (C) 2016 The Qt Company Ltd.
4 ** Contact: https://www.qt.io/licensing/
5 **
6 ** This file is part of the plugins of the Qt Toolkit.
7 **
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** Commercial License Usage
10 ** Licensees holding valid commercial Qt licenses may use this file in
11 ** accordance with the commercial license agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and The Qt Company. For licensing terms
14 ** and conditions see https://www.qt.io/terms-conditions. For further
15 ** information use the contact form at https://www.qt.io/contact-us.
16 **
17 ** GNU Lesser General Public License Usage
18 ** Alternatively, this file may be used under the terms of the GNU Lesser
19 ** General Public License version 3 as published by the Free Software
20 ** Foundation and appearing in the file LICENSE.LGPL3 included in the
21 ** packaging of this file. Please review the following information to
22 ** ensure the GNU Lesser General Public License version 3 requirements
23 ** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
24 **
25 ** GNU General Public License Usage
26 ** Alternatively, this file may be used under the terms of the GNU
27 ** General Public License version 2.0 or (at your option) the GNU General
28 ** Public license version 3 or any later version approved by the KDE Free
29 ** Qt Foundation. The licenses are as published by the Free Software
30 ** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
31 ** included in the packaging of this file. Please review the following
32 ** information to ensure the GNU General Public License requirements will
33 ** be met: https://www.gnu.org/licenses/gpl-2.0.html and
34 ** https://www.gnu.org/licenses/gpl-3.0.html.
35 **
36 ** $QT_END_LICENSE$
37 **
38 ****************************************************************************/
39
40 #include <QDebug>
41 #include <QtEglSupport/private/qeglconvenience_p.h>
42 #include <EGL/egl.h>
43 #include "INTEGRITY.h"
44 #include "qeglfsrcarintegration.h"
45
46 #define RCAR_DEFAULT_DISPLAY 1
47 #define RCAR_DEFAULT_WM_LAYER 2
48
49 extern "C" unsigned long PVRGrfxServerInit(void);
50
51 QT_BEGIN_NAMESPACE
52
platformInit()53 void QEglFSRcarIntegration::platformInit()
54 {
55 bool ok;
56
57 QEglFSDeviceIntegration::platformInit();
58
59 PVRGrfxServerInit();
60
61 mScreenSize = q_screenSizeFromFb(0);
62 mNativeDisplay = (NativeDisplayType)EGL_DEFAULT_DISPLAY;
63
64 mNativeDisplayID = qEnvironmentVariableIntValue("QT_QPA_WM_DISP_ID", &ok);
65 if (!ok)
66 mNativeDisplayID = RCAR_DEFAULT_DISPLAY;
67
68 r_wm_Error_t wm_err = R_WM_DevInit(mNativeDisplayID);
69 if (wm_err != R_WM_ERR_OK)
70 qFatal("Failed to init WM Dev: %d, error: %d", mNativeDisplayID, wm_err);
71 wm_err = R_WM_ScreenBgColorSet(mNativeDisplayID, 0x20, 0x20, 0x20); // Grey
72 if (wm_err != R_WM_ERR_OK)
73 qFatal("Failed to set screen background: %d", wm_err);
74 wm_err = R_WM_ScreenEnable(mNativeDisplayID);
75 if (wm_err != R_WM_ERR_OK)
76 qFatal("Failed to enable screen: %d", wm_err);
77 }
78
screenSize() const79 QSize QEglFSRcarIntegration::screenSize() const
80 {
81 return mScreenSize;
82 }
83
platformDisplay() const84 EGLNativeDisplayType QEglFSRcarIntegration::platformDisplay() const
85 {
86 return mNativeDisplay;
87 }
88
getWMColorFormat(const QSurfaceFormat & format)89 static r_wm_WinColorFmt_t getWMColorFormat(const QSurfaceFormat &format)
90 {
91 const int a = format.alphaBufferSize();
92 const int r = format.redBufferSize();
93 const int g = format.greenBufferSize();
94 const int b = format.blueBufferSize();
95
96 switch (r) {
97 case 4:
98 if (g == 4 && b == 4 && a == 4)
99 return R_WM_COLORFMT_ARGB4444;
100 break;
101 case 5:
102 if (g == 6 && b == 5 && a == 0)
103 return R_WM_COLORFMT_RGB565;
104 else if (g == 5 && b == 5 && a == 1)
105 return R_WM_COLORFMT_ARGB1555;
106 break;
107 case 8:
108 if (g == 8 && b == 8 && a == 0)
109 return R_WM_COLORFMT_RGB0888;
110 else if (g == 8 && b == 8 && a == 8)
111 return R_WM_COLORFMT_ARGB8888;
112 break;
113 }
114
115 qFatal("Unsupported color format: R:%d G:%d B:%d A:%d", r, g, b, a);
116 return R_WM_COLORFMT_LAST;
117 }
118
createNativeWindow(QPlatformWindow * window,const QSize & size,const QSurfaceFormat & format)119 EGLNativeWindowType QEglFSRcarIntegration::createNativeWindow(QPlatformWindow *window, const QSize &size, const QSurfaceFormat &format)
120 {
121 bool ok;
122
123 mNativeWindow = (EGLNativeWindowTypeREL*)malloc(sizeof(EGLNativeWindowTypeREL));
124 memset(mNativeWindow, 0, sizeof(EGLNativeWindowTypeREL));
125
126 mNativeWindow->ColorFmt = getWMColorFormat(format);
127 mNativeWindow->PosX = 0;
128 mNativeWindow->PosY = 0;
129 mNativeWindow->PosZ = qEnvironmentVariableIntValue("QT_QPA_WM_LAYER", &ok);
130 if (!ok)
131 mNativeWindow->PosZ = RCAR_DEFAULT_WM_LAYER;
132 mNativeWindow->Pitch = size.width();
133 mNativeWindow->Width = size.width();
134 mNativeWindow->Height = size.height();
135 mNativeWindow->Alpha = format.alphaBufferSize();
136
137 if (format.swapBehavior() == QSurfaceFormat::DefaultSwapBehavior)
138 mNativeWindow->Surface.BufNum = 3;
139 else
140 mNativeWindow->Surface.BufNum = format.swapBehavior();
141
142 mNativeWindow->Surface.Type = R_WM_SURFACE_FB;
143 mNativeWindow->Surface.BufMode = R_WM_WINBUF_ALLOC_INTERNAL;
144
145 r_wm_Error_t wm_err = R_WM_WindowCreate(mNativeDisplayID, mNativeWindow);
146 if (wm_err != R_WM_ERR_OK)
147 qFatal("Failed to create window layer: %d", wm_err);
148 wm_err = R_WM_DevEventRegister(mNativeDisplayID, R_WM_EVENT_VBLANK, 0);
149 if (wm_err != R_WM_ERR_OK)
150 qFatal("Failed to Register vsync event: %d", wm_err);
151 wm_err = R_WM_WindowEnable(mNativeDisplayID, mNativeWindow);
152 if (wm_err != R_WM_ERR_OK)
153 qFatal("Failed to Enable window surface: %d", wm_err);
154
155 return static_cast<EGLNativeWindowType>(mNativeWindow);
156 }
157
destroyNativeWindow(EGLNativeWindowType window)158 void QEglFSRcarIntegration::destroyNativeWindow(EGLNativeWindowType window)
159 {
160 R_WM_WindowDisable(mNativeDisplayID, mNativeWindow);
161 usleep(100000); //Needed to allow Window Manager make the window transparent
162 R_WM_WindowDelete(mNativeDisplayID, mNativeWindow);
163 R_WM_DevDeinit(mNativeDisplayID);
164 free(mNativeWindow);
165 }
166
167 QT_END_NAMESPACE
168