/* KWin - the KDE window manager This file is part of the KDE project. SPDX-FileCopyrightText: 2016 Roman Gilg SPDX-License-Identifier: GPL-2.0-or-later */ #include "drm_object_crtc.h" #include "drm_backend.h" #include "drm_output.h" #include "drm_buffer.h" #include "drm_pointer.h" #include "logging.h" #include "drm_gpu.h" namespace KWin { DrmCrtc::DrmCrtc(DrmGpu *gpu, uint32_t crtc_id, DrmBackend *backend, int resIndex) : DrmObject(gpu, crtc_id), m_crtc(drmModeGetCrtc(gpu->fd(), crtc_id)), m_resIndex(resIndex), m_backend(backend) { } bool DrmCrtc::init() { if (!m_crtc) { return false; } qCDebug(KWIN_DRM) << "Init for CRTC:" << resIndex() << "id:" << id(); return initProps({ PropertyDefinition(QByteArrayLiteral("MODE_ID")), PropertyDefinition(QByteArrayLiteral("ACTIVE")), }, DRM_MODE_OBJECT_CRTC); } void DrmCrtc::flipBuffer() { m_currentBuffer = m_nextBuffer; m_nextBuffer = nullptr; delete m_blackBuffer; m_blackBuffer = nullptr; } bool DrmCrtc::blank(DrmOutput *output) { if (gpu()->atomicModeSetting()) { return false; } if (!m_blackBuffer) { DrmDumbBuffer *blackBuffer = new DrmDumbBuffer(gpu(), output->pixelSize()); if (!blackBuffer->map()) { delete blackBuffer; return false; } blackBuffer->image()->fill(Qt::black); m_blackBuffer = blackBuffer; } if (output->setModeLegacy(m_blackBuffer)) { m_currentBuffer = nullptr; m_nextBuffer = nullptr; return true; } return false; } bool DrmCrtc::setGammaRamp(const GammaRamp &gamma) { uint16_t *red = const_cast(gamma.red()); uint16_t *green = const_cast(gamma.green()); uint16_t *blue = const_cast(gamma.blue()); const bool isError = drmModeCrtcSetGamma(gpu()->fd(), id(), gamma.size(), red, green, blue); return !isError; } }