KWin
Loading...
Searching...
No Matches
outputscreencastsource.cpp
Go to the documentation of this file.
1/*
2 SPDX-FileCopyrightText: 2021 Vlad Zahorodnii <vlad.zahorodnii@kde.org>
3
4 SPDX-License-Identifier: GPL-2.0-or-later
5*/
6
8#include "screencastutils.h"
9
10#include "compositor.h"
11#include "core/output.h"
12#include "core/renderloop.h"
13#include "opengl/gltexture.h"
14#include "opengl/glutils.h"
16
17#include <drm_fourcc.h>
18
19namespace KWin
20{
21
23 : ScreenCastSource(parent)
24 , m_output(output)
25{
26 connect(m_output, &QObject::destroyed, this, &ScreenCastSource::closed);
27 connect(m_output, &Output::enabledChanged, this, [this] {
28 if (!m_output->isEnabled()) {
29 Q_EMIT closed();
30 }
31 });
32}
33
35{
36 return true;
37}
38
40{
41 return DRM_FORMAT_ARGB8888;
42}
43
45{
46 return m_output->pixelSize();
47}
48
49void OutputScreenCastSource::render(spa_data *spa, spa_video_format format)
50{
51 const auto [outputTexture, colorDescription] = Compositor::self()->scene()->textureForOutput(m_output);
52 if (outputTexture) {
53 grabTexture(outputTexture.get(), spa, format);
54 }
55}
56
58{
59 const auto [outputTexture, colorDescription] = Compositor::self()->scene()->textureForOutput(m_output);
60 if (!outputTexture) {
61 return;
62 }
63
65 QMatrix4x4 projectionMatrix;
66 projectionMatrix.scale(1, -1);
67 projectionMatrix.ortho(QRect(QPoint(), textureSize()));
69 shaderBinder.shader()->setColorspaceUniformsToSRGB(colorDescription);
70
72 outputTexture->render(textureSize());
74}
75
76std::chrono::nanoseconds OutputScreenCastSource::clock() const
77{
78 return m_output->renderLoop()->lastPresentationTimestamp();
79}
80
82{
83 return m_output->refreshRate();
84}
85
86} // namespace KWin
87
88#include "moc_outputscreencastsource.cpp"
WorkspaceScene * scene() const
Definition compositor.h:60
static Compositor * self()
OpenGL framebuffer object.
static GLFramebuffer * popFramebuffer()
static void pushFramebuffer(GLFramebuffer *fbo)
bool setColorspaceUniformsToSRGB(const ColorDescription &src)
Definition glshader.cpp:462
bool setUniform(const char *name, float value)
Definition glshader.cpp:301
void enabledChanged()
void render(GLFramebuffer *target) override
std::chrono::nanoseconds clock() const override
OutputScreenCastSource(Output *output, QObject *parent=nullptr)
virtual std::pair< std::shared_ptr< GLTexture >, ColorDescription > textureForOutput(Output *output) const
GLenum format
Definition gltexture.cpp:49