├── phantom.json ├── .gitignore ├── phantom.pro ├── .qmake.conf ├── phantom.pri ├── README.md ├── LICENSE.BSD ├── main.cpp ├── phantombackingstore.h ├── phantomintegration.h ├── phantombackingstore.cpp └── phantomintegration.cpp /phantom.json: -------------------------------------------------------------------------------- 1 | { 2 | "Keys": [ "phantom" ] 3 | } 4 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | /plugins 2 | Makefile* 3 | /mkspecs 4 | /lib 5 | .qmake.stash 6 | .moc 7 | -------------------------------------------------------------------------------- /phantom.pro: -------------------------------------------------------------------------------- 1 | TARGET = qphantom 2 | 3 | PLUGIN_TYPE = platforms 4 | PLUGIN_CLASS_NAME = PhantomIntegrationPlugin 5 | !equals(TARGET, $$QT_DEFAULT_QPA_PLUGIN): PLUGIN_EXTENDS = - 6 | load(qt_plugin) 7 | 8 | SOURCES += $$PWD/main.cpp 9 | 10 | include(phantom.pri) 11 | -------------------------------------------------------------------------------- /.qmake.conf: -------------------------------------------------------------------------------- 1 | load(qt_build_config) 2 | CONFIG += warning_clean 3 | 4 | QT_SOURCE_TREE = $$PWD 5 | QT_BUILD_TREE = $$shadowed($$PWD) 6 | 7 | # In qtbase, all modules follow qglobal.h 8 | MODULE_VERSION = $$QT_VERSION 9 | 10 | contains(QT_CONFIG,fontconfig): LIBS_PRIVATE += $$QMAKE_LIBS_FONTCONFIG 11 | -------------------------------------------------------------------------------- /phantom.pri: -------------------------------------------------------------------------------- 1 | QT += core-private gui-private eventdispatcher_support-private fontdatabase_support-private 2 | 3 | SOURCES += $$PWD/phantomintegration.cpp \ 4 | $$PWD/phantombackingstore.cpp 5 | 6 | HEADERS += $$PWD/phantomintegration.h \ 7 | $$PWD/phantombackingstore.h 8 | 9 | QMAKE_LFLAGS += $$QMAKE_LFLAGS_NOUNDEF 10 | 11 | INCLUDEPATH += $$PWD 12 | 13 | CONFIG += qpa/genericunixfontdatabase 14 | 15 | OTHER_FILES += $$PWD/phantom.json 16 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Phantom Qt headless qpa plugin 2 | 3 | This is the headless platform plugin for qt, extracted from https://github.com/ariya/phantomjs. It can be used to run Qt applications without an x server. 4 | 5 | This plugin will automatically use fontconfig whereas qt's built-in `headless` plugin will not. 6 | 7 | ## Building 8 | 9 | ``` 10 | qmake 11 | make 12 | ``` 13 | 14 | Copy plugins/platform/libqphantom.so to your qt platform plugin directory, likely `/usr/plugins/platform/` 15 | 16 | ## Usage 17 | 18 | Set the `QT_QPA_PLATFORM=phantom` environment variable before running your application. 19 | 20 | ## License 21 | 22 | See `LICENSE.BSD` 23 | -------------------------------------------------------------------------------- /LICENSE.BSD: -------------------------------------------------------------------------------- 1 | Redistribution and use in source and binary forms, with or without 2 | modification, are permitted provided that the following conditions are met: 3 | 4 | * Redistributions of source code must retain the above copyright 5 | notice, this list of conditions and the following disclaimer. 6 | * Redistributions in binary form must reproduce the above copyright 7 | notice, this list of conditions and the following disclaimer in the 8 | documentation and/or other materials provided with the distribution. 9 | * Neither the name of the nor the 10 | names of its contributors may be used to endorse or promote products 11 | derived from this software without specific prior written permission. 12 | 13 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 14 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 15 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 16 | ARE DISCLAIMED. IN NO EVENT SHALL BE LIABLE FOR ANY 17 | DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 18 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 19 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 20 | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 21 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 22 | THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -------------------------------------------------------------------------------- /main.cpp: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | ** 3 | ** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). 4 | ** Contact: http://www.qt-project.org/legal 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 Digia. For licensing terms and 14 | ** conditions see http://qt.digia.com/licensing. For further information 15 | ** use the contact form at http://qt.digia.com/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 2.1 as published by the Free Software 20 | ** Foundation and appearing in the file LICENSE.LGPL included in the 21 | ** packaging of this file. Please review the following information to 22 | ** ensure the GNU Lesser General Public License version 2.1 requirements 23 | ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. 24 | ** 25 | ** In addition, as a special exception, Digia gives you certain additional 26 | ** rights. These rights are described in the Digia Qt LGPL Exception 27 | ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. 28 | ** 29 | ** GNU General Public License Usage 30 | ** Alternatively, this file may be used under the terms of the GNU 31 | ** General Public License version 3.0 as published by the Free Software 32 | ** Foundation and appearing in the file LICENSE.GPL included in the 33 | ** packaging of this file. Please review the following information to 34 | ** ensure the GNU General Public License version 3.0 requirements will be 35 | ** met: http://www.gnu.org/copyleft/gpl.html. 36 | ** 37 | ** 38 | ** $QT_END_LICENSE$ 39 | ** 40 | ****************************************************************************/ 41 | 42 | 43 | #include 44 | #include "phantomintegration.h" 45 | 46 | QT_BEGIN_NAMESPACE 47 | 48 | class PhantomIntegrationPlugin : public QPlatformIntegrationPlugin 49 | { 50 | Q_OBJECT 51 | Q_PLUGIN_METADATA(IID QPlatformIntegrationFactoryInterface_iid FILE "phantom.json") 52 | public: 53 | PhantomIntegration *create(const QString&, const QStringList&); 54 | }; 55 | 56 | PhantomIntegration *PhantomIntegrationPlugin::create(const QString& system, const QStringList& paramList) 57 | { 58 | Q_UNUSED(paramList) 59 | return new PhantomIntegration(); 60 | } 61 | 62 | QT_END_NAMESPACE 63 | 64 | #include "main.moc" 65 | -------------------------------------------------------------------------------- /phantombackingstore.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | ** 3 | ** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). 4 | ** Contact: http://www.qt-project.org/legal 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 Digia. For licensing terms and 14 | ** conditions see http://qt.digia.com/licensing. For further information 15 | ** use the contact form at http://qt.digia.com/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 2.1 as published by the Free Software 20 | ** Foundation and appearing in the file LICENSE.LGPL included in the 21 | ** packaging of this file. Please review the following information to 22 | ** ensure the GNU Lesser General Public License version 2.1 requirements 23 | ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. 24 | ** 25 | ** In addition, as a special exception, Digia gives you certain additional 26 | ** rights. These rights are described in the Digia Qt LGPL Exception 27 | ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. 28 | ** 29 | ** GNU General Public License Usage 30 | ** Alternatively, this file may be used under the terms of the GNU 31 | ** General Public License version 3.0 as published by the Free Software 32 | ** Foundation and appearing in the file LICENSE.GPL included in the 33 | ** packaging of this file. Please review the following information to 34 | ** ensure the GNU General Public License version 3.0 requirements will be 35 | ** met: http://www.gnu.org/copyleft/gpl.html. 36 | ** 37 | ** 38 | ** $QT_END_LICENSE$ 39 | ** 40 | ****************************************************************************/ 41 | 42 | #ifndef PHANTOMBACKINGSTORE_H 43 | #define PHANTOMBACKINGSTORE_H 44 | 45 | #include 46 | #include 47 | #include 48 | 49 | QT_BEGIN_NAMESPACE 50 | 51 | class PhantomBackingStore : public QPlatformBackingStore 52 | { 53 | public: 54 | PhantomBackingStore(QWindow *window); 55 | ~PhantomBackingStore(); 56 | 57 | QPaintDevice *paintDevice(); 58 | void flush(QWindow *window, const QRegion ®ion, const QPoint &offset); 59 | void resize(const QSize &size, const QRegion &staticContents); 60 | 61 | private: 62 | QImage mImage; 63 | }; 64 | 65 | QT_END_NAMESPACE 66 | 67 | #endif // PHANTOMBACKINGSTORE_H 68 | -------------------------------------------------------------------------------- /phantomintegration.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | ** 3 | ** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). 4 | ** All rights reserved. 5 | ** Contact: Nokia Corporation (qt-info@nokia.com) 6 | ** 7 | ** This file is part of the plugins of the Qt Toolkit. 8 | ** 9 | ** $QT_BEGIN_LICENSE:LGPL$ 10 | ** GNU Lesser General Public License Usage 11 | ** This file may be used under the terms of the GNU Lesser General Public 12 | ** License version 2.1 as published by the Free Software Foundation and 13 | ** appearing in the file LICENSE.LGPL included in the packaging of this 14 | ** file. Please review the following information to ensure the GNU Lesser 15 | ** General Public License version 2.1 requirements will be met: 16 | ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. 17 | ** 18 | ** In addition, as a special exception, Nokia gives you certain additional 19 | ** rights. These rights are described in the Nokia Qt LGPL Exception 20 | ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. 21 | ** 22 | ** GNU General Public License Usage 23 | ** Alternatively, this file may be used under the terms of the GNU General 24 | ** Public License version 3.0 as published by the Free Software Foundation 25 | ** and appearing in the file LICENSE.GPL included in the packaging of this 26 | ** file. Please review the following information to ensure the GNU General 27 | ** Public License version 3.0 requirements will be met: 28 | ** http://www.gnu.org/copyleft/gpl.html. 29 | ** 30 | ** Other Usage 31 | ** Alternatively, this file may be used in accordance with the terms and 32 | ** conditions contained in a signed written agreement between you and Nokia. 33 | ** 34 | ** 35 | ** 36 | ** 37 | ** 38 | ** $QT_END_LICENSE$ 39 | ** 40 | ****************************************************************************/ 41 | 42 | #ifndef PHANTOMINTEGRATION_H 43 | #define PHANTOMINTEGRATION_H 44 | 45 | #include 46 | #include 47 | 48 | #include 49 | 50 | QT_BEGIN_NAMESPACE 51 | 52 | class QWindowSurface; 53 | class PhantomNativeInterface; 54 | 55 | class PhantomIntegration : public QPlatformIntegration 56 | { 57 | public: 58 | PhantomIntegration(); 59 | ~PhantomIntegration(); 60 | 61 | bool hasCapability(QPlatformIntegration::Capability cap) const; 62 | 63 | QPlatformWindow *createPlatformWindow(QWindow *window) const; 64 | QPlatformBackingStore *createPlatformBackingStore(QWindow *window) const; 65 | QAbstractEventDispatcher *createEventDispatcher() const; 66 | 67 | QPlatformFontDatabase *fontDatabase() const; 68 | QPlatformNativeInterface *nativeInterface() const; 69 | 70 | private: 71 | QScopedPointer m_nativeInterface; 72 | }; 73 | 74 | QT_END_NAMESPACE 75 | 76 | #endif // PHANTOMINTEGRATION_H 77 | -------------------------------------------------------------------------------- /phantombackingstore.cpp: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | ** 3 | ** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). 4 | ** Contact: http://www.qt-project.org/legal 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 Digia. For licensing terms and 14 | ** conditions see http://qt.digia.com/licensing. For further information 15 | ** use the contact form at http://qt.digia.com/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 2.1 as published by the Free Software 20 | ** Foundation and appearing in the file LICENSE.LGPL included in the 21 | ** packaging of this file. Please review the following information to 22 | ** ensure the GNU Lesser General Public License version 2.1 requirements 23 | ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. 24 | ** 25 | ** In addition, as a special exception, Digia gives you certain additional 26 | ** rights. These rights are described in the Digia Qt LGPL Exception 27 | ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. 28 | ** 29 | ** GNU General Public License Usage 30 | ** Alternatively, this file may be used under the terms of the GNU 31 | ** General Public License version 3.0 as published by the Free Software 32 | ** Foundation and appearing in the file LICENSE.GPL included in the 33 | ** packaging of this file. Please review the following information to 34 | ** ensure the GNU General Public License version 3.0 requirements will be 35 | ** met: http://www.gnu.org/copyleft/gpl.html. 36 | ** 37 | ** 38 | ** $QT_END_LICENSE$ 39 | ** 40 | ****************************************************************************/ 41 | 42 | 43 | #include "phantombackingstore.h" 44 | #include 45 | #include 46 | 47 | QT_BEGIN_NAMESPACE 48 | 49 | PhantomBackingStore::PhantomBackingStore(QWindow *window) 50 | : QPlatformBackingStore(window) 51 | { 52 | } 53 | 54 | PhantomBackingStore::~PhantomBackingStore() 55 | { 56 | } 57 | 58 | QPaintDevice *PhantomBackingStore::paintDevice() 59 | { 60 | return &mImage; 61 | } 62 | 63 | void PhantomBackingStore::flush(QWindow *window, const QRegion ®ion, const QPoint &offset) 64 | { 65 | Q_UNUSED(window); 66 | Q_UNUSED(region); 67 | Q_UNUSED(offset); 68 | } 69 | 70 | void PhantomBackingStore::resize(const QSize &size, const QRegion &) 71 | { 72 | QImage::Format format = QGuiApplication::primaryScreen()->handle()->format(); 73 | if (mImage.size() != size) 74 | mImage = QImage(size, format); 75 | } 76 | 77 | QT_END_NAMESPACE 78 | -------------------------------------------------------------------------------- /phantomintegration.cpp: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | ** 3 | ** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). 4 | ** All rights reserved. 5 | ** Contact: Nokia Corporation (qt-info@nokia.com) 6 | ** 7 | ** This file is part of the plugins of the Qt Toolkit. 8 | ** 9 | ** $QT_BEGIN_LICENSE:LGPL$ 10 | ** GNU Lesser General Public License Usage 11 | ** This file may be used under the terms of the GNU Lesser General Public 12 | ** License version 2.1 as published by the Free Software Foundation and 13 | ** appearing in the file LICENSE.LGPL included in the packaging of this 14 | ** file. Please review the following information to ensure the GNU Lesser 15 | ** General Public License version 2.1 requirements will be met: 16 | ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. 17 | ** 18 | ** In addition, as a special exception, Nokia gives you certain additional 19 | ** rights. These rights are described in the Nokia Qt LGPL Exception 20 | ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. 21 | ** 22 | ** GNU General Public License Usage 23 | ** Alternatively, this file may be used under the terms of the GNU General 24 | ** Public License version 3.0 as published by the Free Software Foundation 25 | ** and appearing in the file LICENSE.GPL included in the packaging of this 26 | ** file. Please review the following information to ensure the GNU General 27 | ** Public License version 3.0 requirements will be met: 28 | ** http://www.gnu.org/copyleft/gpl.html. 29 | ** 30 | ** Other Usage 31 | ** Alternatively, this file may be used in accordance with the terms and 32 | ** conditions contained in a signed written agreement between you and Nokia. 33 | ** 34 | ** 35 | ** 36 | ** 37 | ** 38 | ** $QT_END_LICENSE$ 39 | ** 40 | ****************************************************************************/ 41 | 42 | #include "phantomintegration.h" 43 | #include "phantombackingstore.h" 44 | 45 | #include 46 | 47 | #if defined(Q_OS_MAC) 48 | # include 49 | #else 50 | # include 51 | #endif 52 | 53 | #include 54 | 55 | #include 56 | #include 57 | #include 58 | 59 | QT_BEGIN_NAMESPACE 60 | 61 | class PhantomNativeInterface : public QPlatformNativeInterface 62 | { 63 | public: 64 | }; 65 | 66 | class PhantomScreen : public QPlatformScreen 67 | { 68 | public: 69 | PhantomScreen() 70 | : mDepth(32), mFormat(QImage::Format_ARGB32_Premultiplied) {} 71 | 72 | QRect geometry() const { return mGeometry; } 73 | QSizeF physicalSize() const { return mPhysicalSize; } 74 | int depth() const { return mDepth; } 75 | QImage::Format format() const { return mFormat; } 76 | 77 | void setGeometry(const QRect& rect) { mGeometry = rect; } 78 | void setPhysicalSize(const QSizeF& physicalSize) { mPhysicalSize = physicalSize; } 79 | void setDepth(int depth) { mDepth = depth; } 80 | void setFormat(QImage::Format format) { mFormat = format; } 81 | 82 | private: 83 | QRect mGeometry; 84 | int mDepth; 85 | QImage::Format mFormat; 86 | QSizeF mPhysicalSize; 87 | }; 88 | 89 | PhantomIntegration::PhantomIntegration() 90 | : m_nativeInterface(new PhantomNativeInterface) 91 | { 92 | PhantomScreen *screen = new PhantomScreen(); 93 | 94 | // Simulate typical desktop screen 95 | int width = 1024; 96 | int height = 768; 97 | int dpi = 72; 98 | qreal physicalWidth = width * 25.4 / dpi; 99 | qreal physicalHeight = height * 25.4 / dpi; 100 | screen->setGeometry(QRect(0, 0, width, height)); 101 | screen->setPhysicalSize(QSizeF(physicalWidth, physicalHeight)); 102 | 103 | screen->setDepth(32); 104 | screen->setFormat(QImage::Format_ARGB32_Premultiplied); 105 | 106 | QWindowSystemInterface::handleScreenAdded(screen); 107 | } 108 | 109 | PhantomIntegration::~PhantomIntegration() 110 | { 111 | } 112 | 113 | bool PhantomIntegration::hasCapability(QPlatformIntegration::Capability cap) const 114 | { 115 | switch (cap) { 116 | case ThreadedPixmaps: return true; 117 | default: return QPlatformIntegration::hasCapability(cap); 118 | } 119 | } 120 | 121 | QPlatformWindow* PhantomIntegration::createPlatformWindow(QWindow* window) const 122 | { 123 | return new QPlatformWindow(window); 124 | } 125 | 126 | QPlatformBackingStore* PhantomIntegration::createPlatformBackingStore(QWindow* window) const 127 | { 128 | return new PhantomBackingStore(window); 129 | } 130 | 131 | QPlatformFontDatabase *PhantomIntegration::fontDatabase() const 132 | { 133 | static QPlatformFontDatabase *db = 0; 134 | if (!db) { 135 | #if defined(Q_OS_MAC) 136 | db = new QCoreTextFontDatabase(); 137 | #else 138 | db = new QGenericUnixFontDatabase(); 139 | #endif 140 | } 141 | return db; 142 | } 143 | 144 | QAbstractEventDispatcher *PhantomIntegration::createEventDispatcher() const 145 | { 146 | return createUnixEventDispatcher(); 147 | } 148 | 149 | QPlatformNativeInterface *PhantomIntegration::nativeInterface() const 150 | { 151 | return m_nativeInterface.data(); 152 | } 153 | 154 | QT_END_NAMESPACE 155 | --------------------------------------------------------------------------------