Skip to content

Commit

Permalink
Guess graphic API for windows (#3398)
Browse files Browse the repository at this point in the history
* Graphic guess component

* Comments applied

* Windows ui fallbacks

Co-authored-by: Lesley Norton <[email protected]>
  • Loading branch information
bakulf and lesleyjanenorton authored May 3, 2022
1 parent d602f83 commit f1176a1
Show file tree
Hide file tree
Showing 19 changed files with 340 additions and 133 deletions.
6 changes: 5 additions & 1 deletion nebula/ui/components/VPNAvatar.qml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ Item {
source: "qrc:/nebula/resources/avatar-default.png"
sourceSize.height: avatarSourceSize
sourceSize.width: avatarSourceSize
visible: avatar.status !== Image.Ready
visible: avatar.status !== Image.Ready || window._fallbackQtQuickRenderer
}

Rectangle {
Expand All @@ -56,6 +56,10 @@ Item {
* and assume that the user did not set a custom avatar
*/
function isDefaultAvatar() {
if (window._fallbackQtQuickRenderer) {
return true;
}

const avatarUrlSplitted = avatarUrl.split("/");
const avatarID = avatarUrlSplitted[avatarUrlSplitted.length - 1];

Expand Down
1 change: 0 additions & 1 deletion nebula/ui/components/VPNCheckBox.qml
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,6 @@ CheckBox {

VPNCheckmark {
anchors.fill: checkBoxIndicator
color: checkBox.checked ? VPNTheme.theme.blue : VPNTheme.theme.bgColor
}

VPNMouseArea {
Expand Down
34 changes: 12 additions & 22 deletions nebula/ui/components/VPNCheckmark.qml
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ import Mozilla.VPN 1.0
import compat 0.1

Item {
property alias color: checkmarkBg.color

id: checkmark

height: VPNTheme.theme.iconSize * 1.5
Expand All @@ -20,43 +18,35 @@ Item {
Rectangle {
id: checkmarkBg

height: parent.height
width: parent.width
anchors.fill: parent
antialiasing: true
smooth: true
visible: false
color: VPNTheme.theme.transparent

Behavior on color {
PropertyAnimation {
duration: 200
duration: 100
}
}
}

Image {
id: checkmarkIcon

source: "qrc:/nebula/resources/checkmark.svg"
sourceSize.height: 13
sourceSize.width: 12
visible: false
anchors.centerIn: checkmark
}

VPNOpacityMask {
anchors.centerIn: checkmark
height: checkmarkIcon.height
width: checkmarkIcon.width
source: checkmarkBg
maskSource: checkmarkIcon
source: "qrc:/nebula/resources/checkmark-blue50.svg"
sourceSize.height: checkmarkIcon.height
sourceSize.width: checkmarkIcon.width
opacity: checkBox.checked ? 1 : 0
anchors.centerIn: parent
Behavior on opacity {
PropertyAnimation {
duration: 100
}
}
}

Behavior on opacity {
PropertyAnimation {
duration: 100
}

}

}
15 changes: 9 additions & 6 deletions nebula/ui/components/VPNMainImage.qml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ Rectangle {
source: "qrc:/nebula/resources/shield-on.svg"
opacity: 1
}

},
State {
name: "stateConfirming"
Expand Down Expand Up @@ -64,6 +63,7 @@ Rectangle {
opacity: 0.55
showVPNOnIcon: false
}

PropertyChanges {
target: insetCircle
color: VPNTheme.colors.error.default
Expand Down Expand Up @@ -96,7 +96,6 @@ Rectangle {
target: spin
running: true
}

},
State {
name: "stateOff"
Expand Down Expand Up @@ -131,7 +130,6 @@ Rectangle {
source: "qrc:/nebula/resources/shield-off.svg"
opacity: 1
}

},
State {
name: "stateOn"
Expand All @@ -151,7 +149,6 @@ Rectangle {
source: "qrc:/nebula/resources/shield-on.svg"
opacity: 1
}

},
State {
name: "unstableOn"
Expand All @@ -172,7 +169,6 @@ Rectangle {
source: "qrc:/nebula/resources/shield-on.svg"
opacity: 1
}

},
State {
name: "noSignalOn"
Expand All @@ -193,7 +189,6 @@ Rectangle {
source: "qrc:/nebula/resources/shield-off.svg"
opacity: 1
}

}
]
transitions: [
Expand Down Expand Up @@ -380,6 +375,14 @@ Rectangle {
visible: false
}

Image {
id: globeFallback
source: logo.showVPNOnIcon ? "qrc:/ui/resources/main-img-vpn-on.svg" : "qrc:/ui/resources/main-img-vpn-off.svg"
sourceSize.height: globe.height
sourceSize.width: globe.width
visible: window._fallbackQtQuickRenderer
}

VPNLinearGradient {
id: gradient
anchors.fill: logo
Expand Down
1 change: 1 addition & 0 deletions nebula/ui/nebula_resources.qrc
Original file line number Diff line number Diff line change
Expand Up @@ -329,5 +329,6 @@
<file>resources/x-red50.svg</file>
<file>resources/check-green70.svg</file>
<file>resources/shield-green50.svg</file>
<file>resources/checkmark-blue50.svg</file>
</qresource>
</RCC>
3 changes: 3 additions & 0 deletions nebula/ui/resources/checkmark-blue50.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
38 changes: 38 additions & 0 deletions src/command.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@
#include "simplenetworkmanager.h"

#ifdef MVPN_WINDOWS
# include <QDir>
# include <QFile>
# include <QSGRendererInterface>
# include <QQuickWindow>
# include <Windows.h>
#endif

Expand All @@ -28,7 +32,32 @@

namespace {
Logger logger(LOG_MAIN, "Command");

#ifdef MVPN_WINDOWS
QSGRendererInterface::GraphicsApi maybeUseCustomGraphicApi() {
QString location =
QStandardPaths::writableLocation(QStandardPaths::AppDataLocation);
QDir appDataLocation(location);

QFile gpuCheckSettings = appDataLocation.filePath("moz.vpn.gpucheck");
if (!gpuCheckSettings.exists()) {
return QSGRendererInterface::Unknown;
}

if (!gpuCheckSettings.open(QIODevice::ReadOnly | QIODevice::Text)) {
return QSGRendererInterface::Unknown;
}

const QByteArray content = gpuCheckSettings.readAll().trimmed();
if (content == "software") {
return QSGRendererInterface::Software;
}

return QSGRendererInterface::Unknown;
}
#endif

} // namespace

QVector<std::function<Command*(QObject*)>> Command::s_commandCreators;

Expand Down Expand Up @@ -169,6 +198,15 @@ int Command::runQmlApp(std::function<int()>&& a_callback) {
Qt::HighDpiScaleFactorRoundingPolicy::Round);
#endif

#ifdef MVPN_WINDOWS
{
QSGRendererInterface::GraphicsApi api = maybeUseCustomGraphicApi();
if (api != QSGRendererInterface::Unknown) {
QQuickWindow::setGraphicsApi(api);
}
}
#endif

QApplication app(CommandLineParser::argc(), CommandLineParser::argv());

QCoreApplication::setApplicationName("Mozilla VPN");
Expand Down
91 changes: 91 additions & 0 deletions src/commands/commandgpucheck.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */

#include "commandgpucheck.h"
#include "commandlineparser.h"
#include "leakdetector.h"
#include "logger.h"

#include <QDir>
#include <QFile>
#include <QGuiApplication>
#include <QQmlApplicationEngine>
#include <QStandardPaths>
#include <QTextStream>

namespace {
Logger logger(LOG_MAIN, "CommandGpuCheck");

uint32_t s_vertexShaderErrorCount = 0;
void messageQTHandler(QtMsgType, const QMessageLogContext&,
const QString& message) {
if (message.contains("0x80070057")) {
++s_vertexShaderErrorCount;
}
}

} // namespace

CommandGpuCheck::CommandGpuCheck(QObject* parent)
: Command(parent, "gpucheck", "GPU configuration check") {
MVPN_COUNT_CTOR(CommandGpuCheck);
}

CommandGpuCheck::~CommandGpuCheck() { MVPN_COUNT_DTOR(CommandGpuCheck); }

int CommandGpuCheck::run(QStringList& tokens) {
Q_ASSERT(!tokens.isEmpty());

// Let's take the location before creating QGuiApplication.
QString location =
QStandardPaths::writableLocation(QStandardPaths::AppDataLocation);

QGuiApplication app(CommandLineParser::argc(), CommandLineParser::argv());

qInstallMessageHandler(messageQTHandler);

QObject::connect(&app, &QCoreApplication::aboutToQuit, [location]() {
QDir appDataLocation(location);
if (!appDataLocation.exists()) {
QDir tmp(location);
tmp.cdUp();
if (!tmp.exists()) {
return;
}
if (!tmp.mkdir(appDataLocation.dirName())) {
return;
}
}

QFile gpuCheckSettings = appDataLocation.filePath("moz.vpn.gpucheck");
if (s_vertexShaderErrorCount == 0) {
if (gpuCheckSettings.exists()) {
gpuCheckSettings.remove();
}
return;
}

if (!gpuCheckSettings.open(QIODevice::WriteOnly | QIODevice::Text)) {
return;
}

gpuCheckSettings.write("software");
});

QQmlApplicationEngine engine;
const QUrl url("qrc:/gpucheck/main.qml");
QObject::connect(
&engine, &QQmlApplicationEngine::objectCreated, &app,
[url](QObject* obj, const QUrl& objUrl) {
if (!obj && url == objUrl) {
QCoreApplication::exit(-1);
}
},
Qt::QueuedConnection);
engine.load(url);

return app.exec();
}

static Command::RegistrationProxy<CommandGpuCheck> s_commandGpuCheck;
18 changes: 18 additions & 0 deletions src/commands/commandgpucheck.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */

#ifndef COMMANDGPUCHECK_H
#define COMMANDGPUCHECK_H

#include "command.h"

class CommandGpuCheck final : public Command {
public:
explicit CommandGpuCheck(QObject* parent);
~CommandGpuCheck();

int run(QStringList& tokens) override;
};

#endif // COMMANDGPUCHECK_H
7 changes: 6 additions & 1 deletion src/commands/commandui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
#include "leakdetector.h"
#include "localizer.h"
#include "logger.h"
#include "loghandler.h"
#include "models/guidemodel.h"
#include "models/tutorialmodel.h"
#include "mozillavpn.h"
Expand All @@ -33,6 +32,8 @@
#include <lottie.h>
#include <nebula.h>

#include <QQmlContext>

#ifdef MVPN_DEBUG
# include <QQmlDebuggingEnabler>
#endif
Expand Down Expand Up @@ -184,6 +185,10 @@ int CommandUI::run(QStringList& tokens) {
QmlEngineHolder engineHolder;
QQmlApplicationEngine* engine = QmlEngineHolder::instance()->engine();

// TODO pending #3398
QQmlContext* ctx = engine->rootContext();
ctx->setContextProperty("QT_QUICK_BACKEND", qgetenv("QT_QUICK_BACKEND"));

Glean::Initialize(engine);
Lottie::initialize(engine, QString(NetworkManager::userAgent()));
Nebula::Initialize(engine);
Expand Down
4 changes: 4 additions & 0 deletions src/qmake/platforms/windows.pri
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ RC_ICONS = $$PWD/../../ui/resources/logo.ico

SOURCES += \
commands/commandcrashreporter.cpp \
commands/commandgpucheck.cpp \
daemon/daemon.cpp \
daemon/daemonlocalserver.cpp \
daemon/daemonlocalserverconnection.cpp \
Expand Down Expand Up @@ -60,6 +61,7 @@ SOURCES += \

HEADERS += \
commands/commandcrashreporter.h \
commands/commandgpucheck.h \
daemon/interfaceconfig.h \
daemon/daemon.h \
daemon/daemonlocalserver.h \
Expand Down Expand Up @@ -155,3 +157,5 @@ mozillavpnnp.files = $$PWD/../../../mozillavpnnp.exe
mozillavpnnp.path = $$PWD/../../../unsigned/
mozillavpnnp.CONFIG = no_check_exist executable
INSTALLS += mozillavpnnp

RESOURCES += ui/gpucheck.qrc
Loading

0 comments on commit f1176a1

Please sign in to comment.