Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1117)

Side by Side Diff: tools/viewer/sk_app/unix/main_unix.cpp

Issue 2226413002: Clean up Xlib viewer (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Fix non-vulkan build Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « tools/viewer/sk_app/VulkanWindowContext.cpp ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 "SkTypes.h" 8 #include "SkTypes.h"
9 #include "SkTHash.h" 9 #include "SkTHash.h"
10 #include "Timer.h" 10 #include "Timer.h"
11 #include "Window_unix.h" 11 #include "Window_unix.h"
12 #include "../Application.h" 12 #include "../Application.h"
13 13
14 using sk_app::Application; 14 using sk_app::Application;
15 15
16 void finishWindow(sk_app::Window_unix* win) { 16 void finishWindow(sk_app::Window_unix* win) {
17 win->finishResize(); 17 win->finishResize();
18 win->finishPaint(); 18 win->finishPaint();
19 } 19 }
20 20
21 int main(int argc, char**argv) { 21 int main(int argc, char**argv) {
22 22
23 Display* display = XOpenDisplay(nullptr); 23 Display* display = XOpenDisplay(nullptr);
24 24
25 Application* app = Application::Create(argc, argv, (void*)display); 25 Application* app = Application::Create(argc, argv, (void*)display);
26 26
27 // Get the file descriptor for the X display 27 // Get the file descriptor for the X display
28 int x11_fd = ConnectionNumber(display); 28 int x11_fd = ConnectionNumber(display);
29 fd_set in_fds; 29 int count = x11_fd + 1;
30 30
31 SkTHashSet<sk_app::Window_unix*> pendingWindows; 31 SkTHashSet<sk_app::Window_unix*> pendingWindows;
32 bool done = false; 32 bool done = false;
33 while (!done) { 33 while (!done) {
34 // Create a file description set containing x11_fd 34 // Create a file description set containing x11_fd
35 fd_set in_fds;
35 FD_ZERO(&in_fds); 36 FD_ZERO(&in_fds);
36 FD_SET(x11_fd, &in_fds); 37 FD_SET(x11_fd, &in_fds);
37 38
38 // Set a sleep timer 39 // Set a sleep timer
39 struct timeval tv; 40 struct timeval tv;
40 tv.tv_usec = 100; 41 tv.tv_usec = 100;
41 tv.tv_sec = 0; 42 tv.tv_sec = 0;
42 43
43 // Wait for an event on the file descriptor or for timer expiration 44 while (!XPending(display)) {
44 (void) select(1, &in_fds, NULL, NULL, &tv); 45 // Wait for an event on the file descriptor or for timer expiration
46 (void) select(count, &in_fds, NULL, NULL, &tv);
47 }
45 48
46 // Handle XEvents (if any) and flush the input 49 // Handle XEvents (if any) and flush the input
47 XEvent event; 50 int count = XPending(display);
48 while (XPending(display) && !done) { 51 while (count-- && !done) {
52 XEvent event;
49 XNextEvent(display, &event); 53 XNextEvent(display, &event);
50 54
51 sk_app::Window_unix* win = sk_app::Window_unix::gWindowMap.find(even t.xany.window); 55 sk_app::Window_unix* win = sk_app::Window_unix::gWindowMap.find(even t.xany.window);
52 // paint and resize events get collapsed 56 // paint and resize events get collapsed
53 switch (event.type) { 57 switch (event.type) {
54 case Expose: 58 case Expose:
55 win->markPendingPaint(); 59 win->markPendingPaint();
56 pendingWindows.add(win); 60 pendingWindows.add(win);
57 break; 61 break;
58 case ConfigureNotify: 62 case ConfigureNotify:
59 win->markPendingResize(event.xconfigurerequest.width, 63 win->markPendingResize(event.xconfigurerequest.width,
60 event.xconfigurerequest.height); 64 event.xconfigurerequest.height);
61 pendingWindows.add(win); 65 pendingWindows.add(win);
62 break; 66 break;
63 default: 67 default:
64 if (win->handleEvent(event)) { 68 if (win->handleEvent(event)) {
65 done = true; 69 done = true;
66 } 70 }
67 break; 71 break;
68 } 72 }
69 } 73 }
70 74
71 pendingWindows.foreach(finishWindow); 75 pendingWindows.foreach(finishWindow);
72 if (pendingWindows.count() > 0) { 76 if (pendingWindows.count() > 0) {
73 app->onIdle(); 77 app->onIdle();
74 } 78 }
75 pendingWindows.reset(); 79 pendingWindows.reset();
80
81 XFlush(display);
76 } 82 }
77 83
78 delete app; 84 delete app;
79 85
80 XCloseDisplay(display); 86 XCloseDisplay(display);
81 87
82 return 0; 88 return 0;
83 } 89 }
OLDNEW
« no previous file with comments | « tools/viewer/sk_app/VulkanWindowContext.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698