File indexing completed on 2024-11-10 04:56:56
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 "qpaintersurfacetexture_wayland.h" 0008 #include "core/graphicsbufferview.h" 0009 0010 #include <QPainter> 0011 0012 namespace KWin 0013 { 0014 0015 QPainterSurfaceTextureWayland::QPainterSurfaceTextureWayland(QPainterBackend *backend, SurfacePixmap *pixmap) 0016 : QPainterSurfaceTexture(backend) 0017 , m_pixmap(pixmap) 0018 { 0019 } 0020 0021 bool QPainterSurfaceTextureWayland::create() 0022 { 0023 const GraphicsBufferView view(m_pixmap->buffer()); 0024 if (Q_LIKELY(view.image())) { 0025 // The buffer data is copied as the buffer interface returns a QImage 0026 // which doesn't own the data of the underlying wl_shm_buffer object. 0027 m_image = view.image()->copy(); 0028 } 0029 return !m_image.isNull(); 0030 } 0031 0032 void QPainterSurfaceTextureWayland::update(const QRegion ®ion) 0033 { 0034 const GraphicsBufferView view(m_pixmap->buffer()); 0035 if (Q_UNLIKELY(!view.image())) { 0036 return; 0037 } 0038 0039 QPainter painter(&m_image); 0040 painter.setCompositionMode(QPainter::CompositionMode_Source); 0041 0042 // The buffer data is copied as the buffer interface returns a QImage 0043 // which doesn't own the data of the underlying wl_shm_buffer object. 0044 for (const QRect &rect : region) { 0045 painter.drawImage(rect, *view.image(), rect); 0046 } 0047 } 0048 0049 } // namespace KWin