Changeset View
Changeset View
Standalone View
Standalone View
autotests/opengl_context_attribute_builder_test.cpp
Show All 16 Lines | |||||
17 | You should have received a copy of the GNU General Public License | 17 | You should have received a copy of the GNU General Public License | ||
18 | along with this program. If not, see <http://www.gnu.org/licenses/>. | 18 | along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
19 | *********************************************************************/ | 19 | *********************************************************************/ | ||
20 | #include "../abstract_opengl_context_attribute_builder.h" | 20 | #include "../abstract_opengl_context_attribute_builder.h" | ||
21 | #include "../egl_context_attribute_builder.h" | 21 | #include "../egl_context_attribute_builder.h" | ||
22 | #include <QtTest/QtTest> | 22 | #include <QtTest/QtTest> | ||
23 | #include <epoxy/egl.h> | 23 | #include <epoxy/egl.h> | ||
24 | 24 | | |||
25 | #include <kwinconfig.h> | ||||
26 | #if HAVE_EPOXY_GLX | ||||
27 | #include "../plugins/platforms/x11/standalone/glx_context_attribute_builder.h" | ||||
28 | #include <epoxy/glx.h> | ||||
29 | | ||||
30 | #ifndef GLX_GENERATE_RESET_ON_VIDEO_MEMORY_PURGE_NV | ||||
31 | #define GLX_GENERATE_RESET_ON_VIDEO_MEMORY_PURGE_NV 0x20F7 | ||||
32 | #endif | ||||
33 | #endif | ||||
34 | | ||||
25 | using namespace KWin; | 35 | using namespace KWin; | ||
26 | 36 | | |||
27 | class OpenGLContextAttributeBuilderTest : public QObject | 37 | class OpenGLContextAttributeBuilderTest : public QObject | ||
28 | { | 38 | { | ||
29 | Q_OBJECT | 39 | Q_OBJECT | ||
30 | private Q_SLOTS: | 40 | private Q_SLOTS: | ||
31 | void testCtor(); | 41 | void testCtor(); | ||
32 | void testRobust(); | 42 | void testRobust(); | ||
33 | void testForwardCompatible(); | 43 | void testForwardCompatible(); | ||
34 | void testProfile(); | 44 | void testProfile(); | ||
45 | void testResetOnVideoMemoryPurge(); | ||||
35 | void testVersionMajor(); | 46 | void testVersionMajor(); | ||
36 | void testVersionMajorAndMinor(); | 47 | void testVersionMajorAndMinor(); | ||
37 | void testEgl_data(); | 48 | void testEgl_data(); | ||
38 | void testEgl(); | 49 | void testEgl(); | ||
39 | void testGles_data(); | 50 | void testGles_data(); | ||
40 | void testGles(); | 51 | void testGles(); | ||
52 | void testGlx_data(); | ||||
53 | void testGlx(); | ||||
41 | }; | 54 | }; | ||
42 | 55 | | |||
43 | class MockOpenGLContextAttributeBuilder : public AbstractOpenGLContextAttributeBuilder | 56 | class MockOpenGLContextAttributeBuilder : public AbstractOpenGLContextAttributeBuilder | ||
44 | { | 57 | { | ||
45 | public: | 58 | public: | ||
46 | std::vector<int> build() const override; | 59 | std::vector<int> build() const override; | ||
47 | }; | 60 | }; | ||
48 | 61 | | |||
49 | std::vector<int> MockOpenGLContextAttributeBuilder::build() const | 62 | std::vector<int> MockOpenGLContextAttributeBuilder::build() const | ||
50 | { | 63 | { | ||
51 | return std::vector<int>(); | 64 | return std::vector<int>(); | ||
52 | } | 65 | } | ||
53 | 66 | | |||
54 | void OpenGLContextAttributeBuilderTest::testCtor() | 67 | void OpenGLContextAttributeBuilderTest::testCtor() | ||
55 | { | 68 | { | ||
56 | MockOpenGLContextAttributeBuilder builder; | 69 | MockOpenGLContextAttributeBuilder builder; | ||
57 | QCOMPARE(builder.isVersionRequested(), false); | 70 | QCOMPARE(builder.isVersionRequested(), false); | ||
58 | QCOMPARE(builder.majorVersion(), 0); | 71 | QCOMPARE(builder.majorVersion(), 0); | ||
59 | QCOMPARE(builder.minorVersion(), 0); | 72 | QCOMPARE(builder.minorVersion(), 0); | ||
60 | QCOMPARE(builder.isRobust(), false); | 73 | QCOMPARE(builder.isRobust(), false); | ||
61 | QCOMPARE(builder.isForwardCompatible(), false); | 74 | QCOMPARE(builder.isForwardCompatible(), false); | ||
62 | QCOMPARE(builder.isCoreProfile(), false); | 75 | QCOMPARE(builder.isCoreProfile(), false); | ||
63 | QCOMPARE(builder.isCompatibilityProfile(), false); | 76 | QCOMPARE(builder.isCompatibilityProfile(), false); | ||
77 | QCOMPARE(builder.isResetOnVideoMemoryPurge(), false); | ||||
64 | } | 78 | } | ||
65 | 79 | | |||
66 | void OpenGLContextAttributeBuilderTest::testRobust() | 80 | void OpenGLContextAttributeBuilderTest::testRobust() | ||
67 | { | 81 | { | ||
68 | MockOpenGLContextAttributeBuilder builder; | 82 | MockOpenGLContextAttributeBuilder builder; | ||
69 | QCOMPARE(builder.isRobust(), false); | 83 | QCOMPARE(builder.isRobust(), false); | ||
70 | builder.setRobust(true); | 84 | builder.setRobust(true); | ||
71 | QCOMPARE(builder.isRobust(), true); | 85 | QCOMPARE(builder.isRobust(), true); | ||
Show All 22 Lines | 101 | { | |||
94 | builder.setCompatibilityProfile(true); | 108 | builder.setCompatibilityProfile(true); | ||
95 | QCOMPARE(builder.isCoreProfile(), false); | 109 | QCOMPARE(builder.isCoreProfile(), false); | ||
96 | QCOMPARE(builder.isCompatibilityProfile(), true); | 110 | QCOMPARE(builder.isCompatibilityProfile(), true); | ||
97 | builder.setCoreProfile(true); | 111 | builder.setCoreProfile(true); | ||
98 | QCOMPARE(builder.isCoreProfile(), true); | 112 | QCOMPARE(builder.isCoreProfile(), true); | ||
99 | QCOMPARE(builder.isCompatibilityProfile(), false); | 113 | QCOMPARE(builder.isCompatibilityProfile(), false); | ||
100 | } | 114 | } | ||
101 | 115 | | |||
116 | void OpenGLContextAttributeBuilderTest::testResetOnVideoMemoryPurge() | ||||
117 | { | ||||
118 | MockOpenGLContextAttributeBuilder builder; | ||||
119 | QCOMPARE(builder.isResetOnVideoMemoryPurge(), false); | ||||
120 | builder.setResetOnVideoMemoryPurge(true); | ||||
121 | QCOMPARE(builder.isResetOnVideoMemoryPurge(), true); | ||||
122 | builder.setResetOnVideoMemoryPurge(false); | ||||
123 | QCOMPARE(builder.isResetOnVideoMemoryPurge(), false); | ||||
124 | } | ||||
125 | | ||||
102 | void OpenGLContextAttributeBuilderTest::testVersionMajor() | 126 | void OpenGLContextAttributeBuilderTest::testVersionMajor() | ||
103 | { | 127 | { | ||
104 | MockOpenGLContextAttributeBuilder builder; | 128 | MockOpenGLContextAttributeBuilder builder; | ||
105 | builder.setVersion(2); | 129 | builder.setVersion(2); | ||
106 | QCOMPARE(builder.isVersionRequested(), true); | 130 | QCOMPARE(builder.isVersionRequested(), true); | ||
107 | QCOMPARE(builder.majorVersion(), 2); | 131 | QCOMPARE(builder.majorVersion(), 2); | ||
108 | QCOMPARE(builder.minorVersion(), 0); | 132 | QCOMPARE(builder.minorVersion(), 0); | ||
109 | builder.setVersion(3); | 133 | builder.setVersion(3); | ||
▲ Show 20 Lines • Show All 134 Lines • ▼ Show 20 Line(s) | 265 | { | |||
244 | EglOpenGLESContextAttributeBuilder builder; | 268 | EglOpenGLESContextAttributeBuilder builder; | ||
245 | builder.setVersion(2); | 269 | builder.setVersion(2); | ||
246 | builder.setRobust(robust); | 270 | builder.setRobust(robust); | ||
247 | 271 | | |||
248 | auto attribs = builder.build(); | 272 | auto attribs = builder.build(); | ||
249 | QTEST(attribs, "expectedAttribs"); | 273 | QTEST(attribs, "expectedAttribs"); | ||
250 | } | 274 | } | ||
251 | 275 | | |||
276 | void OpenGLContextAttributeBuilderTest::testGlx_data() | ||||
277 | { | ||||
278 | #if HAVE_EPOXY_GLX | ||||
279 | QTest::addColumn<bool>("requestVersion"); | ||||
280 | QTest::addColumn<int>("major"); | ||||
281 | QTest::addColumn<int>("minor"); | ||||
282 | QTest::addColumn<bool>("robust"); | ||||
283 | QTest::addColumn<bool>("videoPurge"); | ||||
284 | QTest::addColumn<std::vector<int>>("expectedAttribs"); | ||||
285 | | ||||
286 | QTest::newRow("fallback") << true << 2 << 1 << false << false << std::vector<int>{ | ||||
287 | GLX_CONTEXT_MAJOR_VERSION_ARB, 2, | ||||
288 | GLX_CONTEXT_MINOR_VERSION_ARB, 1, | ||||
289 | 0}; | ||||
290 | QTest::newRow("legacy/robust") << false << 0 << 0 << true << false << std::vector<int>{ | ||||
291 | GLX_CONTEXT_FLAGS_ARB, GLX_CONTEXT_ROBUST_ACCESS_BIT_ARB, | ||||
292 | GLX_CONTEXT_RESET_NOTIFICATION_STRATEGY_ARB, GLX_LOSE_CONTEXT_ON_RESET_ARB, | ||||
293 | 0 | ||||
294 | }; | ||||
295 | QTest::newRow("legacy/robust/videoPurge") << false << 0 << 0 << true << true << std::vector<int>{ | ||||
296 | GLX_CONTEXT_FLAGS_ARB, GLX_CONTEXT_ROBUST_ACCESS_BIT_ARB, | ||||
297 | GLX_CONTEXT_RESET_NOTIFICATION_STRATEGY_ARB, GLX_LOSE_CONTEXT_ON_RESET_ARB, | ||||
298 | GLX_GENERATE_RESET_ON_VIDEO_MEMORY_PURGE_NV, GL_TRUE, | ||||
299 | 0 | ||||
300 | }; | ||||
301 | QTest::newRow("core") << true << 3 << 1 << false << false << std::vector<int>{ | ||||
302 | GLX_CONTEXT_MAJOR_VERSION_ARB, 3, | ||||
303 | GLX_CONTEXT_MINOR_VERSION_ARB, 1, | ||||
304 | 0}; | ||||
305 | QTest::newRow("core/robust") << true << 3 << 1 << true << false << std::vector<int>{ | ||||
306 | GLX_CONTEXT_MAJOR_VERSION_ARB, 3, | ||||
307 | GLX_CONTEXT_MINOR_VERSION_ARB, 1, | ||||
308 | GLX_CONTEXT_FLAGS_ARB, GLX_CONTEXT_ROBUST_ACCESS_BIT_ARB, | ||||
309 | GLX_CONTEXT_RESET_NOTIFICATION_STRATEGY_ARB, GLX_LOSE_CONTEXT_ON_RESET_ARB, | ||||
310 | 0 | ||||
311 | }; | ||||
312 | QTest::newRow("core/robust/videoPurge") << true << 3 << 1 << true << true << std::vector<int>{ | ||||
313 | GLX_CONTEXT_MAJOR_VERSION_ARB, 3, | ||||
314 | GLX_CONTEXT_MINOR_VERSION_ARB, 1, | ||||
315 | GLX_CONTEXT_FLAGS_ARB, GLX_CONTEXT_ROBUST_ACCESS_BIT_ARB, | ||||
316 | GLX_CONTEXT_RESET_NOTIFICATION_STRATEGY_ARB, GLX_LOSE_CONTEXT_ON_RESET_ARB, | ||||
317 | GLX_GENERATE_RESET_ON_VIDEO_MEMORY_PURGE_NV, GL_TRUE, | ||||
318 | 0 | ||||
319 | }; | ||||
320 | #endif | ||||
321 | } | ||||
322 | | ||||
323 | void OpenGLContextAttributeBuilderTest::testGlx() | ||||
324 | { | ||||
325 | #if HAVE_EPOXY_GLX | ||||
326 | QFETCH(bool, requestVersion); | ||||
327 | QFETCH(int, major); | ||||
328 | QFETCH(int, minor); | ||||
329 | QFETCH(bool, robust); | ||||
330 | QFETCH(bool, videoPurge); | ||||
331 | | ||||
332 | GlxContextAttributeBuilder builder; | ||||
333 | if (requestVersion) { | ||||
334 | builder.setVersion(major, minor); | ||||
335 | } | ||||
336 | builder.setRobust(robust); | ||||
337 | builder.setResetOnVideoMemoryPurge(videoPurge); | ||||
338 | | ||||
339 | auto attribs = builder.build(); | ||||
340 | QTEST(attribs, "expectedAttribs"); | ||||
341 | #endif | ||||
342 | } | ||||
343 | | ||||
252 | QTEST_GUILESS_MAIN(OpenGLContextAttributeBuilderTest) | 344 | QTEST_GUILESS_MAIN(OpenGLContextAttributeBuilderTest) | ||
253 | #include "opengl_context_attribute_builder_test.moc" | 345 | #include "opengl_context_attribute_builder_test.moc" |