OLD | NEW |
(Empty) | |
| 1 /* |
| 2 * Copyright 2016 Google Inc. |
| 3 * |
| 4 * Use of this source code is governed by a BSD-style license that can be |
| 5 * found in the LICENSE file. |
| 6 */ |
| 7 |
| 8 #include "SkTypes.h" |
| 9 #include "Timer.h" |
| 10 #include "Window_unix.h" |
| 11 #include "../Application.h" |
| 12 |
| 13 using sk_app::Application; |
| 14 |
| 15 static double now_ms() { return SkTime::GetNSecs() * 1e-6; } |
| 16 |
| 17 int main(int argc, char**argv) { |
| 18 |
| 19 Display* display = XOpenDisplay(nullptr); |
| 20 |
| 21 Application* app = Application::Create(argc, argv, (void*)display); |
| 22 |
| 23 double currentTime = 0.0; |
| 24 double previousTime = 0.0; |
| 25 |
| 26 // Get the file descriptor for the X display |
| 27 int x11_fd = ConnectionNumber(display); |
| 28 fd_set in_fds; |
| 29 |
| 30 bool done = false; |
| 31 while (!done) { |
| 32 // Create a file description set containing x11_fd |
| 33 FD_ZERO(&in_fds); |
| 34 FD_SET(x11_fd, &in_fds); |
| 35 |
| 36 // Set a sleep timer |
| 37 struct timeval tv; |
| 38 tv.tv_usec = 100; |
| 39 tv.tv_sec = 0; |
| 40 |
| 41 // Wait for an event on the file descriptor or for timer expiration |
| 42 (void) select(1, &in_fds, NULL, NULL, &tv); |
| 43 |
| 44 // Handle XEvents (if any) and flush the input |
| 45 XEvent event; |
| 46 while (XPending(display)) { |
| 47 XNextEvent(display, &event); |
| 48 |
| 49 sk_app::Window_unix* win = sk_app::Window_unix::gWindowMap.find(even
t.xany.window); |
| 50 if (win->handleEvent(event)) { |
| 51 done = true; |
| 52 break; |
| 53 } |
| 54 } |
| 55 |
| 56 previousTime = currentTime; |
| 57 currentTime = now_ms(); |
| 58 app->onIdle(currentTime - previousTime); |
| 59 } |
| 60 |
| 61 delete app; |
| 62 |
| 63 XCloseDisplay(display); |
| 64 |
| 65 return 0; |
| 66 } |
OLD | NEW |