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 "qopenwfdintegration.h"
41 #include "qopenwfdscreen.h"
42 #include "qopenwfdnativeinterface.h"
43 #include "qopenwfddevice.h"
44 #include "qopenwfdwindow.h"
45 #include "qopenwfdglcontext.h"
46 #include "qopenwfdbackingstore.h"
47
48 #include <QtPlatformSupport/private/qgenericunixprintersupport_p.h>
49
50 #include <QtGui/private/qguiapplication_p.h>
51 #include <QtGui/QOpenGLContext>
52 #include <QtGui/QScreen>
53 #include <qpa/qwindowsysteminterface.h>
54
55 #include <QtEventDispatcherSupport/private/qgenericunixeventdispatcher_p.h>
56 #include <QtFontDatabaseSupport/private/qgenericunixfontdatabase_p.h>
57
58 #include <stdio.h>
59
60 #include <WF/wfd.h>
61
QOpenWFDIntegration()62 QOpenWFDIntegration::QOpenWFDIntegration()
63 : QPlatformIntegration()
64 , mPrinterSupport(new QGenericUnixPrinterSupport)
65 {
66 int numberOfDevices = wfdEnumerateDevices(0,0,0);
67
68 WFDint devices[numberOfDevices];
69 int actualNumberOfDevices = wfdEnumerateDevices(devices,numberOfDevices,0);
70 Q_ASSERT(actualNumberOfDevices == numberOfDevices);
71
72 mDevices.reserve(actualNumberOfDevices);
73 for (int i = 0; i < actualNumberOfDevices; i++) {
74 mDevices.append(new QOpenWFDDevice(this,devices[i]));
75 }
76
77 mFontDatabase = new QGenericUnixFontDatabase();
78 mNativeInterface = new QOpenWFDNativeInterface;
79 }
80
~QOpenWFDIntegration()81 QOpenWFDIntegration::~QOpenWFDIntegration()
82 {
83 //don't delete screens since they are deleted by the devices
84 qDebug("deleting platform integration");
85 for (int i = 0; i < mDevices.size(); i++) {
86 delete mDevices[i];
87 }
88
89 delete mFontDatabase;
90 delete mNativeInterface;
91 delete mPrinterSupport;
92 }
93
hasCapability(QPlatformIntegration::Capability cap) const94 bool QOpenWFDIntegration::hasCapability(QPlatformIntegration::Capability cap) const
95 {
96 switch (cap) {
97 case ThreadedPixmaps: return true;
98 case OpenGL: return true;
99 default: return QPlatformIntegration::hasCapability(cap);
100 }
101 }
102
createPlatformWindow(QWindow * window) const103 QPlatformWindow *QOpenWFDIntegration::createPlatformWindow(QWindow *window) const
104 {
105 return new QOpenWFDWindow(window);
106 }
107
createPlatformOpenGLContext(QOpenGLContext * context) const108 QPlatformOpenGLContext *QOpenWFDIntegration::createPlatformOpenGLContext(QOpenGLContext *context) const
109 {
110 QOpenWFDScreen *screen = static_cast<QOpenWFDScreen *>(context->screen()->handle());
111
112 return new QOpenWFDGLContext(screen->port()->device());
113 }
114
createPlatformBackingStore(QWindow * window) const115 QPlatformBackingStore *QOpenWFDIntegration::createPlatformBackingStore(QWindow *window) const
116 {
117 return new QOpenWFDBackingStore(window);
118 }
119
createEventDispatcher() const120 QAbstractEventDispatcher *QOpenWFDIntegration::createEventDispatcher() const
121 {
122 return createUnixEventDispatcher();
123 }
124
fontDatabase() const125 QPlatformFontDatabase *QOpenWFDIntegration::fontDatabase() const
126 {
127 return mFontDatabase;
128 }
129
nativeInterface() const130 QPlatformNativeInterface * QOpenWFDIntegration::nativeInterface() const
131 {
132 return mNativeInterface;
133 }
134
printerSupport() const135 QPlatformPrinterSupport * QOpenWFDIntegration::printerSupport() const
136 {
137 return mPrinterSupport;
138 }
139