| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2016 Google Inc. | 2 * Copyright 2016 Google Inc. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
| 5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
| 6 */ | 6 */ |
| 7 | 7 |
| 8 #include <windows.h> | 8 #include <windows.h> |
| 9 #include <tchar.h> | 9 #include <tchar.h> |
| 10 | 10 |
| 11 #include "SkTypes.h" | 11 #include "SkTypes.h" |
| 12 #include "Timer.h" |
| 12 #include "Window_win.h" | 13 #include "Window_win.h" |
| 13 #include "../Application.h" | 14 #include "../Application.h" |
| 14 | 15 |
| 15 static char* tchar_to_utf8(const TCHAR* str) { | 16 static char* tchar_to_utf8(const TCHAR* str) { |
| 16 #ifdef _UNICODE | 17 #ifdef _UNICODE |
| 17 int size = WideCharToMultiByte(CP_UTF8, 0, str, wcslen(str), NULL, 0, NULL,
NULL); | 18 int size = WideCharToMultiByte(CP_UTF8, 0, str, wcslen(str), NULL, 0, NULL,
NULL); |
| 18 char* str8 = (char*)sk_malloc_throw(size + 1); | 19 char* str8 = (char*)sk_malloc_throw(size + 1); |
| 19 WideCharToMultiByte(CP_UTF8, 0, str, wcslen(str), str8, size, NULL, NULL); | 20 WideCharToMultiByte(CP_UTF8, 0, str, wcslen(str), str8, size, NULL, NULL); |
| 20 str8[size] = '\0'; | 21 str8[size] = '\0'; |
| 21 return str8; | 22 return str8; |
| 22 #else | 23 #else |
| 23 return _strdup(str); | 24 return _strdup(str); |
| 24 #endif | 25 #endif |
| 25 } | 26 } |
| 26 | 27 |
| 28 static double now_ms() { return SkTime::GetNSecs() * 1e-6; } |
| 29 |
| 27 // This file can work with GUI or CONSOLE subsystem types since we define _tWinM
ain and main(). | 30 // This file can work with GUI or CONSOLE subsystem types since we define _tWinM
ain and main(). |
| 28 | 31 |
| 29 static int main_common(HINSTANCE hInstance, int show, int argc, char**argv); | 32 static int main_common(HINSTANCE hInstance, int show, int argc, char**argv); |
| 30 | 33 |
| 31 int APIENTRY _tWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPTSTR lpCm
dLine, | 34 int APIENTRY _tWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPTSTR lpCm
dLine, |
| 32 int nCmdShow) { | 35 int nCmdShow) { |
| 33 | 36 |
| 34 // convert from lpCmdLine to argc, argv. | 37 // convert from lpCmdLine to argc, argv. |
| 35 char* argv[4096]; | 38 char* argv[4096]; |
| 36 int argc = 0; | 39 int argc = 0; |
| (...skipping 16 matching lines...) Expand all Loading... |
| 53 | 56 |
| 54 int main(int argc, char**argv) { | 57 int main(int argc, char**argv) { |
| 55 return main_common(GetModuleHandle(NULL), SW_SHOW, argc, argv); | 58 return main_common(GetModuleHandle(NULL), SW_SHOW, argc, argv); |
| 56 } | 59 } |
| 57 | 60 |
| 58 static int main_common(HINSTANCE hInstance, int show, int argc, char**argv) { | 61 static int main_common(HINSTANCE hInstance, int show, int argc, char**argv) { |
| 59 | 62 |
| 60 Application* app = Application::Create(argc, argv, (void*)hInstance); | 63 Application* app = Application::Create(argc, argv, (void*)hInstance); |
| 61 | 64 |
| 62 MSG msg = { 0 }; | 65 MSG msg = { 0 }; |
| 66 |
| 67 double currentTime = 0.0; |
| 68 double previousTime = 0.0; |
| 69 |
| 63 // Main message loop | 70 // Main message loop |
| 64 while (WM_QUIT != msg.message) { | 71 while (WM_QUIT != msg.message) { |
| 65 if (PeekMessage(&msg, nullptr, 0, 0, PM_REMOVE)) { | 72 if (PeekMessage(&msg, nullptr, 0, 0, PM_REMOVE)) { |
| 66 TranslateMessage(&msg); | 73 TranslateMessage(&msg); |
| 67 DispatchMessage(&msg); | 74 DispatchMessage(&msg); |
| 68 } | 75 } |
| 69 | 76 |
| 70 app->onIdle(0.0f); | 77 previousTime = currentTime; |
| 78 currentTime = now_ms(); |
| 79 app->onIdle(currentTime - previousTime); |
| 71 } | 80 } |
| 72 | 81 |
| 73 delete app; | 82 delete app; |
| 74 | 83 |
| 75 return (int)msg.wParam; | 84 return (int)msg.wParam; |
| 76 } | 85 } |
| OLD | NEW |