2021-02-04 09:07:20 +00:00
|
|
|
/*
|
|
|
|
SPDX-FileCopyrightText: 2021 Vlad Zahorodnii <vlad.zahorodnii@kde.org>
|
|
|
|
|
|
|
|
SPDX-License-Identifier: GPL-2.0-or-later
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "surfaceitem_internal.h"
|
2021-04-09 07:06:04 +00:00
|
|
|
#include "composite.h"
|
|
|
|
#include "scene.h"
|
2021-02-04 09:07:20 +00:00
|
|
|
|
|
|
|
namespace KWin
|
|
|
|
{
|
|
|
|
|
2021-08-12 09:07:38 +00:00
|
|
|
SurfaceItemInternal::SurfaceItemInternal(Toplevel *window, Item *parent)
|
2021-02-04 09:07:20 +00:00
|
|
|
: SurfaceItem(window, parent)
|
|
|
|
{
|
2021-08-12 09:07:38 +00:00
|
|
|
connect(window, &Toplevel::bufferGeometryChanged,
|
2021-02-04 09:07:20 +00:00
|
|
|
this, &SurfaceItemInternal::handleBufferGeometryChanged);
|
|
|
|
|
2021-08-12 09:07:38 +00:00
|
|
|
setSize(window->bufferGeometry().size());
|
2021-02-04 09:07:20 +00:00
|
|
|
|
2021-07-21 19:25:42 +00:00
|
|
|
// The device pixel ratio of the internal window is static.
|
|
|
|
QMatrix4x4 surfaceToBufferMatrix;
|
2021-08-12 09:07:38 +00:00
|
|
|
surfaceToBufferMatrix.scale(window->bufferScale());
|
2021-07-21 19:25:42 +00:00
|
|
|
setSurfaceToBufferMatrix(surfaceToBufferMatrix);
|
2021-02-04 09:07:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
QRegion SurfaceItemInternal::shape() const
|
|
|
|
{
|
2021-07-05 17:40:47 +00:00
|
|
|
return QRegion(rect());
|
2021-02-04 09:07:20 +00:00
|
|
|
}
|
|
|
|
|
2021-04-09 07:06:04 +00:00
|
|
|
SurfacePixmap *SurfaceItemInternal::createPixmap()
|
2021-02-04 09:07:20 +00:00
|
|
|
{
|
2021-04-09 07:06:04 +00:00
|
|
|
return new SurfacePixmapInternal(this);
|
2021-02-04 09:07:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void SurfaceItemInternal::handleBufferGeometryChanged(Toplevel *toplevel, const QRect &old)
|
|
|
|
{
|
|
|
|
if (toplevel->bufferGeometry().size() != old.size()) {
|
|
|
|
discardPixmap();
|
|
|
|
}
|
|
|
|
setSize(toplevel->bufferGeometry().size());
|
|
|
|
}
|
|
|
|
|
2021-04-09 07:06:04 +00:00
|
|
|
SurfacePixmapInternal::SurfacePixmapInternal(SurfaceItemInternal *item, QObject *parent)
|
2021-10-20 14:58:58 +00:00
|
|
|
: SurfacePixmap(Compositor::self()->scene()->createSurfaceTextureInternal(this), parent)
|
2021-04-09 07:06:04 +00:00
|
|
|
, m_item(item)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
QOpenGLFramebufferObject *SurfacePixmapInternal::fbo() const
|
|
|
|
{
|
|
|
|
return m_fbo.data();
|
|
|
|
}
|
|
|
|
|
|
|
|
QImage SurfacePixmapInternal::image() const
|
|
|
|
{
|
|
|
|
return m_rasterBuffer;
|
|
|
|
}
|
|
|
|
|
|
|
|
void SurfacePixmapInternal::create()
|
|
|
|
{
|
|
|
|
update();
|
|
|
|
}
|
|
|
|
|
|
|
|
void SurfacePixmapInternal::update()
|
|
|
|
{
|
2021-08-12 09:07:38 +00:00
|
|
|
const Toplevel *window = m_item->window();
|
2021-04-09 07:06:04 +00:00
|
|
|
|
2021-08-12 09:07:38 +00:00
|
|
|
if (window->internalFramebufferObject()) {
|
|
|
|
m_fbo = window->internalFramebufferObject();
|
2021-04-09 07:06:04 +00:00
|
|
|
m_hasAlphaChannel = true;
|
2021-08-12 09:07:38 +00:00
|
|
|
} else if (!window->internalImageObject().isNull()) {
|
|
|
|
m_rasterBuffer = window->internalImageObject();
|
2021-04-09 07:06:04 +00:00
|
|
|
m_hasAlphaChannel = m_rasterBuffer.hasAlphaChannel();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool SurfacePixmapInternal::isValid() const
|
|
|
|
{
|
|
|
|
return !m_fbo.isNull() || !m_rasterBuffer.isNull();
|
|
|
|
}
|
|
|
|
|
2021-02-04 09:07:20 +00:00
|
|
|
} // namespace KWin
|