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/cursordelegate_qpainter.h" 0008 #include "compositor.h" 0009 #include "core/output.h" 0010 #include "core/renderlayer.h" 0011 #include "core/rendertarget.h" 0012 #include "core/renderviewport.h" 0013 #include "cursor.h" 0014 #include "scene/cursorscene.h" 0015 0016 #include <QPainter> 0017 0018 namespace KWin 0019 { 0020 0021 CursorDelegateQPainter::CursorDelegateQPainter(Output *output) 0022 : m_output(output) 0023 { 0024 } 0025 0026 void CursorDelegateQPainter::paint(const RenderTarget &renderTarget, const QRegion ®ion) 0027 { 0028 if (!region.intersects(layer()->mapToGlobal(layer()->rect()).toAlignedRect())) { 0029 return; 0030 } 0031 0032 QImage *buffer = renderTarget.image(); 0033 if (Q_UNLIKELY(!buffer)) { 0034 return; 0035 } 0036 0037 const QSize bufferSize = (Cursors::self()->currentCursor()->rect().size() * m_output->scale()).toSize(); 0038 if (m_buffer.size() != bufferSize) { 0039 m_buffer = QImage(bufferSize, QImage::Format_ARGB32_Premultiplied); 0040 } 0041 0042 RenderTarget offscreenRenderTarget(&m_buffer); 0043 0044 RenderLayer renderLayer(layer()->loop()); 0045 renderLayer.setDelegate(std::make_unique<SceneDelegate>(Compositor::self()->cursorScene(), m_output)); 0046 renderLayer.delegate()->prePaint(); 0047 renderLayer.delegate()->paint(offscreenRenderTarget, infiniteRegion()); 0048 renderLayer.delegate()->postPaint(); 0049 0050 QPainter painter(buffer); 0051 painter.setClipRegion(region); 0052 painter.drawImage(layer()->mapToGlobal(layer()->rect()), m_buffer); 0053 } 0054 0055 } // namespace KWin