This repository has been archived by the owner on Apr 3, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmain.cpp
105 lines (83 loc) · 2.94 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
105
#include "compositor.h"
#include <QGuiApplication>
#include <QOpenGLContext>
#include <QOpenGLDebugMessage>
#include <QOpenGLFunctions>
#include <QScreen>
#include <QQmlContext>
#include <QQuickView>
#include <QX11Info>
#include <QThread>
#include <xcb/xcb.h>
#include <xcb/damage.h>
#include <xcb/composite.h>
#include "windowpixmapitem.h"
class DebugLog : public QObject
{
Q_OBJECT
public:
DebugLog()
{
connect(&glLog, SIGNAL(messageLogged(QOpenGLDebugMessage)),
SLOT(message(QOpenGLDebugMessage)), Qt::DirectConnection);
}
public Q_SLOTS:
void init()
{
QOpenGLContext *context = QOpenGLContext::currentContext();
QOpenGLFunctions *functions = context->functions();
qDebug() << "GL_VENDOR:"
<< reinterpret_cast<const char *>(functions->glGetString(GL_VENDOR));
qDebug() << "GL_RENDERER:"
<< reinterpret_cast<const char *>(functions->glGetString(GL_RENDERER));
qDebug() << "GL_VERSION:"
<< reinterpret_cast<const char *>(functions->glGetString(GL_VERSION));
if (glLog.initialize()) {
glLog.enableMessages();
glLog.startLogging();
} else {
qWarning() << "Can't initialize QOpenGLDebugLogger";
}
}
void message(const QOpenGLDebugMessage &m)
{
qDebug() << m;
}
private:
QOpenGLDebugLogger glLog;
};
int main(int argc, char *argv[])
{
QGuiApplication app(argc, argv);
auto connection = QX11Info::connection();
qDebug() << "Damage major_opcode:" << xcb_get_extension_data(connection, &xcb_damage_id)->major_opcode;
qDebug() << "Composite major_opcode:" << xcb_get_extension_data(connection, &xcb_composite_id)->major_opcode;
WindowPixmapItem::registerQmlTypes();
Compositor compositor;
QQuickView view;
compositor.registerCompositor(&view);
QObject::connect(&view, &QQuickView::sceneGraphError,
[](QQuickWindow::SceneGraphError, const QString &message)
{
qCritical() << "Scene graph error:" << message;
});
#ifndef NDEBUG
QSurfaceFormat format(view.format());
format.setOption(QSurfaceFormat::DebugContext);
view.setFormat(format);
#endif
DebugLog logger;
QObject::connect(&view, SIGNAL(sceneGraphInitialized()),
&logger, SLOT(init()), Qt::DirectConnection);
view.rootContext()->setContextProperty(QStringLiteral("compositor"), &compositor);
view.setParent(compositor.overlayWindow());
view.setSource(QStringLiteral("qrc:/main.qml"));
view.show();
qDebug() << "Root geometry:" << compositor.rootGeometry();
view.setGeometry(compositor.rootGeometry());
QObject::connect(&compositor, &Compositor::rootGeometryChanged,
&view, static_cast<void (QQuickView::*)(const QRect &)>(&QQuickView::setGeometry));
qDebug() << "Main thread:" << QThread::currentThread();
return app.exec();
}
#include "main.moc"