File indexing completed on 2024-11-10 04:56:56
0001 /* 0002 KWin - the KDE window manager 0003 This file is part of the KDE project. 0004 0005 SPDX-FileCopyrightText: 2006 Lubos Lunak <l.lunak@kde.org> 0006 SPDX-FileCopyrightText: 2009, 2010, 2011 Martin Gräßlin <mgraesslin@kde.org> 0007 0008 SPDX-License-Identifier: GPL-2.0-or-later 0009 */ 0010 #include "platformsupport/scenes/opengl/openglbackend.h" 0011 #include "opengl/glutils_funcs.h" 0012 0013 #include "utils/common.h" 0014 0015 #include <QElapsedTimer> 0016 0017 #include <unistd.h> 0018 0019 namespace KWin 0020 { 0021 0022 OpenGLBackend::OpenGLBackend() 0023 : m_haveBufferAge(false) 0024 , m_failed(false) 0025 { 0026 } 0027 0028 OpenGLBackend::~OpenGLBackend() 0029 { 0030 } 0031 0032 CompositingType OpenGLBackend::compositingType() const 0033 { 0034 return OpenGLCompositing; 0035 } 0036 0037 void OpenGLBackend::setFailed(const QString &reason) 0038 { 0039 qCWarning(KWIN_OPENGL) << "Creating the OpenGL rendering failed: " << reason; 0040 m_failed = true; 0041 } 0042 0043 void OpenGLBackend::copyPixels(const QRegion ®ion, const QSize &screenSize) 0044 { 0045 const int height = screenSize.height(); 0046 for (const QRect &r : region) { 0047 const int x0 = r.x(); 0048 const int y0 = height - r.y() - r.height(); 0049 const int x1 = r.x() + r.width(); 0050 const int y1 = height - r.y(); 0051 0052 glBlitFramebuffer(x0, y0, x1, y1, x0, y0, x1, y1, GL_COLOR_BUFFER_BIT, GL_NEAREST); 0053 } 0054 } 0055 0056 std::pair<std::shared_ptr<KWin::GLTexture>, ColorDescription> OpenGLBackend::textureForOutput(Output *output) const 0057 { 0058 return {nullptr, ColorDescription::sRGB}; 0059 } 0060 0061 bool OpenGLBackend::checkGraphicsReset() 0062 { 0063 const GLenum status = KWin::glGetGraphicsResetStatus(); 0064 if (Q_LIKELY(status == GL_NO_ERROR)) { 0065 return false; 0066 } 0067 0068 switch (status) { 0069 case GL_GUILTY_CONTEXT_RESET: 0070 qCWarning(KWIN_OPENGL) << "A graphics reset attributable to the current GL context occurred."; 0071 break; 0072 case GL_INNOCENT_CONTEXT_RESET: 0073 qCWarning(KWIN_OPENGL) << "A graphics reset not attributable to the current GL context occurred."; 0074 break; 0075 case GL_UNKNOWN_CONTEXT_RESET: 0076 qCWarning(KWIN_OPENGL) << "A graphics reset of an unknown cause occurred."; 0077 break; 0078 default: 0079 break; 0080 } 0081 0082 QElapsedTimer timer; 0083 timer.start(); 0084 0085 // Wait until the reset is completed or max one second 0086 while (timer.elapsed() < 10000 && KWin::glGetGraphicsResetStatus() != GL_NO_ERROR) { 0087 usleep(50); 0088 } 0089 if (timer.elapsed() >= 10000) { 0090 qCWarning(KWIN_OPENGL) << "Waiting for glGetGraphicsResetStatus to return GL_NO_ERROR timed out!"; 0091 } 0092 0093 return true; 0094 } 0095 0096 } 0097 0098 #include "moc_openglbackend.cpp"