File indexing completed on 2024-11-10 04:57:16

0001 /*
0002     SPDX-FileCopyrightText: 2021 Vlad Zahorodnii <vlad.zahorodnii@kde.org>
0003 
0004     SPDX-License-Identifier: GPL-2.0-or-later
0005 */
0006 
0007 #include "scene/surfaceitem_internal.h"
0008 #include "compositor.h"
0009 #include "core/renderbackend.h"
0010 #include "internalwindow.h"
0011 
0012 namespace KWin
0013 {
0014 
0015 SurfaceItemInternal::SurfaceItemInternal(InternalWindow *window, Scene *scene, Item *parent)
0016     : SurfaceItem(scene, parent)
0017     , m_window(window)
0018 {
0019     connect(window, &Window::bufferGeometryChanged,
0020             this, &SurfaceItemInternal::handleBufferGeometryChanged);
0021 
0022     setDestinationSize(window->bufferGeometry().size());
0023     setBufferSourceBox(QRectF(QPointF(0, 0), window->bufferGeometry().size() * window->bufferScale()));
0024     setBufferSize((window->bufferGeometry().size() * window->bufferScale()).toSize());
0025 }
0026 
0027 InternalWindow *SurfaceItemInternal::window() const
0028 {
0029     return m_window;
0030 }
0031 
0032 QList<QRectF> SurfaceItemInternal::shape() const
0033 {
0034     return {rect()};
0035 }
0036 
0037 std::unique_ptr<SurfacePixmap> SurfaceItemInternal::createPixmap()
0038 {
0039     return std::make_unique<SurfacePixmapInternal>(this);
0040 }
0041 
0042 void SurfaceItemInternal::handleBufferGeometryChanged()
0043 {
0044     setDestinationSize(m_window->bufferGeometry().size());
0045     setBufferSourceBox(QRectF(QPointF(0, 0), m_window->bufferGeometry().size() * m_window->bufferScale()));
0046     setBufferSize((m_window->bufferGeometry().size() * m_window->bufferScale()).toSize());
0047 }
0048 
0049 SurfacePixmapInternal::SurfacePixmapInternal(SurfaceItemInternal *item, QObject *parent)
0050     : SurfacePixmap(Compositor::self()->backend()->createSurfaceTextureWayland(this), parent)
0051     , m_item(item)
0052 {
0053 }
0054 
0055 void SurfacePixmapInternal::create()
0056 {
0057     update();
0058 }
0059 
0060 void SurfacePixmapInternal::update()
0061 {
0062     const InternalWindow *window = m_item->window();
0063     setBuffer(window->graphicsBuffer());
0064     setBufferOrigin(window->graphicsBufferOrigin());
0065 }
0066 
0067 bool SurfacePixmapInternal::isValid() const
0068 {
0069     return m_bufferRef;
0070 }
0071 
0072 } // namespace KWin
0073 
0074 #include "moc_surfaceitem_internal.cpp"