-
-
Notifications
You must be signed in to change notification settings - Fork 11
/
main.cpp
104 lines (82 loc) · 2.32 KB
/
main.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
#include "MainWindow.h"
#include "VideoFrameData.h"
#include "GlobalData.h"
#include "joinpath.h"
#include "main.h"
#include <QApplication>
#include <QDir>
#include <QFileInfo>
#include <QMetaType>
#include <QPluginLoader>
#include <QStandardPaths>
#include <QTextStream>
#include "CudaPlugin/src/CudaPlugin.h"
class DebugMessageHandler {
public:
DebugMessageHandler() = delete;
static void install();
static void abort(const QMessageLogContext &context, const QString &message);
};
void DebugMessageHandler::abort(QMessageLogContext const &/*context*/, const QString &/*message*/)
{
::abort();
}
void debugMessageHandler(QtMsgType type, const QMessageLogContext &context, const QString &message)
{
(QTextStream(stderr) << qFormatLogMessage(type, context, message) << '\n').flush();
if (type == QtFatalMsg) {
DebugMessageHandler::abort(context, message);
}
}
void DebugMessageHandler::install()
{
qInstallMessageHandler(debugMessageHandler);
}
Cuda *get_cuda_plugin()
{
return global->cuda_plugin.get();
}
int main(int argc, char *argv[])
{
putenv("QT_ASSUME_STDERR_HAS_CONSOLE=1");
#ifdef Q_OS_WIN
CoInitialize(nullptr);
#endif
DebugMessageHandler::install();
global = new GlobalData;
global->organization_name = ORGANIZATION_NAME;
global->application_name = APPLICATION_NAME;
global->generic_config_dir = QStandardPaths::writableLocation(QStandardPaths::GenericConfigLocation);
global->app_config_dir = global->generic_config_dir / global->organization_name / global->application_name;
global->config_file_path = joinpath(global->app_config_dir, global->application_name + ".ini");
if (!QFileInfo(global->app_config_dir).isDir()) {
QDir().mkpath(global->app_config_dir);
}
QApplication a(argc, argv);
QPluginLoader loader("cudaplugin");
CudaInterface *plugin = dynamic_cast<CudaInterface *>(loader.instance());
if (plugin) {
global->cuda_plugin = std::shared_ptr<Cuda>(plugin->create());
if (!global->cuda_plugin->init()) {
qDebug() << "failed to init the plugin";
}
} else {
qDebug() << "failed to load the plugin";
}
qRegisterMetaType<Rational>();
qRegisterMetaType<VideoFrameData>();
{
QPixmap pm(1, 1);
pm.fill(Qt::transparent);
global->invisible_cursor = QCursor(pm);
}
MainWindow w;
w.show();
w.setup();
int r = a.exec();
#ifdef Q_OS_WIN
CoUninitialize();
#endif
delete global;
return r;
}