File indexing completed on 2024-05-19 16:34:57

0001 /*
0002     KWin - the KDE window manager
0003     This file is part of the KDE project.
0004 
0005     SPDX-FileCopyrightText: 2017 Martin Flöser <mgraesslin@kde.org>
0006 
0007     SPDX-License-Identifier: GPL-2.0-or-later
0008 */
0009 #include "egl_context_attribute_builder.h"
0010 #include <epoxy/egl.h>
0011 
0012 namespace KWin
0013 {
0014 std::vector<int> EglContextAttributeBuilder::build() const
0015 {
0016     std::vector<int> attribs;
0017     if (isVersionRequested()) {
0018         attribs.emplace_back(EGL_CONTEXT_MAJOR_VERSION_KHR);
0019         attribs.emplace_back(majorVersion());
0020         attribs.emplace_back(EGL_CONTEXT_MINOR_VERSION_KHR);
0021         attribs.emplace_back(minorVersion());
0022     }
0023     int contextFlags = 0;
0024     if (isRobust()) {
0025         attribs.emplace_back(EGL_CONTEXT_OPENGL_RESET_NOTIFICATION_STRATEGY_KHR);
0026         attribs.emplace_back(EGL_LOSE_CONTEXT_ON_RESET_KHR);
0027         contextFlags |= EGL_CONTEXT_OPENGL_ROBUST_ACCESS_BIT_KHR;
0028         if (isResetOnVideoMemoryPurge()) {
0029             attribs.emplace_back(EGL_GENERATE_RESET_ON_VIDEO_MEMORY_PURGE_NV);
0030             attribs.emplace_back(GL_TRUE);
0031         }
0032     }
0033     if (isForwardCompatible()) {
0034         contextFlags |= EGL_CONTEXT_OPENGL_FORWARD_COMPATIBLE_BIT_KHR;
0035     }
0036     if (contextFlags != 0) {
0037         attribs.emplace_back(EGL_CONTEXT_FLAGS_KHR);
0038         attribs.emplace_back(contextFlags);
0039     }
0040     if (isCoreProfile() || isCompatibilityProfile()) {
0041         attribs.emplace_back(EGL_CONTEXT_OPENGL_PROFILE_MASK_KHR);
0042         if (isCoreProfile()) {
0043             attribs.emplace_back(EGL_CONTEXT_OPENGL_CORE_PROFILE_BIT_KHR);
0044         } else if (isCompatibilityProfile()) {
0045             attribs.emplace_back(EGL_CONTEXT_OPENGL_COMPATIBILITY_PROFILE_BIT_KHR);
0046         }
0047     }
0048     if (isHighPriority()) {
0049         attribs.emplace_back(EGL_CONTEXT_PRIORITY_LEVEL_IMG);
0050         attribs.emplace_back(EGL_CONTEXT_PRIORITY_HIGH_IMG);
0051     }
0052     attribs.emplace_back(EGL_NONE);
0053     return attribs;
0054 }
0055 
0056 std::vector<int> EglOpenGLESContextAttributeBuilder::build() const
0057 {
0058     std::vector<int> attribs;
0059     attribs.emplace_back(EGL_CONTEXT_CLIENT_VERSION);
0060     attribs.emplace_back(majorVersion());
0061     if (isRobust()) {
0062         attribs.emplace_back(EGL_CONTEXT_OPENGL_ROBUST_ACCESS_EXT);
0063         attribs.emplace_back(EGL_TRUE);
0064         attribs.emplace_back(EGL_CONTEXT_OPENGL_RESET_NOTIFICATION_STRATEGY_EXT);
0065         attribs.emplace_back(EGL_LOSE_CONTEXT_ON_RESET_EXT);
0066         if (isResetOnVideoMemoryPurge()) {
0067             attribs.emplace_back(EGL_GENERATE_RESET_ON_VIDEO_MEMORY_PURGE_NV);
0068             attribs.emplace_back(GL_TRUE);
0069         }
0070     }
0071     if (isHighPriority()) {
0072         attribs.emplace_back(EGL_CONTEXT_PRIORITY_LEVEL_IMG);
0073         attribs.emplace_back(EGL_CONTEXT_PRIORITY_HIGH_IMG);
0074     }
0075     attribs.emplace_back(EGL_NONE);
0076     return attribs;
0077 }
0078 
0079 }