File indexing completed on 2024-11-10 04:57:15
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/scene.h" 0008 #include "core/output.h" 0009 #include "core/renderlayer.h" 0010 #include "scene/itemrenderer.h" 0011 0012 namespace KWin 0013 { 0014 0015 SceneDelegate::SceneDelegate(Scene *scene, Output *output) 0016 : m_scene(scene) 0017 , m_output(output) 0018 { 0019 m_scene->addDelegate(this); 0020 } 0021 0022 SceneDelegate::~SceneDelegate() 0023 { 0024 m_scene->removeDelegate(this); 0025 } 0026 0027 SurfaceItem *SceneDelegate::scanoutCandidate() const 0028 { 0029 return m_scene->scanoutCandidate(); 0030 } 0031 0032 QRegion SceneDelegate::prePaint() 0033 { 0034 return m_scene->prePaint(this); 0035 } 0036 0037 void SceneDelegate::postPaint() 0038 { 0039 m_scene->postPaint(); 0040 } 0041 0042 void SceneDelegate::paint(const RenderTarget &renderTarget, const QRegion ®ion) 0043 { 0044 m_scene->paint(renderTarget, region == infiniteRegion() ? infiniteRegion() : region.translated(viewport().topLeft())); 0045 } 0046 0047 void SceneDelegate::frame(OutputFrame *frame) 0048 { 0049 m_scene->frame(this, frame); 0050 } 0051 0052 Output *SceneDelegate::output() const 0053 { 0054 return m_output; 0055 } 0056 0057 qreal SceneDelegate::scale() const 0058 { 0059 return m_output ? m_output->scale() : 1.0; 0060 } 0061 0062 QRect SceneDelegate::viewport() const 0063 { 0064 return m_output ? m_output->geometry() : m_scene->geometry(); 0065 } 0066 0067 Scene::Scene(std::unique_ptr<ItemRenderer> &&renderer) 0068 : m_renderer(std::move(renderer)) 0069 { 0070 } 0071 0072 Scene::~Scene() 0073 { 0074 } 0075 0076 ItemRenderer *Scene::renderer() const 0077 { 0078 return m_renderer.get(); 0079 } 0080 0081 void Scene::addRepaintFull() 0082 { 0083 addRepaint(geometry()); 0084 } 0085 0086 void Scene::addRepaint(int x, int y, int width, int height) 0087 { 0088 addRepaint(QRegion(x, y, width, height)); 0089 } 0090 0091 void Scene::addRepaint(const QRegion ®ion) 0092 { 0093 for (const auto &delegate : std::as_const(m_delegates)) { 0094 const QRect viewport = delegate->viewport(); 0095 QRegion dirtyRegion = region & viewport; 0096 dirtyRegion.translate(-viewport.topLeft()); 0097 if (!dirtyRegion.isEmpty()) { 0098 delegate->layer()->addRepaint(dirtyRegion); 0099 } 0100 } 0101 } 0102 0103 QRegion Scene::damage() const 0104 { 0105 return QRegion(); 0106 } 0107 0108 QRect Scene::geometry() const 0109 { 0110 return m_geometry; 0111 } 0112 0113 void Scene::setGeometry(const QRect &rect) 0114 { 0115 if (m_geometry != rect) { 0116 m_geometry = rect; 0117 addRepaintFull(); 0118 } 0119 } 0120 0121 QList<SceneDelegate *> Scene::delegates() const 0122 { 0123 return m_delegates; 0124 } 0125 0126 void Scene::addDelegate(SceneDelegate *delegate) 0127 { 0128 m_delegates.append(delegate); 0129 } 0130 0131 void Scene::removeDelegate(SceneDelegate *delegate) 0132 { 0133 m_delegates.removeOne(delegate); 0134 Q_EMIT delegateRemoved(delegate); 0135 } 0136 0137 SurfaceItem *Scene::scanoutCandidate() const 0138 { 0139 return nullptr; 0140 } 0141 0142 void Scene::frame(SceneDelegate *delegate, OutputFrame *frame) 0143 { 0144 } 0145 0146 } // namespace KWin 0147 0148 #include "moc_scene.cpp"