Merge branch 'jekstrand_renderpass_transfer_bit_fix' into 'master'
[platform/upstream/VK-GL-CTS.git] / framework / platform / win32 / tcuWin32Platform.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 Win32 platform port.
22  *//*--------------------------------------------------------------------*/
23
24 #include "tcuWin32Platform.hpp"
25 #include "tcuWGLContextFactory.hpp"
26 #include "tcuFunctionLibrary.hpp"
27
28 #if defined(DEQP_SUPPORT_EGL)
29 #       include "tcuWin32EGLNativeDisplayFactory.hpp"
30 #       include "egluGLContextFactory.hpp"
31 #endif
32
33 namespace tcu
34 {
35
36 class VulkanLibrary : public vk::Library
37 {
38 public:
39         VulkanLibrary (void)
40                 : m_library     ("vulkan-1.dll")
41                 , m_driver      (m_library)
42         {
43         }
44
45         const vk::PlatformInterface& getPlatformInterface (void) const
46         {
47                 return m_driver;
48         }
49
50 private:
51         const tcu::DynamicFunctionLibrary       m_library;
52         const vk::PlatformDriver                        m_driver;
53 };
54
55 Win32Platform::Win32Platform (void)
56         : m_instance(GetModuleHandle(NULL))
57 {
58         // Set process priority to lower.
59         SetPriorityClass(GetCurrentProcess(), BELOW_NORMAL_PRIORITY_CLASS);
60
61         {
62                 WGLContextFactory* factory = DE_NULL;
63
64                 try
65                 {
66                         factory = new WGLContextFactory(m_instance);
67                 }
68                 catch (const std::exception& e)
69                 {
70                         print("Warning: WGL not supported: %s\n", e.what());
71                 }
72
73                 if (factory)
74                 {
75                         try
76                         {
77                                 m_contextFactoryRegistry.registerFactory(factory);
78                         }
79                         catch (...)
80                         {
81                                 delete factory;
82                                 throw;
83                         }
84                 }
85         }
86
87 #if defined(DEQP_SUPPORT_EGL)
88         m_nativeDisplayFactoryRegistry.registerFactory(new Win32EGLNativeDisplayFactory(m_instance));
89         m_contextFactoryRegistry.registerFactory(new eglu::GLContextFactory(m_nativeDisplayFactoryRegistry));
90 #endif
91 }
92
93 Win32Platform::~Win32Platform (void)
94 {
95 }
96
97 bool Win32Platform::processEvents (void)
98 {
99         MSG msg;
100         while (PeekMessage(&msg, (HWND)-1, 0, 0, PM_REMOVE))
101         {
102                 DispatchMessage(&msg);
103                 if (msg.message == WM_QUIT)
104                         return false;
105         }
106         return true;
107 }
108
109 vk::Library* Win32Platform::createLibrary (void) const
110 {
111         return new VulkanLibrary();
112 }
113
114 } // tcu
115
116 // Create platform
117 tcu::Platform* createPlatform (void)
118 {
119         return new tcu::Win32Platform();
120 }