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"
|
2022-04-22 17:45:19 +00:00
|
|
|
#include "internalwindow.h"
|
2021-04-09 07:06:04 +00:00
|
|
|
#include "scene.h"
|
2021-02-04 09:07:20 +00:00
|
|
|
|
2022-07-13 13:23:13 +00:00
|
|
|
#include <QOpenGLFramebufferObject>
|
|
|
|
|
2021-02-04 09:07:20 +00:00
|
|
|
namespace KWin
|
|
|
|
{
|
|
|
|
|
2022-04-22 17:45:19 +00:00
|
|
|
SurfaceItemInternal::SurfaceItemInternal(InternalWindow *window, Item *parent)
|
2021-02-04 09:07:20 +00:00
|
|
|
: SurfaceItem(window, parent)
|
|
|
|
{
|
2022-04-22 17:39:12 +00:00
|
|
|
connect(window, &Window::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
|
|
|
}
|
|
|
|
|
2022-09-12 09:29:33 +00:00
|
|
|
QVector<QRectF> SurfaceItemInternal::shape() const
|
2021-02-04 09:07:20 +00:00
|
|
|
{
|
2022-09-12 09:29:33 +00:00
|
|
|
return {rect()};
|
2021-02-04 09:07:20 +00:00
|
|
|
}
|
|
|
|
|
2022-06-29 11:24:56 +00:00
|
|
|
std::unique_ptr<SurfacePixmap> SurfaceItemInternal::createPixmap()
|
2021-02-04 09:07:20 +00:00
|
|
|
{
|
2022-06-29 11:24:56 +00:00
|
|
|
return std::make_unique<SurfacePixmapInternal>(this);
|
2021-02-04 09:07:20 +00:00
|
|
|
}
|
|
|
|
|
2022-05-16 20:13:39 +00:00
|
|
|
void SurfaceItemInternal::handleBufferGeometryChanged(Window *window, const QRectF &old)
|
2021-02-04 09:07:20 +00:00
|
|
|
{
|
2022-04-28 07:44:11 +00:00
|
|
|
if (window->bufferGeometry().size() != old.size()) {
|
2021-02-04 09:07:20 +00:00
|
|
|
discardPixmap();
|
|
|
|
}
|
2022-04-28 07:44:11 +00:00
|
|
|
setSize(window->bufferGeometry().size());
|
2021-02-04 09:07:20 +00:00
|
|
|
}
|
|
|
|
|
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
|
|
|
|
{
|
2022-05-17 10:36:34 +00:00
|
|
|
return m_fbo.get();
|
2021-04-09 07:06:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
QImage SurfacePixmapInternal::image() const
|
|
|
|
{
|
|
|
|
return m_rasterBuffer;
|
|
|
|
}
|
|
|
|
|
|
|
|
void SurfacePixmapInternal::create()
|
|
|
|
{
|
|
|
|
update();
|
|
|
|
}
|
|
|
|
|
|
|
|
void SurfacePixmapInternal::update()
|
|
|
|
{
|
2022-04-22 17:39:12 +00:00
|
|
|
const Window *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();
|
2022-07-13 13:23:13 +00:00
|
|
|
m_size = m_fbo->size();
|
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();
|
2022-07-13 13:23:13 +00:00
|
|
|
m_size = m_rasterBuffer.size();
|
2021-04-09 07:06:04 +00:00
|
|
|
m_hasAlphaChannel = m_rasterBuffer.hasAlphaChannel();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool SurfacePixmapInternal::isValid() const
|
|
|
|
{
|
2022-05-17 10:36:34 +00:00
|
|
|
return m_fbo != nullptr || !m_rasterBuffer.isNull();
|
2021-04-09 07:06:04 +00:00
|
|
|
}
|
|
|
|
|
2021-02-04 09:07:20 +00:00
|
|
|
} // namespace KWin
|