1 /*-------------------------------------------------------------------------
2 * drawElements Quality Program Tester Core
3 * ----------------------------------------
4 *
5 * Copyright 2016 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 "tcuWin32EGLNativeDisplayFactory.hpp"
27 #include "egluGLContextFactory.hpp"
28
29 // MinGW doesn't define this in its headers, but
30 // still has the export in the libs.
31 #if defined(__MINGW32__)
32 extern "C" WINUSERAPI WINBOOL WINAPI SetProcessDPIAware(VOID);
33 #endif
34
35 namespace tcu
36 {
37 namespace win32
38 {
39
Platform(void)40 Platform::Platform(void) : m_instance(GetModuleHandle(NULL)), m_vulkanPlatform(m_instance)
41 {
42 // Set process priority to lower.
43 SetPriorityClass(GetCurrentProcess(), BELOW_NORMAL_PRIORITY_CLASS);
44
45 // Set process to be DPI aware
46 // This is requried for VK tests that manually enter exclusive mode
47 // using VK_FULL_SCREEN_EXCLUSIVE_APPLICATION_CONTROLLED_EXT
48 if (SetProcessDPIAware() == 0)
49 {
50 TCU_FAIL("SetProcessDPIAware function failed");
51 }
52
53 {
54 wgl::ContextFactory *factory = DE_NULL;
55
56 try
57 {
58 factory = new wgl::ContextFactory(m_instance);
59 }
60 catch (const std::exception &e)
61 {
62 print("Warning: WGL not supported: %s\n", e.what());
63 }
64
65 if (factory)
66 {
67 try
68 {
69 m_contextFactoryRegistry.registerFactory(factory);
70 }
71 catch (...)
72 {
73 delete factory;
74 throw;
75 }
76 }
77 }
78
79 m_nativeDisplayFactoryRegistry.registerFactory(new win32::EGLNativeDisplayFactory(m_instance));
80 m_contextFactoryRegistry.registerFactory(new eglu::GLContextFactory(m_nativeDisplayFactoryRegistry));
81 }
82
~Platform(void)83 Platform::~Platform(void)
84 {
85 }
86
processEvents(void)87 bool Platform::processEvents(void)
88 {
89 MSG msg;
90 while (PeekMessage(&msg, (HWND)-1, 0, 0, PM_REMOVE))
91 {
92 DispatchMessage(&msg);
93 if (msg.message == WM_QUIT)
94 return false;
95 }
96 return true;
97 }
98
99 } // namespace win32
100 } // namespace tcu
101
102 // Create platform
createPlatform(void)103 tcu::Platform *createPlatform(void)
104 {
105 return new tcu::win32::Platform();
106 }
107