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
/
windowpixmapitem.cpp
99 lines (84 loc) · 2.77 KB
/
windowpixmapitem.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
#include "windowpixmapitem.h"
#include <QSGSimpleTextureNode>
#include "clientwindow.h"
#include "windowpixmap.h"
#include "glxtexturefrompixmap.h"
void WindowPixmapItem::registerQmlTypes()
{
qmlRegisterUncreatableType<ClientWindow>("Compositor", 1, 0, "ClientWindow", QString());
qmlRegisterType<WindowPixmap>();
qmlRegisterType<WindowPixmapItem>("Compositor", 1, 0, "WindowPixmap");
}
WindowPixmapItem::WindowPixmapItem()
{
setFlag(ItemHasContents);
}
WindowPixmapItem::~WindowPixmapItem()
{
}
void WindowPixmapItem::setClientWindow(ClientWindow *w)
{
if (w == clientWindow_.data()) {
return;
}
if (clientWindow_) {
clientWindow_->disconnect(this);
}
clientWindow_ = w->sharedFromThis();
connect(clientWindow_.data(), SIGNAL(geometryChanged(QRect)), SLOT(updateImplicitSize()));
connect(clientWindow_.data(), SIGNAL(mapStateChanged(bool)), SLOT(updateImplicitSize()));
connect(clientWindow_.data(), SIGNAL(mapStateChanged(bool)), SLOT(update()));
updateImplicitSize();
update();
Q_EMIT clientWindowChanged();
}
QSGNode *WindowPixmapItem::updatePaintNode(QSGNode *old, UpdatePaintNodeData *)
{
auto node = static_cast<QSGSimpleTextureNode *>(old);
auto pixmap = clientWindow_->pixmap();
if (!clientWindow_ || !pixmap || !pixmap->isValid()) {
delete node;
return Q_NULLPTR;
}
if (!node) {
node = new QSGSimpleTextureNode;
}
auto texture = static_cast<GLXTextureFromPixmap *>(node->texture());
if (texture && pixmap_ != pixmap) {
delete texture;
texture = Q_NULLPTR;
}
pixmap_ = pixmap;
if (!texture) {
texture = new GLXTextureFromPixmap(pixmap->pixmap(), pixmap->visual(), pixmap->size());
node->setTexture(texture);
node->setOwnsTexture(true);
if (texture->isYInverted()) {
node->setTextureCoordinatesTransform(QSGSimpleTextureNode::MirrorVertically);
} else {
node->setTextureCoordinatesTransform(QSGSimpleTextureNode::NoTransform);
}
connect(pixmap.data(), SIGNAL(damaged()), SLOT(update()));
}
node->setRect(0, 0, width(), height());
if (pixmap->isDamaged()) {
texture->rebind();
node->markDirty(QSGNode::DirtyMaterial);
pixmap->clearDamage();
}
return node;
}
void WindowPixmapItem::updateImplicitSize()
{
QSize winSize;
if (clientWindow_) {
if (clientWindow()->isValid() && clientWindow_->isMapped()) {
winSize = clientWindow_->geometry().size();
} else if (pixmap_ && pixmap_->isValid()) {
winSize = pixmap_->size();
}
}
if (implicitWidth() != winSize.width() || implicitHeight() != winSize.height()) {
setImplicitSize(winSize.width(), winSize.height());
}
}