File indexing completed on 2024-11-10 04:57:14
0001 /* 0002 SPDX-FileCopyrightText: 2022 Vlad Zahorodnii <vlad.zahorodnii@kde.org> 0003 0004 SPDX-License-Identifier: GPL-2.0-or-later 0005 */ 0006 0007 #include "scene/cursorscene.h" 0008 #include "core/output.h" 0009 #include "core/rendertarget.h" 0010 #include "core/renderviewport.h" 0011 #include "effect/effect.h" 0012 #include "scene/cursoritem.h" 0013 #include "scene/itemrenderer.h" 0014 0015 namespace KWin 0016 { 0017 0018 CursorScene::CursorScene(std::unique_ptr<ItemRenderer> &&renderer) 0019 : Scene(std::move(renderer)) 0020 { 0021 m_rootItem = std::make_unique<CursorItem>(this); 0022 setGeometry(m_rootItem->boundingRect().toRect()); 0023 connect(m_rootItem.get(), &Item::boundingRectChanged, this, [this]() { 0024 setGeometry(m_rootItem->boundingRect().toRect()); 0025 }); 0026 } 0027 0028 CursorScene::~CursorScene() 0029 { 0030 // Avoid accessing m_rootItem if the boundingRectChanged signal is emitted. 0031 disconnect(m_rootItem.get(), nullptr, this, nullptr); 0032 m_rootItem.reset(); 0033 } 0034 0035 static void resetRepaintsHelper(Item *item, SceneDelegate *delegate) 0036 { 0037 item->resetRepaints(delegate); 0038 0039 const auto childItems = item->childItems(); 0040 for (Item *childItem : childItems) { 0041 resetRepaintsHelper(childItem, delegate); 0042 } 0043 } 0044 0045 QRegion CursorScene::prePaint(SceneDelegate *delegate) 0046 { 0047 resetRepaintsHelper(m_rootItem.get(), delegate); 0048 m_paintedOutput = delegate->output(); 0049 return QRegion(); 0050 } 0051 0052 void CursorScene::postPaint() 0053 { 0054 } 0055 0056 void CursorScene::paint(const RenderTarget &renderTarget, const QRegion ®ion) 0057 { 0058 RenderViewport viewport(QRectF(QPointF(), QSizeF(renderTarget.size()) / m_paintedOutput->scale()), m_paintedOutput->scale(), renderTarget); 0059 m_renderer->beginFrame(renderTarget, viewport); 0060 m_renderer->renderBackground(renderTarget, viewport, region); 0061 m_renderer->renderItem(renderTarget, viewport, m_rootItem.get(), 0, region, WindowPaintData(viewport.projectionMatrix())); 0062 m_renderer->endFrame(); 0063 } 0064 0065 } // namespace KWin 0066 0067 #include "moc_cursorscene.cpp"