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 "qdirectfbintegration.h"
41 #include "qdirectfbbackingstore.h"
42 #include "qdirectfbblitter.h"
43 #include "qdirectfbconvenience.h"
44 #include "qdirectfbcursor.h"
45 #include "qdirectfbwindow.h"
46 
47 #include <QtFontDatabaseSupport/private/qgenericunixfontdatabase_p.h>
48 #include <QtEventDispatcherSupport/private/qgenericunixeventdispatcher_p.h>
49 #include <QtServiceSupport/private/qgenericunixservices_p.h>
50 
51 #include <QtGui/private/qpixmap_blitter_p.h>
52 #include <QtGui/private/qpixmap_raster_p.h>
53 #include <QtGui/private/qguiapplication_p.h>
54 #include <qpa/qplatformpixmap.h>
55 #include <QtCore/QCoreApplication>
56 #include <QtCore/QThread>
57 #include <QtCore/QAbstractEventDispatcher>
58 #include <qpa/qplatforminputcontextfactory_p.h>
59 #include <qpa/qwindowsysteminterface.h>
60 
61 QT_BEGIN_NAMESPACE
62 
QDirectFbIntegration()63 QDirectFbIntegration::QDirectFbIntegration()
64     : m_fontDb(new QGenericUnixFontDatabase())
65     , m_services(new QGenericUnixServices)
66 {
67 }
68 
connectToDirectFb()69 void QDirectFbIntegration::connectToDirectFb()
70 {
71     initializeDirectFB();
72     initializeScreen();
73     initializeInput();
74 
75     m_inputContext = QPlatformInputContextFactory::create();
76 }
77 
hasCapability(Capability cap) const78 bool QDirectFbIntegration::hasCapability(Capability cap) const
79 {
80     switch (cap) {
81     case ThreadedPixmaps: return true;
82     case MultipleWindows: return true;
83 #ifdef DIRECTFB_GL_EGL
84     case OpenGL: return true;
85     case ThreadedOpenGL: return true;
86 #endif
87     default: return QPlatformIntegration::hasCapability(cap);
88     }
89 }
90 
initializeDirectFB()91 void QDirectFbIntegration::initializeDirectFB()
92 {
93     const QStringList args = QCoreApplication::arguments();
94     int argc = args.size();
95     char **argv = new char*[argc];
96 
97     for (int i = 0; i < argc; ++i)
98         argv[i] = qstrdup(args.at(i).toLocal8Bit().constData());
99 
100     DFBResult result = DirectFBInit(&argc, &argv);
101     if (result != DFB_OK) {
102         DirectFBError("QDirectFBScreen: error initializing DirectFB",
103                       result);
104     }
105 
106     for (int i = 0; i < argc; ++i)
107         delete[] argv[i];
108     delete[] argv;
109 
110     // This must happen after DirectFBInit.
111     m_dfb.reset(QDirectFbConvenience::dfbInterface());
112 }
113 
initializeScreen()114 void QDirectFbIntegration::initializeScreen()
115 {
116     m_primaryScreen.reset(new QDirectFbScreen(0));
117     QWindowSystemInterface::handleScreenAdded(m_primaryScreen.data());
118 }
119 
initializeInput()120 void QDirectFbIntegration::initializeInput()
121 {
122     m_input.reset(new QDirectFbInput(m_dfb.data(), m_primaryScreen->dfbLayer()));
123     m_input->start();
124 }
125 
~QDirectFbIntegration()126 QDirectFbIntegration::~QDirectFbIntegration()
127 {
128     m_input->stopInputEventLoop();
129     m_input->wait();
130 }
131 
createPlatformPixmap(QPlatformPixmap::PixelType type) const132 QPlatformPixmap *QDirectFbIntegration::createPlatformPixmap(QPlatformPixmap::PixelType type) const
133 {
134     if (type == QPlatformPixmap::BitmapType)
135         return new QRasterPlatformPixmap(type);
136     else
137         return new QDirectFbBlitterPlatformPixmap;
138 }
139 
createPlatformWindow(QWindow * window) const140 QPlatformWindow *QDirectFbIntegration::createPlatformWindow(QWindow *window) const
141 {
142     QDirectFbWindow *dfbWindow = new QDirectFbWindow(window, m_input.data());
143     dfbWindow->createDirectFBWindow();
144     return dfbWindow;
145 }
146 
createEventDispatcher() const147 QAbstractEventDispatcher *QDirectFbIntegration::createEventDispatcher() const
148 {
149     return createUnixEventDispatcher();
150 }
151 
createPlatformBackingStore(QWindow * window) const152 QPlatformBackingStore *QDirectFbIntegration::createPlatformBackingStore(QWindow *window) const
153 {
154     return new QDirectFbBackingStore(window);
155 }
156 
fontDatabase() const157 QPlatformFontDatabase *QDirectFbIntegration::fontDatabase() const
158 {
159     return m_fontDb.data();
160 }
161 
services() const162 QPlatformServices *QDirectFbIntegration::services() const
163 {
164     return m_services.data();
165 }
166 
nativeInterface() const167 QPlatformNativeInterface *QDirectFbIntegration::nativeInterface() const
168 {
169     return const_cast<QDirectFbIntegration *>(this);
170 }
171 
172 QT_END_NAMESPACE
173