File indexing completed on 2025-04-20 10:57:32

0001 /*
0002     KWin - the KDE window manager
0003     This file is part of the KDE project.
0004 
0005     SPDX-FileCopyrightText: 2021 Xaver Hugl <xaver.hugl@gmail.com>
0006 
0007     SPDX-License-Identifier: GPL-2.0-or-later
0008 */
0009 #include "drm_abstract_output.h"
0010 #include "core/renderloop_p.h"
0011 #include "drm_backend.h"
0012 #include "drm_gpu.h"
0013 
0014 namespace KWin
0015 {
0016 
0017 DrmAbstractOutput::DrmAbstractOutput(DrmGpu *gpu)
0018     : Output(gpu->platform())
0019     , m_renderLoop(std::make_unique<RenderLoop>())
0020     , m_gpu(gpu)
0021 {
0022 }
0023 
0024 RenderLoop *DrmAbstractOutput::renderLoop() const
0025 {
0026     return m_renderLoop.get();
0027 }
0028 
0029 void DrmAbstractOutput::frameFailed() const
0030 {
0031     RenderLoopPrivate::get(m_renderLoop.get())->notifyFrameFailed();
0032 }
0033 
0034 void DrmAbstractOutput::pageFlipped(std::chrono::nanoseconds timestamp) const
0035 {
0036     RenderLoopPrivate::get(m_renderLoop.get())->notifyFrameCompleted(timestamp);
0037 }
0038 
0039 QVector<int32_t> DrmAbstractOutput::regionToRects(const QRegion &region) const
0040 {
0041     const int height = pixelSize().height();
0042     const QMatrix4x4 matrix = Output::logicalToNativeMatrix(rect(), scale(), transform());
0043     QVector<EGLint> rects;
0044     rects.reserve(region.rectCount() * 4);
0045     for (const QRect &_rect : region) {
0046         const QRect rect = matrix.mapRect(_rect);
0047         rects << rect.left();
0048         rects << height - (rect.y() + rect.height());
0049         rects << rect.width();
0050         rects << rect.height();
0051     }
0052     return rects;
0053 }
0054 
0055 DrmGpu *DrmAbstractOutput::gpu() const
0056 {
0057     return m_gpu;
0058 }
0059 
0060 void DrmAbstractOutput::updateEnabled(bool enabled)
0061 {
0062     State next = m_state;
0063     next.enabled = enabled;
0064     setState(next);
0065 }
0066 
0067 }