kwin/plugins/platforms/virtual/virtual_output.cpp

72 lines
1.8 KiB
C++
Raw Normal View History

2020-08-02 22:22:19 +00:00
/*
KWin - the KDE window manager
This file is part of the KDE project.
2020-08-02 22:22:19 +00:00
SPDX-FileCopyrightText: 2018 Roman Gilg <subdiff@gmail.com>
2020-08-02 22:22:19 +00:00
SPDX-License-Identifier: GPL-2.0-or-later
*/
#include "virtual_output.h"
2020-11-19 08:52:29 +00:00
#include "renderloop_p.h"
#include "softwarevsyncmonitor.h"
namespace KWin
{
VirtualOutput::VirtualOutput(QObject *parent)
: AbstractWaylandOutput()
2020-11-19 08:52:29 +00:00
, m_renderLoop(new RenderLoop(this))
, m_vsyncMonitor(SoftwareVsyncMonitor::create(this))
{
Q_UNUSED(parent);
2020-11-19 08:52:29 +00:00
connect(m_vsyncMonitor, &VsyncMonitor::vblankOccurred, this, &VirtualOutput::vblank);
static int identifier = -1;
identifier++;
setName("Virtual-" + QString::number(identifier));
}
VirtualOutput::~VirtualOutput()
{
}
2020-11-19 08:52:29 +00:00
RenderLoop *VirtualOutput::renderLoop() const
{
return m_renderLoop;
}
SoftwareVsyncMonitor *VirtualOutput::vsyncMonitor() const
{
return m_vsyncMonitor;
}
void VirtualOutput::init(const QPoint &logicalPosition, const QSize &pixelSize)
{
2020-11-19 08:52:29 +00:00
const int refreshRate = 60000; // TODO: Make the refresh rate configurable.
m_renderLoop->setRefreshRate(refreshRate);
m_vsyncMonitor->setRefreshRate(refreshRate);
KWaylandServer::OutputDeviceInterface::Mode mode;
mode.id = 0;
mode.size = pixelSize;
mode.flags = KWaylandServer::OutputDeviceInterface::ModeFlag::Current;
2020-11-19 08:52:29 +00:00
mode.refreshRate = refreshRate;
initInterfaces("model_TODO", "manufacturer_TODO", "UUID_TODO", pixelSize, { mode }, {});
setGeometry(QRect(logicalPosition, pixelSize));
}
void VirtualOutput::setGeometry(const QRect &geo)
{
// TODO: set mode to have updated pixelSize
setGlobalPos(geo.topLeft());
}
2020-11-19 08:52:29 +00:00
void VirtualOutput::vblank(std::chrono::nanoseconds timestamp)
{
RenderLoopPrivate *renderLoopPrivate = RenderLoopPrivate::get(m_renderLoop);
renderLoopPrivate->notifyFrameCompleted(timestamp);
}
}