47113e09b8
Currently, dealing with sub-surfaces is very difficult due to the scene design being heavily influenced by X11 requirements. The goal of this change is to re-work scene abstractions to make improving the wayland support easier. The Item class is based on the QQuickItem class. My hope is that one day we will be able to transition to QtQuick for painting scene, but in meanwhile it makes more sense to have a minimalistic internal item class. The WindowItem class represents a window. The SurfaceItem class represents the contents of either an X11, or a Wayland, or an internal surface. The DecorationItem and the ShadowItem class represent the server-side deco and drop-shadow, respectively. At the moment, the SurfaceItem is bound to the scene window, but the long term plan is to break that connection so we could re-use the SurfaceItem for things such as software cursors and drag-and-drop additional icons. One of the responsibilities of the Item is to schedule repaints as needed. Ideally, there shouldn't be any addRepaint() calls in the core code. The Item class schedules repaints on geometry updates. In the future, it also has to request an update if its opacity or visibility changes.
119 lines
2.4 KiB
C++
119 lines
2.4 KiB
C++
/*
|
|
SPDX-FileCopyrightText: 2021 Vlad Zahorodnii <vlad.zahorodnii@kde.org>
|
|
|
|
SPDX-License-Identifier: GPL-2.0-or-later
|
|
*/
|
|
|
|
#include "surfaceitem.h"
|
|
|
|
namespace KWin
|
|
{
|
|
|
|
SurfaceItem::SurfaceItem(Scene::Window *window, Item *parent)
|
|
: Item(window, parent)
|
|
{
|
|
}
|
|
|
|
QPointF SurfaceItem::mapToWindow(const QPointF &point) const
|
|
{
|
|
return rootPosition() + point - window()->pos();
|
|
}
|
|
|
|
QRegion SurfaceItem::shape() const
|
|
{
|
|
return QRegion();
|
|
}
|
|
|
|
QRegion SurfaceItem::opaque() const
|
|
{
|
|
return QRegion();
|
|
}
|
|
|
|
void SurfaceItem::addDamage(const QRegion ®ion)
|
|
{
|
|
m_damage += region;
|
|
scheduleRepaint(region);
|
|
|
|
Toplevel *toplevel = window()->window();
|
|
emit toplevel->damaged(toplevel, region);
|
|
}
|
|
|
|
void SurfaceItem::resetDamage()
|
|
{
|
|
m_damage = QRegion();
|
|
}
|
|
|
|
QRegion SurfaceItem::damage() const
|
|
{
|
|
return m_damage;
|
|
}
|
|
|
|
WindowPixmap *SurfaceItem::windowPixmap() const
|
|
{
|
|
if (m_windowPixmap && m_windowPixmap->isValid()) {
|
|
return m_windowPixmap.data();
|
|
}
|
|
if (m_previousWindowPixmap && m_previousWindowPixmap->isValid()) {
|
|
return m_previousWindowPixmap.data();
|
|
}
|
|
return nullptr;
|
|
}
|
|
|
|
WindowPixmap *SurfaceItem::previousWindowPixmap() const
|
|
{
|
|
return m_previousWindowPixmap.data();
|
|
}
|
|
|
|
void SurfaceItem::referencePreviousPixmap()
|
|
{
|
|
if (m_previousWindowPixmap && m_previousWindowPixmap->isDiscarded()) {
|
|
m_referencePixmapCounter++;
|
|
}
|
|
}
|
|
|
|
void SurfaceItem::unreferencePreviousPixmap()
|
|
{
|
|
if (!m_previousWindowPixmap || !m_previousWindowPixmap->isDiscarded()) {
|
|
return;
|
|
}
|
|
m_referencePixmapCounter--;
|
|
if (m_referencePixmapCounter == 0) {
|
|
m_previousWindowPixmap.reset();
|
|
}
|
|
}
|
|
|
|
void SurfaceItem::updatePixmap()
|
|
{
|
|
if (m_windowPixmap.isNull()) {
|
|
m_windowPixmap.reset(createPixmap());
|
|
}
|
|
if (m_windowPixmap->isValid()) {
|
|
m_windowPixmap->update();
|
|
} else {
|
|
m_windowPixmap->create();
|
|
if (m_windowPixmap->isValid()) {
|
|
m_previousWindowPixmap.reset();
|
|
discardQuads();
|
|
}
|
|
}
|
|
}
|
|
|
|
void SurfaceItem::discardPixmap()
|
|
{
|
|
if (!m_windowPixmap.isNull()) {
|
|
if (m_windowPixmap->isValid()) {
|
|
m_previousWindowPixmap.reset(m_windowPixmap.take());
|
|
m_previousWindowPixmap->markAsDiscarded();
|
|
} else {
|
|
m_windowPixmap.reset();
|
|
}
|
|
}
|
|
addDamage(rect());
|
|
}
|
|
|
|
void SurfaceItem::preprocess()
|
|
{
|
|
updatePixmap();
|
|
}
|
|
|
|
} // namespace KWin
|