File indexing completed on 2024-11-10 04:56:27

0001 /*
0002     KWin - the KDE window manager
0003     This file is part of the KDE project.
0004 
0005     SPDX-FileCopyrightText: 2016 Roman Gilg <subdiff@gmail.com>
0006 
0007     SPDX-License-Identifier: GPL-2.0-or-later
0008 */
0009 #include "drm_crtc.h"
0010 #include "drm_backend.h"
0011 #include "drm_buffer.h"
0012 #include "drm_commit.h"
0013 #include "drm_gpu.h"
0014 #include "drm_output.h"
0015 #include "drm_pointer.h"
0016 
0017 namespace KWin
0018 {
0019 
0020 DrmCrtc::DrmCrtc(DrmGpu *gpu, uint32_t crtcId, int pipeIndex, DrmPlane *primaryPlane, DrmPlane *cursorPlane)
0021     : DrmObject(gpu, crtcId, DRM_MODE_OBJECT_CRTC)
0022     , modeId(this, QByteArrayLiteral("MODE_ID"))
0023     , active(this, QByteArrayLiteral("ACTIVE"))
0024     , vrrEnabled(this, QByteArrayLiteral("VRR_ENABLED"))
0025     , gammaLut(this, QByteArrayLiteral("GAMMA_LUT"))
0026     , gammaLutSize(this, QByteArrayLiteral("GAMMA_LUT_SIZE"))
0027     , ctm(this, QByteArrayLiteral("CTM"))
0028     , degammaLut(this, QByteArrayLiteral("DEGAMMA_LUT"))
0029     , degammaLutSize(this, QByteArrayLiteral("DEGAMMA_LUT_SIZE"))
0030     , m_crtc(drmModeGetCrtc(gpu->fd(), crtcId))
0031     , m_pipeIndex(pipeIndex)
0032     , m_primaryPlane(primaryPlane)
0033     , m_cursorPlane(cursorPlane)
0034 {
0035 }
0036 
0037 bool DrmCrtc::updateProperties()
0038 {
0039     if (!m_crtc) {
0040         return false;
0041     }
0042     DrmPropertyList props = queryProperties();
0043     modeId.update(props);
0044     active.update(props);
0045     vrrEnabled.update(props);
0046     gammaLut.update(props);
0047     gammaLutSize.update(props);
0048     ctm.update(props);
0049     degammaLut.update(props);
0050     degammaLutSize.update(props);
0051 
0052     return !gpu()->atomicModeSetting() || (modeId.isValid() && active.isValid());
0053 }
0054 
0055 drmModeModeInfo DrmCrtc::queryCurrentMode()
0056 {
0057     m_crtc.reset(drmModeGetCrtc(gpu()->fd(), id()));
0058     return m_crtc->mode;
0059 }
0060 
0061 int DrmCrtc::pipeIndex() const
0062 {
0063     return m_pipeIndex;
0064 }
0065 
0066 std::shared_ptr<DrmFramebuffer> DrmCrtc::current() const
0067 {
0068     return m_currentBuffer;
0069 }
0070 
0071 void DrmCrtc::setCurrent(const std::shared_ptr<DrmFramebuffer> &buffer)
0072 {
0073     m_currentBuffer = buffer;
0074 }
0075 
0076 int DrmCrtc::gammaRampSize() const
0077 {
0078     if (gpu()->atomicModeSetting()) {
0079         // limit atomic gamma ramp to 4096 to work around https://gitlab.freedesktop.org/drm/intel/-/issues/3916
0080         if (gammaLutSize.isValid() && gammaLutSize.value() <= 4096) {
0081             return gammaLutSize.value();
0082         }
0083     }
0084     return m_crtc->gamma_size;
0085 }
0086 
0087 DrmPlane *DrmCrtc::primaryPlane() const
0088 {
0089     return m_primaryPlane;
0090 }
0091 
0092 DrmPlane *DrmCrtc::cursorPlane() const
0093 {
0094     return m_cursorPlane;
0095 }
0096 
0097 void DrmCrtc::disable(DrmAtomicCommit *commit)
0098 {
0099     commit->addProperty(active, 0);
0100     commit->addProperty(modeId, 0);
0101 }
0102 
0103 void DrmCrtc::releaseCurrentBuffer()
0104 {
0105     if (m_currentBuffer) {
0106         m_currentBuffer->releaseBuffer();
0107     }
0108 }
0109 }