22#include "bench.h"
33#include "pal/pal_video.h"
44
5- #ifdef _WIN32
6- #ifndef WIN32_LEAN_AND_MEAN
7- #define WIN32_LEAN_AND_MEAN
8- #endif // WIN32_LEAN_AND_MEAN
9-
10- #ifndef NOMINMAX
11- #define NOMINMAX
12- #endif // NOMINMAX
13-
14- // set unicode
15- #ifndef UNICODE
16- #define UNICODE
17- #endif // UNICODE
18-
19- #include <windows.h>
20-
21- #define PLATFORM_CLASS L"Platform"
22- static HINSTANCE g_Instance ;
23-
24- #endif // _WIN32
25-
26- #define MAX_ITERATIONS 1000
27-
285static inline void createDestroy ()
296{
307 PalResult result ;
@@ -39,93 +16,26 @@ static inline void createDestroy()
3916
4017 result = palCreateWindow (& createInfo , & window );
4118 if (result != PAL_RESULT_SUCCESS ) {
42- palLog (nullptr , "Failed to create window %s" , palFormatResult (result ));
19+ const char * error = palFormatResult (result );
20+ palLog (nullptr , "Failed to create window %s" , error );
4321 return ;
4422 }
4523
4624 palDestroyWindow (window );
4725}
4826
49- static inline void createDestroyPlatform ()
50- {
51- HWND window = nullptr ;
52- Uint32 style = WS_OVERLAPPEDWINDOW ;
53- Uint32 exStyle = WS_EX_APPWINDOW ;
54-
55- window = CreateWindowExW (
56- exStyle ,
57- PLATFORM_CLASS ,
58- L"Platform Window" ,
59- style ,
60- 100 ,
61- 100 ,
62- 640 ,
63- 480 ,
64- nullptr ,
65- nullptr ,
66- g_Instance ,
67- nullptr );
68-
69- if (!window ) {
70- palLog (nullptr , "Platform Error" );
71- return ;
72- }
73-
74- ShowWindow (window , SW_SHOW );
75- UpdateWindow (window );
76- SetWindowLongPtrW (window , GWLP_USERDATA , (LONG_PTR )nullptr );
77-
78- DestroyWindow (window );
79- }
80-
8127void windowBench ()
8228{
8329 // initialize PAL video
8430 PalResult result = palInitVideo (nullptr , nullptr );
8531 if (result != PAL_RESULT_SUCCESS ) {
86- palLog (
87- nullptr ,
88- "Failed to initialize video %s" ,
89- palFormatResult (result ));
32+ const char * error = palFormatResult (result );
33+ palLog (nullptr , "Failed to initialize video %s" , error );
9034 return ;
9135 }
9236
93- // initialize platform video
94- #ifdef _WIN32
95- HINSTANCE g_Instance = GetModuleHandleW (nullptr );
96-
97- // register class
98- WNDCLASSEXW wc = {0 };
99- wc .cbSize = sizeof (WNDCLASSEXW );
100- wc .hCursor = LoadCursorW (NULL , IDC_ARROW );
101- wc .hIcon = LoadIconW (NULL , IDI_APPLICATION );
102- wc .hIconSm = LoadIconW (NULL , IDI_APPLICATION );
103- wc .hInstance = g_Instance ;
104- wc .lpfnWndProc = DefWindowProcW ;
105- wc .lpszClassName = PLATFORM_CLASS ;
106- wc .style = CS_OWNDC ;
107-
108- if (!RegisterClassExW (& wc )) {
109- palLog (nullptr , "Platform Error" );
110- return ;
111- }
112- #endif // _WIN32
113-
114- // run benchmarks
115- // platform
116- runBench (
117- createDestroyPlatform ,
118- "Platform Window Benchmark" ,
119- MAX_ITERATIONS );
120-
121- // PAL
12237 runBench (createDestroy , "PAL Window Benchmark" , MAX_ITERATIONS );
12338
124- // shutdown platform video
125- #ifdef _WIN32
126- UnregisterClassW (PLATFORM_CLASS , g_Instance );
127- #endif // _WIN32
128-
12939 // shutdown PAL video
13040 palShutdownVideo ();
13141}
0 commit comments