Merge Vulkan CTS 1.0.2.2 into goog/oc-dev
[platform/upstream/VK-GL-CTS.git] / framework / platform / X11 / tcuX11Platform.cpp
1 /*-------------------------------------------------------------------------
2  * drawElements Quality Program Tester Core
3  * ----------------------------------------
4  *
5  * Copyright 2014 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 X11 Platform.
22  *//*--------------------------------------------------------------------*/
23
24 #include "tcuX11Platform.hpp"
25 #include "vkWsiPlatform.hpp"
26
27 #include "deUniquePtr.hpp"
28 #include "gluPlatform.hpp"
29 #include "vkPlatform.hpp"
30 #include "tcuX11.hpp"
31 #include "tcuFunctionLibrary.hpp"
32 #include "deMemory.h"
33 #include "tcuX11VulkanPlatform.hpp"
34 #include "tcuX11EglPlatform.hpp"
35
36 #if defined (DEQP_SUPPORT_GLX)
37 #       include "tcuX11GlxPlatform.hpp"
38 #endif
39
40 #include <sys/utsname.h>
41
42 using de::MovePtr;
43 using de::UniquePtr;
44
45 namespace tcu
46 {
47 namespace x11
48 {
49
50 class X11GLPlatform : public glu::Platform
51 {
52 public:
53         void            registerFactory (de::MovePtr<glu::ContextFactory> factory)
54         {
55                 m_contextFactoryRegistry.registerFactory(factory.release());
56         }
57 };
58
59 class X11Platform : public tcu::Platform
60 {
61 public:
62                                                         X11Platform                     (void);
63         bool                                    processEvents           (void) { return !m_eventState.getQuitFlag(); }
64
65         const vk::Platform&             getVulkanPlatform       (void) const { return m_vkPlatform; }
66         const eglu::Platform&   getEGLPlatform          (void) const { return m_eglPlatform; }
67         const glu::Platform&    getGLPlatform           (void) const { return m_glPlatform; }
68
69 private:
70         EventState                              m_eventState;
71         x11::VulkanPlatform             m_vkPlatform;
72         x11::egl::Platform              m_eglPlatform;
73         X11GLPlatform                   m_glPlatform;
74 };
75
76 X11Platform::X11Platform (void)
77         : m_vkPlatform  (m_eventState)
78         , m_eglPlatform (m_eventState)
79 {
80 #if defined (DEQP_SUPPORT_GLX)
81         m_glPlatform.registerFactory(glx::createContextFactory(m_eventState));
82 #endif // DEQP_SUPPORT_GLX
83
84         m_glPlatform.registerFactory(m_eglPlatform.createContextFactory());
85 }
86
87 } // x11
88 } // tcu
89
90 tcu::Platform* createPlatform (void)
91 {
92         // From man:XinitThreads(3):
93         //
94         //     The XInitThreads function initializes Xlib support for concurrent
95         //     threads.  This function must be the first Xlib function
96         //     a multi-threaded program calls, and it must complete before any other
97         //     Xlib call is made.
98         DE_CHECK_RUNTIME_ERR(XInitThreads() != 0);
99
100         return new tcu::x11::X11Platform();
101 }