KWin
Loading...
Searching...
No Matches
windowscreencastsource.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 "core/rendertarget.h"
14#include "core/renderviewport.h"
15#include "effect/effect.h"
16#include "opengl/gltexture.h"
17#include "opengl/glutils.h"
18#include "scene/itemrenderer.h"
19#include "scene/windowitem.h"
21#include <drm_fourcc.h>
22
23namespace KWin
24{
25
27 : ScreenCastSource(parent)
28 , m_window(window)
29 , m_offscreenRef(window)
30{
31 connect(m_window, &Window::closed, this, &ScreenCastSource::closed);
32}
33
35{
36 return DRM_FORMAT_ARGB8888;
37}
38
40{
41 return true;
42}
43
45{
46 return m_window->clientGeometry().size().toSize();
47}
48
49void WindowScreenCastSource::render(spa_data *spa, spa_video_format format)
50{
51 const auto offscreenTexture = GLTexture::allocate(hasAlphaChannel() ? GL_RGBA8 : GL_RGB8, textureSize());
52 if (!offscreenTexture) {
53 return;
54 }
55 offscreenTexture->setContentTransform(OutputTransform::FlipY);
56
57 GLFramebuffer offscreenTarget(offscreenTexture.get());
58 render(&offscreenTarget);
59 grabTexture(offscreenTexture.get(), spa, format);
60}
61
63{
64 RenderTarget renderTarget(target);
65 RenderViewport viewport(m_window->clientGeometry(), 1, renderTarget);
66
67 WindowPaintData data;
69
71 glClearColor(0.0, 0.0, 0.0, 0.0);
72 glClear(GL_COLOR_BUFFER_BIT);
73 Compositor::self()->scene()->renderer()->renderItem(renderTarget, viewport, m_window->windowItem(), Scene::PAINT_WINDOW_TRANSFORMED, infiniteRegion(), data);
75}
76
77std::chrono::nanoseconds WindowScreenCastSource::clock() const
78{
79 return m_window->output()->renderLoop()->lastPresentationTimestamp();
80}
81
83{
84 return m_window->output()->refreshRate();
85}
86
87} // namespace KWin
88
89#include "moc_windowscreencastsource.cpp"
WorkspaceScene * scene() const
Definition compositor.h:60
static Compositor * self()
OpenGL framebuffer object.
static GLFramebuffer * popFramebuffer()
static void pushFramebuffer(GLFramebuffer *fbo)
static std::unique_ptr< GLTexture > allocate(GLenum internalFormat, const QSize &size, int levels=1)
virtual void renderItem(const RenderTarget &renderTarget, const RenderViewport &viewport, Item *item, int mask, const QRegion &region, const WindowPaintData &data)=0
QMatrix4x4 projectionMatrix() const
@ PAINT_WINDOW_TRANSFORMED
Definition scene.h:55
ItemRenderer * renderer() const
Definition scene.cpp:76
std::chrono::nanoseconds clock() const override
void render(GLFramebuffer *target) override
WindowScreenCastSource(Window *window, QObject *parent=nullptr)
void setProjectionMatrix(const QMatrix4x4 &matrix)
Definition effect.cpp:327
KWIN_EXPORT QRect infiniteRegion()
Definition globals.h:234
GLenum format
Definition gltexture.cpp:49