KWin
Loading...
Searching...
No Matches
openglbackend.cpp
Go to the documentation of this file.
1/*
2 KWin - the KDE window manager
3 This file is part of the KDE project.
4
5 SPDX-FileCopyrightText: 2006 Lubos Lunak <l.lunak@kde.org>
6 SPDX-FileCopyrightText: 2009, 2010, 2011 Martin Gräßlin <mgraesslin@kde.org>
7
8 SPDX-License-Identifier: GPL-2.0-or-later
9*/
12
13#include "utils/common.h"
14
15#include <QElapsedTimer>
16
17#include <unistd.h>
18
19namespace KWin
20{
21
23 : m_haveBufferAge(false)
24 , m_failed(false)
25{
26}
27
31
36
37void OpenGLBackend::setFailed(const QString &reason)
38{
39 qCWarning(KWIN_OPENGL) << "Creating the OpenGL rendering failed: " << reason;
40 m_failed = true;
41}
42
43void OpenGLBackend::copyPixels(const QRegion &region, const QSize &screenSize)
44{
45 const int height = screenSize.height();
46 for (const QRect &r : region) {
47 const int x0 = r.x();
48 const int y0 = height - r.y() - r.height();
49 const int x1 = r.x() + r.width();
50 const int y1 = height - r.y();
51
52 glBlitFramebuffer(x0, y0, x1, y1, x0, y0, x1, y1, GL_COLOR_BUFFER_BIT, GL_NEAREST);
53 }
54}
55
56std::pair<std::shared_ptr<KWin::GLTexture>, ColorDescription> OpenGLBackend::textureForOutput(Output *output) const
57{
58 return {nullptr, ColorDescription::sRGB};
59}
60
62{
63 const GLenum status = KWin::glGetGraphicsResetStatus();
64 if (Q_LIKELY(status == GL_NO_ERROR)) {
65 return false;
66 }
67
68 switch (status) {
69 case GL_GUILTY_CONTEXT_RESET:
70 qCWarning(KWIN_OPENGL) << "A graphics reset attributable to the current GL context occurred.";
71 break;
72 case GL_INNOCENT_CONTEXT_RESET:
73 qCWarning(KWIN_OPENGL) << "A graphics reset not attributable to the current GL context occurred.";
74 break;
75 case GL_UNKNOWN_CONTEXT_RESET:
76 qCWarning(KWIN_OPENGL) << "A graphics reset of an unknown cause occurred.";
77 break;
78 default:
79 break;
80 }
81
82 QElapsedTimer timer;
83 timer.start();
84
85 // Wait until the reset is completed or max one second
86 while (timer.elapsed() < 10000 && KWin::glGetGraphicsResetStatus() != GL_NO_ERROR) {
87 usleep(50);
88 }
89 if (timer.elapsed() >= 10000) {
90 qCWarning(KWIN_OPENGL) << "Waiting for glGetGraphicsResetStatus to return GL_NO_ERROR timed out!";
91 }
92
93 return true;
94}
95
96}
97
98#include "moc_openglbackend.cpp"
static const ColorDescription sRGB
Definition colorspace.h:132
CompositingType compositingType() const override final
bool checkGraphicsReset() override final
virtual std::pair< std::shared_ptr< GLTexture >, ColorDescription > textureForOutput(Output *output) const
void setFailed(const QString &reason)
Sets the backend initialization to failed.
void copyPixels(const QRegion &region, const QSize &screenSize)
CompositingType
Definition globals.h:28
@ OpenGLCompositing
Definition globals.h:37
glGetGraphicsResetStatus_func glGetGraphicsResetStatus