1 /****************************************************************************
3 ** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/
6 ** This file is part of the qmake spec of the Qt Toolkit.
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** GNU Lesser General Public License Usage
10 ** This file may be used under the terms of the GNU Lesser General Public
11 ** License version 2.1 as published by the Free Software Foundation and
12 ** appearing in the file LICENSE.LGPL included in the packaging of this
13 ** file. Please review the following information to ensure the GNU Lesser
14 ** General Public License version 2.1 requirements will be met:
15 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
17 ** In addition, as a special exception, Nokia gives you certain additional
18 ** rights. These rights are described in the Nokia Qt LGPL Exception
19 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
21 ** GNU General Public License Usage
22 ** Alternatively, this file may be used under the terms of the GNU General
23 ** Public License version 3.0 as published by the Free Software Foundation
24 ** and appearing in the file LICENSE.GPL included in the packaging of this
25 ** file. Please review the following information to ensure the GNU General
26 ** Public License version 3.0 requirements will be met:
27 ** http://www.gnu.org/copyleft/gpl.html.
30 ** Alternatively, this file may be used in accordance with the terms and
31 ** conditions contained in a signed written agreement between you and Nokia.
40 ****************************************************************************/
42 #include "qeglfshooks.h"
48 #include <sys/ioctl.h>
49 #include <sys/types.h>
57 static DISPMANX_DISPLAY_HANDLE_T dispman_display = 0;
58 static DISPMANX_UPDATE_HANDLE_T dispman_update = 0;
60 class QEglFSPiHooks : public QEglFSHooks
63 virtual void platformInit();
64 virtual void platformDestroy();
65 virtual EGLNativeDisplayType platformDisplay() const;
66 virtual QSize screenSize() const;
67 virtual EGLNativeWindowType createNativeWindow(const QSize &size);
68 virtual void destroyNativeWindow(EGLNativeWindowType window);
69 virtual bool hasCapability(QPlatformIntegration::Capability cap) const;
72 void QEglFSPiHooks::platformInit()
77 EGLNativeDisplayType QEglFSPiHooks::platformDisplay() const
79 dispman_display = vc_dispmanx_display_open(0/* LCD */);
80 return EGL_DEFAULT_DISPLAY;
83 void QEglFSPiHooks::platformDestroy()
85 vc_dispmanx_display_close(dispman_display);
88 QSize QEglFSPiHooks::screenSize() const
90 //both mechanisms work
92 uint32_t width, height;
93 graphics_get_display_size(0 /* LCD */, &width, &height);
94 return QSize(width, height);
96 int fd = open("/dev/fb0", O_RDONLY);
98 fprintf(stderr, "Failed to open fb to detect screen resolution!\n");
102 struct fb_var_screeninfo vinfo;
103 if (ioctl(fd, FBIOGET_VSCREENINFO, &vinfo) = -1) {
104 fprintf(stderr, "Could not query screen info variable\n");
111 return QSize(vinfo.xres, vinfo.yres);
115 EGLNativeWindowType QEglFSPiHooks::createNativeWindow(const QSize &size)
120 dst_rect.width = size.width();
121 dst_rect.height = size.height();
126 src_rect.width = size.width() << 16;
127 src_rect.height = size.height() << 16;
129 dispman_update = vc_dispmanx_update_start(0);
131 VC_DISPMANX_ALPHA_T alpha;
132 alpha.flags = DISPMANX_FLAGS_ALPHA_FIXED_ALL_PIXELS;
133 alpha.opacity = 0xFF;
136 DISPMANX_ELEMENT_HANDLE_T dispman_element = vc_dispmanx_element_add(
137 dispman_update, dispman_display, 0, &dst_rect, 0, &src_rect,
138 DISPMANX_PROTECTION_NONE, &alpha, (DISPMANX_CLAMP_T *)NULL, (DISPMANX_TRANSFORM_T)0);
140 vc_dispmanx_update_submit_sync(dispman_update);
142 EGL_DISPMANX_WINDOW_T *eglWindow = new EGL_DISPMANX_WINDOW_T;
143 eglWindow->element = dispman_element;
144 eglWindow->width = size.width();
145 eglWindow->height = size.height();
150 void QEglFSPiHooks::destroyNativeWindow(EGLNativeWindowType window)
152 EGL_DISPMANX_WINDOW_T *eglWindow = static_cast<EGL_DISPMANX_WINDOW_T *>(window);
153 vc_dispmanx_element_remove(dispman_update, eglWindow->element);
157 bool QEglFSPiHooks::hasCapability(QPlatformIntegration::Capability cap) const
160 case QPlatformIntegration::ThreadedPixmaps:
161 case QPlatformIntegration::OpenGL:
162 case QPlatformIntegration::ThreadedOpenGL:
163 case QPlatformIntegration::BufferQueueingOpenGL:
170 QEglFSPiHooks eglFSPiHooks;
171 QEglFSHooks *platformHooks = &eglFSPiHooks;