xref: /aosp_15_r20/external/deqp/framework/platform/lnx/tcuLnxPlatform.cpp (revision 35238bce31c2a825756842865a792f8cf7f89930)
1 /*-------------------------------------------------------------------------
2  * drawElements Quality Program Tester Core
3  * ----------------------------------------
4  *
5  * Copyright 2017 The Android Open Source Project
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  *
19  *//*!
20  * \file
21  * \brief Linux Platform.
22  *//*--------------------------------------------------------------------*/
23 
24 #include "tcuLnxPlatform.hpp"
25 
26 #include "tcuLnxVulkanPlatform.hpp"
27 #include "tcuLnxEglPlatform.hpp"
28 
29 #include "deUniquePtr.hpp"
30 #include "gluPlatform.hpp"
31 #include "vkPlatform.hpp"
32 
33 #if defined(DEQP_SUPPORT_X11)
34 #include <X11/Xlib.h>
35 #endif // DEQP_SUPPORT_X11
36 
37 #if defined(DEQP_SUPPORT_GLX)
38 #include "tcuLnxX11GlxPlatform.hpp"
39 #endif // DEQP_SUPPORT_GLX
40 
41 using de::MovePtr;
42 using de::UniquePtr;
43 
44 namespace tcu
45 {
46 namespace lnx
47 {
48 
49 class LinuxGLPlatform : public glu::Platform
50 {
51 public:
registerFactory(de::MovePtr<glu::ContextFactory> factory)52     void registerFactory(de::MovePtr<glu::ContextFactory> factory)
53     {
54         m_contextFactoryRegistry.registerFactory(factory.release());
55     }
56 };
57 
58 class LinuxPlatform : public tcu::Platform
59 {
60 public:
61     LinuxPlatform(void);
processEvents(void)62     bool processEvents(void)
63     {
64         return !m_eventState.getQuitFlag();
65     }
66 
getVulkanPlatform(void) const67     const vk::Platform &getVulkanPlatform(void) const
68     {
69         return m_vkPlatform;
70     }
getEGLPlatform(void) const71     const eglu::Platform &getEGLPlatform(void) const
72     {
73         return m_eglPlatform;
74     }
getGLPlatform(void) const75     const glu::Platform &getGLPlatform(void) const
76     {
77         return m_glPlatform;
78     }
79 
80 private:
81     EventState m_eventState;
82     VulkanPlatform m_vkPlatform;
83     egl::Platform m_eglPlatform;
84     LinuxGLPlatform m_glPlatform;
85 };
86 
LinuxPlatform(void)87 LinuxPlatform::LinuxPlatform(void) : m_vkPlatform(m_eventState), m_eglPlatform(m_eventState)
88 {
89 #if defined(DEQP_SUPPORT_GLX)
90     m_glPlatform.registerFactory(x11::glx::createContextFactory(m_eventState));
91 #endif // DEQP_SUPPORT_GLX
92 
93     m_glPlatform.registerFactory(m_eglPlatform.createContextFactory());
94 }
95 
96 } // namespace lnx
97 } // namespace tcu
98 
createPlatform(void)99 tcu::Platform *createPlatform(void)
100 {
101 #if defined(DEQP_SUPPORT_X11)
102     // From man:XinitThreads(3):
103     //
104     //     The XInitThreads function initializes Xlib support for concurrent
105     //     threads.  This function must be the first Xlib function
106     //     a multi-threaded program calls, and it must complete before any other
107     //     Xlib call is made.
108     DE_CHECK_RUNTIME_ERR(XInitThreads() != 0);
109 #endif // DEQP_SUPPORT_X11
110 
111     return new tcu::lnx::LinuxPlatform();
112 }
113